void CvCaptureCAM_XIMEA::resetCvImage() { int width = 0, height = 0, format = 0; xiGetParamInt( hmv, XI_PRM_WIDTH, &width); xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &format); if( (int)image.width != frame->width || (int)image.height != frame->height || image.frm != (XI_IMG_FORMAT)format) { if(frame) cvReleaseImage(&frame); frame = NULL; switch( image.frm) { case XI_MONO8 : case XI_RAW8 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break; case XI_MONO16 : case XI_RAW16 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_16U, 1); break; case XI_RGB24 : case XI_RGB_PLANAR : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 3); break; case XI_RGB32 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 4); break; default : return; } } cvZero(frame); }
// Initialize camera input bool CvCaptureCAM_XIMEA::open( int wIndex ) { int mvret = XI_OK; if(numDevices == 0) return false; if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) { errMsg("Open XI_DEVICE failed", mvret); return false; } // always use auto exposure/gain xiSetParamInt( hmv, XI_PRM_AEAG, 1); // always use auto white ballance xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1); xiGetParamInt( hmv, XI_PRM_WIDTH, &width); xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); // default image format RGB24 xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); format = XI_RGB24; // allocate frame buffer for RGB24 image frame = cvCreateImage(cvSize( width, height), IPL_DEPTH_8U, 3); //default capture timeout 10s timeout = 10000; return true; }
void CaptureCAM_XIMEA::resetCvImage() { if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format) { xiGetParamInt( hmv, XI_PRM_WIDTH, &width); xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &format); } }
int Camera::getIntParam(const char* name) { if (!opened) { return -1; } int intParam = 0; xiGetParamInt(device, name, &intParam); return intParam; }
CameraSettings CameraXIMEA::getCameraSettings(){ CameraSettings settings; int shutter; xiGetParamInt(camera, XI_PRM_EXPOSURE, &shutter); settings.shutter = shutter/1000.0; // from us to ms xiGetParamFloat(camera, XI_PRM_GAIN, &settings.gain); return settings; }
bool Camera::open(int serial) { std::cout << "! Searching for a camera with serial: " << serial << std::endl; DWORD deviceCount = 0; xiGetNumberDevices(&deviceCount); if (deviceCount == 0) { std::cout << "- Failed to detect any cameras" << std::endl; return false; } if (serial != 0) { std::cout << " > found " << deviceCount << " available devices" << std::endl; } int sn = 0; bool found = false; for (unsigned int i = 0; i < deviceCount; i++) { std::cout << " > opening camera #" << i << ".. "; xiOpenDevice(i, &device); std::cout << "done!" << std::endl; xiGetParamInt(device, XI_PRM_DEVICE_SN, &sn); std::cout << " > found camera with serial number: " << sn << ".. "; if (serial == 0 || serial == sn) { found = true; std::cout << "match found!" << std::endl; break; } else { std::cout << "not the right one, closing it" << std::endl; xiCloseDevice(device); } } if (!found) { std::cout << "- No camera with serial #" << serial << " could be found" << std::endl; return false; } xiSetParamInt(device, XI_PRM_EXPOSURE, 16000); //xiSetParamInt(device, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8); //xiSetParamInt(device, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); xiSetParamInt(device, XI_PRM_BUFFER_POLICY, XI_BP_UNSAFE); //xiSetParamInt(device, XI_PRM_FRAMERATE, 60); //xiSetParamInt(device, XI_PRM_DOWNSAMPLING, 2); // @TEMP //xiSetParamInt(device, XI_PRM_DOWNSAMPLING_TYPE, XI_BINNING); //xiSetParamFloat(device, XI_PRM_GAIN, 5.0f); //xiSetParamInt(device, XI_PRM_ACQ_BUFFER_SIZE, 70*1000*1000); xiSetParamInt(device, XI_PRM_BUFFERS_QUEUE_SIZE, 1); //xiSetParamInt(device, XI_PRM_RECENT_FRAME, 1); xiSetParamInt(device, XI_PRM_AUTO_WB, 0); //xiSetParamFloat(device, XI_PRM_WB_KR, 1.0f); //xiSetParamFloat(device, XI_PRM_WB_KG, 1.0f); //xiSetParamFloat(device, XI_PRM_WB_KB, 1.0f); //xiSetParamFloat(device, XI_PRM_GAMMAY, 1.0f); //xiSetParamFloat(device, XI_PRM_GAMMAC, 1.0f); //xiSetParamFloat(device, XI_PRM_SHARPNESS, 0.0f); xiSetParamInt(device, XI_PRM_AEAG, 0); //xiSetParamInt(device, XI_PRM_BPC, 1); // fixes bad pixel //xiSetParamInt(device, XI_PRM_HDR, 1); opened = true; serialNumber = serial; return true; }
double CvCaptureCAM_XIMEA::getProperty( int property_id ) { if(hmv == NULL) return 0; int ival = 0; float fval = 0; switch( property_id ) { // OCV parameters case CV_CAP_PROP_POS_FRAMES : return (double) image.nframe; case CV_CAP_PROP_FRAME_WIDTH : xiGetParamInt( hmv, XI_PRM_WIDTH, &ival); return ival; case CV_CAP_PROP_FRAME_HEIGHT : xiGetParamInt( hmv, XI_PRM_HEIGHT, &ival); return ival; case CV_CAP_PROP_FPS : xiGetParamFloat( hmv, XI_PRM_FRAMERATE, &fval); return fval; case CV_CAP_PROP_GAIN : xiGetParamFloat( hmv, XI_PRM_GAIN, &fval); return fval; case CV_CAP_PROP_EXPOSURE : xiGetParamInt( hmv, XI_PRM_EXPOSURE, &ival); return ival; // XIMEA camera properties case CV_CAP_PROP_XI_DOWNSAMPLING : xiGetParamInt( hmv, XI_PRM_DOWNSAMPLING, &ival); return ival; case CV_CAP_PROP_XI_DATA_FORMAT : xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &ival); return ival; case CV_CAP_PROP_XI_OFFSET_X : xiGetParamInt( hmv, XI_PRM_OFFSET_X, &ival); return ival; case CV_CAP_PROP_XI_OFFSET_Y : xiGetParamInt( hmv, XI_PRM_OFFSET_Y, &ival); return ival; case CV_CAP_PROP_XI_TRG_SOURCE : xiGetParamInt( hmv, XI_PRM_TRG_SOURCE, &ival); return ival; case CV_CAP_PROP_XI_GPI_SELECTOR : xiGetParamInt( hmv, XI_PRM_GPI_SELECTOR, &ival); return ival; case CV_CAP_PROP_XI_GPI_MODE : xiGetParamInt( hmv, XI_PRM_GPI_MODE, &ival); return ival; case CV_CAP_PROP_XI_GPI_LEVEL : xiGetParamInt( hmv, XI_PRM_GPI_LEVEL, &ival); return ival; case CV_CAP_PROP_XI_GPO_SELECTOR : xiGetParamInt( hmv, XI_PRM_GPO_SELECTOR, &ival); return ival; case CV_CAP_PROP_XI_GPO_MODE : xiGetParamInt( hmv, XI_PRM_GPO_MODE, &ival); return ival; case CV_CAP_PROP_XI_LED_SELECTOR : xiGetParamInt( hmv, XI_PRM_LED_SELECTOR, &ival); return ival; case CV_CAP_PROP_XI_LED_MODE : xiGetParamInt( hmv, XI_PRM_LED_MODE, &ival); return ival; case CV_CAP_PROP_XI_AUTO_WB : xiGetParamInt( hmv, XI_PRM_AUTO_WB, &ival); return ival; case CV_CAP_PROP_XI_AEAG : xiGetParamInt( hmv, XI_PRM_AEAG, &ival); return ival; case CV_CAP_PROP_XI_EXP_PRIORITY : xiGetParamFloat( hmv, XI_PRM_EXP_PRIORITY, &fval); return fval; case CV_CAP_PROP_XI_AE_MAX_LIMIT : xiGetParamInt( hmv, XI_PRM_EXP_PRIORITY, &ival); return ival; case CV_CAP_PROP_XI_AG_MAX_LIMIT : xiGetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, &fval); return fval; case CV_CAP_PROP_XI_AEAG_LEVEL : xiGetParamInt( hmv, XI_PRM_AEAG_LEVEL, &ival); return ival; case CV_CAP_PROP_XI_TIMEOUT : return timeout; } return 0; }
// 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; }
size_t CameraXIMEA::getFrameHeight(){ int h; xiGetParamInt(camera, XI_PRM_HEIGHT, &h); return h; }
size_t CameraXIMEA::getFrameWidth(){ int w; xiGetParamInt(camera, XI_PRM_WIDTH, &w); return w; }