2017-06-04 65 views
1

使用opencv2 - 2.4.9尝试使用cv2.findHomography计算单应矩阵时出现以下错误。我正在使用的值有一些明显的错误,特别是rect_points矩阵。如果我改变矩阵的值以使它们变小,那么在一些矩阵上计算成功。python opencv2 findHomography

(Pdb) findHomography(pts_dst,pts_src) 
(array([[ 1.80258009e+00, 1.55276411e+00, -7.76398173e+02], 
     [ -8.09994414e-01, 2.13295256e+00, -1.07909987e+02], 
     [ 5.79313440e-04, 7.57830547e-04, 1.00000000e+00]]), array([[1], 
     [1], 
     [1], 
     [1]], dtype=uint8)) 
(Pdb) findHomography(tc,pts_dst) 
(array([[ 5.86310680e-01, -1.02457072e+00, 3.18000000e+02], 
     [ 2.73257186e-01, 4.37679421e-01, 2.56000000e+02], 
     [ -4.88292404e-04, -8.73786408e-04, 1.00000000e+00]]), array([[1], 
     [1], 
     [1], 
     [1]], dtype=uint8)) 
(Pdb) findHomography(rect_points/2,tc) 
(array([[ 3.12565925e+00, -4.01560389e-01, -1.46710631e+02], 
     [ 6.46267255e-01, 3.94065399e-01, -7.32725203e+01], 
     [ -1.24144088e-02, 9.62934110e-04, 1.00000000e+00]]), array([[1], 
     [1], 
     [1], 
     [1]], dtype=uint8)) 
(Pdb) findHomography(rect_points-50,tc) 
(array([[ 2.18971678e+00, -2.81317781e-01, -1.10139713e+02], 
     [ 4.52750009e-01, 2.76067079e-01, -6.62229708e+01], 
     [ -8.69705784e-03, 6.74594641e-04, 1.00000000e+00]]), array([[1], 
     [1], 
     [1], 
     [1]], dtype=uint8)) 
(Pdb) findHomography(rect_points,tc) 
OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type()) in findHomography, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/calib3d/src/fundam.cpp, line 1074 
*** error: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/calib3d/src/fundam.cpp:1074: error: (-215) npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type() in function findHomography 



    (Pdb) rect_points 
    array([[ 117., 180.], 
      [ 142., 139.], 
      [ 160., 314.], 
      [ 154., 468.]], dtype=float32) 
    (Pdb) tc 
    array([[ 0., 0.], 
      [ 255., 0.], 
      [ 255., 255.], 
      [ 0., 255.]], dtype=float32) 
    (Pdb) 

(Pdb) pts_src 
array([[ 141., 131.], 
     [ 480., 159.], 
     [ 493., 630.], 
     [ 64., 601.]], dtype=float32) 
(Pdb) pts_dst 
array([[ 318., 256.], 
     [ 534., 372.], 
     [ 316., 670.], 
     [ 73., 473.]], dtype=float32) 
(Pdb) 
+0

作为一个初步的冰雹玛丽,我可能会尝试添加第三维到你的观点,给他们的形式'数组([[[x1,y1]],...,作为函数(至少对于C++)而言,[[xi,yi]],...,[[xn,yn]]])需要一个* 2通道*数组,即“4x1x2”或“1x4x2”数组。 此外,尝试函数['getPerspectiveTransform'](http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform)而不是'findHomography'时使用,当你有*超过*四点。 *(FWIW您的错误行对我来说在Python 3.6.1的OpenCV 3.2.0上运行良好。)* –

回答

0

这与cv库FindHomography运行没有错误,而不是cv2 FindHomography。这个问题必须与cv2 v2.4.9