-
Notifications
You must be signed in to change notification settings - Fork 31
op matchTemplate
OpenCV matchTemplate wrapper with FireSight extensions.
Correlation-based template matching is quite powerful. The frequency spectrum of a template is multiplied by the frequency spectrum of an image to obtain the correlation. Maxima (or minima, depending on the method) indicate the candidates for matching. If the images to be recognized are all in a flat plane orthogonal to the camera, there is little or no need to account for perspective skew or near/far size adjustments. For this reason, matchTemplate alone can be used quite effectively in a great majority pick-and-place use cases.
-
method Default is
CV_TM_CCOEFF_NORMED
. - template Path to image template to match
-
output FireSight: Image for stage output. Default is
current
, which displays working image. To use input image, useinput
; to see correlation image, usecorr
. -
threshold FireSight: If maxVal is below this value, then no matches will be reported. Default is
0.7
. -
corr FireSight: Normalized recognition threshold in the interval [0,1]. Used to determine best match of candidates. For CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED, CV_TM_CCORR, and CV_TM_CCORR_NORMED methods, this is a minimum threshold for positive recognition; for all other methods, it is a maximum threshold. Default is
0.85
. - angle FireSight: Match template at specified angle in degrees
{ "maxVal":0.97696870565414429, "rects":[ { "x":467.0, "y":68.0, "width":29.0, "height":37.0, "angle":0.0, "corr":1.0 }, { "x":518.0, "y":69.0, "width":29.0, "height":37.0, "angle":0.0, "corr":0.99414855241775513 }, { "x":711.0, "y":71.0, "width":29.0, "height":37.0, "angle":0.0, "corr":0.99687016010284424 }, { "x":760.0, "y":71.0, "width":29.0, "height":37.0, "angle":0.0, "corr":0.99490123987197876 } ] }
- maxVal The maximum value in the correlation matrix
- rects The RotatedRect values of the matched positions
- x Center x
- y Center y
- height Height of rectangle
- width Widht of rectangle
- corr Normalized correlation over the interval [0,1], with respect to maxVal
Example: Find 37x29 rectangles in a pcb image pipeline
firesight -i img/pcb.jpg -p json/matchCCOEFF_NORMED.json -o target/matchCCOEFF_NORMED.jpg
The template is remarkably simple and can even be generated by the pipeline. It is just a 37x29 rectangle:
Bright spots in the correlation image correspond to matches:
Example: Find 37x29 rectangles rotated 45 degrees pipeline
firesight -i img/pcb.jpg -p json/match45.json -o target/match45.jpg
Example: Find template at 0, 90, 180, and 270 degrees pipeline
firesight -i img/chris-reference.jpg -p json/chris-match-search.json -o target/chris-match.jpg
Here is a simple way to recognize four orientations with a single pipeline. Although easy to put together, it quadruples the total time taken to match the templates. Other solutions such as template ring projection can create templates capable of recognizing arbitrary or specific angles.
Example: Find the crash dummy pipeline
firesight -i img/fiducial-cam1.jpg -p json/match-fiducial.json -o target/match-fiducial.jpg -Dtemplate=img/bwwb.png
A common problem in vision recognition is locating the crash dummy symbol:
Interestingly, the best template for matching the crash dummy symbol is a rather simple black-white-white-black squares image. What's nice about this template is that it is scale tolerant and will recognize the crash dummy symbol in multiple sizes.