Merge pull request #1098 from SeninAndrew:ximea_camera_bw_fix

pull/1070/merge
Andrey Pavlenko 12 years ago committed by OpenCV Buildbot
commit 2b8d868560
  1. 45
      modules/highgui/src/cap_ximea.cpp

@ -52,6 +52,8 @@ void CvCaptureCAM_XIMEA::init()
{ {
xiGetNumberDevices( &numDevices); xiGetNumberDevices( &numDevices);
hmv = NULL; hmv = NULL;
frame = NULL;
timeout = 0;
memset(&image, 0, sizeof(XI_IMG)); memset(&image, 0, sizeof(XI_IMG));
} }
@ -60,6 +62,8 @@ void CvCaptureCAM_XIMEA::init()
// Initialize camera input // Initialize camera input
bool CvCaptureCAM_XIMEA::open( int wIndex ) bool CvCaptureCAM_XIMEA::open( int wIndex )
{ {
#define HandleXiResult(res) if (res!=XI_OK) goto error;
int mvret = XI_OK; int mvret = XI_OK;
if(numDevices == 0) if(numDevices == 0)
@ -73,26 +77,42 @@ bool CvCaptureCAM_XIMEA::open( int wIndex )
// always use auto exposure/gain // always use auto exposure/gain
mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1); mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
if(mvret != XI_OK) goto error; HandleXiResult(mvret);
// always use auto white ballance
mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
if(mvret != XI_OK) goto error;
// default image format RGB24
mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24);
if(mvret != XI_OK) goto error;
int width = 0; int width = 0;
mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width); mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
if(mvret != XI_OK) goto error; HandleXiResult(mvret);
int height = 0; int height = 0;
mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
if(mvret != XI_OK) goto error; HandleXiResult(mvret);
int isColor = 0;
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 ballance for color cameras
mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
HandleXiResult(mvret);
// allocate frame buffer for RGB24 image // allocate frame buffer for RGB24 image
frame = cvCreateImage(cvSize( width, height), IPL_DEPTH_8U, 3); 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 //default capture timeout 10s
timeout = 10000; timeout = 10000;
@ -119,8 +139,11 @@ void CvCaptureCAM_XIMEA::close()
if(frame) if(frame)
cvReleaseImage(&frame); cvReleaseImage(&frame);
if(hmv)
{
xiStopAcquisition(hmv); xiStopAcquisition(hmv);
xiCloseDevice(hmv); xiCloseDevice(hmv);
}
hmv = NULL; hmv = NULL;
} }

Loading…
Cancel
Save