How To: Match a Part from a Camera Image
End-to-end walkthrough, from a running camera to a match result, using the module the application creates for you on installation.
Before you start
-
LumiScan Cam Driver, or another image source, is running on the same ctrlX CORE and has captured an image.
-
You know the address of its image node. For camera 1 of the cam driver:
hdvisionsystems/lumiscan-cam-driver/camera1/output/image
Throughout, paths are relative to:
hdvisionsystems/lumiscan-template-finder/module-1/
Step 1 - Point both operations at the camera
Set the image address on both operations:
create-template/input/input-image-address = hdvisionsystems/lumiscan-cam-driver/camera1/output/image find-template/input/input-image-address = hdvisionsystems/lumiscan-cam-driver/camera1/output/image
They are separate nodes on purpose - a template can be cut from one camera and searched for in another.
Step 2 - Capture an image with the part in view
Trigger a capture in the camera application, with the part positioned as it will be in production. The template is cut from this image, so its lighting and working distance become the reference.
Step 3 - Cut the template
Find the pixel coordinates of a region containing the part. The camera application’s image preview is the easiest way to read them off.
Then:
create-template/input/crop/startX = 100 create-template/input/crop/startY = 200 create-template/input/crop/width = 190 create-template/input/crop/height = 100 create-template/input/template-name = screw
Write to create-template/execute, then read create-template/output/status-code.
1 means it worked, and create-template/output/template-path now reads templates/screw.png.
If you get -5, the region does not fit the image; output/status-text names the actual image size.
Step 4 - Verify against the same image
Before changing anything, search the image you just cut from:
find-template/input/template-name = screw
Write to find-template/execute and read find-template/output/result.
You should get exactly one match, its oriented_bounding_box centred at the middle of the region
you specified - (195, 250) for the values above - with a confidence close to 1.
|
This check is worth the half minute it takes. If the template is not found in the very image it came from, the problem is the region or the image address, and no amount of parameter tuning will fix it. |
Step 5 - Search a real image
Capture a new image with the part in a different position and search again. The match should follow the part.
If nothing is found, the part has probably changed size or orientation relative to the template. Go to step 6.
Step 6 - Widen the search, if needed
Only if step 5 failed:
The part rotates. Set a rotation range with a coarse step:
find-template/input/rotation/max-rot = 360 find-template/input/rotation/step-rot = 5
The part changes distance. Set a scale range:
find-template/input/scale/min-scale = 0.9 find-template/input/scale/max-scale = 1.1 find-template/input/scale/step-scale = 0.05
Each combination is a separate pass over the image, so both settings together are 72 x 5 = 360 passes. Widen one at a time and stop as soon as the part is found reliably.
If widening the range starts producing matches in the wrong places, raise the threshold:
find-template/input/match-thresh = 0.95
The reason is explained in Tuning the Search.