V5 Vision Sensor Color Code Coordinate Tracking

So I was working on an auto aiming system using the V5 Vision Sensor, and was trying to use the color codes to detect flags and track them using their x position. I set up the color codes for the flags correctly, and the sensor could detect them consistently, and display its x coordinate. However, when I used the command for


Vision.takeSnapshot(REDFLAG, 2)

(RED FLAG is the name for the color code and I was trying to track two objects) and


Vision.objects[0].centerX


Vision.objects[1].centerX

to track two objects, it would not return the coordinates for the two. Is there something critical that I’m doing wrong with the commands? I would be happy to post the code if anyone would like to see it.

If someone who knows how to work the color code system can help that would be awesome.

Try printing vision.objectCount . From my experience with using color codes, it’s not gonna be what you want. Most likely 0, occasionally jumping to 1 or 2 for no reason whatsoever, but at intervals so far apart it’s useless for your code. Unfortunately the only workaround I could find was using signitures instead of color codes. I suppose you could write some code to look for the second signature, and see if it’s nearby the other one, but I don’t think it’s worth the hassle. I’m wondering if anyone has managed to successfully use color codes, they seem really simple in theory, and they work in the Vision Utility, but never in my code, and I’m not sure if there’s a problem with the vision API or if there’s a problem with my code. With basic signitures, I had no problems with my code.

Thanks for the response. I’m working on a code that will track multiple different signatures. I’ve tried using normal signatures for the tracking using the same commands and it works well. the biggest issue with that though is that it will track background objects that are blue red or green, which is annoying.

I had similar experiences as you. I tried for about a month with color codes, and I assumed my code was faulty and gave up on the vision sensor for awhile as nothing worked. It turns out, it just wasn’t working with color codes. It’s a shame color codes don’t seem to work properly, as being able to look for objects that are composed of two signitures next to each other would be great in the game, especially for differentiating flags from background noise.

@jpearman, do you know if the API for color codes with 2 signitures work properly in VCS, or are there any coding tricks you need to get them to function properly?

Could you post the code

I don’t have my competition vision code on me, however a simple demonstration for my non functional color-code code can be recreated fairly easily. General flow →

  1. Save 2 signitures in vision utility
    2 Create color code, name it, use SIG_1 , SIG_2 under field for signitures
  2. Under main, create loop, inside loop call Vision.takeSnapshot(color_code_name_here); and then print Vision.objectCount on the screen.

You would expect it to be the same as the number of color code objects tracked in the vision utility (3 if your camera is aligned to see all three flags), but instead it just shows 0, occasionally 1 or 2.