Ask Your Question

Revision history [back]

Camera Calibration

Hello, I'm trying to calibrate my webcam. I used the OpenCV C++ example to get the camera matrix and distortion coefficients. This has worked perfectly.

Now I would like to apply this in my C code. However, that does not work.

CvMat CameraMatrix;
CvMat DistortionCoefficients;


const float camera_matrix[3][3] = {
{1.9109556203786724e+03, 0., 9.7868550610235718e+02}, 
{0., 1.9067942582652870e+03, 5.3264622851365255e+02},
{0., 0., 1.}};

const CvMat CameraMatrix = cvMat(3,3,CV_64FC1, camera_matrix);

float distortion_coefficients[1][5] = {
{8.4168872817623579e-03, -1.6092726101677710e-01,
 1.4210945666220784e-03, -3.9888765134799423e-03,
 1.3635442753934679e-01}
};

const CvMat DistortionCoefficients = cvMat(1,5,CV_64FC1, distortion_coefficients);

IplImage *dst;
cvUndistort2(src, dst, &CameraMatrix, &DistortionCoefficients, &CameraMatrix);

src = dst;

I get the following error:

Aborted (core dumped)