来自solvePnP的输出与projectPoints不匹配 [英] output from solvePnP doesn't match projectPoints

查看:344
本文介绍了来自solvePnP的输出与projectPoints不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从solvePnP获得了奇怪的数据,所以我尝试使用projectPoints进行检查:

I get strange data from solvePnP, so I tried to check it with projectPoints:

retval, rvec, tvec=cv2.solvePnP(opts, ipts, mtx, dist, flags=cv2.SOLVEPNP_ITERATIVE)
print(retval,rvec,tvec)
proj, jac = cv2.projectPoints(opts, rvec, tvec, mtx, dist)
print(proj,ipts)

在此图片上检测到的是z = 0的3d点:

here opts are 3d points with z=0, detected on this picture:

ipts取自此图片(此处仅图片的一部分):

And ipts are taken from this pic (only part of picture here):

我已经检查了点本身(通过SIFT进行检测,可以正确检测到点并以正确的方式配对).

I've checked points themselves (detected with SIFT, points are detected correctly and pairing in a right way).

现在,我想测试由SolvePnP找到的rvec和tvec是否正确,因此我调用cv2.projectPoint来测试3d点是否投影到图像点.这就是我所拥有的:

Now I want to test if rvec and tvec, found by SolvePnP is correct, so I invoke cv2.projectPoint to test if 3d points are projected to the image points. And here is what I have:

所以我看到投影点位于图像之外,且y <0.

So I see that projected points lie outside of image, having y<0.

(resolvePnP中的撤除为true)

(retval from solvePnP is true)

这是失真矩阵dist:

This is distortion matrix dist:

1.6324642475694839e+02 -2.1480843988631259e+04 -3.4969507980045117e-01 7.9693609309756430e-01 -4.0684056606034986e+01

这是mtx:

6.4154558230601404e+04 0. 1.2973531562160772e+03
0. 9.8908265814965678e+04 9.5760834379036123e+02
0. 0. 1.

这是选择项:

[[ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1708.74987793  1138.92041016     0.        ]
 [ 1984.09973145  1069.31677246     0.        ]
 [ 1984.09973145  1069.31677246     0.        ]
 [ 1908.19396973  1200.05529785     0.        ]
 [ 1994.56677246  1286.16516113     0.        ]
 [ 1994.56677246  1286.16516113     0.        ]
 [ 1806.82177734  1058.06872559     0.        ]
 [ 1925.55639648  1077.33703613     0.        ]
 [ 1998.30627441  1115.51647949     0.        ]
 [ 1998.30627441  1115.51647949     0.        ]
 [ 1998.30627441  1115.51647949     0.        ]
 [ 2013.79003906  1168.08728027     0.        ]
 [ 1972.93457031  1234.92614746     0.        ]
 [ 2029.11364746  1220.234375       0.        ]]

这是ipts:

[[  71.6125946    11.61344719]
 [ 116.60684967   71.6068573 ]
 [ 116.60684967   71.6068573 ]
 [ 101.60684967   86.60684967]
 [ 101.60684967   86.60684967]
 [ 116.60684967  101.6068573 ]
 [ 116.60684967  101.6068573 ]
 [ 112.37421417   53.40462112]
 [ 112.37421417   53.40462112]
 [  83.76233673   84.36077118]
 [  98.45358276  112.38414764]
 [  98.45358276  112.38414764]
 [  67.2594223    38.04878998]
 [  96.85155487   51.85028076]
 [ 112.26165009   67.25630188]
 [ 112.26165009   67.25630188]
 [ 112.26165009   67.25630188]
 [ 112.24694061   82.24401855]
 [  96.82528687   97.66513824]
 [ 112.2511673    97.25905609]]

rvec = [[-0.21890167] [-0.86241377] [ 0.96051463]]
tvec = [[  239.04461181] [-2165.99539286] [-1700.61539107]]

我也尝试遵循其中一个注释,并将opt中的y乘以-1,但这给了我更疯狂的坐标,例如10 ^ 13.

Also I tried to follow one of the comments and multiply each y from opts by -1, but this gave me even more crazy coordinates outside picture like 10^13.

推荐答案

相机矩阵(mts)不正确. Fx和Fy非常不同(Fx = 6.4154558230601404e + 04 Fy = 9.8908265814965678e + 04)并且很大.根据OpenCV calibrateCamera()函数中的注释,通常会出现此问题,因为您可能在findChessboardCorners中使用了patternSize = cvSize(rows,cols)而不是使用patternSize = cvSize(cols,rows).

Camera matrix (mts) is incorrect. Fx and Fy are very different (Fx=6.4154558230601404e+04 Fy=9.8908265814965678e+04) and very big. According to comment in OpenCV calibrateCamera() function this problem usually occurs because you have probably used patternSize=cvSize(rows,cols) instead of using patternSize=cvSize(cols,rows) in findChessboardCorners.

这篇关于来自solvePnP的输出与projectPoints不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