【学习ARToolkit小记之八】 开发第一个ARToolkit程序(Developing your First Application)(续2)

接上一则: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)加载一个声明了多模板的文件;2)使用和模板相关联的的新的结构来指示不同的代码和转换方式;3)重新定义drew函数。


二、重要的函数和数据结构

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








评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值