No markers detected with aruco

asked 2020-05-21 06:14:44 -0600

Aquas gravatar image

Hello.

I've been trying to do a simple Marker finder with opencv aruco, but the program does not detect any (the std::cout outputs 0) even though it compiles. So I have no idea where the error can be. Here's the code:

#include <stdio.h>
#include <iostream>

#include <opencv2/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/imgcodecs.hpp>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "Euler.hpp"
#include <opencv2/aruco.hpp>

int main(int argc, char **argv)
{

    Mat img_scene = imread("/home/javier/pruebas/MasPruebas/Imagenes/Scene.jpg", IMREAD_COLOR );

     if( /*!img_object.data ||*/ !img_scene.data )
     { std::cout<< " --(!) Error reading images " << std::endl;}

     Mat CameraMatrix = (Mat_<double>(3,3) << 374.67,0,320.5,0,374.67,180.5,0,0,1);

     cv::aruco::Dictionary dictionary =   cv::aruco::getPredefinedDictionary(cv::aruco::DICT_ARUCO_ORIGINAL);

     std::vector<int> ids;
         std::vector<cv::Point2f> corners;

         cv::aruco::detectMarkers(img_scene, dictionary, corners, ids);
     std::cout<< ids.size() << std::endl;
    // if at least one marker detected
         if (ids.size() > 0) {
             cv::aruco::drawDetectedMarkers(img_scene, corners, ids);
             std::vector<cv::Vec3d> rvecs, tvecs;
             cv::aruco::estimatePoseSingleMarkers(corners, 0.05, CameraMatrix, cv::Mat(), rvecs, tvecs);
        // draw axis for each marker
             for(int i=0; i<ids.size(); i++)
                 cv::aruco::drawAxis(img_scene, CameraMatrix, cv::Mat(), rvecs[i], tvecs[i], 0.1);
         }
         cv::imshow("out", img_scene);

    cv::waitKey(0);
    return 0;

}

image description I'm using OpenCV3.1 as it is the one compatible with other projects I have right now.

edit retag flag offensive close merge delete

Comments

just to be sure: is the attached marker part of the DICT_ARUCO_ORIGINAL? Did you try with other markers?

kbarni gravatar imagekbarni ( 2020-05-22 04:31:34 -0600 )edit