OpenCV::solvePNP() - Assertion failed

后端 未结 3 1761
臣服心动
臣服心动 2021-01-16 01:28

I am trying to get the pose of the camera with the help of solvePNP() from OpenCV.

After running my program I get the following errors:

OpenCV Error:         


        
3条回答
  •  离开以前
    2021-01-16 01:59

    I run in exactly the same problem with solvePnP and opencv3. I tried to isolate the problem in a single test case. I seams passing a std::vector to cv::InputArray does not what is expected. The following small test works with opencv 2.4.9 but not with 3.2.

    And this is exactly the problem when passing a std::vector of points to solvePnP and causes the assert at line 63 in solvepnp.cpp to fail !

    Generating a cv::mat out of the vector list before passing to solvePnP works.

    //create list with 3 points
    std::vector vectorList;
    vectorList.push_back(cv::Point3f(1.0, 1.0, 1.0));
    vectorList.push_back(cv::Point3f(1.0, 1.0, 1.0));
    vectorList.push_back(cv::Point3f(1.0, 1.0, 1.0));
    
    //to input array
    cv::InputArray inputArray(vectorList);
    cv::Mat mat = inputArray.getMat();
    cv::Mat matDirect = cv::Mat(vectorList);
    
    LOG_INFO("Size vector: %d mat: %d matDirect: %d", vectorList.size(), mat.checkVector(3, CV_32F), matDirect.checkVector(3, CV_32F));
    
    QVERIFY(vectorList.size() == mat.checkVector(3, CV_32F));
    

    Result opencv 2.4.9 macos:

    TestObject: OpenCV
    Size vector: 3 mat: 3 matDirect: 3
    

    Result opencv 3.2 win64:

    TestObject: OpenCV
    Size vector: 3 mat: 9740 matDirect: 3
    

提交回复
热议问题