omr in java or c++ ? [closed]
Please help me to improve this code for wrapping? anyone please
This is my code for wrapping this image .
Mat gray = new Mat();
Mat blurred = new Mat();
Mat edged = new Mat();
Mat img = Imgcodecs.imread(getImg().getPath());
if (img.empty()) {
Log.e("FragmentMain", "Empty Image");
}
Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.GaussianBlur(gray, blurred, new Size(5, 5), 0);
Imgproc.Canny(blurred, edged, 75, 200);
Mat clone = edged.clone();
Mat hierarchy= new Mat();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(clone, contours, hierarchy, Imgproc.RETR_EXTERNAL,
Imgproc.CHAIN_APPROX_SIMPLE);
List<Point> curves = new ArrayList<>();
hierarchy.release();
Mat corners = new Mat(4, 1, CvType.CV_32FC2);
for (int idx = 0; idx < contours.size(); idx++) {
MatOfPoint contour = contours.get(idx);
MatOfPoint2f contour_points = new MatOfPoint2f(contour.toArray());
RotatedRect minRect = Imgproc.minAreaRect(contour_points);
Point[] rect_points = new Point[4];
minRect.points(rect_points);
if (minRect.size.height > img.width() / 2) {
List<Point> srcPoints = new ArrayList<Point>(4);
srcPoints.add(rect_points[1]);
srcPoints.add(rect_points[2]);
srcPoints.add(rect_points[3]);
srcPoints.add(rect_points[0]);
corners = Converters.vector_Point_to_Mat(
srcPoints, CvType.CV_32F);
}
}
Mat results = new Mat();
List<Point> dstPoints = new ArrayList<Point>(4);
dstPoints.add(new Point(0, 0));
dstPoints.add(new Point(1000, 0));
dstPoints.add(new Point(1000, 1920));
dstPoints.add(new Point(0, 1920));
Mat quad_pts = Converters.vector_Point_to_Mat(
dstPoints, CvType.CV_32F);
Mat transmtx = Imgproc.getPerspectiveTransform(corners, quad_pts);
Imgproc.warpPerspective(img, results, transmtx, new Size(1000, 1920));
Imgcodecs.imwrite("results.png", results);
showImage(results);
it's such a common problem, and it seems you haven't tried anything on your own.
i tried so hard , since i am new to open cv , i do not get what result i wanted .
we won't write your app, so, unless you show us your attempt, we cannot help.
please help me this is what i tried . and whats next?