omr in java or c++ ? [closed]

asked 2018-04-16 05:02:08 -0600

mar_y_ow_777 gravatar image

updated 2018-04-17 01:17:15 -0600

image description

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);
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-27 09:23:17.304220

Comments

it's such a common problem, and it seems you haven't tried anything on your own.

berak gravatar imageberak ( 2018-04-16 05:09:59 -0600 )edit

i tried so hard , since i am new to open cv , i do not get what result i wanted .

mar_y_ow_777 gravatar imagemar_y_ow_777 ( 2018-04-16 05:54:30 -0600 )edit
1

we won't write your app, so, unless you show us your attempt, we cannot help.

berak gravatar imageberak ( 2018-04-16 07:52:08 -0600 )edit

please help me this is what i tried . and whats next?

mar_y_ow_777 gravatar imagemar_y_ow_777 ( 2018-04-17 01:17:55 -0600 )edit