Recently I got quite interested in LabVIEW's IMAQ add-on and using it to do various image processing. I decided to start simple and try color recognition first, however none of the examples I found seemed accurate or robust enough so I decided to give it a go myself. In the end my approach looked relatively resistant to errors and noise. I was able to detect red and blue colors successfully in images and ignore unwanted shades.
This example acquires data from a camera device connected to your machine. It then extracts two separate color planes from images grabbed (e.g. Blue and Red) and performs a Logical Diff (NAND) operation on them. This allows to extract only a very specific range of colors that we are interested in. Then a threshold is applied to the 8bit image and it is then cleared from unwanted particles. Once all this is done, the VI extracts remaining particle data and checks whether object of desired size is within camera's field of view. If object of interest is found, a red rectangle is drawn around it.
Steps to Implement or Execute Code
1) Download the vi
2) Make sure you have selected your camera input in the block diagram
3) Select what colour you want to acquire and other relevant settings on the front panel (can also be adjusted while running) 4) Hit run
5) Try tweaking the settings to improve color detection
6) Press the "Reset Default Settings" button on the front panel to reset controls to their default values (can be changed in the block diagram)