mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
bug hunting
This commit is contained in:
@@ -54,23 +54,28 @@ public class CVProcess {
|
||||
List<MatOfPoint> FilterContours(List<MatOfPoint> InputContours, List<Integer> area, List<Integer> ratio, List<Integer> extent) {
|
||||
for (MatOfPoint Contour : InputContours){
|
||||
try{
|
||||
var contourArea = Imgproc.contourArea(Contour);
|
||||
double targetArea = FastMath.round((contourArea / CamVals.ImageArea) * 100);
|
||||
if (targetArea <= area.get(0) || targetArea >= area.get(1)){
|
||||
var contourArea = Imgproc.contourArea(Contour);//TODO change scaling
|
||||
int targetArea = (int) ((((float) contourArea) / CamVals.ImageArea) * 100);
|
||||
if (targetArea < area.get(0) || targetArea > area.get(1)){
|
||||
continue;
|
||||
}
|
||||
var rect = Imgproc.minAreaRect(new MatOfPoint2f(Contour.toArray()));
|
||||
var targetFullness = (contourArea / rect.size.area()) * 100;
|
||||
if (targetFullness <= extent.get(0) || targetArea >= extent.get(1)){
|
||||
if (targetFullness < extent.get(0) || targetArea > extent.get(1)){
|
||||
continue;
|
||||
}
|
||||
var aspectRatio = rect.size.width / rect.size.height;
|
||||
if (aspectRatio <= ratio.get(0) || aspectRatio >= ratio.get(1)){
|
||||
double aspectRatio = rect.size.width / rect.size.height;//TODO i think aspectRatio is inverted
|
||||
System.out.println(aspectRatio);
|
||||
if (aspectRatio < ratio.get(0) || aspectRatio > ratio.get(1)){
|
||||
continue;
|
||||
}
|
||||
FilteredContours.add(Contour);
|
||||
}
|
||||
catch (Exception ignored) { }
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("Error while filtering contours");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return FilteredContours;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user