Hello Everyone,
I am currently working on a project which requires marker detection and then over laying it with some other image. I am not able to understand how marker detection works and how can I program it with OpenCV. The ARToolkit examples are in OpenGL but I need my program to be in OpenCV.
The problem is I am not able to under stand how do I detect the marker and get its co- ordinates.
I have attached my code Please guide me on what should I do next I just need to learn to detect a marker any marker would do.
int pattID = 0;
char *patt_name = "Data/patt.hiro";
double patt_width = 80.0;
double patt_center[2] = {0.0, 0.0};
double patt_trans[3][4];
int main()
{
CvCapture* capture = cvCaptureFromCAM(0);
if(!capture)
{
printf("No Cam Connected");
getch();
return -1;
}
IplImage* frame = cvQueryFrame(capture);
//Load (default) camera parameters
ARParam cameraParam;
if(arParamLoad("camera_para.dat",1,&cameraParam) < 0)
{
printf("Camera calibration parameters file Load Error\n");
getch();
return -1;
}
//Initalize Camera Parameters
arInitCparam(&cameraParam);
//Load Hiro Pattern
if((pattID = arLoadPatt(patt_name)) < 0)
{
printf("Pattern File Load Error");
getch();
return -1;
}
while(1)
{
ARMarkerInfo* markerInfo = NULL;
int markerNum = -1;
IplImage* img = cvQueryFrame(capture);
//Code for Resizing of image
/* input new width and height.
arParamChangeSize(&cameraParam, frame.rows, frame.cols, &cameraParam);
*/
// Marker Detection
if (arDetectMarker((ARUint8 *)frame->imageData, 150, &markerInfo, &markerNum) < 0)
{
printf("Marker Detector Error");
getch();
return -1;
}
//Check which one of the found markers is the one we seek
int k = -1;
for (int i = 0; i < markerNum; i++)
{
if (pattID == markerInfo[i].id)
{
if (k == -1)
{
k = i;
}
else if (markerInfo[k].cf < markerInfo[i].cf)
{
k = i;
}
}
}
//Please Let me know how to proceed further in this code. }