diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index d47dd53fcd..59dca6990e 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -29,6 +29,10 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) endif(MSVC) +if (HAVE_WINRT) + add_definitions(-DHAVE_WINRT) +endif() + add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs}) target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARY}) diff --git a/3rdparty/libpng/opencv-libpng.path b/3rdparty/libpng/opencv-libpng.path new file mode 100644 index 0000000000..6ca96392a0 --- /dev/null +++ b/3rdparty/libpng/opencv-libpng.path @@ -0,0 +1,22 @@ +diff --git a/3rdparty/libpng/pngpriv.h b/3rdparty/libpng/pngpriv.h +index 07b2b0b..e7824b8 100644 +--- a/3rdparty/libpng/pngpriv.h ++++ b/3rdparty/libpng/pngpriv.h +@@ -360,7 +360,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; + + /* Memory model/platform independent fns */ + #ifndef PNG_ABORT +-# ifdef _WINDOWS_ ++# if defined(_WINDOWS_) && !defined(HAVE_WINRT) + # define PNG_ABORT() ExitProcess(0) + # else + # define PNG_ABORT() abort() +@@ -378,7 +378,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; + # define png_memcpy _fmemcpy + # define png_memset _fmemset + #else +-# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ ++# if defined(_WINDOWS_) && !defined(HAVE_WINRT) /* Favor Windows over C runtime fns */ + # define CVT_PTR(ptr) (ptr) + # define CVT_PTR_NOCHECK(ptr) (ptr) + # define png_strlen lstrlenA diff --git a/3rdparty/libpng/pngpriv.h b/3rdparty/libpng/pngpriv.h index 07b2b0b05b..e7824b839e 100644 --- a/3rdparty/libpng/pngpriv.h +++ b/3rdparty/libpng/pngpriv.h @@ -360,7 +360,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; /* Memory model/platform independent fns */ #ifndef PNG_ABORT -# ifdef _WINDOWS_ +# if defined(_WINDOWS_) && !defined(HAVE_WINRT) # define PNG_ABORT() ExitProcess(0) # else # define PNG_ABORT() abort() @@ -378,7 +378,7 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; # define png_memcpy _fmemcpy # define png_memset _fmemset #else -# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ +# if defined(_WINDOWS_) && !defined(HAVE_WINRT) /* Favor Windows over C runtime fns */ # define CVT_PTR(ptr) (ptr) # define CVT_PTR_NOCHECK(ptr) (ptr) # define png_strlen lstrlenA diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e25f16cce..0c498cd37a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -736,8 +736,8 @@ if(DEFINED WITH_GIGEAPI) endif(DEFINED WITH_GIGEAPI) if(DEFINED WITH_QUICKTIME) - status(" QuickTime:" WITH_QUICKTIME THEN YES ELSE NO) - status(" QTKit:" WITH_QUICKTIME THEN NO ELSE YES) + status(" QuickTime:" HAVE_QUICKTIME THEN YES ELSE NO) + status(" QTKit:" HAVE_QTKIT THEN YES ELSE NO) endif(DEFINED WITH_QUICKTIME) if(DEFINED WITH_UNICAP) diff --git a/cmake/OpenCVCRTLinkage.cmake b/cmake/OpenCVCRTLinkage.cmake index 295b914b68..62d89af4a9 100644 --- a/cmake/OpenCVCRTLinkage.cmake +++ b/cmake/OpenCVCRTLinkage.cmake @@ -4,37 +4,39 @@ endif() #INCLUDE (CheckIncludeFiles) -if (ENABLE_WINRT_MODE) - set(HAVE_WINRT True) +set(HAVE_WINRT FALSE) - # search Windows Platform SDK - message(STATUS "Checking for Windows Platfrom SDK") - GET_FILENAME_COMPONENT(WINDOWS_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE) - if (WINDOWS_SDK_PATH STREQUAL "") - message(ERROR "Windows Platform SDK 8.0 was not found!") - set(HAVE_WINRT False) - endif() +# search Windows Platform SDK +message(STATUS "Checking for Windows Platform SDK") +GET_FILENAME_COMPONENT(WINDOWS_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE) +if (WINDOWS_SDK_PATH STREQUAL "") + set(HAVE_MSPDK FALSE) + message(STATUS "Windows Platform SDK 8.0 was not found") +else() + set(HAVE_MSPDK TRUE) +endif() - #search for Visual Studio 11.0 install directory - message(STATUS "Checking for Visual Studio 2012") - GET_FILENAME_COMPONENT(VISUAL_STUDIO_PATH [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VS;ProductDir] REALPATH CACHE) - if (VISUAL_STUDIO_PATH STREQUAL "") - message(ERROR "Visual Studio 2012 was not found!") - set(HAVE_WINRT False) - endif() +#search for Visual Studio 11.0 install directory +message(STATUS "Checking for Visual Studio 2012") +GET_FILENAME_COMPONENT(VISUAL_STUDIO_PATH [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VS;ProductDir] REALPATH CACHE) +if (VISUAL_STUDIO_PATH STREQUAL "") + set(HAVE_MSVC2012 FALSE) + message(STATUS "Visual Studio 2012 was not found") +else() + set(HAVE_MSVC2012 TRUE) +endif() - if (HAVE_WINRT) - TRY_COMPILE(HAVE_WINRT - "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" - "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp" - CMAKE_FLAGS "\"kernel.lib\" \"user32.lib\"" - OUTPUT_VARIABLE OUTPUT) - endif() +TRY_COMPILE(HAVE_WINRT_SDK + "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" + "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp") - if (HAVE_WINRT) - add_definitions(/DWINVER=0x0602 /DNTDDI_VERSION=NTDDI_WIN8 /D_WIN32_WINNT=0x0602) - endif() -endif(ENABLE_WINRT_MODE) +if (ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK) + set(HAVE_WINRT TRUE) +endif() + +if (HAVE_WINRT) + add_definitions(/DWINVER=0x0602 /DNTDDI_VERSION=NTDDI_WIN8 /D_WIN32_WINNT=0x0602) +endif() if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) foreach(flag_var diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 89982b2622..d8d0be8ea7 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -70,7 +70,7 @@ endif(WITH_OPENGL) if(APPLE) if(WITH_CARBON) set(HAVE_CARBON YES) - elif(NOT IOS) + elseif(NOT IOS) set(HAVE_COCOA YES) endif() endif() diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index 718ada3d97..472620aac4 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -273,4 +273,6 @@ endif() # --- QuickTime --- if(WITH_QUICKTIME) set(HAVE_QUICKTIME YES) +elseif(APPLE) + set(HAVE_QTKIT YES) endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index e602955573..816758d37d 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -470,8 +470,16 @@ endmacro() # ocv_create_module() # ocv_create_module(SKIP_LINK) macro(ocv_create_module) + # The condition we ought to be testing here is whether ocv_add_precompiled_headers will + # be called at some point in the future. We can't look into the future, though, + # so this will have to do. + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp") + get_native_precompiled_header(${the_module} precomp.hpp) + endif() + add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} - "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp") + "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" + ${${the_module}_pch}) if(NOT the_module STREQUAL opencv_ts) set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL) endif() @@ -640,7 +648,9 @@ function(ocv_add_perf_tests) set(OPENCV_PERF_${the_module}_SOURCES ${perf_srcs} ${perf_hdrs}) endif() - add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES}) + get_native_precompiled_header(${the_target} test_precomp.hpp) + + add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES} ${${the_target}_pch}) target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${perf_deps} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_perf_tests ${the_target}) @@ -688,7 +698,9 @@ function(ocv_add_accuracy_tests) set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs}) endif() - add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES}) + get_native_precompiled_header(${the_target} test_precomp.hpp) + + add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch}) target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${test_deps} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_tests ${the_target}) diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake index 9b3efd9d11..060965346a 100644 --- a/cmake/OpenCVPCHSupport.cmake +++ b/cmake/OpenCVPCHSupport.cmake @@ -279,12 +279,9 @@ ENDMACRO(ADD_PRECOMPILED_HEADER) MACRO(GET_NATIVE_PRECOMPILED_HEADER _targetName _input) if(CMAKE_GENERATOR MATCHES "^Visual.*$") - SET(_dummy_str "#include \"${_input}\"\n" -"// This is required to suppress LNK4221. Very annoying.\n" -"void *g_${_targetName}Dummy = 0\;\n") + set(_dummy_str "#include \"${_input}\"\n") - # Use of cxx extension for generated files (as Qt does) - SET(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cxx) + set(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cpp) if(EXISTS ${${_targetName}_pch}) # Check if contents is the same, if not rewrite # todo @@ -344,11 +341,7 @@ ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER) macro(ocv_add_precompiled_header_to_target the_target pch_header) if(PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS AND EXISTS "${pch_header}") - if(CMAKE_GENERATOR MATCHES Visual) - string(REGEX REPLACE "hpp$" "cpp" ${the_target}_pch "${pch_header}") - add_native_precompiled_header(${the_target} ${pch_header}) - unset(${the_target}_pch) - elseif(CMAKE_GENERATOR MATCHES Xcode) + if(CMAKE_GENERATOR MATCHES "^Visual" OR CMAKE_GENERATOR MATCHES Xcode) add_native_precompiled_header(${the_target} ${pch_header}) elseif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GENERATOR MATCHES "Makefiles|Ninja") add_precompiled_header(${the_target} ${pch_header}) diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index 72cf58b5fc..56c5d5aadc 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -130,6 +130,9 @@ /* QuickTime video libraries */ #cmakedefine HAVE_QUICKTIME +/* QTKit video libraries */ +#cmakedefine HAVE_QTKIT + /* Intel Threading Building Blocks */ #cmakedefine HAVE_TBB diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index c42c3b1bb1..87368465ee 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -49,7 +49,7 @@ if(BUILD_DOCS AND HAVE_SPHINX) set(toc_file "${OPENCV_MODULE_opencv_${mod}_LOCATION}/doc/${mod}.rst") if(EXISTS "${toc_file}") file(RELATIVE_PATH toc_file "${OpenCV_SOURCE_DIR}/modules" "${toc_file}") - set(OPENCV_REFMAN_TOC "${OPENCV_REFMAN_TOC} ${toc_file}\r\n") + set(OPENCV_REFMAN_TOC "${OPENCV_REFMAN_TOC} ${toc_file}\n") endif() endforeach() diff --git a/doc/tutorials/calib3d/camera_calibration/camera_calibration.rst b/doc/tutorials/calib3d/camera_calibration/camera_calibration.rst index 77723b2b8b..4e807698e3 100644 --- a/doc/tutorials/calib3d/camera_calibration/camera_calibration.rst +++ b/doc/tutorials/calib3d/camera_calibration/camera_calibration.rst @@ -3,42 +3,42 @@ Camera calibration With OpenCV ****************************** -Cameras have been around for a long-long time. However, with the introduction of the cheap *pinhole* cameras in the late 20th century, they became a common occurrence in our everyday life. Unfortunately, this cheapness comes with its price: significant distortion. Luckily, these are constants and with a calibration and some remapping we can correct this. Furthermore, with calibration you may also determinate the relation between the camera's natural units (pixels) and the real world units (for example millimeters). +Cameras have been around for a long-long time. However, with the introduction of the cheap *pinhole* cameras in the late 20th century, they became a common occurrence in our everyday life. Unfortunately, this cheapness comes with its price: significant distortion. Luckily, these are constants and with a calibration and some remapping we can correct this. Furthermore, with calibration you may also determine the relation between the camera's natural units (pixels) and the real world units (for example millimeters). Theory ====== -For the distortion OpenCV takes into account the radial and tangential factors. For the radial one uses the following formula: +For the distortion OpenCV takes into account the radial and tangential factors. For the radial factor one uses the following formula: .. math:: x_{corrected} = x( 1 + k_1 r^2 + k_2 r^4 + k_3 r^6) \\ y_{corrected} = y( 1 + k_1 r^2 + k_2 r^4 + k_3 r^6) -So for an old pixel point at :math:`(x,y)` coordinate in the input image, for a corrected output image its position will be :math:`(x_{corrected} y_{corrected})` . The presence of the radial distortion manifests in form of the "barrel" or "fish-eye" effect. +So for an old pixel point at :math:`(x,y)` coordinates in the input image, its position on the corrected output image will be :math:`(x_{corrected} y_{corrected})`. The presence of the radial distortion manifests in form of the "barrel" or "fish-eye" effect. -Tangential distortion occurs because the image taking lenses are not perfectly parallel to the imaging plane. Correcting this is made via the formulas: +Tangential distortion occurs because the image taking lenses are not perfectly parallel to the imaging plane. It can be corrected via the formulas: .. math:: x_{corrected} = x + [ 2p_1xy + p_2(r^2+2x^2)] \\ y_{corrected} = y + [ p_1(r^2+ 2y^2)+ 2p_2xy] -So we have five distortion parameters, which in OpenCV are organized in a 5 column one row matrix: +So we have five distortion parameters which in OpenCV are presented as one row matrix with 5 columns: .. math:: Distortion_{coefficients}=(k_1 \hspace{10pt} k_2 \hspace{10pt} p_1 \hspace{10pt} p_2 \hspace{10pt} k_3) -Now for the unit conversion, we use the following formula: +Now for the unit conversion we use the following formula: .. math:: \left [ \begin{matrix} x \\ y \\ w \end{matrix} \right ] = \left [ \begin{matrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{matrix} \right ] \left [ \begin{matrix} X \\ Y \\ Z \end{matrix} \right ] -Here the presence of the :math:`w` is cause we use a homography coordinate system (and :math:`w=Z`). The unknown parameters are :math:`f_x` and :math:`f_y` (camera focal lengths) and :math:`(c_x, c_y)` what are the optical centers expressed in pixels coordinates. If for both axes a common focal length is used with a given :math:`a` aspect ratio (usually 1), then :math:`f_y=f_x*a` and in the upper formula we will have a single :math:`f` focal length. The matrix containing these four parameters is referred to as the *camera matrix*. While the distortion coefficients are the same regardless of the camera resolutions used, these should be scaled along with the current resolution from the calibrated resolution. +Here the presence of :math:`w` is explained by the use of homography coordinate system (and :math:`w=Z`). The unknown parameters are :math:`f_x` and :math:`f_y` (camera focal lengths) and :math:`(c_x, c_y)` which are the optical centers expressed in pixels coordinates. If for both axes a common focal length is used with a given :math:`a` aspect ratio (usually 1), then :math:`f_y=f_x*a` and in the upper formula we will have a single focal length :math:`f`. The matrix containing these four parameters is referred to as the *camera matrix*. While the distortion coefficients are the same regardless of the camera resolutions used, these should be scaled along with the current resolution from the calibrated resolution. -The process of determining these two matrices is the calibration. Calculating these parameters is done by some basic geometrical equations. The equations used depend on the calibrating objects used. Currently OpenCV supports three types of object for calibration: +The process of determining these two matrices is the calibration. Calculation of these parameters is done through basic geometrical equations. The equations used depend on the chosen calibrating objects. Currently OpenCV supports three types of objects for calibration: .. container:: enumeratevisibleitemswithsquare @@ -46,7 +46,7 @@ The process of determining these two matrices is the calibration. Calculating th + Symmetrical circle pattern + Asymmetrical circle pattern -Basically, you need to take snapshots of these patterns with your camera and let OpenCV find them. Each found pattern equals in a new equation. To solve the equation you need at least a predetermined number of pattern snapshots to form a well-posed equation system. This number is higher for the chessboard pattern and less for the circle ones. For example, in theory the chessboard one requires at least two. However, in practice we have a good amount of noise present in our input images, so for good results you will probably want at least 10 good snapshots of the input pattern in different position. +Basically, you need to take snapshots of these patterns with your camera and let OpenCV find them. Each found pattern results in a new equation. To solve the equation you need at least a predetermined number of pattern snapshots to form a well-posed equation system. This number is higher for the chessboard pattern and less for the circle ones. For example, in theory the chessboard pattern requires at least two snapshots. However, in practice we have a good amount of noise present in our input images, so for good results you will probably need at least 10 good snapshots of the input pattern in different positions. Goal ==== @@ -55,19 +55,19 @@ The sample application will: .. container:: enumeratevisibleitemswithsquare - + Determinate the distortion matrix - + Determinate the camera matrix - + Input from Camera, Video and Image file list - + Configuration from XML/YAML file + + Determine the distortion matrix + + Determine the camera matrix + + Take input from Camera, Video and Image file list + + Read configuration from XML/YAML file + Save the results into XML/YAML file + Calculate re-projection error Source code =========== -You may also find the source code in the :file:`samples/cpp/tutorial_code/calib3d/camera_calibration/` folder of the OpenCV source library or :download:`download it from here <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp>`. The program has a single argument. The name of its configuration file. If none given it will try to open the one named "default.xml". :download:`Here's a sample configuration file <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/in_VID5.xml>` in XML format. In the configuration file you may choose to use as input a camera, a video file or an image list. If you opt for the later one, you need to create a configuration file where you enumerate the images to use. Here's :download:`an example of this <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/VID5.xml>`. The important part to remember is that the images needs to be specified using the absolute path or the relative one from your applications working directory. You may find all this in the beforehand mentioned directory. +You may also find the source code in the :file:`samples/cpp/tutorial_code/calib3d/camera_calibration/` folder of the OpenCV source library or :download:`download it from here <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp>`. The program has a single argument: the name of its configuration file. If none is given then it will try to open the one named "default.xml". :download:`Here's a sample configuration file <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/in_VID5.xml>` in XML format. In the configuration file you may choose to use camera as an input, a video file or an image list. If you opt for the last one, you will need to create a configuration file where you enumerate the images to use. Here's :download:`an example of this <../../../../samples/cpp/tutorial_code/calib3d/camera_calibration/VID5.xml>`. The important part to remember is that the images need to be specified using the absolute path or the relative one from your application's working directory. You may find all this in the samples directory mentioned above. -The application starts up with reading the settings from the configuration file. Although, this is an important part of it, it has nothing to do with the subject of this tutorial: *camera calibration*. Therefore, I've chosen to do not post here the code part for that. The technical background on how to do this you can find in the :ref:`fileInputOutputXMLYAML` tutorial. +The application starts up with reading the settings from the configuration file. Although, this is an important part of it, it has nothing to do with the subject of this tutorial: *camera calibration*. Therefore, I've chosen not to post the code for that part here. Technical background on how to do this you can find in the :ref:`fileInputOutputXMLYAML` tutorial. Explanation =========== @@ -93,9 +93,9 @@ Explanation return -1; } - For this I've used simple OpenCV class input operation. After reading the file I've an additional post-process function that checks for the validity of the input. Only if all of them are good will be the *goodInput* variable true. + For this I've used simple OpenCV class input operation. After reading the file I've an additional post-processing function that checks validity of the input. Only if all inputs are good then *goodInput* variable will be true. -#. **Get next input, if it fails or we have enough of them calibrate**. After this we have a big loop where we do the following operations: get the next image from the image list, camera or video file. If this fails or we have enough images we run the calibration process. In case of image we step out of the loop and otherwise the remaining frames will be undistorted (if the option is set) via changing from *DETECTION* mode to *CALIBRATED* one. +#. **Get next input, if it fails or we have enough of them - calibrate**. After this we have a big loop where we do the following operations: get the next image from the image list, camera or video file. If this fails or we have enough images then we run the calibration process. In case of image we step out of the loop and otherwise the remaining frames will be undistorted (if the option is set) via changing from *DETECTION* mode to the *CALIBRATED* one. .. code-block:: cpp @@ -125,7 +125,7 @@ Explanation For some cameras we may need to flip the input image. Here we do this too. -#. **Find the pattern in the current input**. The formation of the equations I mentioned above consists of finding the major patterns in the input: in case of the chessboard this is their corners of the squares and for the circles, well, the circles itself. The position of these will form the result and is collected into the *pointBuf* vector. +#. **Find the pattern in the current input**. The formation of the equations I mentioned above aims to finding major patterns in the input: in case of the chessboard this are corners of the squares and for the circles, well, the circles themselves. The position of these will form the result which will be written into the *pointBuf* vector. .. code-block:: cpp @@ -146,9 +146,9 @@ Explanation break; } - Depending on the type of the input pattern you use either the :calib3d:`findChessboardCorners ` or the :calib3d:`findCirclesGrid ` function. For both of them you pass on the current image, the size of the board and you'll get back the positions of the patterns. Furthermore, they return a boolean variable that states if in the input we could find or not the pattern (we only need to take into account images where this is true!). + Depending on the type of the input pattern you use either the :calib3d:`findChessboardCorners ` or the :calib3d:`findCirclesGrid ` function. For both of them you pass the current image and the size of the board and you'll get the positions of the patterns. Furthermore, they return a boolean variable which states if the pattern was found in the input (we only need to take into account those images where this is true!). - Then again in case of cameras we only take camera images after an input delay time passed. This is in order to allow for the user to move the chessboard around and as getting different images. Same images mean same equations, and same equations at the calibration will form an ill-posed problem, so the calibration will fail. For square images the position of the corners are only approximate. We may improve this by calling the :feature2d:`cornerSubPix ` function. This way will get a better calibration result. After this we add a valid inputs result to the *imagePoints* vector to collect all of the equations into a single container. Finally, for visualization feedback purposes we will draw the found points on the input image with the :calib3d:`findChessboardCorners ` function. + Then again in case of cameras we only take camera images when an input delay time is passed. This is done in order to allow user moving the chessboard around and getting different images. Similar images result in similar equations, and similar equations at the calibration step will form an ill-posed problem, so the calibration will fail. For square images the positions of the corners are only approximate. We may improve this by calling the :feature2d:`cornerSubPix ` function. It will produce better calibration result. After this we add a valid inputs result to the *imagePoints* vector to collect all of the equations into a single container. Finally, for visualization feedback purposes we will draw the found points on the input image using :calib3d:`findChessboardCorners ` function. .. code-block:: cpp @@ -175,7 +175,7 @@ Explanation drawChessboardCorners( view, s.boardSize, Mat(pointBuf), found ); } -#. **Show state and result for the user, plus command line control of the application**. The showing part consists of a text output on the live feed, and for video or camera input to show the "capturing" frame we simply bitwise negate the input image. +#. **Show state and result to the user, plus command line control of the application**. This part shows text output on the image. .. code-block:: cpp @@ -199,7 +199,7 @@ Explanation if( blinkOutput ) bitwise_not(view, view); - If we only ran the calibration and got the camera matrix plus the distortion coefficients we may just as correct the image with the :imgproc_geometric:`undistort ` function: + If we ran calibration and got camera's matrix with the distortion coefficients we may want to correct the image using :imgproc_geometric:`undistort ` function: .. code-block:: cpp @@ -212,7 +212,7 @@ Explanation //------------------------------ Show image and check for input commands ------------------- imshow("Image View", view); - Then we wait for an input key and if this is *u* we toggle the distortion removal, if it is *g* we start all over the detection process (or simply start it), and finally for the *ESC* key quit the application: + Then we wait for an input key and if this is *u* we toggle the distortion removal, if it is *g* we start again the detection process, and finally for the *ESC* key we quit the application: .. code-block:: cpp @@ -229,7 +229,7 @@ Explanation imagePoints.clear(); } -#. **Show the distortion removal for the images too**. When you work with an image list it is not possible to remove the distortion inside the loop. Therefore, you must append this after the loop. Taking advantage of this now I'll expand the :imgproc_geometric:`undistort ` function, which is in fact first a call of the :imgproc_geometric:`initUndistortRectifyMap ` to find out the transformation matrices and then doing the transformation with the :imgproc_geometric:`remap ` function. Because, after a successful calibration the map calculation needs to be done only once, by using this expanded form you may speed up your application: +#. **Show the distortion removal for the images too**. When you work with an image list it is not possible to remove the distortion inside the loop. Therefore, you must do this after the loop. Taking advantage of this now I'll expand the :imgproc_geometric:`undistort ` function, which is in fact first calls :imgproc_geometric:`initUndistortRectifyMap ` to find transformation matrices and then performs transformation using :imgproc_geometric:`remap ` function. Because, after successful calibration map calculation needs to be done only once, by using this expanded form you may speed up your application: .. code-block:: cpp @@ -256,7 +256,7 @@ Explanation The calibration and save ======================== -Because the calibration needs to be only once per camera it makes sense to save them after a successful calibration. This way later on you can just load these values into your program. Due to this we first make the calibration, and if it succeeds we save the result into an OpenCV style XML or YAML file, depending on the extension you give in the configuration file. +Because the calibration needs to be done only once per camera, it makes sense to save it after a successful calibration. This way later on you can just load these values into your program. Due to this we first make the calibration, and if it succeeds we save the result into an OpenCV style XML or YAML file, depending on the extension you give in the configuration file. Therefore in the first function we just split up these two processes. Because we want to save many of the calibration variables we'll create these variables here and pass on both of them to the calibration and saving function. Again, I'll not show the saving part as that has little in common with the calibration. Explore the source file in order to find out how and what: @@ -280,7 +280,7 @@ Therefore in the first function we just split up these two processes. Because we return ok; } -We do the calibration with the help of the :calib3d:`calibrateCamera ` function. This has the following parameters: +We do the calibration with the help of the :calib3d:`calibrateCamera ` function. It has the following parameters: .. container:: enumeratevisibleitemswithsquare @@ -318,11 +318,11 @@ We do the calibration with the help of the :calib3d:`calibrateCamera ` or the :calib3d:`findCirclesGrid ` function returned. We just need to pass it on. + + The image points. This is a vector of *Point2f* vector which for each input image contains coordinates of the important points (corners for chessboard and centers of the circles for the circle pattern). We have already collected this from :calib3d:`findChessboardCorners ` or :calib3d:`findCirclesGrid ` function. We just need to pass it on. + The size of the image acquired from the camera, video file or the images. - + The camera matrix. If we used the fix aspect ratio option we need to set the :math:`f_x` to zero: + + The camera matrix. If we used the fixed aspect ratio option we need to set the :math:`f_x` to zero: .. code-block:: cpp @@ -336,16 +336,16 @@ We do the calibration with the help of the :calib3d:`calibrateCamera ` to first transform the object point to image point. Then we calculate the absolute norm between what we got with our transformation and the corner/circle finding algorithm. To find the average error we calculate the arithmetical mean of the errors calculate for all the calibration images. + + The function returns the average re-projection error. This number gives a good estimation of precision of the found parameters. This should be as close to zero as possible. Given the intrinsic, distortion, rotation and translation matrices we may calculate the error for one view by using the :calib3d:`projectPoints ` to first transform the object point to image point. Then we calculate the absolute norm between what we got with our transformation and the corner/circle finding algorithm. To find the average error we calculate the arithmetical mean of the errors calculated for all the calibration images. .. code-block:: cpp @@ -378,25 +378,25 @@ We do the calibration with the help of the :calib3d:`calibrateCamera ` that has a size of 9 X 6. I've used an AXIS IP camera to create a couple of snapshots of the board and saved it into a VID5 directory. I've put this inside the :file:`images/CameraCalibraation` folder of my working directory and created the following :file:`VID5.XML` file that describes which images to use: +Let there be :download:`this input chessboard pattern <../../../pattern.png>` which has a size of 9 X 6. I've used an AXIS IP camera to create a couple of snapshots of the board and saved it into VID5 directory. I've put this inside the :file:`images/CameraCalibration` folder of my working directory and created the following :file:`VID5.XML` file that describes which images to use: .. code-block:: xml - images/CameraCalibraation/VID5/xx1.jpg - images/CameraCalibraation/VID5/xx2.jpg - images/CameraCalibraation/VID5/xx3.jpg - images/CameraCalibraation/VID5/xx4.jpg - images/CameraCalibraation/VID5/xx5.jpg - images/CameraCalibraation/VID5/xx6.jpg - images/CameraCalibraation/VID5/xx7.jpg - images/CameraCalibraation/VID5/xx8.jpg + images/CameraCalibration/VID5/xx1.jpg + images/CameraCalibration/VID5/xx2.jpg + images/CameraCalibration/VID5/xx3.jpg + images/CameraCalibration/VID5/xx4.jpg + images/CameraCalibration/VID5/xx5.jpg + images/CameraCalibration/VID5/xx6.jpg + images/CameraCalibration/VID5/xx7.jpg + images/CameraCalibration/VID5/xx8.jpg -Then specified the :file:`images/CameraCalibraation/VID5/VID5.XML` as input in the configuration file. Here's a chessboard pattern found during the runtime of the application: +Then passed :file:`images/CameraCalibration/VID5/VID5.XML` as an input in the configuration file. Here's a chessboard pattern found during the runtime of the application: .. image:: images/fileListImage.jpg :alt: A found chessboard @@ -433,7 +433,7 @@ In both cases in the specified output XML/YAML file you'll find the camera and d -4.1802327176423804e-001 5.0715244063187526e-001 0. 0. -5.7843597214487474e-001 -Add these values as constants to your program, call the :imgproc_geometric:`initUndistortRectifyMap ` and the :imgproc_geometric:`remap ` function to remove distortion and enjoy distortion free inputs with cheap and low quality cameras. +Add these values as constants to your program, call the :imgproc_geometric:`initUndistortRectifyMap ` and the :imgproc_geometric:`remap ` function to remove distortion and enjoy distortion free inputs for cheap and low quality cameras. You may observe a runtime instance of this on the `YouTube here `_. diff --git a/doc/tutorials/features2d/feature_detection/feature_detection.rst b/doc/tutorials/features2d/feature_detection/feature_detection.rst index 1c9ca7cf82..02da6d0806 100644 --- a/doc/tutorials/features2d/feature_detection/feature_detection.rst +++ b/doc/tutorials/features2d/feature_detection/feature_detection.rst @@ -31,6 +31,7 @@ This tutorial code's is shown lines below. You can also download it from `here < #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" #include "opencv2/highgui.hpp" + #include "opencv2/nonfree.hpp" using namespace cv; @@ -94,4 +95,3 @@ Result .. image:: images/Feature_Detection_Result_b.jpg :align: center :height: 200pt - diff --git a/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst b/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst index 4b3ffbcae2..9839c89841 100644 --- a/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst +++ b/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst @@ -28,6 +28,7 @@ This tutorial code's is shown lines below. You can also download it from `here < #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" #include "opencv2/highgui.hpp" + #include "opencv2/nonfree.hpp" using namespace cv; diff --git a/doc/tutorials/features2d/feature_homography/feature_homography.rst b/doc/tutorials/features2d/feature_homography/feature_homography.rst index 0d78229599..3040ed7d75 100644 --- a/doc/tutorials/features2d/feature_homography/feature_homography.rst +++ b/doc/tutorials/features2d/feature_homography/feature_homography.rst @@ -30,6 +30,7 @@ This tutorial code's is shown lines below. You can also download it from `here < #include "opencv2/features2d.hpp" #include "opencv2/highgui.hpp" #include "opencv2/calib3d.hpp" + #include "opencv2/nonfree.hpp" using namespace cv; @@ -145,4 +146,3 @@ Result .. image:: images/Feature_Homography_Result.jpg :align: center :height: 200pt - diff --git a/modules/calib3d/perf/perf_precomp.cpp b/modules/calib3d/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/calib3d/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/calib3d/src/precomp.cpp b/modules/calib3d/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/calib3d/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/calib3d/test/test_precomp.cpp b/modules/calib3d/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/calib3d/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/contrib/src/precomp.cpp b/modules/contrib/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/contrib/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/contrib/test/test_precomp.cpp b/modules/contrib/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/contrib/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index 29252bb8f6..7acd1e2186 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -49,6 +49,43 @@ Point\_ ------- .. ocv:class:: Point_ +:: + + template class CV_EXPORTS Point_ + { + public: + typedef _Tp value_type; + + // various constructors + Point_(); + Point_(_Tp _x, _Tp _y); + Point_(const Point_& pt); + Point_(const CvPoint& pt); + Point_(const CvPoint2D32f& pt); + Point_(const Size_<_Tp>& sz); + Point_(const Vec<_Tp, 2>& v); + + Point_& operator = (const Point_& pt); + //! conversion to another data type + template operator Point_<_Tp2>() const; + + //! conversion to the old-style C structures + operator CvPoint() const; + operator CvPoint2D32f() const; + operator Vec<_Tp, 2>() const; + + //! dot product + _Tp dot(const Point_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point_& pt) const; + //! cross-product + double cross(const Point_& pt) const; + //! checks whether the point is inside the specified rectangle + bool inside(const Rect_<_Tp>& r) const; + + _Tp x, y; //< the point coordinates + }; + Template class for 2D points specified by its coordinates :math:`x` and :math:`y` . @@ -84,6 +121,39 @@ Point3\_ -------- .. ocv:class:: Point3_ +:: + + template class CV_EXPORTS Point3_ + { + public: + typedef _Tp value_type; + + // various constructors + Point3_(); + Point3_(_Tp _x, _Tp _y, _Tp _z); + Point3_(const Point3_& pt); + explicit Point3_(const Point_<_Tp>& pt); + Point3_(const CvPoint3D32f& pt); + Point3_(const Vec<_Tp, 3>& v); + + Point3_& operator = (const Point3_& pt); + //! conversion to another data type + template operator Point3_<_Tp2>() const; + //! conversion to the old-style CvPoint... + operator CvPoint3D32f() const; + //! conversion to cv::Vec<> + operator Vec<_Tp, 3>() const; + + //! dot product + _Tp dot(const Point3_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point3_& pt) const; + //! cross product of the 2 3D points + Point3_ cross(const Point3_& pt) const; + + _Tp x, y, z; //< the point coordinates + }; + Template class for 3D points specified by its coordinates :math:`x`, :math:`y` and @@ -100,6 +170,35 @@ Size\_ ------ .. ocv:class:: Size_ +:: + + template class CV_EXPORTS Size_ + { + public: + typedef _Tp value_type; + + //! various constructors + Size_(); + Size_(_Tp _width, _Tp _height); + Size_(const Size_& sz); + Size_(const CvSize& sz); + Size_(const CvSize2D32f& sz); + Size_(const Point_<_Tp>& pt); + + Size_& operator = (const Size_& sz); + //! the area (width*height) + _Tp area() const; + + //! conversion of another data type. + template operator Size_<_Tp2>() const; + + //! conversion to the old-style OpenCV types + operator CvSize() const; + operator CvSize2D32f() const; + + _Tp width, height; // the width and the height + }; + Template class for specifying the size of an image or rectangle. The class includes two members called ``width`` and ``height``. The structure can be converted to and from the old OpenCV structures ``CvSize`` and ``CvSize2D32f`` . The same set of arithmetic and comparison operations as for ``Point_`` is available. @@ -113,6 +212,43 @@ Rect\_ ------ .. ocv:class:: Rect_ +:: + + template class CV_EXPORTS Rect_ + { + public: + typedef _Tp value_type; + + //! various constructors + Rect_(); + Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); + Rect_(const Rect_& r); + Rect_(const CvRect& r); + Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); + Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); + + Rect_& operator = ( const Rect_& r ); + //! the top-left corner + Point_<_Tp> tl() const; + //! the bottom-right corner + Point_<_Tp> br() const; + + //! size (width, height) of the rectangle + Size_<_Tp> size() const; + //! area (width*height) of the rectangle + _Tp area() const; + + //! conversion to another data type + template operator Rect_<_Tp2>() const; + //! conversion to the old-style CvRect + operator CvRect() const; + + //! checks whether the rectangle contains the point + bool contains(const Point_<_Tp>& pt) const; + + _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle + }; + Template class for 2D rectangles, described by the following parameters: * Coordinates of the top-left corner. This is a default interpretation of ``Rect_::x`` and ``Rect_::y`` in OpenCV. Though, in your algorithms you may count ``x`` and ``y`` from the bottom-left corner. @@ -171,6 +307,28 @@ RotatedRect ----------- .. ocv:class:: RotatedRect +:: + + class CV_EXPORTS RotatedRect + { + public: + //! various constructors + RotatedRect(); + RotatedRect(const Point2f& center, const Size2f& size, float angle); + RotatedRect(const CvBox2D& box); + + //! returns 4 vertices of the rectangle + void points(Point2f pts[]) const; + //! returns the minimal up-right rectangle containing the rotated rectangle + Rect boundingRect() const; + //! conversion to the old-style CvBox2D structure + operator CvBox2D() const; + + Point2f center; //< the rectangle mass center + Size2f size; //< width and height of the rectangle + float angle; //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle. + }; + The class represents rotated (i.e. not up-right) rectangles on a plane. Each rectangle is specified by the center point (mass center), length of each side (represented by cv::Size2f structure) and the rotation angle in degrees. .. ocv:function:: RotatedRect::RotatedRect() @@ -217,7 +375,33 @@ TermCriteria ------------ .. ocv:class:: TermCriteria - The class defining termination criteria for iterative algorithms. You can initialize it by default constructor and then override any parameters, or the structure may be fully initialized using the advanced variant of the constructor. +:: + + class CV_EXPORTS TermCriteria + { + public: + enum + { + COUNT=1, //!< the maximum number of iterations or elements to compute + MAX_ITER=COUNT, //!< ditto + EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops + }; + + //! default constructor + TermCriteria(); + //! full constructor + TermCriteria(int type, int maxCount, double epsilon); + //! conversion from CvTermCriteria + TermCriteria(const CvTermCriteria& criteria); + //! conversion to CvTermCriteria + operator CvTermCriteria() const; + + int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS + int maxCount; // the maximum number of iterations/elements + double epsilon; // the desired accuracy + }; + +The class defining termination criteria for iterative algorithms. You can initialize it by default constructor and then override any parameters, or the structure may be fully initialized using the advanced variant of the constructor. TermCriteria::TermCriteria -------------------------- @@ -321,9 +505,36 @@ Scalar\_ -------- .. ocv:class:: Scalar_ -Template class for a 4-element vector derived from Vec. :: +Template class for a 4-element vector derived from Vec. + +:: + + template class CV_EXPORTS Scalar_ : public Vec<_Tp, 4> + { + public: + //! various constructors + Scalar_(); + Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0); + Scalar_(const CvScalar& s); + Scalar_(_Tp v0); + + //! returns a scalar with all elements set to v0 + static Scalar_<_Tp> all(_Tp v0); + //! conversion to the old-style CvScalar + operator CvScalar() const; + + //! conversion to another data type + template operator Scalar_() const; - template class Scalar_ : public Vec<_Tp, 4> { ... }; + //! per-element product + Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const; + + // returns (v0, -v1, -v2, -v3) + Scalar_<_Tp> conj() const; + + // returns true iff v1 == v2 == v3 == 0 + bool isReal() const; + }; typedef Scalar_ Scalar; @@ -333,12 +544,21 @@ Range ----- .. ocv:class:: Range -Template class specifying a continuous subsequence (slice) of a sequence. :: +Template class specifying a continuous subsequence (slice) of a sequence. + +:: - class Range + class CV_EXPORTS Range { public: - ... + Range(); + Range(int _start, int _end); + Range(const CvSlice& slice); + int size() const; + bool empty() const; + static Range all(); + operator CvSlice() const; + int start, end; }; @@ -617,8 +837,8 @@ Ptr::operator -> ---------------- Provide access to the object fields and methods. - .. ocv:function:: template _Tp* Ptr::operator -> () - .. ocv:function:: template const _Tp* Ptr::operator -> () const +.. ocv:function:: template _Tp* Ptr::operator -> () +.. ocv:function:: template const _Tp* Ptr::operator -> () const Ptr::operator _Tp* @@ -626,15 +846,16 @@ Ptr::operator _Tp* Returns the underlying object pointer. Thanks to the methods, the ``Ptr<_Tp>`` can be used instead of ``_Tp*``. - .. ocv:function:: template Ptr::operator _Tp* () - .. ocv:function:: template Ptr::operator const _Tp*() const +.. ocv:function:: template Ptr::operator _Tp* () +.. ocv:function:: template Ptr::operator const _Tp*() const Mat --- .. ocv:class:: Mat -OpenCV C++ n-dimensional dense array class :: +OpenCV C++ n-dimensional dense array class +:: class CV_EXPORTS Mat { @@ -664,7 +885,6 @@ OpenCV C++ n-dimensional dense array class :: ... }; - The class ``Mat`` represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms may be better stored in a ``SparseMat`` ). The data layout of the array :math:`M` is defined by the array ``M.step[]``, so that the address of element :math:`(i_0,...,i_{M.dims-1})`, where @@ -2491,6 +2711,82 @@ Algorithm --------- .. ocv:class:: Algorithm +:: + + class CV_EXPORTS_W Algorithm + { + public: + Algorithm(); + virtual ~Algorithm(); + string name() const; + + template typename ParamType<_Tp>::member_type get(const string& name) const; + template typename ParamType<_Tp>::member_type get(const char* name) const; + + CV_WRAP int getInt(const string& name) const; + CV_WRAP double getDouble(const string& name) const; + CV_WRAP bool getBool(const string& name) const; + CV_WRAP string getString(const string& name) const; + CV_WRAP Mat getMat(const string& name) const; + CV_WRAP vector getMatVector(const string& name) const; + CV_WRAP Ptr getAlgorithm(const string& name) const; + + void set(const string& name, int value); + void set(const string& name, double value); + void set(const string& name, bool value); + void set(const string& name, const string& value); + void set(const string& name, const Mat& value); + void set(const string& name, const vector& value); + void set(const string& name, const Ptr& value); + template void set(const string& name, const Ptr<_Tp>& value); + + CV_WRAP void setInt(const string& name, int value); + CV_WRAP void setDouble(const string& name, double value); + CV_WRAP void setBool(const string& name, bool value); + CV_WRAP void setString(const string& name, const string& value); + CV_WRAP void setMat(const string& name, const Mat& value); + CV_WRAP void setMatVector(const string& name, const vector& value); + CV_WRAP void setAlgorithm(const string& name, const Ptr& value); + template void setAlgorithm(const string& name, const Ptr<_Tp>& value); + + void set(const char* name, int value); + void set(const char* name, double value); + void set(const char* name, bool value); + void set(const char* name, const string& value); + void set(const char* name, const Mat& value); + void set(const char* name, const vector& value); + void set(const char* name, const Ptr& value); + template void set(const char* name, const Ptr<_Tp>& value); + + void setInt(const char* name, int value); + void setDouble(const char* name, double value); + void setBool(const char* name, bool value); + void setString(const char* name, const string& value); + void setMat(const char* name, const Mat& value); + void setMatVector(const char* name, const vector& value); + void setAlgorithm(const char* name, const Ptr& value); + template void setAlgorithm(const char* name, const Ptr<_Tp>& value); + + CV_WRAP string paramHelp(const string& name) const; + int paramType(const char* name) const; + CV_WRAP int paramType(const string& name) const; + CV_WRAP void getParams(CV_OUT vector& names) const; + + + virtual void write(FileStorage& fs) const; + virtual void read(const FileNode& fn); + + typedef Algorithm* (*Constructor)(void); + typedef int (Algorithm::*Getter)() const; + typedef void (Algorithm::*Setter)(int); + + CV_WRAP static void getList(CV_OUT vector& algorithms); + CV_WRAP static Ptr _create(const string& name); + template static Ptr<_Tp> create(const string& name); + + virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; } + }; + This is a base class for all more or less complex algorithms in OpenCV, especially for classes of algorithms, for which there can be multiple implementations. The examples are stereo correspondence (for which there are algorithms like block matching, semi-global block matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck etc.). The class provides the following features for all derived classes: diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index e81401caed..1b2bbf688c 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -406,6 +406,59 @@ CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Ma CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); CV_EXPORTS void read(const FileNode& node, std::vector& keypoints); +template static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Point_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Point3_<_Tp>& value, const Point3_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 3 ? default_value : Point3_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2])); +} + +template static inline void read(const FileNode& node, Size_<_Tp>& value, const Size_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Size_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Complex<_Tp>& value, const Complex<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Complex<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Rect_<_Tp>& value, const Rect_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Rect_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +template static inline void read(const FileNode& node, Vec<_Tp, cn>& value, const Vec<_Tp, cn>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]); +} + +template static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Scalar_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +static inline void read(const FileNode& node, Range& value, const Range& default_value) +{ + Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end); + read(node, temp, default_temp); + value.start = temp.x; value.end = temp.y; +} + + CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str); diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 0d27bf3d8d..4920d8f89d 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -56,6 +56,9 @@ #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) +#define CVAUX_STRW_EXP(__A) L#__A +#define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) + #if CV_VERSION_REVISION # define CV_VERSION CVAUX_STR(CV_VERSION_EPOCH) "." CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) #else diff --git a/modules/core/perf/perf_precomp.cpp b/modules/core/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/core/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 98b67aabf1..7ad7b097d0 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1131,23 +1131,33 @@ static void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, } } -static BinaryFunc maxTab[] = +static BinaryFunc* getMaxTab() { - (BinaryFunc)GET_OPTIMIZED(max8u), (BinaryFunc)GET_OPTIMIZED(max8s), - (BinaryFunc)GET_OPTIMIZED(max16u), (BinaryFunc)GET_OPTIMIZED(max16s), - (BinaryFunc)GET_OPTIMIZED(max32s), - (BinaryFunc)GET_OPTIMIZED(max32f), (BinaryFunc)max64f, - 0 -}; + static BinaryFunc maxTab[] = + { + (BinaryFunc)GET_OPTIMIZED(max8u), (BinaryFunc)GET_OPTIMIZED(max8s), + (BinaryFunc)GET_OPTIMIZED(max16u), (BinaryFunc)GET_OPTIMIZED(max16s), + (BinaryFunc)GET_OPTIMIZED(max32s), + (BinaryFunc)GET_OPTIMIZED(max32f), (BinaryFunc)max64f, + 0 + }; + + return maxTab; +} -static BinaryFunc minTab[] = +static BinaryFunc* getMinTab() { - (BinaryFunc)GET_OPTIMIZED(min8u), (BinaryFunc)GET_OPTIMIZED(min8s), - (BinaryFunc)GET_OPTIMIZED(min16u), (BinaryFunc)GET_OPTIMIZED(min16s), - (BinaryFunc)GET_OPTIMIZED(min32s), - (BinaryFunc)GET_OPTIMIZED(min32f), (BinaryFunc)min64f, - 0 -}; + static BinaryFunc minTab[] = + { + (BinaryFunc)GET_OPTIMIZED(min8u), (BinaryFunc)GET_OPTIMIZED(min8s), + (BinaryFunc)GET_OPTIMIZED(min16u), (BinaryFunc)GET_OPTIMIZED(min16s), + (BinaryFunc)GET_OPTIMIZED(min32s), + (BinaryFunc)GET_OPTIMIZED(min32f), (BinaryFunc)min64f, + 0 + }; + + return minTab; +} } @@ -1177,24 +1187,24 @@ void cv::bitwise_not(InputArray a, OutputArray c, InputArray mask) void cv::max( InputArray src1, InputArray src2, OutputArray dst ) { - binary_op(src1, src2, dst, noArray(), maxTab, false ); + binary_op(src1, src2, dst, noArray(), getMaxTab(), false ); } void cv::min( InputArray src1, InputArray src2, OutputArray dst ) { - binary_op(src1, src2, dst, noArray(), minTab, false ); + binary_op(src1, src2, dst, noArray(), getMinTab(), false ); } void cv::max(const Mat& src1, const Mat& src2, Mat& dst) { OutputArray _dst(dst); - binary_op(src1, src2, _dst, noArray(), maxTab, false ); + binary_op(src1, src2, _dst, noArray(), getMaxTab(), false ); } void cv::min(const Mat& src1, const Mat& src2, Mat& dst) { OutputArray _dst(dst); - binary_op(src1, src2, _dst, noArray(), minTab, false ); + binary_op(src1, src2, _dst, noArray(), getMinTab(), false ); } @@ -1482,39 +1492,54 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, } } -static BinaryFunc addTab[] = +static BinaryFunc* getAddTab() { - (BinaryFunc)GET_OPTIMIZED(add8u), (BinaryFunc)GET_OPTIMIZED(add8s), - (BinaryFunc)GET_OPTIMIZED(add16u), (BinaryFunc)GET_OPTIMIZED(add16s), - (BinaryFunc)GET_OPTIMIZED(add32s), - (BinaryFunc)GET_OPTIMIZED(add32f), (BinaryFunc)add64f, - 0 -}; + static BinaryFunc addTab[] = + { + (BinaryFunc)GET_OPTIMIZED(add8u), (BinaryFunc)GET_OPTIMIZED(add8s), + (BinaryFunc)GET_OPTIMIZED(add16u), (BinaryFunc)GET_OPTIMIZED(add16s), + (BinaryFunc)GET_OPTIMIZED(add32s), + (BinaryFunc)GET_OPTIMIZED(add32f), (BinaryFunc)add64f, + 0 + }; -static BinaryFunc subTab[] = + return addTab; +} + +static BinaryFunc* getSubTab() { - (BinaryFunc)GET_OPTIMIZED(sub8u), (BinaryFunc)GET_OPTIMIZED(sub8s), - (BinaryFunc)GET_OPTIMIZED(sub16u), (BinaryFunc)GET_OPTIMIZED(sub16s), - (BinaryFunc)GET_OPTIMIZED(sub32s), - (BinaryFunc)GET_OPTIMIZED(sub32f), (BinaryFunc)sub64f, - 0 -}; + static BinaryFunc subTab[] = + { + (BinaryFunc)GET_OPTIMIZED(sub8u), (BinaryFunc)GET_OPTIMIZED(sub8s), + (BinaryFunc)GET_OPTIMIZED(sub16u), (BinaryFunc)GET_OPTIMIZED(sub16s), + (BinaryFunc)GET_OPTIMIZED(sub32s), + (BinaryFunc)GET_OPTIMIZED(sub32f), (BinaryFunc)sub64f, + 0 + }; + + return subTab; +} -static BinaryFunc absdiffTab[] = +static BinaryFunc* getAbsDiffTab() { - (BinaryFunc)GET_OPTIMIZED(absdiff8u), (BinaryFunc)GET_OPTIMIZED(absdiff8s), - (BinaryFunc)GET_OPTIMIZED(absdiff16u), (BinaryFunc)GET_OPTIMIZED(absdiff16s), - (BinaryFunc)GET_OPTIMIZED(absdiff32s), - (BinaryFunc)GET_OPTIMIZED(absdiff32f), (BinaryFunc)absdiff64f, - 0 -}; + static BinaryFunc absDiffTab[] = + { + (BinaryFunc)GET_OPTIMIZED(absdiff8u), (BinaryFunc)GET_OPTIMIZED(absdiff8s), + (BinaryFunc)GET_OPTIMIZED(absdiff16u), (BinaryFunc)GET_OPTIMIZED(absdiff16s), + (BinaryFunc)GET_OPTIMIZED(absdiff32s), + (BinaryFunc)GET_OPTIMIZED(absdiff32f), (BinaryFunc)absdiff64f, + 0 + }; + + return absDiffTab; +} } void cv::add( InputArray src1, InputArray src2, OutputArray dst, InputArray mask, int dtype ) { - arithm_op(src1, src2, dst, mask, dtype, addTab ); + arithm_op(src1, src2, dst, mask, dtype, getAddTab() ); } void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, @@ -1549,12 +1574,12 @@ void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, } } #endif - arithm_op(src1, src2, dst, mask, dtype, subTab ); + arithm_op(src1, src2, dst, mask, dtype, getSubTab() ); } void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst ) { - arithm_op(src1, src2, dst, noArray(), -1, absdiffTab); + arithm_op(src1, src2, dst, noArray(), -1, getAbsDiffTab()); } /****************************************************************************************\ @@ -1844,46 +1869,60 @@ static void recip64f( const double* src1, size_t step1, const double* src2, size } -static BinaryFunc mulTab[] = +static BinaryFunc* getMulTab() { - (BinaryFunc)mul8u, (BinaryFunc)mul8s, (BinaryFunc)mul16u, - (BinaryFunc)mul16s, (BinaryFunc)mul32s, (BinaryFunc)mul32f, - (BinaryFunc)mul64f, 0 -}; + static BinaryFunc mulTab[] = + { + (BinaryFunc)mul8u, (BinaryFunc)mul8s, (BinaryFunc)mul16u, + (BinaryFunc)mul16s, (BinaryFunc)mul32s, (BinaryFunc)mul32f, + (BinaryFunc)mul64f, 0 + }; + + return mulTab; +} -static BinaryFunc divTab[] = +static BinaryFunc* getDivTab() { - (BinaryFunc)div8u, (BinaryFunc)div8s, (BinaryFunc)div16u, - (BinaryFunc)div16s, (BinaryFunc)div32s, (BinaryFunc)div32f, - (BinaryFunc)div64f, 0 -}; + static BinaryFunc divTab[] = + { + (BinaryFunc)div8u, (BinaryFunc)div8s, (BinaryFunc)div16u, + (BinaryFunc)div16s, (BinaryFunc)div32s, (BinaryFunc)div32f, + (BinaryFunc)div64f, 0 + }; -static BinaryFunc recipTab[] = + return divTab; +} + +static BinaryFunc* getRecipTab() { - (BinaryFunc)recip8u, (BinaryFunc)recip8s, (BinaryFunc)recip16u, - (BinaryFunc)recip16s, (BinaryFunc)recip32s, (BinaryFunc)recip32f, - (BinaryFunc)recip64f, 0 -}; + static BinaryFunc recipTab[] = + { + (BinaryFunc)recip8u, (BinaryFunc)recip8s, (BinaryFunc)recip16u, + (BinaryFunc)recip16s, (BinaryFunc)recip32s, (BinaryFunc)recip32f, + (BinaryFunc)recip64f, 0 + }; + return recipTab; +} } void cv::multiply(InputArray src1, InputArray src2, OutputArray dst, double scale, int dtype) { - arithm_op(src1, src2, dst, noArray(), dtype, mulTab, true, &scale); + arithm_op(src1, src2, dst, noArray(), dtype, getMulTab(), true, &scale); } void cv::divide(InputArray src1, InputArray src2, OutputArray dst, double scale, int dtype) { - arithm_op(src1, src2, dst, noArray(), dtype, divTab, true, &scale); + arithm_op(src1, src2, dst, noArray(), dtype, getDivTab(), true, &scale); } void cv::divide(double scale, InputArray src2, OutputArray dst, int dtype) { - arithm_op(src2, src2, dst, noArray(), dtype, recipTab, true, &scale); + arithm_op(src2, src2, dst, noArray(), dtype, getRecipTab(), true, &scale); } /****************************************************************************************\ @@ -2026,12 +2065,17 @@ static void addWeighted64f( const double* src1, size_t step1, const double* src2 addWeighted_(src1, step1, src2, step2, dst, step, sz, scalars); } -static BinaryFunc addWeightedTab[] = +static BinaryFunc* getAddWeightedTab() { - (BinaryFunc)GET_OPTIMIZED(addWeighted8u), (BinaryFunc)GET_OPTIMIZED(addWeighted8s), (BinaryFunc)GET_OPTIMIZED(addWeighted16u), - (BinaryFunc)GET_OPTIMIZED(addWeighted16s), (BinaryFunc)GET_OPTIMIZED(addWeighted32s), (BinaryFunc)addWeighted32f, - (BinaryFunc)addWeighted64f, 0 -}; + static BinaryFunc addWeightedTab[] = + { + (BinaryFunc)GET_OPTIMIZED(addWeighted8u), (BinaryFunc)GET_OPTIMIZED(addWeighted8s), (BinaryFunc)GET_OPTIMIZED(addWeighted16u), + (BinaryFunc)GET_OPTIMIZED(addWeighted16s), (BinaryFunc)GET_OPTIMIZED(addWeighted32s), (BinaryFunc)addWeighted32f, + (BinaryFunc)addWeighted64f, 0 + }; + + return addWeightedTab; +} } @@ -2039,7 +2083,7 @@ void cv::addWeighted( InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype ) { double scalars[] = {alpha, beta, gamma}; - arithm_op(src1, src2, dst, noArray(), dtype, addWeightedTab, true, scalars); + arithm_op(src1, src2, dst, noArray(), dtype, getAddWeightedTab(), true, scalars); } @@ -2299,15 +2343,19 @@ static void cmp64f(const double* src1, size_t step1, const double* src2, size_t cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); } -static BinaryFunc cmpTab[] = +static BinaryFunc getCmpFunc(int depth) { - (BinaryFunc)GET_OPTIMIZED(cmp8u), (BinaryFunc)GET_OPTIMIZED(cmp8s), - (BinaryFunc)GET_OPTIMIZED(cmp16u), (BinaryFunc)GET_OPTIMIZED(cmp16s), - (BinaryFunc)GET_OPTIMIZED(cmp32s), - (BinaryFunc)GET_OPTIMIZED(cmp32f), (BinaryFunc)cmp64f, - 0 -}; + static BinaryFunc cmpTab[] = + { + (BinaryFunc)GET_OPTIMIZED(cmp8u), (BinaryFunc)GET_OPTIMIZED(cmp8s), + (BinaryFunc)GET_OPTIMIZED(cmp16u), (BinaryFunc)GET_OPTIMIZED(cmp16s), + (BinaryFunc)GET_OPTIMIZED(cmp32s), + (BinaryFunc)GET_OPTIMIZED(cmp32f), (BinaryFunc)cmp64f, + 0 + }; + return cmpTab[depth]; +} static double getMinVal(int depth) { @@ -2337,7 +2385,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) _dst.create(src1.size(), CV_8UC(cn)); Mat dst = _dst.getMat(); Size sz = getContinuousSize(src1, src2, dst, src1.channels()); - cmpTab[src1.depth()](src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, &op); + getCmpFunc(src1.depth())(src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, &op); return; } @@ -2369,7 +2417,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) size_t esz = src1.elemSize(); size_t blocksize0 = (size_t)(BLOCK_SIZE + esz-1)/esz; - BinaryFunc func = cmpTab[depth1]; + BinaryFunc func = getCmpFunc(depth1); if( !haveScalar ) { @@ -2546,12 +2594,17 @@ static void inRangeReduce(const uchar* src, uchar* dst, size_t len, int cn) typedef void (*InRangeFunc)( const uchar* src1, size_t step1, const uchar* src2, size_t step2, const uchar* src3, size_t step3, uchar* dst, size_t step, Size sz ); -static InRangeFunc inRangeTab[] = +static InRangeFunc getInRangeFunc(int depth) { - (InRangeFunc)GET_OPTIMIZED(inRange8u), (InRangeFunc)GET_OPTIMIZED(inRange8s), (InRangeFunc)GET_OPTIMIZED(inRange16u), - (InRangeFunc)GET_OPTIMIZED(inRange16s), (InRangeFunc)GET_OPTIMIZED(inRange32s), (InRangeFunc)GET_OPTIMIZED(inRange32f), - (InRangeFunc)inRange64f, 0 -}; + static InRangeFunc inRangeTab[] = + { + (InRangeFunc)GET_OPTIMIZED(inRange8u), (InRangeFunc)GET_OPTIMIZED(inRange8s), (InRangeFunc)GET_OPTIMIZED(inRange16u), + (InRangeFunc)GET_OPTIMIZED(inRange16s), (InRangeFunc)GET_OPTIMIZED(inRange32s), (InRangeFunc)GET_OPTIMIZED(inRange32f), + (InRangeFunc)inRange64f, 0 + }; + + return inRangeTab[depth]; +} } @@ -2590,7 +2643,7 @@ void cv::inRange(InputArray _src, InputArray _lowerb, _dst.create(src.dims, src.size, CV_8U); Mat dst = _dst.getMat(); - InRangeFunc func = inRangeTab[depth]; + InRangeFunc func = getInRangeFunc(depth); const Mat* arrays_sc[] = { &src, &dst, 0 }; const Mat* arrays_nosc[] = { &src, &dst, &lb, &ub, 0 }; diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index f5d6e9998f..97bd5ddd93 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -194,17 +194,27 @@ static void merge64s(const int64** src, int64* dst, int len, int cn ) typedef void (*SplitFunc)(const uchar* src, uchar** dst, int len, int cn); typedef void (*MergeFunc)(const uchar** src, uchar* dst, int len, int cn); -static SplitFunc splitTab[] = +static SplitFunc getSplitFunc(int depth) { - (SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split16u), (SplitFunc)GET_OPTIMIZED(split16u), - (SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split64s), 0 -}; + static SplitFunc splitTab[] = + { + (SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split16u), (SplitFunc)GET_OPTIMIZED(split16u), + (SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split64s), 0 + }; + + return splitTab[depth]; +} -static MergeFunc mergeTab[] = +static MergeFunc getMergeFunc(int depth) { - (MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge16u), (MergeFunc)GET_OPTIMIZED(merge16u), - (MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge64s), 0 -}; + static MergeFunc mergeTab[] = + { + (MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge16u), (MergeFunc)GET_OPTIMIZED(merge16u), + (MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge64s), 0 + }; + + return mergeTab[depth]; +} } @@ -217,7 +227,7 @@ void cv::split(const Mat& src, Mat* mv) return; } - SplitFunc func = splitTab[depth]; + SplitFunc func = getSplitFunc(depth); CV_Assert( func != 0 ); int esz = (int)src.elemSize(), esz1 = (int)src.elemSize1(); @@ -323,7 +333,7 @@ void cv::merge(const Mat* mv, size_t n, OutputArray _dst) NAryMatIterator it(arrays, ptrs, cn+1); int total = (int)it.size, blocksize = cn <= 4 ? total : std::min(total, blocksize0); - MergeFunc func = mergeTab[depth]; + MergeFunc func = getMergeFunc(depth); for( i = 0; i < it.nplanes; i++, ++it ) { @@ -419,12 +429,17 @@ static void mixChannels64s( const int64** src, const int* sdelta, typedef void (*MixChannelsFunc)( const uchar** src, const int* sdelta, uchar** dst, const int* ddelta, int len, int npairs ); -static MixChannelsFunc mixchTab[] = +static MixChannelsFunc getMixchFunc(int depth) { - (MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels16u, - (MixChannelsFunc)mixChannels16u, (MixChannelsFunc)mixChannels32s, (MixChannelsFunc)mixChannels32s, - (MixChannelsFunc)mixChannels64s, 0 -}; + static MixChannelsFunc mixchTab[] = + { + (MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels16u, + (MixChannelsFunc)mixChannels16u, (MixChannelsFunc)mixChannels32s, (MixChannelsFunc)mixChannels32s, + (MixChannelsFunc)mixChannels64s, 0 + }; + + return mixchTab[depth]; +} } @@ -479,7 +494,7 @@ void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, cons NAryMatIterator it(arrays, ptrs, (int)(nsrcs + ndsts)); int total = (int)it.size, blocksize = std::min(total, (int)((BLOCK_SIZE + esz1-1)/esz1)); - MixChannelsFunc func = mixchTab[depth]; + MixChannelsFunc func = getMixchFunc(depth); for( i = 0; i < it.nplanes; i++, ++it ) { @@ -947,104 +962,109 @@ DEF_CVT_FUNC(32s64f, int, double); DEF_CVT_FUNC(32f64f, float, double); DEF_CPY_FUNC(64s, int64); -static BinaryFunc cvtScaleAbsTab[] = -{ - (BinaryFunc)cvtScaleAbs8u, (BinaryFunc)cvtScaleAbs8s8u, (BinaryFunc)cvtScaleAbs16u8u, - (BinaryFunc)cvtScaleAbs16s8u, (BinaryFunc)cvtScaleAbs32s8u, (BinaryFunc)cvtScaleAbs32f8u, - (BinaryFunc)cvtScaleAbs64f8u, 0 -}; - -static BinaryFunc cvtScaleTab[][8] = +static BinaryFunc getCvtScaleAbsFunc(int depth) { + static BinaryFunc cvtScaleAbsTab[] = { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8u), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8u), - (BinaryFunc)cvtScale64f8u, 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u8s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8s), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8s), - (BinaryFunc)cvtScale64f8s, 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u16u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16u), - (BinaryFunc)cvtScale64f16u, 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u16s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u16s), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16s), - (BinaryFunc)cvtScale64f16s, 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u32s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32s), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f32s), - (BinaryFunc)cvtScale64f32s, 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvtScale8u32f), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32f), - (BinaryFunc)GET_OPTIMIZED(cvtScale16s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32f), - (BinaryFunc)cvtScale64f32f, 0 - }, - { - (BinaryFunc)cvtScale8u64f, (BinaryFunc)cvtScale8s64f, (BinaryFunc)cvtScale16u64f, - (BinaryFunc)cvtScale16s64f, (BinaryFunc)cvtScale32s64f, (BinaryFunc)cvtScale32f64f, - (BinaryFunc)cvtScale64f, 0 - }, - { - 0, 0, 0, 0, 0, 0, 0, 0 - } -}; + (BinaryFunc)cvtScaleAbs8u, (BinaryFunc)cvtScaleAbs8s8u, (BinaryFunc)cvtScaleAbs16u8u, + (BinaryFunc)cvtScaleAbs16s8u, (BinaryFunc)cvtScaleAbs32s8u, (BinaryFunc)cvtScaleAbs32f8u, + (BinaryFunc)cvtScaleAbs64f8u, 0 + }; -static BinaryFunc cvtTab[][8] = -{ - { - (BinaryFunc)(cvt8u), (BinaryFunc)GET_OPTIMIZED(cvt8s8u), (BinaryFunc)GET_OPTIMIZED(cvt16u8u), - (BinaryFunc)GET_OPTIMIZED(cvt16s8u), (BinaryFunc)GET_OPTIMIZED(cvt32s8u), (BinaryFunc)GET_OPTIMIZED(cvt32f8u), - (BinaryFunc)GET_OPTIMIZED(cvt64f8u), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u8s), (BinaryFunc)cvt8u, (BinaryFunc)GET_OPTIMIZED(cvt16u8s), - (BinaryFunc)GET_OPTIMIZED(cvt16s8s), (BinaryFunc)GET_OPTIMIZED(cvt32s8s), (BinaryFunc)GET_OPTIMIZED(cvt32f8s), - (BinaryFunc)GET_OPTIMIZED(cvt64f8s), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u16u), (BinaryFunc)GET_OPTIMIZED(cvt8s16u), (BinaryFunc)cvt16u, - (BinaryFunc)GET_OPTIMIZED(cvt16s16u), (BinaryFunc)GET_OPTIMIZED(cvt32s16u), (BinaryFunc)GET_OPTIMIZED(cvt32f16u), - (BinaryFunc)GET_OPTIMIZED(cvt64f16u), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u16s), (BinaryFunc)GET_OPTIMIZED(cvt8s16s), (BinaryFunc)GET_OPTIMIZED(cvt16u16s), - (BinaryFunc)cvt16u, (BinaryFunc)GET_OPTIMIZED(cvt32s16s), (BinaryFunc)GET_OPTIMIZED(cvt32f16s), - (BinaryFunc)GET_OPTIMIZED(cvt64f16s), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u32s), (BinaryFunc)GET_OPTIMIZED(cvt8s32s), (BinaryFunc)GET_OPTIMIZED(cvt16u32s), - (BinaryFunc)GET_OPTIMIZED(cvt16s32s), (BinaryFunc)cvt32s, (BinaryFunc)GET_OPTIMIZED(cvt32f32s), - (BinaryFunc)GET_OPTIMIZED(cvt64f32s), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u32f), (BinaryFunc)GET_OPTIMIZED(cvt8s32f), (BinaryFunc)GET_OPTIMIZED(cvt16u32f), - (BinaryFunc)GET_OPTIMIZED(cvt16s32f), (BinaryFunc)GET_OPTIMIZED(cvt32s32f), (BinaryFunc)cvt32s, - (BinaryFunc)GET_OPTIMIZED(cvt64f32f), 0 - }, - { - (BinaryFunc)GET_OPTIMIZED(cvt8u64f), (BinaryFunc)GET_OPTIMIZED(cvt8s64f), (BinaryFunc)GET_OPTIMIZED(cvt16u64f), - (BinaryFunc)GET_OPTIMIZED(cvt16s64f), (BinaryFunc)GET_OPTIMIZED(cvt32s64f), (BinaryFunc)GET_OPTIMIZED(cvt32f64f), - (BinaryFunc)(cvt64s), 0 - }, - { - 0, 0, 0, 0, 0, 0, 0, 0 - } -}; + return cvtScaleAbsTab[depth]; +} BinaryFunc getConvertFunc(int sdepth, int ddepth) { + static BinaryFunc cvtTab[][8] = + { + { + (BinaryFunc)(cvt8u), (BinaryFunc)GET_OPTIMIZED(cvt8s8u), (BinaryFunc)GET_OPTIMIZED(cvt16u8u), + (BinaryFunc)GET_OPTIMIZED(cvt16s8u), (BinaryFunc)GET_OPTIMIZED(cvt32s8u), (BinaryFunc)GET_OPTIMIZED(cvt32f8u), + (BinaryFunc)GET_OPTIMIZED(cvt64f8u), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u8s), (BinaryFunc)cvt8u, (BinaryFunc)GET_OPTIMIZED(cvt16u8s), + (BinaryFunc)GET_OPTIMIZED(cvt16s8s), (BinaryFunc)GET_OPTIMIZED(cvt32s8s), (BinaryFunc)GET_OPTIMIZED(cvt32f8s), + (BinaryFunc)GET_OPTIMIZED(cvt64f8s), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u16u), (BinaryFunc)GET_OPTIMIZED(cvt8s16u), (BinaryFunc)cvt16u, + (BinaryFunc)GET_OPTIMIZED(cvt16s16u), (BinaryFunc)GET_OPTIMIZED(cvt32s16u), (BinaryFunc)GET_OPTIMIZED(cvt32f16u), + (BinaryFunc)GET_OPTIMIZED(cvt64f16u), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u16s), (BinaryFunc)GET_OPTIMIZED(cvt8s16s), (BinaryFunc)GET_OPTIMIZED(cvt16u16s), + (BinaryFunc)cvt16u, (BinaryFunc)GET_OPTIMIZED(cvt32s16s), (BinaryFunc)GET_OPTIMIZED(cvt32f16s), + (BinaryFunc)GET_OPTIMIZED(cvt64f16s), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u32s), (BinaryFunc)GET_OPTIMIZED(cvt8s32s), (BinaryFunc)GET_OPTIMIZED(cvt16u32s), + (BinaryFunc)GET_OPTIMIZED(cvt16s32s), (BinaryFunc)cvt32s, (BinaryFunc)GET_OPTIMIZED(cvt32f32s), + (BinaryFunc)GET_OPTIMIZED(cvt64f32s), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u32f), (BinaryFunc)GET_OPTIMIZED(cvt8s32f), (BinaryFunc)GET_OPTIMIZED(cvt16u32f), + (BinaryFunc)GET_OPTIMIZED(cvt16s32f), (BinaryFunc)GET_OPTIMIZED(cvt32s32f), (BinaryFunc)cvt32s, + (BinaryFunc)GET_OPTIMIZED(cvt64f32f), 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvt8u64f), (BinaryFunc)GET_OPTIMIZED(cvt8s64f), (BinaryFunc)GET_OPTIMIZED(cvt16u64f), + (BinaryFunc)GET_OPTIMIZED(cvt16s64f), (BinaryFunc)GET_OPTIMIZED(cvt32s64f), (BinaryFunc)GET_OPTIMIZED(cvt32f64f), + (BinaryFunc)(cvt64s), 0 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0 + } + }; + return cvtTab[CV_MAT_DEPTH(ddepth)][CV_MAT_DEPTH(sdepth)]; } static BinaryFunc getConvertScaleFunc(int sdepth, int ddepth) { + static BinaryFunc cvtScaleTab[][8] = + { + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8u), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8u), + (BinaryFunc)cvtScale64f8u, 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u8s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8s), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8s), + (BinaryFunc)cvtScale64f8s, 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u16u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16u), + (BinaryFunc)cvtScale64f16u, 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u16s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u16s), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16s), + (BinaryFunc)cvtScale64f16s, 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u32s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32s), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f32s), + (BinaryFunc)cvtScale64f32s, 0 + }, + { + (BinaryFunc)GET_OPTIMIZED(cvtScale8u32f), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32f), + (BinaryFunc)GET_OPTIMIZED(cvtScale16s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32f), + (BinaryFunc)cvtScale64f32f, 0 + }, + { + (BinaryFunc)cvtScale8u64f, (BinaryFunc)cvtScale8s64f, (BinaryFunc)cvtScale16u64f, + (BinaryFunc)cvtScale16s64f, (BinaryFunc)cvtScale32s64f, (BinaryFunc)cvtScale32f64f, + (BinaryFunc)cvtScale64f, 0 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0 + } + }; + return cvtScaleTab[CV_MAT_DEPTH(ddepth)][CV_MAT_DEPTH(sdepth)]; } @@ -1057,7 +1077,7 @@ void cv::convertScaleAbs( InputArray _src, OutputArray _dst, double alpha, doubl double scale[] = {alpha, beta}; _dst.create( src.dims, src.size, CV_8UC(cn) ); Mat dst = _dst.getMat(); - BinaryFunc func = cvtScaleAbsTab[src.depth()]; + BinaryFunc func = getCvtScaleAbsFunc(src.depth()); CV_Assert( func != 0 ); if( src.dims <= 2 ) diff --git a/modules/core/src/matmul.cpp b/modules/core/src/matmul.cpp index 404c5b4341..7c33a30773 100644 --- a/modules/core/src/matmul.cpp +++ b/modules/core/src/matmul.cpp @@ -1725,19 +1725,29 @@ diagtransform_64f(const double* src, double* dst, const double* m, int len, int typedef void (*TransformFunc)( const uchar* src, uchar* dst, const uchar* m, int, int, int ); -static TransformFunc transformTab[] = +static TransformFunc getTransformFunc(int depth) { - (TransformFunc)transform_8u, (TransformFunc)transform_8s, (TransformFunc)transform_16u, - (TransformFunc)transform_16s, (TransformFunc)transform_32s, (TransformFunc)transform_32f, - (TransformFunc)transform_64f, 0 -}; + static TransformFunc transformTab[] = + { + (TransformFunc)transform_8u, (TransformFunc)transform_8s, (TransformFunc)transform_16u, + (TransformFunc)transform_16s, (TransformFunc)transform_32s, (TransformFunc)transform_32f, + (TransformFunc)transform_64f, 0 + }; + + return transformTab[depth]; +} -static TransformFunc diagTransformTab[] = +static TransformFunc getDiagTransformFunc(int depth) { - (TransformFunc)diagtransform_8u, (TransformFunc)diagtransform_8s, (TransformFunc)diagtransform_16u, - (TransformFunc)diagtransform_16s, (TransformFunc)diagtransform_32s, (TransformFunc)diagtransform_32f, - (TransformFunc)diagtransform_64f, 0 -}; + static TransformFunc diagTransformTab[] = + { + (TransformFunc)diagtransform_8u, (TransformFunc)diagtransform_8s, (TransformFunc)diagtransform_16u, + (TransformFunc)diagtransform_16s, (TransformFunc)diagtransform_32s, (TransformFunc)diagtransform_32f, + (TransformFunc)diagtransform_64f, 0 + }; + + return diagTransformTab[depth]; +} } @@ -1800,7 +1810,7 @@ void cv::transform( InputArray _src, OutputArray _dst, InputArray _mtx ) } } - TransformFunc func = isDiag ? diagTransformTab[depth] : transformTab[depth]; + TransformFunc func = isDiag ? getDiagTransformFunc(depth): getTransformFunc(depth); CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &dst, 0}; @@ -2761,19 +2771,24 @@ static double dotProd_64f(const double* src1, const double* src2, int len) typedef double (*DotProdFunc)(const uchar* src1, const uchar* src2, int len); -static DotProdFunc dotProdTab[] = +static DotProdFunc getDotProdFunc(int depth) { - (DotProdFunc)GET_OPTIMIZED(dotProd_8u), (DotProdFunc)GET_OPTIMIZED(dotProd_8s), - (DotProdFunc)dotProd_16u, (DotProdFunc)dotProd_16s, - (DotProdFunc)dotProd_32s, (DotProdFunc)GET_OPTIMIZED(dotProd_32f), - (DotProdFunc)dotProd_64f, 0 -}; + static DotProdFunc dotProdTab[] = + { + (DotProdFunc)GET_OPTIMIZED(dotProd_8u), (DotProdFunc)GET_OPTIMIZED(dotProd_8s), + (DotProdFunc)dotProd_16u, (DotProdFunc)dotProd_16s, + (DotProdFunc)dotProd_32s, (DotProdFunc)GET_OPTIMIZED(dotProd_32f), + (DotProdFunc)dotProd_64f, 0 + }; + + return dotProdTab[depth]; +} double Mat::dot(InputArray _mat) const { Mat mat = _mat.getMat(); int cn = channels(); - DotProdFunc func = dotProdTab[depth()]; + DotProdFunc func = getDotProdFunc(depth()); CV_Assert( mat.type() == type() && mat.size == size && func != 0 ); if( isContinuous() && mat.isContinuous() ) diff --git a/modules/core/src/precomp.cpp b/modules/core/src/precomp.cpp deleted file mode 100644 index e540cc5e8a..0000000000 --- a/modules/core/src/precomp.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index 6bc3a4d493..780012c0ed 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -200,14 +200,19 @@ static int sum64f( const double* src, const uchar* mask, double* dst, int len, i typedef int (*SumFunc)(const uchar*, const uchar* mask, uchar*, int, int); -static SumFunc sumTab[] = +static SumFunc getSumFunc(int depth) { - (SumFunc)GET_OPTIMIZED(sum8u), (SumFunc)sum8s, - (SumFunc)sum16u, (SumFunc)sum16s, - (SumFunc)sum32s, - (SumFunc)GET_OPTIMIZED(sum32f), (SumFunc)sum64f, - 0 -}; + static SumFunc sumTab[] = + { + (SumFunc)GET_OPTIMIZED(sum8u), (SumFunc)sum8s, + (SumFunc)sum16u, (SumFunc)sum16s, + (SumFunc)sum32s, + (SumFunc)GET_OPTIMIZED(sum32f), (SumFunc)sum64f, + 0 + }; + + return sumTab[depth]; +} template static int countNonZero_(const T* src, int len ) @@ -272,14 +277,18 @@ static int countNonZero64f( const double* src, int len ) typedef int (*CountNonZeroFunc)(const uchar*, int); -static CountNonZeroFunc countNonZeroTab[] = +static CountNonZeroFunc getCountNonZeroTab(int depth) { - (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), - (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), - (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32s), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32f), - (CountNonZeroFunc)GET_OPTIMIZED(countNonZero64f), 0 -}; + static CountNonZeroFunc countNonZeroTab[] = + { + (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), + (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), + (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32s), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32f), + (CountNonZeroFunc)GET_OPTIMIZED(countNonZero64f), 0 + }; + return countNonZeroTab[depth]; +} template static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int len, int cn ) @@ -428,11 +437,16 @@ static int sqsum64f( const double* src, const uchar* mask, double* sum, double* typedef int (*SumSqrFunc)(const uchar*, const uchar* mask, uchar*, uchar*, int, int); -static SumSqrFunc sumSqrTab[] = +static SumSqrFunc getSumSqrTab(int depth) { - (SumSqrFunc)GET_OPTIMIZED(sqsum8u), (SumSqrFunc)sqsum8s, (SumSqrFunc)sqsum16u, (SumSqrFunc)sqsum16s, - (SumSqrFunc)sqsum32s, (SumSqrFunc)GET_OPTIMIZED(sqsum32f), (SumSqrFunc)sqsum64f, 0 -}; + static SumSqrFunc sumSqrTab[] = + { + (SumSqrFunc)GET_OPTIMIZED(sqsum8u), (SumSqrFunc)sqsum8s, (SumSqrFunc)sqsum16u, (SumSqrFunc)sqsum16s, + (SumSqrFunc)sqsum32s, (SumSqrFunc)GET_OPTIMIZED(sqsum32f), (SumSqrFunc)sqsum64f, 0 + }; + + return sumSqrTab[depth]; +} } @@ -479,7 +493,7 @@ cv::Scalar cv::sum( InputArray _src ) } #endif - SumFunc func = sumTab[depth]; + SumFunc func = getSumFunc(depth); CV_Assert( cn <= 4 && func != 0 ); @@ -531,7 +545,7 @@ cv::Scalar cv::sum( InputArray _src ) int cv::countNonZero( InputArray _src ) { Mat src = _src.getMat(); - CountNonZeroFunc func = countNonZeroTab[src.depth()]; + CountNonZeroFunc func = getCountNonZeroTab(src.depth()); CV_Assert( src.channels() == 1 && func != 0 ); @@ -627,7 +641,7 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) } #endif - SumFunc func = sumTab[depth]; + SumFunc func = getSumFunc(depth); CV_Assert( cn <= 4 && func != 0 ); @@ -686,7 +700,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input CV_Assert( mask.empty() || mask.type() == CV_8U ); int k, cn = src.channels(), depth = src.depth(); - SumSqrFunc func = sumSqrTab[depth]; + SumSqrFunc func = getSumSqrTab(depth); CV_Assert( func != 0 ); @@ -860,14 +874,19 @@ static void minMaxIdx_64f(const double* src, const uchar* mask, double* minval, typedef void (*MinMaxIdxFunc)(const uchar*, const uchar*, int*, int*, size_t*, size_t*, int, size_t); -static MinMaxIdxFunc minmaxTab[] = +static MinMaxIdxFunc getMinmaxTab(int depth) { - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8u), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_16u), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_16s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_32s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_32f), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_64f), - 0 -}; + static MinMaxIdxFunc minmaxTab[] = + { + (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8u), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8s), + (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_16u), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_16s), + (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_32s), + (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_32f), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_64f), + 0 + }; + + return minmaxTab[depth]; +} static void ofs2idx(const Mat& a, size_t ofs, int* idx) { @@ -900,7 +919,7 @@ void cv::minMaxIdx(InputArray _src, double* minVal, CV_Assert( (cn == 1 && (mask.empty() || mask.type() == CV_8U)) || (cn >= 1 && mask.empty() && !minIdx && !maxIdx) ); - MinMaxIdxFunc func = minmaxTab[depth]; + MinMaxIdxFunc func = getMinmaxTab(depth); CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &mask, 0}; @@ -1365,43 +1384,53 @@ CV_DEF_NORM_ALL(64f, double, double, double, double) typedef int (*NormFunc)(const uchar*, const uchar*, uchar*, int, int); typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int); -static NormFunc normTab[3][8] = +static NormFunc getNormFunc(int normType, int depth) { + static NormFunc normTab[3][8] = { - (NormFunc)GET_OPTIMIZED(normInf_8u), (NormFunc)GET_OPTIMIZED(normInf_8s), (NormFunc)GET_OPTIMIZED(normInf_16u), (NormFunc)GET_OPTIMIZED(normInf_16s), - (NormFunc)GET_OPTIMIZED(normInf_32s), (NormFunc)GET_OPTIMIZED(normInf_32f), (NormFunc)normInf_64f, 0 - }, - { - (NormFunc)GET_OPTIMIZED(normL1_8u), (NormFunc)GET_OPTIMIZED(normL1_8s), (NormFunc)GET_OPTIMIZED(normL1_16u), (NormFunc)GET_OPTIMIZED(normL1_16s), - (NormFunc)GET_OPTIMIZED(normL1_32s), (NormFunc)GET_OPTIMIZED(normL1_32f), (NormFunc)normL1_64f, 0 - }, - { - (NormFunc)GET_OPTIMIZED(normL2_8u), (NormFunc)GET_OPTIMIZED(normL2_8s), (NormFunc)GET_OPTIMIZED(normL2_16u), (NormFunc)GET_OPTIMIZED(normL2_16s), - (NormFunc)GET_OPTIMIZED(normL2_32s), (NormFunc)GET_OPTIMIZED(normL2_32f), (NormFunc)normL2_64f, 0 - } -}; + { + (NormFunc)GET_OPTIMIZED(normInf_8u), (NormFunc)GET_OPTIMIZED(normInf_8s), (NormFunc)GET_OPTIMIZED(normInf_16u), (NormFunc)GET_OPTIMIZED(normInf_16s), + (NormFunc)GET_OPTIMIZED(normInf_32s), (NormFunc)GET_OPTIMIZED(normInf_32f), (NormFunc)normInf_64f, 0 + }, + { + (NormFunc)GET_OPTIMIZED(normL1_8u), (NormFunc)GET_OPTIMIZED(normL1_8s), (NormFunc)GET_OPTIMIZED(normL1_16u), (NormFunc)GET_OPTIMIZED(normL1_16s), + (NormFunc)GET_OPTIMIZED(normL1_32s), (NormFunc)GET_OPTIMIZED(normL1_32f), (NormFunc)normL1_64f, 0 + }, + { + (NormFunc)GET_OPTIMIZED(normL2_8u), (NormFunc)GET_OPTIMIZED(normL2_8s), (NormFunc)GET_OPTIMIZED(normL2_16u), (NormFunc)GET_OPTIMIZED(normL2_16s), + (NormFunc)GET_OPTIMIZED(normL2_32s), (NormFunc)GET_OPTIMIZED(normL2_32f), (NormFunc)normL2_64f, 0 + } + }; -static NormDiffFunc normDiffTab[3][8] = + return normTab[normType][depth]; +} + +static NormDiffFunc getNormDiffFunc(int normType, int depth) { + static NormDiffFunc normDiffTab[3][8] = { - (NormDiffFunc)GET_OPTIMIZED(normDiffInf_8u), (NormDiffFunc)normDiffInf_8s, - (NormDiffFunc)normDiffInf_16u, (NormDiffFunc)normDiffInf_16s, - (NormDiffFunc)normDiffInf_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffInf_32f), - (NormDiffFunc)normDiffInf_64f, 0 - }, - { - (NormDiffFunc)GET_OPTIMIZED(normDiffL1_8u), (NormDiffFunc)normDiffL1_8s, - (NormDiffFunc)normDiffL1_16u, (NormDiffFunc)normDiffL1_16s, - (NormDiffFunc)normDiffL1_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffL1_32f), - (NormDiffFunc)normDiffL1_64f, 0 - }, - { - (NormDiffFunc)GET_OPTIMIZED(normDiffL2_8u), (NormDiffFunc)normDiffL2_8s, - (NormDiffFunc)normDiffL2_16u, (NormDiffFunc)normDiffL2_16s, - (NormDiffFunc)normDiffL2_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffL2_32f), - (NormDiffFunc)normDiffL2_64f, 0 - } -}; + { + (NormDiffFunc)GET_OPTIMIZED(normDiffInf_8u), (NormDiffFunc)normDiffInf_8s, + (NormDiffFunc)normDiffInf_16u, (NormDiffFunc)normDiffInf_16s, + (NormDiffFunc)normDiffInf_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffInf_32f), + (NormDiffFunc)normDiffInf_64f, 0 + }, + { + (NormDiffFunc)GET_OPTIMIZED(normDiffL1_8u), (NormDiffFunc)normDiffL1_8s, + (NormDiffFunc)normDiffL1_16u, (NormDiffFunc)normDiffL1_16s, + (NormDiffFunc)normDiffL1_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffL1_32f), + (NormDiffFunc)normDiffL1_64f, 0 + }, + { + (NormDiffFunc)GET_OPTIMIZED(normDiffL2_8u), (NormDiffFunc)normDiffL2_8s, + (NormDiffFunc)normDiffL2_16u, (NormDiffFunc)normDiffL2_16s, + (NormDiffFunc)normDiffL2_32s, (NormDiffFunc)GET_OPTIMIZED(normDiffL2_32f), + (NormDiffFunc)normDiffL2_64f, 0 + } + }; + + return normDiffTab[normType][depth]; +} } @@ -1485,7 +1514,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) return result; } - NormFunc func = normTab[normType >> 1][depth]; + NormFunc func = getNormFunc(normType >> 1, depth); CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &mask, 0}; @@ -1626,7 +1655,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m return result; } - NormDiffFunc func = normDiffTab[normType >> 1][depth]; + NormDiffFunc func = getNormDiffFunc(normType >> 1, depth); CV_Assert( func != 0 ); const Mat* arrays[] = {&src1, &src2, &mask, 0}; diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 602dcd1e14..d88b1b0301 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -391,7 +391,6 @@ protected: try { string fname = cv::tempfile(".xml"); - FileStorage fs(fname, FileStorage::WRITE); vector mi, mi2, mi3, mi4; vector mv, mv2, mv3, mv4; Mat m(10, 9, CV_32F); @@ -399,24 +398,59 @@ protected: randu(m, 0, 1); mi3.push_back(5); mv3.push_back(m); + Point_ p1(1.1f, 2.2f), op1; + Point3i p2(3, 4, 5), op2; + Size s1(6, 7), os1; + Complex c1(9, 10), oc1; + Rect r1(11, 12, 13, 14), or1; + Vec v1(15, 16, 17, 18, 19), ov1; + Scalar sc1(20.0, 21.1, 22.2, 23.3), osc1; + Range g1(7, 8), og1; + + FileStorage fs(fname, FileStorage::WRITE); fs << "mi" << mi; fs << "mv" << mv; fs << "mi3" << mi3; fs << "mv3" << mv3; fs << "empty" << empty; + fs << "p1" << p1; + fs << "p2" << p2; + fs << "s1" << s1; + fs << "c1" << c1; + fs << "r1" << r1; + fs << "v1" << v1; + fs << "sc1" << sc1; + fs << "g1" << g1; fs.release(); + fs.open(fname, FileStorage::READ); fs["mi"] >> mi2; fs["mv"] >> mv2; fs["mi3"] >> mi4; fs["mv3"] >> mv4; fs["empty"] >> empty; + fs["p1"] >> op1; + fs["p2"] >> op2; + fs["s1"] >> os1; + fs["c1"] >> oc1; + fs["r1"] >> or1; + fs["v1"] >> ov1; + fs["sc1"] >> osc1; + fs["g1"] >> og1; CV_Assert( mi2.empty() ); CV_Assert( mv2.empty() ); CV_Assert( norm(mi3, mi4, CV_C) == 0 ); CV_Assert( mv4.size() == 1 ); double n = norm(mv3[0], mv4[0], CV_C); CV_Assert( n == 0 ); + CV_Assert( op1 == p1 ); + CV_Assert( op2 == p2 ); + CV_Assert( os1 == s1 ); + CV_Assert( oc1 == c1 ); + CV_Assert( or1 == r1 ); + CV_Assert( ov1 == v1 ); + CV_Assert( osc1 == sc1 ); + CV_Assert( og1 == g1 ); } catch(...) { diff --git a/modules/core/test/test_precomp.cpp b/modules/core/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/core/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/features2d/perf/perf_precomp.cpp b/modules/features2d/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/features2d/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/features2d/src/precomp.cpp b/modules/features2d/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/features2d/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/features2d/test/test_precomp.cpp b/modules/features2d/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/features2d/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/flann/src/precomp.cpp b/modules/flann/src/precomp.cpp deleted file mode 100644 index c149df18f9..0000000000 --- a/modules/flann/src/precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "precomp.hpp" diff --git a/modules/flann/test/test_precomp.cpp b/modules/flann/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/flann/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/gpu/perf/perf_precomp.cpp b/modules/gpu/perf/perf_precomp.cpp deleted file mode 100644 index 81f16e8f14..0000000000 --- a/modules/gpu/perf/perf_precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "perf_precomp.hpp" diff --git a/modules/gpu/test/test_precomp.cpp b/modules/gpu/test/test_precomp.cpp deleted file mode 100644 index 0fb6521809..0000000000 --- a/modules/gpu/test/test_precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "test_precomp.hpp" diff --git a/modules/gpubgsegm/perf/perf_bgsegm.cpp b/modules/gpubgsegm/perf/perf_bgsegm.cpp index d4421691e7..6f864fd75c 100644 --- a/modules/gpubgsegm/perf/perf_bgsegm.cpp +++ b/modules/gpubgsegm/perf/perf_bgsegm.cpp @@ -57,6 +57,7 @@ using namespace perf; #if defined(HAVE_XINE) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(WIN32) /* assume that we have ffmpeg */ diff --git a/modules/gpubgsegm/test/test_bgsegm.cpp b/modules/gpubgsegm/test/test_bgsegm.cpp index e8fc68ddcb..3b5526b6c6 100644 --- a/modules/gpubgsegm/test/test_bgsegm.cpp +++ b/modules/gpubgsegm/test/test_bgsegm.cpp @@ -53,6 +53,7 @@ using namespace cvtest; #if defined(HAVE_XINE) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(WIN32) /* assume that we have ffmpeg */ diff --git a/modules/gpucodec/perf/perf_video.cpp b/modules/gpucodec/perf/perf_video.cpp index f389605d05..c4ab227c84 100644 --- a/modules/gpucodec/perf/perf_video.cpp +++ b/modules/gpucodec/perf/perf_video.cpp @@ -50,6 +50,7 @@ using namespace perf; #if defined(HAVE_XINE) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(WIN32) /* assume that we have ffmpeg */ diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index dbea6ec1c2..3737d25d83 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -64,7 +64,6 @@ set(highgui_srcs src/cap_images.cpp src/cap_ffmpeg.cpp src/loadsave.cpp - src/precomp.cpp src/utils.cpp src/window.cpp ) @@ -216,7 +215,7 @@ endif() if(HAVE_QUICKTIME) list(APPEND highgui_srcs src/cap_qt.cpp) list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore") -elseif(APPLE) +elseif(HAVE_QTKIT) list(APPEND highgui_srcs src/cap_qtkit.mm) list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit") endif() diff --git a/modules/highgui/perf/perf_precomp.cpp b/modules/highgui/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/highgui/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/highgui/perf/perf_precomp.hpp b/modules/highgui/perf/perf_precomp.hpp index f8e02fa70c..faf34617e3 100644 --- a/modules/highgui/perf/perf_precomp.hpp +++ b/modules/highgui/perf/perf_precomp.hpp @@ -19,6 +19,7 @@ #if defined(HAVE_XINE) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(HAVE_MSMF) || \ @@ -33,6 +34,7 @@ #if /*defined(HAVE_XINE) || */\ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(HAVE_MSMF) || \ diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index c25666379b..453f1dd122 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -135,7 +135,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) #ifdef HAVE_MIL CV_CAP_MIL, #endif -#ifdef HAVE_QUICKTIME +#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT) CV_CAP_QT, #endif #ifdef HAVE_UNICAP @@ -185,6 +185,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) defined(HAVE_CMU1394) || \ defined(HAVE_MIL) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_UNICAP) || \ defined(HAVE_PVAPI) || \ defined(HAVE_OPENNI) || \ @@ -277,7 +278,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) break; #endif -#ifdef HAVE_QUICKTIME +#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT) case CV_CAP_QT: capture = cvCreateCameraCapture_QT (index); if (capture) @@ -379,7 +380,7 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename) result = cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename); #endif -#ifdef HAVE_QUICKTIME +#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT) if (! result) result = cvCreateFileCapture_QT (filename); #endif @@ -437,7 +438,7 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, result = cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color); #endif -#ifdef HAVE_QUICKTIME +#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT) if(!result) result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color); #endif diff --git a/modules/highgui/src/cap_ffmpeg.cpp b/modules/highgui/src/cap_ffmpeg.cpp index 3734bb646d..192c0da694 100644 --- a/modules/highgui/src/cap_ffmpeg.cpp +++ b/modules/highgui/src/cap_ffmpeg.cpp @@ -85,6 +85,16 @@ private: icvInitFFMPEG() { #if defined WIN32 || defined _WIN32 + # ifdef HAVE_WINRT + const wchar_t* module_name = L"opencv_ffmpeg" + CVAUX_STRW(CV_MAJOR_VERSION) CVAUX_STRW(CV_MINOR_VERSION) CVAUX_STRW(CV_SUBMINOR_VERSION) + #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__) + L"_64" + #endif + L".dll"; + + icvFFOpenCV = LoadPackagedLibrary( module_name, 0 ); + # else const char* module_name = "opencv_ffmpeg" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION) #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__) @@ -93,6 +103,8 @@ private: ".dll"; icvFFOpenCV = LoadLibrary( module_name ); + # endif + if( icvFFOpenCV ) { icvCreateFileCapture_FFMPEG_p = diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index dca57ab3d7..fbe6bc8730 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -374,7 +374,15 @@ private: struct ImplMutex::Impl { - void init() { InitializeCriticalSection(&cs); refcount = 1; } + void init() + { +#if (_WIN32_WINNT >= 0x0600) + ::InitializeCriticalSectionEx(&cs, 1000, 0); +#else + ::InitializeCriticalSection(&cs); +#endif + refcount = 1; + } void destroy() { DeleteCriticalSection(&cs); } void lock() { EnterCriticalSection(&cs); } diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm index d44b7636d7..02afb9bf54 100644 --- a/modules/highgui/src/cap_qtkit.mm +++ b/modules/highgui/src/cap_qtkit.mm @@ -1,32 +1,44 @@ -/* - * CvCapture.mm - * - * Created by Nicholas Butko on 11/3/09. - * Copyright 2009. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributor be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*//////////////////////////////////////////////////////////////////////////////////////// + #include "precomp.hpp" #include "opencv2/imgproc.hpp" @@ -399,6 +411,9 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) { void CvCaptureCAM::setWidthHeight() { NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init]; + + [mCaptureSession stopRunning]; + NSDictionary* pixelBufferOptions = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithDouble:1.0*width], (id)kCVPixelBufferWidthKey, [NSNumber numberWithDouble:1.0*height], (id)kCVPixelBufferHeightKey, @@ -407,6 +422,9 @@ void CvCaptureCAM::setWidthHeight() { nil]; [mCaptureDecompressedVideoOutput setPixelBufferAttributes:pixelBufferOptions]; + + [mCaptureSession startRunning]; + grabFrame(60); [localpool drain]; } diff --git a/modules/highgui/src/precomp.cpp b/modules/highgui/src/precomp.cpp deleted file mode 100644 index d6f6e18f74..0000000000 --- a/modules/highgui/src/precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - diff --git a/modules/highgui/test/test_precomp.cpp b/modules/highgui/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/highgui/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/highgui/test/test_precomp.hpp b/modules/highgui/test/test_precomp.hpp index 34e9f974bb..8468e46181 100644 --- a/modules/highgui/test/test_precomp.hpp +++ b/modules/highgui/test/test_precomp.hpp @@ -28,6 +28,7 @@ defined(HAVE_CMU1394) || \ defined(HAVE_MIL) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_UNICAP) || \ defined(HAVE_PVAPI) || \ defined(HAVE_OPENNI) || \ @@ -44,6 +45,7 @@ #if defined(HAVE_XINE) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ /*defined(HAVE_OPENNI) || too specialized */ \ defined(HAVE_FFMPEG) || \ @@ -56,6 +58,7 @@ #if /*defined(HAVE_XINE) || */\ defined(HAVE_GSTREAMER) || \ defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_FFMPEG) || \ defined(HAVE_MSMF) diff --git a/modules/imgproc/doc/filtering.rst b/modules/imgproc/doc/filtering.rst index 5803145c5c..ee3dd2f6cd 100755 --- a/modules/imgproc/doc/filtering.rst +++ b/modules/imgproc/doc/filtering.rst @@ -1378,7 +1378,7 @@ Applies a separable linear filter to an image. :param kernelY: Coefficients for filtering each column. - :param anchor: Anchor position within the kernel. The default value :math:`(-1, 1)` means that the anchor is at the kernel center. + :param anchor: Anchor position within the kernel. The default value :math:`(-1,-1)` means that the anchor is at the kernel center. :param delta: Value added to the filtered results before storing them. diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index c2a488aac2..24d9f4463d 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -795,18 +795,18 @@ public: }; -class CV_EXPORTS CLAHE : public Algorithm +class CV_EXPORTS_W CLAHE : public Algorithm { public: - virtual void apply(InputArray src, OutputArray dst) = 0; + CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0; - virtual void setClipLimit(double clipLimit) = 0; - virtual double getClipLimit() const = 0; + CV_WRAP virtual void setClipLimit(double clipLimit) = 0; + CV_WRAP virtual double getClipLimit() const = 0; - virtual void setTilesGridSize(Size tileGridSize) = 0; - virtual Size getTilesGridSize() const = 0; + CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0; + CV_WRAP virtual Size getTilesGridSize() const = 0; - virtual void collectGarbage() = 0; + CV_WRAP virtual void collectGarbage() = 0; }; @@ -1479,7 +1479,7 @@ CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType, //! checks if the point is inside the contour. Optionally computes the signed distance from the point to the contour boundary CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist ); -CV_EXPORTS Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); +CV_EXPORTS_W Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. //! Detects position only without traslation and rotation diff --git a/modules/imgproc/perf/perf_precomp.cpp b/modules/imgproc/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/imgproc/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/imgproc/src/precomp.cpp b/modules/imgproc/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/imgproc/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 672e911131..e194def845 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -191,6 +191,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType ) typedef typename CastOp::type1 WT; typedef typename CastOp::rtype T; + CV_Assert( !_src.empty() ); Size ssize = _src.size(), dsize = _dst.size(); int cn = _src.channels(); int bufstep = (int)alignSize(dsize.width*cn, 16); diff --git a/modules/imgproc/test/test_precomp.cpp b/modules/imgproc/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/imgproc/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index ae8c3b4974..cf9295533b 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -12,7 +12,7 @@ class_ignore_list = ( #core "FileNode", "FileStorage", "KDTree", "KeyPoint", "DMatch", #highgui - "VideoWriter", "VideoCapture", + "VideoWriter", ) const_ignore_list = ( @@ -510,6 +510,54 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1getTextSize "resizeWindow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' }, }, # Highgui + 'VideoCapture' : + { + "getSupportedPreviewSizes" : + { + 'j_code' : +""" + public java.util.List getSupportedPreviewSizes() + { + String[] sizes_str = getSupportedPreviewSizes_0(nativeObj).split(","); + java.util.List sizes = new java.util.ArrayList(sizes_str.length); + + for (String str : sizes_str) { + String[] wh = str.split("x"); + sizes.add(new org.opencv.core.Size(Double.parseDouble(wh[0]), Double.parseDouble(wh[1]))); + } + + return sizes; + } + +""", + 'jn_code' : +"""\n private static native String getSupportedPreviewSizes_0(long nativeObj);\n""", + 'cpp_code' : +""" +JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_getSupportedPreviewSizes_10 + (JNIEnv *env, jclass, jlong self); + +JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_getSupportedPreviewSizes_10 + (JNIEnv *env, jclass, jlong self) +{ + static const char method_name[] = "highgui::VideoCapture_getSupportedPreviewSizes_10()"; + try { + LOGD(%s, method_name); + VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL + union {double prop; const char* name;} u; + u.prop = me->get(CAP_PROP_ANDROID_PREVIEW_SIZES_STRING); + return env->NewStringUTF(u.name); + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); + } catch (...) { + throwJavaException(env, 0, method_name); + } + return env->NewStringUTF(""); +} + +""", + }, # getSupportedPreviewSizes + }, # VideoCapture } # { class : { func : { arg_name : {"ctype" : ctype, "attrib" : [attrib]} } } } @@ -898,21 +946,51 @@ public class %(jc)s { self.add_func(decl) self.cpp_code = StringIO() - self.cpp_code.write(""" + self.cpp_code.write(Template(""" // // This file is auto-generated, please don't edit! // -#define LOG_TAG "org.opencv.%(m)s" +#define LOG_TAG "org.opencv.$m" #include "common.h" -#include "opencv2/%(m)s.hpp" + +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_$M + +#include + +#include "opencv2/$m.hpp" using namespace cv; +/// throw java exception +static void throwJavaException(JNIEnv *env, const std::exception *e, const char *method) { + std::string what = "unknown exception"; + jclass je = 0; + + if(e) { + std::string exception_type = "std::exception"; + + if(dynamic_cast(e)) { + exception_type = "cv::Exception"; + je = env->FindClass("org/opencv/core/CvException"); + } + + what = exception_type + ": " + e->what(); + } + + if(!je) je = env->FindClass("java/lang/Exception"); + env->ThrowNew(je, what.c_str()); + + LOGE("%s caught %s", method, what.c_str()); + (void)method; // avoid "unused" warning +} + + extern "C" { -""" % {'m' : module} ) +""").substitute( m = module, M = module.upper() ) ) # generate code for the classes for name in self.classes.keys(): @@ -927,7 +1005,7 @@ extern "C" { java_code = Template(java_code).substitute(imports = imports) self.save("%s/%s+%s.java" % (output_path, module, self.classes[name].jname), java_code) - self.cpp_code.write( '\n} // extern "C"\n' ) + self.cpp_code.write( '\n} // extern "C"\n\n#endif // HAVE_OPENCV_%s\n' % module.upper() ) self.save(output_path+"/"+module+".cpp", self.cpp_code.getvalue()) # report @@ -1293,23 +1371,18 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname ($argst); JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname ($args) { + static const char method_name[] = "$module::$fname()"; try { - LOGD("$module::$fname()"); + LOGD("%s", method_name); $prologue $retval$cvname( $cvargs ); $epilogue$ret - } catch(cv::Exception e) { - LOGD("$module::$fname() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - $default + } catch(const std::exception &e) { + throwJavaException(env, &e, method_name); } catch (...) { - LOGD("$module::$fname() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {$module::$fname()}"); - $default + throwJavaException(env, 0, method_name); } + $default } @@ -1442,4 +1515,3 @@ if __name__ == "__main__": #print "Generating module '" + module + "' from headers:\n\t" + "\n\t".join(srcfiles) generator = JavaWrapperGenerator() generator.gen(srcfiles, module, dstdir) - diff --git a/modules/java/generator/src/cpp/VideoCapture.cpp b/modules/java/generator/src/cpp/VideoCapture.cpp deleted file mode 100644 index 312d710202..0000000000 --- a/modules/java/generator/src/cpp/VideoCapture.cpp +++ /dev/null @@ -1,434 +0,0 @@ -#define LOG_TAG "org.opencv.highgui.VideoCapture" -#include "common.h" - -#include "opencv2/opencv_modules.hpp" -#ifdef HAVE_OPENCV_HIGHGUI - -#include "opencv2/highgui.hpp" -using namespace cv; - - -extern "C" { - -// -// VideoCapture::VideoCapture() -// - -JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__ - (JNIEnv* env, jclass); - -JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__ - (JNIEnv* env, jclass) -{ - try { - LOGD("highgui::VideoCapture_n_1VideoCapture__()"); - - VideoCapture* _retval_ = new VideoCapture( ); - - return (jlong) _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1VideoCapture__() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1VideoCapture__() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}"); - return 0; - } -} - - -// -// VideoCapture::VideoCapture(int device) -// - -JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I - (JNIEnv* env, jclass, jint device); - -JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I - (JNIEnv* env, jclass, jint device) -{ - try { - LOGD("highgui::VideoCapture_n_1VideoCapture__I()"); - - VideoCapture* _retval_ = new VideoCapture( device ); - - return (jlong) _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__I()}"); - return 0; - } -} - - - -// -// double VideoCapture::get(int propId) -// - -JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get - (JNIEnv* env, jclass, jlong self, jint propId); - -JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get - (JNIEnv* env, jclass, jlong self, jint propId) -{ - try { - LOGD("highgui::VideoCapture_n_1get()"); - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - double _retval_ = me->get( propId ); - - return _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1get() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1get() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1get()}"); - return 0; - } -} - - - -// -// bool VideoCapture::grab() -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab - (JNIEnv* env, jclass, jlong self); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab - (JNIEnv* env, jclass, jlong self) -{ - try { - LOGD("highgui::VideoCapture_n_1grab()"); - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - bool _retval_ = me->grab( ); - - return _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1grab() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1grab() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1grab()}"); - return 0; - } -} - - - -// -// bool VideoCapture::isOpened() -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened - (JNIEnv* env, jclass, jlong self); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened - (JNIEnv* env, jclass, jlong self) -{ - try { - LOGD("highgui::VideoCapture_n_1isOpened()"); - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - bool _retval_ = me->isOpened( ); - - return _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1isOpened() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1isOpened() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1isOpened()}"); - return 0; - } -} - - -// -// bool VideoCapture::open(int device) -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI - (JNIEnv* env, jclass, jlong self, jint device); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI - (JNIEnv* env, jclass, jlong self, jint device) -{ - try { - LOGD("highgui::VideoCapture_n_1open__JI()"); - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - bool _retval_ = me->open( device ); - - return _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1open__JI() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1open__JI() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1open__JI()}"); - return 0; - } -} - - - -// -// bool VideoCapture::read(Mat image) -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj) -{ - try { - LOGD("highgui::VideoCapture_n_1read()"); - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - Mat& image = *((Mat*)image_nativeObj); - bool _retval_ = me->read( image ); - - return _retval_; - } catch(cv::Exception e) { - LOGD("highgui::VideoCapture_n_1read() catched cv::Exception: %s", e.what()); - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - LOGD("highgui::VideoCapture_n_1read() catched unknown exception (...)"); - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1read()}"); - return 0; - } -} - - - -// -// void VideoCapture::release() -// - -JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release - (JNIEnv* env, jclass, jlong self); - -JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release - (JNIEnv* env, jclass, jlong self) -{ - try { - - LOGD("highgui::VideoCapture_n_1release()"); - - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - me->release( ); - - return; - } catch(cv::Exception e) { - - LOGD("highgui::VideoCapture_n_1release() catched cv::Exception: %s", e.what()); - - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return; - } catch (...) { - - LOGD("highgui::VideoCapture_n_1release() catched unknown exception (...)"); - - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1release()}"); - return; - } -} - - - -// -// bool VideoCapture::retrieve(Mat image, int channel = 0) -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel) -{ - try { - - LOGD("highgui::VideoCapture_n_1retrieve__JJI()"); - - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - Mat& image = *((Mat*)image_nativeObj); - bool _retval_ = me->retrieve( image, channel ); - - return _retval_; - } catch(cv::Exception e) { - - LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched cv::Exception: %s", e.what()); - - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - - LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched unknown exception (...)"); - - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJI()}"); - return 0; - } -} - - - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ - (JNIEnv* env, jclass, jlong self, jlong image_nativeObj) -{ - try { - - LOGD("highgui::VideoCapture_n_1retrieve__JJ()"); - - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - Mat& image = *((Mat*)image_nativeObj); - bool _retval_ = me->retrieve( image ); - - return _retval_; - } catch(cv::Exception e) { - - LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched cv::Exception: %s", e.what()); - - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - - LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched unknown exception (...)"); - - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJ()}"); - return 0; - } -} - - - -// -// bool VideoCapture::set(int propId, double value) -// - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set - (JNIEnv* env, jclass, jlong self, jint propId, jdouble value); - -JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set - (JNIEnv* env, jclass, jlong self, jint propId, jdouble value) -{ - try { - - LOGD("highgui::VideoCapture_n_1set()"); - - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - bool _retval_ = me->set( propId, value ); - - return _retval_; - } catch(cv::Exception e) { - - LOGD("highgui::VideoCapture_n_1set() catched cv::Exception: %s", e.what()); - - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return 0; - } catch (...) { - - LOGD("highgui::VideoCapture_n_1set() catched unknown exception (...)"); - - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1set()}"); - return 0; - } -} - -JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes - (JNIEnv *env, jclass, jlong self); - -JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes - (JNIEnv *env, jclass, jlong self) -{ - try { - - LOGD("highgui::VideoCapture_n_1set()"); - - VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL - union {double prop; const char* name;} u; - u.prop = me->get(CAP_PROP_ANDROID_PREVIEW_SIZES_STRING); - return env->NewStringUTF(u.name); - } catch(cv::Exception e) { - - LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched cv::Exception: %s", e.what()); - - jclass je = env->FindClass("org/opencv/core/CvException"); - if(!je) je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, e.what()); - return env->NewStringUTF(""); - } catch (...) { - - LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched unknown exception (...)"); - - jclass je = env->FindClass("java/lang/Exception"); - env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1getSupportedPreviewSizes()}"); - return env->NewStringUTF(""); - } -} - - - -// -// native support for java finalize() -// static void VideoCapture::n_delete( __int64 self ) -// - -JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete - (JNIEnv*, jclass, jlong self); - -JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete - (JNIEnv*, jclass, jlong self) -{ - delete (VideoCapture*) self; -} - -} // extern "C" - -#endif // HAVE_OPENCV_HIGHGUI diff --git a/modules/java/generator/src/java/highgui+VideoCapture.java b/modules/java/generator/src/java/highgui+VideoCapture.java deleted file mode 100644 index 6f3b03540d..0000000000 --- a/modules/java/generator/src/java/highgui+VideoCapture.java +++ /dev/null @@ -1,240 +0,0 @@ -package org.opencv.highgui; - -import java.util.List; -import java.util.LinkedList; - -import org.opencv.core.Mat; -import org.opencv.core.Size; - -// C++: class VideoCapture -//javadoc: VideoCapture -public class VideoCapture { - - protected final long nativeObj; - - protected VideoCapture(long addr) { - nativeObj = addr; - } - - // - // C++: VideoCapture::VideoCapture() - // - - // javadoc: VideoCapture::VideoCapture() - public VideoCapture() - { - - nativeObj = n_VideoCapture(); - - return; - } - - // - // C++: VideoCapture::VideoCapture(int device) - // - - // javadoc: VideoCapture::VideoCapture(device) - public VideoCapture(int device) - { - - nativeObj = n_VideoCapture(device); - - return; - } - - // - // C++: double VideoCapture::get(int propId) - // - -/** - * Returns the specified "VideoCapture" property. - * - * Note: When querying a property that is not supported by the backend used by - * the "VideoCapture" class, value 0 is returned. - * - * @param propId property identifier; it can be one of the following: - * * CV_CAP_PROP_FRAME_WIDTH width of the frames in the video stream. - * * CV_CAP_PROP_FRAME_HEIGHT height of the frames in the video stream. - * - * @see org.opencv.highgui.VideoCapture.get - */ - public double get(int propId) - { - - double retVal = n_get(nativeObj, propId); - - return retVal; - } - - public List getSupportedPreviewSizes() - { - String[] sizes_str = n_getSupportedPreviewSizes(nativeObj).split(","); - List sizes = new LinkedList(); - - for (String str : sizes_str) { - String[] wh = str.split("x"); - sizes.add(new Size(Double.parseDouble(wh[0]), Double.parseDouble(wh[1]))); - } - - return sizes; - } - - // - // C++: bool VideoCapture::grab() - // - - // javadoc: VideoCapture::grab() - public boolean grab() - { - - boolean retVal = n_grab(nativeObj); - - return retVal; - } - - // - // C++: bool VideoCapture::isOpened() - // - - // javadoc: VideoCapture::isOpened() - public boolean isOpened() - { - - boolean retVal = n_isOpened(nativeObj); - - return retVal; - } - - // - // C++: bool VideoCapture::open(int device) - // - - // javadoc: VideoCapture::open(device) - public boolean open(int device) - { - - boolean retVal = n_open(nativeObj, device); - - return retVal; - } - - // - // C++: bool VideoCapture::read(Mat image) - // - - // javadoc: VideoCapture::read(image) - public boolean read(Mat image) - { - - boolean retVal = n_read(nativeObj, image.nativeObj); - - return retVal; - } - - // - // C++: void VideoCapture::release() - // - - // javadoc: VideoCapture::release() - public void release() - { - - n_release(nativeObj); - - return; - } - - // - // C++: bool VideoCapture::retrieve(Mat image, int channel = 0) - // - - // javadoc: VideoCapture::retrieve(image, channel) - public boolean retrieve(Mat image, int channel) - { - - boolean retVal = n_retrieve(nativeObj, image.nativeObj, channel); - - return retVal; - } - - // javadoc: VideoCapture::retrieve(image) - public boolean retrieve(Mat image) - { - - boolean retVal = n_retrieve(nativeObj, image.nativeObj); - - return retVal; - } - - // - // C++: bool VideoCapture::set(int propId, double value) - // - -/** - * Sets a property in the "VideoCapture". - * - * @param propId property identifier; it can be one of the following: - * * CV_CAP_PROP_FRAME_WIDTH width of the frames in the video stream. - * * CV_CAP_PROP_FRAME_HEIGHT height of the frames in the video stream. - * @param value value of the property. - * - * @see org.opencv.highgui.VideoCapture.set - */ - public boolean set(int propId, double value) - { - - boolean retVal = n_set(nativeObj, propId, value); - - return retVal; - } - - @Override - protected void finalize() throws Throwable { - n_delete(nativeObj); - super.finalize(); - } - - // C++: VideoCapture::VideoCapture() - private static native long n_VideoCapture(); - - // C++: VideoCapture::VideoCapture(string filename) - private static native long n_VideoCapture(java.lang.String filename); - - // C++: VideoCapture::VideoCapture(int device) - private static native long n_VideoCapture(int device); - - // C++: double VideoCapture::get(int propId) - private static native double n_get(long nativeObj, int propId); - - // C++: bool VideoCapture::grab() - private static native boolean n_grab(long nativeObj); - - // C++: bool VideoCapture::isOpened() - private static native boolean n_isOpened(long nativeObj); - - // C++: bool VideoCapture::open(string filename) - private static native boolean n_open(long nativeObj, java.lang.String filename); - - // C++: bool VideoCapture::open(int device) - private static native boolean n_open(long nativeObj, int device); - - // C++: bool VideoCapture::read(Mat image) - private static native boolean n_read(long nativeObj, long image_nativeObj); - - // C++: void VideoCapture::release() - private static native void n_release(long nativeObj); - - // C++: bool VideoCapture::retrieve(Mat image, int channel = 0) - private static native boolean n_retrieve(long nativeObj, long image_nativeObj, int channel); - - private static native boolean n_retrieve(long nativeObj, long image_nativeObj); - - // C++: bool VideoCapture::set(int propId, double value) - private static native boolean n_set(long nativeObj, int propId, double value); - - private static native String n_getSupportedPreviewSizes(long nativeObj); - - // native support for java finalize() - private static native void n_delete(long nativeObj); - -} diff --git a/modules/java/test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java index fd29096649..496f96242b 100644 --- a/modules/java/test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java @@ -97,7 +97,7 @@ public class OpenCVTestCase extends TestCase { super.setUp(); try { - System.loadLibrary("opencv_java"); + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (SecurityException e) { System.out.println(e.toString()); System.exit(-1); diff --git a/modules/legacy/src/precomp.cpp b/modules/legacy/src/precomp.cpp deleted file mode 100644 index a9477b85ba..0000000000 --- a/modules/legacy/src/precomp.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" diff --git a/modules/legacy/test/test_precomp.cpp b/modules/legacy/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/legacy/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/ml/src/precomp.cpp b/modules/ml/src/precomp.cpp deleted file mode 100644 index e540cc5e8a..0000000000 --- a/modules/ml/src/precomp.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/ml/test/test_precomp.cpp b/modules/ml/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/ml/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/nonfree/perf/perf_precomp.cpp b/modules/nonfree/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/nonfree/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/nonfree/src/opencl/surf.cl b/modules/nonfree/src/opencl/surf.cl index 1975713654..aace143d53 100644 --- a/modules/nonfree/src/opencl/surf.cl +++ b/modules/nonfree/src/opencl/surf.cl @@ -16,6 +16,7 @@ // // @Authors // Peng Xiao, pengxiao@multicorewareinc.com +// Sen Liu, swjtuls1987@126.com // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: @@ -43,9 +44,6 @@ // //M*/ -#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable -#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable - // specialized for non-image2d_t supported platform, intel HD4000, for example #ifdef DISABLE_IMAGE2D #define IMAGE_INT32 __global uint * @@ -105,7 +103,7 @@ __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAM // for simple haar paatern float icvCalcHaarPatternSum_2( IMAGE_INT32 sumTex, - __constant float src[2][5], + __constant float2 *src, int oldSize, int newSize, int y, int x, @@ -116,21 +114,24 @@ float icvCalcHaarPatternSum_2( F d = 0; -#pragma unroll - for (int k = 0; k < 2; ++k) - { - int dx1 = convert_int_rte(ratio * src[k][0]); - int dy1 = convert_int_rte(ratio * src[k][1]); - int dx2 = convert_int_rte(ratio * src[k][2]); - int dy2 = convert_int_rte(ratio * src[k][3]); - - F t = 0; - t += read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy1), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy2), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy1), rows, cols, elemPerRow ); - t += read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy2), rows, cols, elemPerRow ); - d += t * src[k][4] / ((dx2 - dx1) * (dy2 - dy1)); - } + int2 dx1 = convert_int2_rte(ratio * src[0]); + int2 dy1 = convert_int2_rte(ratio * src[1]); + int2 dx2 = convert_int2_rte(ratio * src[2]); + int2 dy2 = convert_int2_rte(ratio * src[3]); + + F t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy1.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy2.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy1.x), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy2.x), rows, cols, elemPerRow ); + d += t * src[4].x / ((dx2.x - dx1.x) * (dy2.x - dy1.x)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy1.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy2.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy1.y), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy2.y), rows, cols, elemPerRow ); + d += t * src[4].y / ((dx2.y - dx1.y) * (dy2.y - dy1.y)); return (float)d; } @@ -138,7 +139,7 @@ float icvCalcHaarPatternSum_2( // N = 3 float icvCalcHaarPatternSum_3( IMAGE_INT32 sumTex, - __constant float src[2][5], + __constant float4 *src, int oldSize, int newSize, int y, int x, @@ -149,21 +150,31 @@ float icvCalcHaarPatternSum_3( F d = 0; -#pragma unroll - for (int k = 0; k < 3; ++k) - { - int dx1 = convert_int_rte(ratio * src[k][0]); - int dy1 = convert_int_rte(ratio * src[k][1]); - int dx2 = convert_int_rte(ratio * src[k][2]); - int dy2 = convert_int_rte(ratio * src[k][3]); - - F t = 0; - t += read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy1), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy2), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy1), rows, cols, elemPerRow ); - t += read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy2), rows, cols, elemPerRow ); - d += t * src[k][4] / ((dx2 - dx1) * (dy2 - dy1)); - } + int4 dx1 = convert_int4_rte(ratio * src[0]); + int4 dy1 = convert_int4_rte(ratio * src[1]); + int4 dx2 = convert_int4_rte(ratio * src[2]); + int4 dy2 = convert_int4_rte(ratio * src[3]); + + F t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy1.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy2.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy1.x), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy2.x), rows, cols, elemPerRow ); + d += t * src[4].x / ((dx2.x - dx1.x) * (dy2.x - dy1.x)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy1.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy2.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy1.y), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy2.y), rows, cols, elemPerRow ); + d += t * src[4].y / ((dx2.y - dx1.y) * (dy2.y - dy1.y)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.z, y + dy1.z), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.z, y + dy2.z), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.z, y + dy1.z), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.z, y + dy2.z), rows, cols, elemPerRow ); + d += t * src[4].z / ((dx2.z - dx1.z) * (dy2.z - dy1.z)); return (float)d; } @@ -171,7 +182,7 @@ float icvCalcHaarPatternSum_3( // N = 4 float icvCalcHaarPatternSum_4( IMAGE_INT32 sumTex, - __constant float src[2][5], + __constant float4 *src, int oldSize, int newSize, int y, int x, @@ -182,21 +193,38 @@ float icvCalcHaarPatternSum_4( F d = 0; -#pragma unroll - for (int k = 0; k < 4; ++k) - { - int dx1 = convert_int_rte(ratio * src[k][0]); - int dy1 = convert_int_rte(ratio * src[k][1]); - int dx2 = convert_int_rte(ratio * src[k][2]); - int dy2 = convert_int_rte(ratio * src[k][3]); - - F t = 0; - t += read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy1), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx1, y + dy2), rows, cols, elemPerRow ); - t -= read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy1), rows, cols, elemPerRow ); - t += read_sumTex( sumTex, sampler, (int2)(x + dx2, y + dy2), rows, cols, elemPerRow ); - d += t * src[k][4] / ((dx2 - dx1) * (dy2 - dy1)); - } + int4 dx1 = convert_int4_rte(ratio * src[0]); + int4 dy1 = convert_int4_rte(ratio * src[1]); + int4 dx2 = convert_int4_rte(ratio * src[2]); + int4 dy2 = convert_int4_rte(ratio * src[3]); + + F t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy1.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.x, y + dy2.x), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy1.x), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.x, y + dy2.x), rows, cols, elemPerRow ); + d += t * src[4].x / ((dx2.x - dx1.x) * (dy2.x - dy1.x)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy1.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.y, y + dy2.y), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy1.y), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.y, y + dy2.y), rows, cols, elemPerRow ); + d += t * src[4].y / ((dx2.y - dx1.y) * (dy2.y - dy1.y)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.z, y + dy1.z), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.z, y + dy2.z), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.z, y + dy1.z), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.z, y + dy2.z), rows, cols, elemPerRow ); + d += t * src[4].z / ((dx2.z - dx1.z) * (dy2.z - dy1.z)); + + t = 0; + t += read_sumTex( sumTex, sampler, (int2)(x + dx1.w, y + dy1.w), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx1.w, y + dy2.w), rows, cols, elemPerRow ); + t -= read_sumTex( sumTex, sampler, (int2)(x + dx2.w, y + dy1.w), rows, cols, elemPerRow ); + t += read_sumTex( sumTex, sampler, (int2)(x + dx2.w, y + dy2.w), rows, cols, elemPerRow ); + d += t * src[4].w / ((dx2.w - dx1.w) * (dy2.w - dy1.w)); return (float)d; } @@ -204,9 +232,9 @@ float icvCalcHaarPatternSum_4( //////////////////////////////////////////////////////////////////////// // Hessian -__constant float c_DX [3][5] = { {0, 2, 3, 7, 1}, {3, 2, 6, 7, -2}, {6, 2, 9, 7, 1} }; -__constant float c_DY [3][5] = { {2, 0, 7, 3, 1}, {2, 3, 7, 6, -2}, {2, 6, 7, 9, 1} }; -__constant float c_DXY[4][5] = { {1, 1, 4, 4, 1}, {5, 1, 8, 4, -1}, {1, 5, 4, 8, -1}, {5, 5, 8, 8, 1} }; +__constant float4 c_DX[5] = { (float4)(0, 3, 6, 0), (float4)(2, 2, 2, 0), (float4)(3, 6, 9, 0), (float4)(7, 7, 7, 0), (float4)(1, -2, 1, 0) }; +__constant float4 c_DY[5] = { (float4)(2, 2, 2, 0), (float4)(0, 3, 6, 0), (float4)(7, 7, 7, 0), (float4)(3, 6, 9, 0), (float4)(1, -2, 1, 0) }; +__constant float4 c_DXY[5] = { (float4)(1, 5, 1, 5), (float4)(1, 1, 5, 5), (float4)(4, 8, 4, 8), (float4)(4, 4, 8, 8), (float4)(1, -1, -1, 1) };// Use integral image to calculate haar wavelets. __inline int calcSize(int octave, int layer) { @@ -236,7 +264,7 @@ __kernel void icvCalcLayerDetAndTrace( int c_octave, int c_layer_rows, int sumTex_step - ) +) { det_step /= sizeof(*det); trace_step /= sizeof(*trace); @@ -300,7 +328,7 @@ bool within_check(IMAGE_INT32 maskSumTex, int sum_i, int sum_j, int size, int ro // Non-maximal suppression to further filtering the candidates from previous step __kernel - void icvFindMaximaInLayer_withmask( +void icvFindMaximaInLayer_withmask( __global const float * det, __global const float * trace, __global int4 * maxPosBuffer, @@ -318,7 +346,7 @@ __kernel float c_hessianThreshold, IMAGE_INT32 maskSumTex, int mask_step - ) +) { volatile __local float N9[768]; // threads.x * threads.y * 3 @@ -347,26 +375,26 @@ __kernel const int localLin = get_local_id(0) + get_local_id(1) * get_local_size(0) + zoff; N9[localLin - zoff] = det[det_step * - (c_layer_rows * (layer - 1) + min(max(i, 0), c_img_rows - 1)) // y - + min(max(j, 0), c_img_cols - 1)]; // x + (c_layer_rows * (layer - 1) + min(max(i, 0), c_img_rows - 1)) // y + + min(max(j, 0), c_img_cols - 1)]; // x N9[localLin ] = det[det_step * - (c_layer_rows * (layer ) + min(max(i, 0), c_img_rows - 1)) // y - + min(max(j, 0), c_img_cols - 1)]; // x + (c_layer_rows * (layer ) + min(max(i, 0), c_img_rows - 1)) // y + + min(max(j, 0), c_img_cols - 1)]; // x N9[localLin + zoff] = det[det_step * - (c_layer_rows * (layer + 1) + min(max(i, 0), c_img_rows - 1)) // y - + min(max(j, 0), c_img_cols - 1)]; // x + (c_layer_rows * (layer + 1) + min(max(i, 0), c_img_rows - 1)) // y + + min(max(j, 0), c_img_cols - 1)]; // x barrier(CLK_LOCAL_MEM_FENCE); if (i < c_layer_rows - margin - && j < c_layer_cols - margin - && get_local_id(0) > 0 - && get_local_id(0) < get_local_size(0) - 1 - && get_local_id(1) > 0 - && get_local_id(1) < get_local_size(1) - 1 // these are unnecessary conditions ported from CUDA - ) + && j < c_layer_cols - margin + && get_local_id(0) > 0 + && get_local_id(0) < get_local_size(0) - 1 + && get_local_id(1) > 0 + && get_local_id(1) < get_local_size(1) - 1 // these are unnecessary conditions ported from CUDA + ) { float val0 = N9[localLin]; @@ -382,34 +410,34 @@ __kernel { // Check to see if we have a max (in its 26 neighbours) const bool condmax = val0 > N9[localLin - 1 - get_local_size(0) - zoff] - && val0 > N9[localLin - get_local_size(0) - zoff] - && val0 > N9[localLin + 1 - get_local_size(0) - zoff] - && val0 > N9[localLin - 1 - zoff] - && val0 > N9[localLin - zoff] - && val0 > N9[localLin + 1 - zoff] - && val0 > N9[localLin - 1 + get_local_size(0) - zoff] - && val0 > N9[localLin + get_local_size(0) - zoff] - && val0 > N9[localLin + 1 + get_local_size(0) - zoff] - - && val0 > N9[localLin - 1 - get_local_size(0)] - && val0 > N9[localLin - get_local_size(0)] - && val0 > N9[localLin + 1 - get_local_size(0)] - && val0 > N9[localLin - 1 ] - && val0 > N9[localLin + 1 ] - && val0 > N9[localLin - 1 + get_local_size(0)] - && val0 > N9[localLin + get_local_size(0)] - && val0 > N9[localLin + 1 + get_local_size(0)] - - && val0 > N9[localLin - 1 - get_local_size(0) + zoff] - && val0 > N9[localLin - get_local_size(0) + zoff] - && val0 > N9[localLin + 1 - get_local_size(0) + zoff] - && val0 > N9[localLin - 1 + zoff] - && val0 > N9[localLin + zoff] - && val0 > N9[localLin + 1 + zoff] - && val0 > N9[localLin - 1 + get_local_size(0) + zoff] - && val0 > N9[localLin + get_local_size(0) + zoff] - && val0 > N9[localLin + 1 + get_local_size(0) + zoff] - ; + && val0 > N9[localLin - get_local_size(0) - zoff] + && val0 > N9[localLin + 1 - get_local_size(0) - zoff] + && val0 > N9[localLin - 1 - zoff] + && val0 > N9[localLin - zoff] + && val0 > N9[localLin + 1 - zoff] + && val0 > N9[localLin - 1 + get_local_size(0) - zoff] + && val0 > N9[localLin + get_local_size(0) - zoff] + && val0 > N9[localLin + 1 + get_local_size(0) - zoff] + + && val0 > N9[localLin - 1 - get_local_size(0)] + && val0 > N9[localLin - get_local_size(0)] + && val0 > N9[localLin + 1 - get_local_size(0)] + && val0 > N9[localLin - 1 ] + && val0 > N9[localLin + 1 ] + && val0 > N9[localLin - 1 + get_local_size(0)] + && val0 > N9[localLin + get_local_size(0)] + && val0 > N9[localLin + 1 + get_local_size(0)] + + && val0 > N9[localLin - 1 - get_local_size(0) + zoff] + && val0 > N9[localLin - get_local_size(0) + zoff] + && val0 > N9[localLin + 1 - get_local_size(0) + zoff] + && val0 > N9[localLin - 1 + zoff] + && val0 > N9[localLin + zoff] + && val0 > N9[localLin + 1 + zoff] + && val0 > N9[localLin - 1 + get_local_size(0) + zoff] + && val0 > N9[localLin + get_local_size(0) + zoff] + && val0 > N9[localLin + 1 + get_local_size(0) + zoff] + ; if(condmax) { @@ -428,7 +456,7 @@ __kernel } __kernel - void icvFindMaximaInLayer( +void icvFindMaximaInLayer( __global float * det, __global float * trace, __global int4 * maxPosBuffer, @@ -444,7 +472,7 @@ __kernel int c_layer_cols, int c_max_candidates, float c_hessianThreshold - ) +) { volatile __local float N9[768]; // threads.x * threads.y * 3 @@ -483,12 +511,12 @@ __kernel barrier(CLK_LOCAL_MEM_FENCE); if (i < c_layer_rows - margin - && j < c_layer_cols - margin - && get_local_id(0) > 0 - && get_local_id(0) < get_local_size(0) - 1 - && get_local_id(1) > 0 - && get_local_id(1) < get_local_size(1) - 1 // these are unnecessary conditions ported from CUDA - ) + && j < c_layer_cols - margin + && get_local_id(0) > 0 + && get_local_id(0) < get_local_size(0) - 1 + && get_local_id(1) > 0 + && get_local_id(1) < get_local_size(1) - 1 // these are unnecessary conditions ported from CUDA + ) { float val0 = N9[localLin]; if (val0 > c_hessianThreshold) @@ -499,38 +527,38 @@ __kernel // Check to see if we have a max (in its 26 neighbours) const bool condmax = val0 > N9[localLin - 1 - get_local_size(0) - zoff] - && val0 > N9[localLin - get_local_size(0) - zoff] - && val0 > N9[localLin + 1 - get_local_size(0) - zoff] - && val0 > N9[localLin - 1 - zoff] - && val0 > N9[localLin - zoff] - && val0 > N9[localLin + 1 - zoff] - && val0 > N9[localLin - 1 + get_local_size(0) - zoff] - && val0 > N9[localLin + get_local_size(0) - zoff] - && val0 > N9[localLin + 1 + get_local_size(0) - zoff] - - && val0 > N9[localLin - 1 - get_local_size(0)] - && val0 > N9[localLin - get_local_size(0)] - && val0 > N9[localLin + 1 - get_local_size(0)] - && val0 > N9[localLin - 1 ] - && val0 > N9[localLin + 1 ] - && val0 > N9[localLin - 1 + get_local_size(0)] - && val0 > N9[localLin + get_local_size(0)] - && val0 > N9[localLin + 1 + get_local_size(0)] - - && val0 > N9[localLin - 1 - get_local_size(0) + zoff] - && val0 > N9[localLin - get_local_size(0) + zoff] - && val0 > N9[localLin + 1 - get_local_size(0) + zoff] - && val0 > N9[localLin - 1 + zoff] - && val0 > N9[localLin + zoff] - && val0 > N9[localLin + 1 + zoff] - && val0 > N9[localLin - 1 + get_local_size(0) + zoff] - && val0 > N9[localLin + get_local_size(0) + zoff] - && val0 > N9[localLin + 1 + get_local_size(0) + zoff] - ; + && val0 > N9[localLin - get_local_size(0) - zoff] + && val0 > N9[localLin + 1 - get_local_size(0) - zoff] + && val0 > N9[localLin - 1 - zoff] + && val0 > N9[localLin - zoff] + && val0 > N9[localLin + 1 - zoff] + && val0 > N9[localLin - 1 + get_local_size(0) - zoff] + && val0 > N9[localLin + get_local_size(0) - zoff] + && val0 > N9[localLin + 1 + get_local_size(0) - zoff] + + && val0 > N9[localLin - 1 - get_local_size(0)] + && val0 > N9[localLin - get_local_size(0)] + && val0 > N9[localLin + 1 - get_local_size(0)] + && val0 > N9[localLin - 1 ] + && val0 > N9[localLin + 1 ] + && val0 > N9[localLin - 1 + get_local_size(0)] + && val0 > N9[localLin + get_local_size(0)] + && val0 > N9[localLin + 1 + get_local_size(0)] + + && val0 > N9[localLin - 1 - get_local_size(0) + zoff] + && val0 > N9[localLin - get_local_size(0) + zoff] + && val0 > N9[localLin + 1 - get_local_size(0) + zoff] + && val0 > N9[localLin - 1 + zoff] + && val0 > N9[localLin + zoff] + && val0 > N9[localLin + 1 + zoff] + && val0 > N9[localLin - 1 + get_local_size(0) + zoff] + && val0 > N9[localLin + get_local_size(0) + zoff] + && val0 > N9[localLin + 1 + get_local_size(0) + zoff] + ; if(condmax) { - int ind = atomic_inc(maxCounter); + int ind = atomic_inc(maxCounter); if (ind < c_max_candidates) { @@ -544,30 +572,30 @@ __kernel } // solve 3x3 linear system Ax=b for floating point input -inline bool solve3x3_float(volatile __local const float A[3][3], volatile __local const float b[3], volatile __local float x[3]) +inline bool solve3x3_float(volatile __local const float4 *A, volatile __local const float *b, volatile __local float *x) { - float det = A[0][0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) - - A[0][1] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) - + A[0][2] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]); + float det = A[0].x * (A[1].y * A[2].z - A[1].z * A[2].y) + - A[0].y * (A[1].x * A[2].z - A[1].z * A[2].x) + + A[0].z * (A[1].x * A[2].y - A[1].y * A[2].x); if (det != 0) { F invdet = 1.0 / det; x[0] = invdet * - (b[0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) - - A[0][1] * (b[1] * A[2][2] - A[1][2] * b[2] ) + - A[0][2] * (b[1] * A[2][1] - A[1][1] * b[2] )); + (b[0] * (A[1].y * A[2].z - A[1].z * A[2].y) - + A[0].y * (b[1] * A[2].z - A[1].z * b[2] ) + + A[0].z * (b[1] * A[2].y - A[1].y * b[2] )); x[1] = invdet * - (A[0][0] * (b[1] * A[2][2] - A[1][2] * b[2] ) - - b[0] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + - A[0][2] * (A[1][0] * b[2] - b[1] * A[2][0])); + (A[0].x * (b[1] * A[2].z - A[1].z * b[2] ) - + b[0] * (A[1].x * A[2].z - A[1].z * A[2].x) + + A[0].z * (A[1].x * b[2] - b[1] * A[2].x)); x[2] = invdet * - (A[0][0] * (A[1][1] * b[2] - b[1] * A[2][1]) - - A[0][1] * (A[1][0] * b[2] - b[1] * A[2][0]) + - b[0] * (A[1][0] * A[2][1] - A[1][1] * A[2][0])); + (A[0].x * (A[1].y * b[2] - b[1] * A[2].y) - + A[0].y * (A[1].x * b[2] - b[1] * A[2].x) + + b[0] * (A[1].x * A[2].y - A[1].y * A[2].x)); return true; } @@ -586,7 +614,7 @@ inline bool solve3x3_float(volatile __local const float A[3][3], volatile __loc //////////////////////////////////////////////////////////////////////// // INTERPOLATION __kernel - void icvInterpolateKeypoint( +void icvInterpolateKeypoint( __global const float * det, __global const int4 * maxPosBuffer, __global float * keypoints, @@ -598,7 +626,7 @@ __kernel int c_octave, int c_layer_rows, int c_max_features - ) +) { det_step /= sizeof(*det); keypoints_step /= sizeof(*keypoints); @@ -632,26 +660,26 @@ __kernel //ds dD[2] = -0.5f * (N9[2][1][1] - N9[0][1][1]); - volatile __local float H[3][3]; + volatile __local float4 H[3]; //dxx - H[0][0] = N9[1][1][0] - 2.0f * N9[1][1][1] + N9[1][1][2]; + H[0].x = N9[1][1][0] - 2.0f * N9[1][1][1] + N9[1][1][2]; //dxy - H[0][1]= 0.25f * (N9[1][2][2] - N9[1][2][0] - N9[1][0][2] + N9[1][0][0]); + H[0].y= 0.25f * (N9[1][2][2] - N9[1][2][0] - N9[1][0][2] + N9[1][0][0]); //dxs - H[0][2]= 0.25f * (N9[2][1][2] - N9[2][1][0] - N9[0][1][2] + N9[0][1][0]); + H[0].z= 0.25f * (N9[2][1][2] - N9[2][1][0] - N9[0][1][2] + N9[0][1][0]); //dyx = dxy - H[1][0] = H[0][1]; + H[1].x = H[0].y; //dyy - H[1][1] = N9[1][0][1] - 2.0f * N9[1][1][1] + N9[1][2][1]; + H[1].y = N9[1][0][1] - 2.0f * N9[1][1][1] + N9[1][2][1]; //dys - H[1][2]= 0.25f * (N9[2][2][1] - N9[2][0][1] - N9[0][2][1] + N9[0][0][1]); + H[1].z= 0.25f * (N9[2][2][1] - N9[2][0][1] - N9[0][2][1] + N9[0][0][1]); //dsx = dxs - H[2][0] = H[0][2]; + H[2].x = H[0].z; //dsy = dys - H[2][1] = H[1][2]; + H[2].y = H[1].z; //dss - H[2][2] = N9[0][1][1] - 2.0f * N9[1][1][1] + N9[2][1][1]; + H[2].z = N9[0][1][1] - 2.0f * N9[1][1][1] + N9[2][1][1]; volatile __local float x[3]; @@ -689,7 +717,7 @@ __kernel if ((c_img_rows + 1) >= grad_wav_size && (c_img_cols + 1) >= grad_wav_size) { // Get a new feature index. - int ind = atomic_inc(featureCounter); + int ind = atomic_inc(featureCounter); if (ind < c_max_features) { @@ -716,31 +744,32 @@ __kernel __constant float c_aptX[ORI_SAMPLES] = {-6, -5, -5, -5, -5, -5, -5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6}; __constant float c_aptY[ORI_SAMPLES] = {0, -3, -2, -1, 0, 1, 2, 3, -4, -3, -2, -1, 0, 1, 2, 3, 4, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, -4, -3, -2, -1, 0, 1, 2, 3, 4, -3, -2, -1, 0, 1, 2, 3, 0}; __constant float c_aptW[ORI_SAMPLES] = {0.001455130288377404f, 0.001707611023448408f, 0.002547456417232752f, 0.003238451667129993f, 0.0035081731621176f, - 0.003238451667129993f, 0.002547456417232752f, 0.001707611023448408f, 0.002003900473937392f, 0.0035081731621176f, 0.005233579315245152f, - 0.00665318313986063f, 0.00720730796456337f, 0.00665318313986063f, 0.005233579315245152f, 0.0035081731621176f, - 0.002003900473937392f, 0.001707611023448408f, 0.0035081731621176f, 0.006141661666333675f, 0.009162282571196556f, - 0.01164754293859005f, 0.01261763460934162f, 0.01164754293859005f, 0.009162282571196556f, 0.006141661666333675f, - 0.0035081731621176f, 0.001707611023448408f, 0.002547456417232752f, 0.005233579315245152f, 0.009162282571196556f, - 0.01366852037608624f, 0.01737609319388866f, 0.0188232995569706f, 0.01737609319388866f, 0.01366852037608624f, - 0.009162282571196556f, 0.005233579315245152f, 0.002547456417232752f, 0.003238451667129993f, 0.00665318313986063f, - 0.01164754293859005f, 0.01737609319388866f, 0.02208934165537357f, 0.02392910048365593f, 0.02208934165537357f, - 0.01737609319388866f, 0.01164754293859005f, 0.00665318313986063f, 0.003238451667129993f, 0.001455130288377404f, - 0.0035081731621176f, 0.00720730796456337f, 0.01261763460934162f, 0.0188232995569706f, 0.02392910048365593f, - 0.02592208795249462f, 0.02392910048365593f, 0.0188232995569706f, 0.01261763460934162f, 0.00720730796456337f, - 0.0035081731621176f, 0.001455130288377404f, 0.003238451667129993f, 0.00665318313986063f, 0.01164754293859005f, - 0.01737609319388866f, 0.02208934165537357f, 0.02392910048365593f, 0.02208934165537357f, 0.01737609319388866f, - 0.01164754293859005f, 0.00665318313986063f, 0.003238451667129993f, 0.002547456417232752f, 0.005233579315245152f, - 0.009162282571196556f, 0.01366852037608624f, 0.01737609319388866f, 0.0188232995569706f, 0.01737609319388866f, - 0.01366852037608624f, 0.009162282571196556f, 0.005233579315245152f, 0.002547456417232752f, 0.001707611023448408f, - 0.0035081731621176f, 0.006141661666333675f, 0.009162282571196556f, 0.01164754293859005f, 0.01261763460934162f, - 0.01164754293859005f, 0.009162282571196556f, 0.006141661666333675f, 0.0035081731621176f, 0.001707611023448408f, - 0.002003900473937392f, 0.0035081731621176f, 0.005233579315245152f, 0.00665318313986063f, 0.00720730796456337f, - 0.00665318313986063f, 0.005233579315245152f, 0.0035081731621176f, 0.002003900473937392f, 0.001707611023448408f, - 0.002547456417232752f, 0.003238451667129993f, 0.0035081731621176f, 0.003238451667129993f, 0.002547456417232752f, - 0.001707611023448408f, 0.001455130288377404f}; - -__constant float c_NX[2][5] = {{0, 0, 2, 4, -1}, {2, 0, 4, 4, 1}}; -__constant float c_NY[2][5] = {{0, 0, 4, 2, 1}, {0, 2, 4, 4, -1}}; + 0.003238451667129993f, 0.002547456417232752f, 0.001707611023448408f, 0.002003900473937392f, 0.0035081731621176f, 0.005233579315245152f, + 0.00665318313986063f, 0.00720730796456337f, 0.00665318313986063f, 0.005233579315245152f, 0.0035081731621176f, + 0.002003900473937392f, 0.001707611023448408f, 0.0035081731621176f, 0.006141661666333675f, 0.009162282571196556f, + 0.01164754293859005f, 0.01261763460934162f, 0.01164754293859005f, 0.009162282571196556f, 0.006141661666333675f, + 0.0035081731621176f, 0.001707611023448408f, 0.002547456417232752f, 0.005233579315245152f, 0.009162282571196556f, + 0.01366852037608624f, 0.01737609319388866f, 0.0188232995569706f, 0.01737609319388866f, 0.01366852037608624f, + 0.009162282571196556f, 0.005233579315245152f, 0.002547456417232752f, 0.003238451667129993f, 0.00665318313986063f, + 0.01164754293859005f, 0.01737609319388866f, 0.02208934165537357f, 0.02392910048365593f, 0.02208934165537357f, + 0.01737609319388866f, 0.01164754293859005f, 0.00665318313986063f, 0.003238451667129993f, 0.001455130288377404f, + 0.0035081731621176f, 0.00720730796456337f, 0.01261763460934162f, 0.0188232995569706f, 0.02392910048365593f, + 0.02592208795249462f, 0.02392910048365593f, 0.0188232995569706f, 0.01261763460934162f, 0.00720730796456337f, + 0.0035081731621176f, 0.001455130288377404f, 0.003238451667129993f, 0.00665318313986063f, 0.01164754293859005f, + 0.01737609319388866f, 0.02208934165537357f, 0.02392910048365593f, 0.02208934165537357f, 0.01737609319388866f, + 0.01164754293859005f, 0.00665318313986063f, 0.003238451667129993f, 0.002547456417232752f, 0.005233579315245152f, + 0.009162282571196556f, 0.01366852037608624f, 0.01737609319388866f, 0.0188232995569706f, 0.01737609319388866f, + 0.01366852037608624f, 0.009162282571196556f, 0.005233579315245152f, 0.002547456417232752f, 0.001707611023448408f, + 0.0035081731621176f, 0.006141661666333675f, 0.009162282571196556f, 0.01164754293859005f, 0.01261763460934162f, + 0.01164754293859005f, 0.009162282571196556f, 0.006141661666333675f, 0.0035081731621176f, 0.001707611023448408f, + 0.002003900473937392f, 0.0035081731621176f, 0.005233579315245152f, 0.00665318313986063f, 0.00720730796456337f, + 0.00665318313986063f, 0.005233579315245152f, 0.0035081731621176f, 0.002003900473937392f, 0.001707611023448408f, + 0.002547456417232752f, 0.003238451667129993f, 0.0035081731621176f, 0.003238451667129993f, 0.002547456417232752f, + 0.001707611023448408f, 0.001455130288377404f + }; + +__constant float2 c_NX[5] = { (float2)(0, 2), (float2)(0, 0), (float2)(2, 4), (float2)(4, 4), (float2)(-1, 1) }; +__constant float2 c_NY[5] = { (float2)(0, 0), (float2)(0, 2), (float2)(4, 4), (float2)(2, 4), (float2)(1, -1) }; void reduce_32_sum(volatile __local float * data, volatile float* partial_reduction, int tid) { @@ -759,14 +788,14 @@ void reduce_32_sum(volatile __local float * data, volatile float* partial_reduc if (tid < 8) { #endif - data[tid] = *partial_reduction = op(partial_reduction, data[tid + 8 ]); + data[tid] = *partial_reduction = op(partial_reduction, data[tid + 8]); #if WAVE_SIZE < 8 } barrier(CLK_LOCAL_MEM_FENCE); if (tid < 4) { #endif - data[tid] = *partial_reduction = op(partial_reduction, data[tid + 4 ]); + data[tid] = *partial_reduction = op(partial_reduction, data[tid + 4]); #if WAVE_SIZE < 4 } barrier(CLK_LOCAL_MEM_FENCE); @@ -787,14 +816,14 @@ void reduce_32_sum(volatile __local float * data, volatile float* partial_reduc } __kernel - void icvCalcOrientation( +void icvCalcOrientation( IMAGE_INT32 sumTex, __global float * keypoints, int keypoints_step, int c_img_rows, int c_img_cols, int sum_step - ) +) { keypoints_step /= sizeof(*keypoints); sum_step /= sizeof(uint); @@ -838,7 +867,7 @@ __kernel const int y = convert_int_rte(featureY[get_group_id(0)] + c_aptY[tid] * s - margin); if (y >= 0 && y < (c_img_rows + 1) - grad_wav_size && - x >= 0 && x < (c_img_cols + 1) - grad_wav_size) + x >= 0 && x < (c_img_cols + 1) - grad_wav_size) { X = c_aptW[tid] * icvCalcHaarPatternSum_2(sumTex, c_NX, 4, grad_wav_size, y, x, c_img_rows, c_img_cols, sum_step); Y = c_aptW[tid] * icvCalcHaarPatternSum_2(sumTex, c_NY, 4, grad_wav_size, y, x, c_img_rows, c_img_cols, sum_step); @@ -934,11 +963,11 @@ __kernel __kernel - void icvSetUpright( +void icvSetUpright( __global float * keypoints, int keypoints_step, int nFeatures - ) +) { keypoints_step /= sizeof(*keypoints); __global float* featureDir = keypoints + ANGLE_ROW * keypoints_step; @@ -988,7 +1017,7 @@ inline uchar readerGet( IMAGE_INT8 src, const float centerX, const float centerY, const float win_offset, const float cos_dir, const float sin_dir, int i, int j, int rows, int cols, int elemPerRow - ) +) { float pixel_x = centerX + (win_offset + j) * cos_dir + (win_offset + i) * sin_dir; float pixel_y = centerY - (win_offset + j) * sin_dir + (win_offset + i) * cos_dir; @@ -999,7 +1028,7 @@ inline float linearFilter( IMAGE_INT8 src, const float centerX, const float centerY, const float win_offset, const float cos_dir, const float sin_dir, float y, float x, int rows, int cols, int elemPerRow - ) +) { x -= 0.5f; y -= 0.5f; @@ -1028,9 +1057,9 @@ inline float linearFilter( void calc_dx_dy( IMAGE_INT8 imgTex, - volatile __local float s_dx_bin[25], - volatile __local float s_dy_bin[25], - volatile __local float s_PATCH[6][6], + volatile __local float *s_dx_bin, + volatile __local float *s_dy_bin, + volatile __local float *s_PATCH, __global const float* featureX, __global const float* featureY, __global const float* featureSize, @@ -1038,7 +1067,7 @@ void calc_dx_dy( int rows, int cols, int elemPerRow - ) +) { const float centerX = featureX[get_group_id(0)]; const float centerY = featureY[get_group_id(0)]; @@ -1048,6 +1077,7 @@ void calc_dx_dy( { descriptor_dir = 0.0f; } + descriptor_dir *= (float)(CV_PI_F / 180.0f); /* The sampling intervals and wavelet sized for selecting an orientation @@ -1074,7 +1104,7 @@ void calc_dx_dy( const float icoo = ((float)yIndex / (PATCH_SZ + 1)) * win_size; const float jcoo = ((float)xIndex / (PATCH_SZ + 1)) * win_size; - s_PATCH[get_local_id(1)][get_local_id(0)] = linearFilter(imgTex, centerX, centerY, win_offset, cos_dir, sin_dir, icoo, jcoo, rows, cols, elemPerRow); + s_PATCH[get_local_id(1) * 6 + get_local_id(0)] = linearFilter(imgTex, centerX, centerY, win_offset, cos_dir, sin_dir, icoo, jcoo, rows, cols, elemPerRow); barrier(CLK_LOCAL_MEM_FENCE); @@ -1085,17 +1115,17 @@ void calc_dx_dy( const float dw = c_DW[yIndex * PATCH_SZ + xIndex]; const float vx = ( - s_PATCH[get_local_id(1) ][get_local_id(0) + 1] - - s_PATCH[get_local_id(1) ][get_local_id(0) ] + - s_PATCH[get_local_id(1) + 1][get_local_id(0) + 1] - - s_PATCH[get_local_id(1) + 1][get_local_id(0) ]) - * dw; + s_PATCH[ get_local_id(1) * 6 + get_local_id(0) + 1] - + s_PATCH[ get_local_id(1) * 6 + get_local_id(0) ] + + s_PATCH[(get_local_id(1) + 1) * 6 + get_local_id(0) + 1] - + s_PATCH[(get_local_id(1) + 1) * 6 + get_local_id(0) ]) + * dw; const float vy = ( - s_PATCH[get_local_id(1) + 1][get_local_id(0) ] - - s_PATCH[get_local_id(1) ][get_local_id(0) ] + - s_PATCH[get_local_id(1) + 1][get_local_id(0) + 1] - - s_PATCH[get_local_id(1) ][get_local_id(0) + 1]) - * dw; + s_PATCH[(get_local_id(1) + 1) * 6 + get_local_id(0) ] - + s_PATCH[ get_local_id(1) * 6 + get_local_id(0) ] + + s_PATCH[(get_local_id(1) + 1) * 6 + get_local_id(0) + 1] - + s_PATCH[ get_local_id(1) * 6 + get_local_id(0) + 1]) + * dw; s_dx_bin[tid] = vx; s_dy_bin[tid] = vy; } @@ -1106,7 +1136,7 @@ void reduce_sum25( volatile __local float* sdata3, volatile __local float* sdata4, int tid - ) +) { #ifndef WAVE_SIZE #define WAVE_SIZE 1 @@ -1125,11 +1155,8 @@ void reduce_sum25( { #endif sdata1[tid] += sdata1[tid + 8]; - sdata2[tid] += sdata2[tid + 8]; - sdata3[tid] += sdata3[tid + 8]; - sdata4[tid] += sdata4[tid + 8]; #if WAVE_SIZE < 8 } @@ -1166,7 +1193,7 @@ void reduce_sum25( } __kernel - void compute_descriptors64( +void compute_descriptors64( IMAGE_INT8 imgTex, __global float * descriptors, __global const float * keypoints, @@ -1175,7 +1202,7 @@ __kernel int rows, int cols, int img_step - ) +) { descriptors_step /= sizeof(float); keypoints_step /= sizeof(float); @@ -1189,7 +1216,7 @@ __kernel volatile __local float sdy[25]; volatile __local float sdxabs[25]; volatile __local float sdyabs[25]; - volatile __local float s_PATCH[6][6]; + volatile __local float s_PATCH[6*6]; calc_dx_dy(imgTex, sdx, sdy, s_PATCH, featureX, featureY, featureSize, featureDir, rows, cols, img_step); barrier(CLK_LOCAL_MEM_FENCE); @@ -1203,7 +1230,7 @@ __kernel } barrier(CLK_LOCAL_MEM_FENCE); - reduce_sum25(sdx, sdy, sdxabs, sdyabs, tid); + reduce_sum25(sdx, sdy, sdxabs, sdyabs, tid); barrier(CLK_LOCAL_MEM_FENCE); if (tid < 25) @@ -1221,7 +1248,7 @@ __kernel } } __kernel - void compute_descriptors128( +void compute_descriptors128( IMAGE_INT8 imgTex, __global float * descriptors, __global float * keypoints, @@ -1230,7 +1257,7 @@ __kernel int rows, int cols, int img_step - ) +) { descriptors_step /= sizeof(*descriptors); keypoints_step /= sizeof(*keypoints); @@ -1249,7 +1276,7 @@ __kernel volatile __local float sd2[25]; volatile __local float sdabs1[25]; volatile __local float sdabs2[25]; - volatile __local float s_PATCH[6][6]; + volatile __local float s_PATCH[6*6]; calc_dx_dy(imgTex, sdx, sdy, s_PATCH, featureX, featureY, featureSize, featureDir, rows, cols, img_step); barrier(CLK_LOCAL_MEM_FENCE); @@ -1275,7 +1302,7 @@ __kernel } barrier(CLK_LOCAL_MEM_FENCE); - reduce_sum25(sd1, sd2, sdabs1, sdabs2, tid); + reduce_sum25(sd1, sd2, sdabs1, sdabs2, tid); barrier(CLK_LOCAL_MEM_FENCE); __global float* descriptors_block = descriptors + descriptors_step * get_group_id(0) + (get_group_id(1) << 3); @@ -1306,8 +1333,7 @@ __kernel } } barrier(CLK_LOCAL_MEM_FENCE); - - reduce_sum25(sd1, sd2, sdabs1, sdabs2, tid); + reduce_sum25(sd1, sd2, sdabs1, sdabs2, tid); barrier(CLK_LOCAL_MEM_FENCE); if (tid < 25) @@ -1322,11 +1348,13 @@ __kernel } } } + void reduce_sum128(volatile __local float* smem, int tid) { #ifndef WAVE_SIZE #define WAVE_SIZE 1 #endif + if (tid < 64) { smem[tid] += smem[tid + 64]; @@ -1374,6 +1402,8 @@ void reduce_sum128(volatile __local float* smem, int tid) smem[tid] += smem[tid + 1]; } } + + void reduce_sum64(volatile __local float* smem, int tid) { #ifndef WAVE_SIZE @@ -1421,7 +1451,7 @@ void reduce_sum64(volatile __local float* smem, int tid) } __kernel - void normalize_descriptors128(__global float * descriptors, int descriptors_step) +void normalize_descriptors128(__global float * descriptors, int descriptors_step) { descriptors_step /= sizeof(*descriptors); // no need for thread ID @@ -1436,8 +1466,6 @@ __kernel reduce_sum128(sqDesc, get_local_id(0)); barrier(CLK_LOCAL_MEM_FENCE); - - // compute length (square root) volatile __local float len; if (get_local_id(0) == 0) @@ -1450,7 +1478,7 @@ __kernel descriptor_base[get_local_id(0)] = lookup / len; } __kernel - void normalize_descriptors64(__global float * descriptors, int descriptors_step) +void normalize_descriptors64(__global float * descriptors, int descriptors_step) { descriptors_step /= sizeof(*descriptors); // no need for thread ID @@ -1462,7 +1490,6 @@ __kernel sqDesc[get_local_id(0)] = lookup * lookup; barrier(CLK_LOCAL_MEM_FENCE); - reduce_sum64(sqDesc, get_local_id(0)); barrier(CLK_LOCAL_MEM_FENCE); diff --git a/modules/nonfree/src/precomp.cpp b/modules/nonfree/src/precomp.cpp deleted file mode 100644 index 730edbb63d..0000000000 --- a/modules/nonfree/src/precomp.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/nonfree/test/test_precomp.cpp b/modules/nonfree/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/nonfree/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/objdetect/perf/perf_precomp.cpp b/modules/objdetect/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/objdetect/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/objdetect/src/precomp.cpp b/modules/objdetect/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/objdetect/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/objdetect/test/test_precomp.cpp b/modules/objdetect/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/objdetect/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/ocl/include/opencv2/ocl.hpp b/modules/ocl/include/opencv2/ocl.hpp index d4ce905fea..7aaafca441 100644 --- a/modules/ocl/include/opencv2/ocl.hpp +++ b/modules/ocl/include/opencv2/ocl.hpp @@ -710,7 +710,7 @@ namespace cv //! returns 2D filter with the specified kernel // supports CV_8UC1 and CV_8UC4 types CV_EXPORTS Ptr getLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, const Size &ksize, - Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT); + const Point &anchor = Point(-1, -1), int borderType = BORDER_DEFAULT); //! returns the non-separable linear filter engine CV_EXPORTS Ptr createLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, diff --git a/modules/ocl/perf/main.cpp b/modules/ocl/perf/main.cpp index bbc6716041..65218a9018 100644 --- a/modules/ocl/perf/main.cpp +++ b/modules/ocl/perf/main.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" static int cvErrorCallback(int /*status*/, const char * /*func_name*/, const char *err_msg, const char * /*file_name*/, diff --git a/modules/ocl/perf/perf_arithm.cpp b/modules/ocl/perf/perf_arithm.cpp index 3ef0634e70..29ff0d802a 100644 --- a/modules/ocl/perf/perf_arithm.cpp +++ b/modules/ocl/perf/perf_arithm.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// Lut //////////////////////// PERFTEST(lut) { diff --git a/modules/ocl/perf/perf_blend.cpp b/modules/ocl/perf/perf_blend.cpp index 8ebb6482ba..22139779d4 100644 --- a/modules/ocl/perf/perf_blend.cpp +++ b/modules/ocl/perf/perf_blend.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// blend //////////////////////// template void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &weights1, const cv::Mat &weights2, cv::Mat &result_gold) diff --git a/modules/ocl/perf/perf_brute_force_matcher.cpp b/modules/ocl/perf/perf_brute_force_matcher.cpp index 406b46a324..c481766035 100644 --- a/modules/ocl/perf/perf_brute_force_matcher.cpp +++ b/modules/ocl/perf/perf_brute_force_matcher.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" //////////////////// BruteForceMatch ///////////////// PERFTEST(BruteForceMatcher) diff --git a/modules/ocl/perf/perf_calib3d.cpp b/modules/ocl/perf/perf_calib3d.cpp index 428f00ea94..f9fe654ce9 100644 --- a/modules/ocl/perf/perf_calib3d.cpp +++ b/modules/ocl/perf/perf_calib3d.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// StereoMatchBM //////////////////////// PERFTEST(StereoMatchBM) { diff --git a/modules/ocl/perf/perf_canny.cpp b/modules/ocl/perf/perf_canny.cpp index 8fc0d13ccd..8aa6d98fc8 100644 --- a/modules/ocl/perf/perf_canny.cpp +++ b/modules/ocl/perf/perf_canny.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// Canny //////////////////////// PERFTEST(Canny) diff --git a/modules/ocl/perf/perf_color.cpp b/modules/ocl/perf/perf_color.cpp index 44dc8f855c..05e66550bc 100644 --- a/modules/ocl/perf/perf_color.cpp +++ b/modules/ocl/perf/perf_color.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// cvtColor//////////////////////// PERFTEST(cvtColor) diff --git a/modules/ocl/perf/perf_fft.cpp b/modules/ocl/perf/perf_fft.cpp index 6e0be3f19d..7073eb691d 100644 --- a/modules/ocl/perf/perf_fft.cpp +++ b/modules/ocl/perf/perf_fft.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// dft //////////////////////// PERFTEST(dft) diff --git a/modules/ocl/perf/perf_filters.cpp b/modules/ocl/perf/perf_filters.cpp index e988ce09d6..be288b444b 100644 --- a/modules/ocl/perf/perf_filters.cpp +++ b/modules/ocl/perf/perf_filters.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// Blur//////////////////////// PERFTEST(Blur) diff --git a/modules/ocl/perf/perf_gemm.cpp b/modules/ocl/perf/perf_gemm.cpp index f197c5f5a0..abaeda363c 100644 --- a/modules/ocl/perf/perf_gemm.cpp +++ b/modules/ocl/perf/perf_gemm.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// gemm //////////////////////// PERFTEST(gemm) diff --git a/modules/ocl/perf/perf_gftt.cpp b/modules/ocl/perf/perf_gftt.cpp index bdc62b622e..430d441430 100644 --- a/modules/ocl/perf/perf_gftt.cpp +++ b/modules/ocl/perf/perf_gftt.cpp @@ -44,7 +44,7 @@ //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// GoodFeaturesToTrack //////////////////////// PERFTEST(GoodFeaturesToTrack) diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index 38e9d5e968..f1a6e43c0e 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -43,7 +43,8 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" + ///////////// Haar //////////////////////// PERFTEST(Haar) @@ -103,4 +104,4 @@ PERFTEST(Haar) faceCascade.detectMultiScale(d_img, oclfaces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30)); GPU_FULL_OFF; -} \ No newline at end of file +} diff --git a/modules/ocl/perf/perf_hog.cpp b/modules/ocl/perf/perf_hog.cpp index 7daa61396c..0f05581295 100644 --- a/modules/ocl/perf/perf_hog.cpp +++ b/modules/ocl/perf/perf_hog.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// HOG//////////////////////// diff --git a/modules/ocl/perf/perf_hough.cpp b/modules/ocl/perf/perf_hough.cpp index 53c7b3b050..61e8e48d2f 100644 --- a/modules/ocl/perf/perf_hough.cpp +++ b/modules/ocl/perf/perf_hough.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/perf/perf_imgproc.cpp b/modules/ocl/perf/perf_imgproc.cpp index 605b1ecb3d..7419475bc7 100644 --- a/modules/ocl/perf/perf_imgproc.cpp +++ b/modules/ocl/perf/perf_imgproc.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// equalizeHist //////////////////////// PERFTEST(equalizeHist) diff --git a/modules/ocl/perf/perf_match_template.cpp b/modules/ocl/perf/perf_match_template.cpp index 1330e268f8..af23501c69 100644 --- a/modules/ocl/perf/perf_match_template.cpp +++ b/modules/ocl/perf/perf_match_template.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" /////////// matchTemplate //////////////////////// //void InitMatchTemplate() diff --git a/modules/ocl/perf/perf_matrix_operation.cpp b/modules/ocl/perf/perf_matrix_operation.cpp index b724cdbe64..bb407c9afe 100644 --- a/modules/ocl/perf/perf_matrix_operation.cpp +++ b/modules/ocl/perf/perf_matrix_operation.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// ConvertTo//////////////////////// PERFTEST(ConvertTo) diff --git a/modules/ocl/perf/perf_moments.cpp b/modules/ocl/perf/perf_moments.cpp index 7fa3948dec..a1515b879b 100644 --- a/modules/ocl/perf/perf_moments.cpp +++ b/modules/ocl/perf/perf_moments.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// Moments //////////////////////// PERFTEST(Moments) { diff --git a/modules/ocl/perf/perf_norm.cpp b/modules/ocl/perf/perf_norm.cpp index 1d986c8e49..fec8d73791 100644 --- a/modules/ocl/perf/perf_norm.cpp +++ b/modules/ocl/perf/perf_norm.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// norm//////////////////////// PERFTEST(norm) diff --git a/modules/ocl/perf/perf_opticalflow.cpp b/modules/ocl/perf/perf_opticalflow.cpp index 10763b5b0f..a6724c8123 100644 --- a/modules/ocl/perf/perf_opticalflow.cpp +++ b/modules/ocl/perf/perf_opticalflow.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// PyrLKOpticalFlow //////////////////////// PERFTEST(PyrLKOpticalFlow) diff --git a/modules/ocl/perf/precomp.cpp b/modules/ocl/perf/perf_precomp.cpp similarity index 99% rename from modules/ocl/perf/precomp.cpp rename to modules/ocl/perf/perf_precomp.cpp index daeaad6dbc..ca2f08c008 100644 --- a/modules/ocl/perf/precomp.cpp +++ b/modules/ocl/perf/perf_precomp.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" #if GTEST_OS_WINDOWS #ifndef NOMINMAX #define NOMINMAX diff --git a/modules/ocl/perf/precomp.hpp b/modules/ocl/perf/perf_precomp.hpp similarity index 99% rename from modules/ocl/perf/precomp.hpp rename to modules/ocl/perf/perf_precomp.hpp index 385320beea..6d3f31c9fa 100644 --- a/modules/ocl/perf/precomp.hpp +++ b/modules/ocl/perf/perf_precomp.hpp @@ -40,6 +40,9 @@ // //M*/ +#ifndef __OPENCV_PERF_PRECOMP_HPP__ +#define __OPENCV_PERF_PRECOMP_HPP__ + #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" # if defined __clang__ || defined __APPLE__ @@ -515,3 +518,5 @@ struct name##_test: Runnable { \ #define WARMUP_OFF \ ocl::finish(); \ } TestSystem::instance().warmupComplete() + +#endif diff --git a/modules/ocl/perf/perf_pyramid.cpp b/modules/ocl/perf/perf_pyramid.cpp index 3b96251e5d..b98f531b5e 100644 --- a/modules/ocl/perf/perf_pyramid.cpp +++ b/modules/ocl/perf/perf_pyramid.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// pyrDown ////////////////////// PERFTEST(pyrDown) diff --git a/modules/ocl/perf/perf_split_merge.cpp b/modules/ocl/perf/perf_split_merge.cpp index 0fafd14aba..cbe817faff 100644 --- a/modules/ocl/perf/perf_split_merge.cpp +++ b/modules/ocl/perf/perf_split_merge.cpp @@ -43,7 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "perf_precomp.hpp" ///////////// Merge//////////////////////// PERFTEST(Merge) diff --git a/modules/ocl/src/color.cpp b/modules/ocl/src/color.cpp index d449547bfb..13136e0d33 100644 --- a/modules/ocl/src/color.cpp +++ b/modules/ocl/src/color.cpp @@ -213,7 +213,7 @@ void cvtColor_caller(const oclMat &src, oclMat &dst, int code, int dcn) case COLOR_RGB2YUV: { CV_Assert(scn == 3 || scn == 4); - bidx = code == COLOR_BGR2YUV ? 0 : 2; + bidx = code == COLOR_RGB2YUV ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 3)); RGB2YUV_caller(src, dst, bidx); break; @@ -222,7 +222,7 @@ void cvtColor_caller(const oclMat &src, oclMat &dst, int code, int dcn) case COLOR_YUV2RGB: { CV_Assert(scn == 3 || scn == 4); - bidx = code == COLOR_YUV2BGR ? 0 : 2; + bidx = code == COLOR_YUV2RGB ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 3)); YUV2RGB_caller(src, dst, bidx); break; diff --git a/modules/ocl/src/filtering.cpp b/modules/ocl/src/filtering.cpp index 79113706a0..713854299d 100644 --- a/modules/ocl/src/filtering.cpp +++ b/modules/ocl/src/filtering.cpp @@ -572,7 +572,7 @@ void cv::ocl::morphologyEx(const oclMat &src, oclMat &dst, int op, const Mat &ke namespace { -typedef void (*GPUFilter2D_t)(const oclMat & , oclMat & , oclMat & , Size &, const Point, const int); +typedef void (*GPUFilter2D_t)(const oclMat & , oclMat & , const oclMat & , const Size &, const Point&, const int); class LinearFilter_GPU : public BaseFilter_GPU { @@ -591,21 +591,22 @@ public: }; } -static void GPUFilter2D(const oclMat &src, oclMat &dst, oclMat &mat_kernel, - Size &ksize, const Point anchor, const int borderType) +static void GPUFilter2D(const oclMat &src, oclMat &dst, const oclMat &mat_kernel, + const Size &ksize, const Point& anchor, const int borderType) { CV_Assert(src.clCxt == dst.clCxt); CV_Assert((src.cols == dst.cols) && (src.rows == dst.rows)); CV_Assert((src.oclchannels() == dst.oclchannels())); - CV_Assert((borderType != 0)); CV_Assert(ksize.height > 0 && ksize.width > 0 && ((ksize.height & 1) == 1) && ((ksize.width & 1) == 1)); CV_Assert((anchor.x == -1 && anchor.y == -1) || (anchor.x == ksize.width >> 1 && anchor.y == ksize.height >> 1)); + CV_Assert(ksize.width == ksize.height); Context *clCxt = src.clCxt; - int cn = src.oclchannels(); - int depth = src.depth(); - String kernelName = "filter2D"; + int filterWidth = ksize.width; + bool ksize_3x3 = filterWidth == 3 && src.type() != CV_32FC4; // CV_32FC4 is not tuned up with filter2d_3x3 kernel + + String kernelName = ksize_3x3 ? "filter2D_3x3" : "filter2D"; size_t src_offset_x = (src.offset % src.step) / src.elemSize(); size_t src_offset_y = src.offset / src.step; @@ -613,55 +614,81 @@ static void GPUFilter2D(const oclMat &src, oclMat &dst, oclMat &mat_kernel, size_t dst_offset_x = (dst.offset % dst.step) / dst.elemSize(); size_t dst_offset_y = dst.offset / dst.step; - int vector_lengths[4][7] = {{4, 4, 4, 4, 4, 4, 4}, - {4, 4, 1, 1, 1, 1, 1}, - {1, 1, 1, 1, 1, 1, 1}, - {4, 4, 4, 4, 1, 1, 4} - }; + int paddingPixels = filterWidth & (-2); + + size_t localThreads[3] = {ksize_3x3 ? 256 : 16, ksize_3x3 ? 1 : 16, 1}; + size_t globalThreads[3] = {src.wholecols, src.wholerows, 1}; - int vector_length = vector_lengths[cn - 1][depth]; - int offset_cols = (dst_offset_x) & (vector_length - 1); - int cols = dst.cols + offset_cols; - int rows = divUp(dst.rows, vector_length); + int cn = src.oclchannels(); + int src_step = (int)(src.step/src.elemSize()); + int dst_step = (int)(dst.step/src.elemSize()); - size_t localThreads[3] = {256, 1, 1}; - size_t globalThreads[3] = { divUp(cols, localThreads[0]) *localThreads[0], - divUp(rows, localThreads[1]) *localThreads[1], 1 - }; + int localWidth = localThreads[0] + paddingPixels; + int localHeight = localThreads[1] + paddingPixels; + + // 260 = divup((localThreads[0] + filterWidth * 2), 4) * 4 + // 6 = (ROWS_PER_GROUP_WHICH_IS_4 + filterWidth * 2) + size_t localMemSize = ksize_3x3 ? 260 * 6 * src.elemSize() : (localWidth * localHeight) * src.elemSize(); + + int vector_lengths[4][7] = {{4, 4, 4, 4, 4, 4, 4}, + {4, 4, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1}, + {4, 4, 4, 4, 1, 1, 4} + }; + int cols = dst.cols + ((dst_offset_x) & (vector_lengths[cn - 1][src.depth()] - 1)); std::vector< std::pair > args; args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); - args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); + args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); + args.push_back(std::make_pair(sizeof(cl_int), (void *)&src_step)); + args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst_step)); + args.push_back(std::make_pair(sizeof(cl_mem), (void *)&mat_kernel.data)); + args.push_back(std::make_pair(localMemSize, (void *)NULL)); + args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.wholerows)); + args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.wholecols)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&src_offset_x)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&src_offset_y)); - args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); - args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst_offset_x)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst_offset_y)); - args.push_back(std::make_pair(sizeof(cl_mem), (void *)&mat_kernel.data)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.cols)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.rows)); args.push_back(std::make_pair(sizeof(cl_int), (void *)&cols)); - args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.wholecols)); - args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.wholerows)); - - const int buffer_size = 100; - char opt_buffer [buffer_size] = ""; - sprintf(opt_buffer, "-DANCHOR=%d -DANX=%d -DANY=%d", ksize.width, anchor.x, anchor.y); - - openCLExecuteKernel(clCxt, &filtering_laplacian, kernelName, globalThreads, localThreads, args, cn, depth, opt_buffer); + char btype[30]; + switch (borderType) + { + case 0: + sprintf(btype, "BORDER_CONSTANT"); + break; + case 1: + sprintf(btype, "BORDER_REPLICATE"); + break; + case 2: + sprintf(btype, "BORDER_REFLECT"); + break; + case 3: + CV_Error(CV_StsUnsupportedFormat, "BORDER_WRAP is not supported!"); + return; + case 4: + sprintf(btype, "BORDER_REFLECT_101"); + break; + } + int type = src.depth(); + char build_options[150]; + sprintf(build_options, "-D %s -D IMG_C_%d_%d -D CN=%d -D FILTER_SIZE=%d", btype, cn, type, cn, ksize.width); + openCLExecuteKernel(clCxt, &filtering_laplacian, kernelName, globalThreads, localThreads, args, -1, -1, build_options); } + Ptr cv::ocl::getLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, const Size &ksize, - Point anchor, int borderType) + const Point &anchor, int borderType) { static const GPUFilter2D_t GPUFilter2D_callers[] = {0, GPUFilter2D, 0, GPUFilter2D, GPUFilter2D}; CV_Assert((srcType == CV_8UC1 || srcType == CV_8UC3 || srcType == CV_8UC4 || srcType == CV_32FC1 || srcType == CV_32FC3 || srcType == CV_32FC4) && dstType == srcType); oclMat gpu_krnl; - int nDivisor; - normalizeKernel(kernel, gpu_krnl, CV_32S, &nDivisor, false); - normalizeAnchor(anchor, ksize); + Point norm_archor = anchor; + normalizeKernel(kernel, gpu_krnl, CV_32FC1); + normalizeAnchor(norm_archor, ksize); return Ptr(new LinearFilter_GPU(ksize, anchor, gpu_krnl, GPUFilter2D_callers[CV_MAT_CN(srcType)], borderType)); diff --git a/modules/ocl/src/haar.cpp b/modules/ocl/src/haar.cpp index a8118dba60..ac6a6e0a4e 100644 --- a/modules/ocl/src/haar.cpp +++ b/modules/ocl/src/haar.cpp @@ -258,7 +258,7 @@ static GpuHidHaarClassifierCascade * gpuCreateHidHaarClassifierCascade( CvHaarCl int datasize; int total_classifiers = 0; int total_nodes = 0; - char errorstr[100]; + char errorstr[256]; GpuHidHaarStageClassifier *stage_classifier_ptr; GpuHidHaarClassifier *haar_classifier_ptr; diff --git a/modules/ocl/src/opencl/filtering_laplacian.cl b/modules/ocl/src/opencl/filtering_laplacian.cl index 8535eb1a54..f7430d5332 100644 --- a/modules/ocl/src/opencl/filtering_laplacian.cl +++ b/modules/ocl/src/opencl/filtering_laplacian.cl @@ -15,7 +15,9 @@ // Third party copyrights are property of their respective owners. // // @Authors +// Pang Erping, erping@multicorewareinc.com // Jia Haipeng, jiahaipeng95@gmail.com +// Peng Xiao, pengxiao@outlook.com // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: @@ -42,292 +44,228 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#define BORDER_REFLECT_101 /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////Macro for border type//////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// #ifdef BORDER_REPLICATE + //BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh #define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? (l_edge) : (i)) #define ADDR_R(i, r_edge, addr) ((i) >= (r_edge) ? (r_edge)-1 : (addr)) -#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? (t_edge) :(i)) +#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? (t_edge) : (i)) #define ADDR_B(i, b_edge, addr) ((i) >= (b_edge) ? (b_edge)-1 :(addr)) #endif #ifdef BORDER_REFLECT -//BORDER_REFLECT: fedcba|abcdefgh|hgfedcb -#define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? -(i)-1 : (i)) +#define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? ((l_edge)<<1)-(i)-1 : (i)) #define ADDR_R(i, r_edge, addr) ((i) >= (r_edge) ? -(i)-1+((r_edge)<<1) : (addr)) -#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? -(i)-1 : (i)) +#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? ((t_edge)<<1)-(i)-1 : (i)) #define ADDR_B(i, b_edge, addr) ((i) >= (b_edge) ? -(i)-1+((b_edge)<<1) : (addr)) #endif #ifdef BORDER_REFLECT_101 //BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba -#define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? -(i) : (i)) +#define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? ((l_edge)<<1)-(i) : (i)) #define ADDR_R(i, r_edge, addr) ((i) >= (r_edge) ? -(i)-2+((r_edge)<<1) : (addr)) -#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? -(i) : (i)) +#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? ((t_edge)<<1)-(i) : (i)) #define ADDR_B(i, b_edge, addr) ((i) >= (b_edge) ? -(i)-2+((b_edge)<<1) : (addr)) #endif -#ifdef BORDER_WRAP -//BORDER_WRAP: cdefgh|abcdefgh|abcdefg -#define ADDR_L(i, l_edge, r_edge) ((i) < (l_edge) ? (i)+(r_edge) : (i)) -#define ADDR_R(i, r_edge, addr) ((i) >= (r_edge) ? (i)-(r_edge) : (addr)) -#define ADDR_H(i, t_edge, b_edge) ((i) < (t_edge) ? (i)+(b_edge) : (i)) -#define ADDR_B(i, b_edge, addr) ((i) >= (b_edge) ? (i)-(b_edge) : (addr)) +#ifdef IMG_C_1_0 +#define T_IMG uchar +#define T_IMGx4 uchar4 +#define T_IMG_C1 uchar +#define CONVERT_TYPE convert_uchar_sat +#define CONVERT_TYPEx4 convert_uchar4_sat +#endif +#ifdef IMG_C_4_0 +#define T_IMG uchar4 +#define T_IMGx4 uchar16 +#define T_IMG_C1 uchar +#define CONVERT_TYPE convert_uchar4_sat +#define CONVERT_TYPEx4 convert_uchar16_sat +#endif +#ifdef IMG_C_1_5 +#define T_IMG float +#define T_IMGx4 float4 +#define T_IMG_C1 float +#define CONVERT_TYPE convert_float +#define CONVERT_TYPEx4 convert_float4 +#endif +#ifdef IMG_C_4_5 +#define T_IMG float4 +#define T_IMGx4 float16 +#define T_IMG_C1 float +#define CONVERT_TYPE convert_float4 +#define CONVERT_TYPEx4 convert_float16 #endif -////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////Macro for define elements number per thread///////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -//#define ANCHOR 3 -//#define ANX 1 -//#define ANY 1 - -#define ROWS_PER_GROUP 4 -#define ROWS_PER_GROUP_BITS 2 -#define ROWS_FETCH (ROWS_PER_GROUP + ANY + ANY) //(ROWS_PER_GROUP + anY * 2) - -#define THREADS_PER_ROW 64 -#define THREADS_PER_ROW_BIT 6 +#ifndef CN +#define CN 1 +#endif -#define ELEMENTS_PER_THREAD 4 -#define ELEMENTS_PER_THREAD_BIT 2 +#if CN == 1 +#define T_SUM float +#define T_SUMx4 float4 +#define CONVERT_TYPE_SUM convert_float +#define CONVERT_TYPE_SUMx4 convert_float4 +#define SUM_ZERO (0.0f) +#define SUM_ZEROx4 (0.0f, 0.0f, 0.0f, 0.0f) +#define VLOAD4 vload4 +#define SX x +#define SY y +#define SZ z +#define SW w +#elif CN == 4 +#define T_SUM float4 +#define T_SUMx4 float16 +#define CONVERT_TYPE_SUM convert_float4 +#define CONVERT_TYPE_SUMx4 convert_float16 +#define SUM_ZERO (0.0f, 0.0f, 0.0f, 0.0f) +#define SUM_ZEROx4 (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f) +#define VLOAD4 vload16 +#define SX s0123 +#define SY s4567 +#define SZ s89ab +#define SW scdef +#endif -#define LOCAL_MEM_STEP 260 //divup((get_local_size(0) + anX * 2), 4) * 4 +#ifndef FILTER_SIZE +#define FILTER_SIZE 3 +#endif -/////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////8uC1//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -__kernel void filter2D_C1_D0(__global uchar *src, int src_step, int src_offset_x, int src_offset_y, - __global uchar *dst, int dst_step, int dst_offset_x, int dst_offset_y, - __constant int *mat_kernel __attribute__((max_constant_size (16384))), - int cols,int rows, int operate_cols, int wholecols, int wholerows) +#define LOCAL_GROUP_SIZE 16 + +#define LOCAL_WIDTH ((FILTER_SIZE/2)*2 + LOCAL_GROUP_SIZE) +#define LOCAL_HEIGHT ((FILTER_SIZE/2)*2 + LOCAL_GROUP_SIZE) + +#define FILTER_RADIUS (FILTER_SIZE >> 1) + +__kernel void filter2D( + __global T_IMG *src, + __global T_IMG *dst, + int src_step, + int dst_step, + __constant float *mat_kernel, + __local T_IMG *local_data, + int wholerows, + int wholecols, + int src_offset_x, + int src_offset_y, + int dst_offset_x, + int dst_offset_y, + int cols, + int rows, + int operate_cols +) { - int gX = get_global_id(0); - int gY = get_global_id(1); - - int lX = get_local_id(0); - - int groupX_size = get_local_size(0); - int groupX_id = get_group_id(0); - -#define dst_align (dst_offset_x & 3) - int cols_start_index_group = src_offset_x - dst_align + groupX_size * groupX_id - ANX; - int rows_start_index = src_offset_y + (gY << ROWS_PER_GROUP_BITS) - ANY; - - __local uchar local_data[LOCAL_MEM_STEP * ROWS_FETCH]; - if((gY << 2) < rows) + int groupStartCol = get_group_id(0) * get_local_size(0); + int groupStartRow = get_group_id(1) * get_local_size(1); + + int localCol = get_local_id(0); + int localRow = get_local_id(1); + int globalCol = groupStartCol + localCol; + int globalRow = groupStartRow + localRow; + const int src_offset = mad24(src_offset_y, src_step, src_offset_x); + const int dst_offset = mad24(dst_offset_y, dst_step, dst_offset_x); +#ifdef BORDER_CONSTANT + for(int i = localRow; i < LOCAL_HEIGHT; i += get_local_size(1)) { - for(int i = 0; i < ROWS_FETCH; ++i) + int curRow = groupStartRow + i; + for(int j = localCol; j < LOCAL_WIDTH; j += get_local_size(0)) { - if((rows_start_index - src_offset_y) + i < rows + ANY) + int curCol = groupStartCol + j; + if(curRow < FILTER_RADIUS - src_offset_y || (curRow - FILTER_RADIUS) >= wholerows - src_offset_y|| + curCol < FILTER_RADIUS - src_offset_x || (curCol - FILTER_RADIUS) >= wholecols - src_offset_x) { -#ifdef BORDER_CONSTANT - int selected_row = rows_start_index + i; - int selected_cols = cols_start_index_group + lX; - - uchar data = *(src + selected_row * src_step + selected_cols); - int con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX ] =data; - - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - - data = *(src + selected_row * src_step + selected_cols); - con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; - } -#else - int selected_row = ADDR_H(rows_start_index + i, 0, wholerows); - selected_row = ADDR_B(rows_start_index + i, wholerows, selected_row); - - int selected_cols = ADDR_L(cols_start_index_group + lX, 0, wholecols); - selected_cols = ADDR_R(cols_start_index_group + lX, wholecols, selected_cols); - - uchar data = *(src + selected_row * src_step + selected_cols); - - local_data[i * LOCAL_MEM_STEP + lX ] =data; - - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - selected_cols = ADDR_R(selected_cols, wholecols, selected_cols); - - data = *(src + selected_row * src_step + selected_cols); - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; - } -#endif + local_data[(i) * LOCAL_WIDTH + j] = 0; + } + else + { + local_data[(i) * LOCAL_WIDTH + j] = src[(curRow - FILTER_RADIUS) * src_step + curCol - FILTER_RADIUS + src_offset]; } } } - barrier(CLK_LOCAL_MEM_FENCE); - - int process_col = groupX_size * groupX_id + ((lX % THREADS_PER_ROW) << 2); - if(((gY << 2) < rows) && (process_col < operate_cols)) +#else + for(int i = localRow; i < LOCAL_HEIGHT; i += get_local_size(1)) { - int dst_cols_start = dst_offset_x; - int dst_cols_end = dst_offset_x + cols; - int dst_cols_index = (dst_offset_x + process_col) & 0xfffffffc; - - int dst_rows_end = dst_offset_y + rows; - int dst_rows_index = dst_offset_y + (gY << ROWS_PER_GROUP_BITS) + (lX >> THREADS_PER_ROW_BIT); + int curRow = groupStartRow + i; - uchar4 dst_data = *((__global uchar4 *)(dst + dst_rows_index * dst_step + dst_cols_index)); + curRow = ADDR_H(curRow, FILTER_RADIUS - src_offset_y, wholerows - src_offset_y); - int4 sum = (int4)(0); - uchar4 data; + curRow = ADDR_B(curRow - FILTER_RADIUS, wholerows - src_offset_y, curRow - FILTER_RADIUS); - for(int i = 0; i < ANCHOR; i++) + for(int j = localCol; j < LOCAL_WIDTH; j += get_local_size(0)) { -#pragma unroll - for(int j = 0; j < ANCHOR; j++) + int curCol = groupStartCol + j; + curCol = ADDR_L(curCol, FILTER_RADIUS - src_offset_x, wholecols - src_offset_x); + curCol = ADDR_R(curCol - FILTER_RADIUS, wholecols - src_offset_x, curCol - FILTER_RADIUS); + if(curRow < wholerows && curCol < wholecols) { - if(dst_rows_index < dst_rows_end) - { - int local_row = (lX >> THREADS_PER_ROW_BIT) + i; - int local_cols = ((lX % THREADS_PER_ROW) << ELEMENTS_PER_THREAD_BIT) + j; - - data = vload4(0, local_data+local_row * LOCAL_MEM_STEP + local_cols); - sum = sum + (mat_kernel[i * ANCHOR + j] * convert_int4_sat(data)); - } + local_data[(i) * LOCAL_WIDTH + j] = src[(curRow) * src_step + curCol + src_offset]; } } - - if(dst_rows_index < dst_rows_end) - { - sum.x = ((dst_cols_index + 0 >= dst_cols_start) && (dst_cols_index + 0 < dst_cols_end)) ? sum.x : dst_data.x; - sum.y = ((dst_cols_index + 1 >= dst_cols_start) && (dst_cols_index + 1 < dst_cols_end)) ? sum.y : dst_data.y; - sum.z = ((dst_cols_index + 2 >= dst_cols_start) && (dst_cols_index + 2 < dst_cols_end)) ? sum.z : dst_data.z; - sum.w = ((dst_cols_index + 3 >= dst_cols_start) && (dst_cols_index + 3 < dst_cols_end)) ? sum.w : dst_data.w; - *((__global uchar4 *)(dst + dst_rows_index * dst_step + dst_cols_index)) = convert_uchar4_sat(sum); - } } -} -/////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////32FC1//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -__kernel void filter2D_C1_D5(__global float *src, int src_step, int src_offset_x, int src_offset_y, - __global float *dst, int dst_step, int dst_offset_x, int dst_offset_y, - __constant int *mat_kernel __attribute__((max_constant_size (16384))), - int cols,int rows, int operate_cols, int wholecols, int wholerows) -{ - int gX = get_global_id(0); - int gY = get_global_id(1); - - int lX = get_local_id(0); - - int groupX_size = get_local_size(0); - int groupX_id = get_group_id(0); - -#define dst_align (dst_offset_x & 3) - int cols_start_index_group = src_offset_x - dst_align + groupX_size * groupX_id - ANX; - int rows_start_index = src_offset_y + (gY << ROWS_PER_GROUP_BITS) - ANY; - - __local float local_data[LOCAL_MEM_STEP * ROWS_FETCH]; - if(((gY << 2) < rows)) +#endif + barrier(CLK_LOCAL_MEM_FENCE); + if(globalRow < rows && globalCol < cols) { - for(int i = 0; i < ROWS_FETCH; ++i) + T_SUM sum = (T_SUM)SUM_ZERO; + int filterIdx = 0; + for(int i = 0; i < FILTER_SIZE; i++) { - if((rows_start_index - src_offset_y) + i < rows + ANY) - { -#ifdef BORDER_CONSTANT - int selected_row = rows_start_index + i; - int selected_cols = cols_start_index_group + lX; - - float data = *((__global float *)((__global char *)src + selected_row * src_step + (selected_cols << 2))); - int con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX ] =data; + int offset = (i + localRow) * LOCAL_WIDTH; - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - - data = *((__global float *)((__global char *)src + selected_row * src_step + (selected_cols << 2))); - con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; - } -#else - int selected_row = ADDR_H(rows_start_index + i, 0, wholerows); - selected_row = ADDR_B(rows_start_index + i, wholerows, selected_row); - - int selected_cols = ADDR_L(cols_start_index_group + lX, 0, wholecols); - selected_cols = ADDR_R(cols_start_index_group + lX, wholecols, selected_cols); - - float data = *((__global float *)((__global char *)src + selected_row * src_step + (selected_cols << 2))); - local_data[i * LOCAL_MEM_STEP + lX] =data; - - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - selected_cols = ADDR_R(selected_cols, wholecols, selected_cols); - - data = *((__global float *)((__global char *)src + selected_row * src_step + (selected_cols << 2))); - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; - } -#endif + for(int j = 0; j < FILTER_SIZE; j++) + { + sum += CONVERT_TYPE_SUM(local_data[offset + j + localCol]) * mat_kernel[filterIdx++]; } } + dst[(globalRow)*dst_step + (globalCol) + dst_offset] = CONVERT_TYPE(sum); } - barrier(CLK_LOCAL_MEM_FENCE); - - int process_col = groupX_size * groupX_id + ((lX % THREADS_PER_ROW) << 2); - if(((gY << 2) < rows) && (process_col < operate_cols)) - { - int dst_cols_start = dst_offset_x; - int dst_cols_end = dst_offset_x + cols; - int dst_cols_index = (dst_offset_x + process_col) & 0xfffffffc; - - int dst_rows_end = dst_offset_y + rows; - int dst_rows_index = dst_offset_y + (gY << ROWS_PER_GROUP_BITS) + (lX >> THREADS_PER_ROW_BIT); +} - float4 dst_data = *((__global float4*)((__global char *)dst + dst_rows_index * dst_step + (dst_cols_index << 2))); +/// following is specific for 3x3 kernels - float4 sum = (float4)(0); - float4 data; +////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////Macro for define elements number per thread///////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define ANX 1 +#define ANY 1 - for(int i = 0; i < ANCHOR; i++) - { -#pragma unroll - for(int j = 0; j < ANCHOR; j++) - { - if(dst_rows_index < dst_rows_end) - { - int local_row = (lX >> THREADS_PER_ROW_BIT) + i; - int local_cols = ((lX % THREADS_PER_ROW) << ELEMENTS_PER_THREAD_BIT) + j; +#define ROWS_PER_GROUP 4 +#define ROWS_PER_GROUP_BITS 2 +#define ROWS_FETCH (ROWS_PER_GROUP + ANY + ANY) //(ROWS_PER_GROUP + anY * 2) - data = vload4(0, local_data+local_row * LOCAL_MEM_STEP + local_cols); - sum = sum + ((float)(mat_kernel[i * ANCHOR + j]) * data); - } - } - } +#define THREADS_PER_ROW 64 +#define THREADS_PER_ROW_BIT 6 - if(dst_rows_index < dst_rows_end) - { - sum.x = ((dst_cols_index + 0 >= dst_cols_start) && (dst_cols_index + 0 < dst_cols_end)) ? sum.x : dst_data.x; - sum.y = ((dst_cols_index + 1 >= dst_cols_start) && (dst_cols_index + 1 < dst_cols_end)) ? sum.y : dst_data.y; - sum.z = ((dst_cols_index + 2 >= dst_cols_start) && (dst_cols_index + 2 < dst_cols_end)) ? sum.z : dst_data.z; - sum.w = ((dst_cols_index + 3 >= dst_cols_start) && (dst_cols_index + 3 < dst_cols_end)) ? sum.w : dst_data.w; +#define ELEMENTS_PER_THREAD 4 +#define ELEMENTS_PER_THREAD_BIT 2 - *((__global float4 *)((__global char *)dst + dst_rows_index * dst_step + (dst_cols_index << 2))) = sum; - } - } -} +#define LOCAL_MEM_STEP 260 //divup((get_local_size(0) + anX * 2), 4) * 4 /////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////8uC4//////////////////////////////////////////////////////// +/////////////////////////////////////////8uC1//////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -__kernel void filter2D_C4_D0(__global uchar4 *src, int src_step, int src_offset_x, int src_offset_y, - __global uchar4 *dst, int dst_step, int dst_offset_x, int dst_offset_y, - __constant int *mat_kernel __attribute__((max_constant_size (16384))), - int cols,int rows, int operate_cols, int wholecols, int wholerows) +__kernel void filter2D_3x3( + __global T_IMG *src, + __global T_IMG *dst, + int src_step, + int dst_step, + __constant float *mat_kernel, + __local T_IMG *local_data, + int wholerows, + int wholecols, + int src_offset_x, + int src_offset_y, + int dst_offset_x, + int dst_offset_y, + int cols, + int rows, + int operate_cols +) { int gX = get_global_id(0); int gY = get_global_id(1); @@ -341,9 +279,7 @@ __kernel void filter2D_C4_D0(__global uchar4 *src, int src_step, int src_offset_ int cols_start_index_group = src_offset_x - dst_align + groupX_size * groupX_id - ANX; int rows_start_index = src_offset_y + (gY << ROWS_PER_GROUP_BITS) - ANY; - __local uchar4 local_data[LOCAL_MEM_STEP * ROWS_FETCH]; - - if(((gY << 2) < rows)) + if((gY << 2) < rows) { for(int i = 0; i < ROWS_FETCH; ++i) { @@ -353,19 +289,19 @@ __kernel void filter2D_C4_D0(__global uchar4 *src, int src_step, int src_offset_ int selected_row = rows_start_index + i; int selected_cols = cols_start_index_group + lX; - uchar4 data = *((__global uchar4*)((__global char*)src + selected_row * src_step + (selected_cols << 2))); - int con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; + T_IMG data = src[mad24(selected_row, src_step, selected_cols)]; + int con = selected_row >= 0 && selected_row < wholerows && selected_cols >= 0 && selected_cols < wholecols; data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX ] =data; + local_data[mad24(i, LOCAL_MEM_STEP, lX)] = data; if(lX < (ANX << 1)) { selected_cols = cols_start_index_group + lX + groupX_size; - data = *((__global uchar4*)((__global char*)src + selected_row * src_step + (selected_cols << 2))); - con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; + data = src[mad24(selected_row, src_step, selected_cols)]; + con = selected_row >= 0 && selected_row < wholerows && selected_cols >= 0 && selected_cols < wholecols; data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; + local_data[mad24(i, LOCAL_MEM_STEP, lX) + groupX_size] = data; } #else int selected_row = ADDR_H(rows_start_index + i, 0, wholerows); @@ -374,17 +310,17 @@ __kernel void filter2D_C4_D0(__global uchar4 *src, int src_step, int src_offset_ int selected_cols = ADDR_L(cols_start_index_group + lX, 0, wholecols); selected_cols = ADDR_R(cols_start_index_group + lX, wholecols, selected_cols); - uchar4 data = *((__global uchar4*)((__global char*)src + selected_row * src_step + (selected_cols << 2))); + T_IMG data = src[mad24(selected_row, src_step, selected_cols)]; - local_data[i * LOCAL_MEM_STEP + lX] =data; + local_data[mad24(i, LOCAL_MEM_STEP, lX)] = data; if(lX < (ANX << 1)) { selected_cols = cols_start_index_group + lX + groupX_size; selected_cols = ADDR_R(selected_cols, wholecols, selected_cols); - data = *((__global uchar4*)((__global char*)src + selected_row * src_step + (selected_cols << 2))); - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; + data = src[mad24(selected_row, src_step, selected_cols)]; + local_data[mad24(i, LOCAL_MEM_STEP, lX) + groupX_size] = data; } #endif } @@ -401,131 +337,40 @@ __kernel void filter2D_C4_D0(__global uchar4 *src, int src_step, int src_offset_ int dst_rows_end = dst_offset_y + rows; int dst_rows_index = dst_offset_y + (gY << ROWS_PER_GROUP_BITS) + (lX >> THREADS_PER_ROW_BIT); + dst = dst + mad24(dst_rows_index, dst_step, dst_cols_index); - uchar16 dst_data; - dst_data = *((__global uchar16*)((__global char *)dst + dst_rows_index * dst_step + (dst_cols_index << 2))); + T_IMGx4 dst_data = *(__global T_IMGx4 *)dst; - int16 sum = (int16)(0); - uchar16 data; + T_SUMx4 sum = (T_SUMx4)SUM_ZEROx4; + T_IMGx4 data; - for(int i = 0; i < ANCHOR; i++) + for(int i = 0; i < FILTER_SIZE; i++) { #pragma unroll - for(int j = 0; j < ANCHOR; j++) + for(int j = 0; j < FILTER_SIZE; j++) { if(dst_rows_index < dst_rows_end) { int local_row = (lX >> THREADS_PER_ROW_BIT) + i; int local_cols = ((lX % THREADS_PER_ROW) << ELEMENTS_PER_THREAD_BIT) + j; - data = vload16(0, (__local uchar *)(local_data+local_row * LOCAL_MEM_STEP + local_cols)); - sum = sum + (mat_kernel[i * ANCHOR + j] * convert_int16_sat(data)); + data = VLOAD4(0, (__local T_IMG_C1 *)(local_data + local_row * LOCAL_MEM_STEP + local_cols)); + sum = sum + (mat_kernel[i * FILTER_SIZE + j] * CONVERT_TYPE_SUMx4(data)); } } } - if(dst_rows_index < dst_rows_end) { - uchar16 sum1 = convert_uchar16_sat(sum); - sum1.s0123 = ((dst_cols_index + 0 >= dst_cols_start) && (dst_cols_index + 0 < dst_cols_end))? - sum1.s0123 : dst_data.s0123; - sum1.s4567 = ((dst_cols_index + 1 >= dst_cols_start) && (dst_cols_index + 1 < dst_cols_end))? - sum1.s4567 : dst_data.s4567; - sum1.s89ab = ((dst_cols_index + 2 >= dst_cols_start) && (dst_cols_index + 2 < dst_cols_end))? - sum1.s89ab : dst_data.s89ab; - sum1.scdef = ((dst_cols_index + 3 >= dst_cols_start) && (dst_cols_index + 3 < dst_cols_end))? - sum1.scdef : dst_data.scdef; - - *((__global uchar16*)((__global char *)dst + dst_rows_index * dst_step + (dst_cols_index << 2))) = sum1; + T_IMGx4 tmp_dst = CONVERT_TYPEx4(sum); + tmp_dst.SX = ((dst_cols_index + 0 >= dst_cols_start) && (dst_cols_index + 0 < dst_cols_end)) ? + tmp_dst.SX : dst_data.SX; + tmp_dst.SY = ((dst_cols_index + 1 >= dst_cols_start) && (dst_cols_index + 1 < dst_cols_end)) ? + tmp_dst.SY : dst_data.SY; + tmp_dst.SZ = ((dst_cols_index + 2 >= dst_cols_start) && (dst_cols_index + 2 < dst_cols_end)) ? + tmp_dst.SZ : dst_data.SZ; + tmp_dst.SW = ((dst_cols_index + 3 >= dst_cols_start) && (dst_cols_index + 3 < dst_cols_end)) ? + tmp_dst.SW : dst_data.SW; + *(__global T_IMGx4 *)dst = tmp_dst; } } } -/////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////32FC4//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// -#define ROWS_FETCH_C4 (1 + ANY + ANY) //(ROWS_PER_GROUP + anY * 2) -#define LOCAL_MEM_STEP_C4 260 //divup((get_local_size(0) + anX * 2), 4) * 4) -__kernel void filter2D_C4_D5(__global float4 *src, int src_step, int src_offset_x, int src_offset_y, - __global float4 *dst, int dst_step, int dst_offset_x, int dst_offset_y, - __constant int *mat_kernel __attribute__((max_constant_size (16384))), - int cols,int rows, int operate_cols, int wholecols, int wholerows) -{ - int gX = get_global_id(0); - int gY = get_global_id(1); - - int lX = get_local_id(0); - - int groupX_size = get_local_size(0); - int groupX_id = get_group_id(0); - - int cols_start_index_group = src_offset_x + groupX_size * groupX_id - ANX; - int rows_start_index = src_offset_y + gY - ANY; - - __local float4 local_data[LOCAL_MEM_STEP_C4 * ROWS_FETCH_C4]; - if((gY < rows) && (gX < (operate_cols + ANX + ANX))) - { - for(int i = 0; i < ROWS_FETCH_C4; ++i) - { - if((rows_start_index - src_offset_y) + i < rows + ANY) - { -#ifdef BORDER_CONSTANT - int selected_row = rows_start_index + i; - int selected_cols = cols_start_index_group + lX; - - float4 data = *((__global float4*)((__global char*)src + selected_row * src_step + (selected_cols << 4))); - int con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX ] =data; - - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - - data = *((__global float4*)((__global char*)src + selected_row * src_step + (selected_cols << 4))); - con = selected_row >=0 && selected_row < wholerows && selected_cols >=0 && selected_cols < wholecols; - data = con ? data : 0; - local_data[i * LOCAL_MEM_STEP + lX + groupX_size] =data; - } -#else - int selected_row = ADDR_H(rows_start_index + i, 0, wholerows); - selected_row = ADDR_B(rows_start_index + i, wholerows, selected_row); - - int selected_cols = ADDR_L(cols_start_index_group + lX, 0, wholecols); - selected_cols = ADDR_R(cols_start_index_group + lX, wholecols, selected_cols); - - float4 data = *((__global float4*)((__global char*)src + selected_row * src_step + (selected_cols << 4))); - local_data[i * LOCAL_MEM_STEP_C4 + lX] =data; - - if(lX < (ANX << 1)) - { - selected_cols = cols_start_index_group + lX + groupX_size; - selected_cols = ADDR_R(selected_cols, wholecols, selected_cols); - - data = *((__global float4*)((__global char*)src + selected_row * src_step + (selected_cols << 4))); - local_data[i * LOCAL_MEM_STEP_C4 + lX + groupX_size] =data; - } -#endif - } - } - } - barrier(CLK_LOCAL_MEM_FENCE); - - if((gY < rows) && (gX < operate_cols)) - { - int dst_cols_index = dst_offset_x + gX; - int dst_rows_index = dst_offset_y + gY; - - float4 sum = (float4)(0); - - for(int i = 0; i < ANCHOR; i++) - { - for(int j = 0; j < ANCHOR; j++) - { - int local_cols = lX + j; - sum = sum + ((float)mat_kernel[i * ANCHOR + j] * local_data[i * LOCAL_MEM_STEP_C4 + local_cols]); - } - } - - *((__global float4*)((__global char *)dst + dst_rows_index * dst_step + (dst_cols_index << 4))) = sum; - } -} diff --git a/modules/ocl/src/precomp.cpp b/modules/ocl/src/precomp.cpp deleted file mode 100644 index 766138c577..0000000000 --- a/modules/ocl/src/precomp.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. -// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// @Authors -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other oclMaterials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" -//CriticalSection cs; -/* End of file. */ diff --git a/modules/ocl/test/main.cpp b/modules/ocl/test/main.cpp index 48d21b9aed..05052f38f3 100644 --- a/modules/ocl/test/main.cpp +++ b/modules/ocl/test/main.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/precomp.cpp b/modules/ocl/test/precomp.cpp deleted file mode 100644 index 7d287004ee..0000000000 --- a/modules/ocl/test/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - - diff --git a/modules/ocl/test/test_arithm.cpp b/modules/ocl/test/test_arithm.cpp index d12cef0b22..149c172efa 100644 --- a/modules/ocl/test/test_arithm.cpp +++ b/modules/ocl/test/test_arithm.cpp @@ -54,7 +54,7 @@ //#define PRINT_TIME -#include "precomp.hpp" +#include "test_precomp.hpp" #include #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_blend.cpp b/modules/ocl/test/test_blend.cpp index fa1aea1727..9341981609 100644 --- a/modules/ocl/test/test_blend.cpp +++ b/modules/ocl/test/test_blend.cpp @@ -42,7 +42,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #include using namespace cv; diff --git a/modules/ocl/test/test_brute_force_matcher.cpp b/modules/ocl/test/test_brute_force_matcher.cpp index 84e5d4c772..4d0b45fb78 100644 --- a/modules/ocl/test/test_brute_force_matcher.cpp +++ b/modules/ocl/test/test_brute_force_matcher.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL namespace { diff --git a/modules/ocl/test/test_calib3d.cpp b/modules/ocl/test/test_calib3d.cpp index 950f19d3c0..7e5c4a4196 100644 --- a/modules/ocl/test/test_calib3d.cpp +++ b/modules/ocl/test/test_calib3d.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #include #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_canny.cpp b/modules/ocl/test/test_canny.cpp index b378b2281b..6c6ea4eddb 100644 --- a/modules/ocl/test/test_canny.cpp +++ b/modules/ocl/test/test_canny.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL //////////////////////////////////////////////////////// diff --git a/modules/ocl/test/test_color.cpp b/modules/ocl/test/test_color.cpp index efc96de235..b0a223091a 100644 --- a/modules/ocl/test/test_color.cpp +++ b/modules/ocl/test/test_color.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" using namespace cv; diff --git a/modules/ocl/test/test_fft.cpp b/modules/ocl/test/test_fft.cpp index e16de2454f..29a2b815a3 100644 --- a/modules/ocl/test/test_fft.cpp +++ b/modules/ocl/test/test_fft.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" using namespace std; #ifdef HAVE_CLAMDFFT //////////////////////////////////////////////////////////////////////////// diff --git a/modules/ocl/test/test_filters.cpp b/modules/ocl/test/test_filters.cpp index cfd57413e1..9a1264f8a4 100644 --- a/modules/ocl/test/test_filters.cpp +++ b/modules/ocl/test/test_filters.cpp @@ -48,7 +48,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL @@ -324,6 +324,35 @@ TEST_P(GaussianBlur, Mat) +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Filter2D +struct Filter2D : FilterTestBase +{ + int type; + cv::Size ksize; + int bordertype; + Point anchor; + virtual void SetUp() + { + type = GET_PARAM(0); + ksize = GET_PARAM(1); + bordertype = GET_PARAM(3); + Init(type); + anchor = Point(-1,-1); + } +}; + +TEST_P(Filter2D, Mat) +{ + cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0); + for(int j = 0; j < LOOP_TIMES; j++) + { + random_roi(); + cv::filter2D(mat1_roi, dst_roi, -1, kernel, anchor, 0.0, bordertype); + cv::ocl::filter2D(gmat1, gdst, -1, kernel, anchor, bordertype); + Near(1); + } +} INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine( Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4), Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)), @@ -331,7 +360,7 @@ INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine( Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101))); -INSTANTIATE_TEST_CASE_P(Filters, Laplacian, Combine( +INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine( Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(Size(3, 3)), Values(Size(0, 0)), //not use @@ -365,4 +394,10 @@ INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine( +INSTANTIATE_TEST_CASE_P(Filter, Filter2D, testing::Combine( + Values(CV_8UC1, CV_32FC1, CV_32FC4), + Values(Size(3, 3), Size(15, 15), Size(25, 25)), + Values(Size(0, 0)), //not use + Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REFLECT101, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT))); + #endif // HAVE_OPENCL diff --git a/modules/ocl/test/test_gemm.cpp b/modules/ocl/test/test_gemm.cpp index 5548456568..00d428770f 100644 --- a/modules/ocl/test/test_gemm.cpp +++ b/modules/ocl/test/test_gemm.cpp @@ -43,7 +43,7 @@ //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" using namespace std; #ifdef HAVE_CLAMDBLAS //////////////////////////////////////////////////////////////////////////// diff --git a/modules/ocl/test/test_hough.cpp b/modules/ocl/test/test_hough.cpp index 365e0dadb2..9e45076cd7 100644 --- a/modules/ocl/test/test_hough.cpp +++ b/modules/ocl/test/test_hough.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_imgproc.cpp b/modules/ocl/test/test_imgproc.cpp index 2734871d17..e60fc41115 100644 --- a/modules/ocl/test/test_imgproc.cpp +++ b/modules/ocl/test/test_imgproc.cpp @@ -51,7 +51,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_kmeans.cpp b/modules/ocl/test/test_kmeans.cpp index a29c879b83..ab4e340c94 100644 --- a/modules/ocl/test/test_kmeans.cpp +++ b/modules/ocl/test/test_kmeans.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_match_template.cpp b/modules/ocl/test/test_match_template.cpp index a393abdeb3..551c9ff12a 100644 --- a/modules/ocl/test/test_match_template.cpp +++ b/modules/ocl/test/test_match_template.cpp @@ -43,7 +43,7 @@ //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL //////////////////////////////////////////////////////////////////////////////// diff --git a/modules/ocl/test/test_matrix_operation.cpp b/modules/ocl/test/test_matrix_operation.cpp index 92d810818b..e8b5022324 100644 --- a/modules/ocl/test/test_matrix_operation.cpp +++ b/modules/ocl/test/test_matrix_operation.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_moments.cpp b/modules/ocl/test/test_moments.cpp index c2aefde225..9f4232738c 100644 --- a/modules/ocl/test/test_moments.cpp +++ b/modules/ocl/test/test_moments.cpp @@ -1,4 +1,4 @@ -#include "precomp.hpp" +#include "test_precomp.hpp" #include #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_objdetect.cpp b/modules/ocl/test/test_objdetect.cpp index d9c9a84e18..5a47d72f94 100644 --- a/modules/ocl/test/test_objdetect.cpp +++ b/modules/ocl/test/test_objdetect.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #include "opencv2/objdetect.hpp" using namespace std; diff --git a/modules/ocl/test/test_optflow.cpp b/modules/ocl/test/test_optflow.cpp index 941ade129e..4693d46ddf 100644 --- a/modules/ocl/test/test_optflow.cpp +++ b/modules/ocl/test/test_optflow.cpp @@ -43,7 +43,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #include #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/precomp.hpp b/modules/ocl/test/test_precomp.hpp similarity index 100% rename from modules/ocl/test/precomp.hpp rename to modules/ocl/test/test_precomp.hpp diff --git a/modules/ocl/test/test_pyramids.cpp b/modules/ocl/test/test_pyramids.cpp index 1bd188dea6..b7bc752d67 100644 --- a/modules/ocl/test/test_pyramids.cpp +++ b/modules/ocl/test/test_pyramids.cpp @@ -44,7 +44,7 @@ //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #include #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/test_sort.cpp b/modules/ocl/test/test_sort.cpp index f39f78e9bf..83326a5426 100644 --- a/modules/ocl/test/test_sort.cpp +++ b/modules/ocl/test/test_sort.cpp @@ -44,7 +44,7 @@ //M*/ #include #include -#include "precomp.hpp" +#include "test_precomp.hpp" using namespace std; using namespace cvtest; diff --git a/modules/ocl/test/test_split_merge.cpp b/modules/ocl/test/test_split_merge.cpp index 854ce309c2..9663f5321c 100644 --- a/modules/ocl/test/test_split_merge.cpp +++ b/modules/ocl/test/test_split_merge.cpp @@ -44,7 +44,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_OPENCL diff --git a/modules/ocl/test/utility.cpp b/modules/ocl/test/utility.cpp index d7f6732069..64da6e69c0 100644 --- a/modules/ocl/test/utility.cpp +++ b/modules/ocl/test/utility.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #define VARNAME(A) #A using namespace std; using namespace cv; diff --git a/modules/photo/perf/perf_precomp.cpp b/modules/photo/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/photo/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/photo/src/precomp.cpp b/modules/photo/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/photo/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/photo/test/test_precomp.cpp b/modules/photo/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/photo/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 2de187ceea..e94da958af 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -136,6 +136,7 @@ typedef Ptr Ptr_StereoBM; typedef Ptr Ptr_StereoSGBM; typedef Ptr Ptr_ChannelFeatureBuilder; +typedef Ptr Ptr_CLAHE; typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; diff --git a/modules/stitching/perf/perf_precomp.cpp b/modules/stitching/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/stitching/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/stitching/src/precomp.cpp b/modules/stitching/src/precomp.cpp deleted file mode 100644 index 390dbfbc6b..0000000000 --- a/modules/stitching/src/precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" \ No newline at end of file diff --git a/modules/stitching/test/test_precomp.cpp b/modules/stitching/test/test_precomp.cpp deleted file mode 100644 index 14a070e817..0000000000 --- a/modules/stitching/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" \ No newline at end of file diff --git a/modules/superres/perf/perf_precomp.cpp b/modules/superres/perf/perf_precomp.cpp deleted file mode 100644 index 81f16e8f14..0000000000 --- a/modules/superres/perf/perf_precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "perf_precomp.hpp" diff --git a/modules/superres/src/precomp.cpp b/modules/superres/src/precomp.cpp deleted file mode 100644 index 3c01a2596d..0000000000 --- a/modules/superres/src/precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" diff --git a/modules/superres/test/test_precomp.cpp b/modules/superres/test/test_precomp.cpp deleted file mode 100644 index 0fb6521809..0000000000 --- a/modules/superres/test/test_precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "test_precomp.hpp" diff --git a/modules/ts/src/precomp.cpp b/modules/ts/src/precomp.cpp deleted file mode 100644 index c149df18f9..0000000000 --- a/modules/ts/src/precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "precomp.hpp" diff --git a/modules/video/perf/perf_precomp.cpp b/modules/video/perf/perf_precomp.cpp deleted file mode 100644 index 8552ac3d42..0000000000 --- a/modules/video/perf/perf_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_precomp.hpp" diff --git a/modules/video/src/precomp.cpp b/modules/video/src/precomp.cpp deleted file mode 100644 index 3e0ec42de9..0000000000 --- a/modules/video/src/precomp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// Intel License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000, Intel Corporation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" - -/* End of file. */ diff --git a/modules/video/src/simpleflow.cpp b/modules/video/src/simpleflow.cpp index f987b42ee8..6aa8f7d07a 100644 --- a/modules/video/src/simpleflow.cpp +++ b/modules/video/src/simpleflow.cpp @@ -319,7 +319,7 @@ static Mat upscaleOpticalFlow(int new_rows, static Mat calcIrregularityMat(const Mat& flow, int radius) { const int rows = flow.rows; const int cols = flow.cols; - Mat irregularity(rows, cols, CV_32F); + Mat irregularity = Mat::zeros(rows, cols, CV_32F); for (int r = 0; r < rows; ++r) { const int start_row = std::max(0, r - radius); const int end_row = std::min(rows - 1, r + radius); @@ -441,7 +441,7 @@ static void extrapolateFlow(Mat& flow, const Mat& speed_up) { const int rows = flow.rows; const int cols = flow.cols; - Mat done(rows, cols, CV_8U); + Mat done = Mat::zeros(rows, cols, CV_8U); for (int r = 0; r < rows; ++r) { for (int c = 0; c < cols; ++c) { if (!done.at(r, c) && speed_up.at(r, c) > 1) { @@ -540,8 +540,8 @@ CV_EXPORTS_W void calcOpticalFlowSF(InputArray _from, Mat mask = Mat::ones(curr_from.size(), CV_8U); Mat mask_inv = Mat::ones(curr_from.size(), CV_8U); - Mat flow(curr_from.size(), CV_32FC2); - Mat flow_inv(curr_to.size(), CV_32FC2); + Mat flow = Mat::zeros(curr_from.size(), CV_32FC2); + Mat flow_inv = Mat::zeros(curr_to.size(), CV_32FC2); Mat confidence; Mat confidence_inv; diff --git a/modules/video/test/test_precomp.cpp b/modules/video/test/test_precomp.cpp deleted file mode 100644 index 5956e13e3e..0000000000 --- a/modules/video/test/test_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "test_precomp.hpp" diff --git a/modules/videostab/src/precomp.cpp b/modules/videostab/src/precomp.cpp deleted file mode 100644 index 111385282e..0000000000 --- a/modules/videostab/src/precomp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" diff --git a/modules/world/src/precomp.cpp b/modules/world/src/precomp.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/platforms/scripts/cmake_winrt.cmd b/platforms/scripts/cmake_winrt.cmd index df70e856c5..3cdff97b75 100644 --- a/platforms/scripts/cmake_winrt.cmd +++ b/platforms/scripts/cmake_winrt.cmd @@ -1,6 +1,9 @@ mkdir build_winrt_arm cd build_winrt_arm -rem call "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat" +set msvc_path=C:\Program Files\Microsoft Visual Studio 11.0 -cmake.exe -GNinja -DWITH_TBB=ON -DBUILD_TBB=ON -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DCMAKE_TOOLCHAIN_FILE=..\winrt\arm.winrt.toolchain.cmake ..\.. +call "%msvc_path%\Common7\Tools\VsDevCmd.bat" +call "%msvc_path%\VC\bin\x86_arm\vcvarsx86_arm.bat" + +cmake.exe -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_WINRT_MODE=ON -DWITH_FFMPEG=OFF -DWITH_MSMF=OFF -DWITH_DSHOW=OFF -DWITH_VFW=OFF -DWITH_TIFF=OFF -DWITH_OPENEXR=OFF -DWITH_CUDA=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_java=OFF -DCMAKE_TOOLCHAIN_FILE=..\winrt\arm.winrt.toolchain.cmake %* ..\.. \ No newline at end of file diff --git a/samples/c/mushroom.cpp b/samples/c/mushroom.cpp index 5763b12464..60eb9f066c 100644 --- a/samples/c/mushroom.cpp +++ b/samples/c/mushroom.cpp @@ -90,7 +90,7 @@ static int mushroom_read_database( const char* filename, CvMat** data, CvMat** m } cvReleaseMemStorage( &storage ); - delete el_ptr; + delete [] el_ptr; return 1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp index 53120b7800..0536404a1a 100644 --- a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp @@ -15,7 +15,6 @@ using namespace cv; Mat src, dst; int top, bottom, left, right; int borderType; -Scalar value; const char* window_name = "copyMakeBorder Demo"; RNG rng(12345); @@ -64,7 +63,7 @@ int main( int, char** argv ) else if( (char)c == 'r' ) { borderType = BORDER_REPLICATE; } - value = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) ); + Scalar value( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) ); copyMakeBorder( src, dst, top, bottom, left, right, borderType, value ); imshow( window_name, dst ); diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index a14c5907ab..b85c760e7e 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -5,7 +5,6 @@ SET(OPENCV_GPU_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc ope opencv_gpuarithm opencv_gpufilters opencv_gpuwarping opencv_gpuimgproc opencv_gpufeatures2d opencv_gpuoptflow opencv_gpubgsegm opencv_gpustereo opencv_gpulegacy) - ocv_check_dependencies(${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) @@ -32,6 +31,10 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ocv_include_directories(${CUDA_INCLUDE_DIRS}) endif() + if(HAVE_OPENCL) + ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/ocl/include") + endif() + if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") endif() @@ -51,6 +54,10 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) target_link_libraries(${the_target} opencv_gpucodec) endif() + if(HAVE_OPENCL) + target_link_libraries(${the_target} opencv_ocl) + endif() + set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${project}-example-${name}" PROJECT_LABEL "(EXAMPLE_${project_upper}) ${name}") @@ -84,4 +91,3 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32) DESTINATION share/OpenCV/samples/${project} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) endif() - diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 4f3b4e20e9..5b6d6f193e 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -8,11 +8,16 @@ #include "opencv2/contrib.hpp" #include "opencv2/superres.hpp" #include "opencv2/superres/optical_flow.hpp" +#include "opencv2/opencv_modules.hpp" + +#if defined(HAVE_OPENCV_OCL) +#include "opencv2/ocl/ocl.hpp" +#endif using namespace std; using namespace cv; using namespace cv::superres; - +bool useOclChanged; #define MEASURE_TIME(op) \ { \ TickMeter tm; \ @@ -50,9 +55,38 @@ static Ptr createOptFlow(const string& name, bool useGpu) } return 0; } - +#if defined(HAVE_OPENCV_OCL) +static Ptr createOptFlow(const string& name) +{ + if (name == "farneback") + { + return createOptFlow_Farneback_OCL(); + } + else if (name == "simple") + { + useOclChanged = true; + std::cout<<"simple on OpenCL has not been implemented. Use CPU instead!\n"; + return createOptFlow_Simple(); + } + else if (name == "tvl1") + return createOptFlow_DualTVL1_OCL(); + else if (name == "brox") + { + std::cout<<"brox has not been implemented!\n"; + return NULL; + } + else if (name == "pyrlk") + return createOptFlow_PyrLK_OCL(); + else + { + cerr << "Incorrect Optical Flow algorithm - " << name << endl; + } + return 0; +} +#endif int main(int argc, const char* argv[]) { + useOclChanged = false; CommandLineParser cmd(argc, argv, "{ v video | | Input video }" "{ o output | | Output video }" @@ -60,7 +94,7 @@ int main(int argc, const char* argv[]) "{ i iterations | 180 | Iteration count }" "{ t temporal | 4 | Radius of the temporal search area }" "{ f flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }" - "{ gpu | false | Use GPU }" + "{ g | false | CPU as default device, cuda for CUDA and ocl for OpenCL }" "{ h help | false | Print help message }" ); @@ -77,25 +111,79 @@ int main(int argc, const char* argv[]) const int iterations = cmd.get("iterations"); const int temporalAreaRadius = cmd.get("temporal"); const string optFlow = cmd.get("flow"); - const bool useGpu = cmd.get("gpu"); + string gpuOption = cmd.get("gpu"); + + std::transform(gpuOption.begin(), gpuOption.end(), gpuOption.begin(), ::tolower); + + bool useCuda = false; + bool useOcl = false; + + if(gpuOption.compare("ocl") == 0) + useOcl = true; + else if(gpuOption.compare("cuda") == 0) + useCuda = true; +#ifndef HAVE_OPENCV_OCL + if(useOcl) + { + { + cout<<"OPENCL is not compiled\n"; + return 0; + } + } +#endif +#if defined(HAVE_OPENCV_OCL) + std::vectorinfo; + if(useCuda) + { + CV_Assert(!useOcl); + info.clear(); + } + + if(useOcl) + { + CV_Assert(!useCuda); + cv::ocl::getDevice(info); + } +#endif Ptr superRes; - if (useGpu) - superRes = createSuperResolution_BTVL1_GPU(); + + +#if defined(HAVE_OPENCV_OCL) + if(useOcl) + { + Ptr of = createOptFlow(optFlow); + if (of.empty()) + exit(-1); + if(useOclChanged) + { + superRes = createSuperResolution_BTVL1(); + useOcl = !useOcl; + }else + superRes = createSuperResolution_BTVL1_OCL(); + superRes->set("opticalFlow", of); + } else - superRes = createSuperResolution_BTVL1(); +#endif + { + if (useCuda) + superRes = createSuperResolution_BTVL1_GPU(); + else + superRes = createSuperResolution_BTVL1(); + + Ptr of = createOptFlow(optFlow, useCuda); + + if (of.empty()) + exit(-1); + superRes->set("opticalFlow", of); + } superRes->set("scale", scale); superRes->set("iterations", iterations); superRes->set("temporalAreaRadius", temporalAreaRadius); - Ptr of = createOptFlow(optFlow, useGpu); - if (of.empty()) - exit(-1); - superRes->set("opticalFlow", of); - Ptr frameSource; - if (useGpu) + if (useCuda) { // Try to use gpu Video Decoding try @@ -121,7 +209,11 @@ int main(int argc, const char* argv[]) cout << "Iterations : " << iterations << endl; cout << "Temporal radius : " << temporalAreaRadius << endl; cout << "Optical Flow : " << optFlow << endl; - cout << "Mode : " << (useGpu ? "GPU" : "CPU") << endl; +#if defined(HAVE_OPENCV_OCL) + cout << "Mode : " << (useCuda ? "CUDA" : useOcl? "OpenCL" : "CPU") << endl; +#else + cout << "Mode : " << (useGpu ? "CUDA" : "CPU") << endl; +#endif } superRes->setInput(frameSource); @@ -131,10 +223,30 @@ int main(int argc, const char* argv[]) for (int i = 0;; ++i) { cout << '[' << setw(3) << i << "] : "; - Mat result; - MEASURE_TIME(superRes->nextFrame(result)); +#if defined(HAVE_OPENCV_OCL) + cv::ocl::oclMat result_; + + if(useOcl) + { + MEASURE_TIME(superRes->nextFrame(result_)); + } + else +#endif + { + MEASURE_TIME(superRes->nextFrame(result)); + } + +#ifdef HAVE_OPENCV_OCL + if(useOcl) + { + if(!result_.empty()) + { + result_.download(result); + } + } +#endif if (result.empty()) break;