'How to split the pictures of two page book

enter image description here

How can this picture be divided into two pictures according to the middle of the book?

I tried to use the houghlines method in OpenCV to find the line according to the line, but I couldn't find the middle line

mycode



public class OpenCv {
    public static void main(String[] args) throws Exception {

        System.setProperty("java.awt.headless", "false");
        System.out.println(System.getProperty("java.library.path"));
      
        URL url = new URL("file:\\D:\\opencv\\opencv\\build\\java\\x64\\opencv_java455.dll");
        System.load(url.getPath());

        Mat canny2 = new Mat();
        Mat canny3 = new Mat();
        Mat canny4 = new Mat();
        Mat canny5 = new Mat();

        Mat srcImage = imread("e:\\aa.jpg");
        Mat dstImage = srcImage.clone();
        Imgproc.Canny(srcImage, dstImage, 50, 200, 3, false);

        Imgcodecs.imwrite("F:\\dst3.jpg", dstImage);

        Imgproc.dilate(dstImage,canny4,canny3,new Point(),2);
        Imgcodecs.imwrite("F:\\canny4.jpg", canny4);
        Imgproc.erode(canny4, canny5, canny3);
        Imgcodecs.imwrite("F:\\dst5.jpg", canny5);

        Imgproc.watershed(srcImage,canny5);

        Mat storage = new Mat();
        Imgproc.HoughLines(canny5, storage, 1, Math.PI / 180, 500, 0, 0, 0, 10);
        for (int x = 0; x < storage.rows(); x++)
        {
            double[] vec = storage.get(x, 0);

            double rho = vec[0];
            double theta = vec[1];

            Point pt1 = new Point();
            Point pt2 = new Point();

            double a = Math.cos(theta);
            double b = Math.sin(theta);

            double x0 = a * rho;
            double y0 = b * rho;

            pt1.x = Math.round(x0 + 1000 * (-b));
            pt1.y = Math.round(y0 + 1000 * (a));
            pt2.x = Math.round(x0 - 1000 * (-b));
            pt2.y = Math.round(y0 - 1000 * (a));

            if (theta >= 0)
            {
                Imgproc.line(srcImage, pt1, pt2, new Scalar(255, 255, 255, 255), 1, Imgproc.LINE_4, 0);
            }
        }
        Imgcodecs.imwrite("F:\\dst2.jpg", srcImage);
    }

}

I want to output two pictures like this ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

enter image description here enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source