// Initialize camera input bool CvCaptureCAM_XIMEA::open( int wIndex ) { #define HandleXiResult(res) if (res!=XI_OK) goto error; int mvret = XI_OK; if(numDevices == 0) return false; if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) { #if defined WIN32 || defined _WIN32 errMsg("Open XI_DEVICE failed", mvret); return false; #else // try opening second time if first fails if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) { errMsg("Open XI_DEVICE failed", mvret); return false; } #endif } int width = 0; int height = 0; int isColor = 0; // always use auto exposure/gain mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1); HandleXiResult(mvret); mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width); HandleXiResult(mvret); mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); HandleXiResult(mvret); mvret = xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor); HandleXiResult(mvret); if(isColor) // for color cameras { // default image format RGB24 mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); HandleXiResult(mvret); // always use auto white balance for color cameras mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1); HandleXiResult(mvret); // allocate frame buffer for RGB24 image frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); } else // for mono cameras { // default image format MONO8 mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8); HandleXiResult(mvret); // allocate frame buffer for MONO8 image frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); } //default capture timeout 10s timeout = 10000; mvret = xiStartAcquisition(hmv); if(mvret != XI_OK) { errMsg("StartAcquisition XI_DEVICE failed", mvret); goto error; } return true; error: errMsg("Open XI_DEVICE failed", mvret); xiCloseDevice(hmv); hmv = NULL; return false; }
// Initialize camera input bool CaptureCAM_XIMEA::open( char * device_path ) { cout << "OPEN DEVICE BY NAME" << endl; #define HandleXiResult(res) if (res!=XI_OK) goto error; int mvret = XI_OK; if(numDevices == 0) return false; trigger = false; if(xiOpenDeviceBy(XI_OPEN_BY_INST_PATH, device_path, &hmv) != XI_OK) { #if defined WIN32 || defined _WIN32 errMsg("Open XI_DEVICE failed", mvret); return false; #else // try opening second time if first fails if(xiOpenDeviceBy(XI_OPEN_BY_INST_PATH, device_path, &hmv) != XI_OK) { errMsg("Open XI_DEVICE failed", mvret); return false; } #endif } int width = 0; int height = 0; int isColor = 0; // always use auto exposure/gain mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1); HandleXiResult(mvret); mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width); HandleXiResult(mvret); mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); HandleXiResult(mvret); mvret = xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor); HandleXiResult(mvret); mvret = xiSetParamInt(hmv, XI_PRM_ACQ_TIMING_MODE, XI_ACQ_TIMING_MODE_FREE_RUN); HandleXiResult(mvret); if(isColor) // for color cameras { // default image format RGB24 mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); HandleXiResult(mvret); // always use auto white balance for color cameras mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1); HandleXiResult(mvret); } else // for mono cameras { // default image format MONO8 mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8); HandleXiResult(mvret); } //default capture timeout 10s timeout = 10000; /* NOT WORKING IF XI_PRM_BUFFERS_QUEUE_SIZE is set to a value < 3*/ mvret = xiSetParamInt(hmv, XI_PRM_BUFFERS_QUEUE_SIZE, 3); if( mvret != XI_OK) errMsg("Set parameter error (XI_PRM_BUFFERS_QUEUE_SIZE)", mvret); mvret = xiSetParamInt(hmv, XI_PRM_RECENT_FRAME, 1); if( mvret != XI_OK) errMsg("Set parameter error (XI_PRM_RECENT_FRAME)", mvret); mvret = xiSetParamInt(hmv, XI_PRM_TRG_SOURCE, XI_TRG_SOFTWARE); if( mvret != XI_OK){ errMsg("Error while disabling external trigger source", mvret); } mvret = xiStartAcquisition(hmv); if(mvret != XI_OK) { errMsg("StartAcquisition XI_DEVICE failed", mvret); goto error; } xiSetParamInt(hmv, XI_PRM_TS_RST_MODE , XI_TS_RST_ARM_ONCE); xiSetParamInt(hmv, XI_PRM_TS_RST_SOURCE , XI_TS_RST_SRC_SW); isopened=true; return true; error: errMsg("Open XI_DEVICE failed", mvret); xiCloseDevice(hmv); hmv = NULL; return false; }