Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Perspective transformation "not working"

I am trying some perspective transformation (in Jave) ... so i did this simple example and it does not work. I get distorted result image (like lines from left top corner to right top and right-bottom). I suppose to get minification of origin 512x512 image.

What is wrong?

thanks

public void run2() {
    Mat mat = Imgcodecs.imread(getFilePath("/lena.png"));
    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, 0.0,0.0,     500.0,0.0,   500.0,500.0, 500.0,0.0);
    dst_mat.put(0,0, 0.0,0.0,     300.0,0.0,   300.0,300.0, 300.0,0.0);
    Mat perspectiveTransform = Imgproc.getPerspectiveTransform(src_mat, dst_mat);

    Mat dst = mat.clone();

    Imgproc.warpPerspective(mat, dst, perspectiveTransform, new Size(300, 300));
    Imgcodecs.imwrite("result.jpg", dst);
}