2015-11-04 84 views
0

我有一个程序,检测实时视频流中的对象。我正在寻找补偿相机失真的方法,我使用了OpenCV校准工具并生成了具有相关参数的XML文件。OpenCV应用相机失真 - 应用校准

但是我不确定如何使用undistort函数来应用这个函数,我的理解是这需要在捕获每个帧时应用到每个帧上?

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

我无法确定这些参数,下面是我目前的理解。

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

这是函数调用如下:

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

检查此答案http://stackoverflow.com/questions/19897414/understanding-opencvs-undistort-function – ikaro

回答

0

未失真(设置currentFrame,resultsWindow,calibrationFile,notSure, notSure);

不,这是行不通的。您需要事先手动读取您的XML文件,并使用文件中找到的数据填写相应的参数。该文件应该包含相机矩阵(查找cx,cy,fx,fy值)和失真参数(k1,k2,k3,p1,p2等)。

为undistort为2.4.x的文档是在这里:http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#undistort

通常src是包含当前帧一个Matdst输出为Mat,尺寸相同,将填充未失真的图像。您必须将其转换回您的首选格式或将其显示在窗口中。 cameraMatrix是一个3x3垫,您已经充满了相机内在功能。 distCoeffs通常是1x4或1x5 Mat,包含扭曲系数。 (请注意,p1和p2必须在k2之后立即写入)。