python opencv2 findHomography

标签 python opencv

使用 opencv2 - 2.4.9 尝试使用 cv2.findHomography 计算单应矩阵时出现以下错误。我使用的值显然有问题,尤其是 rect_points 矩阵。如果我更改矩阵的值以使它们更小,则某些矩阵的计算会成功。

(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

关于python opencv2 findHomography,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44357305/

相关文章:

python - google answers 如何使用 .py 文件?

Python 列表和相等

python - Tkinter, 'module' 对象没有属性 'Frame'

python - Pandas - 过滤列至少匹配一次的行

c++ - 简单的opencv相机程序中抛出异常

opencv - 使用 opencv 为灰度图像着色

opencv - 处理中的OpenCV Canny Edge检测器(实时视频)

Python-子进程

java - 如何用java和OpenCV关闭摄像头?

android - 使用opencv进行文档轮廓检测