Ejemplo n.º 1
0
static void   init(int argc, char *argv[])
{
    ARParam         cparam;
    ARGViewport     viewport;
    ARPattHandle    *arPattHandle;
    char            vconf[512];
    AR_PIXEL_FORMAT pixFormat;
    ARUint32        id0, id1;
    int             i;

    if (argc == 1)
        vconf[0] = '\0';
    else
    {
        strcpy(vconf, argv[1]);

        for (i = 2; i < argc; i++)
        {
            strcat(vconf, " "); strcat(vconf, argv[i]);
        }
    }

    /* open the video path */
    if (arVideoOpen(vconf) < 0)
        exit(0);

    if (arVideoGetSize(&xsize, &ysize) < 0)
        exit(0);

    ARLOG("Image size (x,y) = (%d,%d)\n", xsize, ysize);
    if ((pixFormat = arVideoGetPixelFormat()) < 0)
        exit(0);

    if (arVideoGetId(&id0, &id1) == 0)
    {
        ARLOG("Camera ID = (%08x, %08x)\n", id1, id0);
        sprintf(vconf, VPARA_NAME, id1, id0);
        if (arVideoLoadParam(vconf) < 0)
        {
            ARLOGe("No camera setting data!!\n");
        }
    }

    /* set the initial camera parameters */
    if (arParamLoad(CPARA_NAME, 1, &cparam) < 0)
    {
        ARLOGe("Camera parameter load error !!\n");
        exit(0);
    }

    arParamChangeSize(&cparam, xsize, ysize, &cparam);
    ARLOG("*** Camera Parameter ***\n");
    arParamDisp(&cparam);
    if ((gCparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET)) == NULL)
    {
        ARLOGe("Error: arParamLTCreate.\n");
        exit(-1);
    }

    if ((arHandle = arCreateHandle(gCparamLT)) == NULL)
    {
        ARLOGe("Error: arCreateHandle.\n");
        exit(0);
    }

    if (arSetPixelFormat(arHandle, pixFormat) < 0)
    {
        ARLOGe("Error: arSetPixelFormat.\n");
        exit(0);
    }

    if ((ar3DHandle = ar3DCreateHandle(&cparam)) == NULL)
    {
        ARLOGe("Error: ar3DCreateHandle.\n");
        exit(0);
    }

    if ((arPattHandle = arPattCreateHandle()) == NULL)
    {
        ARLOGe("Error: arPattCreateHandle.\n");
        exit(0);
    }

    if ((patt_id = arPattLoad(arPattHandle, PATT_NAME)) < 0)
    {
        ARLOGe("pattern load error !!\n");
        exit(0);
    }

    arPattAttach(arHandle, arPattHandle);

    /* open the graphics window */
    w1             = argCreateWindow(xsize, ysize);
    viewport.sx    = 0;
    viewport.sy    = 0;
    viewport.xsize = xsize;
    viewport.ysize = ysize;
    if ((vp1 = argCreateViewport(&viewport)) == NULL)
        exit(0);

    argViewportSetCparam(vp1, &cparam);
    argViewportSetPixFormat(vp1, pixFormat);
    argViewportSetDispMethod(vp1, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME);
    argViewportSetDispMode(vp1, AR_GL_DISP_MODE_FIT_TO_VIEWPORT);
    argViewportSetDistortionMode(vp1, AR_GL_DISTORTION_COMPENSATE_ENABLE);

    w2             = argCreateWindow(xsize, ysize);
    viewport.sx    = 0;
    viewport.sy    = 0;
    viewport.xsize = xsize;
    viewport.ysize = ysize;
    if ((vp2 = argCreateViewport(&viewport)) == NULL)
        exit(0);

    argViewportSetCparam(vp2, &cparam);
    argViewportSetPixFormat(vp2, pixFormat);
    argViewportSetDispMethod(vp2, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME);
    argViewportSetDispMode(vp2, AR_GL_DISP_MODE_FIT_TO_VIEWPORT);
    argViewportSetDistortionMode(vp2, AR_GL_DISTORTION_COMPENSATE_DISABLE);

    return;
}
Ejemplo n.º 2
0
static void init( int argc, char *argv[] )
{
    char         vconf[256];
    ARGViewport  viewport;
    ARUint32     euid0, euid1;
    double       length;
    int          i, j;

	// Allow user to choose file version for backwards compatibility.
    ARLOG("A calibrated camera parameter file for ARToolKit will be produced.\n");
    ARLOG("The file can be generated to be backwards compatible with previous ARToolKit versions.\n");
    ARLOG("    1: ARToolKit v1.0 and later\n");
    ARLOG("    2: ARToolKit v4.0 and later\n");
    ARLOG("    3: ARToolKit v4.1 and later\n");
	printf("Enter the number (1 to %d) of the camera parameter file version: ", AR_DIST_FUNCTION_VERSION_MAX); 
	scanf("%d", &dist_function_version); while (getchar() != '\n');
	
	patt.h_num    = H_NUM;
    patt.v_num    = V_NUM;
    patt.loop_num = 0;
    if( patt.h_num < 3 || patt.v_num < 3 ) exit(0);

    printf("Input the distance between each marker dot, in millimeters: ");
    scanf("%lf", &length); while( getchar()!='\n' );
    patt.world_coord = (CALIB_COORD_T *)malloc( sizeof(CALIB_COORD_T)*patt.h_num*patt.v_num );
    for( j = 0; j < patt.v_num; j++ ) {
        for( i = 0; i < patt.h_num; i++ ) {
            patt.world_coord[j*patt.h_num+i].x_coord =  length * i;
            patt.world_coord[j*patt.h_num+i].y_coord =  length * j;
        }
    }

    if( argc == 1 ) {
        strcpy(vconf, VCONF);
    }
    else {
        strcpy(vconf, argv[1]);
        for( i = 2; i < argc; i++ ) {
            strcat(vconf, " ");
            strcat(vconf, argv[i]);
        }
    }
    if( arVideoOpen(vconf) < 0  ) exit(0);
    if( arVideoGetSize(&xsize, &ysize) < 0 ) exit(0);
    if( (pixelFormat=arVideoGetPixelFormat()) < 0 ) exit(0);
    if( (pixelSize=arVideoGetPixelSize()) < 0 ) exit(0);
    ARLOG("Camera image size (x,y) = (%d,%d)\n", xsize, ysize);

    viewport.sx = 0;
    viewport.sy = 0;
    viewport.xsize = xsize/SCALE;
    viewport.ysize = ysize/SCALE;
    if( (vp=argCreateViewport(&viewport)) == NULL ) exit(0);
    argViewportSetImageSize( vp, xsize, ysize );
    argViewportSetPixFormat( vp, pixelFormat );
    argViewportSetDispMethod( vp, AR_GL_DISP_METHOD_GL_DRAW_PIXELS );
    argViewportSetDispMode( vp, AR_GL_DISP_MODE_FIT_TO_VIEWPORT );
    argViewportSetDistortionMode( vp, AR_GL_DISTORTION_COMPENSATE_DISABLE );

    clipImage = (unsigned char *)malloc( xsize*ysize*pixelSize );
    if( clipImage == NULL ) exit(0);

    save_filename[0] = '\0';
    if( arVideoGetId(&euid0, &euid1) == 0 ) {
        sprintf(save_filename, "cpara.%08x%08x", euid0, euid1);
    }
}