0
votes

I have a program that detects objects in a live video stream. I am looking to compensate for the distortion in the camera, I have used the OpenCV calibration tool and produced an XML file with the relevant parameters.

However I am unsure how to then apply this using the undistort function, it is my understanding that this will need to be applied to each frame as it is captured?

void undistort(InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, InputArray newCameraMatrix=noArray() )

I am having trouble identifying each of these parameters, below is my current understanding.

undistorted(currentFrame, resultsWindow, calibrationFile, notSure, notSure);

Is this function called as below:

  if(captureOpen == false){
    img_scene = cvCaptureFromFile(videoFeed);
  }
  while(1) {
    image = cvQueryFrame(img_scene);
    undistort();
1

1 Answers

0
votes

undistorted(currentFrame, resultsWindow, calibrationFile, notSure, notSure);

No, that will not work. You need to manually read your XML file beforehand and fill the corresponding parameters with the data found in the file. The file should contain the camera matrix (look for cx, cy, fx, fy values) and the distortion parameters (k1, k2, k3, p1, p2, etc.).

The documentation for undistort for 2.4.x is here : http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#undistort

Typically src is a Mat containing the current frame. dst an output Mat of the same size that will be filled with the undistorted image. You will have to convert that back to your preferred format or display it in the window. cameraMatrix is a 3x3 Mat that you have filled with your camera intrinsics. distCoeffs is usually a 1x4 or 1x5 Mat containing the distorsion coeffs. (Note that p1 and p2 must be written right after k2).