[SOLVED] ar-detector : the program crash when it detects the marker

Post here to get support
Post Reply
PierreD
Beginner
Posts: 15
Joined: Fri Jul 01, 2016 8:44 am

[SOLVED] ar-detector : the program crash when it detects the marker

Post by PierreD »

I everybody !

I'm using xubuntu 16.04 (no vm).

I'm trying to make the crazyflie-ar-detector works (github : https://github.com/bitcraze/crazyflie-ar-detector) . I was able to calibrate my camera with the program "calibrate_camera_charuco" from opencv_contrib.
Moreover, the program "detect_markers" from opencv_contrib is perfectly working.

The program made by bitcraze is based on the program "detect_markers" form opencv_contrib :
opencv_contrib program https://github.com/opencv/opencv_contri ... arkers.cpp
bitcraze program https://github.com/bitcraze/crazyflie-a ... arkers.cpp
I've compiled the program "detect_markers" made by bitcraze, and it works if it doesn't detect any marker. But when it detects a marker (e.g. when I place the marker in front of the camera), the program stop working.

I get this error :
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in getMat_, file /home/pierre/projects/opencv/modules/core/src/matrix.cpp, line 1201
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pierre/projects/opencv/modules/core/src/matrix.cpp:1201: error: (-215) 0 <= i && i < (int)v.size() in function getMat_

Abandon (core dumped)
I searched a lot, and by comparing the code from the bitcraze program and the code from opencv_contrib, I noticed a change :
In the while loop, the vectors rvecs and tvecs are not the same type.
bitcraze version (line 284) :

Code: Select all

vector< Mat > rvecs, tvecs;
opencv_contrib version (line 177) :

Code: Select all

vector< Vec3d > rvecs, tvecs;
I think that the method used here (line 289) :

Code: Select all

aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs,
                                           tvecs);
has been changed since the release of the code by bitcraze.

With the original code form bitcraze I can compile and the program works until the method estimatePoseSingleMarkers(...) is called.
But if I changed the type of vector, I can't compile the program because of these lines (line 346) :

Code: Select all

          pos_x = tvecs[0].at<double>(0);
          pos_y = tvecs[0].at<double>(1);
          pos_z = tvecs[0].at<double>(2);
If tvecs is a vector<Vec3d>, the method .at can't be used.

To be sure of that, I've commented these lines and I was able to compile. Moreover the program detected the marker but with a position equal to (0,0,0) of course, because pos_x, pos_y and pos_z weren't changed.

A solution to this problem would be to install an older version of openCV3.
But it would be better to correct this problem !

Do you have any clue about this problem?
If you think that my problem is badly expressed, just ask me to rephrase or to add information.

Thanks,
Pierre
Last edited by PierreD on Fri Aug 19, 2016 12:53 pm, edited 1 time in total.
PierreD
Beginner
Posts: 15
Joined: Fri Jul 01, 2016 8:44 am

Re: ar-detector : the program crash when it detects the marker

Post by PierreD »

I finally found how to make it works !
In the bitcraze code I changed the type of tvecs :

Code: Select all

          vector< Vec3d > rvecs, tvecs;
Then, I changed the way the values are picked. Instead of :

Code: Select all

          pos_x = tvecs[0].at<double>(0);
          pos_y = tvecs[0].at<double>(1);
          pos_z = tvecs[0].at<double>(2);
I wrote :

Code: Select all

          cx = tvecs[i][0];;
          cy = tvecs[i][1];;
          cz = tvecs[i][2];
These are the main modifications, if you want to see more, you can take a look here :
https://github.com/Darkwa/crazyflie-ar- ... 4b1c5b7e3a

The funny thing is that almost all the code I modified seems not to be necessary. :D
It's basically some printing to see the values in the console.

Now the crazyflie keep crashing but at least it is properly detected, and the ZMQ commands are sent. :mrgreen:
Post Reply