2015-11-04 82 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之後立即寫入)。