接上一则:ARToolkit(7):开发第一个ARToolkit程序(Developing your First Application)(续1)(http://blog.csdn.net/qingyang8513/article/details/45363321)
这部分内容为多个标记块的使用(Using Multiple Patterns),官网的教程显示程序来源于examples/simplem/文件夹下的simplemTest.c 和 object.c两个文件,可是我的版本的ARToolkit里面只有钱一个,不过其他文件夹中却能够找到objec.c,如ARToolKit\examples\loadMultiple文件夹下,下面介绍一下官网中的主要内容:
一、和单个模板相比较的不同点
下面是官网给出的不同点:
1、loading of a file with the declaration of multiple pattern.
2、a new structure associate to the patterns that imply a different checking code and transformation call in your program.
3、a redefinition of the syntax and the definition of the draw function.
二、重要的函数和数据结构
1、重要的函数:read_ObjData(),调用方式如下:
if( (object=read_ObjData(model_name, &objectnum)) == NULL ) exit(0);
printf("Objectfile num = %d\n", objectnum);
其中,object是指向ObjectData_T结构体的指针;model_name是特定的含有多模板定义的文件名,程序中使用的是object_data文件,详细结构如2中所述。
2、重要的数据结构
ObjectData_T结构体
typedef struct {
char name[256];
int id;
int visible;
int collide;
double marker_coord[4][2];
double trans[3][4];
double marker_width;
double marker_center[2];
} ObjectData_T;
3、重要的文件结构
object_data
Name
Pattern Recognition File Name
Width of tracking marker
Center of tracking marker
如:
#pattern 1
cone
Data/patt.hiro
80.0
0.0 0.0
下面是模板的识别和渲染:
/* check for known patterns */
<span style="white-space:pre"> </span>for( i = 0; i < objectnum; i++ ) {
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( object[i].id == marker_info[j].id) {
/* you've found a pattern */
//printf("Found pattern: %d ",patt_id);
glColor3f( 0.0, 1.0, 0.0 );
argDrawSquare(marker_info[j].vertex,0,0);
if( k == -1 ) k = j;
else /* make sure you have the best pattern (highest confidence factor) */
if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
object[i].visible = 0;
continue;
}
/* calculate the transform for each marker */
if( object[i].visible == 0 ) {
arGetTransMat(&marker_info[k],
object[i].marker_center, object[i].marker_width,
object[i].trans);
}
else {
arGetTransMatCont(&marker_info[k], object[i].trans,
object[i].marker_center, object[i].marker_width,
object[i].trans);
}
object[i].visible = 1;
}
arVideoCapNext();
/* draw the AR graphics */
<span style="white-space:pre"> </span> draw( object, objectnum );
/*swap the graphics buffers*/
argSwapBuffers();
三、测试
1、打印模板:pattHiro和pattKanji(ARToolKit\patterns\);
2、运行程序:loadMultiple.exe(ARToolKit\bin\);
3、将模板放在摄像头前进行测试,结果如下图所示:
图1 多模板识别
四、主要参考
1、官网教程:Documentation --- Developing your First Application, Part 2(http://www.hitl.washington.edu/artoolkit/documentation/devmulti.htm)