Vision Functions: Use Example

Lets start by using the vision system to make your bot recognize colored cards (and display the color name).
Begin by selecting ‘Vision’ from the CBC top-level display screen. (If using the Link controller, go to      The Link Camera  and follow definitions and directions there. )
For the CBC controller:

– Using the ‘Camera Parameters’ screen & arrows, turn on for a couple seconds (select) the ‘auto exposure’,then turn it off (this sets exposure to your lighting).  Set other parameters to ‘default’
– Using the vision ‘Tracking’ screen, train two channels for the color models ‘pink’ and ‘green’ (or similar colors that are on two cards or other objects),
Now write a program to print “pink card” or “green card” if the card color, in front of the camera, is seen as greater than a minimum and is mostly pink or green respectively.  If card color is not in view print “hold up colored card”.

Hint: One method -use a while “forever” loop to update the color models and select the model color based upon the size of the largest blob greater than 20 (minimum size) of the two color models, using an if branch; else, if neither size is greater than 20 pixels, prompt for a card to view.
If color model training is not good, the program will be unable to identify either color; then go back to Vision-Tracking and re-adjust the two color selection channels.

Here is an example of the C code:

/***************** Vision Excercise#1 - recognizing colored cards ****************
 //assumes color select channel 0 set for 'pink' and channel 1 set for 'green' */
 int main() {
    cbc_display_clear(); // just <display_clear() > under KISS IDE for'Link'
    printf("Card Color Recognition\n");
    while(1){//keep checking the vision frames forever 
          (track_size(0,0)>track_size(1,0))) {printf("pinkcard\n");}
              (track_size(1,0)>track_size(0,0))) {printf("green card\n");}
           else{printf("hold up colored card\n");}
       msleep(150); // wait for display print out
    } //end while

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s