![]() |
Tracking Multiple Targets
This year our team was finally able to track shapes with the vision tape. During the build season we were able to track 1 target perfectly, but when we added the other 3 targets the robot freaked out and would track right. It would track the two side targets switching between them. We've looked at the code multiple times and couldn't figure out why it wasn't able to lock onto the center. Would someone be able to look at our code to lead us in the right direction on why we aren't able to track multiple targets at once. Your help is greatly appreciated. Thanks in advance.
This is part of our teleop mode where when you press a button it calls a method to find the targets and tells the Drive Team when its ready to shoot. Code:
else if (stickShooter.getRawButton(2)) { |
Re: Tracking Multiple Targets
Well, first of all, that code doesn't track multiple targets... It only tracks the lowest one. The most important part of the code for this topic is:
Code:
for (int i = 0; i < reports.length; i++) {On a slightly different topic, what are you trying to do with this? Code:
reports[i].imageHeight > minSquareHeight |
Re: Tracking Multiple Targets
Yea. We decided to track the bottom target, but when we added multiple targets the camera would track the left and right targets not knowing what target to lock onto. With reports[i].imageHeight > minSquareHeight we were trying to find where the lowest target was. If I were to change report[i].imageHeight to boundingRectHeight will the camera be able to find the middle of the bottom target. Where would I get the BinaryImage.particleFilter(). I don't see it under the Binary Image class. How does it work and where would I put it in the code.
How would this work? Code:
for (int i = 0; i < reports.length; i++) { |
Re: Tracking Multiple Targets
Would it be better to change all of the reports[i].center to boundingRectHeight
|
Re: Tracking Multiple Targets
To understand boundingBoxHeight and why you want it instead of imageHeight, you have to first understand what the bounding box is.
Now, particles can be any shape whatsoever, but National Instrument's IMAQ library (the library powering the FIRST image processing stuff) only worries about it's bounding rect. The image looks something like this: ![]() The red circle is your particle, the red box is your bounding box, and the black box is your image. imageHeight is the height of the black box, which is always the same because you're getting it from the camera, which is why you should care about boundingBoxHeight instead; it's the height of the red box. To use particleFilter, you need a CriteriaCollection. I don't have the code we used on me, but it would go something like this for a height filter: Code:
CriteriaCollection cc = new CriteriaCollection();You say that you changed the code to work with multiple targets. Can you provide this code? And no, changing center_mass_y to boundingRectHeight would not be helpful. Height is independent of location, and you care about location, so height should not be what you're looking for. |
Re: Tracking Multiple Targets
Ok that makes sense. However the CriteriaCollection and particleFilter class doesn't show up. I've looked through the the NIVision class along with the Binary Image classes and can't find it. I know that CritieriaCollection is part of the image class but when I try to type it in it doesn't show up. I have the most recent API for this year but it doesn't show up. I did see that the NIVision class had many IMAQ methods. Would I use one of them instead of the CriteriaCollection or particleFilter class.
The code that was able to track multiple targets is the same code as below but without the for loop. When ever we added a target it would track the most recent target or the closest one (the one it saw first). |
Re: Tracking Multiple Targets
I was looking around and I did find the CriteriaCollection and particleFilter.
Here is the code below. Do you think this will be able to track the targets. Do you think that I should rearrange anything to make it work better? Thanks again for your help. Code:
//[%Camera] |
Re: Tracking Multiple Targets
I see quite a bit wrong with that code... so I'll break it down one piece at a time:
So in short, no, I don't think it can track multiple targets. It's a step in the right direction, but you definitely made some mistakes. |
Re: Tracking Multiple Targets
Ok I think I fixed the code. So the code will declare the binary images and such. Then add values for the rectangles. After that it will try to get a color image from the camera and set the binary image to the image that the camera got and look for the color specified. It will then fill in the boxes and remove the small boxes. After that it will filter the particles based on the criteria collection and then order the 4 biggest particles in size (i think smallest to biggest). Then if reports is bigger than 0 it will go through and find the lowest square on the y axis (bottom target). Then it'll find the center of that target. Does that seem about right? If I were to take out the for loop. would it then be able to track all 4 targets because I would then not be restricting it to just look at the bottom half of the image.
Code:
|
Re: Tracking Multiple Targets
You still have not caught the memory leak created by removeSmallObjects(), or freed filteredImage. Also, be careful about using NIVision, because BinaryImage hides certain functionality from you, and using NIVision along with BinaryImage can mess up particle counting. Until you have a working product and you know it's too slow, I'd recommend against using NIVision's methods directly.
Removing the for loop would not allow multiple target tracking on its own. However, if you make it go through each particle, and output the data for all of them, then it would be tracking multiple targets. |
Re: Tracking Multiple Targets
Sorry but I don't understand how I haven't caught the memory leak created by removeSmallObjects(), or freed filteredImage. Isn't when you free the images you remove the memory for more pictures?
|
Re: Tracking Multiple Targets
Here is updated code. I changed the way I used NIVision methods. I believe I freed all the images that I needed to. I haven't changed it to look at all the particles yet.
Code:
//[%Camera] |
Re: Tracking Multiple Targets
It looks like it should work ;) If you have any other issues, just ask!
|
Re: Tracking Multiple Targets
Ok thanks for all your help. Greatly appreciated. :)
|
Re: Tracking Multiple Targets
We tested the code to see if the robot will track and it froze and we got robot drive not outputed often enought? We had the same code as a few posts ago. Do you think it could be caught in the if statement somewhere?
|
| All times are GMT -5. The time now is 12:46. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi