Template matching is an image processing technique which is used to find the location of small-parts/template of a large image. This technique is widely used for object detection projects, like product quality, vahicle tracking, robotics etc.
In this article, we will learn how to use template matching for detecting the related fields in a document image.
Above task can be achieved using template matching. Clip out the field images and apply template matching using clipped field images and the document image. The algorithm is simple yet reproducible into complex versions to solve the problem of field detection and localization for document images belonging to specific domains.
- Clip/Crop field images from the main document and use them as separate templates.
- Define/tune thresholds for different fields.
- Apply template matching for each cropped field template using OpenCV function
- Draw bounding boxes using the coordinates of rectangles fetched from template matching.
- Optional: Augment field templates and fine tune threshold to improve result for different document images.
Below is the Python code:
Advantages of using template matching:
- Computationally inexpensive.
- Easy to use and modifiable for different use-cases.
- Gives good results in case of document data scarcity.
- Result are not highly accurate as compared to segmentation techniques using deep learning.
- Lacks overlapping pattern problem resolution.
- Template matching using OpenCV in Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python | Corner Detection with Shi-Tomasi Corner Detection Method using OpenCV
- Python | Corner detection with Harris Corner Detection method using OpenCV
- Hotword detection with Python
- Pattern matching in Python with Regex
- Python | Remove matching tuples
- Python | Get matching substrings in string
- Car driving using hand detection in Python
- Python | Smile detection using OpenCV
- Circle Detection using OpenCV | Python
- Python | Count of elements matching particular condition
- Python | Remove first K elements matching some condition
- Prefix matching in Python using pytrie module
- Face Detection using Python and OpenCV with webcam
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.