1 | initial version |
java is somewhat clumsy here, but it's just a few lines:
mask = Mat.zeros(400,400,CvType.CV_8U); // all black
// your RotatedRect will come from minAreaRect(), this is just demo data !
RotatedRect rc = new RotatedRect(Point(200,200), new Size(200,100), 23);
// retrieve corner points:
Point[] p = Point[4];
rc.points(p);
// draw white, filled poly:
MatOfPoint mp = new MatOfPoint(p);
Imgproc.fillConvexPoly(mask, mp, new Scalar(255));
2 | No.2 Revision |
java is somewhat clumsy here, but it's just a few lines:
Mat mask = Mat.zeros(400,400,CvType.CV_8U); // all black
// your RotatedRect will come from minAreaRect(), this is just demo data !
RotatedRect rc = new RotatedRect(Point(200,200), new Size(200,100), 23);
// retrieve corner points:
Point[] p = Point[4];
rc.points(p);
// draw white, filled poly:
MatOfPoint mp = new MatOfPoint(p);
Imgproc.fillConvexPoly(mask, mp, new Scalar(255));
3 | No.3 Revision |
java is somewhat clumsy here, but it's just a few lines:
Mat mask = Mat.zeros(400,400,CvType.CV_8U); // all black
// your RotatedRect will come from minAreaRect(), this is just demo data !
RotatedRect rc = new RotatedRect(Point(200,200), new Size(200,100), 23);
// retrieve corner points:
Point[] p = Point[4];
rc.points(p);
// draw white, filled poly:
MatOfPoint mp = new MatOfPoint(p);
Imgproc.fillConvexPoly(mask, mp, new Scalar(255));
usually you need a contour as input for minAreaRect(), see tutorial and some conversion code (sorry, untested):
List<MatOfPoint> contours = new ArrayList<>();
Imgproc.findContours(cannyOutput, contours, ...);
Point [] pts = contours.get(i).toArray();
RotatedRect rc = Imgproc.minAreaRect(new MatOfPoint2f(pts));
maybe you can use the points from findNonZero(), too, but to use that you need MatOfPoint (not 2f)
MatOfPoint Points = new MatOfPoint();
Core.findNonZero(paper_mat,Points);
RotatedRect rc = Imgproc.minAreaRect(new MatOfPoint2f(Points.toArray()));
sorry, i was just trying out latest 4.0, where all drawing stuff was moved to Imgproc for consistency, but yes, it's likely in Core with your version
4 | No.4 Revision |
java is somewhat clumsy here, but it's just a few lines:
Mat mask = Mat.zeros(400,400,CvType.CV_8U); // all black
// your RotatedRect will come from minAreaRect(), this is just demo data !
RotatedRect rc = new RotatedRect(Point(200,200), new Size(200,100), 23);
// retrieve corner points:
Point[] p = Point[4];
rc.points(p);
// draw white, filled poly:
MatOfPoint mp = new MatOfPoint(p);
Imgproc.fillConvexPoly(mask, mp, new Scalar(255));
usually you need a contour as input for minAreaRect(), see tutorial and some conversion code (sorry, untested):
List<MatOfPoint> contours = new ArrayList<>();
Imgproc.findContours(cannyOutput, contours, ...);
Point [] pts = contours.get(i).toArray();
RotatedRect rc = Imgproc.minAreaRect(new MatOfPoint2f(pts));
maybe you can use the points from findNonZero(), too, but to use that you need MatOfPoint (not 2f)
MatOfPoint Points = new MatOfPoint();
Core.findNonZero(paper_mat,Points);
RotatedRect rc = Imgproc.minAreaRect(new MatOfPoint2f(Points.toArray()));
sorry, i was just trying out latest 4.0, where all drawing stuff was moved to Imgproc for consistency, but yes, it's likely in Core with your version