public List<List<Point2D_F64>> getEdges() { if (this.scale != 1.0) { for (List<Point2D_F64> l : prunedCannyEdgeList) { for (Point2D_F64 p : l) { p.x *= this.scale; p.y *= this.scale; } } this.scale = 1.0; } return prunedCannyEdgeList; }
public List<List<Point2D_F64>> getBlobRegions() { if (this.scale != 1.0) { for (List<Point2D_F64> l : blobQuads) { for (Point2D_F64 p : l) { p.x *= this.scale; p.y *= this.scale; } } this.scale = 1.0; } return blobQuads; // if (this.blobQuads.size() < 9) { // System.out.println("blobs can't find enough things that might be cards"); // } // else { // // // See whether the top 9/12/15 ROIs by size are roughly the same size // // Calculate areas and sort // int[] areas = new int[blobQuads.size()]; // for (int i=0; i<blobQuads.size(); i++) { // areas[i] = Segmenter.areaOfRegion(blobQuads.get(i)); // } // Arrays.sort(areas); // // // From the top, see if they're all within tolerance from the mean // int similarSizedLargest = -1; // if (blobQuads.size() >= 15 && Segmenter.topNSimilarSized(areas, 15)) { // similarSizedLargest = 15; // } // else if (blobQuads.size() >= 12 && Segmenter.topNSimilarSized(areas, 12)) { // similarSizedLargest = 12; // } // else if (Segmenter.topNSimilarSized(areas, 9)) { // similarSizedLargest = 9; // } // // if (similarSizedLargest != -1) { // List<List<Point2D_F64>> finalEdgeList = // blobQuads.subList(blobQuads.size()-similarSizedLargest, blobQuads.size()-1); // return finalEdgeList; // } // } // return null; }
/** * Given a sequence of points on the contour find the best fit line. * * @param contourIndex0 contour index of first point in the sequence * @param contourIndex1 contour index of last point (exclusive) in the sequence * @param line storage for the found line * @return true if successful or false if it failed */ boolean fitLine(int contourIndex0, int contourIndex1, LineGeneral2D_F64 line) { int numPixels = CircularIndex.distanceP(contourIndex0, contourIndex1, contour.size()); // if its too small if (numPixels < minimumLineLength) return false; Point2D_I32 c0 = contour.get(contourIndex0); Point2D_I32 c1 = contour.get(contourIndex1); double scale = c0.distance(c1); double centerX = (c1.x + c0.x) / 2.0; double centerY = (c1.y + c0.y) / 2.0; int numSamples = Math.min(20, numPixels); pointsFit.reset(); for (int i = 0; i < numSamples; i++) { int index = i * (numPixels - 1) / (numSamples - 1); Point2D_I32 c = contour.get(CircularIndex.addOffset(contourIndex0, index, contour.size())); Point2D_F64 p = pointsFit.grow(); p.x = (c.x - centerX) / scale; p.y = (c.y - centerY) / scale; } if (null == FitLine_F64.polar(pointsFit.toList(), linePolar)) { return false; } UtilLine2D_F64.convert(linePolar, line); // go from local coordinates into global line.C = scale * line.C - centerX * line.A - centerY * line.B; return true; }
@Override public void compute(double x, double y, Point2D_F64 out) { out.x = x; out.y = height - y; }