问题描述
我正在尝试编写一个简单的增强现实程序,该程序在给定并输出视频和摄像机固有参数的情况下,将3行投影到每个视频帧中。这些线是x,y和z轴。
我不是在寻求程序本身而是在SolvePnP函数方面寻求帮助,因为我只是不明白自己在做什么以得到此错误:
抛出'cv :: Exception'实例后调用terminate what():OpenCV(4.4.0)/home/nel/opencv-4.4.0/modules/calib3d/src/solvepnp.cpp:753:错误:(-215:断言失败)((npoints> = 4)| |(npoints == 3 &&标志== SOLVEPNP_IteraTIVE && useExtrinsicGuess))&& npoints == std :: max(ipoints.checkVector(2,CV_32F),ipoints.checkVector(2,CV_64F))在函数'solvePnPGeneric'
这是我的代码:
#include <vector>
#include <opencv2/highgui/highgui_c.h>
using namespace cv;
using namespace std;
int main(int,char**)
{
VideoCapture cap("./video.mp4"); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat image;
Size patternsize(9,6); //interior number of corners
vector<Point2f> corners;
vector<Point3f> axis={Point3f(0.0,0.0,0.0),Point3f(0.0,0.1,0.1),Point3f(0.1,0.0)};
FileStorage fs("intrinsics.yml",FileStorage::READ);
if (!fs.isOpened())
{
cerr << "Failed to open " << "intrinsic.yml" << endl;
return 0;
}
Mat camera_matrix,distortion_coefficients;
cout << "reading R and T" << endl;
fs["camera_matrix"] >> camera_matrix;
fs["distortion_coefficients"] >> distortion_coefficients;
fs.release();
for(;;)
{
Mat frame;
Mat rvec,tvec,points2d;
cap >> frame; // get a new frame from camera
cvtColor(frame,image,COLOR_BGR2GRAY);
bool patternfound = findChessboardCorners(image,patternsize,corners,CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_norMALIZE_IMAGE
+ CALIB_CB_FAST_CHECK);
if(patternfound) cornerSubPix(image,Size(11,11),Size(-1,-1),TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER,30,0.1));
else{cerr<<"Error: pattern not found"<<endl;return 0;}
cv::solvePnP(axis,camera_matrix,distortion_coefficients,rvec,tvec);
cout<<"Extrinsic params calculated"<<endl;
cv::projectPoints(axis,points2d);
MatIterator_<double> it,end;
for( it = points2d.begin<double>(),end = points2d.end<double>(); it != end; ++it)
{
cv::line(image,(Point)points2d.at<double>(0,0),(Point)*it,(255,3,8);
}
imshow("image",image);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)