// 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; }
int _tmain(int argc, _TCHAR* argv[]) { // image buffer XI_IMG image; memset(&image,0,sizeof(image)); image.size = sizeof(XI_IMG); // Sample for XIMEA API V4.05 HANDLE xiH = NULL; XI_RETURN stat = XI_OK; // Retrieving a handle to the camera device printf("Opening first camera...\n"); stat = xiOpenDevice(0, &xiH); HandleResult(stat,"xiOpenDevice"); // Setting "exposure" parameter (10ms=10000us) stat = xiSetParamInt(xiH, XI_PRM_EXPOSURE, 10000); HandleResult(stat,"xiSetParam (exposure set)"); // Note: // The default parameters of each camera might be different in different API versions // In order to ensure that your application will have camera in expected state, // please set all parameters expected by your application to required value. printf("Starting acquisition...\n"); stat = xiStartAcquisition(xiH); HandleResult(stat,"xiStartAcquisition"); #define EXPECTED_IMAGES 10 for (int images=0;images < EXPECTED_IMAGES;images++) { // getting image from camera stat = xiGetImage(xiH, 5000, &image); HandleResult(stat,"xiGetImage"); unsigned char pixel = *(unsigned char*)image.bp; printf("Image %d (%dx%d) received from camera. First pixel value: %d\n", images, (int)image.width, (int)image.height, pixel); } printf("Stopping acquisition...\n"); xiStopAcquisition(xiH); xiCloseDevice(xiH); finish: printf("Done\n"); #ifdef WIN32 Sleep(2000); #endif return 0; }
void CRCamera::initialize() { DWORD dwNumberOfDevices = 0; float maxFps; xiGetNumberDevices(&dwNumberOfDevices); if (!dwNumberOfDevices) { LOG("Camera was NOT found."); } xiOpenDevice(0, &this->xiH); int exposure = (int)(1000000.0 / Global::crConfig->frameRate); xiSetParamInt(this->xiH, XI_PRM_EXPOSURE, exposure); xiGetParamFloat(this->xiH, XI_PRM_FRAMERATE XI_PRM_INFO_MAX, &maxFps); LOG("Max framerate : %f [fps]", maxFps); LOG("Exposure time : %d [us]", exposure); xiSetParamInt(this->xiH, XI_PRM_ACQ_TIMING_MODE, XI_ACQ_TIMING_MODE_FRAME_RATE); xiSetParamFloat(this->xiH, XI_PRM_FRAMERATE, Global::crConfig->frameRate); xiSetParamInt(this->xiH, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); }
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; }
// 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( int wIndex ) { #define HandleXiResult(res) if (res!=XI_OK) goto error; cout << "OPEN DEVICE BY ID" << endl; int mvret = XI_OK; if(numDevices == 0) return false; trigger = 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); } 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; }
CameraXIMEA::CameraXIMEA(unsigned int camNum, CameraTriggerMode triggerMode) : Camera(triggerMode), camera(NULL){ // Set debugging level xiSetParamInt(0, XI_PRM_DEBUG_LEVEL, XI_DL_FATAL); // Disable auto bandwidth determination (takes some seconds in initialization) xiSetParamInt(0, XI_PRM_AUTO_BANDWIDTH_CALCULATION, XI_OFF); // Retrieve a handle to the camera device stat = xiOpenDevice(camNum, &camera); HandleResult(stat,"xiOpenDevice"); // Configure unsafe buffers (prevents old buffers, memory leak) xiSetParamInt(camera, XI_PRM_BUFFER_POLICY, XI_BP_UNSAFE); // // Output frame signal // xiSetParamInt(camera, XI_PRM_GPO_SELECTOR, 1); // xiSetParamInt(camera, XI_PRM_GPO_MODE, XI_GPO_ON); // Configure buffer size // stat = xiSetParamInt(camera, XI_PRM_ACQ_BUFFER_SIZE, 128*1024); // HandleResult(stat,"xiSetParam (XI_PRM_ACQ_BUFFER_SIZE)"); stat = xiSetParamInt(camera, XI_PRM_BUFFERS_QUEUE_SIZE, 10); HandleResult(stat,"xiSetParam (XI_PRM_BUFFERS_QUEUE_SIZE)"); // Configure queue mode (0 = next frame in queue, 1 = most recent frame) stat = xiSetParamInt(camera, XI_PRM_RECENT_FRAME, 0); HandleResult(stat,"xiSetParam (XI_PRM_RECENT_FRAME)"); // Configure image type stat = xiSetParamInt(camera, XI_PRM_IMAGE_DATA_FORMAT, XI_RAW8); HandleResult(stat,"xiSetParam (XI_PRM_IMAGE_DATA_FORMAT)"); // Configure input pin 1 as trigger input xiSetParamInt(camera, XI_PRM_GPI_SELECTOR, 1); stat = xiSetParamInt(camera, XI_PRM_GPI_MODE, XI_GPI_TRIGGER); HandleResult(stat,"xiSetParam (XI_PRM_GPI_MODE)"); // // Configure frame rate // stat = xiSetParamFloat(camera, XI_PRM_FRAMERATE, 10); // HandleResult(stat,"xiSetParam (XI_PRM_FRAMERATE)"); // // Downsample to half size // stat = xiSetParamInt(camera, XI_PRM_DOWNSAMPLING_TYPE, XI_BINNING); // HandleResult(stat,"xiSetParam (XI_PRM_DOWNSAMPLING_TYPE)"); // stat = xiSetParamInt(camera, XI_PRM_DOWNSAMPLING, 2); // HandleResult(stat,"xiSetParam (XI_PRM_DOWNSAMPLING)"); // Define ROI stat = xiSetParamInt(camera, XI_PRM_WIDTH, 1024); HandleResult(stat,"xiSetParam (XI_PRM_WIDTH)"); stat = xiSetParamInt(camera, XI_PRM_HEIGHT, 544); HandleResult(stat,"xiSetParam (XI_PRM_HEIGHT)"); stat = xiSetParamInt(camera, XI_PRM_OFFSET_X, 512); HandleResult(stat,"xiSetParam (XI_PRM_OFFSET_X)"); stat = xiSetParamInt(camera, XI_PRM_OFFSET_Y, 272-50); HandleResult(stat,"xiSetParam (XI_PRM_OFFSET_Y)"); // Setting reasonable default settings xiSetParamFloat(camera, XI_PRM_GAMMAY, 1.0); xiSetParamInt(camera, XI_PRM_EXPOSURE, 16666); //us xiSetParamFloat(camera, XI_PRM_GAIN, 0); }