大家,早安!
我在使用 opencv 函式校準相機時遇到了以下錯誤:
OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\calibration.cpp:3350: 錯誤: (-210: 不支持的格式或格式組合) objectPoints 應該包含向量函式 'cv::collectCalibrationData' 中 Point3f 型別點的向量
我試圖找到解決方案,但除了型別問題或長度問題外,在任何地方都找不到任何東西。我為 objPoints 和 imgPoints 使用了一個 float 32 型別的 np.array:
objpoints = np.array(objpoints, dtype = np.float32)
imgpoints = np.array(imgpoints, dtype = np.float32)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, imsize, None, None )
變數資源管理器為使用的變數提供以下值:
在:物件點
出去:
陣列([[ 0. , 246.5, 0. ],
[ 14.5, 246.5, 0. ],
[ 43.5, 246.5, 0. ],
...,
[174. , 0. , 0. ],
[319. , 0. , 0. ],
[333.5, 0. , 0. ]], dtype=float32)
在: imgpoints
出去:
陣列([[1310., 1032.],
[1258., 1032.],
[1154., 1032.],
[1206., 1032.],
...,
[739., 134.],
[686., 133.],
[162., 132.],
[ 110., 132.]], dtype=float32)
在: 大小
輸出:(1080, 1440)
在:len(imgpoints)
輸出:440
在:len(物件點)
輸出:440
我還嘗試在calibrateCamera 函式中切換objpoints 和imgpoints,但這導致了相同的錯誤訊息。當我在 C 中閱讀了很多針對此函式的解決方案時,我想指出這是一個與 Python 相關的問題。
我希望有人能幫我解決這個問題!提前致謝!
uj5u.com熱心網友回復:
這個函式可以有多個視圖(比方說N),每個視圖可能顯示一個不同的物件。
“點向量的向量”意味著允許每個“點向量”具有不同的長度,因為該物件可能與在其他視圖中看到的物件不同。
如果您的所有視圖都顯示相同的物件(陣列具有相同的長度),您可以傳遞具有外部維度的單個陣列,但在一般情況下您應該傳遞一個陣列串列,因此每個陣列都可以有自己合適的大小。(N, ...)
objApoints = np.array(objApoints, dtype=np.float32)
img1points = np.array(img1points, dtype=np.float32)
# have another picture? img2points...
# it may show the same object (objApoints) or a different object (objBpoints)
objpointslist = [objApoints]
imgpointslist = [img1points]
cv2.calibrateCamera(objpointslist, imgpointslist, ...)
uj5u.com熱心網友回復:
ImagePoints 和 objectPoints 應包含點向量的向量。這意味著你應該有多個影像的影像和物件點。在你的情況下,我看到只有一個影像有影像和物件點。你可以做的是在這種情況下使用 np.newaxis 如下。但是,為了使校準做得更好,請嘗試使用多個影像。
objpoints = np.array(objpoints, dtype = np.float32)[np.newaxis]
imgpoints = np.array(imgpoints, dtype = np.float32)[np.newaxis]
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, imsize, None, None )
uj5u.com熱心網友回復:
已解決:我必須將 objpoints 和 imgpoints 放在串列中,然后才能從中制作 numpy 陣列:
objpoints = np.array([objpoints], dtype = np.float32)
imgpoints = np.array([imgpoints], dtype = np.float32)
代替:
objpoints = np.array(objpoints, dtype = np.float32)
imgpoints = np.array(imgpoints, dtype = np.float32)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/389675.html
