Skip to content Skip to sidebar Skip to footer

Android Opencv Getperspectivetransform And Warpperspective

I am a bit confused with the parameters of getPerspectiveTransform as I cannot see a proper image. Here is my code. The original_image variable is the image that contains a square

Solution 1:

This worked for me. in the src_mat.put you should have 0,0 at first and then the float values for the coordinates.

    Mat mat=Highgui.imread("inputImage.jpg");
    Mat src_mat=new Mat(4,1,CvType.CV_32FC2);
    Mat dst_mat=new Mat(4,1,CvType.CV_32FC2);


    src_mat.put(0,0,407.0,74.0,1606.0,74.0,420.0,2589.0,1698.0,2589.0);
    dst_mat.put(0,0,0.0,0.0,1600.0,0.0, 0.0,2500.0,1600.0,2500.0);
    Mat perspectiveTransform=Imgproc.getPerspectiveTransform(src_mat, dst_mat);

    Mat dst=mat.clone();

    Imgproc.warpPerspective(mat, dst, perspectiveTransform, new Size(1600,2500));
    Highgui.imwrite("resultImage.jpg", dst);

Post a Comment for "Android Opencv Getperspectivetransform And Warpperspective"