gpt4 book ai didi

c++ - 关于点数的断言失败,在 OpenCV 的 solvePNP 上

转载 作者:行者123 更新时间:2023-11-28 04:10:10 27 4
gpt4 key购买 nike

考虑以下代码:

  std::vector<cv::Point2f> vecUV = Vec2DFromFile(argv[2]);
std::vector<cv::Point3f> vecXYZ = Vec3DFromFile(argv[3]);

cv::Mat matCalib(3, 3, CV_64F);
cv::setIdentity(matCalib);

cv::Mat matRot(3, 1, CV_64F);
cv::Mat matTrans(3, 1, CV_64F);

cv::Mat matDistortion = cv::Mat::zeros(4, 1, CV_64F);

cv::solvePnP(vecUV, vecXYZ, matCalib, matDistortion, matRot, matTrans);

其中 vecUV 和 vecXYZ 的大小都是 4。这失败了:

OpenCV(3.4.1) Error: Assertion failed (( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, 5), ipoints.checkVector(2, 6))) in solvePnP, file /var/tmp/portage/media-libs/opencv-3.4.1-r5/work/opencv-3.4.1/modules/calib3d/src/solvepnp.cpp, line 65
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /var/tmp/portage/media-libs/opencv-3.4.1-r5/work/opencv-3.4.1/modules/calib3d/src/solvepnp.cpp:65: error: (-215) ( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, 5), ipoints.checkVector(2, 6)) in function solvePnP

我不明白为什么断言会失败,因为每个 vector 都有 4 个点。我尝试用 gdb 进入它,但无济于事:

...
(gdb) s
cv::_InputArray::init (this=0x7fffffffe350, _flags=-2130509811, _obj=0x7fffffffe2f0)
at /usr/include/opencv2/core/mat.inl.hpp:67
67 { flags = _flags; obj = (void*)_obj; }
(gdb) s
cv::_InputArray::_InputArray<cv::Point_<float> > (this=0x7fffffffe350,
vec=std::vector of length 4, capacity 4 = {...}) at /usr/include/opencv2/core/mat.inl.hpp:85
85 { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
(gdb) s
OpenCV(3.4.1) Error: Assertion failed (( (npoints >= 4) || (npoints == 3 && flags == SOLVEPNP_ITERATIVE && useExtrinsicGuess) ) && npoints == std::max(ipoints.checkVector(2, 5), ipoints.checkVector(2, 6))) in solvePnP, file /var/tmp/portage/media-libs/opencv-3.4.1-r5/work/opencv-3.4.1/modules/calib3d/src/solvepnp.cpp, line 65
terminate called after throwing an instance of 'cv::Exception'
0x00007ffff6e7334f in __gnu_cxx::__verbose_terminate_handler ()
from /usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/libstdc++.so.6

我已阅读 this ,米thisthis answer ,但情况似乎不同 - 错误的参数类型是罪魁祸首。

.zip with minimum reproducible example - 将输入文件作为第二个和第三个参数传递,第一个参数保留。

最佳答案

看看 OpenCV documentation .由于您使用的是 3.4.1 版本,因此 solvePnP 的文档是 here .

首先是objectPoints,然后是imagePoints

关于c++ - 关于点数的断言失败,在 OpenCV 的 solvePNP 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57997144/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com