Log in

View Full Version : Finding green/pink flags


ellisk
04-01-2009, 16:28
Hi everyone,

I am trying to use the Axis Camera to locate green and pink flags. However, it fails when actually finding the colors. Here's the relevant portion of my code so far:


int i = StartCameraTask();
StartImageAcquisition();


while (IsOperatorControl())
{
double timestamp;
Image *img = frcCreateImage(IMAQ_IMAGE_HSL);
int getImage = GetImage(img,&timestamp);

TrackingThreshold tdata = GetTrackingData(GREEN, PASSIVE_LIGHT);
ParticleAnalysisReport par;

int findcolor = FindColor(IMAQ_HSL, &tdata.hue, &tdata.saturation,&tdata.luminance, &par);

}

StopImageAcquisition();
StopCameraTask();


I find the values of par, tdata, getImage, and findcolor using the debugger. It succeeds up to the call to FindColor. I am using the stock green flag. I've tried positioning it differently in front of the camera, but it still doesn't recognize it!

I've tried it with PINK as well with the pink flag, and I've tried changing PASSIVE_LIGHT to FLORESCENT (neither work).

Has anyone had any success with getting the camera to recognize the flags/know what I'm doing wrong?

Thanks,
Kevin

nickmagus
04-01-2009, 21:22
I have had the same problem. I also tried.
if (StartCameraTask(10, 0, k160x120, ROT_0) == -1){
printf("Failed to spawn camera task: %s\n",GetVisionErrorText(GetLastVisionError()));
}

// Set up camera tracking parameters.
tdata = GetTrackingData(GREEN, PASSIVE_LIGHT);
tdata.hue.minValue = 67;
tdata.hue.maxValue = 114;
tdata.saturation.minValue = 161;
tdata.saturation.maxValue = 255;
tdata.luminance.minValue = 24;
tdata.luminance.maxValue = 101;
in the init with
ParticleAnalysisReport par;
if (FindColor(IMAQ_HSL, &tdata.hue, &tdata.saturation, &tdata.luminance, &par)
&& par.particleToImagePercent < MAX_PARTICLE_TO_IMAGE_PERCENT
&& par.particleToImagePercent > MIN_PARTICLE_TO_IMAGE_PERCENT) {
int lightX = (int)(par.center_mass_x_normalized * 1000.0);
int lightY = (int)(par.center_mass_y_normalized * 1000.0);
printf("Light found: x: %i y: %i\n", lightX, lightY);
} else {
if (err)
printf("Failed to spawn camera task: %s\n", GetVisionErrorText(GetLastVisionError()));
else
printf("light not found\n");
}
in the main loop but that didn't work either

Kingofl337
04-01-2009, 21:25
Try this,
1. Log into the camera
2. Goto Advanced Settings and set White Balance to Hold
3. Goto Settings and turn down the brightness 20% of what it's set too
4. Goto Live video settings and take a screen shot (Alt + Print Screen)
5. Open MSPaint and Paste in the Picture, save as a JPG
6. Open Labview Vision Assistant, Open the file, and
7. Select Color, then Color Threshold, and then Color Model:HSL
8. Play with the Hue, Sat, Lum levels until most of the target is high lighted red
9. Set the new levels by updating tdata parameters, here is the list, these worked for me. You only need to set the values you changed in Vision Assistant.
//tdata.hue.minValue = 60;
//tdata.hue.maxValue = 80;
//tdata.saturation.minValue = 34;
//tdata.saturation.maxValue = 200;
//tdata.luminance.minValue = 128;
//tdata.luminance.maxValue = 240;


Edit: Also, it's a really good idea to start with the simple tracker demo 100% unmodified. Then you can tell if it's you or the camera values.

fordchrist675
05-01-2009, 11:45
My friends and I are trying to get the Axis Camera to find the green/pink flags, but we are having a problem getting the camera to recognize anything and it didn't say it failed to recognize the camera, so what could help make it work?

The camera is just not working all together, but it is connected and on so we are in a jam. any Ideas?

Kingofl337
05-01-2009, 12:46
Did you run the Camera Configuration Utility? Are you using the orange CAT-5 cable? Are you using the example? Does it work connected to your PC?

BradAMiller
05-01-2009, 14:37
There will be example code posted soon that will do the detection of the two color targets. The code will be able to differentiate between the red and blue alliances.

fordchrist675
05-01-2009, 17:22
Alright thanks very much for the help

fordchrist675
05-01-2009, 17:42
Actually it is still not working we used the CAT-5 and still are getting no feedback.

So the programmer and I are at a loss. also the utility isn't working so any ideas what to do?

DanDon
05-01-2009, 19:22
Hey all-

I'm running WindRiver, and I'm running the SimpleTracker example code. I've used the NI Vision Assistant to get color values for my green vision target, and put those into the WindRiver code.

tdata = GetTrackingData(GREEN, FLUORESCENT);
tdata.luminance.maxValue = 187;
tdata.luminance.minValue = 103;
tdata.hue.minValue = 71;
tdata.hue.maxValue = 98;
tdata.saturation.minValue = 56;
tdata.saturation.maxValue = 111;

I'm getting terminal feedback from the CRIO (finally...but that's another story), but the camera is failing to find any blobs matching the numbers that were obtained using the Vision Assistant.

Help, please?

