image = camera.getImage();
} catch (AxisCameraException ex) {
} catch (NIVisionException ex) {
}
BinaryImage thresholdImage = image.thresholdHSL(0, 255, 0, 31, 229, 255); // keep only red objects
BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 2); // remove small artifacts
BinaryImage convexHullImage = bigObjectsImage.convexHull(false); // fill in occluded rectangles
BinaryImage filteredImage = convexHullImage.particleFilter(cc); // find filled in rectangles
ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports(); // get list of results
if(reports[1] != null) {
ParticleAnalysisReport r = reports[1];
System.out.println("x: " + r.center_mass_x_normalized + " y: " + r.center_mass_y_normalized);
System.out.println(r.boundingRectHeight + " " + r.boundingRectWidth);
distance = (9/tan23) * 240/r.boundingRectHeight;
System.out.println("Distance: " + distance);
SmartDashboard.putDouble("Distance", distance);
array[0] = distance;
offset = (46 * (160 - r.center_mass_x)) / 320;
System.out.println("Offset: " + offset);
SmartDashboard.putDouble("Offset", offset);
array[1] = offset;
}
System.out.println(filteredImage.getNumberParticles() + " " + Timer.getFPGATimestamp());
filteredImage.free();
convexHullImage.free();
bigObjectsImage.free();
thresholdImage.free();
image.free();