13

uncompressPoints(opencv 2.4.1)に渡すポイントのx、yリストをフォーマットするのに問題があります。

エラーメッセージはC++固有であり、ポイントの配列がCV_32FC2タイプではないことについて文句を言います。Nx2 numpy配列を渡すことはできませんか?

import cv2

camera_matrix = array(mat('1.3e+03, 0., 6.0e+02; 0., 1.3e+03, 4.8e+02; 0., 0., 1.'), dtype=float32)
dist_coeffs = array(mat('-2.4-01, 9.5e-02, -4.0e-04, 8.9e-05, 0.'), dtype=float32)

test = zeros((10,2), dtype=float32)

print test.shape, type(test)

xy_undistorted = cv2.undistortPoints(test, camera_matrix, dist_coeffs)

結果:

opencv/modules/imgproc/src/undistort.cpp:279: error: (-215) CV_IS_MAT(_src) && CV_IS_MAT(_dst) && (_src->rows == 1 || _src->cols == 1) && (_dst->rows == 1 || _dst->cols == 1) && _src->cols + _src->rows - 1 == _dst->rows + _dst->cols - 1 && (CV_MAT_TYPE(_src->type) == CV_32FC2 || CV_MAT_TYPE(_src->type) == CV_64FC2) && (CV_MAT_TYPE(_dst->type) == CV_32FC2 || CV_MAT_TYPE(_dst->type) == CV_64FC2) in function cvUndistortPoints

samples / python2 / video.pyには、配列を取得してそれを再形成(-1,3)するprojectPointsの使用法があり、その関数のNx3配列になります。ここでは、同じ形式が機能するようです。

4

2 に答える 2

13

カメラのキャリブレーションについてはよくわかりません。しかし、あなたのコードとエラーを見て、次のように変更しました:

import cv2
import numpy as np
camera_matrix = np.array([[1.3e+03, 0., 6.0e+02], [0., 1.3e+03, 4.8e+02], [0., 0., 1.]], dtype=np.float32)
dist_coeffs = np.array([-2.4-01, 9.5e-02, -4.0e-04, 8.9e-05, 0.], dtype=np.float32)

test = np.zeros((10,1,2), dtype=np.float32)
xy_undistorted = cv2.undistortPoints(test, camera_matrix, dist_coeffs)

print xy_undistorted

以下は私が得た結果です。正しいかどうかを確認してください。

[[[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]

 [[ 0.0187303   0.01477836]]]

何が問題ですか :

エラーは、ソースにはEITHER one row OR one column. また、CV_32FC2 または CV_64FC2 である必要があります。これは、2 つのチャネルと浮動小数点を意味します。したがって、形状の src を作成します(10,1,2) or (1,10,2)。どちらの方法も機能し、同じ結果が得られます (自分で確認しました)。唯一の問題は、それが正しいかどうかわからないので、自分で確認してください。

于 2012-06-13T17:56:03.567 に答える