nickmagus
05-01-2009, 19:59
the simple tracker demo 100% unmodified did not find anything...

David Doerr
05-01-2009, 20:05
the simple tracker demo 100% unmodified did not find anything...

There are bugs in the current versions of FindColor, GetLargestParticle and InArea. These have been fixed at the beta level and should be published shortly along with the pink-green demo that Brad mentioned above.

Dave D

nickmagus
06-01-2009, 11:05
Oh ok that's good to know. Thanks. Any ideas as to when the code with those functions fixed will be posted. I looked through the functions but couldn't find the error (though I didn't spend that much time since you said its already fixed). The sooner its up the better. On that note I just wanna thank all the people who wrote and are writing this library (it makes all our lives much easier).

Bongle
10-01-2009, 12:58
There are bugs in the current versions of FindColor, GetLargestParticle and InArea. These have been fixed at the beta level and should be published shortly along with the pink-green demo that Brad mentioned above.

Dave D

(not directly to dave D)
If you're a team that simply can't wait, you can look at GetLargestParticle and FindColor in TrackApi.cpp. Notice that GetLargestParticle never actually returns the largest particle index to the 2nd parameter. The code to return isn't there, and in the 2nd line of the function it actually blows away the pointer value so it becomes impossible to return the largest particle index. Since it's probably not a good idea to go fiddling with the supplied code unless you know what you're doing, I'll leave it as an exercise to the reader to figure out what to do.

Further, in the full-size version of FindColor, its check for success is incorrect. Rather than "if(largestParticleIndex == 0), it seems that it should be if(largestParticleIndex >= 0) in case the largest particle is not the first one.

virtuald
10-01-2009, 18:23
There are bugs in the current versions of FindColor, GetLargestParticle and InArea. These have been fixed at the beta level and should be published shortly along with the pink-green demo that Brad mentioned above.

Dave D

Shortly, eh? :)

Uberbots
10-01-2009, 18:42
I helped team 1124 make the red/blue target tracker with great success (double thumbs up).

in labview, you basically copy the image from the camera, do a color threshold for each picture, do a particle report for each picture, and decide which one of those reports is the "top" color and which is the "bottom" color.

once you have that data, you run a loop as follows:
for each "top color:
check if the area of the color is big enough. if so:
for each "bottom" color:
check if the bottom color is directly below (with some tolerance) the "top" color.
add the "top" target to the output targets array

that basic algorithm allowed us to differentiate between red/green targets and green/red targets. there was a slight bit of extra post-processing to deal with multiple visible targets (basically you pick the uppermost one or the largest one etc).

what you do with the final target(s) is up to you... we cached the previous target position and velocity to do second-degree motion prediction for the target in case we lose it. (amongst other things)

The yellowdart
11-01-2009, 16:07
Have you updated all the firmware? Are you using all the most current software?

Chris1228
13-01-2009, 16:10
can someone help me program the camera to track colors in labview? i can get it to recognize a color but i dont know how to get motors/servos to move when it sees a color

wt200999
13-01-2009, 20:51
It appears as though an update on this matter has been posted (an example) :yikes:

http://first.wpi.edu/FRC/frcupdates.html

fordchrist675
18-01-2009, 18:14
Our programming team has tried all of the listed ideas, and still have had no luck, so we really need some help. Any suggestions please

Greg McKaskle
18-01-2009, 18:22
If you really want help, can you break it down? What works, what doesn't, what have you tried, what environment are you using?

My first suggestion would be to try running and learning from one of the vision examples.

Greg McKaskle

fordchrist675
18-01-2009, 19:11
We have set up the camera correctly, with the CAT-5 cable. We debugged the code, tried it with the bug , updated all firmware and software and gotten nothing. The CRIO is still getting nothing from the camera

fordchrist675
18-01-2009, 19:12
The CRIO kept posting error messages

Greg McKaskle
18-01-2009, 21:51
Make sure you are using the orange cross over cable. What are do the error messages.

Greg McKaskle

gokul
19-01-2009, 08:20
The CRIO kept posting error messages

It will help if we know what these error messages are.

1. Use the Orange Crossover cable with the camera.
2. Make sure the camera is set correctly (Brightness = 40, Light settings = Flourescent 1) using the Axis instructions after connecting the Cam to your PC. Make sure you hit "Save" after the changes to the cam.
3. Make sure that the Green/Pink is the right way up as the program expects it - in the program (C/C++) there is a setting for ABOVE and BELOW. If the colors are reversed to what the program expects it won't find it.
4. Make sure that the cam is receiving signal by watching for the Green light around the lens.
5. Make sure your target is not too close or too bright.
6. For the C/C++ code, teams will have to play around a bit with cam settings and HSL values to make sure everything works.
7. The C/C++ code is based on SimpleRobot so once it is out of Autonomous, it won't go back to Auto even if you flip the DS Auto/Tele Switch - you will have reboot the cRIO with the Autonomous enabled on the DS.

aerophd2001
06-02-2009, 20:04
One thing that may solve many peoples problems:

>> Test the two-color tracking routines in a room WITHOUT windows <<

Daylight coming in from outside *can* change the color of the targets from the camera's perspective. You will want to test in a room with only fluorescent lighting.

Additionally, you will want to have equal lighting on the target from all directions (no shadows around the periphery of the target).

I hope these tips help.