簡體   English   中英

在Python中使用OpenCV進行無失真點時的結果不佳

[英]Bad results when undistorting points using OpenCV in Python

我在使用用於OpenCV的Python綁定的校准相機拍攝的圖像上沒有失真點。 未失真的點具有與圖像中檢測到的原始點完全不同的坐標。

這是違規的電話:

undistorted = cv2.undistortPoints(image_points,
                                  camera_matrix,
                                  distortion_coefficients)

其中image_points是由cv2.findChessboardCorners返回的檢測到的棋盤角的numpy數組,並且被重新整形以匹配cv2.undistortPoints的尺寸要求,並且camera_matrix返回了cv2.calibrateCameradistortion_coefficients

camera_matrixdistortion_coefficients對我來說似乎沒問題, image_points也是如此。 然而, distorted似乎與image_points沒有任何關系。 以下是值的摘要:

>>> image_points
array([[[ 186.95303345,  163.25502014]],

       [[ 209.54478455,  164.62690735]],

       [[ 232.26443481,  166.10734558]],

       ..., 

       [[ 339.03695679,  385.97784424]],

       [[ 339.20108032,  400.38635254]],

       [[ 339.13067627,  415.30780029]]], dtype=float32)
>>> undistorted
array([[[-0.19536583, -0.07900728]],

       [[-0.16608481, -0.0772614 ]],

       [[-0.13660771, -0.07537176]],

       ..., 

       [[ 0.00228534,  0.21044853]],

       [[ 0.00249786,  0.22910291]],

       [[ 0.00240568,  0.24841554]]], dtype=float32)
>>> camera_matrix
array([[ 767.56947802,    0.        ,  337.27849576],
   [   0.        ,  767.56947802,  224.04766824],
   [   0.        ,    0.        ,    1.        ]])
>>> distortion_coefficients
array([[ 0.06993424, -0.32645465,  0.        ,  0.        , -0.04310827]])

我正在使用參考C代碼,所有內容都匹配,直到我撥打電話。 出了什么問題?

我想您忘記在調用undistortPoints指定新的相機矩陣 如果你查看函數的文檔 ,它會說簽名是:

Python: cv.UndistortPoints(src, dst, cameraMatrix, distCoeffs, R=None, P=None) → None

其中dst是非失真后的點陣列,“如果P是同一性或被省略,則它包含歸一化點坐標”,意味着在使用校准矩陣在圖像中投影之前。

如果將P設置為cameraMatrix該功能應該可以達到預期cameraMatrix

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM