2015-10-09 188 views
1

我試圖糾正的圖像和一些點,這是該圖像上。 整頓圖像效果非常好(在這部分代碼是不是從我):undistortPoints在OpenCV中(CV2)與Python錯誤的結果

(mapx, mapy) = cv2.initUndistortRectifyMap(camera_matrix,dist_coefs,np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),newCameraMatrix,(int(resolution*w), int(resolution*h)), cv2.CV_32FC1) 
RectImg = cv2.remap(img, mapx,mapy,cv2.INTER_LINEAR) 

但是當我糾正與undistortPoints和相同參數的點,我得到(我的意見)錯誤的座標。

point_file = np.loadtxt(fn) 
point_matrix = np.zeros(shape=(nr_points,1,2)) 

# fill Pointfile in n x 1 x 2-Matrix 
for each in range(0, nr_points): 
    point_matrix[each][0][0] = point_file[each][0] 
    point_matrix[each][0][1] = point_file[each][1] 

point_matrix_new = cv2.undistortPoints(point_matrix, newCameraMatrix, dist_coefs) 

這是我使用的參數(newCameraMatrix & dist_coefs):

[[ 4.93906295e+02 0.00000000e+00 1.24539714e+03] 
    [ 0.00000000e+00 4.92616567e+02 1.03814593e+03] 
    [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]] 
    [ 5.93179211e-01 3.59577119e-02 -3.34062329e-05 -8.92301489e-05 
     -5.27895858e-04 9.28762999e-01 1.46636733e-01 0.00000000e+00] 

我也不太清楚,什麼輸出實際上是。結果值是圖像座標還是傳感器座標,以及哪個單位?我只能找到undistortPoints爲CV(http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html),但不是一個CV2文檔。

例如(圖像尺寸= 2448×2048像素/傳感器尺寸= 8.6×6.6毫米

輸入(point_matrix):

[[[ 0.  0.]] 

[[ 2448.  0.]] 

[[ 0. 2048.]] 

[[ 2448. 2048.]] 

[[ 1224. 1024.]]] 

輸出(point_matrix_new):

[[[-6.49236118 -5.42726306]] 

[[ 6.39989444 -5.5358653 ]] 

[[-6.50237385 5.28935346]] 

[[ 6.58981334 5.54673511]] 

[[-0.04336093 -0.02874159]]] 

謝謝您的幫助!

回答

1

所以我發現我的錯誤:我有使用舊的和cv2.undistortPoints新的相機矩陣像cv2.initUndistortRectifyMap。

所以要糾正我只是用這個代碼:

point_matrix_new = cv2.undistortPoints(point_matrix,camera_matrix,dist_coefs,P=newCameraMatrix) 
相關問題