Back to the previous coding way (using the macro with the goto).

This commit is contained in:
Philippe FOUBERT 2013-11-19 21:51:47 +01:00
parent 93120775cd
commit 78e16a906b

View File

@ -62,95 +62,75 @@ void CvCaptureCAM_XIMEA::init()
// Initialize camera input // Initialize camera input
bool CvCaptureCAM_XIMEA::open( int wIndex ) bool CvCaptureCAM_XIMEA::open( int wIndex )
{ {
bool res = true; #define HandleXiResult(res) if (res!=XI_OK) goto error;
int mvret = XI_OK; int mvret = XI_OK;
if(0 == numDevices) if(numDevices == 0)
{ return false;
res = false;
} if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK)
else if(XI_OK != (mvret = xiOpenDevice(wIndex, &hmv)))
{ {
errMsg("Open XI_DEVICE failed", mvret); errMsg("Open XI_DEVICE failed", mvret);
res = false; return false;
} }
else
{
int width = 0; int width = 0;
int height = 0; int height = 0;
int isColor = 0; int isColor = 0;
// always use auto exposure/gain // always use auto exposure/gain
if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_AEAG, 1))) mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
{ HandleXiResult(mvret);
res = false;
} mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_WIDTH, &width))) HandleXiResult(mvret);
{
res = false; mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
} HandleXiResult(mvret);
else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_HEIGHT, &height)))
{ mvret = xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor);
res = false; HandleXiResult(mvret);
}
else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor)))
{
res = false;
}
else
{
if(isColor) // for color cameras if(isColor) // for color cameras
{ {
// default image format RGB24 // default image format RGB24
if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24))) mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24);
{ HandleXiResult(mvret);
res = false;
} // always use auto white balance for color cameras
// always use auto white ballance for color cameras mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
else if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_AUTO_WB, 1))) HandleXiResult(mvret);
{
res = false;
}
else
{
// 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 else // for mono cameras
{ {
// default image format MONO8 // default image format MONO8
if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8))) mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8);
{ HandleXiResult(mvret);
res = false;
}
else
{
// allocate frame buffer for MONO8 image // allocate frame buffer for MONO8 image
frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
} }
}
}
if(true == res)
{
//default capture timeout 10s //default capture timeout 10s
timeout = 10000; timeout = 10000;
if(XI_OK != (mvret = xiStartAcquisition(hmv))) mvret = xiStartAcquisition(hmv);
if(mvret != XI_OK)
{ {
errMsg("StartAcquisition XI_DEVICE failed", mvret); errMsg("StartAcquisition XI_DEVICE failed", mvret);
res = false; goto error;
} }
} return true;
else
{ error:
errMsg("Open XI_DEVICE failed", mvret); errMsg("Open XI_DEVICE failed", mvret);
xiCloseDevice(hmv); xiCloseDevice(hmv);
hmv = NULL; hmv = NULL;
} return false;
}
return true;
} }
/**********************************************************************************/ /**********************************************************************************/