djoele
June 15th, 2005, 04:52 PM
We have a camera with a large field of view. We want to simulate a
camera with a smaller field of view. I?m able to change the markerInfo structure so that the found marker is the same as would be seen by a
camera with a small field of view. When I run ARToolkit it also draws virtual object in the same way as normally would be seen by a camera with a smaller angle. But I have the problem that once in a while the object is drawn on the marker and once in a while the scaled object is drawn. I would like it to be drawn scaled always. Anybody has an idea what I?m doing wrong? Maybe it has something to do with videoCapNext? I scale with a factor 2 in the x and y direction. The image is 640*480.This is my code:
static void mainLoop(void)
{
ARUint8 *dataPtr;
ARMarkerInfo *marker_info;
int marker_num;
int j, k;
/* grab a vide frame */
if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
arUtilSleep(2);
return;
}
argDrawMode2D();
argDispImage( dataPtr, 0,0 );
/* detect the markers in the video frame */
if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
cleanup();
exit(0);
}
//change centre coordinate and coordinates of the vertices
//of the found marker
marker_info->pos[0]=2.0*(marker_info->pos[0]-160);
marker_info->pos[1]=2.0*(marker_info->pos[1]-120);
marker_info->vertex[0][0]=2.0*(marker_info->vertex[0][0]-160);
marker_info->vertex[0][1]=2.0*(marker_info->vertex[0][1]-120);
marker_info->vertex[1][0]=2.0*(marker_info->vertex[1][0]-160);
marker_info->vertex[1][1]=2.0*(marker_info->vertex[1][1]-120);
marker_info->vertex[2][0]=2.0*(marker_info->vertex[2][0]-160);
marker_info->vertex[2][1]=2.0*(marker_info->vertex[2][1]-120);
marker_info->vertex[3][0]=2.0*(marker_info->vertex[3][0]-160);
marker_info->vertex[3][1]=2.0*(marker_info->vertex[3][1]-120);
//change a and b of the line equations of the four sides
//of the found marker
marker_info->line[0][0]=marker_info->line[0][0]/2.0;
marker_info->line[0][1]=marker_info->line[0][1]/2.0;
marker_info->line[1][0]=marker_info->line[1][0]/2.0;
marker_info->line[1][1]=marker_info->line[1][1]/2.0;
marker_info->line[2][0]=marker_info->line[2][0]/2.0;
marker_info->line[2][1]=marker_info->line[2][1]/2.0;
marker_info->line[3][0]=marker_info->line[3][0]/2.0;
marker_info->line[3][1]=marker_info->line[3][1]/2.0;
arVideoCapNext();
/* check for object visibility */
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( patt_id == marker_info[j].id ) {
if( k == -1 ) k = j;
else if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
argSwapBuffers();
return;
}
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
draw( patt_trans );
argSwapBuffers();
}
camera with a smaller field of view. I?m able to change the markerInfo structure so that the found marker is the same as would be seen by a
camera with a small field of view. When I run ARToolkit it also draws virtual object in the same way as normally would be seen by a camera with a smaller angle. But I have the problem that once in a while the object is drawn on the marker and once in a while the scaled object is drawn. I would like it to be drawn scaled always. Anybody has an idea what I?m doing wrong? Maybe it has something to do with videoCapNext? I scale with a factor 2 in the x and y direction. The image is 640*480.This is my code:
static void mainLoop(void)
{
ARUint8 *dataPtr;
ARMarkerInfo *marker_info;
int marker_num;
int j, k;
/* grab a vide frame */
if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
arUtilSleep(2);
return;
}
argDrawMode2D();
argDispImage( dataPtr, 0,0 );
/* detect the markers in the video frame */
if( arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
cleanup();
exit(0);
}
//change centre coordinate and coordinates of the vertices
//of the found marker
marker_info->pos[0]=2.0*(marker_info->pos[0]-160);
marker_info->pos[1]=2.0*(marker_info->pos[1]-120);
marker_info->vertex[0][0]=2.0*(marker_info->vertex[0][0]-160);
marker_info->vertex[0][1]=2.0*(marker_info->vertex[0][1]-120);
marker_info->vertex[1][0]=2.0*(marker_info->vertex[1][0]-160);
marker_info->vertex[1][1]=2.0*(marker_info->vertex[1][1]-120);
marker_info->vertex[2][0]=2.0*(marker_info->vertex[2][0]-160);
marker_info->vertex[2][1]=2.0*(marker_info->vertex[2][1]-120);
marker_info->vertex[3][0]=2.0*(marker_info->vertex[3][0]-160);
marker_info->vertex[3][1]=2.0*(marker_info->vertex[3][1]-120);
//change a and b of the line equations of the four sides
//of the found marker
marker_info->line[0][0]=marker_info->line[0][0]/2.0;
marker_info->line[0][1]=marker_info->line[0][1]/2.0;
marker_info->line[1][0]=marker_info->line[1][0]/2.0;
marker_info->line[1][1]=marker_info->line[1][1]/2.0;
marker_info->line[2][0]=marker_info->line[2][0]/2.0;
marker_info->line[2][1]=marker_info->line[2][1]/2.0;
marker_info->line[3][0]=marker_info->line[3][0]/2.0;
marker_info->line[3][1]=marker_info->line[3][1]/2.0;
arVideoCapNext();
/* check for object visibility */
k = -1;
for( j = 0; j < marker_num; j++ ) {
if( patt_id == marker_info[j].id ) {
if( k == -1 ) k = j;
else if( marker_info[k].cf < marker_info[j].cf ) k = j;
}
}
if( k == -1 ) {
argSwapBuffers();
return;
}
arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
draw( patt_trans );
argSwapBuffers();
}