From 5d82ee4667e41f7468c52d4521f86dda44e2479a Mon Sep 17 00:00:00 2001
From: marian <marian.zajko@ximea.com>
Date: Thu, 29 Nov 2012 16:58:06 +0100
Subject: [PATCH] OpenCVFindXimea.cmake update:
 - fixed XIMEA API path checking, added option for WINX64 systems
 cap_ximea.cpp update:
 - fixed retrieveFrame() method to support monochrome cameras
 CMakeLists.txt (from highgui module) update:
 - added xiAPI library option for WINX64 systems

---
 cmake/OpenCVFindXimea.cmake       |   89 +++---
 modules/highgui/CMakeLists.txt    |  566 ++++++++++++++++---------------
 modules/highgui/src/cap_ximea.cpp |  681 +++++++++++++++++++++----------------
 3 files changed, 715 insertions(+), 621 deletions(-)

diff --git a/cmake/OpenCVFindXimea.cmake b/cmake/OpenCVFindXimea.cmake
index 5600275..cd141fa 100644
--- a/cmake/OpenCVFindXimea.cmake
+++ b/cmake/OpenCVFindXimea.cmake
@@ -1,42 +1,47 @@
-# - Find XIMEA
-# This module finds if XIMEA Software package is installed
-# and determines where the binaries and header files are.
-# This code sets the following variables:
-#
-#  XIMEA_FOUND          - True if XIMEA API found
-#  XIMEA_PATH:          - Path to the XIMEA API folder
-#  XIMEA_LIBRARY_DIR    - XIMEA libraries folder
-#
-# Created: 5 Aug 2011 by Marian Zajko (marian.zajko@ximea.com)
-# Updated: 25 June 2012 by Igor Kuzmin (parafin@ximea.com)
-#
-
-set(XIMEA_FOUND)
-set(XIMEA_PATH)
-set(XIMEA_LIBRARY_DIR)
-
-if(WIN32)
-  # Try to find the XIMEA API path in registry.
-  GET_FILENAME_COMPONENT(XIMEA_PATH "[HKEY_CURRENT_USER\\Software\\XIMEA\\CamSupport\\API;Path]" ABSOLUTE)
-
-  if(EXISTS XIMEA_PATH)
-    set(XIMEA_FOUND 1)
-    # set LIB folders
-    set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x86")
-  else()
-    set(XIMEA_FOUND 0)
-  endif()
-else()
-  if(EXISTS /opt/XIMEA)
-    set(XIMEA_FOUND 1)
-    # set folders
-    set(XIMEA_PATH /opt/XIMEA/include)
-  else()
-    set(XIMEA_FOUND 0)
-  endif()
-endif()
-
-mark_as_advanced(FORCE XIMEA_FOUND)
-mark_as_advanced(FORCE XIMEA_PATH)
-mark_as_advanced(FORCE XIMEA_LIBRARY_DIR)
-
+# - Find XIMEA
+# This module finds if XIMEA Software package is installed
+# and determines where the binaries and header files are.
+# This code sets the following variables:
+#
+#  XIMEA_FOUND          - True if XIMEA API found
+#  XIMEA_PATH:          - Path to the XIMEA API folder
+#  XIMEA_LIBRARY_DIR    - XIMEA libraries folder
+#
+# Created: 5 Aug 2011 by Marian Zajko (marian.zajko@ximea.com)
+# Updated: 25 June 2012 by Igor Kuzmin (parafin@ximea.com)
+# Updated: 22 October 2012 by Marian Zajko (marian.zajko@ximea.com)
+#
+
+set(XIMEA_FOUND)
+set(XIMEA_PATH)
+set(XIMEA_LIBRARY_DIR)
+
+if(WIN32)
+  # Try to find the XIMEA API path in registry.
+  GET_FILENAME_COMPONENT(XIMEA_PATH "[HKEY_CURRENT_USER\\Software\\XIMEA\\CamSupport\\API;Path]" ABSOLUTE)
+ 
+  if(EXISTS ${XIMEA_PATH})
+    set(XIMEA_FOUND 1)
+    # set LIB folders
+    if(CMAKE_CL_64)
+      set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x64")
+    else()
+      set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x86")
+    endif()
+  else()
+    set(XIMEA_FOUND 0)
+  endif()
+else()
+  if(EXISTS /opt/XIMEA)
+    set(XIMEA_FOUND 1)
+    # set folders
+    set(XIMEA_PATH /opt/XIMEA/include)
+  else()
+    set(XIMEA_FOUND 0)
+  endif()
+endif()
+
+mark_as_advanced(FORCE XIMEA_FOUND)
+mark_as_advanced(FORCE XIMEA_PATH)
+mark_as_advanced(FORCE XIMEA_LIBRARY_DIR)
+
diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt
index b4b2896..f79002c 100644
--- a/modules/highgui/CMakeLists.txt
+++ b/modules/highgui/CMakeLists.txt
@@ -1,281 +1,285 @@
-set(the_description "High-level GUI and Media I/O")
-ocv_add_module(highgui opencv_imgproc OPTIONAL opencv_androidcamera)
-
-# ----------------------------------------------------------------------------
-#  CMake file for highgui. See root CMakeLists.txt
-#   Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
-#   Jose Luis Blanco, 2008
-# ----------------------------------------------------------------------------
-
-ocv_clear_vars(GRFMT_LIBS)
-
-if(WITH_PNG OR WITH_TIFF OR WITH_OPENEXR)
-  ocv_include_directories(${ZLIB_INCLUDE_DIR})
-  list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
-endif()
-
-if(WITH_JPEG)
-  add_definitions(-DHAVE_JPEG)
-  ocv_include_directories(${JPEG_INCLUDE_DIR})
-  list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
-endif()
-
-if(WITH_PNG)
-  add_definitions(-DHAVE_PNG)
-  add_definitions(${PNG_DEFINITIONS})
-  ocv_include_directories(${PNG_INCLUDE_DIR})
-  list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
-endif()
-
-if(WITH_TIFF)
-  add_definitions(-DHAVE_TIFF)
-  ocv_include_directories(${TIFF_INCLUDE_DIR})
-  list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
-endif()
-
-if(WITH_JASPER)
-  add_definitions(-DHAVE_JASPER)
-  ocv_include_directories(${JASPER_INCLUDE_DIR})
-  list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
-endif()
-
-if(WITH_OPENEXR)
-  add_definitions(-DHAVE_OPENEXR)
-  include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
-  list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
-endif()
-
-file(GLOB grfmt_hdrs src/grfmt*.hpp)
-file(GLOB grfmt_srcs src/grfmt*.cpp)
-list(APPEND grfmt_hdrs src/bitstrm.hpp)
-list(APPEND grfmt_srcs src/bitstrm.cpp)
-
-source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
-
-set(highgui_hdrs
-    src/precomp.hpp
-    src/utils.hpp
-    src/cap_ffmpeg_impl.hpp
-    )
-
-set(highgui_srcs
-    src/cap.cpp
-    src/cap_images.cpp
-    src/cap_ffmpeg.cpp
-    src/loadsave.cpp
-    src/precomp.cpp
-    src/utils.cpp
-    src/window.cpp
-    )
-
-file(GLOB highgui_ext_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
-
-if(HAVE_QT)
-  if (HAVE_QT_OPENGL)
-    set(QT_USE_QTOPENGL TRUE)
-  endif()
-  include(${QT_USE_FILE})
-
-  if(QT_INCLUDE_DIR)
-    ocv_include_directories(${QT_INCLUDE_DIR})
-  endif()
-
-  QT4_ADD_RESOURCES(_RCC_OUTFILES src/window_QT.qrc)
-  QT4_WRAP_CPP(_MOC_OUTFILES src/window_QT.h)
-
-  list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
-  list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES})
-  ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag)
-  if(${_have_flag})
-    set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
-  endif()
-elseif(WIN32)
-  list(APPEND highgui_srcs src/window_w32.cpp)
-elseif(HAVE_GTK)
-  list(APPEND highgui_srcs src/window_gtk.cpp)
-elseif(APPLE)
-  if(WITH_CARBON)
-    add_definitions(-DHAVE_CARBON=1)
-    list(APPEND highgui_srcs src/window_carbon.cpp)
-    list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime")
-  elseif(NOT IOS)
-    add_definitions(-DHAVE_COCOA=1)
-    list(APPEND highgui_srcs src/window_cocoa.mm)
-    list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
-  endif()
-endif()
-
-if(WIN32)
-  list(APPEND highgui_srcs src/cap_vfw.cpp src/cap_cmu.cpp src/cap_dshow.cpp)
-endif(WIN32)
-
-if(HAVE_XINE)
-  list(APPEND highgui_srcs src/cap_xine.cpp)
-endif(HAVE_XINE)
-
-if(HAVE_DC1394_2)
-  list(APPEND highgui_srcs src/cap_dc1394_v2.cpp)
-endif(HAVE_DC1394_2)
-
-if(HAVE_DC1394)
-  list(APPEND highgui_srcs src/cap_dc1394.cpp)
-endif(HAVE_DC1394)
-
-if(HAVE_GSTREAMER)
-  list(APPEND highgui_srcs src/cap_gstreamer.cpp)
-endif(HAVE_GSTREAMER)
-
-if(HAVE_UNICAP)
-  list(APPEND highgui_srcs src/cap_unicap.cpp)
-endif(HAVE_UNICAP)
-
-if(HAVE_LIBV4L)
-  list(APPEND highgui_srcs src/cap_libv4l.cpp)
-elseif(HAVE_CAMV4L OR HAVE_CAMV4L2)
-  list(APPEND highgui_srcs src/cap_v4l.cpp)
-endif()
-
-if(HAVE_OPENNI)
-  list(APPEND highgui_srcs src/cap_openni.cpp)
-  ocv_include_directories(${OPENNI_INCLUDE_DIR})
-  list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
-endif(HAVE_OPENNI)
-
-if(HAVE_opencv_androidcamera)
-  list(APPEND highgui_srcs src/cap_android.cpp)
-  add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
-endif(HAVE_opencv_androidcamera)
-
-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()
-  list(APPEND HIGHGUI_LIBRARIES m3api)
-endif(HAVE_XIMEA)
-
-if(HAVE_FFMPEG)
-  if(UNIX AND BZIP2_LIBRARIES)
-    list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
-  endif()
-  if(APPLE)
-    list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
-  endif()
-endif(HAVE_FFMPEG)
-
-if(HAVE_PVAPI)
-  add_definitions(-DHAVE_PVAPI)
-  ocv_include_directories(${PVAPI_INCLUDE_PATH})
-  set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
-  list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY})
-endif()
-
-if(HAVE_GIGE_API)
-  add_definitions(-DHAVE_GIGE_API)
-  ocv_include_directories(${GIGEAPI_INCLUDE_PATH})
-  set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs})
-  list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES})
-  list(APPEND highgui_srcs src/cap_giganetix.cpp)
-endif(HAVE_GIGE_API)
-
-if(WITH_IMAGEIO)
-  add_definitions(-DHAVE_IMAGEIO=1)
-  if(IOS)
-    list(APPEND HIGHGUI_LIBRARIES "-framework ImageIO")
-  endif()
-endif(WITH_IMAGEIO)
-
-if(WITH_AVFOUNDATION)
-  add_definitions(-DHAVE_AVFOUNDATION=1)
-  list(APPEND highgui_srcs src/cap_avfoundation.mm)
-  list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
-elseif(APPLE)
-  add_definitions(-DHAVE_QUICKTIME=1)
-  if(WITH_QUICKTIME)
-    list(APPEND highgui_srcs src/cap_qt.cpp)
-    list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
-  else()
-    list(APPEND highgui_srcs src/cap_qtkit.mm)
-    list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
-  endif()
-endif()
-
-if(IOS)
-  add_definitions(-DHAVE_IOS=1)
-  list(APPEND highgui_srcs src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm)
-  list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary")
-endif()
-
-if(WIN32)
-  link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
-  include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
-endif()
-
-if(UNIX)
-  #these variables are set by CHECK_MODULE macro
-  foreach(P ${HIGHGUI_INCLUDE_DIRS})
-    ocv_include_directories(${P})
-  endforeach()
-
-  foreach(P ${HIGHGUI_LIBRARY_DIRS})
-    link_directories(${P})
-  endforeach()
-endif()
-
-source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
-source_group("Include" FILES ${highgui_ext_hdrs})
-ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
-ocv_module_include_directories()
-
-ocv_create_module(${GRFMT_LIBS} ${HIGHGUI_LIBRARIES})
-
-if(BUILD_SHARED_LIBS)
-  add_definitions(-DHIGHGUI_EXPORTS)
-endif()
-
-if(MSVC)
-  set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
-endif()
-
-#stop automatic dependencies propagation for this module
-set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
-
-ocv_add_precompiled_headers(${the_module})
-ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
-
-if(WIN32 AND WITH_FFMPEG)
-  #copy ffmpeg dll to the output folder
-  if(MSVC64 OR MINGW64)
-    set(FFMPEG_SUFFIX _64)
-  endif()
-
-  set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
-  set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
-  set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
-
-  #if(MSVC AND CMAKE_VERSION VERSION_GREATER "2.8.2")
-  #  add_custom_command(TARGET ${the_module} POST_BUILD
-  #                     COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>/${ffmpeg_bare_name_ver}"
-  #                     COMMENT "Copying ${ffmpeg_path} to the output directory")
-  #else
-  if(MSVC_IDE)
-    add_custom_command(TARGET ${the_module} POST_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
-                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
-                       COMMENT "Copying ${ffmpeg_path} to the output directory")
-  elseif(MSVC)
-    add_custom_command(TARGET ${the_module} POST_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
-                       COMMENT "Copying ${ffmpeg_path} to the output directory")
-  else()
-    add_custom_command(TARGET ${the_module} POST_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
-                       COMMENT "Copying ${ffmpeg_path} to the output directory")
-  endif()
-
-  install(FILES "${ffmpeg_path}" DESTINATION bin COMPONENT main RENAME "${ffmpeg_bare_name_ver}")
-endif()
-
-ocv_add_accuracy_tests()
-ocv_add_perf_tests()
+set(the_description "High-level GUI and Media I/O")
+ocv_add_module(highgui opencv_imgproc OPTIONAL opencv_androidcamera)
+
+# ----------------------------------------------------------------------------
+#  CMake file for highgui. See root CMakeLists.txt
+#   Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
+#   Jose Luis Blanco, 2008
+# ----------------------------------------------------------------------------
+
+ocv_clear_vars(GRFMT_LIBS)
+
+if(WITH_PNG OR WITH_TIFF OR WITH_OPENEXR)
+  ocv_include_directories(${ZLIB_INCLUDE_DIR})
+  list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
+endif()
+
+if(WITH_JPEG)
+  add_definitions(-DHAVE_JPEG)
+  ocv_include_directories(${JPEG_INCLUDE_DIR})
+  list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
+endif()
+
+if(WITH_PNG)
+  add_definitions(-DHAVE_PNG)
+  add_definitions(${PNG_DEFINITIONS})
+  ocv_include_directories(${PNG_INCLUDE_DIR})
+  list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
+endif()
+
+if(WITH_TIFF)
+  add_definitions(-DHAVE_TIFF)
+  ocv_include_directories(${TIFF_INCLUDE_DIR})
+  list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
+endif()
+
+if(WITH_JASPER)
+  add_definitions(-DHAVE_JASPER)
+  ocv_include_directories(${JASPER_INCLUDE_DIR})
+  list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
+endif()
+
+if(WITH_OPENEXR)
+  add_definitions(-DHAVE_OPENEXR)
+  include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
+  list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
+endif()
+
+file(GLOB grfmt_hdrs src/grfmt*.hpp)
+file(GLOB grfmt_srcs src/grfmt*.cpp)
+list(APPEND grfmt_hdrs src/bitstrm.hpp)
+list(APPEND grfmt_srcs src/bitstrm.cpp)
+
+source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
+
+set(highgui_hdrs
+    src/precomp.hpp
+    src/utils.hpp
+    src/cap_ffmpeg_impl.hpp
+    )
+
+set(highgui_srcs
+    src/cap.cpp
+    src/cap_images.cpp
+    src/cap_ffmpeg.cpp
+    src/loadsave.cpp
+    src/precomp.cpp
+    src/utils.cpp
+    src/window.cpp
+    )
+
+file(GLOB highgui_ext_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
+
+if(HAVE_QT)
+  if (HAVE_QT_OPENGL)
+    set(QT_USE_QTOPENGL TRUE)
+  endif()
+  include(${QT_USE_FILE})
+
+  if(QT_INCLUDE_DIR)
+    ocv_include_directories(${QT_INCLUDE_DIR})
+  endif()
+
+  QT4_ADD_RESOURCES(_RCC_OUTFILES src/window_QT.qrc)
+  QT4_WRAP_CPP(_MOC_OUTFILES src/window_QT.h)
+
+  list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
+  list(APPEND highgui_srcs src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES})
+  ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag)
+  if(${_have_flag})
+    set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
+  endif()
+elseif(WIN32)
+  list(APPEND highgui_srcs src/window_w32.cpp)
+elseif(HAVE_GTK)
+  list(APPEND highgui_srcs src/window_gtk.cpp)
+elseif(APPLE)
+  if(WITH_CARBON)
+    add_definitions(-DHAVE_CARBON=1)
+    list(APPEND highgui_srcs src/window_carbon.cpp)
+    list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime")
+  elseif(NOT IOS)
+    add_definitions(-DHAVE_COCOA=1)
+    list(APPEND highgui_srcs src/window_cocoa.mm)
+    list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
+  endif()
+endif()
+
+if(WIN32)
+  list(APPEND highgui_srcs src/cap_vfw.cpp src/cap_cmu.cpp src/cap_dshow.cpp)
+endif(WIN32)
+
+if(HAVE_XINE)
+  list(APPEND highgui_srcs src/cap_xine.cpp)
+endif(HAVE_XINE)
+
+if(HAVE_DC1394_2)
+  list(APPEND highgui_srcs src/cap_dc1394_v2.cpp)
+endif(HAVE_DC1394_2)
+
+if(HAVE_DC1394)
+  list(APPEND highgui_srcs src/cap_dc1394.cpp)
+endif(HAVE_DC1394)
+
+if(HAVE_GSTREAMER)
+  list(APPEND highgui_srcs src/cap_gstreamer.cpp)
+endif(HAVE_GSTREAMER)
+
+if(HAVE_UNICAP)
+  list(APPEND highgui_srcs src/cap_unicap.cpp)
+endif(HAVE_UNICAP)
+
+if(HAVE_LIBV4L)
+  list(APPEND highgui_srcs src/cap_libv4l.cpp)
+elseif(HAVE_CAMV4L OR HAVE_CAMV4L2)
+  list(APPEND highgui_srcs src/cap_v4l.cpp)
+endif()
+
+if(HAVE_OPENNI)
+  list(APPEND highgui_srcs src/cap_openni.cpp)
+  ocv_include_directories(${OPENNI_INCLUDE_DIR})
+  list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
+endif(HAVE_OPENNI)
+
+if(HAVE_opencv_androidcamera)
+  list(APPEND highgui_srcs src/cap_android.cpp)
+  add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
+endif(HAVE_opencv_androidcamera)
+
+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)
+    list(APPEND HIGHGUI_LIBRARIES m3apiX64)
+  else()
+    list(APPEND HIGHGUI_LIBRARIES m3api)
+  endif()
+endif(HAVE_XIMEA)
+
+if(HAVE_FFMPEG)
+  if(UNIX AND BZIP2_LIBRARIES)
+    list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
+  endif()
+  if(APPLE)
+    list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
+  endif()
+endif(HAVE_FFMPEG)
+
+if(HAVE_PVAPI)
+  add_definitions(-DHAVE_PVAPI)
+  ocv_include_directories(${PVAPI_INCLUDE_PATH})
+  set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
+  list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY})
+endif()
+
+if(HAVE_GIGE_API)
+  add_definitions(-DHAVE_GIGE_API)
+  ocv_include_directories(${GIGEAPI_INCLUDE_PATH})
+  set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs})
+  list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES})
+  list(APPEND highgui_srcs src/cap_giganetix.cpp)
+endif(HAVE_GIGE_API)
+
+if(WITH_IMAGEIO)
+  add_definitions(-DHAVE_IMAGEIO=1)
+  if(IOS)
+    list(APPEND HIGHGUI_LIBRARIES "-framework ImageIO")
+  endif()
+endif(WITH_IMAGEIO)
+
+if(WITH_AVFOUNDATION)
+  add_definitions(-DHAVE_AVFOUNDATION=1)
+  list(APPEND highgui_srcs src/cap_avfoundation.mm)
+  list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
+elseif(APPLE)
+  add_definitions(-DHAVE_QUICKTIME=1)
+  if(WITH_QUICKTIME)
+    list(APPEND highgui_srcs src/cap_qt.cpp)
+    list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
+  else()
+    list(APPEND highgui_srcs src/cap_qtkit.mm)
+    list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
+  endif()
+endif()
+
+if(IOS)
+  add_definitions(-DHAVE_IOS=1)
+  list(APPEND highgui_srcs src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm)
+  list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary")
+endif()
+
+if(WIN32)
+  link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
+  include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
+endif()
+
+if(UNIX)
+  #these variables are set by CHECK_MODULE macro
+  foreach(P ${HIGHGUI_INCLUDE_DIRS})
+    ocv_include_directories(${P})
+  endforeach()
+
+  foreach(P ${HIGHGUI_LIBRARY_DIRS})
+    link_directories(${P})
+  endforeach()
+endif()
+
+source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
+source_group("Include" FILES ${highgui_ext_hdrs})
+ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
+ocv_module_include_directories()
+
+ocv_create_module(${GRFMT_LIBS} ${HIGHGUI_LIBRARIES})
+
+if(BUILD_SHARED_LIBS)
+  add_definitions(-DHIGHGUI_EXPORTS)
+endif()
+
+if(MSVC)
+  set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
+endif()
+
+#stop automatic dependencies propagation for this module
+set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
+
+ocv_add_precompiled_headers(${the_module})
+ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
+
+if(WIN32 AND WITH_FFMPEG)
+  #copy ffmpeg dll to the output folder
+  if(MSVC64 OR MINGW64)
+    set(FFMPEG_SUFFIX _64)
+  endif()
+
+  set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
+  set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
+  set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
+
+  #if(MSVC AND CMAKE_VERSION VERSION_GREATER "2.8.2")
+  #  add_custom_command(TARGET ${the_module} POST_BUILD
+  #                     COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>/${ffmpeg_bare_name_ver}"
+  #                     COMMENT "Copying ${ffmpeg_path} to the output directory")
+  #else
+  if(MSVC_IDE)
+    add_custom_command(TARGET ${the_module} POST_BUILD
+                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
+                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
+                       COMMENT "Copying ${ffmpeg_path} to the output directory")
+  elseif(MSVC)
+    add_custom_command(TARGET ${the_module} POST_BUILD
+                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
+                       COMMENT "Copying ${ffmpeg_path} to the output directory")
+  else()
+    add_custom_command(TARGET ${the_module} POST_BUILD
+                       COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
+                       COMMENT "Copying ${ffmpeg_path} to the output directory")
+  endif()
+
+  install(FILES "${ffmpeg_path}" DESTINATION bin COMPONENT main RENAME "${ffmpeg_bare_name_ver}")
+endif()
+
+ocv_add_accuracy_tests()
+ocv_add_perf_tests()
diff --git a/modules/highgui/src/cap_ximea.cpp b/modules/highgui/src/cap_ximea.cpp
index dbb8f58..9b7a5b3 100644
--- a/modules/highgui/src/cap_ximea.cpp
+++ b/modules/highgui/src/cap_ximea.cpp
@@ -1,299 +1,384 @@
-#include "precomp.hpp"
-
-#include "xiApi.h"
-#include "xiExt.h"
-#include "m3Api.h"
-
-/**********************************************************************************/
-
-class CvCaptureCAM_XIMEA : public CvCapture
-{
-public:
-    CvCaptureCAM_XIMEA() { init(); }
-    virtual ~CvCaptureCAM_XIMEA() { close(); }
-
-    virtual bool open( int index );
-    virtual void close();
-    virtual double getProperty(int);
-    virtual bool setProperty(int, double);
-    virtual bool grabFrame();
-    virtual IplImage* retrieveFrame(int);
-    virtual int getCaptureDomain() { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc...
-
-protected:
-    void init();
-    void errMsg(const char* msg, int errNum);
-    IplImage* frame;
-
-    HANDLE    hmv;
-    DWORD     numDevices;
-    XI_IMG    image;
-    int       width;
-    int       height;
-    int       format;
-    int       timeout;
-};
-
-/**********************************************************************************/
-
-CvCapture* cvCreateCameraCapture_XIMEA( int index )
-{
-     CvCaptureCAM_XIMEA* capture = new CvCaptureCAM_XIMEA;
-
-    if( capture->open( index ))
-        return capture;
-
-    delete capture;
-    return 0;
-}
-
-/**********************************************************************************/
-// Enumerate connected devices
-void CvCaptureCAM_XIMEA::init()
-{
-    xiGetNumberDevices( &numDevices);
-    hmv = NULL;
-    memset(&image, 0, sizeof(XI_IMG));
-}
-
-
-/**********************************************************************************/
-// 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
-    mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
-    if(mvret != XI_OK) goto error;
-
-    // always use auto white ballance
-    mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
-    if(mvret != XI_OK) goto error;
-
-    mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
-    if(mvret != XI_OK) goto error;
-
-    mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
-    if(mvret != XI_OK) goto error;
-
-    // default image format RGB24
-    format = XI_RGB24;
-    mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, format);
-    if(mvret != XI_OK) goto error;
-
-    // allocate frame buffer for RGB24 image
-    frame = cvCreateImage(cvSize( width, height), IPL_DEPTH_8U, 3);
-
-    //default capture timeout 10s
-    timeout = 10000;
-
-    mvret = xiStartAcquisition(hmv);
-    if(mvret != XI_OK)
-    {
-        errMsg("StartAcquisition XI_DEVICE failed", mvret);
-        goto error;
-    }
-
-    return true;
-
-error:
-    xiCloseDevice(hmv);
-    hmv = NULL;
-    return false;
-}
-
-/**********************************************************************************/
-
-void CvCaptureCAM_XIMEA::close()
-{
-    if(hmv)
-    {
-        xiStopAcquisition(hmv);
-        xiCloseDevice(hmv);
-        hmv = NULL;
-    }
-}
-
-/**********************************************************************************/
-
-bool CvCaptureCAM_XIMEA::grabFrame()
-{
-    image.size = sizeof(XI_IMG);
-    int mvret = xiGetImage( hmv, timeout, &image);
-
-    if(mvret == MM40_ACQUISITION_STOPED)
-    {
-        xiStartAcquisition(hmv);
-        mvret = xiGetImage(hmv, timeout, &image);
-    }
-
-    if(mvret != XI_OK)
-    {
-        errMsg("Error during GetImage", mvret);
-        return false;
-    }
-
-    return true;
-}
-
-/**********************************************************************************/
-
-IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
-{
-    // update cvImage after format has changed
-    if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format)
-    {
-        cvReleaseImage(&frame);
-        switch( image.frm)
-        {
-        case XI_MONO8  : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break;
-        case XI_MONO16 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_16U, 1); break;
-        case XI_RGB24  : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 3); break;
-        case XI_RGB32  : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 4); break;
-        default :
-            return frame;
-        }
-        // update global image format
-        format = image.frm;
-        width = image.width;
-        height = image.height;
-    }
-
-    // copy pixel data
-    switch( image.frm)
-    {
-    case XI_MONO8  : memcpy( frame->imageData, image.bp, image.width*image.height); break;
-    case XI_MONO16 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(WORD)); break;
-    case XI_RGB24  : memcpy( frame->imageData, image.bp, image.width*image.height*3); break;
-    case XI_RGB32  : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(DWORD)); break;
-    default: break;
-    }
-    return frame;
-}
-
-/**********************************************************************************/
-
-double CvCaptureCAM_XIMEA::getProperty( int property_id )
-{
-    if(hmv == NULL)
-        return 0;
-
-    int ival = 0;
-    float fval = 0;
-
-    switch( property_id )
-    {
-    // OCV parameters
-    case CV_CAP_PROP_POS_FRAMES   : return (double) image.nframe;
-    case CV_CAP_PROP_FRAME_WIDTH  : xiGetParamInt( hmv, XI_PRM_WIDTH, &ival); return ival;
-    case CV_CAP_PROP_FRAME_HEIGHT : xiGetParamInt( hmv, XI_PRM_HEIGHT, &ival); return ival;
-    case CV_CAP_PROP_FPS          : xiGetParamFloat( hmv, XI_PRM_FRAMERATE, &fval); return fval;
-    case CV_CAP_PROP_GAIN         : xiGetParamFloat( hmv, XI_PRM_GAIN, &fval); return fval;
-    case CV_CAP_PROP_EXPOSURE     : xiGetParamInt( hmv, XI_PRM_EXPOSURE, &ival); return ival;
-
-    // XIMEA camera properties
-    case CV_CAP_PROP_XI_DOWNSAMPLING  : xiGetParamInt( hmv, XI_PRM_DOWNSAMPLING, &ival); return ival;
-    case CV_CAP_PROP_XI_DATA_FORMAT   : xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &ival); return ival;
-    case CV_CAP_PROP_XI_OFFSET_X      : xiGetParamInt( hmv, XI_PRM_OFFSET_X, &ival); return ival;
-    case CV_CAP_PROP_XI_OFFSET_Y      : xiGetParamInt( hmv, XI_PRM_OFFSET_Y, &ival); return ival;
-    case CV_CAP_PROP_XI_TRG_SOURCE    : xiGetParamInt( hmv, XI_PRM_TRG_SOURCE, &ival); return ival;
-    case CV_CAP_PROP_XI_GPI_SELECTOR  : xiGetParamInt( hmv, XI_PRM_GPI_SELECTOR, &ival); return ival;
-    case CV_CAP_PROP_XI_GPI_MODE      : xiGetParamInt( hmv, XI_PRM_GPI_MODE, &ival); return ival;
-    case CV_CAP_PROP_XI_GPI_LEVEL     : xiGetParamInt( hmv, XI_PRM_GPI_LEVEL, &ival); return ival;
-    case CV_CAP_PROP_XI_GPO_SELECTOR  : xiGetParamInt( hmv, XI_PRM_GPO_SELECTOR, &ival); return ival;
-    case CV_CAP_PROP_XI_GPO_MODE      : xiGetParamInt( hmv, XI_PRM_GPO_MODE, &ival); return ival;
-    case CV_CAP_PROP_XI_LED_SELECTOR  : xiGetParamInt( hmv, XI_PRM_LED_SELECTOR, &ival); return ival;
-    case CV_CAP_PROP_XI_LED_MODE      : xiGetParamInt( hmv, XI_PRM_LED_MODE, &ival); return ival;
-    case CV_CAP_PROP_XI_AUTO_WB       : xiGetParamInt( hmv, XI_PRM_AUTO_WB, &ival); return ival;
-    case CV_CAP_PROP_XI_AEAG          : xiGetParamInt( hmv, XI_PRM_AEAG, &ival); return ival;
-    case CV_CAP_PROP_XI_EXP_PRIORITY  : xiGetParamFloat( hmv, XI_PRM_EXP_PRIORITY, &fval); return fval;
-    case CV_CAP_PROP_XI_AE_MAX_LIMIT  : xiGetParamInt( hmv, XI_PRM_EXP_PRIORITY, &ival); return ival;
-    case CV_CAP_PROP_XI_AG_MAX_LIMIT  : xiGetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, &fval); return fval;
-    case CV_CAP_PROP_XI_AEAG_LEVEL    : xiGetParamInt( hmv, XI_PRM_AEAG_LEVEL, &ival); return ival;
-    case CV_CAP_PROP_XI_TIMEOUT       : return timeout;
-
-    }
-    return 0;
-}
-
-/**********************************************************************************/
-
-bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
-{
-    int ival = (int) value;
-    float fval = (float) value;
-
-    int mvret = XI_OK;
-
-    switch(property_id)
-    {
-    // OCV parameters
-    case CV_CAP_PROP_FRAME_WIDTH  : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival);
-        if(mvret == XI_OK) width = ival;
-        break;
-    case CV_CAP_PROP_FRAME_HEIGHT : mvret = xiSetParamInt( hmv, XI_PRM_HEIGHT, ival);
-        if(mvret == XI_OK) height = ival;
-        break;
-    case CV_CAP_PROP_FPS          : mvret = xiSetParamFloat( hmv, XI_PRM_FRAMERATE, fval); break;
-    case CV_CAP_PROP_GAIN         : mvret = xiSetParamFloat( hmv, XI_PRM_GAIN, fval); break;
-    case CV_CAP_PROP_EXPOSURE     : mvret = xiSetParamInt( hmv, XI_PRM_EXPOSURE, ival); break;
-    // XIMEA camera properties
-    case CV_CAP_PROP_XI_DOWNSAMPLING  : mvret = xiSetParamInt( hmv, XI_PRM_DOWNSAMPLING, ival); break;
-    case CV_CAP_PROP_XI_DATA_FORMAT   : mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, ival);
-        if(mvret == XI_OK) format = ival;
-        break;
-    case CV_CAP_PROP_XI_OFFSET_X      : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_X, ival); break;
-    case CV_CAP_PROP_XI_OFFSET_Y      : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_Y, ival); break;
-    case CV_CAP_PROP_XI_TRG_SOURCE    : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, ival); break;
-    case CV_CAP_PROP_XI_GPI_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_GPI_SELECTOR, ival); break;
-    case CV_CAP_PROP_XI_TRG_SOFTWARE  : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, 1); break;
-    case CV_CAP_PROP_XI_GPI_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_GPI_MODE, ival); break;
-    case CV_CAP_PROP_XI_GPI_LEVEL     : mvret = xiSetParamInt( hmv, XI_PRM_GPI_LEVEL, ival); break;
-    case CV_CAP_PROP_XI_GPO_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_GPO_SELECTOR, ival); break;
-    case CV_CAP_PROP_XI_GPO_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_GPO_MODE, ival); break;
-    case CV_CAP_PROP_XI_LED_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_LED_SELECTOR, ival); break;
-    case CV_CAP_PROP_XI_LED_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_LED_MODE, ival); break;
-    case CV_CAP_PROP_XI_AUTO_WB       : mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, ival); break;
-    case CV_CAP_PROP_XI_MANUAL_WB     : mvret = xiSetParamInt( hmv, XI_PRM_LED_MODE, ival); break;
-    case CV_CAP_PROP_XI_AEAG          : mvret = xiSetParamInt( hmv, XI_PRM_AEAG, ival); break;
-    case CV_CAP_PROP_XI_EXP_PRIORITY  : mvret = xiSetParamFloat( hmv, XI_PRM_EXP_PRIORITY, fval); break;
-    case CV_CAP_PROP_XI_AE_MAX_LIMIT  : mvret = xiSetParamInt( hmv, XI_PRM_EXP_PRIORITY, ival); break;
-    case CV_CAP_PROP_XI_AG_MAX_LIMIT  : mvret = xiSetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, fval); break;
-    case CV_CAP_PROP_XI_AEAG_LEVEL    : mvret = xiSetParamInt( hmv, XI_PRM_AEAG_LEVEL, ival); break;
-    case CV_CAP_PROP_XI_TIMEOUT       : timeout = ival; break;
-    }
-
-    if(mvret != XI_OK)
-    {
-        errMsg("Set parameter error", mvret);
-        return false;
-    }
-    else
-        return true;
-
-}
-
-/**********************************************************************************/
-
-void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum)
-{
-#if defined WIN32 || defined _WIN32
-    char buf[512];
-    sprintf( buf, "%s : %d\n", msg, errNum);
-    OutputDebugString(buf);
-#else
-    fprintf(stderr, "%s : %d\n", msg, errNum);
-#endif
-}
-
+#include "precomp.hpp"
+
+#include "xiApi.h"
+#include "xiExt.h"
+#include "m3Api.h"
+
+/**********************************************************************************/
+
+class CvCaptureCAM_XIMEA : public CvCapture
+{
+public:
+    CvCaptureCAM_XIMEA() { init(); }
+    virtual ~CvCaptureCAM_XIMEA() { close(); }
+
+    virtual bool open( int index );
+    virtual void close();
+    virtual double getProperty(int);
+    virtual bool setProperty(int, double);
+    virtual bool grabFrame();
+    virtual IplImage* retrieveFrame(int);
+    virtual int getCaptureDomain() { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc...
+
+protected:
+    void init();
+    void errMsg(const char* msg, int errNum);
+	void resetImage();
+	int  getBpp();
+    IplImage* frame;
+
+    HANDLE    hmv;
+    DWORD     numDevices;
+    XI_IMG    image;
+    int       width;
+    int       height;
+    int       format;
+    int       timeout;
+	int       isColor;
+};
+
+/**********************************************************************************/
+
+CvCapture* cvCreateCameraCapture_XIMEA( int index )
+{
+     CvCaptureCAM_XIMEA* capture = new CvCaptureCAM_XIMEA;
+
+    if( capture->open( index ))
+        return capture;
+
+    delete capture;
+    return 0;
+}
+
+/**********************************************************************************/
+// Enumerate connected devices
+void CvCaptureCAM_XIMEA::init()
+{
+    xiGetNumberDevices( &numDevices);
+    hmv = NULL;
+    memset(&image, 0, sizeof(XI_IMG));
+}
+
+
+/**********************************************************************************/
+// 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
+    mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
+    if(mvret != XI_OK) goto error;
+
+    // always use auto white ballance
+    mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
+    if(mvret != XI_OK) goto error;
+
+    mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
+    if(mvret != XI_OK) goto error;
+
+    mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
+    if(mvret != XI_OK) goto error;
+
+    // default image format RGB24
+    format = XI_RGB24;
+    mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, format);
+    if(mvret != XI_OK) goto error;
+
+    // allocate frame buffer for RGB24 image
+    frame = cvCreateImage(cvSize( width, height), IPL_DEPTH_8U, 3);
+
+    // check if is color camera
+    xiGetParamInt(hmv, XI_PRM_IMAGE_IS_COLOR, &isColor);
+
+    //default capture timeout 10s
+    timeout = 10000;
+
+    mvret = xiStartAcquisition(hmv);
+    if(mvret != XI_OK)
+    {
+        errMsg("StartAcquisition XI_DEVICE failed", mvret);
+        goto error;
+    }
+
+    return true;
+
+error:
+    xiCloseDevice(hmv);
+    hmv = NULL;
+    return false;
+}
+
+/**********************************************************************************/
+
+void CvCaptureCAM_XIMEA::close()
+{
+	if(frame)
+		cvReleaseImage(&frame);
+
+    xiStopAcquisition(hmv);
+    xiCloseDevice(hmv);
+    hmv = NULL;
+}
+
+/**********************************************************************************/
+
+bool CvCaptureCAM_XIMEA::grabFrame()
+{
+    image.size = sizeof(XI_IMG);
+    int mvret = xiGetImage( hmv, timeout, &image);
+
+    if(mvret == MM40_ACQUISITION_STOPED)
+    {
+        xiStartAcquisition(hmv);
+        mvret = xiGetImage(hmv, timeout, &image);
+    }
+
+    if(mvret != XI_OK)
+    {
+        errMsg("Error during GetImage", mvret);
+        return false;
+    }
+
+    return true;
+}
+
+/**********************************************************************************/
+
+IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
+{
+    // update cvImage after format has changed
+	resetImage();
+    
+    // copy pixel data
+    switch( image.frm)
+    {
+    case XI_MONO8       : 
+	case XI_RAW8        : memcpy( frame->imageData, image.bp, image.width*image.height); break;
+    case XI_MONO16      :
+	case XI_RAW16       : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(WORD)); break;
+    case XI_RGB24       :
+	case XI_RGB_PLANAR  :
+		if(isColor)
+		{
+			memcpy( frame->imageData, image.bp, image.width*image.height*3); 
+			break;
+		}
+		else
+		{
+			memcpy( frame->imageData, image.bp, image.width*image.height); 
+			break;
+		}
+    case XI_RGB32       : 
+		if(isColor)
+		{
+			memcpy( frame->imageData, image.bp, image.width*image.height*4); 
+			break;
+		}
+		else
+		{
+			memcpy( frame->imageData, image.bp, image.width*image.height); 
+			break;
+		}
+    default: break;
+    }
+    return frame;
+}
+
+/**********************************************************************************/
+
+double CvCaptureCAM_XIMEA::getProperty( int property_id )
+{
+    if(hmv == NULL)
+        return 0;
+
+    int ival = 0;
+    float fval = 0;
+
+    switch( property_id )
+    {
+    // OCV parameters
+    case CV_CAP_PROP_POS_FRAMES   : return (double) image.nframe;
+    case CV_CAP_PROP_FRAME_WIDTH  : xiGetParamInt( hmv, XI_PRM_WIDTH, &ival); return ival;
+    case CV_CAP_PROP_FRAME_HEIGHT : xiGetParamInt( hmv, XI_PRM_HEIGHT, &ival); return ival;
+    case CV_CAP_PROP_FPS          : xiGetParamFloat( hmv, XI_PRM_FRAMERATE, &fval); return fval;
+    case CV_CAP_PROP_GAIN         : xiGetParamFloat( hmv, XI_PRM_GAIN, &fval); return fval;
+    case CV_CAP_PROP_EXPOSURE     : xiGetParamInt( hmv, XI_PRM_EXPOSURE, &ival); return ival;
+
+    // XIMEA camera properties
+    case CV_CAP_PROP_XI_DOWNSAMPLING  : xiGetParamInt( hmv, XI_PRM_DOWNSAMPLING, &ival); return ival;
+    case CV_CAP_PROP_XI_DATA_FORMAT   : xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &ival); return ival;
+    case CV_CAP_PROP_XI_OFFSET_X      : xiGetParamInt( hmv, XI_PRM_OFFSET_X, &ival); return ival;
+    case CV_CAP_PROP_XI_OFFSET_Y      : xiGetParamInt( hmv, XI_PRM_OFFSET_Y, &ival); return ival;
+    case CV_CAP_PROP_XI_TRG_SOURCE    : xiGetParamInt( hmv, XI_PRM_TRG_SOURCE, &ival); return ival;
+    case CV_CAP_PROP_XI_GPI_SELECTOR  : xiGetParamInt( hmv, XI_PRM_GPI_SELECTOR, &ival); return ival;
+    case CV_CAP_PROP_XI_GPI_MODE      : xiGetParamInt( hmv, XI_PRM_GPI_MODE, &ival); return ival;
+    case CV_CAP_PROP_XI_GPI_LEVEL     : xiGetParamInt( hmv, XI_PRM_GPI_LEVEL, &ival); return ival;
+    case CV_CAP_PROP_XI_GPO_SELECTOR  : xiGetParamInt( hmv, XI_PRM_GPO_SELECTOR, &ival); return ival;
+    case CV_CAP_PROP_XI_GPO_MODE      : xiGetParamInt( hmv, XI_PRM_GPO_MODE, &ival); return ival;
+    case CV_CAP_PROP_XI_LED_SELECTOR  : xiGetParamInt( hmv, XI_PRM_LED_SELECTOR, &ival); return ival;
+    case CV_CAP_PROP_XI_LED_MODE      : xiGetParamInt( hmv, XI_PRM_LED_MODE, &ival); return ival;
+    case CV_CAP_PROP_XI_AUTO_WB       : xiGetParamInt( hmv, XI_PRM_AUTO_WB, &ival); return ival;
+    case CV_CAP_PROP_XI_AEAG          : xiGetParamInt( hmv, XI_PRM_AEAG, &ival); return ival;
+    case CV_CAP_PROP_XI_EXP_PRIORITY  : xiGetParamFloat( hmv, XI_PRM_EXP_PRIORITY, &fval); return fval;
+    case CV_CAP_PROP_XI_AE_MAX_LIMIT  : xiGetParamInt( hmv, XI_PRM_EXP_PRIORITY, &ival); return ival;
+    case CV_CAP_PROP_XI_AG_MAX_LIMIT  : xiGetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, &fval); return fval;
+    case CV_CAP_PROP_XI_AEAG_LEVEL    : xiGetParamInt( hmv, XI_PRM_AEAG_LEVEL, &ival); return ival;
+    case CV_CAP_PROP_XI_TIMEOUT       : return timeout;
+
+    }
+    return 0;
+}
+
+/**********************************************************************************/
+
+bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
+{
+    int ival = (int) value;
+    float fval = (float) value;
+
+    int mvret = XI_OK;
+
+    switch(property_id)
+    {
+    // OCV parameters
+    case CV_CAP_PROP_FRAME_WIDTH  : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival);
+        if(mvret == XI_OK) width = ival;
+        break;
+    case CV_CAP_PROP_FRAME_HEIGHT : mvret = xiSetParamInt( hmv, XI_PRM_HEIGHT, ival);
+        if(mvret == XI_OK) height = ival;
+        break;
+    case CV_CAP_PROP_FPS          : mvret = xiSetParamFloat( hmv, XI_PRM_FRAMERATE, fval); break;
+    case CV_CAP_PROP_GAIN         : mvret = xiSetParamFloat( hmv, XI_PRM_GAIN, fval); break;
+    case CV_CAP_PROP_EXPOSURE     : mvret = xiSetParamInt( hmv, XI_PRM_EXPOSURE, ival); break;
+    // XIMEA camera properties
+    case CV_CAP_PROP_XI_DOWNSAMPLING  : mvret = xiSetParamInt( hmv, XI_PRM_DOWNSAMPLING, ival); break;
+    case CV_CAP_PROP_XI_DATA_FORMAT   : mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, ival);
+        if(mvret == XI_OK) format = ival;
+        break;
+    case CV_CAP_PROP_XI_OFFSET_X      : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_X, ival); break;
+    case CV_CAP_PROP_XI_OFFSET_Y      : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_Y, ival); break;
+    case CV_CAP_PROP_XI_TRG_SOURCE    : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, ival); break;
+    case CV_CAP_PROP_XI_GPI_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_GPI_SELECTOR, ival); break;
+    case CV_CAP_PROP_XI_TRG_SOFTWARE  : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, 1); break;
+    case CV_CAP_PROP_XI_GPI_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_GPI_MODE, ival); break;
+    case CV_CAP_PROP_XI_GPI_LEVEL     : mvret = xiSetParamInt( hmv, XI_PRM_GPI_LEVEL, ival); break;
+    case CV_CAP_PROP_XI_GPO_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_GPO_SELECTOR, ival); break;
+    case CV_CAP_PROP_XI_GPO_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_GPO_MODE, ival); break;
+    case CV_CAP_PROP_XI_LED_SELECTOR  : mvret = xiSetParamInt( hmv, XI_PRM_LED_SELECTOR, ival); break;
+    case CV_CAP_PROP_XI_LED_MODE      : mvret = xiSetParamInt( hmv, XI_PRM_LED_MODE, ival); break;
+    case CV_CAP_PROP_XI_AUTO_WB       : mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, ival); break;
+    case CV_CAP_PROP_XI_MANUAL_WB     : mvret = xiSetParamInt( hmv, XI_PRM_LED_MODE, ival); break;
+    case CV_CAP_PROP_XI_AEAG          : mvret = xiSetParamInt( hmv, XI_PRM_AEAG, ival); break;
+    case CV_CAP_PROP_XI_EXP_PRIORITY  : mvret = xiSetParamFloat( hmv, XI_PRM_EXP_PRIORITY, fval); break;
+    case CV_CAP_PROP_XI_AE_MAX_LIMIT  : mvret = xiSetParamInt( hmv, XI_PRM_EXP_PRIORITY, ival); break;
+    case CV_CAP_PROP_XI_AG_MAX_LIMIT  : mvret = xiSetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, fval); break;
+    case CV_CAP_PROP_XI_AEAG_LEVEL    : mvret = xiSetParamInt( hmv, XI_PRM_AEAG_LEVEL, ival); break;
+    case CV_CAP_PROP_XI_TIMEOUT       : timeout = ival; break;
+    }
+
+    if(mvret != XI_OK)
+    {
+        errMsg("Set parameter error", mvret);
+        return false;
+    }
+    else
+        return true;
+
+}
+
+/**********************************************************************************/
+
+void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum)
+{
+#if defined WIN32 || defined _WIN32
+    char buf[512];
+    sprintf( buf, "%s : %d\n", msg, errNum);
+    OutputDebugString(buf);
+#else
+    fprintf(stderr, "%s : %d\n", msg, errNum);
+#endif
+}
+
+/**********************************************************************************/
+
+void CvCaptureCAM_XIMEA::resetImage()
+{
+	if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format || getBpp() != frame->nChannels)
+    {
+        if(frame)
+			cvReleaseImage(&frame);
+
+        switch( image.frm)
+        {
+		case XI_MONO8       :
+		case XI_RAW8        : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break;
+        case XI_MONO16      : 
+		case XI_RAW16       : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_16U, 1); break;
+		case XI_RGB24       : 
+		case XI_RGB_PLANAR  :
+			if(isColor)
+			{
+				frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 3); 
+				break;
+			}
+			else
+			{
+				frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); 
+				break;
+			}
+        case XI_RGB32       : 
+			if(isColor)
+			{
+				frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 4); break;
+			}
+			else
+			{
+				frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break;
+			}
+        default :
+            return;
+        }
+        // update global image format
+        format = image.frm;
+        width = image.width;
+        height = image.height;
+    }
+}
+
+/**********************************************************************************/
+
+int  CvCaptureCAM_XIMEA::getBpp()
+{
+	switch( image.frm)
+    {
+	case XI_MONO8       :
+	case XI_RAW8        : return 1;
+    case XI_MONO16      : 
+	case XI_RAW16       : return 2;
+	case XI_RGB24       : 
+	case XI_RGB_PLANAR  :
+		if(isColor)
+			return 3;
+		else
+			return 1;
+    case XI_RGB32       : 
+		if(isColor)
+			return 4;
+		else
+			return 1;
+    default :
+        return 0;
+    }
+}
+
 /**********************************************************************************/
\ No newline at end of file
-- 
1.7.0.2.msysgit.0

