Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Taking a photo with USB webcam and comparing with more than one template

Solved!
Go to solution

Hello everybody,

 

I'm currently working (starting now, actually) on a project that needs to do the following:

 

- Take one photo from a USB webcam;

- Compare with 6 differents templates (I attached two of them to show the complexity of the images);

- Show in an indicator which of the templates the photo matches.

 

The photos are taken with a steady tripod and in a closed area, so I believe the resulting snapshot would be pretty similar to one of the templates.

 

I have vision module with me, but I've never used it before and I'm having a hard time. Tried to use the "Golden Template" example, but did not succed. 

 

May anybody enlighten me with some tips or a general architecture that I can use?

 

PS: If you know any material (youtube videos or even some written guides), please share with me. Unfortunatelly I don't have the condition do to the full course from National, so I'll try to learn by myself.

 

 

Download All
0 Kudos
Message 1 of 9
(4,274 Views)

Hi,

 

that's probably not really an issue for template matching.. it is a matter of measuring if a light is on or off.
I will assume that the position of the lights are always the same (camera + object are steady). If not, we have to add another step.

 

You can break your problem into two steps:

1) Continously acquiring images. Use Vision Acquisition Express with continous acquisition for that. Just let it create a loop.


2) Processing the image.
Directly inside the loop, you have to process the image.

- First, I would turn the image into a grayscale image, because grayscale is easier to process. You can use IMAQ ExtractSingleColorPlane for this. You have a choice between a few planes, I would probably choose the saturation plane, because you see a big difference between on/off.

saturation.png

Then I would use IMAQ LightMeter to check if the lights are on or off:
In the following example, you can see how LightMeter is used with 2 regions to detect if a LED is on or off. lightmeter.png

 

You should be able to extend this example to 6 LEDs by defining 6 areas which signify the lights.
Now check which LED has the highest mean intensity.. and don't forget that there could be a case where there are no lights on!

 

Good luck,
Birgit

 

0 Kudos
Message 2 of 9
(4,242 Views)

Birgit,

 

Thank you for your answer. Really appreciate it.

 

Your assumption was correct. Camera and object are steady.

 

I'll try to do these steps this week and as soon as I've done it, I'll post here for future references.

 

Thanks again.

 

By the way, where can I find the rest of this lightmeter example? Is it exclusively from the machine vision books?

 

 

0 Kudos
Message 3 of 9
(4,234 Views)

Hi,

glad this helps. 
The example is from a textbook that will be published in a few weeks - written by me 😉
Cheers

Birgit

0 Kudos
Message 4 of 9
(4,230 Views)

Hello one more time, Birgit.

 

Here's a screenshot of my current interface.

 

ShowBirgit.png

 

 

It worked quite well (when I change states at my washing machine, the respective LED lights up), but there's a minor inconvenience. Because of my webcam's frame rate, it captures the LED blinking.

 

Can you suggest a way to make my indicators stay high?

 

Here's my main VI:

Main.png

  

 

And this guy is a little subvi to shorten my code:

 

SubVI.png

Thanks in advance!

(Sorry about the comments. I'm brazilian and my company requires to make all documentation in portuguese).

0 Kudos
Message 5 of 9
(4,217 Views)

Another approach would be to use threshold then particle analysis to extract the blob where the light is. The y coordinate of the blob will tell you which label the light is in front of.

 

Christophe

 

0 Kudos
Message 6 of 9
(4,212 Views)

See attached example of what I described in my previous post.

0 Kudos
Message 7 of 9
(4,211 Views)
Solution
Accepted by andrefcbruni

Hi,

 

well.. technically you could use IMAQ Compute Average to just average like 5 images.


However, I would not average the input.. because that would require a more sophisticated software architecture... memory management. I would keep a running average of results. Which means converting the boolean to a decimal number with Boolean To (0,1) and then feed that to Mean PtByPt (with a sample length of 5 or 10 or so). And compare the result of this with Greater? 0.5 or 0.7 or so to turn it back into a boolean. The real values of the constants depends on the framerate versus blinking rate.

 

Cheers,
Birgit

Message 8 of 9
(4,201 Views)

Hello everybody.

 

Christophe, thank you for posting your VI. I understood the concept but decided to go with Birgit's call.

 

It is working fine now. Front panel is showing the leds exactly how I want them to. The solution was to make this "filter" Birgit suggested and to rearrange the size of the rectangles I had on IMAQ LightMeter, focusing on the region that had more light.

 

Here's the front panel and block diagram for anyone who may need it.

 

Front panel.Front panel.

 Block diagram.Block diagram.

 

 Thank you both for your help! Much appreciated.

 

PS: Birgit, don't forget to send me a link after that textbook is published, k? :3

 

 

0 Kudos
Message 9 of 9
(4,191 Views)