A question about alvar marker detector

Aug 13, 2012 at 4:30 PM
Edited Aug 13, 2012 at 4:31 PM

Hello everyone!

I have a question about the marker detector in ALVAR 2.0.0. I want to detect markers in a single image. My question is as follows:

I load an image with 21 detectable markers, and the output of function "marker_detector.Detect(image, &cam, false, true)" is 21, but why the "marker_detector.markers->size()" is 6?

I looked at the source code of MarkerDetector.cpp, and I think these two outputs should be the same, since each visualized marker is pushed back into the vector.

Why only 6 markers are pushed into the vector "marker"?

Thank you very much for your help!

Best regards

Jiaxiang Zhang

Rensselaer polytechnic institute


In the following is my code:


#include "stdafx.h"

#include "cv.h"

#include "cxcore.h"

#include "highgui.h"

#include "MarkerDetector.h"

#include <iostream>

#include "Camera.h"

using namespace cv;

using namespace alvar;

using namespace std;

int _tmain(int argc, char* argv[])


       //load image

       IplImage* image = cvLoadImage( "MyImage.bmp" );

       bool flip_image = (image->origin?true:false);

       if (flip_image) {


        image->origin = !image->origin;


       //initialize cam

       char calibrationFilename[] = "default_calib.xml";//the .xml is modified to match the webcam

       Camera cam;

       if (cam.SetCalib(calibrationFilename, image->width, image->height))

       {cout<<"camera calibration file loaded"<<endl; }


       //initialize marker detector

       MarkerDetector<MarkerData> marker_detector;

       marker_detector.SetMarkerSize(1, 5, 1.7); //my marker resolution is 5x5

       //these two output does not match, why?

       std::cout<<"1. detected markers: "<<marker_detector.Detect(image, &cam, false, true)<<endl;

      std::cout<<"2. marker vector size: "<<marker_detector.markers->size()<<endl;

       //display the image with red cubes, which is corect

       cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );

       cvShowImage("Example1", image);


       cvReleaseImage( &image );

       cvDestroyWindow( "Example1" );

       return 0;


And here is the output of the code:

1. detected markers:  21

2. marker vector size: 6

Aug 13, 2012 at 10:17 PM

You should send ALVAR related questions to VTT. We do not develop ALVAR.