简体   繁体   English

python opencv2 findHomography

[英]python opencv2 findHomography

Using opencv2 - 2.4.9 I get the following error when attempting to compute a homography matrix with cv2.findHomography. 使用opencv2-2.4.9尝试使用cv2.findHomography计算单应性矩阵时出现以下错误。 There is something obviously wrong with the values that I am using, in particular the rect_points matrix. 我使用的值,尤其是rect_points矩阵,显然有问题。 If I change the values of the matrix to make them smaller the computation succeeds on some matrices. 如果更改矩阵的值以使其更小,则在某些矩阵上的计算会成功。

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

This ran without error with cv libraries FindHomography as opposed to cv2 FindHomography. 与cv2 FindHomography相比,cv库FindHomography的运行没有错误。 The issue must be with cv2 v2.4.9 问题必须出在cv2 v2.4.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM