Java OPENCV - Как найти разделительные линии, чтобы вырезать изображение - PullRequest
0 голосов
/ 21 апреля 2020

Я пытаюсь разделить этот вид изображений с помощью панелей гондолы в java, я пытаюсь с помощью горизонтальных линий, но я не могу найти подразделения.

ORG

результат, который мне нужен, - это точки для разделения и обрезки изображений, как это

г1 g2 g3 это мой код

Mat src = Imgcodecs.imread(f.getAbsolutePath());
        Mat gray = new Mat();
        Mat cdst = new Mat();
        if (src.channels() > 2) {
            Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
        } else {
            gray = src.clone();
        }
        //cdst=gray.clone();
        Mat bw = new Mat();
        Core.bitwise_not(gray, gray);
        Imgproc.adaptiveThreshold(gray, bw, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 15, -2);
        Mat horizontal = bw.clone();
        int horizontal_size = horizontal.cols() / 30;
        // Create structure element for extracting horizontal lines through morphology operations
        Mat horizontalStructure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(horizontal_size, 1));
        // Apply morphology operations
        Imgproc.erode(horizontal, horizontal, horizontalStructure);
        Mat lines = new Mat(); // will hold the results of the detection
        Imgproc.HoughLinesP(horizontal, lines, 2, Math.PI / 180, 200, 100, 5); // runs the actual detection
         Imgproc.cvtColor(gray, cdst, Imgproc.COLOR_GRAY2BGR);
        // Draw the lines
        Point pt1 = new Point();
        Point pt2 = new Point();
        double[] data;
        for (int x = 0; x < lines.rows(); x++) {
            data = lines.get(x, 0);
            pt1.x = data[0];
            pt1.y = data[1];
            pt2.x = data[2];
            pt2.y = data[3];
            if (Math.abs(pt1.x - pt2.x) > (gray.width() / 2)) {
                Imgproc.line(cdst, pt1, pt2, new Scalar(255, 0, 0), 10);
            }

        }
         imwrite(fAnn.getAbsolutePath() + "/RES_" + f.getName(), cdst);
...