Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python opencv2 findHomography_Python_Opencv - Fatal编程技术网

python opencv2 findHomography

python opencv2 findHomography,python,opencv,Python,Opencv,使用opencv2-2.4.9,在尝试使用cv2.FindHomeography计算单应矩阵时,我得到以下错误。我使用的值,特别是rect_点矩阵,显然有问题。如果我改变矩阵的值使它们变小,那么在某些矩阵上计算会成功 (Pdb) findHomography(pts_dst,pts_src) (array([[ 1.80258009e+00, 1.55276411e+00, -7.76398173e+02], [ -8.09994414e-01, 2.13295256e

使用opencv2-2.4.9,在尝试使用cv2.FindHomeography计算单应矩阵时,我得到以下错误。我使用的值,特别是rect_点矩阵,显然有问题。如果我改变矩阵的值使它们变小,那么在某些矩阵上计算会成功

(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) 

与cv2 FindHomography相反,cv库FindHomography运行时没有错误。问题必须是cv2 v2.4.9

与cv2 FindHomeography相反,cv库FindHomeography运行时没有错误。问题一定是cv2 v2.4.9作为一个最初的圣母玛利亚,我可能会尝试为你的观点添加一个第三维度,给他们一个
数组([[[x1,y1]],…,[[xi,yi]],…,[[xn,yn]])
,因为函数(至少对于C++)需要一个双通道数组,即
4x1x2
1x4x2
数组。此外,当您有四个以上的点时,请尝试使用
findHomography
。(FWIW您有错误的那一行在OpenCV 3.2.0和Python 3.6.1上运行得很好。)作为一个初始的问候,我可能会尝试向您的点添加一个第三维度,给它们一个
数组形式([[[[x1,y1]],…,[[xi,yi],…,[[xn,yn]])
,因为函数(至少对于C++)需要一个双通道数组,即。,一个
4x1x2
1x4x2
阵列。此外,当您有四个以上的点时,请尝试使用
findHomography
。(FWIW您有错误的代码行在使用Python 3.6.1的OpenCV 3.2.0上运行良好。)