diff --git a/chameleon-server/src/main/java/com/chameleonvision/vision/pipeline/pipes/SolvePNPPipe.java b/chameleon-server/src/main/java/com/chameleonvision/vision/pipeline/pipes/SolvePNPPipe.java index 110e885e1..fd4d301bb 100644 --- a/chameleon-server/src/main/java/com/chameleonvision/vision/pipeline/pipes/SolvePNPPipe.java +++ b/chameleon-server/src/main/java/com/chameleonvision/vision/pipeline/pipes/SolvePNPPipe.java @@ -160,23 +160,25 @@ public class SolvePNPPipe implements Pipe distanceProvider = Comparator.comparingDouble((Point point) -> FastMath.sqrt(FastMath.pow(centroid.x - point.x, 2) + FastMath.pow(centroid.y - point.y, 2))); - var contour = target.rawContour; - var convex = tempInt; - tempMatOfPoint.fromList(contour.toList()); - Imgproc.convexHull(tempMatOfPoint, convex); - var combinedList = contour.toList(); + // algorithm from team 4915 - // approx poly dp time + // Contour perimiter + var peri = Imgproc.arcLength(target.rawContour, true); + // approximating a shape around the contours + // Can be tuned to allow/disallow hulls + // Approx is the number of verticies + // Ramer–Douglas–Peucker algorithm + Imgproc.approxPolyDP(target.rawContour, polyOutput, 0.01 * peri, true); - Point[] contourArray = contour.toArray(); - Point[] hullPoints = new Point[convex.rows()]; - List hullContourIdxList = convex.toList(); - for (int i = 0; i < hullContourIdxList.size(); i++) { - hullPoints[i] = contourArray[hullContourIdxList.get(i)]; + if(polyOutput.toList().size() != 8) { + return null; } - tempMat2f.fromArray(hullPoints); - Imgproc.approxPolyDP(tempMat2f, polyOutput, 5, true); + var area = Imgproc.moments(polyOutput); + + if (area.get_m00() < 200) { + return null; + } var polyList = polyOutput.toList(); @@ -420,14 +422,14 @@ public class SolvePNPPipe implements Pipe