Trying to match color template with cv::ximgproc::colorMatchTemplate()

asked 2020-03-23 04:56:56 -0600

micmac gravatar image

updated 2020-03-23 05:01:58 -0600

I'm trying to use colorMatchTemplate from L. Berger, in order to find a template that is a color stripe from a resistor (electronic component) inside a picture of the whole resistor.

The resistor: image description

The template: image description

When I tried the colorMatchTemplate method on a simple example (finding a red circle template inside a bigger image with dark background) it worked well (the max quarternion image displayed white pixel where the circle template has been located), but for some reason it does not work well with my resistor stripe template (no white pixel at the right location on the max quarternion image).

I have these results with the official example of colorMatchTemplate included in opencv 4.2.0

Also, the template should be found, because I extracted it from the original resistor image. So that's an exact match.

Any idea on how to make this algorithm work please ?

I read somewhere that I need to have pictures with even number of cols, so I did that, but the results are incorrect (template not located correctly).

edit retag flag offensive close merge delete

Comments

1

What is the result with image and template?

LBerger gravatar imageLBerger ( 2020-03-23 05:28:41 -0600 )edit

But how do we get template image? You wanted to read 10K ohms?

supra56 gravatar imagesupra56 ( 2020-03-23 07:52:47 -0600 )edit
1

@LBerger, here is the result when I launch the opencv example with this image and template, and set the level at 94:

link text

So when I set the level right (94 here), it seems there is a max approximately at the same height as the brown stripe I'm looking for. But it's not very precise (the exact template was extracted in the middle of the image, but the max seem to be detected elsewhere). Also there are erroneous detections at the top and bottom of max quaternion image.

@supra56:I gave the template in my original post. I'm trying to find the color stripes (more precisely, I'm trying to find the area where the color changes between the body of the resistor and the individual stripes (here the brown one))..

micmac gravatar imagemicmac ( 2020-03-23 09:54:37 -0600 )edit