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              *vconfL = NULL;
    char              *vconfR = NULL;
    char              *cparaL = NULL;
    char              *cparaR = NULL;
    char               cparaLDefault[] = "Data/cparaL.dat";
    char               cparaRDefault[] = "Data/cparaR.dat";

    ARParam            wparam;
    ARGViewport        viewport;
    int                i, j;
    int                gotTwoPartOption;
    int                screenWidth, screenHeight, screenMargin;
    double             wscalef, hscalef, scalef;

    chessboardCornerNumX = 0;
    chessboardCornerNumY = 0;
    calibImageNum        = 0;
    patternWidth         = 0.0f;

    i = 1; // argv[0] is name of app, so start at 1.
    while (i < argc) {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc) {
            if (strcmp(argv[i], "--vconfL") == 0) {
                i++;
                vconfL = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--vconfR") == 0) {
                i++;
                vconfR = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cparaL") == 0) {
                i++;
                cparaL = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cparaR") == 0) {
                i++;
                cparaR = argv[i];
                gotTwoPartOption = TRUE;
            }
        }
        if (!gotTwoPartOption) {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
                usage(argv[0]);
            } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            } else if( strncmp(argv[i], "-cornerx=", 9) == 0 ) {
                if( sscanf(&(argv[i][9]), "%d", &chessboardCornerNumX) != 1 ) usage(argv[0]);
                if( chessboardCornerNumX <= 0 ) usage(argv[0]);
            } else if( strncmp(argv[i], "-cornery=", 9) == 0 ) {
                if( sscanf(&(argv[i][9]), "%d", &chessboardCornerNumY) != 1 ) usage(argv[0]);
                if( chessboardCornerNumY <= 0 ) usage(argv[0]);
            } else if( strncmp(argv[i], "-imagenum=", 10) == 0 ) {
                if( sscanf(&(argv[i][10]), "%d", &calibImageNum) != 1 ) usage(argv[0]);
                if( calibImageNum <= 0 ) usage(argv[0]);
            } else if( strncmp(argv[i], "-pattwidth=", 11) == 0 ) {
                if( sscanf(&(argv[i][11]), "%f", &patternWidth) != 1 ) usage(argv[0]);
                if( patternWidth <= 0 ) usage(argv[0]);
            } else if( strncmp(argv[i], "-cparaL=", 8) == 0 ) {
                cparaL = &(argv[i][8]);
            } else if( strncmp(argv[i], "-cparaR=", 8) == 0 ) {
                cparaR = &(argv[i][8]);
            } else {
                ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                usage(argv[0]);
            }
        }
        i++;
    }

    if( chessboardCornerNumX == 0 ) chessboardCornerNumX = CHESSBOARD_CORNER_NUM_X;
    if( chessboardCornerNumY == 0 ) chessboardCornerNumY = CHESSBOARD_CORNER_NUM_Y;
    if( calibImageNum == 0 )        calibImageNum = CALIB_IMAGE_NUM;
    if( patternWidth == 0.0f )      patternWidth = (float)CHESSBOARD_PATTERN_WIDTH;
    if (!cparaL) cparaL = cparaLDefault;
    if (!cparaR) cparaR = cparaRDefault;
    ARLOG("CHESSBOARD_CORNER_NUM_X = %d\n", chessboardCornerNumX);
    ARLOG("CHESSBOARD_CORNER_NUM_Y = %d\n", chessboardCornerNumY);
    ARLOG("CHESSBOARD_PATTERN_WIDTH = %f\n", patternWidth);
    ARLOG("CALIB_IMAGE_NUM = %d\n", calibImageNum);
    ARLOG("Video parameter Left : %s\n", vconfL);
    ARLOG("Video parameter Right: %s\n", vconfR);
    ARLOG("Camera parameter Left : %s\n", cparaL);
    ARLOG("Camera parameter Right: %s\n", cparaR);

    if( (vidL=ar2VideoOpen(vconfL)) == NULL ) {
        ARLOGe("Cannot found the first camera.\n");
        exit(0);
    }
    if( (vidR=ar2VideoOpen(vconfR)) == NULL ) {
        ARLOGe("Cannot found the second camera.\n");
        exit(0);
    }
    if( ar2VideoGetSize(vidL, &xsizeL, &ysizeL) < 0 ) exit(0);
    if( ar2VideoGetSize(vidR, &xsizeR, &ysizeR) < 0 ) exit(0);
    if( (pixFormatL=ar2VideoGetPixelFormat(vidL)) < 0 ) exit(0);
    if( (pixFormatR=ar2VideoGetPixelFormat(vidR)) < 0 ) exit(0);
    ARLOG("Image size for the left camera  = (%d,%d)\n", xsizeL, ysizeL);
    ARLOG("Image size for the right camera = (%d,%d)\n", xsizeR, ysizeR);

    if( arParamLoad(cparaL, 1, &wparam) < 0 ) {
        ARLOGe("Camera parameter load error !!   %s\n", cparaL);
        exit(0);
    }
    arParamChangeSize( &wparam, xsizeL, ysizeL, &paramL );
    ARLOG("*** Camera Parameter for the left camera ***\n");
    arParamDisp( &paramL );
    if( arParamLoad(cparaR, 1, &wparam) < 0 ) {
        ARLOGe("Camera parameter load error !!   %s\n", cparaR);
        exit(0);
    }
    arParamChangeSize( &wparam, xsizeR, ysizeR, &paramR );
    ARLOG("*** Camera Parameter for the right camera ***\n");
    arParamDisp( &paramR );

    screenWidth = glutGet(GLUT_SCREEN_WIDTH);
    screenHeight = glutGet(GLUT_SCREEN_HEIGHT);
    if (screenWidth > 0 && screenHeight > 0) {
        screenMargin = (int)(MAX(screenWidth, screenHeight) * SCREEN_SIZE_MARGIN);
        if ((screenWidth - screenMargin) < (xsizeL + xsizeR) || (screenHeight - screenMargin) < MAX(ysizeL, ysizeR)) {
            wscalef = (double)(screenWidth - screenMargin) / (double)(xsizeL + xsizeR);
            hscalef = (double)(screenHeight - screenMargin) / (double)MAX(ysizeL, ysizeR);
            scalef = MIN(wscalef, hscalef);
            ARLOG("Scaling %dx%d window by %0.3f to fit onto %dx%d screen (with %2.0f%% margin).\n", xsizeL + xsizeR, MAX(ysizeL, ysizeR), scalef, screenWidth, screenHeight, SCREEN_SIZE_MARGIN*100.0);
        } else {
            scalef = 1.0;
        }
    } else {
        scalef = 1.0;
    }

    /* open the graphics window */
    if( argCreateWindow((int)((xsizeL + xsizeR)*scalef), (int)(MAX(ysizeL, ysizeR)*scalef)) < 0 ) {
        ARLOGe("Error: argCreateWindow.\n");
        exit(0);
    }
    viewport.sx = 0;
    viewport.sy = 0;
    viewport.xsize = (int)(xsizeL*scalef);
    viewport.ysize = (int)(ysizeL*scalef);
    if( (vpL=argCreateViewport(&viewport)) == NULL ) {
        ARLOGe("Error: argCreateViewport.\n");
        exit(0);
    }
    viewport.sx = (int)(xsizeL*scalef);
    viewport.sy = 0;
    viewport.xsize = (int)(xsizeR*scalef);
    viewport.ysize = (int)(ysizeR*scalef);
    if( (vpR=argCreateViewport(&viewport)) == NULL ) {
        ARLOGe("Error: argCreateViewport.\n");
        exit(0);
    }
    argViewportSetPixFormat( vpL, pixFormatL );
    argViewportSetPixFormat( vpR, pixFormatR );
    argViewportSetCparam( vpL, &paramL );
    argViewportSetCparam( vpR, &paramR );
    argViewportSetDispMethod( vpL, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME );
    argViewportSetDispMethod( vpR, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME );
    argViewportSetDispMode(vpL, AR_GL_DISP_MODE_FIT_TO_VIEWPORT_KEEP_ASPECT_RATIO);
    argViewportSetDispMode(vpR, AR_GL_DISP_MODE_FIT_TO_VIEWPORT_KEEP_ASPECT_RATIO);


    calibImageL = cvCreateImage( cvSize(xsizeL, ysizeL), IPL_DEPTH_8U, 1);
    calibImageR = cvCreateImage( cvSize(xsizeR, ysizeR), IPL_DEPTH_8U, 1);
    arMalloc(cornersL, CvPoint2D32f, chessboardCornerNumX*chessboardCornerNumY);
    arMalloc(cornersR, CvPoint2D32f, chessboardCornerNumX*chessboardCornerNumY);
    arMalloc(worldCoord, ICP3DCoordT, chessboardCornerNumX*chessboardCornerNumY);
    for( i = 0; i < chessboardCornerNumX; i++ ) {
        for( j = 0; j < chessboardCornerNumY; j++ ) {
            worldCoord[i*chessboardCornerNumY+j].x = patternWidth*i;
            worldCoord[i*chessboardCornerNumY+j].y = patternWidth*j;
            worldCoord[i*chessboardCornerNumY+j].z = 0.0;
        }
    }
    arMalloc(calibData, ICPCalibDataT, calibImageNum);
    for( i = 0; i < calibImageNum; i++ ) {
        arMalloc(calibData[i].screenCoordL, ICP2DCoordT, chessboardCornerNumX*chessboardCornerNumY);
        arMalloc(calibData[i].screenCoordR, ICP2DCoordT, chessboardCornerNumX*chessboardCornerNumY);
        calibData[i].worldCoordL = worldCoord;
        calibData[i].worldCoordR = worldCoord;
        calibData[i].numL = chessboardCornerNumX*chessboardCornerNumY;
        calibData[i].numR = chessboardCornerNumX*chessboardCornerNumY;
    }

    return;
}
Ejemplo n.º 3
0
static void init( void )
{
    ARParam          cparam;
    ARParamLT       *cparamLT;
    ARGViewport      viewport;

    xsize = 640;
    ysize = 480;
    ARLOGi("Image size (x,y) = (%d,%d)\n", xsize, ysize);

    /* set the initial camera parameters */
    arParamClear(&cparam, xsize, ysize, AR_DIST_FUNCTION_VERSION_DEFAULT);
    ARLOG("*** Camera Parameter ***\n");
    arParamDisp( &cparam );
    //COVHI10445 ignored as false positive, i.e. cparam->m[3][4] uninitialized.
    cparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET);
    
    arHandle = arCreateHandle(cparamLT);
    if( arHandle == NULL ) {
        ARLOGe("Error: arCreateHandle.\n");
        exit(0);
    }
    arSetPixelFormat( arHandle, PIXEL_FORMAT );
    arSetLabelingMode( arHandle, AR_LABELING_BLACK_REGION );
    arSetImageProcMode( arHandle, AR_IMAGE_PROC_FRAME_IMAGE );

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

    /* open the graphics window */
    viewport.sx = 0;
    viewport.sy = 0;
    viewport.xsize = xsize;
    viewport.ysize = ysize;
    vp = argCreateViewport( &viewport );
    if( vp == NULL ) exit(0);
    argViewportSetCparam( vp, &cparam );
    argViewportSetPixFormat( vp, PIXEL_FORMAT );
    argViewportSetDispMode( vp, AR_GL_DISP_MODE_FIT_TO_VIEWPORT );

    argViewportSetDispMethod( vp, AR_GL_DISP_METHOD_GL_DRAW_PIXELS );
    //argViewportSetDispMethod( vp, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME );
    //argViewportSetDispMethod( vp, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FIELD );

    argViewportSetDistortionMode( vp, AR_GL_DISTORTION_COMPENSATE_DISABLE );
    //argViewportSetDistortionMode( vp, AR_GL_DISTORTION_COMPENSATE_ENABLE );
  
#if 0
    if( argSetFullScreenConfig("1024x768") == 0 ) {
        ARLOGe("Full screen is not possible.\n");
        exit(0);
    }
    //argGetWindowSizeFullScreen( &viewport.xsize, &viewport.ysize );
    viewport.sx = 0;
    viewport.sy = 0;
    viewport.xsize = 1024;
    viewport.ysize = 768;
    argViewportSetViewportFullScreen( vpL, &viewport );
    viewport.sx = 1024;
    argViewportSetViewportFullScreen( vpR, &viewport );
#endif
}