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 Harris Corner Detection method using OpenCV
- Python | Corner Detection with Shi-Tomasi Corner Detection Method using OpenCV
- Pattern matching in Python with Regex
- Python | Get matching substrings in string
- Python - Sum elements matching condition
- Python | Remove matching tuples
- Python | Summation of first N matching condition
- Hotword detection with Python
- Python | Count of elements matching particular condition
- Python | Remove first K elements matching some condition
- Python | Find dictionary matching value in list
- Python | Count of Matching i, j index elements
- Prefix matching in Python using pytrie module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.