How to create a matrix and make it a copy of the camera matrix?

asked 2017-04-04 16:04:05 -0600

SniFFzoR gravatar image

Hello,

I have retrieved the calibration parameters for my camera, meaning that I have the camera matrix and the distortion vector. However, now that I have those, I want to undistort my image using the function:

Imgproc.undistort(Mat src, Mat dst, Mat cameraMatrix, Mat distVector);

I have them all, I just don't know how to create a matrix and fill it with values.

I would like to do something like this:

Mat cameraMatrix = new Mat(3,3);
cameraMatrix.put(0, 0, f_x);
cameraMatrix.put(0, 1, 0);
cameraMatrix.put(0, 2, c_x);
cameraMatrix.put(1, 0, 0);
cameraMatrix.put(1, 1, f_y);
cameraMatrix.put(1, 2, c_y);
cameraMatrix.put(2, 0, 0);
cameraMatrix.put(2, 1, 0);
cameraMatrix.put(2, 2, 1)

Of course, I would do the same for the distortion vector.

The problem is that I haven't found any documentation on how to create matrices in OpenCV for Java. I don't mean like Mat mat = new Mat(), but how to create a matrix and fill it with values.

I hope that you guys can help.

edit retag flag offensive close merge delete

Comments

and the error is ?

no java here, but i think, it's mainly lacking the type, like new Mat(3,3,CvType.CV_32F);

berak gravatar imageberak ( 2017-04-04 20:51:16 -0600 )edit