// Assumes that the points are ordered going around the quadrilateral private static double areaOfQuad(List<Point2D_F64> quad) { double area1 = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.area( quad.get(0), quad.get(2), quad.get(1)); double area2 = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.area( quad.get(0), quad.get(2), quad.get(3)); return area1 + area2; }
public static boolean isCardShaped(List<Point2D_I32> contour) { // turn it into a quad List<Point2D_F64> f64Contour = new ArrayList<Point2D_F64>(); for (Point2D_I32 point : contour) { f64Contour.add(new Point2D_F64(point.x, point.y)); } List<Point2D_F64> quad; try { quad = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.findCorners(f64Contour); } catch (Exception e) { System.out.println("finding corners of bounding quadrilateral failed"); return false; } Double ratio = aspectRatio(quad); if (ratio == null) { return false; } if (Math.min(ratio, TARGET_ASPECT_RATIO) / Math.max(ratio, TARGET_ASPECT_RATIO) < ASPECT_RATIO_TOLERANCE) { return true; } return false; }
public static int areaOfRegion(List<Point2D_F64> list) { List<Point2D_F64> quad; try { quad = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.findCorners(list); } catch (Exception e) { System.out.println("finding corners of bounding quadrilateral failed"); return -1; } double triangleArea0 = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.area( quad.get(0), quad.get(1), quad.get(2)); double triangleArea1 = boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.area( quad.get(0), quad.get(3), quad.get(2)); return (int) Math.round(triangleArea1 + triangleArea0); }
// convert a blob image into quadrilaterals bounding each of the blobs public static List<List<Point2D_F64>> quadsFromBlobs(ImageSInt32 blobImage, int numBlobs) { @SuppressWarnings("unchecked") List<List<Point2D_F64>> points = new ArrayList(); for (int i = 1; i < numBlobs; i++) { // TODO: make fast ArrayList<Point2D_F64> inClass = new ArrayList<Point2D_F64>(); for (int x = 0; x < blobImage.getWidth(); x++) { for (int y = 0; y < blobImage.getHeight(); y++) { if (blobImage.get(x, y) == i) { inClass.add(new Point2D_F64(x, y)); } } } // Transform blobs into quadrilaterals, ignoring blobs of very small size if (inClass.size() > BLOB_SIZE_THRESHOLD) { points.add( boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.findCorners(inClass)); } } return points; }