From 78e16a906be177b0311c97834429cf40defc4b27 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Tue, 19 Nov 2013 21:51:47 +0100 Subject: [PATCH] Back to the previous coding way (using the macro with the goto). --- modules/highgui/src/cap_ximea.cpp | 136 +++++++++++++----------------- 1 file changed, 58 insertions(+), 78 deletions(-) diff --git a/modules/highgui/src/cap_ximea.cpp b/modules/highgui/src/cap_ximea.cpp index a2d0f0bd67..891b96115b 100644 --- a/modules/highgui/src/cap_ximea.cpp +++ b/modules/highgui/src/cap_ximea.cpp @@ -62,95 +62,75 @@ void CvCaptureCAM_XIMEA::init() // Initialize camera input bool CvCaptureCAM_XIMEA::open( int wIndex ) { - bool res = true; +#define HandleXiResult(res) if (res!=XI_OK) goto error; + int mvret = XI_OK; - if(0 == numDevices) + if(numDevices == 0) + return false; + + if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) { - res = false; + errMsg("Open XI_DEVICE failed", mvret); + return false; } - else if(XI_OK != (mvret = xiOpenDevice(wIndex, &hmv))) + + 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 { - errMsg("Open XI_DEVICE failed", mvret); - res = false; + // 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 + else // for mono cameras { - int width = 0; - int height = 0; - int isColor = 0; + // default image format MONO8 + mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8); + HandleXiResult(mvret); - // always use auto exposure/gain - if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_AEAG, 1))) - { - res = false; - } - else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_WIDTH, &width))) - { - res = false; - } - else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_HEIGHT, &height))) - { - res = false; - } - else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor))) - { - res = false; - } - else - { - if(isColor) // for color cameras - { - // default image format RGB24 - if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24))) - { - res = false; - } - // always use auto white ballance for color cameras - else if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_AUTO_WB, 1))) - { - res = false; - } - else - { - // allocate frame buffer for RGB24 image - frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); - } - } - else // for mono cameras - { - // default image format MONO8 - if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_MONO8))) - { - res = false; - } - else - { - // allocate frame buffer for MONO8 image - frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); - } - } - } + // allocate frame buffer for MONO8 image + frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); + } - if(true == res) - { - //default capture timeout 10s - timeout = 10000; - - if(XI_OK != (mvret = xiStartAcquisition(hmv))) - { - errMsg("StartAcquisition XI_DEVICE failed", mvret); - res = false; - } - } - else - { - errMsg("Open XI_DEVICE failed", mvret); - xiCloseDevice(hmv); - hmv = NULL; - } + //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; } /**********************************************************************************/