From 8b0fc04d935f101a9f573af41179c0cccfab86a7 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Sun, 10 Nov 2013 17:46:59 +0100 Subject: [PATCH 1/4] Fix the build of OpenCV with XIMEA on Windows 64 bits: - crosses initializations in "cap_ximea.cpp" (which also contained some awfull "goto" instructions) - the "CMAKE_CL_64" variable is not initialized when using mingw PR#1039 modified to be able to merge on branch 2.4 --- cmake/OpenCVFindXimea.cmake | 2 +- modules/highgui/CMakeLists.txt | 6 +- modules/highgui/src/cap_ximea.cpp | 145 +++++++++++++++++------------- 3 files changed, 87 insertions(+), 66 deletions(-) diff --git a/cmake/OpenCVFindXimea.cmake b/cmake/OpenCVFindXimea.cmake index 6b86b609e..5f85a13dd 100644 --- a/cmake/OpenCVFindXimea.cmake +++ b/cmake/OpenCVFindXimea.cmake @@ -23,7 +23,7 @@ if(WIN32) if(EXISTS ${XIMEA_PATH}) set(XIMEA_FOUND 1) # set LIB folders - if(CMAKE_CL_64) + if(X86_64) set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x64") else() set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x86") diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 15e2e7982..69ece1b8f 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -167,9 +167,9 @@ if(HAVE_XIMEA) list(APPEND highgui_srcs src/cap_ximea.cpp) ocv_include_directories(${XIMEA_PATH}) if(XIMEA_LIBRARY_DIR) - link_directories(${XIMEA_LIBRARY_DIR}) - endif() - if(CMAKE_CL_64) + link_directories("${XIMEA_LIBRARY_DIR}") + endif() + if(X86_64) list(APPEND HIGHGUI_LIBRARIES m3apiX64) else() list(APPEND HIGHGUI_LIBRARIES m3api) diff --git a/modules/highgui/src/cap_ximea.cpp b/modules/highgui/src/cap_ximea.cpp index 7292727b7..427ea056f 100644 --- a/modules/highgui/src/cap_ximea.cpp +++ b/modules/highgui/src/cap_ximea.cpp @@ -62,74 +62,95 @@ void CvCaptureCAM_XIMEA::init() // Initialize camera input bool CvCaptureCAM_XIMEA::open( int wIndex ) { -#define HandleXiResult(res) if (res!=XI_OK) goto error; - + bool res = true; int mvret = XI_OK; - if(numDevices == 0) - return false; - - if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) + if(0 == numDevices) { + res = false; + } + else if(XI_OK != (mvret = xiOpenDevice(wIndex, &hmv))) + { + errMsg("Open XI_DEVICE failed", mvret); + res = false; + } + else + { + int width = 0; + int height = 0; + int isColor = 0; + + // 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); + } + } + } + + 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); - return false; - } - - // always use auto exposure/gain - mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1); - HandleXiResult(mvret); - - int width = 0; - mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width); - HandleXiResult(mvret); - - int height = 0; - mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); - 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 - 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; + xiCloseDevice(hmv); + hmv = NULL; + } } return true; - -error: - errMsg("Open XI_DEVICE failed", mvret); - xiCloseDevice(hmv); - hmv = NULL; - return false; } /**********************************************************************************/ From 05d93757597c68fc986cbab165707c2ef9f7e3d1 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Mon, 11 Nov 2013 10:26:28 +0100 Subject: [PATCH 2/4] Trailing whitespace removal. --- modules/highgui/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 69ece1b8f..c3ad7ca74 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -168,7 +168,7 @@ if(HAVE_XIMEA) ocv_include_directories(${XIMEA_PATH}) if(XIMEA_LIBRARY_DIR) link_directories("${XIMEA_LIBRARY_DIR}") - endif() + endif() if(X86_64) list(APPEND HIGHGUI_LIBRARIES m3apiX64) else() From 93120775cd8af9381a8ab10660b575113b81e630 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Mon, 11 Nov 2013 20:40:18 +0100 Subject: [PATCH 3/4] Using four spaces for indentation. --- modules/highgui/src/cap_ximea.cpp | 132 +++++++++++++++--------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/modules/highgui/src/cap_ximea.cpp b/modules/highgui/src/cap_ximea.cpp index 427ea056f..a2d0f0bd6 100644 --- a/modules/highgui/src/cap_ximea.cpp +++ b/modules/highgui/src/cap_ximea.cpp @@ -67,88 +67,88 @@ bool CvCaptureCAM_XIMEA::open( int wIndex ) if(0 == numDevices) { - res = false; + res = false; } else if(XI_OK != (mvret = xiOpenDevice(wIndex, &hmv))) { - errMsg("Open XI_DEVICE failed", mvret); - res = false; + errMsg("Open XI_DEVICE failed", mvret); + res = false; } else { - int width = 0; - int height = 0; - int isColor = 0; + int width = 0; + int height = 0; + int isColor = 0; - // 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 + // always use auto exposure/gain + if(XI_OK != (mvret = xiSetParamInt(hmv, XI_PRM_AEAG, 1))) { - // 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 + else if(XI_OK != (mvret = xiGetParamInt(hmv, XI_PRM_WIDTH, &width))) { - // 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); - } } - } + 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); + } + } + } - if(true == res) - { - //default capture timeout 10s - timeout = 10000; - - if(XI_OK != (mvret = xiStartAcquisition(hmv))) + if(true == res) { - errMsg("StartAcquisition XI_DEVICE failed", mvret); - res = false; + //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; } - } - else - { - errMsg("Open XI_DEVICE failed", mvret); - xiCloseDevice(hmv); - hmv = NULL; - } } return true; } From 78e16a906be177b0311c97834429cf40defc4b27 Mon Sep 17 00:00:00 2001 From: Philippe FOUBERT Date: Tue, 19 Nov 2013 21:51:47 +0100 Subject: [PATCH 4/4] 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 a2d0f0bd6..891b96115 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) - { - res = false; - } - else if(XI_OK != (mvret = xiOpenDevice(wIndex, &hmv))) + if(numDevices == 0) + return false; + + if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK) { errMsg("Open XI_DEVICE failed", mvret); - res = false; + return false; } - else + + 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 { - int width = 0; - int height = 0; - int isColor = 0; + // default image format RGB24 + mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24); + 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); - } - } - } + // always use auto white balance for color cameras + mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1); + HandleXiResult(mvret); - if(true == res) - { - //default capture timeout 10s - timeout = 10000; + // 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); - 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; - } + // 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; } /**********************************************************************************/