Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;OpenCV 4.4.0 solvePnP错误:(-215:断言失败)_C++_Opencv_Opencv Solvepnp - Fatal编程技术网

C++ C++;OpenCV 4.4.0 solvePnP错误:(-215:断言失败)

C++ C++;OpenCV 4.4.0 solvePnP错误:(-215:断言失败),c++,opencv,opencv-solvepnp,C++,Opencv,Opencv Solvepnp,我正试图编写一个简单的增强现实程序,在给定和输出视频和相机的内在参数后,将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>

我正试图编写一个简单的增强现实程序,在给定和输出视频和相机的内在参数后,将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&&flags==solvepnp_迭代和使用外部cguess))&&npoints==std::max(ipoints.checkVector(2,cv32f),ipoints.checkVector(2,cv64f))

这是我的代码:

#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.0),Point3f(0.0,0.0,0.1), Point3f(0.1,0.0,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, corners, 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, corners, camera_matrix, distortion_coefficients, rvec, tvec); 
       
  cout<<"Extrinsic params calculated"<<endl;


  cv::projectPoints(axis, rvec, tvec, camera_matrix, distortion_coefficients, 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,0,0), 3,8);
}
        imshow("image", image);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main(int,char**)
{
VideoCapture cap(“./video.mp4”);//打开默认摄像机
if(!cap.isopend())//检查我们是否成功
返回-1;
Mat图像;
大小图案大小(9,6);//内部角数
矢量角点;
向量轴={Point3f(0.0,0.0,0.0),Point3f(0.0,0.1,0.0),Point3f(0.0,0.0,0.1),Point3f(0.1,0.0,0.0)};
FileStorage fs(“intrinsics.yml”,FileStorage::READ);
如果(!fs.isOpened())
{
cerr>frame;//从摄影机获取新帧
CVT颜色(框架、图像、颜色和灰色);
bool patternfound=findChessboardCorners(图像、图案大小、角、,
CALIB_CB_自适应阈值+CALIB_CB_归一化图像
+校准(CB快速检查);
如果(找到模式)拐角子像素(图像、拐角、尺寸(11,11)、尺寸(-1,-1)、术语标准(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,0.1));
else{cerr