Apply infinite homography to image

asked 2014-07-20 22:35:11 -0600

rafaoc gravatar image

updated 2020-10-24 15:24:30 -0600

Hi,
I want to apply a infinite homography to an image, but I dont know how to do it.
I'm working with the openCV api for java.
I have the below code, but I dont get good results.
From image A, I get image B
Do someone know how to apply this homography ?

image description


Calib3d.stereoCalibrate(objectPoints_1, imagePoints_1, imagePoints_2, 
    cameraMatrix_1, distCoeffs_1, cameraMatrix_2, distCoeffs_2, imageSize_1, R, T, E, F, 
    new TermCriteria( TermCriteria.MAX_ITER + TermCriteria.EPS , 30, 0.1), 
    Calib3d.CALIB_FIX_INTRINSIC );

Imgproc.initUndistortRectifyMap(cameraMatrix_1, distCoeffs_1, new Mat(), new Mat(), newImageSize_1, CvType.CV_32FC1, mapx_1, mapy_1);
Imgproc.initUndistortRectifyMap(cameraMatrix_2, distCoeffs_2, new Mat(), new Mat(), newImageSize_2, CvType.CV_32FC1, mapx_2, mapy_2);

Imgproc.remap(image_1, undistorted_1, mapx_1, mapy_1, Imgproc.INTER_LINEAR);
Imgproc.remap(image_2, undistorted_2, mapx_2, mapy_2, Imgproc.INTER_LINEAR);

Mat cameraMatrix_2_inv = new Mat(cameraMatrix_2.size(),cameraMatrix_2.type());
Core.invert(cameraMatrix_2, cameraMatrix_2_inv);
Core.invert(R, R_inv);

// inverse Homography: H_inf = k1*R*k2_inv
Mat H_inf = new Mat(3,3,CvType.CV_64FC1);
Core.gemm(cameraMatrix_1, R, 1, cameraMatrix_2_inv, 1, H_inf);

Mat outputImage_3 = new Mat();
Imgproc.warpPerspective(undistorted_2, outputImage_3, H_inf, undistorted_2.size());

edit retag flag offensive close merge delete

Comments

Look at the documentation of gemm(): dst = alphasrc1.t()src2 + beta*src3.t(); In c++ I would use the operator *, there must be a Java equivalent to that.

kovand11 gravatar imagekovand11 ( 2014-07-22 06:25:14 -0600 )edit

@kovand11. The matrix multiplication with gemm works good.I have already ckecked it

rafaoc gravatar imagerafaoc ( 2014-07-22 12:00:02 -0600 )edit