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; }
//======== // 初期化 //======== bool cARTK::initialize( void ) { const char *szCameraParamFName = "Data/camera_para.dat"; #ifdef _WIN32 char *szVConfFName = "Data/WDM_camera_flipV.xml"; #else char *vconf = ""; #endif ARParam sCamParamTemp; int iCamImgSizeX, iCamImgSizeY; // カメラデバイスのオープン if( arVideoOpen( szVConfFName ) < 0 ) { ErrorMessage( "Unable to open connection to camera.\n" ); return false; } // カメラ画像のサイズを取得 if( arVideoInqSize( &iCamImgSizeX, &iCamImgSizeY ) < 0 ) return false; // カメラパラメータファイルの読込み if( arParamLoad( szCameraParamFName, 1, &sCamParamTemp ) < 0 ) { ErrorMessage( "Error loading parameter file for camera.\n" ); return false; } // カメラパラメータのサイズ部分を変更 arParamChangeSize( &sCamParamTemp, iCamImgSizeX, iCamImgSizeY, &m_sCameraParam ); // ライブラリ内のカメラパラメータの初期化 arInitCparam( &m_sCameraParam ); // NyARTransMatの初期化 m_pNyARInst = nyar_NyARTransMat_O2_create( &m_sCameraParam ); // カメラ画像のキャプチャを開始 if( arVideoCapStart() != 0 ) { ErrorMessage( "Unable to begin camera data capture.\n" ); return false; } // マーカーパターンファイルの読込み for( int i = 0 ; i < ARMK_MAXNUM ; i++ ) { if( (m_sMarkerInfo[i].iPattID = arLoadPatt( g_szPattFName[i] )) < 0 ) { ErrorMessage( "Pattern file load error !!\n" ); return false; } m_sMarkerInfo[i].dWidth = g_dPattWidth[i]; m_sMarkerInfo[i].dCenterPos[0] = m_sMarkerInfo[i].dCenterPos[1] = 0.0f; m_sMarkerInfo[i].bVisible = false; } // ちょっとずらす m_sMarkerInfo[1].dCenterPos[0] = 0.0f; m_sMarkerInfo[1].dCenterPos[1] = 30.0f; m_iThreshold = 120; m_dViewScaleFactor = 0.16; return true; }
bool ARTApp::setupCamera(const char *cparamName, char *vconf, ARParamLT **cparamLT_p, ARHandle **arhandle, AR3DHandle **ar3dhandle) { ARParam cparam; int xsize, ysize; AR_PIXEL_FORMAT pixFormat; // Open the video path. if (arVideoOpen(vconf) < 0) { ARLOGe("setupCamera(): Unable to open connection to camera.\n"); return false; } // Find the size of the window. if (arVideoGetSize(&xsize, &ysize) < 0) { ARLOGe("setupCamera(): Unable to determine camera frame size.\n"); arVideoClose(); return false; } ARLOGi("Camera image size (x,y) = (%d,%d)\n", xsize, ysize); // Get the format in which the camera is returning pixels. pixFormat = arVideoGetPixelFormat(); if (pixFormat == AR_PIXEL_FORMAT_INVALID) { ARLOGe("setupCamera(): Camera is using unsupported pixel format.\n"); arVideoClose(); return false; } // Load the camera parameters, resize for the window and init. if (arParamLoad(cparamName, 1, &cparam) < 0) { ARLOGe("setupCamera(): Error loading parameter file %s for camera.\n", cparamName); arVideoClose(); return false; } if (cparam.xsize != xsize || cparam.ysize != ysize) { ARLOGw("*** Camera Parameter resized from %d, %d. ***\n", cparam.xsize, cparam.ysize); arParamChangeSize(&cparam, xsize, ysize, &cparam); } #ifdef DEBUG ARLOG("*** Camera Parameter ***\n"); arParamDisp(&cparam); #endif if ((*cparamLT_p = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET)) == NULL) { ARLOGe("setupCamera(): Error: arParamLTCreate.\n"); return false; } if ((*arhandle = arCreateHandle(*cparamLT_p)) == NULL) { ARLOGe("setupCamera(): Error: arCreateHandle.\n"); return false; } if (arSetPixelFormat(*arhandle, pixFormat) < 0) { ARLOGe("setupCamera(): Error: arSetPixelFormat.\n"); return false; } if (arSetDebugMode(*arhandle, AR_DEBUG_DISABLE) < 0) { ARLOGe("setupCamera(): Error: arSetDebugMode.\n"); return false; } if ((*ar3dhandle = ar3DCreateHandle(&cparam)) == NULL) { ARLOGe("setupCamera(): Error: ar3DCreateHandle.\n"); return false; } if (arVideoCapStart() != 0) { ARLOGe("setupCamera(): Unable to begin camera data capture.\n"); return false; } return true; }