OpenCV Java: Iterate through all points in Line as obtained from FitLine & find distance of each point to Contour edge using pointPolygonTest - Little Help Please!

asked 2019-12-24 14:18:38 -0600

karDilip gravatar image

Question#01 -- How can we get all the Points under Line, after running FitLine ? As we don't have LineIterator available for Java, is there way we can convert from Mat of line to Points and use each point under pointPolygonTest? Checking for fitline: https://docs.opencv.org/3.4/js_contou...).

    RotatedRect boundedLeaf = Imgproc.minAreaRect(new MatOfPoint2f(max_contour.toArray()));
    Mat line = new Mat();
    Imgproc.fitLine(max_contour,line,CV_DIST_L2,0,0.01,0.01);

Question#02 -- Need to finally find distance of each point on line from the edge of the contour using Imgproc.pointPolygonTest. I was able to find the distance using center of rotated rectangle but the width of the rectangle has to be adjusted to the min width of the object, therefore the requirement. (Open for suggestions as well, on how to fit a rectangle to min width of a object detected.)

    double dist = Imgproc.pointPolygonTest(new MatOfPoint2f(max_contour.toArray()), boundedLeaf.center, true);

Input Image: image description

Output Image: image description

edit retag flag offensive close merge delete