The Color Recognition algorithm determines if the color within region of interest matches the color in predefined template images. The transform returns an enumerated value for the closest matched color. Color Recognition configuration steps are similar to the Pattern Recognition configuration.  To begin you need to acquire an image for every different state that signal can obtain (for example, if desired signal can be green, yellow, or red, capture 3 images that show the different states.)

To set up Color Recognition, create a full image for every different state that needs to be recognized. Create a new directory for every signal under the RecoImages folder in the project folder. Place the full images in the "Full_Image" folder and follow these steps:

1.Make sure the Camera transform is set up.

2.In MxTransIt, add the Image Recognition transform by selecting it from the Toolbox.

3.Configure transform properties: Change the transform name from the default name to the signal name you would like to see in the MxVDev test case. This is the signal name that is added to the signal dictionary.

4.Under Image Recognition Properties, set the Image Recognition Mode is set to Color Recognition.

5.Also in properties, set the Base Directory Path. The name of the folder should be the name of the signal.

6.Click the 3dots_button button in Configure Image Recognition to bring up the configuration form for this signal.

7.The first page of the configuration form shows images found in the Full_Image directory under the Base Directory for this signal. If no images are shown, click cancel and make sure that the directory points to the right Base Directory and that the Full_Image folder contains your full images.

8.Select the desired Full Image from the list box on the left and draw a rectangle for the ROI around the pattern to be used for Pattern Recognition. Alternatively, you can input the ROI pixel coordinates manually into the fields on the right. For Color Recognition, the ROI should be about the size of the region that changes color. Using the toolbar under the image, you can Zoom In, Zoom Out, and Pan the Image. The Rectangle ROI tool is used to draw or modify the ROI rectangle on the image. You can move the rectangle by clicking in the middle, or drag bounding lines or corners.

Set Region of Interest.  Click to expand.

Set Region of Interest.  Click to expand.

 

9.After the ROI is selected, create a Sample image by clicking the Add button. A sample image is a version of the full image cropped to the selected ROI. Sample images are used for testing the search algorithm and Pattern creation. You can add a couple different Samples or click 'Add All' to create a Sample image out of all full images (useful for multi-state signals).
 
Note: Do not click OK. Proceed to the next step.

10.Click the Create Pattern tab to show the just created sample images. Click the Add' button to create a pattern image. Click 'Add All' only if you want to create a pattern image for all sample images (in the case where each sample image shows a different state of the multi-state signal; otherwise if the signal can have only 3 values, create only 3 pattern images).

 

Create pattern.  Click to expand.

Create pattern.  Click to expand.

 

11.Select the Test Pattern Match tab to test the recognition algorithm. Change search options or use the default values and click the Run Test button. Color recognition works by comparing all pixel values in a sample image to all pixel values in the pattern image; only color information is compared. Check the Match Color and Pattern box if the pattern shape needs to be matched as well as color. Results of the test run are shown. The score indicates how closely the template image (pattern image) matches the image tested (sample image). For multi-state signals, click next/previous buttons to test all patterns. The highest match score determines which value is passed to the test case after the algorithm is executed.

Test Pattern Match.  Click to expand.

Test Pattern Match.  Click to expand.

 

12.Select the Signal Port Properties tab to specify what values are returned during the test. The Enumeration set up during this step is passed to the signal dictionary. If the pattern is not found in the image ROI, it returns default value 0. Click on the Cell for Enum ID or Enum Name to modify the values to be returned during the test. (In the example below, the signal returns 1 if the pattern is white, 2 if the pattern is red, and 0 if not found or if color does not match the two specified within the allowed minimum match score.)

Signal Port Properties.  Click to expand.

Signal Port Properties.  Click to expand.

 

13.Click OK when done. Now you can export transform ports and connect the SourceImage port to the SourceImage port on the camera transform.

BasicPatternXform

Related Topics:

Recognition Modes

Camera Transform

Image Recognition Overview

Working with Enums