1

Hello I am getting an error when using aruco. I am just trying to get an example from the tutorial working. I did everything according to the tutorial but I get:

    /home/pi/Programs/markerDetection/markerDetection.cpp: In function ‘int main(int, char**)’:
/home/pi/Programs/markerDetection/markerDetection.cpp:26:104: error: invalid initialization of reference of type ‘cv::Ptr<cv::aruco::Dictionary>&’ from expression of type ‘cv::aruco::Dictionary’
   aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);
                                                                                                        ^
In file included from /home/pi/Programs/markerDetection/markerDetection.cpp:6:0:
/home/pi/opencv/include/opencv2/aruco.hpp:176:19: note: in passing argument 2 of ‘void cv::aruco::detectMarkers(cv::InputArray, cv::Ptr<cv::aruco::Dictionary>&, cv::OutputArrayOfArrays, cv::OutputArray, const cv::Ptr<cv::aruco::DetectorParameters>&, cv::OutputArrayOfArrays)’
 CV_EXPORTS_W void detectMarkers(InputArray image, Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
                   ^
CMakeFiles/marker.dir/build.make:54: recipe for target 'CMakeFiles/marker.dir/markerDetection.cpp.o' failed
make[2]: *** [CMakeFiles/marker.dir/markerDetection.cpp.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/marker.dir/all' failed
make[1]: *** [CMakeFiles/marker.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

My code is:

#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/aruco.hpp"
#include <vector>

using namespace cv;
using namespace std;

int main (int argc, char** argv)
{
        VideoCapture cap;

        if(!cap.open(0)){
                return 0;
        }
        for(;;){
                Mat inputImage;
                cap >> inputImage;
                vector< int > markerIds;
                vector< vector<Point2f> > markerCorners, rejectedCandidates;
                aruco::DetectorParameters parameters;
                aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
                aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);
                Mat outputImage;
                aruco::drawDetectedMarkers(outputImage, markerCorners, markerIds);
                if(inputImage.empty()) break;
                imshow("Webcam", outputImage);
                if(waitKey(1) >= 0) break;
        }

        return 0;
}

I know there are too many includes and the code needs some work but I just need it to compile and I have no idea what is happening there. Has the function changed?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Martinator
  • 176
  • 2
  • 8
  • Can you include the exception are you getting when trying to compile? – Tah Apr 03 '16 at 22:08
  • 1
    @TahTatsumoto it's up at the top of the question. From the error message it appears one must wrap the dictionary in a `cv::Ptr` and unless they're partaking in some buffoonery, [that doesn't quite jive with what I see in the recent documentation](http://docs.opencv.org/3.1.0/d9/d6a/group__aruco.html#ga306791ee1aab1513bc2c2b40d774f370&gsc.tab=0). I also don't see aruco in the 3.0 docs, so it could be thrashing about in early development. – user4581301 Apr 03 '16 at 22:19
  • Hey, I included `cv::Ptr dictionaryPtr(&dictionary)` and the same for parameters and used that in the function. Now it works, but I still have trouble with it since I get an `numpad_chunk() : invalid pointer ...` when the program ends. I know I am using the Ptr wrong, but I have no idea what is going on. – Martinator Apr 06 '16 at 22:09

3 Answers3

1

The following code works for me:

Dictionary declaration:

cv::Ptr<cv::aruco::Dictionary> dictionary =   cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);

As the function getPredefinedDictionary returns a Ptr<Dictionary> (http://docs.opencv.org/trunk/d9/d6a/group__aruco.html)

To detect markers:

cv::aruco::detectMarkers(gray, dictionary, marker_corners, marker_ids);
Ivan
  • 168
  • 1
  • 6
0

I had the same problem as you. Here is what did the trick:

instead of:

aruco::DetectorParameters parameters;
aruco::Dictionary dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250);

use:

cv::Ptr<aruco::DetectorParameters> parameters;
cv::Ptr<aruco::Dictionary> dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250);

I hope it helps you.

JuarezASF
  • 11
  • 5
0

I was missing some include files. These are the ones I have now:

#include "opencv2/aruco.hpp"
#include <iostream>
#include <stdio.h>
#include <opencv2/highgui.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/videoio/videoio.hpp"
#include <vector>

And the libraries are (these are included in Project-> Properties->settings->Linker->Input ):

opencv_core450.lib
opencv_highgui450.lib
opencv_objdetect450.lib
opencv_videoio450.lib
opencv_imgproc450.lib
opencv_imgcodecs450.lib
opencv_aruco450.lib
opencv_core450d.lib
opencv_highgui450d.lib
opencv_objdetect450d.lib
opencv_videoio450d.lib
opencv_imgproc450d.lib
opencv_imgcodecs450d.lib
opencv_aruco450d.lib

The opencv_aruco450.lib was not getting properly saved as far as I know. This was my problem.

Connell.O'Donnell
  • 3,603
  • 11
  • 27
  • 61
holouser
  • 172
  • 11