Create speckle rejection code and add to VisionProcess

Isn't yet added to the GUI
This commit is contained in:
Matt M
2019-10-23 21:39:47 +00:00
committed by ori agranat
parent 12c409b953
commit 910d377440
14 changed files with 37 additions and 124 deletions

View File

@@ -24,6 +24,7 @@ public class CVProcess {
private Mat binaryMat = new Mat();
private List<MatOfPoint> filteredContours = new ArrayList<>();
private Comparator<RotatedRect> sortByCentermostComparator = Comparator.comparingDouble(this::calcDistance);
private List<MatOfPoint> speckleRejectedContours = new ArrayList<>();
private Comparator<MatOfPoint> sortByMomentsX = Comparator.comparingDouble(this::calcMomentsX);
private List<RotatedRect> finalCountours = new ArrayList<>();
private MatOfPoint2f intersectMatA = new MatOfPoint2f();
@@ -86,6 +87,20 @@ public class CVProcess {
return filteredContours;
}
List<MatOfPoint> rejectSpeckles(List<MatOfPoint> inputContours, Double minimumPercentOfAverage) {
double averageArea = 0.0;
for(MatOfPoint c : inputContours) {
averageArea += Imgproc.contourArea(c);
}
averageArea /= inputContours.size();
var minimumAllowableArea = minimumPercentOfAverage / 100.0 * averageArea;
speckleRejectedContours.clear();
for(MatOfPoint c : inputContours) {
if(Imgproc.contourArea(c) >= minimumAllowableArea) speckleRejectedContours.add(c);
}
return speckleRejectedContours;
}
private double calcDistance(RotatedRect rect) {
return FastMath.sqrt(FastMath.pow(cameraValues.CenterX - rect.center.x, 2) + FastMath.pow(cameraValues.CenterY - rect.center.y, 2));
}

View File

@@ -2,6 +2,7 @@ package com.chameleonvision.vision.process;
import org.opencv.core.RotatedRect;
@SuppressWarnings("WeakerAccess")
public class PipelineResult {
public boolean IsValid = false;
public double CalibratedX = 0.0;