bool ofxArtool5::setupCamera(string pthCamParam, ofVec2f _camSize, ofVec2f _viewportSize, ofPixelFormat pf){ ARParam cParam; AR_PIXEL_FORMAT pixFormat = toAR(pf); const char * cPathCamParam = ofToDataPath(pthCamParam).c_str(); camSize=_camSize; viewportSize=_viewportSize; if(arParamLoad(cPathCamParam, 1, &cParam)){ ofLogError("ofxArtool5::setupCamera()", "error loading param file"); return false; } if(cParam.xsize!=camSize.x||cParam.ysize!=camSize.y){ ofLogWarning("ofxArtool5::setupCamera()","camera param needs resizing"); arParamChangeSize(&cParam, camSize.x, camSize.y, &cParam); } if((gCparamLT = arParamLTCreate(&cParam, AR_PARAM_LT_DEFAULT_OFFSET))==NULL){ ofLogError("ofxArtool5::setupCamera()","Error: arParamLTCreate"); return false; } if(artMode==ART_PATTERN){ if((gARHandle = arCreateHandle(gCparamLT))==NULL){ ofLogError("ofxArtool5::setupCamera()","Error: arCreateHandle"); return false; } if(arSetPixelFormat(gARHandle, pixFormat)<0){ ofLogError("ofxArtool5::setupCamera()","Error arSetPixelFormat"); return false; } if(arSetDebugMode(gARHandle, AR_DEBUG_DISABLE)<0){ ofLogError("ofxArtool5::setupCamera()","Error arSetDebugMode"); return false; } if((gAR3DHandle = ar3DCreateHandle(&cParam))==NULL){ ofLogError("ofxArtool5::setupCamera()","Error ar3DCreateHandle"); return false; } }else if(artMode==ART_NFT){ arglCameraFrustumRH(&(gCparamLT->param), getMinDistance(), getMaxDistance(), cameraLens); } cvColorFrame.allocate(camSize.x, camSize.y); cvGrayFrame.allocate(camSize.x, camSize.y); return true; }
static void nativeVideoGetCparamCallback(const ARParam *cparam_p, void *userdata) { // Load the camera parameters, resize for the window and init. ARParam cparam; if (cparam_p) cparam = *cparam_p; else { LOGE("Unable to automatically determine camera parameters. Using default.\n"); if (arParamLoad(cparaName, 1, &cparam) < 0) { LOGE("Error: Unable to load parameter file %s for camera.\n", cparaName); return; } } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG LOGI("*** Camera Parameter resized from %d, %d. ***\n", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } #ifdef DEBUG LOGI("*** Camera Parameter ***\n"); arParamDisp(&cparam); #endif if ((gCparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET)) == NULL) { LOGE("Error: arParamLTCreate.\n"); return; } videoInited = true; // // AR init. // // Create the OpenGL projection from the calibrated camera parameters. arglCameraFrustumRHf(&gCparamLT->param, NEAR_PLANE, FAR_PLANE, cameraLens); cameraPoseValid = FALSE; if (!initNFT(gCparamLT, gPixFormat)) { LOGE("Error initialising NFT.\n"); arParamLTFree(&gCparamLT); return; } // Marker data has already been loaded, so now load NFT data on a second thread. nftDataLoadingThreadHandle = threadInit(0, NULL, loadNFTDataAsync); if (!nftDataLoadingThreadHandle) { LOGE("Error starting NFT loading thread.\n"); arParamLTFree(&gCparamLT); return; } threadStartSignal(nftDataLoadingThreadHandle); }
static int setupCamera(const char *cparam_name, char *vconf, ARParamLT **cparamLT_p) { 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(cparam_name, 1, &cparam) < 0) { ARLOGe("setupCamera(): Error loading parameter file %s for camera.\n", cparam_name); 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"); arVideoClose(); return (FALSE); } return (TRUE); }
static void nativeVideoGetCparamCallback(const ARParam *cparam_p, void *userdata) { // Load the camera parameters, resize for the window and init. ARParam cparam; if (cparam_p) cparam = *cparam_p; else { LOGE("Unable to automatically determine camera parameters. Using default.\n"); if (arParamLoad(cparaName, 1, &cparam) < 0) { LOGE("Error: Unable to load parameter file %s for camera.\n", cparaName); return; } } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG LOGI("*** Camera Parameter resized from %d, %d. ***\n", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } #ifdef DEBUG LOGI("*** Camera Parameter ***\n"); arParamDisp(&cparam); #endif if ((gCparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET)) == NULL) { LOGE("Error: arParamLTCreate.\n"); return; } videoInited = true; // // AR init. // // Create the OpenGL projection from the calibrated camera parameters. arglCameraFrustumRHf(&gCparamLT->param, NEAR_PLANE, FAR_PLANE, cameraLens); cameraPoseValid = FALSE; // Init AR. arHandle = arCreateHandle(gCparamLT); if (arHandle == NULL) { LOGE("Error creating AR handle"); return; } arPattAttach(arHandle, arPattHandle); if (arSetPixelFormat(arHandle, gPixFormat) < 0) { LOGE("Error setting pixel format"); return; } ar3DHandle = ar3DCreateHandle(&gCparamLT->param); if (ar3DHandle == NULL) { LOGE("Error creating 3D handle"); return; } // Other ARToolKit setup. arSetMarkerExtractionMode(arHandle, AR_USE_TRACKING_HISTORY_V2); //arSetMarkerExtractionMode(arHandle, AR_NOUSE_TRACKING_HISTORY); //arSetLabelingThreshMode(arHandle, AR_LABELING_THRESH_MODE_MANUAL); // Uncomment to use manual thresholding. // Set the pattern detection mode (template (pictorial) vs. matrix (barcode) based on // the marker types as defined in the marker config. file. arSetPatternDetectionMode(arHandle, arPattDetectionMode); // Default = AR_TEMPLATE_MATCHING_COLOR // Other application-wide marker options. Once set, these apply to all markers in use in the application. // If you are using standard ARToolKit picture (template) markers, leave commented to use the defaults. // If you are usign a different marker design (see http://www.artoolworks.com/support/app/marker.php ) // then uncomment and edit as instructed by the marker design application. //arSetLabelingMode(arHandle, AR_LABELING_BLACK_REGION); // Default = AR_LABELING_BLACK_REGION //arSetBorderSize(arHandle, 0.25f); // Default = 0.25f //arSetMatrixCodeType(arHandle, AR_MATRIX_CODE_3x3); // Default = AR_MATRIX_CODE_3x3 }
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 ARToolKitVideoSource::open() { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): called, opening ARToolKit video"); if (deviceState != DEVICE_CLOSED) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error: device is already open, exiting returning false"); return false; } // Open the video path gVid = ar2VideoOpen(videoConfiguration); if (!gVid) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): arVideoOpen unable to open connection to camera using configuration '%s', exiting returning false", videoConfiguration); return false; } ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Opened connection to camera using configuration '%s'", videoConfiguration); deviceState = DEVICE_OPEN; // Find the size of the video if (ar2VideoGetSize(gVid, &videoWidth, &videoHeight) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): Error: unable to get video size, calling close(), exiting returning false"); this->close(); return false; } // Get the format in which the camera is returning pixels pixelFormat = ar2VideoGetPixelFormat(gVid); if (pixelFormat < 0 ) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): Error: unable to get pixel format, calling close(), exiting returning false"); this->close(); return false; } ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Video %dx%d@%dBpp (%s)", videoWidth, videoHeight, arUtilGetPixelSize(pixelFormat), arUtilGetPixelFormatName(pixelFormat)); #ifndef _WINRT // Translate pixel format into OpenGL texture intformat, format, and type. switch (pixelFormat) { case AR_PIXEL_FORMAT_RGBA: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_RGB: glPixIntFormat = GL_RGB; glPixFormat = GL_RGB; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_BGRA: glPixIntFormat = GL_RGBA; glPixFormat = GL_BGRA; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_ABGR: glPixIntFormat = GL_RGBA; glPixFormat = GL_ABGR_EXT; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_ARGB: glPixIntFormat = GL_RGBA; glPixFormat = GL_BGRA; #ifdef AR_BIG_ENDIAN glPixType = GL_UNSIGNED_INT_8_8_8_8_REV; #else glPixType = GL_UNSIGNED_INT_8_8_8_8; #endif break; case AR_PIXEL_FORMAT_BGR: glPixIntFormat = GL_RGB; glPixFormat = GL_BGR; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_MONO: case AR_PIXEL_FORMAT_420v: case AR_PIXEL_FORMAT_420f: case AR_PIXEL_FORMAT_NV21: glPixIntFormat = GL_LUMINANCE; glPixFormat = GL_LUMINANCE; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_RGB_565: glPixIntFormat = GL_RGB; glPixFormat = GL_RGB; glPixType = GL_UNSIGNED_SHORT_5_6_5; break; case AR_PIXEL_FORMAT_RGBA_5551: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_SHORT_5_5_5_1; break; case AR_PIXEL_FORMAT_RGBA_4444: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_SHORT_4_4_4_4; break; default: ARController::logv("Error: Unsupported pixel format.\n"); this->close(); return false; break; } #endif // !_WINRT #if TARGET_PLATFORM_IOS // Tell arVideo what the typical focal distance will be. Note that this does NOT // change the actual focus, but on devices with non-fixed focus, it lets arVideo // choose a better set of camera parameters. ar2VideoSetParami(gVid, AR_VIDEO_PARAM_IOS_FOCUS, AR_VIDEO_IOS_FOCUS_0_3M); // Default is 0.3 metres. See <AR/sys/videoiPhone.h> for allowable values. #endif // Load the camera parameters, resize for the window and init. ARParam cparam; // Prefer internal camera parameters. if (ar2VideoGetCParam(gVid, &cparam) == 0) { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Using internal camera parameters."); } else { const char cparam_name_default[] = "camera_para.dat"; // Default name for the camera parameters. if (cameraParamBuffer) { if (arParamLoadFromBuffer(cameraParamBuffer, cameraParamBufferLen, &cparam) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to load camera parameters from buffer, calling close(), exiting returning false"); this->close(); return false; } else { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Camera parameters loaded from buffer"); } } else { if (arParamLoad((cameraParam ? cameraParam : cparam_name_default), 1, &cparam) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to load camera parameters %s, calling close(), exiting returning false", (cameraParam ? cameraParam : cparam_name_default)); this->close(); return false; } else { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open():Camera parameters loaded from %s", (cameraParam ? cameraParam : cparam_name_default)); } } } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG ARController::logv(AR_LOG_LEVEL_ERROR, "*** Camera Parameter resized from %d, %d. ***\n", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } if (!(cparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET))) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to create camera parameters lookup table, calling close(), exiting returning false"); this->close(); return false; } int err = ar2VideoCapStart(gVid); if (err != 0) { if (err == -2) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error starting video-device unavailable \"%d,\" setting ARW_ERROR_DEVICE_UNAVAILABLE error state", err); setError(ARW_ERROR_DEVICE_UNAVAILABLE); } else { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error \"%d\" starting video capture", err); } ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): calling close(), exiting returning false"); this->close(); return false; } deviceState = DEVICE_RUNNING; ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): exiting returning true, deviceState = DEVICE_RUNNING, video capture started"); return true; }
bool AndroidVideoSource::getVideoReadyAndroid2(const ARParam *cparam_p) { // Load camera parameters ARParam cparam; if (cparam_p) cparam = *cparam_p; else { ARController::logv("Unable to automatically determine camera parameters. Using supplied default.\n"); if (cameraParam) { if (arParamLoad(cameraParam, 1, &cparam) < 0) { ARController::logv("Error: Unable to load camera parameters from file '%s'.", cameraParam); goto bail; } } else if (cameraParamBuffer) { if (arParamLoadFromBuffer(cameraParamBuffer, cameraParamBufferLen, &cparam) < 0) { ARController::logv("Error: Unable to load camera parameters from buffer."); goto bail; } } else { ARController::logv("Error: video source must be configured before opening."); goto bail; } } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG ARController::logv("*** Camera Parameter resized from %d, %d. ***", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } if (!(cparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET))) { ARController::logv("Error: Failed to create camera parameters lookup table."); goto bail; } // Allocate local buffer for video frame after copy or conversion. if (pixelFormat == AR_PIXEL_FORMAT_NV21 || pixelFormat == AR_PIXEL_FORMAT_420f) { frameBufferSize = videoWidth * videoHeight + 2 * videoWidth/2 * videoHeight/2; } else { frameBufferSize = videoWidth * videoHeight * arUtilGetPixelSize(pixelFormat); } localFrameBuffer = (ARUint8*)calloc(frameBufferSize, sizeof(ARUint8)); if (!localFrameBuffer) { ARController::logv("Error: Unable to allocate memory for local video frame buffer"); goto bail; } frameBuffer = localFrameBuffer; if (pixelFormat == AR_PIXEL_FORMAT_NV21 || pixelFormat == AR_PIXEL_FORMAT_420f) { frameBuffer2 = localFrameBuffer + videoWidth*videoHeight; } else { frameBuffer2 = NULL; } ARController::logv("Android Video Source running %dx%d.", videoWidth, videoHeight); deviceState = DEVICE_RUNNING; return true; bail: deviceState = DEVICE_OPEN; return false; }
static int setupCamera(const char *cparam_name, 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(cparam_name, 1, &cparam) < 0) { ARLOGe("setupCamera(): Error loading parameter file %s for camera.\n", cparam_name); 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"); arVideoClose(); 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 (arSetImageProcMode(*arhandle, AR_IMAGE_PROC_FRAME_IMAGE) < 0) { // Change to AR_IMAGE_PROC_FIELD_IMAGE if using a DVCam. ARLOGe("setupCamera(): Error: arSetImageProcMode.\n"); return (FALSE); } if ((*ar3dhandle = ar3DCreateHandle(&(*cparamLT_p)->param)) == NULL) { ARLOGe("setupCamera(): Error: ar3DCreateHandle.\n"); return (FALSE); } if (arVideoCapStart() != 0) { ARLOGe("setupCamera(): Unable to begin camera data capture.\n"); return (FALSE); } return (TRUE); }
bool AndroidVideoSource::getVideoReadyAndroid2(const ARParam *cparam_p) { ARParam cparam; if (cparam_p) { cparam = *cparam_p; } else { arParamClearWithFOVy(&cparam, videoWidth, videoHeight, M_PI_4); // M_PI_4 radians = 45 degrees. ARController::logv(AR_LOG_LEVEL_WARN, "Using default camera parameters for %dx%d image size, 45 degrees vertical field-of-view.", videoWidth, videoHeight); } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG ARController::logv(AR_LOG_LEVEL_WARN, "*** Camera Parameter resized from %d, %d. ***", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } if (!(cparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET))) { ARController::logv(AR_LOG_LEVEL_ERROR, "Error: Failed to create camera parameters lookup table."); goto bail; } // Allocate buffer for incoming video frame. incomingFrameRawBufferSize = videoWidth * videoHeight + 2 * videoWidth/2 * videoHeight/2; incomingFrameRawBuffer[0] = (unsigned char *)calloc(incomingFrameRawBufferSize, sizeof(unsigned char)); incomingFrameRawBuffer[1] = (unsigned char *)calloc(incomingFrameRawBufferSize, sizeof(unsigned char)); if (!incomingFrameRawBuffer[0] || !incomingFrameRawBuffer[1]) { ARController::logv(AR_LOG_LEVEL_ERROR, "Error: Unable to allocate memory for incoming frame raw buffer."); goto bail; } // Next, an AR2VideoBufferT. localFrameBuffer = (AR2VideoBufferT *)calloc(1, sizeof(AR2VideoBufferT)); if (!localFrameBuffer) { ARController::logv(AR_LOG_LEVEL_ERROR, "Error: Unable to allocate memory for local video frame buffer"); goto bail; } if (pixelFormat == AR_PIXEL_FORMAT_NV21 || pixelFormat == AR_PIXEL_FORMAT_420f) { localFrameBuffer->buff = incomingFrameRawBuffer[0]; localFrameBuffer->buffLuma = incomingFrameRawBuffer[0]; localFrameBuffer->bufPlaneCount = 2; localFrameBuffer->bufPlanes = (ARUint8 **)calloc(2, sizeof(ARUint8 *)); localFrameBuffer->bufPlanes[0] = incomingFrameRawBuffer[0]; localFrameBuffer->bufPlanes[1] = incomingFrameRawBuffer[0] + videoWidth*videoHeight; } else { convertedFrameRawBufferSize = videoWidth * videoHeight * arUtilGetPixelSize(pixelFormat); convertedFrameRawBuffer[0] = (ARUint8 *)calloc(convertedFrameRawBufferSize, sizeof(ARUint8)); convertedFrameRawBuffer[1] = (ARUint8 *)calloc(convertedFrameRawBufferSize, sizeof(ARUint8)); if (!convertedFrameRawBuffer[0] || !convertedFrameRawBuffer[1]) { ARController::logv(AR_LOG_LEVEL_ERROR, "Error: Unable to allocate memory for converted video frame buffer."); goto bail; } localFrameBuffer->buff = convertedFrameRawBuffer[0]; localFrameBuffer->buffLuma = incomingFrameRawBuffer[0]; localFrameBuffer->bufPlaneCount = 0; } frameBuffer = localFrameBuffer; ARController::logv(AR_LOG_LEVEL_INFO, "Android Video Source running %dx%d.", videoWidth, videoHeight); deviceState = DEVICE_RUNNING; return true; bail: if (localFrameBuffer) { free(localFrameBuffer->bufPlanes); free(localFrameBuffer); localFrameBuffer = NULL; } if (incomingFrameRawBuffer[0]) { free(incomingFrameRawBuffer[0]); incomingFrameRawBuffer[0] = NULL; } if (incomingFrameRawBuffer[1]) { free(incomingFrameRawBuffer[1]); incomingFrameRawBuffer[1] = NULL; } if (convertedFrameRawBuffer[0]) { free(convertedFrameRawBuffer[0]); convertedFrameRawBuffer[0] = NULL; } if (convertedFrameRawBuffer[1]) { free(convertedFrameRawBuffer[1]); convertedFrameRawBuffer[1] = NULL; } incomingFrameRawBufferSize = 0; convertedFrameRawBufferSize = 0; frameBuffer = NULL; deviceState = DEVICE_OPEN; return false; }
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 }