Log in

View Full Version : Vision Processing


cogbrained3244
16-03-2014, 23:41
So my team has been trying to take advantage of our camera for autonomous. We've been using some code from 3313, as seen here (http://www.youtube.com/watch?v=AkEdmYjPEOU), to do the processing. Afterwards the for loop is supposed to print out the area of each particle. The number of particles is inconsistent-I may get many, or I may get none. Any extra green in the scene is sure to throw off the number of particles returned. I also had to set up the code to catch an ArrayIndexOutOfBounds exception, which the for loop seems to be causing. I've tried changing the thresholds for RGB- it doesn't seem to help. I can't get the code posted right now, but does anyone have any tips on improving the consistency of our detection?

wolfspell12
17-03-2014, 19:13
Code used by 3244, much of which is origionally from 3313 :
private boolean isGoalHot() {
boolean morePoints;
ColorImage image = null;
BinaryImage thresholdImage = null;
BinaryImage bigObjects = null;
BinaryImage convexHullImage = null;
BinaryImage filteredImage = null;
try {
image = camera.getImage();
thresholdImage = image.thresholdRGB(100, 200, 200, 255, 150, 200);//0, 45, 20, 255, 0, 47
bigObjects = thresholdImage.removeSmallObjects(false, 2);
convexHullImage = bigObjects.convexHull(false);
filteredImage = convexHullImage.particleFilter(data);
ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports();
for (int i = 0; i < reports.length + 1; i++)
{
String stuff;
stuff = "Area " + i + " is " + reports[i].particleArea;
System.out.println(stuff);
log(stuff);
iterations = i;
}
// for (int i = 0; i< reports.length + 1;, i++;) {
// System.out.println(reports[i].center_mass_y);
// double reflectiveTapeArea = 350;
// if(reports[i].particleArea >= reflectiveTapeArea){
// reflectiveTapeCount++;
// }
// if(reflectiveTapeCount >= 2){
// runAuto = true;
// break;
// }
// }


} catch (AxisCameraException axis) {

} catch (NIVisionException ni) {
} catch (ArrayIndexOutOfBoundsException ex){
System.out.println("Array index went out of bounds.");
System.out.println(" " + iterations + "iterations of for loop.");
iterations = 0;
}

finally {
}
try {
filteredImage.free();
convexHullImage.free();
bigObjects.free();
thresholdImage.free();
image.free();
} catch (NIVisionException ni) {
}
return runAuto;

}


To be clear, we've tried tweaking the values for the threshold from what 3313 had. We are currently dealing with particle areas, and our goal with the commented part is to count how many particles meet a minimum area, and if there are more than two, return a value to start the autonomous. But until we can get consistency, then we don't want to do that.

cogbrained3244
21-03-2014, 00:03
We did find one of our problems: "reports.length +1" should drop the adding one-it knocks the array out of bounds. Thanks to a programming mentor for pointing that out-we'll test it tomorrow to be sure.

There's still the issue of why particle 1 in the array is not being returned. I'm wondering if it passes under the minimum area of CriteriaCollection data, which is declared outside of the method, and happens to be set to 150. That's another thing to test tomorrow. If someone could give us some feedback on this, it would still be helpful.