Ask Your Question

OpenCV Assertion failed when using perspective transform

asked 2015-04-11 08:51:31 -0600

mirind4 gravatar image

Hey all! I am using Aruco AR library to make a project. My project is based on the following concept: I would like do define the camera position in world coordinates system using AR markers. The markers positions are known in world coordinate system. If I could define the distance of each markers relating to my camera I could define the world coordinates of my camera. For this purpose I would need to define minimum two markers coordinates. In this way I would get two result coordinates of the camera, so for the proper solution I would need three detected markers with the distance estimations.

I have successfully done the marker detection, and I also can draw f.e a cube on them, so the the camera calibration is valid, and everything works fine. I have the following problem. When I try to use the cv::projectPoints function, i got the following errors:

OpenCV Error: Assertion failed (npoints >= 0 && (depth == CV_32F || depth == CV_64F)) in projectPoints, file /home/mirind4/DiplomaMSC/OpenCV/opencv-2.4.10/modules/calib3d/src/calibration.cpp, line 3349
Exception :/home/mirind4/DiplomaMSC/OpenCV/opencv-2.4.10/modules/calib3d/src/calibration.cpp:3349: error: (-215) npoints >= 0 && (depth == CV_32F || depth == CV_64F) in function projectPoints

I tried to find solution for this error, and I have found a seemingly good one Link to the question, but in my code I do not know how to define the type of datas to "CvType.CV_32FC2"

I would like to ask two question: What would you advise for this error? Do you think that my concept of the camera pose estimation is good?

Thanks in advance!

My source code is the following: (I am using the Aruco with python, so that's why you can see the "BOOST_PYTHON_MODULE" part at the end of it.

#include <iostream>
#include <aruco/aruco.h>
#include <aruco/cvdrawingutils.h>
#include <opencv2/highgui/highgui.hpp>
#include <fstream>
#include <sstream>
#include <boost/python.hpp>

using namespace cv;
using namespace aruco;

string TheInputVideo;
string TheIntrinsicFile;
float TheMarkerSize=45;
int ThePyrDownLevel;
MarkerDetector MDetector;
VideoCapture TheVideoCapturer;
vector<Marker> TheMarkers;
//projected points vector
std::vector<cv::Point2f> projectedPoints;

Mat TheInputImage,TheInputImageCopy;
CameraParameters TheCameraParameters;
void cvTackBarEvents(int pos,void*);
bool readCameraParameters(string TheIntrinsicFile,CameraParameters &CP,Size size);

pair<double,double> AvrgTime(0,0) ;//determines the average time required for detection
double ThresParam1,ThresParam2;
int iThresParam1,iThresParam2;
int waitTime=0;

void Init(){
    int vIdx = 1;
    cout<<"Opening camera index "<<vIdx<<endl;;


    //Camera paramteres
        cout<<"Camera paramteres valid? : " << TheCameraParameters.isValid()<<endl<<std::flush;
    //Create gui
        MDetector.getThresholdParams( ThresParam1,ThresParam2);       
        cv::createTrackbar("ThresParam1", "in",&iThresParam1, 13, cvTackBarEvents);
        cv::createTrackbar("ThresParam2", "in",&iThresParam2, 13, cvTackBarEvents);

int yay()

            char key=0;
            //capture until press ESC or until the end of the video
            TheVideoCapturer.retrieve( TheInputImage);

            //Detection of markers in the image passed
                    MDetector.detect(TheInputImage,TheMarkers,TheCameraParameters ...
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-04-19 05:19:48 -0600

sgarrido gravatar image

updated 2015-04-19 05:34:05 -0600


in this line:




TheMarkers[i] is a std::vector<cv::Point2f> (aruco::Marker inherits from std::vector<cv::Point2f> ), i.e. a vector composed by the 2D coordinates of the four marker's corners in the image.

You are trying to project 2D points, which is probably producing the error.

Anyway, I dont see the point of your project. You say you want to "define the camera position in world coordinates system using AR markers". You already have this information in TheMarkers[i].Rvec and TheMarkers[i].Tvec.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-11 08:51:31 -0600

Seen: 2,257 times

Last updated: Apr 19 '15