diff --git a/.gitignore b/.gitignore index 46d3499e5..0d0dcf8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.autosave *.pyc *.user +*~ .*.swp .DS_Store .sw[a-z] diff --git a/.tgitconfig b/.tgitconfig new file mode 100644 index 000000000..5fa522d23 --- /dev/null +++ b/.tgitconfig @@ -0,0 +1,2 @@ +[tgit] + icon = doc/opencv.ico diff --git a/3rdparty/include/opencl/1.2/CL/cl.hpp b/3rdparty/include/opencl/1.2/CL/cl.hpp index 0480e3116..2502d4c52 100644 --- a/3rdparty/include/opencl/1.2/CL/cl.hpp +++ b/3rdparty/include/opencl/1.2/CL/cl.hpp @@ -210,7 +210,7 @@ #include #endif -#if defined(linux) || defined(__APPLE__) || defined(__MACOSX) +#if defined(__linux__) || defined(__APPLE__) || defined(__MACOSX) #include #include diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so index 5b618a874..aac6634b4 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so index 846fc88bd..d523f69de 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so index 80bf459cc..e386bf4f9 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so index e5cc7d296..028ab7d1e 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so index d3cf3b124..48cbdd096 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so index 6498151ba..7fe50875c 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so index 58bef3455..15827d818 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so index ce69b52ea..ec1edfb04 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so differ diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so index 3e65fb171..4d777edf8 100755 Binary files a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r2.2.0.so b/3rdparty/lib/armeabi/libnative_camera_r2.2.0.so index 68805b589..1707a8850 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r2.2.0.so and b/3rdparty/lib/armeabi/libnative_camera_r2.2.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r2.3.3.so b/3rdparty/lib/armeabi/libnative_camera_r2.3.3.so index 88ac3f7e3..fb4b125fd 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r2.3.3.so and b/3rdparty/lib/armeabi/libnative_camera_r2.3.3.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r3.0.1.so b/3rdparty/lib/armeabi/libnative_camera_r3.0.1.so index fa41cb250..96b264d0e 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r3.0.1.so and b/3rdparty/lib/armeabi/libnative_camera_r3.0.1.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.0.0.so b/3rdparty/lib/armeabi/libnative_camera_r4.0.0.so index a305c2b00..179eef9a9 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.0.0.so and b/3rdparty/lib/armeabi/libnative_camera_r4.0.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.0.3.so b/3rdparty/lib/armeabi/libnative_camera_r4.0.3.so index 8c34357cc..165dc463c 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.0.3.so and b/3rdparty/lib/armeabi/libnative_camera_r4.0.3.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so b/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so index a01ee15e2..a9a5d7da7 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so and b/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so b/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so index a8ff89465..9037c6860 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so and b/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.3.0.so b/3rdparty/lib/armeabi/libnative_camera_r4.3.0.so index aa1cfd844..026f0b48b 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.3.0.so and b/3rdparty/lib/armeabi/libnative_camera_r4.3.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.4.0.so b/3rdparty/lib/armeabi/libnative_camera_r4.4.0.so index 264f6f217..6aebec923 100755 Binary files a/3rdparty/lib/armeabi/libnative_camera_r4.4.0.so and b/3rdparty/lib/armeabi/libnative_camera_r4.4.0.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.0.3.so b/3rdparty/lib/mips/libnative_camera_r4.0.3.so index 14dfaf23b..6dee89780 100755 Binary files a/3rdparty/lib/mips/libnative_camera_r4.0.3.so and b/3rdparty/lib/mips/libnative_camera_r4.0.3.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.1.1.so b/3rdparty/lib/mips/libnative_camera_r4.1.1.so index a37474256..71a6354ac 100755 Binary files a/3rdparty/lib/mips/libnative_camera_r4.1.1.so and b/3rdparty/lib/mips/libnative_camera_r4.1.1.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.2.0.so b/3rdparty/lib/mips/libnative_camera_r4.2.0.so index 31cbb3a99..21bcffb4a 100755 Binary files a/3rdparty/lib/mips/libnative_camera_r4.2.0.so and b/3rdparty/lib/mips/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.3.0.so b/3rdparty/lib/mips/libnative_camera_r4.3.0.so index 379fc7003..653c2f1ca 100755 Binary files a/3rdparty/lib/mips/libnative_camera_r4.3.0.so and b/3rdparty/lib/mips/libnative_camera_r4.3.0.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.4.0.so b/3rdparty/lib/mips/libnative_camera_r4.4.0.so index 0f6c83713..8d6fdf2bc 100755 Binary files a/3rdparty/lib/mips/libnative_camera_r4.4.0.so and b/3rdparty/lib/mips/libnative_camera_r4.4.0.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r2.3.3.so b/3rdparty/lib/x86/libnative_camera_r2.3.3.so index 5c46b1607..a47b8b2ce 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r2.3.3.so and b/3rdparty/lib/x86/libnative_camera_r2.3.3.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r3.0.1.so b/3rdparty/lib/x86/libnative_camera_r3.0.1.so index 77512e5de..faa13461f 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r3.0.1.so and b/3rdparty/lib/x86/libnative_camera_r3.0.1.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.0.3.so b/3rdparty/lib/x86/libnative_camera_r4.0.3.so index b5de08299..2d2fb8eb1 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r4.0.3.so and b/3rdparty/lib/x86/libnative_camera_r4.0.3.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.1.1.so b/3rdparty/lib/x86/libnative_camera_r4.1.1.so index 867137410..f40da0d9d 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r4.1.1.so and b/3rdparty/lib/x86/libnative_camera_r4.1.1.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.2.0.so b/3rdparty/lib/x86/libnative_camera_r4.2.0.so index 52e9a5792..0d4ac03b5 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r4.2.0.so and b/3rdparty/lib/x86/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.3.0.so b/3rdparty/lib/x86/libnative_camera_r4.3.0.so index af898ccad..7e1c5803a 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r4.3.0.so and b/3rdparty/lib/x86/libnative_camera_r4.3.0.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.4.0.so b/3rdparty/lib/x86/libnative_camera_r4.4.0.so index 108862f56..37ab6d080 100755 Binary files a/3rdparty/lib/x86/libnative_camera_r4.4.0.so and b/3rdparty/lib/x86/libnative_camera_r4.4.0.so differ diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index dda9cd255..7b3dcb08a 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -46,5 +46,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 8d622f24f..02d71ade2 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -39,5 +39,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index 42b6263e5..8d3d5f497 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -55,5 +55,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index 6c34fb5e3..addbb5551 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -115,5 +115,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libtiff/tif_config.h.cmakein b/3rdparty/libtiff/tif_config.h.cmakein index 182f2833d..24f58119b 100644 --- a/3rdparty/libtiff/tif_config.h.cmakein +++ b/3rdparty/libtiff/tif_config.h.cmakein @@ -54,7 +54,7 @@ /* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#define HOST_BIGENDIAN 0 +#define HOST_BIGENDIAN @WORDS_BIGENDIAN@ /* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ #define HOST_FILLORDER FILLORDER_LSB2MSB @@ -156,15 +156,7 @@ /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -/* # undef WORDS_BIGENDIAN */ -# endif -#endif +#cmakedefine WORDS_BIGENDIAN 1 /* Support Deflate compression */ #define ZIP_SUPPORT 1 diff --git a/3rdparty/openexr/CMakeLists.txt b/3rdparty/openexr/CMakeLists.txt index 2b11436e1..c4facad2f 100644 --- a/3rdparty/openexr/CMakeLists.txt +++ b/3rdparty/openexr/CMakeLists.txt @@ -62,7 +62,7 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() set(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATHS} PARENT_SCOPE) diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index 272c195b3..e16f6cd38 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -248,9 +248,9 @@ if(ENABLE_SOLUTION_FOLDERS) endif() ocv_install_target(tbb EXPORT OpenCVModules - RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main + RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs + ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev ) # get TBB version diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index f1b28fd39..410f2420b 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -95,5 +95,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 2973f4ca0..b610ecf97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,7 @@ OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O" ON IF IOS) OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa" OFF IF APPLE ) OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" ON IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) ) +OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" ON IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) ) OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) ) OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS AND NOT APPLE) ) @@ -141,7 +142,7 @@ OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ON IF (NOT IOS) ) -OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF IF (NOT ANDROID AND NOT APPLE) ) +OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF IF (NOT ANDROID) ) OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_PNG "Include PNG support" ON) OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" ON IF (NOT ANDROID AND NOT IOS) ) @@ -197,7 +198,7 @@ OCV_OPTION(INSTALL_C_EXAMPLES "Install C examples" OFF ) OCV_OPTION(INSTALL_PYTHON_EXAMPLES "Install Python examples" OFF ) OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples" OFF IF ANDROID ) OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS AND BUILD_SHARED_LIBS) ) - +OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binaries and test data" OFF) # OpenCV build options # =================================================== @@ -205,6 +206,7 @@ OCV_OPTION(ENABLE_DYNAMIC_CUDA "Enabled dynamic CUDA linkage" OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS) ) OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) IF (CMAKE_VERSION VERSION_GREATER "2.8.0") ) OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CMAKE_COMPILER_IS_GNUCXX ) +OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CMAKE_COMPILER_IS_GNUCXX ) OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CMAKE_COMPILER_IS_GNUCXX AND NOT (APPLE AND CMAKE_COMPILER_IS_CLANGCXX) ) OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) ) OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) @@ -220,6 +222,7 @@ OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF ) OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF ) OCV_OPTION(ENABLE_WINRT_MODE "Build with Windows Runtime support" OFF IF WIN32 ) +OCV_OPTION(ENABLE_WINRT_MODE_NATIVE "Build with Windows Runtime native C++ support" OFF IF WIN32 ) # uncategorized options # =================================================== @@ -267,13 +270,27 @@ if(WIN32) message(STATUS "Can't detect runtime and/or arch") set(OpenCV_INSTALL_BINARIES_PREFIX "") endif() +elseif(ANDROID) + set(OpenCV_INSTALL_BINARIES_PREFIX "sdk/native/") else() set(OpenCV_INSTALL_BINARIES_PREFIX "") endif() -set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples") +if(ANDROID) + set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples/${ANDROID_NDK_ABI_NAME}") +else() + set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples") +endif() -set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin") +if(ANDROID) + set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin/${ANDROID_NDK_ABI_NAME}") +else() + set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin") +endif() + +if(NOT OPENCV_TEST_INSTALL_PATH) + set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}") +endif() if(ANDROID) set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}") @@ -282,6 +299,7 @@ if(ANDROID) set(OPENCV_3P_LIB_INSTALL_PATH sdk/native/3rdparty/libs/${ANDROID_NDK_ABI_NAME}) set(OPENCV_CONFIG_INSTALL_PATH sdk/native/jni) set(OPENCV_INCLUDE_INSTALL_PATH sdk/native/jni/include) + set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native) else() set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib") set(3P_LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/3rdparty/lib${LIB_SUFFIX}") @@ -292,9 +310,11 @@ else() set(OPENCV_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}lib${LIB_SUFFIX}") endif() set(OPENCV_3P_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib${LIB_SUFFIX}") + set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native) else() set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX}) set(OPENCV_3P_LIB_INSTALL_PATH share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}) + set(OPENCV_SAMPLES_SRC_INSTALL_PATH share/OpenCV/samples) endif() set(OPENCV_INCLUDE_INSTALL_PATH "include") @@ -425,6 +445,19 @@ endif() include(cmake/OpenCVPCHSupport.cmake) include(cmake/OpenCVModule.cmake) +# ---------------------------------------------------------------------------- +# Detect endianness of build platform +# ---------------------------------------------------------------------------- + +if(CMAKE_SYSTEM_NAME STREQUAL iOS) + # test_big_endian needs try_compile, which doesn't work for iOS + # http://public.kitware.com/Bug/view.php?id=12288 + set(WORDS_BIGENDIAN 0) +else() + include(TestBigEndian) + test_big_endian(WORDS_BIGENDIAN) +endif() + # ---------------------------------------------------------------------------- # Detect 3rd-party libraries # ---------------------------------------------------------------------------- @@ -434,7 +467,6 @@ include(cmake/OpenCVFindLibsGUI.cmake) include(cmake/OpenCVFindLibsVideo.cmake) include(cmake/OpenCVFindLibsPerf.cmake) - # ---------------------------------------------------------------------------- # Detect other 3rd-party libraries/tools # ---------------------------------------------------------------------------- @@ -470,6 +502,9 @@ if(WITH_OPENCL) include(cmake/OpenCVDetectOpenCL.cmake) endif() +# --- VTK support --- +include(cmake/OpenCVDetectVTK.cmake) + # ---------------------------------------------------------------------------- # Add CUDA libraries (needed for apps/tools, samples) # ---------------------------------------------------------------------------- @@ -557,6 +592,49 @@ include(cmake/OpenCVGenConfig.cmake) # Generate Info.plist for the IOS framework include(cmake/OpenCVGenInfoPlist.cmake) +# Generate environment setup file +if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX) + if(ANDROID) + get_filename_component(TEST_PATH ${OPENCV_TEST_INSTALL_PATH} DIRECTORY) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_android.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) + install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT tests) + else() + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" + DESTINATION /etc/profile.d/ COMPONENT tests) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_unix.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) + install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" + DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) + + endif() +endif() + +if(NOT OPENCV_README_FILE) + if(ANDROID) + set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android) + endif() +endif() + +if(NOT OPENCV_LICENSE_FILE) + set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) +endif() + +# for UNIX it does not make sense as LICENSE and readme will be part of the package automatically +if(ANDROID OR NOT UNIX) + install(FILES ${OPENCV_LICENSE_FILE} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs) + if(OPENCV_README_FILE) + install(FILES ${OPENCV_README_FILE} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs) + endif() +endif() + # ---------------------------------------------------------------------------- # Summary: # ---------------------------------------------------------------------------- @@ -666,7 +744,7 @@ endif() if(WIN32) status("") status(" Windows RT support:" HAVE_WINRT THEN YES ELSE NO) - if (ENABLE_WINRT_MODE) + if (ENABLE_WINRT_MODE OR ENABLE_WINRT_MODE_NATIVE) status(" Windows SDK v8.0:" ${WINDOWS_SDK_PATH}) status(" Visual Studio 2012:" ${VISUAL_STUDIO_PATH}) endif() @@ -704,6 +782,7 @@ else() endif() status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO) +status(" VTK support:" HAVE_VTK THEN "YES (ver ${VTK_VERSION})" ELSE NO) # ========================== MEDIA IO ========================== status("") @@ -974,3 +1053,9 @@ ocv_finalize_status() if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree") endif() + +# ---------------------------------------------------------------------------- +# CPack stuff +# ---------------------------------------------------------------------------- + +include(cmake/OpenCVPackaging.cmake) diff --git a/doc/license.txt b/LICENSE similarity index 65% rename from doc/license.txt rename to LICENSE index 8824228d0..5e32d88b4 100644 --- a/doc/license.txt +++ b/LICENSE @@ -1,16 +1,11 @@ -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. +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) 2008-2011, Willow Garage Inc., all rights reserved. -Third party copyrights are property of their respective owners. + (3-clause BSD License) Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -22,13 +17,14 @@ are permitted provided that the following conditions are met: 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. + * Neither the names of the copyright holders nor the names of the contributors + may 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, +In no event shall copyright holders 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 diff --git a/README.md b/README.md index 403f118ee..3a26ad855 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ### OpenCV: Open Source Computer Vision Library +[![Gittip](http://img.shields.io/gittip/OpenCV.png)](https://www.gittip.com/OpenCV/) + #### Resources * Homepage: @@ -18,6 +20,3 @@ Summary of guidelines: * Include tests and documentation; * Clean up "oops" commits before submitting; * Follow the coding style guide. - -[![Donate OpenCV project](http://opencv.org/wp-content/uploads/2013/07/gittip1.png)](https://www.gittip.com/OpenCV/) -[![Donate OpenCV project](http://opencv.org/wp-content/uploads/2013/07/paypal-donate-button.png)](https://www.paypal.com/cgi-bin/webscr?item_name=Donation+to+OpenCV&cmd=_donations&business=accountant%40opencv.org) \ No newline at end of file diff --git a/apps/haartraining/CMakeLists.txt b/apps/haartraining/CMakeLists.txt index cdc280556..d8a3c55c8 100644 --- a/apps/haartraining/CMakeLists.txt +++ b/apps/haartraining/CMakeLists.txt @@ -71,14 +71,14 @@ set_target_properties(opencv_performance PROPERTIES if(INSTALL_CREATE_DISTRIB) if(BUILD_SHARED_LIBS) - install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) - install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) - install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) + install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) + install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) + install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) endif() else() - install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) - install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) - install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) + install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) + install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) + install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) endif() if(ENABLE_SOLUTION_FOLDERS) diff --git a/apps/haartraining/cvclassifier.h b/apps/haartraining/cvclassifier.h index df644ed17..3faec500a 100644 --- a/apps/haartraining/cvclassifier.h +++ b/apps/haartraining/cvclassifier.h @@ -338,7 +338,7 @@ typedef enum CvBoostType CV_LKCLASS = 5, /* classification (K class problem) */ CV_LSREG = 6, /* least squares regression */ CV_LADREG = 7, /* least absolute deviation regression */ - CV_MREG = 8, /* M-regression (Huber loss) */ + CV_MREG = 8 /* M-regression (Huber loss) */ } CvBoostType; /****************************************************************************************\ diff --git a/apps/traincascade/CMakeLists.txt b/apps/traincascade/CMakeLists.txt index 8f6fbe034..941c0ec71 100644 --- a/apps/traincascade/CMakeLists.txt +++ b/apps/traincascade/CMakeLists.txt @@ -35,8 +35,8 @@ endif() if(INSTALL_CREATE_DISTRIB) if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) endif() else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) endif() diff --git a/cmake/OpenCVCRTLinkage.cmake b/cmake/OpenCVCRTLinkage.cmake index 8a297c685..5265e3e8a 100644 --- a/cmake/OpenCVCRTLinkage.cmake +++ b/cmake/OpenCVCRTLinkage.cmake @@ -9,7 +9,7 @@ set(HAVE_WINRT FALSE) # 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 "") +if(WINDOWS_SDK_PATH STREQUAL "") set(HAVE_MSPDK FALSE) message(STATUS "Windows Platform SDK 8.0 was not found") else() @@ -19,7 +19,7 @@ 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 "") +if(VISUAL_STUDIO_PATH STREQUAL "") set(HAVE_MSVC2012 FALSE) message(STATUS "Visual Studio 2012 was not found") else() @@ -30,11 +30,15 @@ try_compile(HAVE_WINRT_SDK "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp") -if (ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK) +if(ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK) set(HAVE_WINRT TRUE) + set(HAVE_WINRT_CX TRUE) +elseif(ENABLE_WINRT_MODE_NATIVE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK) + set(HAVE_WINRT TRUE) + set(HAVE_WINRT_CX FALSE) endif() -if (HAVE_WINRT) +if(HAVE_WINRT) add_definitions(/DWINVER=0x0602 /DNTDDI_VERSION=NTDDI_WIN8 /D_WIN32_WINNT=0x0602) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /appcontainer") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /appcontainer") diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index a4b039280..d525609d1 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -187,6 +187,11 @@ if(CMAKE_COMPILER_IS_GNUCXX) add_extra_compiler_option(-ffunction-sections) endif() + if(ENABLE_COVERAGE) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} --coverage") + set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} --coverage") + endif() + set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG") set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") endif() diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index 393dbb62d..273758967 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -180,7 +180,7 @@ unset(__android_project_chain CACHE) # add_android_project(target_name ${path} NATIVE_DEPS opencv_core LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11) macro(add_android_project target path) # parse arguments - set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST) + set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST EMBED_CUDA FORCE_EMBED_OPENCV) set(__varname "android_proj_") foreach(v ${android_proj_arglist}) set(${__varname}${v} "") @@ -303,6 +303,46 @@ macro(add_android_project target path) add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}") endif() endif() + + # copy opencv_java, tbb if it is shared and dynamicuda if present if FORCE_EMBED_OPENCV flag is set + if(android_proj_FORCE_EMBED_OPENCV) + set(native_deps ${android_proj_NATIVE_DEPS}) + # filter out gpu module as it is always static library on Android + list(REMOVE_ITEM native_deps "opencv_gpu") + if(ENABLE_DYNAMIC_CUDA) + list(APPEND native_deps "opencv_dynamicuda") + endif() + foreach(lib ${native_deps}) + get_property(f TARGET ${lib} PROPERTY LOCATION) + get_filename_component(f_name ${f} NAME) + add_custom_command( + OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}" + COMMAND ${CMAKE_COMMAND} -E copy "${f}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}" + DEPENDS "${lib}" VERBATIM + COMMENT "Embedding ${f}") + list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}") + endforeach() + endif() + + # copy all needed CUDA libs to project if EMBED_CUDA flag is present + if(android_proj_EMBED_CUDA) + set(android_proj_culibs ${CUDA_npp_LIBRARY_ABS} ${CUDA_LIBRARIES_ABS}) + if(HAVE_CUFFT) + list(INSERT android_proj_culibs 0 ${CUDA_cufft_LIBRARY_ABS}) + endif() + if(HAVE_CUBLAS) + list(INSERT android_proj_culibs 0 ${CUDA_cublas_LIBRARY_ABS}) + endif() + foreach(lib ${android_proj_culibs}) + get_filename_component(f "${lib}" NAME) + add_custom_command( + OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}" + COMMAND ${CMAKE_COMMAND} -E copy "${lib}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}" + DEPENDS "${lib}" VERBATIM + COMMENT "Embedding ${f}") + list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}") + endforeach() + endif() endif() # build java part @@ -344,20 +384,20 @@ macro(add_android_project target path) add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${android_proj_bin_dir}/bin/${target}-debug.apk" "${OpenCV_BINARY_DIR}/bin/${target}.apk") if(INSTALL_ANDROID_EXAMPLES AND "${target}" MATCHES "^example-") #apk - install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT samples) get_filename_component(sample_dir "${path}" NAME) #java part list(REMOVE_ITEM android_proj_files ${ANDROID_MANIFEST_FILE}) foreach(f ${android_proj_files} ${ANDROID_MANIFEST_FILE}) get_filename_component(install_subdir "${f}" PATH) - install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main) + install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples) endforeach() #jni part + eclipse files file(GLOB_RECURSE jni_files RELATIVE "${path}" "${path}/jni/*" "${path}/.cproject") ocv_list_filterout(jni_files "\\\\.svn") foreach(f ${jni_files} ".classpath" ".project" ".settings/org.eclipse.jdt.core.prefs") get_filename_component(install_subdir "${f}" PATH) - install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main) + install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples) endforeach() #update proj if(android_proj_lib_deps_commands) @@ -365,9 +405,9 @@ macro(add_android_project target path) endif() install(CODE "EXECUTE_PROCESS(COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt} WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\" - )" COMPONENT main) + )" COMPONENT samples) #empty 'gen' - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT main) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples) endif() endif() endmacro() diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index b35a7977c..24fbb03ce 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -180,6 +180,9 @@ if(CUDA_FOUND) # we remove -Wsign-promo as it generates warnings under linux string(REPLACE "-Wsign-promo" "" ${var} "${${var}}") + # we remove -Wno-sign-promo as it generates warnings under linux + string(REPLACE "-Wno-sign-promo" "" ${var} "${${var}}") + # we remove -Wno-delete-non-virtual-dtor because it's used for C++ compiler # but NVCC uses C compiler by default string(REPLACE "-Wno-delete-non-virtual-dtor" "" ${var} "${${var}}") @@ -216,3 +219,42 @@ else() unset(CUDA_ARCH_BIN CACHE) unset(CUDA_ARCH_PTX CACHE) endif() + +if(HAVE_CUDA) + set(CUDA_LIBS_PATH "") + foreach(p ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) + get_filename_component(_tmp ${p} PATH) + list(APPEND CUDA_LIBS_PATH ${_tmp}) + endforeach() + + if(HAVE_CUBLAS) + foreach(p ${CUDA_cublas_LIBRARY}) + get_filename_component(_tmp ${p} PATH) + list(APPEND CUDA_LIBS_PATH ${_tmp}) + endforeach() + endif() + + if(HAVE_CUFFT) + foreach(p ${CUDA_cufft_LIBRARY}) + get_filename_component(_tmp ${p} PATH) + list(APPEND CUDA_LIBS_PATH ${_tmp}) + endforeach() + endif() + + list(REMOVE_DUPLICATES CUDA_LIBS_PATH) + link_directories(${CUDA_LIBS_PATH}) + + set(CUDA_LIBRARIES_ABS ${CUDA_LIBRARIES}) + ocv_convert_to_lib_name(CUDA_LIBRARIES ${CUDA_LIBRARIES}) + set(CUDA_npp_LIBRARY_ABS ${CUDA_npp_LIBRARY}) + ocv_convert_to_lib_name(CUDA_npp_LIBRARY ${CUDA_npp_LIBRARY}) + if(HAVE_CUBLAS) + set(CUDA_cublas_LIBRARY_ABS ${CUDA_cublas_LIBRARY}) + ocv_convert_to_lib_name(CUDA_cublas_LIBRARY ${CUDA_cublas_LIBRARY}) + endif() + + if(HAVE_CUFFT) + set(CUDA_cufft_LIBRARY_ABS ${CUDA_cufft_LIBRARY}) + ocv_convert_to_lib_name(CUDA_cufft_LIBRARY ${CUDA_cufft_LIBRARY}) + endif() +endif() \ No newline at end of file diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index 3326bcd98..d02b7596a 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -81,24 +81,39 @@ if(PYTHON_EXECUTABLE) SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.") if(NOT PYTHON_NUMPY_INCLUDE_DIR) - # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]" - RESULT_VARIABLE PYTHON_NUMPY_PROCESS - OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) + if(CMAKE_CROSSCOMPILING) + message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)") + message(STATUS "If you want to enable Python/Numpy support, set the following variables:") + message(STATUS " PYTHON_INCLUDE_PATH") + message(STATUS " PYTHON_LIBRARIES") + message(STATUS " PYTHON_NUMPY_INCLUDE_DIR") + else() + # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]" + RESULT_VARIABLE PYTHON_NUMPY_PROCESS + OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) - if(PYTHON_NUMPY_PROCESS EQUAL 0) - file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR) - set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers") + if(NOT PYTHON_NUMPY_PROCESS EQUAL 0) + unset(PYTHON_NUMPY_INCLUDE_DIR) + endif() endif() endif() if(PYTHON_NUMPY_INCLUDE_DIR) + file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR) + set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers") set(PYTHON_USE_NUMPY TRUE) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version" + if(CMAKE_CROSSCOMPILING) + if(NOT PYTHON_NUMPY_VERSION) + set(PYTHON_NUMPY_VERSION "undefined - cannot be probed because of the cross-compilation") + endif() + else() + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version" RESULT_VARIABLE PYTHON_NUMPY_PROCESS OUTPUT_VARIABLE PYTHON_NUMPY_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() endif() endif(NOT ANDROID AND NOT IOS) diff --git a/cmake/OpenCVDetectVTK.cmake b/cmake/OpenCVDetectVTK.cmake new file mode 100644 index 000000000..2b55a9c3f --- /dev/null +++ b/cmake/OpenCVDetectVTK.cmake @@ -0,0 +1,53 @@ +if(NOT WITH_VTK OR ANDROID OR IOS) + return() +endif() + +# VTK 6.x components +find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE) + +# VTK 5.x components +if(NOT VTK_FOUND) + find_package(VTK QUIET COMPONENTS vtkCommon NO_MODULE) +endif() + +if(NOT VTK_FOUND) + set(HAVE_VTK OFF) + message(STATUS "VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file") + return() +endif() + +# Don't support ealier VTKs +if(${VTK_VERSION} VERSION_LESS "5.8.0") + message(STATUS "VTK support is disabled. VTK ver. 5.8.0 is minimum required, but found VTK ver. ${VTK_VERSION}") + return() +endif() + +# Different Qt versions can't be linked together +if(HAVE_QT5 AND ${VTK_VERSION} VERSION_LESS "6.0.0") + if(VTK_USE_QT) + message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") + endif() +endif() + +# Different Qt versions can't be linked together. VTK 6.0.0 doesn't provide a way to get Qt version it was linked with +if(HAVE_QT5 AND ${VTK_VERSION} VERSION_EQUAL "6.0.0" AND NOT DEFINED FORCE_VTK) + message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt5, and VTK ver.${VTK_VERSION} with Qt4") + message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DFORCE_VTK=TRUE' flag in CMake") + return() +endif() + +# Different Qt versions can't be linked together +if(HAVE_QT AND ${VTK_VERSION} VERSION_GREATER "6.0.0" AND NOT ${VTK_QT_VERSION} STREQUAL "") + if(HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "4") + message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") + return() + endif() + + if(NOT HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "5") + message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt4 and VTK ver.${VTK_VERSION} + Qt5") + return() + endif() +endif() + +set(HAVE_VTK ON) +message(STATUS "Found VTK ver. ${VTK_VERSION} (usefile: ${VTK_USE_FILE})") diff --git a/cmake/OpenCVExtraTargets.cmake b/cmake/OpenCVExtraTargets.cmake index b4d339155..ecb2a3b36 100644 --- a/cmake/OpenCVExtraTargets.cmake +++ b/cmake/OpenCVExtraTargets.cmake @@ -4,7 +4,7 @@ CONFIGURE_FILE( "${OpenCV_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) + @ONLY) ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") if(ENABLE_SOLUTION_FOLDERS) diff --git a/cmake/OpenCVFindIPP.cmake b/cmake/OpenCVFindIPP.cmake index 772cae886..db02e6acb 100644 --- a/cmake/OpenCVFindIPP.cmake +++ b/cmake/OpenCVFindIPP.cmake @@ -163,9 +163,16 @@ function(set_ipp_new_libraries _LATEST_VERSION) ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX} ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX} ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - PARENT_SCOPE) + ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + if (UNIX) + set(IPP_LIBRARIES + ${IPP_LIBRARIES} + ${IPP_LIB_PREFIX}irc${CMAKE_SHARED_LIBRARY_SUFFIX} + ${IPP_LIB_PREFIX}imf${CMAKE_SHARED_LIBRARY_SUFFIX} + ${IPP_LIB_PREFIX}svml${CMAKE_SHARED_LIBRARY_SUFFIX}) + endif() + set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE) return() endfunction() @@ -208,19 +215,39 @@ function(set_ipp_variables _LATEST_VERSION) set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include PARENT_SCOPE) if (APPLE) - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib PARENT_SCOPE) + set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib) elseif (IPP_X64) if(NOT EXISTS ${IPP_ROOT_DIR}/lib/intel64) message(SEND_ERROR "IPP EM64T libraries not found") endif() - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/intel64 PARENT_SCOPE) + set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/intel64) else() if(NOT EXISTS ${IPP_ROOT_DIR}/lib/ia32) message(SEND_ERROR "IPP IA32 libraries not found") endif() - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/ia32 PARENT_SCOPE) + set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/ia32) endif() + if (UNIX) + get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH) + if (IPP_X64) + if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64) + message(SEND_ERROR "Intel compiler EM64T libraries not found") + endif() + set(IPP_LIBRARY_DIRS + ${IPP_LIBRARY_DIRS} + ${INTEL_COMPILER_LIBRARY_DIR}/intel64) + else() + if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32) + message(SEND_ERROR "Intel compiler IA32 libraries not found") + endif() + set(IPP_LIBRARY_DIRS + ${IPP_LIBRARY_DIRS} + ${INTEL_COMPILER_LIBRARY_DIR}/ia32) + endif() + endif() + set(IPP_LIBRARY_DIRS ${IPP_LIBRARY_DIRS} PARENT_SCOPE) + # set IPP_LIBRARIES variable (7.x or 8.x lib names) set_ipp_new_libraries(${_LATEST_VERSION}) set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE) diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index 8792d1b48..2622d2aae 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -56,8 +56,29 @@ if(ANDROID) # remove CUDA runtime and NPP from regular deps # it can be added separately if needed. - ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "libcu") - ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "libnpp") + ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "cusparse") + ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "cufft") + ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "cublas") + ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "npp") + ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "cudart") + + if(HAVE_CUDA) + # CUDA runtime libraries and are required always + set(culibs ${CUDA_LIBRARIES}) + + # right now NPP is requared always too + list(INSERT culibs 0 ${CUDA_npp_LIBRARY}) + + if(HAVE_CUFFT) + list(INSERT culibs 0 ${CUDA_cufft_LIBRARY}) + endif() + + if(HAVE_CUBLAS) + list(INSERT culibs 0 ${CUDA_cublas_LIBRARY}) + endif() + endif() + + ocv_convert_to_lib_name(CUDA_RUNTIME_LIBS_CONFIGMAKE ${culibs}) # split 3rdparty libs and modules foreach(mod ${OPENCV_MODULES_CONFIGMAKE}) @@ -69,8 +90,14 @@ if(ANDROID) list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) endif() + if(ENABLE_DYNAMIC_CUDA) + set(OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE "dynamicuda") + endif() + # GPU module enabled separately - list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "gpu") + list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "opencv_gpu") + list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "opencv_dynamicuda") + if(HAVE_opencv_gpu) set(OPENCV_HAVE_GPU_MODULE_CONFIGMAKE "on") endif() @@ -82,6 +109,7 @@ if(ANDROID) string(REPLACE ";" " " ${lst} "${${lst}}") endforeach() string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") + string(REPLACE ";" " " CUDA_RUNTIME_LIBS_CONFIGMAKE "${CUDA_RUNTIME_LIBS_CONFIGMAKE}") # prepare 3rd-party component list without TBB for armeabi and mips platforms. TBB is useless there. set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) @@ -103,7 +131,7 @@ if(ANDROID) set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/lib/\$(OPENCV_TARGET_ARCH_ABI)") set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/3rdparty/lib/\$(OPENCV_TARGET_ARCH_ABI)") - configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" IMMEDIATE @ONLY) + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/OpenCV.mk" @ONLY) # ------------------------------------------------------------------------------------------- # Part 2/2: ${BIN_DIR}/unix-install/OpenCV.mk -> For use with "make install" @@ -113,6 +141,6 @@ if(ANDROID) set(OPENCV_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../libs/\$(OPENCV_TARGET_ARCH_ABI)") set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../3rdparty/libs/\$(OPENCV_TARGET_ARCH_ABI)") - configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}) + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) endif(ANDROID) diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake index 411d22582..cdf418ec8 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake @@ -83,9 +83,9 @@ endif() export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules${modules_file_suffix}.cmake") -configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY) +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" @ONLY) #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work. -configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" @ONLY) # -------------------------------------------------------------------------------------------- # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install" @@ -98,8 +98,8 @@ if(INSTALL_TO_MANGLED_PATHS) set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE}\"") endif() -configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) -configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" @ONLY) +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" @ONLY) if(UNIX) # ANDROID configuration is created here also #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference @@ -109,18 +109,18 @@ if(UNIX) # ANDROID configuration is created here also # /(share|lib)/*/ (U) # /(share|lib)/*/(cmake|CMake)/ (U) if(INSTALL_TO_MANGLED_PATHS) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/) - install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) else() - install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) - install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) endif() endif() if(ANDROID) - install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) + install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) endif() # -------------------------------------------------------------------------------------------- @@ -131,15 +131,15 @@ if(WIN32) set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"") exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL) - configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) - configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" @ONLY) + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" @ONLY) if(BUILD_SHARED_LIBS) - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib") - install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) else() - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib") - install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) endif() - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}") - install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/") + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT dev) + install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/" COMPONENT dev) endif() diff --git a/cmake/OpenCVGenHeaders.cmake b/cmake/OpenCVGenHeaders.cmake index 35da0fb4b..c892a929c 100644 --- a/cmake/OpenCVGenHeaders.cmake +++ b/cmake/OpenCVGenHeaders.cmake @@ -23,4 +23,4 @@ set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE #endforeach() configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv_modules.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp") -install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT main) +install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT dev) diff --git a/cmake/OpenCVGenPkgconfig.cmake b/cmake/OpenCVGenPkgconfig.cmake index cd54f11bf..fa57db9d3 100644 --- a/cmake/OpenCVGenPkgconfig.cmake +++ b/cmake/OpenCVGenPkgconfig.cmake @@ -78,8 +78,8 @@ else() endif() configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" - @ONLY IMMEDIATE) + @ONLY) if(UNIX AND NOT ANDROID) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 3dd749b05..79e508609 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -27,7 +27,8 @@ # The verbose template for OpenCV module: # # ocv_add_module(modname ) -# ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...) +# ocv_glob_module_sources(([EXCLUDE_CUDA] ) +# or glob them manually and ocv_set_module_sources(...) # ocv_module_include_directories() # ocv_create_module() # @@ -135,13 +136,13 @@ macro(ocv_add_module _name) # parse list of dependencies if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS") - set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The cathegory of the module") + set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The category of the module") set(__ocv_argn__ ${ARGN}) list(REMOVE_AT __ocv_argn__ 0) ocv_add_dependencies(${the_module} ${__ocv_argn__}) unset(__ocv_argn__) else() - set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The cathegory of the module") + set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The category of the module") ocv_add_dependencies(${the_module} ${ARGN}) if(BUILD_${the_module}) set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export") @@ -478,22 +479,38 @@ endmacro() # finds and sets headers and sources for the standard OpenCV module # Usage: -# ocv_glob_module_sources() +# ocv_glob_module_sources([EXCLUDE_CUDA] ) macro(ocv_glob_module_sources) + set(_argn ${ARGN}) + list(FIND _argn "EXCLUDE_CUDA" exclude_cuda) + if(NOT exclude_cuda EQUAL -1) + list(REMOVE_AT _argn ${exclude_cuda}) + endif() + file(GLOB_RECURSE lib_srcs "src/*.cpp") file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h") file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h") + file(GLOB_RECURSE lib_srcs_apple "src/*.mm") + if (APPLE) + list(APPEND lib_srcs ${lib_srcs_apple}) + endif() - file(GLOB lib_cuda_srcs "src/cuda/*.cu") - set(cuda_objs "") - set(lib_cuda_hdrs "") - if(HAVE_CUDA) - ocv_include_directories(${CUDA_INCLUDE_DIRS}) - file(GLOB lib_cuda_hdrs "src/cuda/*.hpp") + if (exclude_cuda EQUAL -1) + file(GLOB lib_cuda_srcs "src/cuda/*.cu") + set(cuda_objs "") + set(lib_cuda_hdrs "") + if(HAVE_CUDA) + ocv_include_directories(${CUDA_INCLUDE_DIRS}) + file(GLOB lib_cuda_hdrs "src/cuda/*.hpp") - ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs}) - source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs}) + ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs}) + source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs}) + endif() + else() + set(cuda_objs "") + set(lib_cuda_srcs "") + set(lib_cuda_hdrs "") endif() source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) @@ -512,8 +529,8 @@ macro(ocv_glob_module_sources) source_group("Include" FILES ${lib_hdrs}) source_group("Include\\detail" FILES ${lib_hdrs_detail}) - ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} - SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs}) + ocv_set_module_sources(${_argn} HEADERS ${lib_hdrs} ${lib_hdrs_detail} + SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs}) endmacro() # creates OpenCV module in current folder @@ -577,9 +594,9 @@ macro(ocv_create_module) endif() ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main + RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT dev ) # only "public" headers need to be installed @@ -587,7 +604,7 @@ macro(ocv_create_module) foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS}) string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}") if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$") - install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main) + install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev) endif() endforeach() endif() @@ -612,11 +629,20 @@ endmacro() # short command for adding simple OpenCV module # see ocv_add_module for argument details # Usage: -# ocv_define_module(module_name [INTERNAL] [REQUIRED] [] [OPTIONAL ]) +# ocv_define_module(module_name [INTERNAL] [EXCLUDE_CUDA] [REQUIRED] [] [OPTIONAL ]) macro(ocv_define_module module_name) - ocv_add_module(${module_name} ${ARGN}) + set(_argn ${ARGN}) + set(exclude_cuda "") + foreach(arg ${_argn}) + if("${arg}" STREQUAL "EXCLUDE_CUDA") + set(exclude_cuda "${arg}") + list(REMOVE_ITEM _argn ${arg}) + endif() + endforeach() + + ocv_add_module(${module_name} ${_argn}) ocv_module_include_directories() - ocv_glob_module_sources() + ocv_glob_module_sources(${exclude_cuda}) ocv_create_module() ocv_add_precompiled_headers(${the_module}) @@ -711,6 +737,9 @@ function(ocv_add_perf_tests) else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) + if(INSTALL_TESTS) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) + endif() endif() endfunction() @@ -741,8 +770,8 @@ function(ocv_add_accuracy_tests) endif() 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}) @@ -764,6 +793,10 @@ function(ocv_add_accuracy_tests) else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) + + if(INSTALL_TESTS) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) + endif() endif() endfunction() @@ -795,7 +828,7 @@ function(ocv_add_samples) endif() if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples) endif() endforeach() endif() @@ -804,8 +837,8 @@ function(ocv_add_samples) if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}") file(GLOB sample_files "${samples_path}/*") install(FILES ${sample_files} - DESTINATION share/OpenCV/samples/${module_id} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() endfunction() diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake new file mode 100644 index 000000000..91f594096 --- /dev/null +++ b/cmake/OpenCVPackaging.cmake @@ -0,0 +1,110 @@ +if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") +set(CPACK_set_DESTDIR "on") + +if(NOT OPENCV_CUSTOM_PACKAGE_INFO) + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open Computer Vision Library") + set(CPACK_PACKAGE_DESCRIPTION +"OpenCV (Open Source Computer Vision Library) is an open source computer vision +and machine learning software library. OpenCV was built to provide a common +infrastructure for computer vision applications and to accelerate the use of +machine perception in the commercial products. Being a BSD-licensed product, +OpenCV makes it easy for businesses to utilize and modify the code.") + set(CPACK_PACKAGE_VENDOR "OpenCV Foundation") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + set(CPACK_PACKAGE_CONTACT "admin@opencv.org") + set(CPACK_PACKAGE_VERSION_MAJOR "${OPENCV_VERSION_MAJOR}") + set(CPACK_PACKAGE_VERSION_MINOR "${OPENCV_VERSION_MINOR}") + set(CPACK_PACKAGE_VERSION_PATCH "${OPENCV_VERSION_PATCH}") + set(CPACK_PACKAGE_VERSION "${OPENCV_VCSVERSION}") +endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) + +#arch +if(X86) + set(CPACK_DEBIAN_ARCHITECTURE "i386") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "i686") +elseif(X86_64) + set(CPACK_DEBIAN_ARCHITECTURE "amd64") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") +elseif(ARM) + set(CPACK_DEBIAN_ARCHITECTURE "armhf") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "armhf") +else() + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +if(CPACK_GENERATOR STREQUAL "DEB") + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_DEBIAN_ARCHITECTURE}) +elseif(CPACK_GENERATOR STREQUAL "RPM") + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_RPM_PACKAGE_ARCHITECTURE}) +else() + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") + +#rpm options +set(CPACK_RPM_COMPONENT_INSTALL TRUE) +set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) +set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) +set(CPACK_RPM_PACKAGE_URL "http://opencv.org") +set(CPACK_RPM_PACKAGE_LICENSE "BSD") + +#deb options +set(CPACK_DEB_COMPONENT_INSTALL TRUE) +set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") +set(CPACK_DEBIAN_PACKAGE_SECTION "libs") +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org") + +#depencencies +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE) +set(CPACK_COMPONENT_samples_DEPENDS libs) +set(CPACK_COMPONENT_dev_DEPENDS libs) +set(CPACK_COMPONENT_docs_DEPENDS libs) +set(CPACK_COMPONENT_java_DEPENDS libs) +set(CPACK_COMPONENT_python_DEPENDS libs) +set(CPACK_COMPONENT_tests_DEPENDS libs) + +if(HAVE_CUDA) + string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION}) + set(CPACK_DEB_libs_PACKAGE_DEPENDS "cuda-core-libs-${cuda_version_suffix}, cuda-extra-libs-${cuda_version_suffix}") + set(CPACK_COMPONENT_dev_DEPENDS libs) + set(CPACK_DEB_dev_PACKAGE_DEPENDS "cuda-headers-${cuda_version_suffix}") +endif() + +if(NOT OPENCV_CUSTOM_PACKAGE_INFO) + set(CPACK_COMPONENT_libs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}") + set(CPACK_COMPONENT_libs_DESCRIPTION "Open Computer Vision Library") + + set(CPACK_COMPONENT_python_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-python") + set(CPACK_COMPONENT_python_DESCRIPTION "Python bindings for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_java_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-java") + set(CPACK_COMPONENT_java_DESCRIPTION "Java bindings for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_dev_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-dev") + set(CPACK_COMPONENT_dev_DESCRIPTION "Development files for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_docs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-docs") + set(CPACK_COMPONENT_docs_DESCRIPTION "Documentation for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_samples_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-samples") + set(CPACK_COMPONENT_samples_DESCRIPTION "Samples for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_tests_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-tests") + set(CPACK_COMPONENT_tests_DESCRIPTION "Accuracy and performance tests for Open Source Computer Vision Library") +endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) + +if(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT) + set(CPACK_libs_COMPONENT_INSTALL TRUE) + set(CPACK_dev_COMPONENT_INSTALL TRUE) + set(CPACK_docs_COMPONENT_INSTALL TRUE) + set(CPACK_python_COMPONENT_INSTALL TRUE) + set(CPACK_java_COMPONENT_INSTALL TRUE) + set(CPACK_samples_COMPONENT_INSTALL TRUE) +endif(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT) + +include(CPack) + +ENDif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") \ No newline at end of file diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 13461e82c..9fa94bb8b 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -448,6 +448,20 @@ macro(ocv_convert_to_full_paths VAR) endmacro() +# convert list of paths to libraries names without lib prefix +macro(ocv_convert_to_lib_name var) + set(__tmp "") + foreach(path ${ARGN}) + get_filename_component(__tmp_name "${path}" NAME_WE) + string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name}) + list(APPEND __tmp "${__tmp_name}") + endforeach() + set(${var} ${__tmp}) + unset(__tmp) + unset(__tmp_name) +endmacro() + + # add install command function(ocv_install_target) install(TARGETS ${ARGN}) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 0fd7b9e05..77229ecf5 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -2,6 +2,13 @@ # you might need to define NDK_USE_CYGPATH=1 before calling the ndk-build USER_LOCAL_PATH:=$(LOCAL_PATH) + +USER_LOCAL_C_INCLUDES:=$(LOCAL_C_INCLUDES) +USER_LOCAL_CFLAGS:=$(LOCAL_CFLAGS) +USER_LOCAL_STATIC_LIBRARIES:=$(LOCAL_STATIC_LIBRARIES) +USER_LOCAL_SHARED_LIBRARIES:=$(LOCAL_SHARED_LIBRARIES) +USER_LOCAL_LDLIBS:=$(LOCAL_LDLIBS) + LOCAL_PATH:=$(subst ?,,$(firstword ?$(subst \, ,$(subst /, ,$(call my-dir))))) OPENCV_TARGET_ARCH_ABI:=$(TARGET_ARCH_ABI) @@ -13,7 +20,7 @@ OPENCV_BASEDIR:=@OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE@ OPENCV_LOCAL_C_INCLUDES:=@OPENCV_INCLUDE_DIRS_CONFIGCMAKE@ OPENCV_MODULES:=@OPENCV_MODULES_CONFIGMAKE@ -OPENCV_HAVE_GPU_MODULE=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ +OPENCV_HAVE_GPU_MODULE:=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ OPENCV_USE_GPU_MODULE:= ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) @@ -22,9 +29,12 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) OPENCV_USE_GPU_MODULE:=on endif endif + OPENCV_DYNAMICUDA_MODULE:=@OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE@ +else + OPENCV_DYNAMICUDA_MODULE:= endif -CUDA_RUNTIME_LIBS:=cufft npps nppi nppc cudart +CUDA_RUNTIME_LIBS:=@CUDA_RUNTIME_LIBS_CONFIGMAKE@ ifeq ($(OPENCV_LIB_TYPE),) OPENCV_LIB_TYPE:=@OPENCV_LIBTYPE_CONFIGMAKE@ @@ -60,7 +70,7 @@ else endif endif -ifeq (${OPENCV_CAMERA_MODULES},on) +ifeq ($(OPENCV_CAMERA_MODULES),on) ifeq ($(TARGET_ARCH_ABI),armeabi) OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_ARMEABI_CONFIGCMAKE@ endif @@ -91,6 +101,13 @@ define add_opencv_module include $(PREBUILT_$(OPENCV_LIB_TYPE)_LIBRARY) endef +define add_cuda_module + include $(CLEAR_VARS) + LOCAL_MODULE:=$1 + LOCAL_SRC_FILES:=$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib/lib$1.so + include $(PREBUILT_SHARED_LIBRARY) +endef + define add_opencv_3rdparty_component include $(CLEAR_VARS) LOCAL_MODULE:=$1 @@ -108,6 +125,17 @@ endef ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED),) ifeq ($(OPENCV_INSTALL_MODULES),on) $(foreach module,$(OPENCV_LIBS),$(eval $(call add_opencv_module,$(module)))) + ifneq ($(OPENCV_DYNAMICUDA_MODULE),) + ifeq ($(OPENCV_LIB_TYPE),SHARED) + $(eval $(call add_opencv_module,$(OPENCV_DYNAMICUDA_MODULE))) + endif + endif + endif + + ifeq ($(OPENCV_USE_GPU_MODULE),on) + ifeq ($(INSTALL_CUDA_LIBRARIES),on) + $(foreach module,$(CUDA_RUNTIME_LIBS),$(eval $(call add_cuda_module,$(module)))) + endif endif $(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module)))) @@ -124,11 +152,14 @@ ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED),) OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED:=on endif -ifeq ($(OPENCV_USE_GPU_MODULE),on) - include $(CLEAR_VARS) - LOCAL_MODULE:=opencv_gpu - LOCAL_SRC_FILES:=$(OPENCV_LIBS_DIR)/libopencv_gpu.a - include $(PREBUILT_STATIC_LIBRARY) +ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_GPU_ALREADY_INCLUDED),) + ifeq ($(OPENCV_USE_GPU_MODULE),on) + include $(CLEAR_VARS) + LOCAL_MODULE:=opencv_gpu + LOCAL_SRC_FILES:=$(OPENCV_LIBS_DIR)/libopencv_gpu.a + include $(PREBUILT_STATIC_LIBRARY) + endif + OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_GPU_ALREADY_INCLUDED:=on endif ifeq ($(OPENCV_LOCAL_CFLAGS),) @@ -136,6 +167,13 @@ ifeq ($(OPENCV_LOCAL_CFLAGS),) endif include $(CLEAR_VARS) + +LOCAL_C_INCLUDES:=$(USER_LOCAL_C_INCLUDES) +LOCAL_CFLAGS:=$(USER_LOCAL_CFLAGS) +LOCAL_STATIC_LIBRARIES:=$(USER_LOCAL_STATIC_LIBRARIES) +LOCAL_SHARED_LIBRARIES:=$(USER_LOCAL_SHARED_LIBRARIES) +LOCAL_LDLIBS:=$(USER_LOCAL_LDLIBS) + LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES) LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS) @@ -145,6 +183,11 @@ endif ifeq ($(OPENCV_INSTALL_MODULES),on) LOCAL_$(OPENCV_LIB_TYPE)_LIBRARIES += $(foreach mod, $(OPENCV_LIBS), opencv_$(mod)) + ifeq ($(OPENCV_LIB_TYPE),SHARED) + ifneq ($(OPENCV_DYNAMICUDA_MODULE),) + LOCAL_$(OPENCV_LIB_TYPE)_LIBRARIES += $(OPENCV_DYNAMICUDA_MODULE) + endif + endif else LOCAL_LDLIBS += -L$(call host-path,$(LOCAL_PATH)/$(OPENCV_LIBS_DIR)) $(foreach lib, $(OPENCV_LIBS), -lopencv_$(lib)) endif @@ -156,8 +199,12 @@ endif LOCAL_LDLIBS += $(foreach lib,$(OPENCV_EXTRA_COMPONENTS), -l$(lib)) ifeq ($(OPENCV_USE_GPU_MODULE),on) + ifeq ($(INSTALL_CUDA_LIBRARIES),on) + LOCAL_SHARED_LIBRARIES += $(foreach mod, $(CUDA_RUNTIME_LIBS), $(mod)) + else + LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) + endif LOCAL_STATIC_LIBRARIES+=libopencv_gpu - LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) endif #restore the LOCAL_PATH diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index 6db61d211..6d1c1a990 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -18,8 +18,8 @@ # This file will define the following variables: # - OpenCV_LIBS : The list of all imported targets for OpenCV modules. # - OpenCV_INCLUDE_DIRS : The OpenCV include directories. -# - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability -# - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API +# - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability. +# - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API. # - OpenCV_VERSION : The version of this OpenCV build: "@OPENCV_VERSION@" # - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION: "@OPENCV_VERSION_MAJOR@" # - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION: "@OPENCV_VERSION_MINOR@" @@ -27,22 +27,26 @@ # - OpenCV_VERSION_TWEAK : Tweak version part of OpenCV_VERSION: "@OPENCV_VERSION_TWEAK@" # # Advanced variables: -# - OpenCV_SHARED -# - OpenCV_CONFIG_PATH -# - OpenCV_INSTALL_PATH (not set on Windows) -# - OpenCV_LIB_COMPONENTS -# - OpenCV_USE_MANGLED_PATHS -# - OpenCV_HAVE_ANDROID_CAMERA +# - OpenCV_SHARED : Use OpenCV as shared library +# - OpenCV_CONFIG_PATH : Path to this OpenCVConfig.cmake +# - OpenCV_INSTALL_PATH : OpenCV location (not set on Windows) +# - OpenCV_LIB_COMPONENTS : Present OpenCV modules list +# - OpenCV_USE_MANGLED_PATHS : Mangled OpenCV path flag +# - OpenCV_MODULES_SUFFIX : The suffix for OpenCVModules-XXX.cmake file +# - OpenCV_HAVE_ANDROID_CAMERA : Presence of Android native camera wrappers # # =================================================================================== -set(modules_file_suffix "") -if(ANDROID) - string(REPLACE - _ modules_file_suffix "_${ANDROID_NDK_ABI_NAME}") +if(NOT DEFINED OpenCV_MODULES_SUFFIX) + if(ANDROID) + string(REPLACE - _ OpenCV_MODULES_SUFFIX "_${ANDROID_NDK_ABI_NAME}") + else() + set(OpenCV_MODULES_SUFFIX "") + endif() endif() if(NOT TARGET opencv_core) - include(${CMAKE_CURRENT_LIST_DIR}/OpenCVModules${modules_file_suffix}.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/OpenCVModules${OpenCV_MODULES_SUFFIX}.cmake) endif() # TODO All things below should be reviewed. What is about of moving this code into related modules (special vars/hooks/files) @@ -56,7 +60,11 @@ set(OpenCV_USE_CUFFT @HAVE_CUFFT@) set(OpenCV_USE_NVCUVID @HAVE_NVCUVID@) # Android API level from which OpenCV has been compiled is remembered -set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@) +if(ANDROID) + set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@) +else() + set(OpenCV_ANDROID_NATIVE_API_LEVEL 0) +endif() # Some additional settings are required if OpenCV is built as static libs set(OpenCV_SHARED @BUILD_SHARED_LIBS@) @@ -67,8 +75,8 @@ set(OpenCV_USE_MANGLED_PATHS @OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE@) # Extract the directory where *this* file has been installed (determined at cmake run-time) get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH CACHE) -if(NOT WIN32 OR OpenCV_ANDROID_NATIVE_API_LEVEL GREATER 0) - if(OpenCV_ANDROID_NATIVE_API_LEVEL GREATER 0) +if(NOT WIN32 OR ANDROID) + if(ANDROID) set(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/../../..") else() set(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/../..") @@ -206,7 +214,7 @@ foreach(__opttype OPT DBG) SET(OpenCV_EXTRA_LIBS_${__opttype} "") # CUDA - if(OpenCV_CUDA_VERSION AND (CMAKE_CROSSCOMPILING OR (WIN32 AND NOT OpenCV_SHARED))) + if(OpenCV_CUDA_VERSION) if(NOT CUDA_FOUND) find_package(CUDA ${OpenCV_CUDA_VERSION} EXACT REQUIRED) else() @@ -215,32 +223,41 @@ foreach(__opttype OPT DBG) endif() endif() - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_LIBRARIES}) + set(OpenCV_CUDA_LIBS_ABSPATH ${CUDA_LIBRARIES}) if(${CUDA_VERSION} VERSION_LESS "5.5") - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_npp_LIBRARY}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_npp_LIBRARY}) else() find_cuda_helper_libs(nppc) find_cuda_helper_libs(nppi) find_cuda_helper_libs(npps) - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nppc_LIBRARY} ${CUDA_nppi_LIBRARY} ${CUDA_npps_LIBRARY}) endif() if(OpenCV_USE_CUBLAS) - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_CUBLAS_LIBRARIES}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUBLAS_LIBRARIES}) endif() if(OpenCV_USE_CUFFT) - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_CUFFT_LIBRARIES}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_CUFFT_LIBRARIES}) endif() if(OpenCV_USE_NVCUVID) - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_nvcuvid_LIBRARIES}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvid_LIBRARIES}) endif() if(WIN32) - list(APPEND OpenCV_EXTRA_LIBS_${__opttype} ${CUDA_nvcuvenc_LIBRARIES}) + list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_nvcuvenc_LIBRARIES}) endif() + + set(OpenCV_CUDA_LIBS_RELPATH "") + foreach(l ${OpenCV_CUDA_LIBS_ABSPATH}) + get_filename_component(_tmp ${l} PATH) + list(APPEND OpenCV_CUDA_LIBS_RELPATH ${_tmp}) + endforeach() + + list(REMOVE_DUPLICATES OpenCV_CUDA_LIBS_RELPATH) + link_directories(${OpenCV_CUDA_LIBS_RELPATH}) endif() endforeach() diff --git a/cmake/templates/cvconfig.h.in b/cmake/templates/cvconfig.h.in index a6cee6368..d1c9e65d3 100644 --- a/cmake/templates/cvconfig.h.in +++ b/cmake/templates/cvconfig.h.in @@ -161,6 +161,6 @@ /* Xine video library */ #cmakedefine HAVE_XINE -/* Define to 1 if your processor stores words with the most significant byte +/* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ #cmakedefine WORDS_BIGENDIAN diff --git a/cmake/templates/opencv_run_all_tests_android.sh.in b/cmake/templates/opencv_run_all_tests_android.sh.in new file mode 100644 index 000000000..93373fa96 --- /dev/null +++ b/cmake/templates/opencv_run_all_tests_android.sh.in @@ -0,0 +1,51 @@ +#!/bin/sh + +BASE_DIR=`dirname $0` +OPENCV_TEST_PATH=$BASE_DIR/@TEST_PATH@ +OPENCV_TEST_DATA_PATH=$BASE_DIR/sdk/etc/testdata/ + +if [ $# -ne 1 ]; then + echo "Device architecture is not preset in command line" + echo "Tests are available for architectures: `ls -m ${OPENCV_TEST_PATH}`" + echo "Usage: $0 " + return 1 +else + TARGET_ARCH=$1 +fi + +if [ -z `which adb` ]; then + echo "adb command was not found in PATH" + return 1 +fi + +adb push $OPENCV_TEST_DATA_PATH /sdcard/opencv_testdata + +adb shell "mkdir -p /data/local/tmp/opencv_test" +SUMMARY_STATUS=0 +for t in "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_test_* "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_perf_*; +do + test_name=`basename "$t"` + report="$test_name-`date --rfc-3339=date`.xml" + adb push $t /data/local/tmp/opencv_test/ + adb shell "export OPENCV_TEST_DATA_PATH=/sdcard/opencv_testdata && /data/local/tmp/opencv_test/$test_name --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:/data/local/tmp/opencv_test/$report" + adb pull "/data/local/tmp/opencv_test/$report" $report + TEST_STATUS=0 + if [ -e $report ]; then + if [ `grep -c "- weighttrimming <weight_trimming>  Specifies -wheter and how much weight trimming should be used. A decent choice is 0.90.

+whether and how much weight trimming should be used. A decent choice is 0.90.

- eqw

diff --git a/doc/tutorials/core/adding_images/adding_images.rst b/doc/tutorials/core/adding_images/adding_images.rst index e3135693d..601dbc07e 100644 --- a/doc/tutorials/core/adding_images/adding_images.rst +++ b/doc/tutorials/core/adding_images/adding_images.rst @@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV Goal ===== -In this tutorial you will learn how to: +In this tutorial you will learn: .. container:: enumeratevisibleitemswithsquare - * What is *linear blending* and why it is useful. - * Add two images using :add_weighted:`addWeighted <>` + * what is *linear blending* and why it is useful; + * how to add two images using :add_weighted:`addWeighted <>` Theory ======= diff --git a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst index 613f4e100..a641435f8 100644 --- a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst +++ b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst @@ -192,7 +192,7 @@ Explanation image.convertTo(new_image, -1, alpha, beta); - where :convert_to:`convertTo <>` would effectively perform *new_image = a*image + beta*. However, we wanted to show you how to access each pixel. In any case, both methods give the same result. + where :convert_to:`convertTo <>` would effectively perform *new_image = a*image + beta*. However, we wanted to show you how to access each pixel. In any case, both methods give the same result but convertTo is more optimized and works a lot faster. Result ======= diff --git a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.rst b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.rst index 42f6a6091..7e1674efa 100644 --- a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.rst +++ b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.rst @@ -31,15 +31,15 @@ Here's a sample code of how to achieve all the stuff enumerated at the goal list Explanation =========== -Here we talk only about XML and YAML file inputs. Your output (and its respective input) file may have only one of these extensions and the structure coming from this. They are two kinds of data structures you may serialize: *mappings* (like the STL map) and *element sequence* (like the STL vector>. The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item. +Here we talk only about XML and YAML file inputs. Your output (and its respective input) file may have only one of these extensions and the structure coming from this. They are two kinds of data structures you may serialize: *mappings* (like the STL map) and *element sequence* (like the STL vector). The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item. -1. **XML\\YAML File Open and Close.** Before you write any content to such file you need to open it and at the end to close it. The XML\YAML data structure in OpenCV is :xmlymlpers:`FileStorage `. To specify that this structure to which file binds on your hard drive you can use either its constructor or the *open()* function of this: +1. **XML/YAML File Open and Close.** Before you write any content to such file you need to open it and at the end to close it. The XML/YAML data structure in OpenCV is :xmlymlpers:`FileStorage `. To specify that this structure to which file binds on your hard drive you can use either its constructor or the *open()* function of this: .. code-block:: cpp string filename = "I.xml"; FileStorage fs(filename, FileStorage::WRITE); - \\... + //... fs.open(filename, FileStorage::READ); Either one of this you use the second argument is a constant specifying the type of operations you'll be able to on them: WRITE, READ or APPEND. The extension specified in the file name also determinates the output format that will be used. The output may be even compressed if you specify an extension such as *.xml.gz*. @@ -64,7 +64,7 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv fs["iterationNr"] >> itNr; itNr = (int) fs["iterationNr"]; -#. **Input\\Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ types: +#. **Input/Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ types: .. code-block:: cpp @@ -77,7 +77,7 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv fs["R"] >> R; // Read cv::Mat fs["T"] >> T; -#. **Input\\Output of vectors (arrays) and associative maps.** As I mentioned beforehand we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map. +#. **Input/Output of vectors (arrays) and associative maps.** As I mentioned beforehand, we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map. For sequence before the first element print the "[" character and after the last one the "]" character: diff --git a/doc/tutorials/core/how_to_scan_images/how_to_scan_images.rst b/doc/tutorials/core/how_to_scan_images/how_to_scan_images.rst index ef0f8640c..b6a18fee8 100644 --- a/doc/tutorials/core/how_to_scan_images/how_to_scan_images.rst +++ b/doc/tutorials/core/how_to_scan_images/how_to_scan_images.rst @@ -18,7 +18,7 @@ We'll seek answers for the following questions: Our test case ============= -Let us consider a simple color reduction method. Using the unsigned char C and C++ type for matrix item storing a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result. +Let us consider a simple color reduction method. By using the unsigned char C and C++ type for matrix item storing, a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result. In this cases it's common that we make a *color space reduction*. This means that we divide the color space current value with a new input value to end up with fewer colors. For instance every value between zero and nine takes the new value zero, every value between ten and nineteen the value ten and so on. diff --git a/doc/tutorials/core/mat-mask-operations/mat-mask-operations.rst b/doc/tutorials/core/mat-mask-operations/mat-mask-operations.rst index 0549a9c12..f28920e77 100644 --- a/doc/tutorials/core/mat-mask-operations/mat-mask-operations.rst +++ b/doc/tutorials/core/mat-mask-operations/mat-mask-operations.rst @@ -32,14 +32,14 @@ Here's a function that will do this: .. code-block:: cpp - void Sharpen(const Mat& myImage,Mat& Result) + void Sharpen(const Mat& myImage, Mat& Result) { CV_Assert(myImage.depth() == CV_8U); // accept only uchar images - Result.create(myImage.size(),myImage.type()); + Result.create(myImage.size(), myImage.type()); const int nChannels = myImage.channels(); - for(int j = 1 ; j < myImage.rows-1; ++j) + for(int j = 1; j < myImage.rows - 1; ++j) { const uchar* previous = myImage.ptr(j - 1); const uchar* current = myImage.ptr(j ); @@ -47,17 +47,17 @@ Here's a function that will do this: uchar* output = Result.ptr(j); - for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i) + for(int i = nChannels; i < nChannels * (myImage.cols - 1); ++i) { - *output++ = saturate_cast(5*current[i] - -current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]); + *output++ = saturate_cast(5 * current[i] + -current[i - nChannels] - current[i + nChannels] - previous[i] - next[i]); } } Result.row(0).setTo(Scalar(0)); - Result.row(Result.rows-1).setTo(Scalar(0)); + Result.row(Result.rows - 1).setTo(Scalar(0)); Result.col(0).setTo(Scalar(0)); - Result.col(Result.cols-1).setTo(Scalar(0)); + Result.col(Result.cols - 1).setTo(Scalar(0)); } At first we make sure that the input images data is in unsigned char format. For this we use the :utilitysystemfunctions:`CV_Assert ` function that throws an error when the expression inside it is false. @@ -70,14 +70,14 @@ We create an output image with the same size and the same type as our input. As .. code-block:: cpp - Result.create(myImage.size(),myImage.type()); + Result.create(myImage.size(), myImage.type()); const int nChannels = myImage.channels(); We'll use the plain C [] operator to access pixels. Because we need to access multiple rows at the same time we'll acquire the pointers for each of them (a previous, a current and a next line). We need another pointer to where we're going to save the calculation. Then simply access the right items with the [] operator. For moving the output pointer ahead we simply increase this (with one byte) after each operation: .. code-block:: cpp - for(int j = 1 ; j < myImage.rows-1; ++j) + for(int j = 1; j < myImage.rows - 1; ++j) { const uchar* previous = myImage.ptr(j - 1); const uchar* current = myImage.ptr(j ); @@ -85,21 +85,21 @@ We'll use the plain C [] operator to access pixels. Because we need to access mu uchar* output = Result.ptr(j); - for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i) + for(int i = nChannels; i < nChannels * (myImage.cols - 1); ++i) { - *output++ = saturate_cast(5*current[i] - -current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]); + *output++ = saturate_cast(5 * current[i] + -current[i - nChannels] - current[i + nChannels] - previous[i] - next[i]); } } -On the borders of the image the upper notation results inexistent pixel locations (like minus one - minus one). In these points our formula is undefined. A simple solution is to not apply the mask in these points and, for example, set the pixels on the borders to zeros: +On the borders of the image the upper notation results inexistent pixel locations (like minus one - minus one). In these points our formula is undefined. A simple solution is to not apply the kernel in these points and, for example, set the pixels on the borders to zeros: .. code-block:: cpp - Result.row(0).setTo(Scalar(0)); // The top row - Result.row(Result.rows-1).setTo(Scalar(0)); // The bottom row - Result.col(0).setTo(Scalar(0)); // The left column - Result.col(Result.cols-1).setTo(Scalar(0)); // The right column + Result.row(0).setTo(Scalar(0)); // The top row + Result.row(Result.rows - 1).setTo(Scalar(0)); // The bottom row + Result.col(0).setTo(Scalar(0)); // The left column + Result.col(Result.cols - 1).setTo(Scalar(0)); // The right column The filter2D function ===================== @@ -116,7 +116,7 @@ Then call the :filtering:`filter2D ` function specifying the input, th .. code-block:: cpp - filter2D(I, K, I.depth(), kern ); + filter2D(I, K, I.depth(), kern); The function even has a fifth optional argument to specify the center of the kernel, and a sixth one for determining what to do in the regions where the operation is undefined (borders). Using this function has the advantage that it's shorter, less verbose and because there are some optimization techniques implemented it is usually faster than the *hand-coded method*. For example in my test while the second one took only 13 milliseconds the first took around 31 milliseconds. Quite some difference. diff --git a/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.rst b/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.rst index 171d2e683..736aceb02 100644 --- a/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.rst +++ b/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.rst @@ -45,7 +45,7 @@ All the above objects, in the end, point to the same single data matrix. Their h :linenos: Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle - Mat E = A(Range:all(), Range(1,3)); // using row and column boundaries + Mat E = A(Range::all(), Range(1,3)); // using row and column boundaries Now you may ask if the matrix itself may belong to multiple *Mat* objects who takes responsibility for cleaning it up when it's no longer needed. The short answer is: the last object that used it. This is handled by using a reference counting mechanism. Whenever somebody copies a header of a *Mat* object, a counter is increased for the matrix. Whenever a header is cleaned this counter is decreased. When the counter reaches zero the matrix too is freed. Sometimes you will want to copy the matrix itself too, so OpenCV provides the :basicstructures:`clone() ` and :basicstructures:`copyTo() ` functions. @@ -86,7 +86,7 @@ Each of the building components has their own valid domains. This leads to the d Creating a *Mat* object explicitly ================================== -In the :ref:`Load_Save_Image` tutorial you have already learned how to write a matrix to an image file by using the :readWriteImageVideo:` imwrite() ` function. However, for debugging purposes it's much more convenient to see the actual values. You can do this using the << operator of *Mat*. Be aware that this only works for two dimensional matrices. +In the :ref:`Load_Save_Image` tutorial you have already learned how to write a matrix to an image file by using the :readwriteimagevideo:`imwrite() ` function. However, for debugging purposes it's much more convenient to see the actual values. You can do this using the << operator of *Mat*. Be aware that this only works for two dimensional matrices. Although *Mat* works really well as an image container, it is also a general matrix class. Therefore, it is possible to create and manipulate multidimensional matrices. You can create a Mat object in multiple ways: @@ -113,7 +113,7 @@ Although *Mat* works really well as an image container, it is also a general mat For instance, *CV_8UC3* means we use unsigned char types that are 8 bit long and each pixel has three of these to form the three channels. This are predefined for up to four channel numbers. The :basicstructures:`Scalar ` is four element short vector. Specify this and you can initialize all matrix points with a custom value. If you need more you can create the type with the upper macro, setting the channel number in parenthesis as you can see below. - + Use C\\C++ arrays and initialize via constructor + + Use C/C++ arrays and initialize via constructor .. literalinclude:: ../../../../samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp :language: cpp diff --git a/doc/tutorials/images/viz.jpg b/doc/tutorials/images/viz.jpg new file mode 100644 index 000000000..7ac8f3ed8 Binary files /dev/null and b/doc/tutorials/images/viz.jpg differ diff --git a/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst b/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst index 1a5c59de0..f5f636d08 100644 --- a/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst +++ b/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst @@ -84,88 +84,10 @@ Code * **Code at glance:** -.. code-block:: cpp +.. literalinclude:: ../../../../../samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp + :language: cpp + :tab-width: 4 - #include "opencv2/highgui/highgui.hpp" - #include "opencv2/imgproc/imgproc.hpp" - #include - #include - - using namespace std; - using namespace cv; - - /** @function main */ - int main( int argc, char** argv ) - { - Mat src_base, hsv_base; - Mat src_test1, hsv_test1; - Mat src_test2, hsv_test2; - Mat hsv_half_down; - - /// Load three images with different environment settings - if( argc < 4 ) - { printf("** Error. Usage: ./compareHist_Demo \n"); - return -1; - } - - src_base = imread( argv[1], 1 ); - src_test1 = imread( argv[2], 1 ); - src_test2 = imread( argv[3], 1 ); - - /// Convert to HSV - cvtColor( src_base, hsv_base, CV_BGR2HSV ); - cvtColor( src_test1, hsv_test1, CV_BGR2HSV ); - cvtColor( src_test2, hsv_test2, CV_BGR2HSV ); - - hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) ); - - /// Using 30 bins for hue and 32 for saturation - int h_bins = 50; int s_bins = 60; - int histSize[] = { h_bins, s_bins }; - - // hue varies from 0 to 256, saturation from 0 to 180 - float h_ranges[] = { 0, 256 }; - float s_ranges[] = { 0, 180 }; - - const float* ranges[] = { h_ranges, s_ranges }; - - // Use the o-th and 1-st channels - int channels[] = { 0, 1 }; - - /// Histograms - MatND hist_base; - MatND hist_half_down; - MatND hist_test1; - MatND hist_test2; - - /// Calculate the histograms for the HSV images - calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false ); - normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() ); - - calcHist( &hsv_half_down, 1, channels, Mat(), hist_half_down, 2, histSize, ranges, true, false ); - normalize( hist_half_down, hist_half_down, 0, 1, NORM_MINMAX, -1, Mat() ); - - calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false ); - normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() ); - - calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false ); - normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() ); - - /// Apply the histogram comparison methods - for( int i = 0; i < 4; i++ ) - { int compare_method = i; - double base_base = compareHist( hist_base, hist_base, compare_method ); - double base_half = compareHist( hist_base, hist_half_down, compare_method ); - double base_test1 = compareHist( hist_base, hist_test1, compare_method ); - double base_test2 = compareHist( hist_base, hist_test2, compare_method ); - - printf( " Method [%d] Perfect, Base-Half, Base-Test(1), Base-Test(2) : %f, %f, %f, %f \n", i, base_base, base_half , base_test1, base_test2 ); - } - - printf( "Done \n" ); - - return 0; - } Explanation @@ -211,11 +133,11 @@ Explanation .. code-block:: cpp - int h_bins = 50; int s_bins = 32; + int h_bins = 50; int s_bins = 60; int histSize[] = { h_bins, s_bins }; - float h_ranges[] = { 0, 256 }; - float s_ranges[] = { 0, 180 }; + float h_ranges[] = { 0, 180 }; + float s_ranges[] = { 0, 256 }; const float* ranges[] = { h_ranges, s_ranges }; diff --git a/doc/tutorials/imgproc/histograms/template_matching/template_matching.rst b/doc/tutorials/imgproc/histograms/template_matching/template_matching.rst index cb7ece86f..db6838a12 100644 --- a/doc/tutorials/imgproc/histograms/template_matching/template_matching.rst +++ b/doc/tutorials/imgproc/histograms/template_matching/template_matching.rst @@ -85,7 +85,7 @@ d. **method=CV\_TM\_CCORR\_NORMED** .. math:: - R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I'(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}} + R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}} e. **method=CV\_TM\_CCOEFF** diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst index 9a683ea49..a70a98d52 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst @@ -48,10 +48,10 @@ The structure of package contents looks as follows: :: - OpenCV-2.4.8-android-sdk + OpenCV-2.4.9-android-sdk |_ apk - | |_ OpenCV_2.4.8_binary_pack_armv7a.apk - | |_ OpenCV_2.4.8_Manager_2.16_XXX.apk + | |_ OpenCV_2.4.9_binary_pack_armv7a.apk + | |_ OpenCV_2.4.9_Manager_2.18_XXX.apk | |_ doc |_ samples @@ -66,7 +66,7 @@ The structure of package contents looks as follows: | |_ armeabi-v7a | |_ x86 | - |_ license.txt + |_ LICENSE |_ README.android * :file:`sdk` folder contains OpenCV API and libraries for Android: @@ -157,10 +157,10 @@ Get the OpenCV4Android SDK .. code-block:: bash - unzip ~/Downloads/OpenCV-2.4.8-android-sdk.zip + unzip ~/Downloads/OpenCV-2.4.9-android-sdk.zip -.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8-android-sdk.zip` -.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8/OpenCV-2.4.8-android-sdk.zip/download +.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.9-android-sdk.zip` +.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.9/OpenCV-2.4.9-android-sdk.zip/download .. |opencv_android_bin_pack_url| replace:: |opencv_android_bin_pack| .. |seven_zip| replace:: 7-Zip .. _seven_zip: http://www.7-zip.org/ @@ -295,7 +295,7 @@ Well, running samples from Eclipse is very simple: .. code-block:: sh :linenos: - /platform-tools/adb install /apk/OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk + /platform-tools/adb install /apk/OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk .. note:: ``armeabi``, ``armv7a-neon``, ``arm7a-neon-android8``, ``mips`` and ``x86`` stand for platform targets: diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index 3d7268c80..6fe8f6b94 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system. :guilabel:`File -> Import -> Existing project in your workspace`. Press :guilabel:`Browse` button and locate OpenCV4Android SDK - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.9-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In application project add a reference to the OpenCV Java SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``. + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.9``. .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library @@ -128,27 +128,27 @@ described above. #. Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`, press :guilabel:`Browse` button and select OpenCV SDK path - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.9-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In the application project add a reference to the OpenCV4Android SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``; + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.9``; .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library :align: center #. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV - native libs from :file:`/sdk/native/libs/` to your + native libs from :file:`/sdk/native/libs/` to your project directory to folder :file:`libs/`. In case of the application project **with a JNI part**, instead of manual libraries copying you need to modify your ``Android.mk`` file: add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before - ``"include path_to_OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk"`` + ``"include path_to_OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk"`` .. code-block:: make :linenos: @@ -221,7 +221,7 @@ taken: .. code-block:: make - include C:\Work\OpenCV4Android\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk + include C:\Work\OpenCV4Android\OpenCV-2.4.9-android-sdk\sdk\native\jni\OpenCV.mk Should be inserted into the :file:`jni/Android.mk` file **after** this line: @@ -382,7 +382,7 @@ result. OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback); } -#. Defines that your activity implements ``CvViewFrameListener2`` interface and fix activity related +#. Defines that your activity implements ``CvCameraViewListener2`` interface and fix activity related errors by defining missed methods. For this activity define ``onCreate``, ``onDestroy`` and ``onPause`` and implement them according code snippet bellow. Fix errors by adding requited imports. @@ -432,7 +432,7 @@ result. Lets discuss some most important steps. Every Android application with UI must implement Activity and View. By the first steps we create blank activity and default view layout. The simplest OpenCV-centric application must implement OpenCV initialization, create its own view to show -preview from camera and implements ``CvViewFrameListener2`` interface to get frames from camera and +preview from camera and implements ``CvCameraViewListener2`` interface to get frames from camera and process it. First of all we create our application view using xml layout. Our layout consists of the only diff --git a/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.rst b/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.rst index f582d3208..9aa1f6289 100644 --- a/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.rst +++ b/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.rst @@ -25,29 +25,34 @@ Let's use a simple program such as DisplayImage.cpp shown below. .. code-block:: cpp - #include - #include + #include + #include - using namespace cv; + using namespace cv; - int main( int argc, char** argv ) - { - Mat image; - image = imread( argv[1], 1 ); + int main(int argc, char** argv ) + { + if ( argc != 2 ) + { + printf("usage: DisplayImage.out \n"); + return -1; + } - if( argc != 2 || !image.data ) - { - printf( "No image data \n" ); - return -1; - } + Mat image; + image = imread( argv[1], 1 ); - namedWindow( "Display Image", CV_WINDOW_AUTOSIZE ); - imshow( "Display Image", image ); + if ( !image.data ) + { + printf("No image data \n"); + return -1; + } + namedWindow("Display Image", CV_WINDOW_AUTOSIZE ); + imshow("Display Image", image); - waitKey(0); + waitKey(0); - return 0; - } + return 0; + } Create a CMake file --------------------- diff --git a/doc/tutorials/introduction/linux_install/linux_install.rst b/doc/tutorials/introduction/linux_install/linux_install.rst index 1e02b64c9..b0dcf6236 100644 --- a/doc/tutorials/introduction/linux_install/linux_install.rst +++ b/doc/tutorials/introduction/linux_install/linux_install.rst @@ -7,22 +7,24 @@ These steps have been tested for Ubuntu 10.04 but should work with other distros Required Packages ================= - * GCC 4.4.x or later. This can be installed with: + * GCC 4.4.x or later + * CMake 2.6 or higher + * Git + * GTK+2.x or higher, including headers (libgtk2.0-dev) + * pkg-config + * Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy) + * ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev + * [optional] libtbb2 libtbb-dev + * [optional] libdc1394 2.x + * [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev + +The packages can be installed using a terminal and the following commands or by using Synaptic Manager: .. code-block:: bash - sudo apt-get install build-essential - - * CMake 2.6 or higher; - * Git; - * GTK+2.x or higher, including headers (libgtk2.0-dev); - * pkgconfig; - * Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy); - * ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev; - * [optional] libdc1394 2.x; - * [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev. - -All the libraries above can be installed via Terminal or by using Synaptic Manager. + [compiler] sudo apt-get install build-essential + [required] sudo apt-get install cmake git libgtk2-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev + [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev Getting OpenCV Source Code ========================== diff --git a/doc/tutorials/introduction/load_save_image/load_save_image.rst b/doc/tutorials/introduction/load_save_image/load_save_image.rst index 50fb9ea37..6f8150a00 100644 --- a/doc/tutorials/introduction/load_save_image/load_save_image.rst +++ b/doc/tutorials/introduction/load_save_image/load_save_image.rst @@ -5,7 +5,7 @@ Load, Modify, and Save an Image .. note:: - We assume that by now you know how to load an image using :imread:`imread <>` and to display it in a window (using :imshow:`imshow <>`). Read the :ref:`Display_Image` tutorial otherwise. + We assume that by now you know how to load an image using :readwriteimagevideo:`imread ` and to display it in a window (using :user_interface:`imshow `). Read the :ref:`Display_Image` tutorial otherwise. Goals ====== @@ -14,9 +14,9 @@ In this tutorial you will learn how to: .. container:: enumeratevisibleitemswithsquare - * Load an image using :imread:`imread <>` - * Transform an image from BGR to Grayscale format by using :cvt_color:`cvtColor <>` - * Save your transformed image in a file on disk (using :imwrite:`imwrite <>`) + * Load an image using :readwriteimagevideo:`imread ` + * Transform an image from BGR to Grayscale format by using :miscellaneous_transformations:`cvtColor ` + * Save your transformed image in a file on disk (using :readwriteimagevideo:`imwrite `) Code ====== @@ -63,10 +63,7 @@ Here it is: Explanation ============ -#. We begin by: - - * Creating a Mat object to store the image information - * Load an image using :imread:`imread <>`, located in the path given by *imageName*. Fort this example, assume you are loading a RGB image. +#. We begin by loading an image using :readwriteimagevideo:`imread `, located in the path given by *imageName*. For this example, assume you are loading a RGB image. #. Now we are going to convert our image from BGR to Grayscale format. OpenCV has a really nice function to do this kind of transformations: @@ -74,15 +71,15 @@ Explanation cvtColor( image, gray_image, CV_BGR2GRAY ); - As you can see, :cvt_color:`cvtColor <>` takes as arguments: + As you can see, :miscellaneous_transformations:`cvtColor ` takes as arguments: .. container:: enumeratevisibleitemswithsquare * a source image (*image*) * a destination image (*gray_image*), in which we will save the converted image. - * an additional parameter that indicates what kind of transformation will be performed. In this case we use **CV_BGR2GRAY** (because of :imread:`imread <>` has BGR default channel order in case of color images). + * an additional parameter that indicates what kind of transformation will be performed. In this case we use **CV_BGR2GRAY** (because of :readwriteimagevideo:`imread ` has BGR default channel order in case of color images). -#. So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to :imread:`imread <>`: :imwrite:`imwrite <>` +#. So now we have our new *gray_image* and want to save it on disk (otherwise it will get lost after the program ends). To save it, we will use a function analagous to :readwriteimagevideo:`imread `: :readwriteimagevideo:`imwrite ` .. code-block:: cpp @@ -100,7 +97,7 @@ Explanation imshow( imageName, image ); imshow( "Gray image", gray_image ); -#. Add add the *waitKey(0)* function call for the program to wait forever for an user key press. +#. Add the *waitKey(0)* function call for the program to wait forever for an user key press. Result diff --git a/doc/tutorials/introduction/windows_install/windows_install.rst b/doc/tutorials/introduction/windows_install/windows_install.rst index c29c13aed..abb39cd13 100644 --- a/doc/tutorials/introduction/windows_install/windows_install.rst +++ b/doc/tutorials/introduction/windows_install/windows_install.rst @@ -55,7 +55,7 @@ Building the OpenCV library from scratch requires a couple of tools installed be .. |TortoiseGit| replace:: TortoiseGit .. _TortoiseGit: http://code.google.com/p/tortoisegit/wiki/Download .. |Python_Libraries| replace:: Python libraries -.. _Python_Libraries: http://www.python.org/getit/ +.. _Python_Libraries: http://www.python.org/downloads/ .. |Numpy| replace:: Numpy .. _Numpy: http://numpy.scipy.org/ .. |IntelTBB| replace:: Intel |copy| Threading Building Blocks (*TBB*) @@ -81,7 +81,7 @@ Building the OpenCV library from scratch requires a couple of tools installed be + An IDE of choice (preferably), or just a C\C++ compiler that will actually make the binary files. Here we will use the `Microsoft Visual Studio `_. However, you can use any other IDE that has a valid C\C++ compiler. - + |CMake|_, which is a neat tool to make the project files (for your choosen IDE) from the OpenCV source files. It will also allow an easy configuration of the OpenCV build files, in order to make binary files that fits exactly to your needs. + + |CMake|_, which is a neat tool to make the project files (for your chosen IDE) from the OpenCV source files. It will also allow an easy configuration of the OpenCV build files, in order to make binary files that fits exactly to your needs. + Git to acquire the OpenCV source files. A good tool for this is |TortoiseGit|_. Alternatively, you can just download an archived version of the source files from our `page on Sourceforge `_ diff --git a/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.rst b/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.rst index 3fd734f35..2ec616fbc 100644 --- a/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.rst +++ b/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.rst @@ -90,17 +90,25 @@ A full list, for the latest version would contain: .. code-block:: bash - opencv_core231d.lib - opencv_imgproc231d.lib - opencv_highgui231d.lib - opencv_ml231d.lib - opencv_video231d.lib - opencv_features2d231d.lib - opencv_calib3d231d.lib - opencv_objdetect231d.lib - opencv_contrib231d.lib - opencv_legacy231d.lib - opencv_flann231d.lib + opencv_calib3d249d.lib + opencv_contrib249d.lib + opencv_core249d.lib + opencv_features2d249d.lib + opencv_flann249d.lib + opencv_gpu249d.lib + opencv_highgui249d.lib + opencv_imgproc249d.lib + opencv_legacy249d.lib + opencv_ml249d.lib + opencv_nonfree249d.lib + opencv_objdetect249d.lib + opencv_ocl249d.lib + opencv_photo249d.lib + opencv_stitching249d.lib + opencv_superres249d.lib + opencv_ts249d.lib + opencv_video249d.lib + opencv_videostab249d.lib The letter *d* at the end just indicates that these are the libraries required for the debug. Now click ok to save and do the same with a new property inside the Release rule section. Make sure to omit the *d* letters from the library names and to save the property sheets with the save icon above them. diff --git a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst index 1337ff3a1..f7d7a1506 100644 --- a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst +++ b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst @@ -78,6 +78,8 @@ Make sure your active solution configuration (:menuselection:`Build --> Configur Build your solution (:menuselection:`Build --> Build Solution`, or press *F7*). +Before continuing, do not forget to add the command line argument of your input image to your project (:menuselection:`Right click on project --> Properties --> Configuration Properties --> Debugging` and then set the field ``Command Arguments`` with the location of the image). + Now set a breakpoint on the source line that says .. code-block:: c++ diff --git a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst index 50f734803..574071de7 100644 --- a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst +++ b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst @@ -105,8 +105,8 @@ Explanation .. code-block:: cpp - Mat trainingDataMat(3, 2, CV_32FC1, trainingData); - Mat labelsMat (3, 1, CV_32FC1, labels); + Mat trainingDataMat(4, 2, CV_32FC1, trainingData); + Mat labelsMat (4, 1, CV_32FC1, labels); 2. **Set up SVM's parameters** diff --git a/doc/tutorials/tutorials.rst b/doc/tutorials/tutorials.rst index cbc51c195..3c4e9213e 100644 --- a/doc/tutorials/tutorials.rst +++ b/doc/tutorials/tutorials.rst @@ -102,7 +102,7 @@ As always, we would be happy to hear your comments and receive your contribution .. cssclass:: toctableopencv =========== ======================================================= - |Video| Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions. + |Video| Look here in order to find use on your video stream algorithms like: motion extraction, feature tracking and foreground extractions. =========== ======================================================= @@ -186,6 +186,21 @@ As always, we would be happy to hear your comments and receive your contribution :width: 80pt :alt: gpu icon +* :ref:`Table-Of-Content-Viz` + + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + + =========== ======================================================= + |Viz| These tutorials show how to use Viz module effectively. + + =========== ======================================================= + + .. |Viz| image:: images/viz.jpg + :height: 80pt + :width: 80pt + :alt: viz icon + * :ref:`Table-Of-Content-General` .. tabularcolumns:: m{100pt} m{300pt} @@ -221,4 +236,5 @@ As always, we would be happy to hear your comments and receive your contribution gpu/table_of_content_gpu/table_of_content_gpu contrib/table_of_content_contrib/table_of_content_contrib ios/table_of_content_ios/table_of_content_ios + viz/table_of_content_viz/table_of_content_viz general/table_of_content_general/table_of_content_general diff --git a/doc/tutorials/video/table_of_content_video/table_of_content_video.rst b/doc/tutorials/video/table_of_content_video/table_of_content_video.rst index a2521d695..ddcad0c70 100644 --- a/doc/tutorials/video/table_of_content_video/table_of_content_video.rst +++ b/doc/tutorials/video/table_of_content_video/table_of_content_video.rst @@ -3,7 +3,7 @@ *video* module. Video analysis ----------------------------------------------------------- -Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions. +Look here in order to find use on your video stream algorithms like: motion extraction, feature tracking and foreground extractions. .. include:: ../../definitions/noContent.rst diff --git a/doc/tutorials/viz/creating_widgets/creating_widgets.rst b/doc/tutorials/viz/creating_widgets/creating_widgets.rst new file mode 100644 index 000000000..8858035c3 --- /dev/null +++ b/doc/tutorials/viz/creating_widgets/creating_widgets.rst @@ -0,0 +1,159 @@ +.. _creating_widgets: + +Creating Widgets +**************** + +Goal +==== + +In this tutorial you will learn how to + +.. container:: enumeratevisibleitemswithsquare + + * Create your own widgets using WidgetAccessor and VTK. + * Show your widget in the visualization window. + +Code +==== + +You can download the code from :download:`here <../../../../samples/cpp/tutorial_code/viz/creating_widgets.cpp>`. + +.. code-block:: cpp + + #include + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + + using namespace cv; + using namespace std; + + /** + * @class WTriangle + * @brief Defining our own 3D Triangle widget + */ + class WTriangle : public viz::Widget3D + { + public: + WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); + }; + + /** + * @function WTriangle::WTriangle + */ + WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color) + { + // Create a triangle + vtkSmartPointer points = vtkSmartPointer::New(); + points->InsertNextPoint(pt1.x, pt1.y, pt1.z); + points->InsertNextPoint(pt2.x, pt2.y, pt2.z); + points->InsertNextPoint(pt3.x, pt3.y, pt3.z); + + vtkSmartPointer triangle = vtkSmartPointer::New(); + triangle->GetPointIds()->SetId(0,0); + triangle->GetPointIds()->SetId(1,1); + triangle->GetPointIds()->SetId(2,2); + + vtkSmartPointer cells = vtkSmartPointer::New(); + cells->InsertNextCell(triangle); + + // Create a polydata object + vtkSmartPointer polyData = vtkSmartPointer::New(); + + // Add the geometry and topology to the polydata + polyData->SetPoints(points); + polyData->SetPolys(cells); + + // Create mapper and actor + vtkSmartPointer mapper = vtkSmartPointer::New(); + #if VTK_MAJOR_VERSION <= 5 + mapper->SetInput(polyData); + #else + mapper->SetInputData(polyData); + #endif + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + // Store this actor in the widget in order that visualizer can access it + viz::WidgetAccessor::setProp(*this, actor); + + // Set the color of the widget. This has to be called after WidgetAccessor. + setColor(color); + } + + /** + * @function main + */ + int main() + { + /// Create a window + viz::Viz3d myWindow("Creating Widgets"); + + /// Create a triangle widget + WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); + + /// Show widget in the visualizer window + myWindow.showWidget("TRIANGLE", tw); + + /// Start event loop + myWindow.spin(); + + return 0; + } + +Explanation +=========== + +Here is the general structure of the program: + +* Extend Widget3D class to create a new 3D widget. + +.. code-block:: cpp + + class WTriangle : public viz::Widget3D + { + public: + WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); + }; + +* Assign a VTK actor to the widget. + +.. code-block:: cpp + + // Store this actor in the widget in order that visualizer can access it + viz::WidgetAccessor::setProp(*this, actor); + +* Set color of the widget. + +.. code-block:: cpp + + // Set the color of the widget. This has to be called after WidgetAccessor. + setColor(color); + +* Construct a triangle widget and display it in the window. + +.. code-block:: cpp + + /// Create a triangle widget + WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); + + /// Show widget in the visualizer window + myWindow.showWidget("TRIANGLE", tw); + +Results +======= + +Here is the result of the program. + +.. image:: images/red_triangle.png + :alt: Creating Widgets + :align: center diff --git a/doc/tutorials/viz/creating_widgets/images/red_triangle.png b/doc/tutorials/viz/creating_widgets/images/red_triangle.png new file mode 100644 index 000000000..7da6ad060 Binary files /dev/null and b/doc/tutorials/viz/creating_widgets/images/red_triangle.png differ diff --git a/doc/tutorials/viz/launching_viz/images/window_demo.png b/doc/tutorials/viz/launching_viz/images/window_demo.png new file mode 100644 index 000000000..b853fe29d Binary files /dev/null and b/doc/tutorials/viz/launching_viz/images/window_demo.png differ diff --git a/doc/tutorials/viz/launching_viz/launching_viz.rst b/doc/tutorials/viz/launching_viz/launching_viz.rst new file mode 100644 index 000000000..a3dd5d93c --- /dev/null +++ b/doc/tutorials/viz/launching_viz/launching_viz.rst @@ -0,0 +1,118 @@ +.. _launching_viz: + +Launching Viz +************* + +Goal +==== + +In this tutorial you will learn how to + +.. container:: enumeratevisibleitemswithsquare + + * Open a visualization window. + * Access a window by its name. + * Start event loop. + * Start event loop for a given amount of time. + +Code +==== + +You can download the code from :download:`here <../../../../samples/cpp/tutorial_code/viz/launching_viz.cpp>`. + +.. code-block:: cpp + + #include + #include + + using namespace cv; + using namespace std; + + /** + * @function main + */ + int main() + { + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + + /// Start event loop + myWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "First event loop is over" << endl; + + /// Access window via its name + viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo"); + + /// Start event loop + sameWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "Second event loop is over" << endl; + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + + /// Once more event loop is stopped + cout << "Last event loop is over" << endl; + return 0; + } + +Explanation +=========== + +Here is the general structure of the program: + +* Create a window. + +.. code-block:: cpp + + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + +* Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**. + +.. code-block:: cpp + + /// Start event loop + myWindow.spin(); + +* Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly the same with **myWindow**. If the name does not exist, a new window is created. + +.. code-block:: cpp + + /// Access window via its name + viz::Viz3d sameWindow = viz::get("Viz Demo"); + +* Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping. Inside the while loop, user can execute other statements including those which interact with the window. + +.. code-block:: cpp + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + +Results +======= + +Here is the result of the program. + +.. image:: images/window_demo.png + :alt: Launching Viz + :align: center diff --git a/doc/tutorials/viz/table_of_content_viz/images/facedetect.jpg b/doc/tutorials/viz/table_of_content_viz/images/facedetect.jpg new file mode 100644 index 000000000..788b7d826 Binary files /dev/null and b/doc/tutorials/viz/table_of_content_viz/images/facedetect.jpg differ diff --git a/doc/tutorials/viz/table_of_content_viz/images/image_effects.png b/doc/tutorials/viz/table_of_content_viz/images/image_effects.png new file mode 100644 index 000000000..1a675ce74 Binary files /dev/null and b/doc/tutorials/viz/table_of_content_viz/images/image_effects.png differ diff --git a/doc/tutorials/viz/table_of_content_viz/images/intro.png b/doc/tutorials/viz/table_of_content_viz/images/intro.png new file mode 100644 index 000000000..4f54cfb91 Binary files /dev/null and b/doc/tutorials/viz/table_of_content_viz/images/intro.png differ diff --git a/doc/tutorials/viz/table_of_content_viz/table_of_content_viz.rst b/doc/tutorials/viz/table_of_content_viz/table_of_content_viz.rst new file mode 100644 index 000000000..c3d08fe17 --- /dev/null +++ b/doc/tutorials/viz/table_of_content_viz/table_of_content_viz.rst @@ -0,0 +1,94 @@ +.. _Table-Of-Content-Viz: + +**OpenCV Viz** +----------------------------------------------------------- + +.. include:: ../../definitions/tocDefinitions.rst + ++ + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + + ================== =============================================================================== + |VizLaunchingViz| **Title:** :ref:`launching_viz` + + *Compatibility:* > OpenCV 3.0.0 + + *Author:* Ozan Tonkal + + You will learn how to launch a viz window. + + ================== =============================================================================== + + .. |VizLaunchingViz| image:: ../launching_viz/images/window_demo.png + :height: 120pt + :width: 90pt + ++ + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + + ================ ============================================================================ + |WidgetPose| **Title:** :ref:`widget_pose` + + *Compatibility:* > OpenCV 3.0.0 + + *Author:* Ozan Tonkal + + You will learn how to change pose of a widget. + + ================ ============================================================================ + + .. |WidgetPose| image:: ../widget_pose/images/widgetpose.png + :height: 90pt + :width: 90pt + ++ + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + + ================== ============================================================================ + |Transformations| **Title:** :ref:`transformations` + + *Compatibility:* > OpenCV 3.0.0 + + *Author:* Ozan Tonkal + + You will learn how to transform between global and camera frames. + + ================== ============================================================================ + + .. |Transformations| image:: ../transformations/images/global_view_point.png + :height: 120pt + :width: 90pt + ++ + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + + ================== ============================================================================ + |CreatingWidgets| **Title:** :ref:`creating_widgets` + + *Compatibility:* > OpenCV 3.0.0 + + *Author:* Ozan Tonkal + + You will learn how to create your own widgets. + + ================== ============================================================================ + + .. |CreatingWidgets| image:: ../creating_widgets/images/red_triangle.png + :height: 120pt + :width: 90pt + +.. raw:: latex + + \pagebreak + +.. toctree:: + :hidden: + + ../launching_viz/launching_viz + ../widget_pose/widget_pose + ../transformations/transformations + ../creating_widgets/creating_widgets diff --git a/doc/tutorials/viz/transformations/images/camera_view_point.png b/doc/tutorials/viz/transformations/images/camera_view_point.png new file mode 100644 index 000000000..e2ac5b0f0 Binary files /dev/null and b/doc/tutorials/viz/transformations/images/camera_view_point.png differ diff --git a/doc/tutorials/viz/transformations/images/global_view_point.png b/doc/tutorials/viz/transformations/images/global_view_point.png new file mode 100644 index 000000000..fc6de2c1a Binary files /dev/null and b/doc/tutorials/viz/transformations/images/global_view_point.png differ diff --git a/doc/tutorials/viz/transformations/transformations.rst b/doc/tutorials/viz/transformations/transformations.rst new file mode 100644 index 000000000..d1f2d0c2e --- /dev/null +++ b/doc/tutorials/viz/transformations/transformations.rst @@ -0,0 +1,202 @@ +.. _transformations: + +Transformations +*************** + +Goal +==== + +In this tutorial you will learn how to + +.. container:: enumeratevisibleitemswithsquare + + * How to use makeTransformToGlobal to compute pose + * How to use makeCameraPose and Viz3d::setViewerPose + * How to visualize camera position by axes and by viewing frustum + +Code +==== + +You can download the code from :download:`here <../../../../samples/cpp/tutorial_code/viz/transformations.cpp>`. + +.. code-block:: cpp + + #include + #include + #include + + using namespace cv; + using namespace std; + + /** + * @function cvcloud_load + * @brief load bunny.ply + */ + Mat cvcloud_load() + { + Mat cloud(1, 1889, CV_32FC3); + ifstream ifs("bunny.ply"); + + string str; + for(size_t i = 0; i < 12; ++i) + getline(ifs, str); + + Point3f* data = cloud.ptr(); + float dummy1, dummy2; + for(size_t i = 0; i < 1889; ++i) + ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2; + + cloud *= 5.0f; + return cloud; + } + + /** + * @function main + */ + int main(int argn, char **argv) + { + if (argn < 2) + { + cout << "Usage: " << endl << "./transformations [ G | C ]" << endl; + return 1; + } + + bool camera_pov = (argv[1][0] == 'C'); + + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Let's assume camera has the following properties + Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + + /// We can get the pose of the cam using makeCameraPose + Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + + /// Create a cloud widget. + Mat bunny_cloud = cvcloud_load(); + viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + + /// Pose of the widget in camera frame + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + /// Pose of the widget in global frame + Affine3f cloud_pose_global = transform * cloud_pose; + + /// Visualize camera frame + if (!camera_pov) + { + viz::WCameraPosition cpw(0.5); // Coordinate axes + viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + myWindow.showWidget("CPW", cpw, cam_pose); + myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); + } + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(cam_pose); + + /// Start event loop. + myWindow.spin(); + + return 0; + } + + +Explanation +=========== + +Here is the general structure of the program: + +* Create a visualization window. + +.. code-block:: cpp + + /// Create a window + viz::Viz3d myWindow("Transformations"); + +* Get camera pose from camera position, camera focal point and y direction. + +.. code-block:: cpp + + /// Let's assume camera has the following properties + Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + + /// We can get the pose of the cam using makeCameraPose + Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); + +* Obtain transform matrix knowing the axes of camera coordinate system. + +.. code-block:: cpp + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + +* Create a cloud widget from bunny.ply file + +.. code-block:: cpp + + /// Create a cloud widget. + Mat bunny_cloud = cvcloud_load(); + viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + +* Given the pose in camera coordinate system, estimate the global pose. + +.. code-block:: cpp + + /// Pose of the widget in camera frame + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + /// Pose of the widget in global frame + Affine3f cloud_pose_global = transform * cloud_pose; + +* If the view point is set to be global, visualize camera coordinate frame and viewing frustum. + +.. code-block:: cpp + + /// Visualize camera frame + if (!camera_pov) + { + viz::WCameraPosition cpw(0.5); // Coordinate axes + viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + myWindow.showWidget("CPW", cpw, cam_pose); + myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); + } + +* Visualize the cloud widget with the estimated global pose + +.. code-block:: cpp + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + +* If the view point is set to be camera's, set viewer pose to **cam_pose**. + +.. code-block:: cpp + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(cam_pose); + +Results +======= + +#. Here is the result from the camera point of view. + + .. image:: images/camera_view_point.png + :alt: Camera Viewpoint + :align: center + +#. Here is the result from global point of view. + + .. image:: images/global_view_point.png + :alt: Global Viewpoint + :align: center diff --git a/doc/tutorials/viz/widget_pose/images/widgetpose.png b/doc/tutorials/viz/widget_pose/images/widgetpose.png new file mode 100644 index 000000000..ef8a5937f Binary files /dev/null and b/doc/tutorials/viz/widget_pose/images/widgetpose.png differ diff --git a/doc/tutorials/viz/widget_pose/widget_pose.rst b/doc/tutorials/viz/widget_pose/widget_pose.rst new file mode 100644 index 000000000..a4466bded --- /dev/null +++ b/doc/tutorials/viz/widget_pose/widget_pose.rst @@ -0,0 +1,162 @@ +.. _widget_pose: + +Pose of a widget +**************** + +Goal +==== + +In this tutorial you will learn how to + +.. container:: enumeratevisibleitemswithsquare + + * Add widgets to the visualization window + * Use Affine3 to set pose of a widget + * Rotating and translating a widget along an axis + +Code +==== + +You can download the code from :download:`here <../../../../samples/cpp/tutorial_code/viz/widget_pose.cpp>`. + +.. code-block:: cpp + + #include + #include + #include + + using namespace cv; + using namespace std; + + /** + * @function main + */ + int main() + { + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Add line to represent (1,1,1) axis + viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); + axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Line Widget", axis); + + /// Construct a cube widget + viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); + cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); + + /// Display widget (update if already displayed) + myWindow.showWidget("Cube Widget", cube_widget); + + /// Rodrigues vector + Mat rot_vec = Mat::zeros(1,3,CV_32F); + float translation_phase = 0.0, translation = 0.0; + while(!myWindow.wasStopped()) + { + /* Rotation using rodrigues */ + /// Rotate around (1,1,1) + rot_vec.at(0,0) += CV_PI * 0.01f; + rot_vec.at(0,1) += CV_PI * 0.01f; + rot_vec.at(0,2) += CV_PI * 0.01f; + + /// Shift on (1,1,1) + translation_phase += CV_PI * 0.01f; + translation = sin(translation_phase); + + Mat rot_mat; + Rodrigues(rot_vec, rot_mat); + + /// Construct pose + Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); + + myWindow.setWidgetPose("Cube Widget", pose); + + myWindow.spinOnce(1, true); + } + + return 0; + } + +Explanation +=========== + +Here is the general structure of the program: + +* Create a visualization window. + +.. code-block:: cpp + + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + +* Show coordinate axes in the window using CoordinateSystemWidget. + +.. code-block:: cpp + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + +* Display a line representing the axis (1,1,1). + +.. code-block:: cpp + + /// Add line to represent (1,1,1) axis + viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); + axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Line Widget", axis); + +* Construct a cube. + +.. code-block:: cpp + + /// Construct a cube widget + viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); + cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Cube Widget", cube_widget); + +* Create rotation matrix from rodrigues vector + +.. code-block:: cpp + + /// Rotate around (1,1,1) + rot_vec.at(0,0) += CV_PI * 0.01f; + rot_vec.at(0,1) += CV_PI * 0.01f; + rot_vec.at(0,2) += CV_PI * 0.01f; + + ... + + Mat rot_mat; + Rodrigues(rot_vec, rot_mat); + +* Use Affine3f to set pose of the cube. + +.. code-block:: cpp + + /// Construct pose + Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); + myWindow.setWidgetPose("Cube Widget", pose); + +* Animate the rotation using wasStopped and spinOnce + +.. code-block:: cpp + + while(!myWindow.wasStopped()) + { + ... + + myWindow.spinOnce(1, true); + } + +Results +======= + +Here is the result of the program. + +.. raw:: html + +
+ +
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index ed3b85a8f..b4e48e6fa 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,7 +1,7 @@ file(GLOB old_hdrs "opencv/*.h*") install(FILES ${old_hdrs} DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv - COMPONENT main) + COMPONENT dev) install(FILES "opencv2/opencv.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 - COMPONENT main) + COMPONENT dev) diff --git a/modules/androidcamera/CMakeLists.txt b/modules/androidcamera/CMakeLists.txt index 8ac8ced88..3858ba9f6 100644 --- a/modules/androidcamera/CMakeLists.txt +++ b/modules/androidcamera/CMakeLists.txt @@ -40,6 +40,6 @@ else() get_filename_component(wrapper_name "${wrapper}" NAME) install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} - COMPONENT main) + COMPONENT libs) endforeach() endif() diff --git a/modules/androidcamera/camera_wrapper/CMakeLists.txt b/modules/androidcamera/camera_wrapper/CMakeLists.txt index 21b9ee1ad..d08e2c469 100644 --- a/modules/androidcamera/camera_wrapper/CMakeLists.txt +++ b/modules/androidcamera/camera_wrapper/CMakeLists.txt @@ -58,9 +58,9 @@ SET_TARGET_PROPERTIES(${the_target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} ) -if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) +if (NOT (CMAKE_BUILD_TYPE MATCHES "Debug")) ADD_CUSTOM_COMMAND( TARGET ${the_target} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${LIBRARY_OUTPUT_PATH}/lib${the_target}.so" ) endif() -install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs) diff --git a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp index 5ca1778a5..0ed301323 100644 --- a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp +++ b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp @@ -61,6 +61,12 @@ using namespace android; +// non-public camera related classes are not binary compatible +// objects of these classes have different sizeof on different platforms +// additional memory tail to all system objects to overcome sizeof issue +#define MAGIC_TAIL 4096 + + void debugShowFPS(); #if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) @@ -90,6 +96,7 @@ public: }; #endif + std::string getProcessName() { std::string result; @@ -142,12 +149,22 @@ class CameraHandler: public CameraListener protected: int cameraId; sp camera; - CameraParameters params; +#if defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) + sp surface; +#endif +#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) + sp queue; + sp listener; +#endif + CameraParameters* params; CameraCallback cameraCallback; void* userData; int emptyCameraCallbackReported; + int width; + int height; + static const char* flashModesNames[ANDROID_CAMERA_FLASH_MODES_NUM]; static const char* focusModesNames[ANDROID_CAMERA_FOCUS_MODES_NUM]; static const char* whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM]; @@ -258,7 +275,7 @@ protected: int is_supported(const char* supp_modes_key, const char* mode) { - const char* supported_modes = params.get(supp_modes_key); + const char* supported_modes = params->get(supp_modes_key); return (supported_modes && mode && (strstr(supported_modes, mode) > 0)); } @@ -268,7 +285,7 @@ protected: if (focus_distance_type >= 0 && focus_distance_type < 3) { float focus_distances[3]; - const char* output = params.get(CameraParameters::KEY_FOCUS_DISTANCES); + const char* output = params->get(CameraParameters::KEY_FOCUS_DISTANCES); int val_num = CameraHandler::split_float(output, focus_distances, ',', 3); if(val_num == 3) { @@ -300,10 +317,15 @@ public: emptyCameraCallbackReported(0) { LOGD("Instantiated new CameraHandler (%p, %p)", callback, _userData); + void* params_buffer = operator new(sizeof(CameraParameters) + MAGIC_TAIL); + params = new(params_buffer) CameraParameters(); } virtual ~CameraHandler() { + if (params) + params->~CameraParameters(); + operator delete(params); LOGD("CameraHandler destructor is called"); } @@ -371,10 +393,18 @@ const char* CameraHandler::focusModesNames[ANDROID_CAMERA_FOCUS_MODES_NUM] = CameraParameters::FOCUS_MODE_AUTO, #if !defined(ANDROID_r2_2_0) CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO, +#else + CameraParameters::FOCUS_MODE_AUTO, #endif CameraParameters::FOCUS_MODE_EDOF, CameraParameters::FOCUS_MODE_FIXED, - CameraParameters::FOCUS_MODE_INFINITY + CameraParameters::FOCUS_MODE_INFINITY, + CameraParameters::FOCUS_MODE_MACRO, +#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) + CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE +#else + CameraParameters::FOCUS_MODE_AUTO +#endif }; const char* CameraHandler::whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM] = @@ -534,39 +564,39 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, { LOGI("initCameraConnect: Setting paramers from previous camera handler"); camera->setParameters(prevCameraParameters->flatten()); - handler->params.unflatten(prevCameraParameters->flatten()); + handler->params->unflatten(prevCameraParameters->flatten()); } else { android::String8 params_str = camera->getParameters(); LOGI("initCameraConnect: [%s]", params_str.string()); - handler->params.unflatten(params_str); + handler->params->unflatten(params_str); - LOGD("Supported Cameras: %s", handler->params.get("camera-indexes")); - LOGD("Supported Picture Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); - LOGD("Supported Picture Formats: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS)); - LOGD("Supported Preview Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); - LOGD("Supported Preview Formats: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS)); - LOGD("Supported Preview Frame Rates: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES)); - LOGD("Supported Thumbnail Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES)); - LOGD("Supported Whitebalance Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE)); - LOGD("Supported Effects: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_EFFECTS)); - LOGD("Supported Scene Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES)); - LOGD("Supported Focus Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES)); - LOGD("Supported Antibanding Options: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_ANTIBANDING)); - LOGD("Supported Flash Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES)); + LOGD("Supported Cameras: %s", handler->params->get("camera-indexes")); + LOGD("Supported Picture Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); + LOGD("Supported Picture Formats: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS)); + LOGD("Supported Preview Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); + LOGD("Supported Preview Formats: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS)); + LOGD("Supported Preview Frame Rates: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES)); + LOGD("Supported Thumbnail Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES)); + LOGD("Supported Whitebalance Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE)); + LOGD("Supported Effects: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_EFFECTS)); + LOGD("Supported Scene Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_SCENE_MODES)); + LOGD("Supported Focus Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES)); + LOGD("Supported Antibanding Options: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_ANTIBANDING)); + LOGD("Supported Flash Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_FLASH_MODES)); #if !defined(ANDROID_r2_2_0) // Set focus mode to continuous-video if supported - const char* available_focus_modes = handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES); + const char* available_focus_modes = handler->params->get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES); if (available_focus_modes != 0) { if (strstr(available_focus_modes, "continuous-video") != NULL) { - handler->params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO); + handler->params->set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO); - status_t resParams = handler->camera->setParameters(handler->params.flatten()); + status_t resParams = handler->camera->setParameters(handler->params->flatten()); if (resParams != 0) { @@ -581,7 +611,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, #endif //check if yuv420sp format available. Set this format as preview format. - const char* available_formats = handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); + const char* available_formats = handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); if (available_formats != 0) { const char* format_to_set = 0; @@ -607,9 +637,9 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, if (0 != format_to_set) { - handler->params.setPreviewFormat(format_to_set); + handler->params->setPreviewFormat(format_to_set); - status_t resParams = handler->camera->setParameters(handler->params.flatten()); + status_t resParams = handler->camera->setParameters(handler->params->flatten()); if (resParams != 0) LOGE("initCameraConnect: failed to set preview format to %s", format_to_set); @@ -617,6 +647,13 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, LOGD("initCameraConnect: preview format is set to %s", format_to_set); } } + + handler->params->setPreviewSize(640, 480); + status_t resParams = handler->camera->setParameters(handler->params->flatten()); + if (resParams != 0) + LOGE("initCameraConnect: failed to set preview resolution to 640x480"); + else + LOGD("initCameraConnect: preview format is set to 640x480"); } status_t bufferStatus; @@ -627,22 +664,27 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, #elif defined(ANDROID_r2_3_3) /* Do nothing in case of 2.3 for now */ #elif defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) - sp surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); - bufferStatus = camera->setPreviewTexture(surfaceTexture); + void* surface_texture_obj = operator new(sizeof(SurfaceTexture) + MAGIC_TAIL); + handler->surface = new(surface_texture_obj) SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); + bufferStatus = camera->setPreviewTexture(handler->surface); if (bufferStatus != 0) LOGE("initCameraConnect: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus); #elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) - sp bufferQueue = new BufferQueue(); - sp queueListener = new ConsumerListenerStub(); - bufferQueue->consumerConnect(queueListener); - bufferStatus = camera->setPreviewTexture(bufferQueue); + void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); + handler->queue = new(buffer_queue_obj) BufferQueue(); + void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL); + handler->listener = new(consumer_listener_obj) ConsumerListenerStub(); + handler->queue->consumerConnect(handler->listener); + bufferStatus = camera->setPreviewTexture(handler->queue); if (bufferStatus != 0) LOGE("initCameraConnect: failed setPreviewTexture call; camera might not work correctly"); # elif defined(ANDROID_r4_4_0) - sp bufferQueue = new BufferQueue(); - sp queueListener = new ConsumerListenerStub(); - bufferQueue->consumerConnect(queueListener, true); - bufferStatus = handler->camera->setPreviewTarget(bufferQueue); + void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); + handler->queue = new(buffer_queue_obj) BufferQueue(); + void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL); + handler->listener = new(consumer_listener_obj) ConsumerListenerStub(); + handler->queue->consumerConnect(handler->listener, true); + bufferStatus = handler->camera->setPreviewTarget(handler->queue); if (bufferStatus != 0) LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); # endif @@ -723,18 +765,18 @@ double CameraHandler::getProperty(int propIdx) case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; - params.getPreviewSize(&w, &h); + params->getPreviewSize(&w, &h); return w; } case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; - params.getPreviewSize(&w, &h); + params->getPreviewSize(&w, &h); return h; } case ANDROID_CAMERA_PROPERTY_SUPPORTED_PREVIEW_SIZES_STRING: { - cameraPropertySupportedPreviewSizesString = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); + cameraPropertySupportedPreviewSizesString = params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); union {const char* str;double res;} u; memset(&u.res, 0, sizeof(u.res)); u.str = cameraPropertySupportedPreviewSizesString.c_str(); @@ -742,7 +784,7 @@ double CameraHandler::getProperty(int propIdx) } case ANDROID_CAMERA_PROPERTY_PREVIEW_FORMAT_STRING: { - const char* fmt = params.get(CameraParameters::KEY_PREVIEW_FORMAT); + const char* fmt = params->get(CameraParameters::KEY_PREVIEW_FORMAT); if (fmt == CameraParameters::PIXEL_FORMAT_YUV422SP) fmt = "yuv422sp"; else if (fmt == CameraParameters::PIXEL_FORMAT_YUV420SP) @@ -762,44 +804,44 @@ double CameraHandler::getProperty(int propIdx) } case ANDROID_CAMERA_PROPERTY_EXPOSURE: { - int exposure = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION); + int exposure = params->getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION); return exposure; } case ANDROID_CAMERA_PROPERTY_FPS: { - return params.getPreviewFrameRate(); + return params->getPreviewFrameRate(); } case ANDROID_CAMERA_PROPERTY_FLASH_MODE: { int flash_mode = getModeNum(CameraHandler::flashModesNames, ANDROID_CAMERA_FLASH_MODES_NUM, - params.get(CameraParameters::KEY_FLASH_MODE)); + params->get(CameraParameters::KEY_FLASH_MODE)); return flash_mode; } case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: { int focus_mode = getModeNum(CameraHandler::focusModesNames, ANDROID_CAMERA_FOCUS_MODES_NUM, - params.get(CameraParameters::KEY_FOCUS_MODE)); + params->get(CameraParameters::KEY_FOCUS_MODE)); return focus_mode; } case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: { int white_balance = getModeNum(CameraHandler::whiteBalanceModesNames, ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM, - params.get(CameraParameters::KEY_WHITE_BALANCE)); + params->get(CameraParameters::KEY_WHITE_BALANCE)); return white_balance; } case ANDROID_CAMERA_PROPERTY_ANTIBANDING: { int antibanding = getModeNum(CameraHandler::antibandingModesNames, ANDROID_CAMERA_ANTIBANDING_MODES_NUM, - params.get(CameraParameters::KEY_ANTIBANDING)); + params->get(CameraParameters::KEY_ANTIBANDING)); return antibanding; } case ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH: { - float focal_length = params.getFloat(CameraParameters::KEY_FOCAL_LENGTH); + float focal_length = params->getFloat(CameraParameters::KEY_FOCAL_LENGTH); return focal_length; } case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR: @@ -814,6 +856,24 @@ double CameraHandler::getProperty(int propIdx) { return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_FAR_INDEX); } +#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) + case ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK: + { + const char* status = params->get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK); + if (status == CameraParameters::TRUE) + return 1.; + else + return 0.; + } + case ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK: + { + const char* status = params->get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK); + if (status == CameraParameters::TRUE) + return 1.; + else + return 0.; + } +#endif default: LOGW("CameraHandler::getProperty - Unsupported property."); }; @@ -824,99 +884,151 @@ void CameraHandler::setProperty(int propIdx, double value) { LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value); + android::String8 params_str; + params_str = camera->getParameters(); + LOGI("Params before set: [%s]", params_str.string()); + switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; - params.getPreviewSize(&w, &h); - w = (int)value; - params.setPreviewSize(w, h); + params->getPreviewSize(&w, &h); + width = (int)value; } break; case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; - params.getPreviewSize(&w, &h); - h = (int)value; - params.setPreviewSize(w, h); + params->getPreviewSize(&w, &h); + height = (int)value; } break; case ANDROID_CAMERA_PROPERTY_EXPOSURE: { - int max_exposure = params.getInt("max-exposure-compensation"); - int min_exposure = params.getInt("min-exposure-compensation"); - if(max_exposure && min_exposure){ + int max_exposure = params->getInt("max-exposure-compensation"); + int min_exposure = params->getInt("min-exposure-compensation"); + if(max_exposure && min_exposure) + { int exposure = (int)value; - if(exposure >= min_exposure && exposure <= max_exposure){ - params.set("exposure-compensation", exposure); - } else { + if(exposure >= min_exposure && exposure <= max_exposure) + params->set("exposure-compensation", exposure); + else LOGE("Exposure compensation not in valid range (%i,%i).", min_exposure, max_exposure); - } - } else { + } else LOGE("Exposure compensation adjust is not supported."); - } + + camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_FLASH_MODE: { int new_val = (int)value; - if(new_val >= 0 && new_val < ANDROID_CAMERA_FLASH_MODES_NUM){ + if(new_val >= 0 && new_val < ANDROID_CAMERA_FLASH_MODES_NUM) + { const char* mode_name = flashModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_FLASH_MODES, mode_name)) - params.set(CameraParameters::KEY_FLASH_MODE, mode_name); + params->set(CameraParameters::KEY_FLASH_MODE, mode_name); else LOGE("Flash mode %s is not supported.", mode_name); - } else { - LOGE("Flash mode value not in valid range."); } + else + LOGE("Flash mode value not in valid range."); + + camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: { int new_val = (int)value; - if(new_val >= 0 && new_val < ANDROID_CAMERA_FOCUS_MODES_NUM){ + if(new_val >= 0 && new_val < ANDROID_CAMERA_FOCUS_MODES_NUM) + { const char* mode_name = focusModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, mode_name)) - params.set(CameraParameters::KEY_FOCUS_MODE, mode_name); + params->set(CameraParameters::KEY_FOCUS_MODE, mode_name); else LOGE("Focus mode %s is not supported.", mode_name); - } else { - LOGE("Focus mode value not in valid range."); } + else + LOGE("Focus mode value not in valid range."); + + camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: { int new_val = (int)value; - if(new_val >= 0 && new_val < ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM){ + if(new_val >= 0 && new_val < ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM) + { const char* mode_name = whiteBalanceModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, mode_name)) - params.set(CameraParameters::KEY_WHITE_BALANCE, mode_name); + params->set(CameraParameters::KEY_WHITE_BALANCE, mode_name); else LOGE("White balance mode %s is not supported.", mode_name); - } else { - LOGE("White balance mode value not in valid range."); } + else + LOGE("White balance mode value not in valid range."); + + camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_ANTIBANDING: { int new_val = (int)value; - if(new_val >= 0 && new_val < ANDROID_CAMERA_ANTIBANDING_MODES_NUM){ + if(new_val >= 0 && new_val < ANDROID_CAMERA_ANTIBANDING_MODES_NUM) + { const char* mode_name = antibandingModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_ANTIBANDING, mode_name)) - params.set(CameraParameters::KEY_ANTIBANDING, mode_name); + params->set(CameraParameters::KEY_ANTIBANDING, mode_name); else LOGE("Antibanding mode %s is not supported.", mode_name); - } else { - LOGE("Antibanding mode value not in valid range."); } + else + LOGE("Antibanding mode value not in valid range."); + + camera->setParameters(params->flatten()); } break; +#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) + case ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK: + { + if (is_supported(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, "true")) + { + if (value != 0) + params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::TRUE); + else + params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::FALSE); + LOGE("Expose lock is set"); + } + else + LOGE("Expose lock is not supported"); + + camera->setParameters(params->flatten()); + } + break; + case ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK: + { + if (is_supported(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, "true")) + { + if (value != 0) + params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::TRUE); + else + params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::FALSE); + LOGE("White balance lock is set"); + } + else + LOGE("White balance lock is not supported"); + + camera->setParameters(params->flatten()); + } + break; +#endif default: LOGW("CameraHandler::setProperty - Unsupported property."); }; + + params_str = camera->getParameters(); + LOGI("Params after set: [%s]", params_str.string()); } void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) @@ -935,7 +1047,10 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) return; } - CameraParameters curCameraParameters((*ppcameraHandler)->params.flatten()); + // delayed resolution setup to exclude errors during other parameres setup on the fly + // without camera restart + if (((*ppcameraHandler)->width != 0) && ((*ppcameraHandler)->height != 0)) + (*ppcameraHandler)->params->setPreviewSize((*ppcameraHandler)->width, (*ppcameraHandler)->height); #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \ || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) @@ -951,27 +1066,27 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) return; } - handler->camera->setParameters(curCameraParameters.flatten()); - handler->params.unflatten(curCameraParameters.flatten()); + handler->camera->setParameters((*ppcameraHandler)->params->flatten()); status_t bufferStatus; # if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) - sp surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); - bufferStatus = handler->camera->setPreviewTexture(surfaceTexture); + void* surface_texture_obj = operator new(sizeof(SurfaceTexture) + MAGIC_TAIL); + handler->surface = new(surface_texture_obj) SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); + bufferStatus = handler->camera->setPreviewTexture(handler->surface); if (bufferStatus != 0) LOGE("applyProperties: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus); # elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) - sp bufferQueue = new BufferQueue(); - sp queueListener = new ConsumerListenerStub(); - bufferQueue->consumerConnect(queueListener); - bufferStatus = handler->camera->setPreviewTexture(bufferQueue); + void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); + handler->queue = new(buffer_queue_obj) BufferQueue(); + handler->queue->consumerConnect(handler->listener); + bufferStatus = handler->camera->setPreviewTexture(handler->queue); if (bufferStatus != 0) LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); # elif defined(ANDROID_r4_4_0) - sp bufferQueue = new BufferQueue(); - sp queueListener = new ConsumerListenerStub(); - bufferQueue->consumerConnect(queueListener, true); - bufferStatus = handler->camera->setPreviewTarget(bufferQueue); + void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); + handler->queue = new(buffer_queue_obj) BufferQueue(); + handler->queue->consumerConnect(handler->listener, true); + bufferStatus = handler->camera->setPreviewTarget(handler->queue); if (bufferStatus != 0) LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); # endif @@ -1002,7 +1117,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect"); LOGD("CameraHandler::applyProperties(): before initCameraConnect"); - CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, &curCameraParameters); + CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, (*ppcameraHandler)->params); LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler); if (handler == NULL) { LOGE("ERROR in applyProperties --- cannot reinit camera"); diff --git a/modules/androidcamera/include/camera_properties.h b/modules/androidcamera/include/camera_properties.h index 2fec745fa..65499be2d 100644 --- a/modules/androidcamera/include/camera_properties.h +++ b/modules/androidcamera/include/camera_properties.h @@ -15,7 +15,9 @@ enum { ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH = 105, ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR = 106, ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL = 107, - ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR = 108 + ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR = 108, + ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK = 109, + ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK = 110 }; @@ -30,12 +32,12 @@ enum { enum { ANDROID_CAMERA_FOCUS_MODE_AUTO = 0, - ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_PICTURE, ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_VIDEO, ANDROID_CAMERA_FOCUS_MODE_EDOF, ANDROID_CAMERA_FOCUS_MODE_FIXED, ANDROID_CAMERA_FOCUS_MODE_INFINITY, ANDROID_CAMERA_FOCUS_MODE_MACRO, + ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_PICTURE, ANDROID_CAMERA_FOCUS_MODES_NUM }; diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index 37159b016..e6edfbeb2 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -217,9 +217,9 @@ Computes useful camera characteristics from the camera matrix. :param imageSize: Input image size in pixels. - :param apertureWidth: Physical width of the sensor. + :param apertureWidth: Physical width in mm of the sensor. - :param apertureHeight: Physical height of the sensor. + :param apertureHeight: Physical height in mm of the sensor. :param fovx: Output field of view in degrees along the horizontal sensor axis. @@ -227,13 +227,15 @@ Computes useful camera characteristics from the camera matrix. :param focalLength: Focal length of the lens in mm. - :param principalPoint: Principal point in pixels. + :param principalPoint: Principal point in mm. :param aspectRatio: :math:`f_y/f_x` The function computes various useful camera characteristics from the previously estimated camera matrix. +.. note:: + Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for the chessboard pitch (it can thus be any value). composeRT ------------- @@ -1483,6 +1485,10 @@ Reconstructs points by triangulation. The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their observations with a stereo camera. Projections matrices can be obtained from :ocv:func:`stereoRectify`. +.. note:: + + Keep in mind that all input data should be of float type in order for this function to work. + .. seealso:: :ocv:func:`reprojectImageTo3D` diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp index e0ffd70cf..557387d9a 100644 --- a/modules/calib3d/perf/perf_pnp.cpp +++ b/modules/calib3d/perf/perf_pnp.cpp @@ -126,7 +126,7 @@ PERF_TEST_P(PointsNum, DISABLED_SolvePnPRansac, testing::Values(4, 3*9, 7*13)) Mat tvec; #ifdef HAVE_TBB - // limit concurrency to get determenistic result + // limit concurrency to get deterministic result cv::Ptr one_thread = new tbb::task_scheduler_init(1); #endif diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 0b9d794a9..bf978bfb0 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -478,7 +478,7 @@ void CV_CameraCalibrationTest::run( int start_from ) values_read = fscanf(file,"%lf",goodDistortion+2); CV_Assert(values_read == 1); values_read = fscanf(file,"%lf",goodDistortion+3); CV_Assert(values_read == 1); - /* Read good Rot matrixes */ + /* Read good Rot matrices */ for( currImage = 0; currImage < numImages; currImage++ ) { for( i = 0; i < 3; i++ ) @@ -1605,7 +1605,7 @@ void CV_StereoCalibrationTest::run( int ) Mat _M1, _M2, _D1, _D2; vector _R1, _R2, _T1, _T2; calibrateCamera( objpt, imgpt1, imgsize, _M1, _D1, _R1, _T1, 0 ); - calibrateCamera( objpt, imgpt2, imgsize, _M2, _D2, _R2, _T1, 0 ); + calibrateCamera( objpt, imgpt2, imgsize, _M2, _D2, _R2, _T2, 0 ); undistortPoints( _imgpt1, _imgpt1, _M1, _D1, Mat(), _M1 ); undistortPoints( _imgpt2, _imgpt2, _M2, _D2, Mat(), _M2 ); diff --git a/modules/calib3d/test/test_chessboardgenerator.hpp b/modules/calib3d/test/test_chessboardgenerator.hpp index 48b3f3a24..6b669d2f5 100644 --- a/modules/calib3d/test/test_chessboardgenerator.hpp +++ b/modules/calib3d/test/test_chessboardgenerator.hpp @@ -34,7 +34,7 @@ private: Mat rvec, tvec; }; -}; +} #endif diff --git a/modules/calib3d/test/test_solvepnp_ransac.cpp b/modules/calib3d/test/test_solvepnp_ransac.cpp index 6c924a580..4c8d56a96 100644 --- a/modules/calib3d/test/test_solvepnp_ransac.cpp +++ b/modules/calib3d/test/test_solvepnp_ransac.cpp @@ -271,7 +271,7 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency) Mat tvec1, tvec2; { - // limit concurrency to get determenistic result + // limit concurrency to get deterministic result cv::theRNG().state = 20121010; cv::Ptr one_thread = new tbb::task_scheduler_init(1); solvePnPRansac(object, image, camera_mat, dist_coef, rvec1, tvec1); diff --git a/modules/contrib/doc/facerec/facerec_api.rst b/modules/contrib/doc/facerec/facerec_api.rst index 3100cfd8f..2aa3dcfa0 100644 --- a/modules/contrib/doc/facerec/facerec_api.rst +++ b/modules/contrib/doc/facerec/facerec_api.rst @@ -75,7 +75,7 @@ Moreover every :ocv:class:`FaceRecognizer` supports the: Setting the Thresholds +++++++++++++++++++++++ -Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common scenario in face recognition is to tell, wether a face belongs to the training dataset or if it is unknown. You might wonder, why there's no public API in :ocv:class:`FaceRecognizer` to set the threshold for the prediction, but rest assured: It's supported. It just means there's no generic way in an abstract class to provide an interface for setting/getting the thresholds of *every possible* :ocv:class:`FaceRecognizer` algorithm. The appropriate place to set the thresholds is in the constructor of the specific :ocv:class:`FaceRecognizer` and since every :ocv:class:`FaceRecognizer` is a :ocv:class:`Algorithm` (see above), you can get/set the thresholds at runtime! +Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common scenario in face recognition is to tell, whether a face belongs to the training dataset or if it is unknown. You might wonder, why there's no public API in :ocv:class:`FaceRecognizer` to set the threshold for the prediction, but rest assured: It's supported. It just means there's no generic way in an abstract class to provide an interface for setting/getting the thresholds of *every possible* :ocv:class:`FaceRecognizer` algorithm. The appropriate place to set the thresholds is in the constructor of the specific :ocv:class:`FaceRecognizer` and since every :ocv:class:`FaceRecognizer` is a :ocv:class:`Algorithm` (see above), you can get/set the thresholds at runtime! Here is an example of setting a threshold for the Eigenfaces method, when creating the model: diff --git a/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst b/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst index 770083170..95c821298 100644 --- a/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst +++ b/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst @@ -71,7 +71,7 @@ You really don't want to create the CSV file by hand. And you really don't want Fisherfaces for Gender Classification -------------------------------------- -If you want to decide wether a person is *male* or *female*, you have to learn the discriminative features of both classes. The Eigenfaces method is based on the Principal Component Analysis, which is an unsupervised statistical model and not suitable for this task. Please see the Face Recognition tutorial for insights into the algorithms. The Fisherfaces instead yields a class-specific linear projection, so it is much better suited for the gender classification task. `http://www.bytefish.de/blog/gender_classification `_ shows the recognition rate of the Fisherfaces method for gender classification. +If you want to decide whether a person is *male* or *female*, you have to learn the discriminative features of both classes. The Eigenfaces method is based on the Principal Component Analysis, which is an unsupervised statistical model and not suitable for this task. Please see the Face Recognition tutorial for insights into the algorithms. The Fisherfaces instead yields a class-specific linear projection, so it is much better suited for the gender classification task. `http://www.bytefish.de/blog/gender_classification `_ shows the recognition rate of the Fisherfaces method for gender classification. The Fisherfaces method achieves a 98% recognition rate in a subject-independent cross-validation. A subject-independent cross-validation means *images of the person under test are never used for learning the model*. And could you believe it: you can simply use the facerec_fisherfaces demo, that's inlcuded in OpenCV. diff --git a/modules/contrib/src/adaptiveskindetector.cpp b/modules/contrib/src/adaptiveskindetector.cpp index 0865ad70b..22f729d91 100644 --- a/modules/contrib/src/adaptiveskindetector.cpp +++ b/modules/contrib/src/adaptiveskindetector.cpp @@ -53,7 +53,7 @@ void CvAdaptiveSkinDetector::initData(IplImage *src, int widthDivider, int heigh imgGrayFrame = cvCreateImage(imageSize, IPL_DEPTH_8U, 1); imgLastGrayFrame = cvCreateImage(imageSize, IPL_DEPTH_8U, 1); imgHSVFrame = cvCreateImage(imageSize, IPL_DEPTH_8U, 3); -}; +} CvAdaptiveSkinDetector::CvAdaptiveSkinDetector(int samplingDivider, int morphingMethod) { @@ -78,7 +78,7 @@ CvAdaptiveSkinDetector::CvAdaptiveSkinDetector(int samplingDivider, int morphing imgLastGrayFrame = NULL; imgSaturationFrame = NULL; imgHSVFrame = NULL; -}; +} CvAdaptiveSkinDetector::~CvAdaptiveSkinDetector() { @@ -91,7 +91,7 @@ CvAdaptiveSkinDetector::~CvAdaptiveSkinDetector() cvReleaseImage(&imgGrayFrame); cvReleaseImage(&imgLastGrayFrame); cvReleaseImage(&imgHSVFrame); -}; +} void CvAdaptiveSkinDetector::process(IplImage *inputBGRImage, IplImage *outputHueMask) { @@ -188,7 +188,7 @@ void CvAdaptiveSkinDetector::process(IplImage *inputBGRImage, IplImage *outputHu if (outputHueMask != NULL) cvCopy(imgFilteredFrame, outputHueMask); -}; +} //------------------------- Histogram for Adaptive Skin Detector -------------------------// @@ -200,12 +200,12 @@ CvAdaptiveSkinDetector::Histogram::Histogram() float *ranges[] = { range }; fHistogram = cvCreateHist(1, histogramSize, CV_HIST_ARRAY, ranges, 1); cvClearHist(fHistogram); -}; +} CvAdaptiveSkinDetector::Histogram::~Histogram() { cvReleaseHist(&fHistogram); -}; +} int CvAdaptiveSkinDetector::Histogram::findCoverageIndex(double surfaceToCover, int defaultValue) { @@ -219,7 +219,7 @@ int CvAdaptiveSkinDetector::Histogram::findCoverageIndex(double surfaceToCover, } } return defaultValue; -}; +} void CvAdaptiveSkinDetector::Histogram::findCurveThresholds(int &x1, int &x2, double percent) { @@ -242,7 +242,7 @@ void CvAdaptiveSkinDetector::Histogram::findCurveThresholds(int &x1, int &x2, do x2 = GSD_HUE_UT; else x2 += GSD_HUE_LT; -}; +} void CvAdaptiveSkinDetector::Histogram::mergeWith(CvAdaptiveSkinDetector::Histogram *source, double weight) { @@ -283,4 +283,4 @@ void CvAdaptiveSkinDetector::Histogram::mergeWith(CvAdaptiveSkinDetector::Histog } } } -}; +} diff --git a/modules/contrib/src/ba.cpp b/modules/contrib/src/ba.cpp index 0e2afd95b..ec90cb79a 100644 --- a/modules/contrib/src/ba.cpp +++ b/modules/contrib/src/ba.cpp @@ -938,7 +938,7 @@ static void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, C #endif -}; +} static void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* estim, void* /*data*/) { //just do projections CvMat _Mi; @@ -977,17 +977,17 @@ static void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, C cvTranspose( _mp2, estim ); cvReleaseMat( &_mp ); cvReleaseMat( &_mp2 ); -}; +} static void fjac_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data) { CvMat _point_params = point_params, _cam_params = cam_params, _Al = A, _Bl = B; fjac(i,j, &_point_params, &_cam_params, &_Al, &_Bl, data); -}; +} static void func_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data) { CvMat _point_params = point_params, _cam_params = cam_params, _estim = estim; func(i,j,&_point_params,&_cam_params,&_estim,data); -}; +} void LevMarqSparse::bundleAdjust( vector& points, //positions of points in global coordinate system (input and output) const vector >& imagePoints, //projections of 3d points for every camera diff --git a/modules/contrib/src/basicretinafilter.hpp b/modules/contrib/src/basicretinafilter.hpp index 8bd136d68..f0b0de4aa 100644 --- a/modules/contrib/src/basicretinafilter.hpp +++ b/modules/contrib/src/basicretinafilter.hpp @@ -439,8 +439,8 @@ namespace cv #ifdef MAKE_PARALLEL /****************************************************** ** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors - ** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary - ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised + ** ==> main idea parallelize main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelized methods as necessary + ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelized ** ==> functors constructors can differ from the parameters used with their related serial functions */ diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index bd202d206..a3d695ad1 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -873,7 +873,7 @@ CV_INIT_ALGORITHM(Eigenfaces, "FaceRecognizer.Eigenfaces", obj.info()->addParam(obj, "labels", obj._labels, true); obj.info()->addParam(obj, "eigenvectors", obj._eigenvectors, true); obj.info()->addParam(obj, "eigenvalues", obj._eigenvalues, true); - obj.info()->addParam(obj, "mean", obj._mean, true)); + obj.info()->addParam(obj, "mean", obj._mean, true)) CV_INIT_ALGORITHM(Fisherfaces, "FaceRecognizer.Fisherfaces", obj.info()->addParam(obj, "ncomponents", obj._num_components); @@ -882,7 +882,7 @@ CV_INIT_ALGORITHM(Fisherfaces, "FaceRecognizer.Fisherfaces", obj.info()->addParam(obj, "labels", obj._labels, true); obj.info()->addParam(obj, "eigenvectors", obj._eigenvectors, true); obj.info()->addParam(obj, "eigenvalues", obj._eigenvalues, true); - obj.info()->addParam(obj, "mean", obj._mean, true)); + obj.info()->addParam(obj, "mean", obj._mean, true)) CV_INIT_ALGORITHM(LBPH, "FaceRecognizer.LBPH", obj.info()->addParam(obj, "radius", obj._radius); @@ -891,7 +891,7 @@ CV_INIT_ALGORITHM(LBPH, "FaceRecognizer.LBPH", obj.info()->addParam(obj, "grid_y", obj._grid_y); obj.info()->addParam(obj, "threshold", obj._threshold); obj.info()->addParam(obj, "histograms", obj._histograms, true); - obj.info()->addParam(obj, "labels", obj._labels, true)); + obj.info()->addParam(obj, "labels", obj._labels, true)) bool initModule_contrib() { diff --git a/modules/contrib/src/fuzzymeanshifttracker.cpp b/modules/contrib/src/fuzzymeanshifttracker.cpp index 0ac6d2443..1932ad595 100644 --- a/modules/contrib/src/fuzzymeanshifttracker.cpp +++ b/modules/contrib/src/fuzzymeanshifttracker.cpp @@ -40,7 +40,7 @@ CvFuzzyPoint::CvFuzzyPoint(double _x, double _y) { x = _x; y = _y; -}; +} bool CvFuzzyCurve::between(double x, double x1, double x2) { @@ -50,37 +50,37 @@ bool CvFuzzyCurve::between(double x, double x1, double x2) return true; return false; -}; +} CvFuzzyCurve::CvFuzzyCurve() { value = 0; -}; +} CvFuzzyCurve::~CvFuzzyCurve() { // nothing to do -}; +} void CvFuzzyCurve::setCentre(double _centre) { centre = _centre; -}; +} double CvFuzzyCurve::getCentre() { return centre; -}; +} void CvFuzzyCurve::clear() { points.clear(); -}; +} void CvFuzzyCurve::addPoint(double x, double y) { points.push_back(CvFuzzyPoint(x, y)); -}; +} double CvFuzzyCurve::calcValue(double param) { @@ -101,41 +101,41 @@ double CvFuzzyCurve::calcValue(double param) } } return 0; -}; +} double CvFuzzyCurve::getValue() { return value; -}; +} void CvFuzzyCurve::setValue(double _value) { value = _value; -}; +} CvFuzzyFunction::CvFuzzyFunction() { // nothing to do -}; +} CvFuzzyFunction::~CvFuzzyFunction() { curves.clear(); -}; +} void CvFuzzyFunction::addCurve(CvFuzzyCurve *curve, double value) { curves.push_back(*curve); curve->setValue(value); -}; +} void CvFuzzyFunction::resetValues() { int numCurves = (int)curves.size(); for (int i = 0; i < numCurves; i++) curves[i].setValue(0); -}; +} double CvFuzzyFunction::calcValue() { @@ -152,7 +152,7 @@ double CvFuzzyFunction::calcValue() return s1/s2; else return 0; -}; +} CvFuzzyCurve *CvFuzzyFunction::newCurve() { @@ -160,14 +160,14 @@ CvFuzzyCurve *CvFuzzyFunction::newCurve() c = new CvFuzzyCurve(); addCurve(c); return c; -}; +} CvFuzzyRule::CvFuzzyRule() { fuzzyInput1 = NULL; fuzzyInput2 = NULL; fuzzyOutput = NULL; -}; +} CvFuzzyRule::~CvFuzzyRule() { @@ -179,14 +179,14 @@ CvFuzzyRule::~CvFuzzyRule() if (fuzzyOutput != NULL) delete fuzzyOutput; -}; +} void CvFuzzyRule::setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1) { fuzzyInput1 = c1; fuzzyInput2 = c2; fuzzyOutput = o1; -}; +} double CvFuzzyRule::calcValue(double param1, double param2) { @@ -202,31 +202,31 @@ double CvFuzzyRule::calcValue(double param1, double param2) } else return v1; -}; +} CvFuzzyCurve *CvFuzzyRule::getOutputCurve() { return fuzzyOutput; -}; +} CvFuzzyController::CvFuzzyController() { // nothing to do -}; +} CvFuzzyController::~CvFuzzyController() { int size = (int)rules.size(); for(int i = 0; i < size; i++) delete rules[i]; -}; +} void CvFuzzyController::addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1) { CvFuzzyRule *f = new CvFuzzyRule(); rules.push_back(f); f->setRule(c1, c2, o1); -}; +} double CvFuzzyController::calcOutput(double param1, double param2) { @@ -242,7 +242,7 @@ double CvFuzzyController::calcOutput(double param1, double param2) } v = list.calcValue(); return v; -}; +} CvFuzzyMeanShiftTracker::FuzzyResizer::FuzzyResizer() { @@ -298,12 +298,12 @@ CvFuzzyMeanShiftTracker::FuzzyResizer::FuzzyResizer() fuzzyController.addRule(i1L, NULL, oS); fuzzyController.addRule(i1M, NULL, oZE); fuzzyController.addRule(i1H, NULL, oE); -}; +} int CvFuzzyMeanShiftTracker::FuzzyResizer::calcOutput(double edgeDensity, double density) { return (int)fuzzyController.calcOutput(edgeDensity, density); -}; +} CvFuzzyMeanShiftTracker::SearchWindow::SearchWindow() { @@ -328,7 +328,7 @@ CvFuzzyMeanShiftTracker::SearchWindow::SearchWindow() depthLow = 0; depthHigh = 0; fuzzyResizer = NULL; -}; +} CvFuzzyMeanShiftTracker::SearchWindow::~SearchWindow() { @@ -354,7 +354,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::setSize(int _x, int _y, int _width, if (y + height > maxHeight) height = maxHeight - y; -}; +} void CvFuzzyMeanShiftTracker::SearchWindow::initDepthValues(IplImage *maskImage, IplImage *depthMap) { @@ -408,7 +408,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::initDepthValues(IplImage *maskImage, depthHigh = 32000; depthLow = 0; } -}; +} bool CvFuzzyMeanShiftTracker::SearchWindow::shift() { @@ -421,7 +421,7 @@ bool CvFuzzyMeanShiftTracker::SearchWindow::shift() { return false; } -}; +} void CvFuzzyMeanShiftTracker::SearchWindow::extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth) { @@ -527,7 +527,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::extractInfo(IplImage *maskImage, Ipl ellipseAngle = 0; density = 0; } -}; +} void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh) { int x1 = horizontalEdgeTop; @@ -571,7 +571,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsEdgeDensityLinear(in } else { resizeDw = - resizeDx; } -}; +} void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh) { @@ -587,7 +587,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsInnerDensity(int &re resizeDy = (int)(py*dy); resizeDw = (int)((1-px)*dx); resizeDh = (int)((1-py)*dy); -}; +} void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh) { @@ -626,7 +626,7 @@ void CvFuzzyMeanShiftTracker::SearchWindow::getResizeAttribsEdgeDensityFuzzy(int resizeDy = int(-dy1); resizeDh = int(dy1+dy2); } -}; +} bool CvFuzzyMeanShiftTracker::SearchWindow::meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth) { @@ -639,7 +639,7 @@ bool CvFuzzyMeanShiftTracker::SearchWindow::meanShift(IplImage *maskImage, IplIm } while (++numShifts < maxIteration); return false; -}; +} void CvFuzzyMeanShiftTracker::findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth) { @@ -679,17 +679,17 @@ void CvFuzzyMeanShiftTracker::findOptimumSearchWindow(SearchWindow &searchWindow searchWindow.setSize(searchWindow.x + resizeDx, searchWindow.y + resizeDy, searchWindow.width + resizeDw, searchWindow.height + resizeDh); } -}; +} CvFuzzyMeanShiftTracker::CvFuzzyMeanShiftTracker() { searchMode = tsSetWindow; -}; +} CvFuzzyMeanShiftTracker::~CvFuzzyMeanShiftTracker() { // nothing to do -}; +} void CvFuzzyMeanShiftTracker::track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass) { @@ -717,4 +717,4 @@ void CvFuzzyMeanShiftTracker::track(IplImage *maskImage, IplImage *depthMap, int else searchMode = tsTracking; } -}; +} diff --git a/modules/contrib/src/imagelogpolprojection.cpp b/modules/contrib/src/imagelogpolprojection.cpp index ed821efa9..2824949c7 100644 --- a/modules/contrib/src/imagelogpolprojection.cpp +++ b/modules/contrib/src/imagelogpolprojection.cpp @@ -362,14 +362,14 @@ bool ImageLogPolProjection::_initLogPolarCortexSampling(const double reductionFa //std::cout<<"ImageLogPolProjection::Starting cortex projection"< main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary - ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised + ** ==> main idea parallelize main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelized methods as necessary + ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelized ** ==> functors constructors can differ from the parameters used with their related serial functions */ class Parallel_amacrineCellsComputing: public cv::ParallelLoopBody diff --git a/modules/contrib/src/parvoretinafilter.hpp b/modules/contrib/src/parvoretinafilter.hpp index 55d61d120..58e1303ec 100644 --- a/modules/contrib/src/parvoretinafilter.hpp +++ b/modules/contrib/src/parvoretinafilter.hpp @@ -219,8 +219,8 @@ private: #ifdef MAKE_PARALLEL /****************************************************** ** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors -** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary -** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised +** ==> main idea parallelize main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelized methods as necessary +** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelized ** ==> functors constructors can differ from the parameters used with their related serial functions */ class Parallel_OPL_OnOffWaysComputing: public cv::ParallelLoopBody diff --git a/modules/contrib/src/retina.cpp b/modules/contrib/src/retina.cpp index 6f08337cc..4a02bbcb4 100644 --- a/modules/contrib/src/retina.cpp +++ b/modules/contrib/src/retina.cpp @@ -85,7 +85,7 @@ Retina::Retina(const cv::Size inputSz, const bool colorMode, RETINA_COLORSAMPLIN { _retinaFilter = 0; _init(inputSz, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght); -}; +} Retina::~Retina() { diff --git a/modules/contrib/src/retinacolor.hpp b/modules/contrib/src/retinacolor.hpp index 7b7294442..275309681 100644 --- a/modules/contrib/src/retinacolor.hpp +++ b/modules/contrib/src/retinacolor.hpp @@ -259,8 +259,8 @@ namespace cv #ifdef MAKE_PARALLEL /****************************************************** ** IF some parallelizing thread methods are available, then, main loops are parallelized using these functors - ** ==> main idea paralellise main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelised methods as necessary - ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelised + ** ==> main idea parallelize main filters loops, then, only the most used methods are parallelized... TODO : increase the number of parallelized methods as necessary + ** ==> functors names = Parallel_$$$ where $$$= the name of the serial method that is parallelized ** ==> functors constructors can differ from the parameters used with their related serial functions */ diff --git a/modules/contrib/src/rgbdodometry.cpp b/modules/contrib/src/rgbdodometry.cpp index 4e9d8c4df..0b2b9518c 100644 --- a/modules/contrib/src/rgbdodometry.cpp +++ b/modules/contrib/src/rgbdodometry.cpp @@ -115,7 +115,7 @@ void computeProjectiveMatrix( const Mat& ksi, Mat& Rt ) { CV_Assert( ksi.size() == Size(1,6) && ksi.type() == CV_64FC1 ); -#if defined(HAVE_EIGEN) && EIGEN_WORLD_VERSION == 3 +#if defined(HAVE_EIGEN) && EIGEN_WORLD_VERSION == 3 && (!defined _MSC_VER || !defined _M_X64 || _MSC_VER > 1500) const double* ksi_ptr = reinterpret_cast(ksi.ptr(0)); Eigen::Matrix twist, g; twist << 0., -ksi_ptr[2], ksi_ptr[1], ksi_ptr[3], diff --git a/modules/contrib/src/spinimages.cpp b/modules/contrib/src/spinimages.cpp index b01090057..747bf3e12 100644 --- a/modules/contrib/src/spinimages.cpp +++ b/modules/contrib/src/spinimages.cpp @@ -718,7 +718,7 @@ void cv::SpinImageModel::defaultParams() T_GeometriccConsistency = 0.25f; T_GroupingCorespondances = 0.25f; -}; +} Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount, size_t yCount) const { diff --git a/modules/contrib/src/templatebuffer.hpp b/modules/contrib/src/templatebuffer.hpp index e50cd442c..8a85b5494 100644 --- a/modules/contrib/src/templatebuffer.hpp +++ b/modules/contrib/src/templatebuffer.hpp @@ -357,27 +357,27 @@ namespace cv for (unsigned int i=0;isize();++i) { - double curentValue=(double)*(bufferPTR++); + double currentValue=(double)*(bufferPTR++); // updating "closest to the high threshold" pixel value - double highValueTest=maxThreshold-curentValue; + double highValueTest=maxThreshold-currentValue; if (highValueTest>0) { if (deltaH>highValueTest) { deltaH=highValueTest; - updatedHighValue=curentValue; + updatedHighValue=currentValue; } } // updating "closest to the low threshold" pixel value - double lowValueTest=curentValue-minThreshold; + double lowValueTest=currentValue-minThreshold; if (lowValueTest>0) { if (deltaL>lowValueTest) { deltaL=lowValueTest; - updatedLowValue=curentValue; + updatedLowValue=currentValue; } } } diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index a1e71bf4f..d9de52da2 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -8,8 +8,11 @@ endif() ocv_module_include_directories("${OpenCV_SOURCE_DIR}/modules/dynamicuda/include/" ${ZLIB_INCLUDE_DIR}) +if(HAVE_WINRT_CX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW") +endif() if(HAVE_WINRT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW /GS /Gm- /AI\"${WINDOWS_SDK_PATH}/References/CommonConfiguration/Neutral\" /AI\"${VISUAL_STUDIO_PATH}/vcpackages\"") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS /Gm- /AI\"${WINDOWS_SDK_PATH}/References/CommonConfiguration/Neutral\" /AI\"${VISUAL_STUDIO_PATH}/vcpackages\"") endif() if(ENABLE_DYNAMIC_CUDA) @@ -22,7 +25,7 @@ endif() if(HAVE_CUDA) ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include") - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) + ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wshadow) endif() file(GLOB lib_cuda_hdrs "include/opencv2/${name}/cuda/*.hpp" "include/opencv2/${name}/cuda/*.h") diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index 6f9c10e1d..95d1b37f1 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -1350,12 +1350,12 @@ Copies the matrix to another one. The method copies the matrix data to another matrix. Before copying the data, the method invokes :: - m.create(this->size(), this->type); + m.create(this->size(), this->type()); so that the destination matrix is reallocated if needed. While ``m.copyTo(m);`` works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices. -When the operation mask is specified, and the ``Mat::create`` call shown above reallocated the matrix, the newly allocated matrix is initialized with all zeros before copying the data. +When the operation mask is specified, if the ``Mat::create`` call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data. .. _Mat::convertTo: @@ -1445,7 +1445,7 @@ Transposes a matrix. The method performs matrix transposition by means of matrix expressions. It does not perform the actual transposition but returns a temporary matrix transposition object that can be further used as a part of more complex matrix expressions or can be assigned to a matrix: :: - Mat A1 = A + Mat::eye(A.size(), A.type)*lambda; + Mat A1 = A + Mat::eye(A.size(), A.type())*lambda; Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I) diff --git a/modules/core/doc/drawing_functions.rst b/modules/core/doc/drawing_functions.rst index 7a6bd173a..f06d0fa60 100644 --- a/modules/core/doc/drawing_functions.rst +++ b/modules/core/doc/drawing_functions.rst @@ -514,7 +514,7 @@ Draws a text string. :param font: ``CvFont`` structure initialized using :ocv:cfunc:`InitFont`. :param fontFace: Font type. One of ``FONT_HERSHEY_SIMPLEX``, ``FONT_HERSHEY_PLAIN``, ``FONT_HERSHEY_DUPLEX``, ``FONT_HERSHEY_COMPLEX``, ``FONT_HERSHEY_TRIPLEX``, ``FONT_HERSHEY_COMPLEX_SMALL``, ``FONT_HERSHEY_SCRIPT_SIMPLEX``, or ``FONT_HERSHEY_SCRIPT_COMPLEX``, - where each of the font ID's can be combined with ``FONT_HERSHEY_ITALIC`` to get the slanted letters. + where each of the font ID's can be combined with ``FONT_ITALIC`` to get the slanted letters. :param fontScale: Font scale factor that is multiplied by the font-specific base size. diff --git a/modules/core/doc/old_basic_structures.rst b/modules/core/doc/old_basic_structures.rst index c8de17ada..1d5880a62 100644 --- a/modules/core/doc/old_basic_structures.rst +++ b/modules/core/doc/old_basic_structures.rst @@ -1436,7 +1436,7 @@ description rewritten using IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3); IplImage gray_img_hdr, *gray_img; - gray_img = (IplImage*)cvReshapeND(color_img, &gray_img_hdr, 1, 0, 0); + gray_img = (IplImage*)cvReshapeMatND(color_img, sizeof(gray_img_hdr), &gray_img_hdr, 1, 0, 0); ... @@ -1444,6 +1444,18 @@ description rewritten using int size[] = { 2, 2, 2 }; CvMatND* mat = cvCreateMatND(3, size, CV_32F); CvMat row_header, *row; + row = (CvMat*)cvReshapeMatND(mat, sizeof(row_header), &row_header, 0, 1, 0); + +.. + +In C, the header file for this function includes a convenient macro ``cvReshapeND`` that does away with the ``sizeof_header`` parameter. So, the lines containing the call to ``cvReshapeMatND`` in the examples may be replaced as follow: + +:: + + gray_img = (IplImage*)cvReshapeND(color_img, &gray_img_hdr, 1, 0, 0); + + ... + row = (CvMat*)cvReshapeND(mat, &row_header, 0, 1, 0); .. diff --git a/modules/core/doc/operations_on_arrays.rst b/modules/core/doc/operations_on_arrays.rst index 8c01a1010..be91944e7 100644 --- a/modules/core/doc/operations_on_arrays.rst +++ b/modules/core/doc/operations_on_arrays.rst @@ -1252,11 +1252,12 @@ gemm ---- Performs generalized matrix multiplication. -.. ocv:function:: void gemm( InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, int flags=0 ) +.. ocv:function:: void gemm( InputArray src1, InputArray src2, double alpha, InputArray src3, double beta, OutputArray dst, int flags=0 ) -.. ocv:pyfunction:: cv2.gemm(src1, src2, alpha, src3, gamma[, dst[, flags]]) -> dst +.. ocv:pyfunction:: cv2.gemm(src1, src2, alpha, src3, beta[, dst[, flags]]) -> dst .. ocv:cfunction:: void cvGEMM( const CvArr* src1, const CvArr* src2, double alpha, const CvArr* src3, double beta, CvArr* dst, int tABC=0) + .. ocv:pyoldfunction:: cv.GEMM(src1, src2, alpha, src3, beta, dst, tABC=0)-> None :param src1: first multiplied input matrix that should have ``CV_32FC1``, ``CV_64FC1``, ``CV_32FC2``, or ``CV_64FC2`` type. diff --git a/modules/core/include/opencv2/core/affine.hpp b/modules/core/include/opencv2/core/affine.hpp new file mode 100644 index 000000000..827d044b8 --- /dev/null +++ b/modules/core/include/opencv2/core/affine.hpp @@ -0,0 +1,509 @@ +/*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. +// 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 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*/ + +#ifndef __OPENCV_CORE_AFFINE3_HPP__ +#define __OPENCV_CORE_AFFINE3_HPP__ + +#ifdef __cplusplus + +#include + +namespace cv +{ + template + class Affine3 + { + public: + typedef T float_type; + typedef Matx Mat3; + typedef Matx Mat4; + typedef Vec Vec3; + + Affine3(); + + //Augmented affine matrix + Affine3(const Mat4& affine); + + //Rotation matrix + Affine3(const Mat3& R, const Vec3& t = Vec3::all(0)); + + //Rodrigues vector + Affine3(const Vec3& rvec, const Vec3& t = Vec3::all(0)); + + //Combines all contructors above. Supports 4x4, 4x3, 3x3, 1x3, 3x1 sizes of data matrix + explicit Affine3(const Mat& data, const Vec3& t = Vec3::all(0)); + + //From 16th element array + explicit Affine3(const float_type* vals); + + static Affine3 Identity(); + + //Rotation matrix + void rotation(const Mat3& R); + + //Rodrigues vector + void rotation(const Vec3& rvec); + + //Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix; + void rotation(const Mat& data); + + void linear(const Mat3& L); + void translation(const Vec3& t); + + Mat3 rotation() const; + Mat3 linear() const; + Vec3 translation() const; + + //Rodrigues vector + Vec3 rvec() const; + + Affine3 inv(int method = cv::DECOMP_SVD) const; + + // a.rotate(R) is equivalent to Affine(R, 0) * a; + Affine3 rotate(const Mat3& R) const; + + // a.rotate(R) is equivalent to Affine(rvec, 0) * a; + Affine3 rotate(const Vec3& rvec) const; + + // a.translate(t) is equivalent to Affine(E, t) * a; + Affine3 translate(const Vec3& t) const; + + // a.concatenate(affine) is equivalent to affine * a; + Affine3 concatenate(const Affine3& affine) const; + + template operator Affine3() const; + + template Affine3 cast() const; + + Mat4 matrix; + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + Affine3(const Eigen::Transform& affine); + Affine3(const Eigen::Transform& affine); + operator Eigen::Transform() const; + operator Eigen::Transform() const; +#endif + }; + + template static + Affine3 operator*(const Affine3& affine1, const Affine3& affine2); + + template static + V operator*(const Affine3& affine, const V& vector); + + typedef Affine3 Affine3f; + typedef Affine3 Affine3d; + + static Vec3f operator*(const Affine3f& affine, const Vec3f& vector); + static Vec3d operator*(const Affine3d& affine, const Vec3d& vector); + + template class DataType< Affine3<_Tp> > + { + public: + typedef Affine3<_Tp> value_type; + typedef Affine3::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + depth = DataType::depth, + channels = 16, + fmt = DataType::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec vec_type; + }; +} + + +/////////////////////////////////////////////////////////////////////////////////// +/// Implementaiton + +template inline +cv::Affine3::Affine3() + : matrix(Mat4::eye()) +{} + +template inline +cv::Affine3::Affine3(const Mat4& affine) + : matrix(affine) +{} + +template inline +cv::Affine3::Affine3(const Mat3& R, const Vec3& t) +{ + rotation(R); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const Vec3& _rvec, const Vec3& t) +{ + rotation(_rvec); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) +{ + CV_Assert(data.type() == cv::DataType::type); + + if (data.cols == 4 && data.rows == 4) + { + data.copyTo(matrix); + return; + } + else if (data.cols == 4 && data.rows == 3) + { + rotation(data(Rect(0, 0, 3, 3))); + translation(data(Rect(3, 0, 1, 3))); + return; + } + + rotation(data); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const float_type* vals) : matrix(vals) +{} + +template inline +cv::Affine3 cv::Affine3::Identity() +{ + return Affine3(cv::Affine3::Mat4::eye()); +} + +template inline +void cv::Affine3::rotation(const Mat3& R) +{ + linear(R); +} + +template inline +void cv::Affine3::rotation(const Vec3& _rvec) +{ + double rx = _rvec[0], ry = _rvec[1], rz = _rvec[2]; + double theta = std::sqrt(rx*rx + ry*ry + rz*rz); + + if (theta < DBL_EPSILON) + rotation(Mat3::eye()); + else + { + const double I[] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; + + double c = std::cos(theta); + double s = std::sin(theta); + double c1 = 1. - c; + double itheta = theta ? 1./theta : 0.; + + rx *= itheta; ry *= itheta; rz *= itheta; + + double rrt[] = { rx*rx, rx*ry, rx*rz, rx*ry, ry*ry, ry*rz, rx*rz, ry*rz, rz*rz }; + double _r_x_[] = { 0, -rz, ry, rz, 0, -rx, -ry, rx, 0 }; + Mat3 R; + + // R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x] + // where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0] + for(int k = 0; k < 9; ++k) + R.val[k] = static_cast(c*I[k] + c1*rrt[k] + s*_r_x_[k]); + + rotation(R); + } +} + +//Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix; +template inline +void cv::Affine3::rotation(const cv::Mat& data) +{ + CV_Assert(data.type() == cv::DataType::type); + + if (data.cols == 3 && data.rows == 3) + { + Mat3 R; + data.copyTo(R); + rotation(R); + } + else if ((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3)) + { + Vec3 _rvec; + data.reshape(1, 3).copyTo(_rvec); + rotation(_rvec); + } + else + CV_Assert(!"Input marix can be 3x3, 1x3 or 3x1"); +} + +template inline +void cv::Affine3::linear(const Mat3& L) +{ + matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2]; + matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5]; + matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8]; +} + +template inline +void cv::Affine3::translation(const Vec3& t) +{ + matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2]; +} + +template inline +typename cv::Affine3::Mat3 cv::Affine3::rotation() const +{ + return linear(); +} + +template inline +typename cv::Affine3::Mat3 cv::Affine3::linear() const +{ + typename cv::Affine3::Mat3 R; + R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2]; + R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6]; + R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10]; + return R; +} + +template inline +typename cv::Affine3::Vec3 cv::Affine3::translation() const +{ + return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]); +} + +template inline +typename cv::Affine3::Vec3 cv::Affine3::rvec() const +{ + cv::Vec3d w; + cv::Matx33d u, vt, R = rotation(); + cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A); + R = u * vt; + + double rx = R.val[7] - R.val[5]; + double ry = R.val[2] - R.val[6]; + double rz = R.val[3] - R.val[1]; + + double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25); + double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5; + c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c; + double theta = acos(c); + + if( s < 1e-5 ) + { + if( c > 0 ) + rx = ry = rz = 0; + else + { + double t; + t = (R.val[0] + 1) * 0.5; + rx = std::sqrt(std::max(t, 0.0)); + t = (R.val[4] + 1) * 0.5; + ry = std::sqrt(std::max(t, 0.0)) * (R.val[1] < 0 ? -1.0 : 1.0); + t = (R.val[8] + 1) * 0.5; + rz = std::sqrt(std::max(t, 0.0)) * (R.val[2] < 0 ? -1.0 : 1.0); + + if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) ) + rz = -rz; + theta /= std::sqrt(rx*rx + ry*ry + rz*rz); + rx *= theta; + ry *= theta; + rz *= theta; + } + } + else + { + double vth = 1/(2*s); + vth *= theta; + rx *= vth; ry *= vth; rz *= vth; + } + + return cv::Vec3d(rx, ry, rz); +} + +template inline +cv::Affine3 cv::Affine3::inv(int method) const +{ + return matrix.inv(method); +} + +template inline +cv::Affine3 cv::Affine3::rotate(const Mat3& R) const +{ + Mat3 Lc = linear(); + Vec3 tc = translation(); + Mat4 result; + result.val[12] = result.val[13] = result.val[14] = 0; + result.val[15] = 1; + + for(int j = 0; j < 3; ++j) + { + for(int i = 0; i < 3; ++i) + { + float_type value = 0; + for(int k = 0; k < 3; ++k) + value += R(j, k) * Lc(k, i); + result(j, i) = value; + } + + result(j, 3) = R.row(j).dot(tc.t()); + } + return result; +} + +template inline +cv::Affine3 cv::Affine3::rotate(const Vec3& _rvec) const +{ + return rotate(Affine3f(_rvec).rotation()); +} + +template inline +cv::Affine3 cv::Affine3::translate(const Vec3& t) const +{ + Mat4 m = matrix; + m.val[ 3] += t[0]; + m.val[ 7] += t[1]; + m.val[11] += t[2]; + return m; +} + +template inline +cv::Affine3 cv::Affine3::concatenate(const Affine3& affine) const +{ + return (*this).rotate(affine.rotation()).translate(affine.translation()); +} + +template template inline +cv::Affine3::operator Affine3() const +{ + return Affine3(matrix); +} + +template template inline +cv::Affine3 cv::Affine3::cast() const +{ + return Affine3(matrix); +} + +template inline +cv::Affine3 cv::operator*(const cv::Affine3& affine1, const cv::Affine3& affine2) +{ + return affine2.concatenate(affine1); +} + +template inline +V cv::operator*(const cv::Affine3& affine, const V& v) +{ + const typename Affine3::Mat4& m = affine.matrix; + + V r; + r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3]; + r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7]; + r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11]; + return r; +} + +static inline +cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) +{ + const cv::Matx44f& m = affine.matrix; + cv::Vec3f r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + +static inline +cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) +{ + const cv::Matx44d& m = affine.matrix; + cv::Vec3d r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + + + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) +{ + cv::Mat(4, 4, cv::DataType::type, affine.matrix().data()).copyTo(matrix); +} + +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) +{ + Eigen::Transform a = affine; + cv::Mat(4, 4, cv::DataType::type, a.matrix().data()).copyTo(matrix); +} + +template inline +cv::Affine3::operator Eigen::Transform() const +{ + Eigen::Transform r; + cv::Mat hdr(4, 4, cv::DataType::type, r.matrix().data()); + cv::Mat(matrix, false).copyTo(hdr); + return r; +} + +template inline +cv::Affine3::operator Eigen::Transform() const +{ + return this->operator Eigen::Transform(); +} + +#endif /* defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H */ + + +#endif /* __cplusplus */ + +#endif /* __OPENCV_CORE_AFFINE3_HPP__ */ diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index cafba0f8f..5667e9e50 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -892,6 +892,7 @@ public: typedef Point_ Point2i; typedef Point2i Point; typedef Size_ Size2i; +typedef Size_ Size2d; typedef Size2i Size; typedef Rect_ Rect; typedef Point_ Point2f; @@ -2318,7 +2319,7 @@ CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val=0); //! implements generalized matrix product algorithm GEMM from BLAS CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, - InputArray src3, double gamma, OutputArray dst, int flags=0); + InputArray src3, double beta, OutputArray dst, int flags=0); //! multiplies matrix by its transposition from the left or from the right CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, InputArray delta=noArray(), diff --git a/modules/core/include/opencv2/core/core_c.h b/modules/core/include/opencv2/core/core_c.h index d4182d2f7..38abfc409 100644 --- a/modules/core/include/opencv2/core/core_c.h +++ b/modules/core/include/opencv2/core/core_c.h @@ -105,7 +105,7 @@ CVAPI(void) cvResetImageROI( IplImage* image ); /* Retrieves image ROI */ CVAPI(CvRect) cvGetImageROI( const IplImage* image ); -/* Allocates and initalizes CvMat header */ +/* Allocates and initializes CvMat header */ CVAPI(CvMat*) cvCreateMatHeader( int rows, int cols, int type ); #define CV_AUTOSTEP 0x7fffffff diff --git a/modules/core/include/opencv2/core/internal.hpp b/modules/core/include/opencv2/core/internal.hpp index 3cd2f90f6..6c9d3d2f1 100644 --- a/modules/core/include/opencv2/core/internal.hpp +++ b/modules/core/include/opencv2/core/internal.hpp @@ -97,6 +97,13 @@ CV_INLINE IppiSize ippiSize(int width, int height) IppiSize size = { width, height }; return size; } + +CV_INLINE IppiSize ippiSize(const cv::Size & _size) +{ + IppiSize size = { _size.width, _size.height }; + return size; +} + #endif #ifndef IPPI_CALL diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 8ddc16eb1..45c25900c 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -2401,7 +2401,7 @@ template inline SparseMat_<_Tp>::SparseMat_(const SparseMat& m) if( m.type() == DataType<_Tp>::type ) *this = (const SparseMat_<_Tp>&)m; else - m.convertTo(this, DataType<_Tp>::type); + m.convertTo(*this, DataType<_Tp>::type); } template inline SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m) diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h index 3e5d5b033..99ac0d257 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -245,7 +245,7 @@ enum { CV_StsVecLengthErr= -28, /* incorrect vector length */ CV_StsFilterStructContentErr= -29, /* incorr. filter structure content */ CV_StsKernelStructContentErr= -30, /* incorr. transform kernel content */ - CV_StsFilterOffsetErr= -31, /* incorrect filter ofset value */ + CV_StsFilterOffsetErr= -31, /* incorrect filter offset value */ CV_StsBadSize= -201, /* the input/output structure size is incorrect */ CV_StsDivByZero= -202, /* division by zero */ CV_StsInplaceNotSupported= -203, /* in-place operation is not supported */ diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 25e5892b6..63c293528 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -49,7 +49,7 @@ #define CV_VERSION_EPOCH 2 #define CV_VERSION_MAJOR 4 -#define CV_VERSION_MINOR 8 +#define CV_VERSION_MINOR 9 #define CV_VERSION_REVISION 0 #define CVAUX_STR_EXP(__A) #__A diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index f96f243cb..5f16f95ed 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -647,7 +647,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR) { if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN - || p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || argType == Param::UCHAR + || p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || p->type == Param::UCHAR || (p->type == Param::SHORT && argType == Param::INT)) ) { string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index a11b64b44..fa74cfa4e 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -533,7 +533,7 @@ static void add8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_8u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), + ippiAdd_8u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0), (vBinOp8, IF_SIMD(_VAdd8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -549,7 +549,7 @@ static void add16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_16u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), + ippiAdd_16u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0), (vBinOp16, IF_SIMD(_VAdd16u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -558,7 +558,7 @@ static void add16s( const short* src1, size_t step1, short* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_16s_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), + ippiAdd_16s_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0), (vBinOp16, IF_SIMD(_VAdd16s)>(src1, step1, src2, step2, dst, step, sz))); } @@ -574,7 +574,7 @@ static void add32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiAdd_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp32f, IF_SIMD(_VAdd32f)>(src1, step1, src2, step2, dst, step, sz))); } @@ -590,7 +590,7 @@ static void sub8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_8u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), + ippiSub_8u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0), (vBinOp8, IF_SIMD(_VSub8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -606,7 +606,7 @@ static void sub16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_16u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), + ippiSub_16u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0), (vBinOp16, IF_SIMD(_VSub16u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -615,7 +615,7 @@ static void sub16s( const short* src1, size_t step1, short* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_16s_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), + ippiSub_16s_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0), (vBinOp16, IF_SIMD(_VSub16s)>(src1, step1, src2, step2, dst, step, sz))); } @@ -631,7 +631,7 @@ static void sub32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_32f_C1R(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz), + ippiSub_32f_C1R(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz)), (vBinOp32f, IF_SIMD(_VSub32f)>(src1, step1, src2, step2, dst, step, sz))); } @@ -668,7 +668,7 @@ static void max8u( const uchar* src1, size_t step1, #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMaxEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp8, IF_SIMD(_VMax8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -702,7 +702,7 @@ static void max16u( const ushort* src1, size_t step1, #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMaxEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp16, IF_SIMD(_VMax16u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -742,7 +742,7 @@ static void max32f( const float* src1, size_t step1, vBinOp32f, IF_SIMD(_VMax32f)>(src1, step1, src2, step2, dst, step, sz); #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMaxEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp32f, IF_SIMD(_VMax32f)>(src1, step1, src2, step2, dst, step, sz))); } @@ -776,7 +776,7 @@ static void min8u( const uchar* src1, size_t step1, #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMinEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp8, IF_SIMD(_VMin8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -810,7 +810,7 @@ static void min16u( const ushort* src1, size_t step1, #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMinEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp16, IF_SIMD(_VMin16u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -850,7 +850,7 @@ static void min32f( const float* src1, size_t step1, vBinOp32f, IF_SIMD(_VMin32f)>(src1, step1, src2, step2, dst, step, sz); #endif // IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), +// ippiMinEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, ippiSize(sz)), // (vBinOp32f, IF_SIMD(_VMin32f)>(src1, step1, src2, step2, dst, step, sz))); } @@ -866,7 +866,7 @@ static void absdiff8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiAbsDiff_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp8, IF_SIMD(_VAbsDiff8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -882,7 +882,7 @@ static void absdiff16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiAbsDiff_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp16, IF_SIMD(_VAbsDiff16u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -905,7 +905,7 @@ static void absdiff32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiAbsDiff_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp32f, IF_SIMD(_VAbsDiff32f)>(src1, step1, src2, step2, dst, step, sz))); } @@ -922,7 +922,7 @@ static void and8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAnd_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiAnd_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp8, IF_SIMD(_VAnd8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -931,7 +931,7 @@ static void or8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiOr_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiOr_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp8, IF_SIMD(_VOr8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -940,7 +940,7 @@ static void xor8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiXor_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), + ippiXor_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz)), (vBinOp8, IF_SIMD(_VXor8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -948,8 +948,8 @@ static void not8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); (void *)src2; - ippiNot_8u_C1R(src1, (int)step1, dst, (int)step, (IppiSize&)sz), + IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); (void)src2; + ippiNot_8u_C1R(src1, (int)step1, dst, (int)step, ippiSize(sz)), (vBinOp8, IF_SIMD(_VNot8u)>(src1, step1, src2, step2, dst, step, sz))); } @@ -1272,8 +1272,8 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, bool haveScalar = false, swapped12 = false; int depth2 = src2.depth(); if( src1.size != src2.size || src1.channels() != src2.channels() || - ((kind1 == _InputArray::MATX || kind2 == _InputArray::MATX) && - src1.cols == 1 && src2.rows == 4) ) + (kind1 == _InputArray::MATX && (src1.size() == Size(1,4) || src1.size() == Size(1,1))) || + (kind2 == _InputArray::MATX && (src2.size() == Size(1,4) || src2.size() == Size(1,1))) ) { if( checkScalar(src1, src2.type(), kind1, kind2) ) { @@ -1553,39 +1553,60 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst, arithm_op(src1, src2, dst, mask, dtype, getAddTab() ); } -void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, +void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, InputArray mask, int dtype ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if (mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U) - { - if (dtype == -1 && dst.fixedType()) - dtype = dst.depth(); + int kind1 = _src1.kind(), kind2 = _src2.kind(); + Mat src1 = _src1.getMat(), src2 = _src2.getMat(); + bool src1Scalar = checkScalar(src1, _src2.type(), kind1, kind2); + bool src2Scalar = checkScalar(src2, _src1.type(), kind2, kind1); - if (!dst.fixedType() || dtype == dst.depth()) + if (!src1Scalar && !src2Scalar && + src1.depth() == CV_8U && src2.type() == src1.type() && + src1.dims == 2 && src2.size() == src1.size() && + mask.empty()) + { + if (dtype < 0) { + if (_dst.fixedType()) + { + dtype = _dst.depth(); + } + else + { + dtype = src1.depth(); + } + } + + dtype = CV_MAT_DEPTH(dtype); + + if (!_dst.fixedType() || dtype == _dst.depth()) + { + _dst.create(src1.size(), CV_MAKE_TYPE(dtype, src1.channels())); + if (dtype == CV_16S) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u16s(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u16s(src1, src2, dst)) return; } else if (dtype == CV_32F) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u32f(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u32f(src1, src2, dst)) return; } else if (dtype == CV_8S) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u8s(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u8s(src1, src2, dst)) return; } } } #endif - arithm_op(src1, src2, dst, mask, dtype, getSubTab() ); + arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab() ); } void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst ) @@ -2184,7 +2205,7 @@ static void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t ste if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if( ippiCompare_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op) >= 0 ) return; } #endif @@ -2267,7 +2288,7 @@ static void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if( ippiCompare_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op) >= 0 ) return; } #endif @@ -2282,7 +2303,7 @@ static void cmp16s(const short* src1, size_t step1, const short* src2, size_t st if( op > 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_16s_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if( ippiCompare_16s_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op) >= 0 ) return; } #endif @@ -2388,7 +2409,7 @@ static void cmp32f(const float* src1, size_t step1, const float* src2, size_t st if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if( ippiCompare_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op) >= 0 ) return; } #endif diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index 9c024293e..a35ad0e2a 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -2897,7 +2897,7 @@ cvCreateImage( CvSize size, int depth, int channels ) } -// initalize IplImage header, allocated by the user +// initialize IplImage header, allocated by the user CV_IMPL IplImage* cvInitImageHeader( IplImage * image, CvSize size, int depth, int channels, int origin, int align ) diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 3de9f83d1..c37208b5c 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -839,122 +839,122 @@ stype* dst, size_t dstep, Size size, double*) \ } -DEF_CVT_SCALE_ABS_FUNC(8u, cvtScaleAbs_, uchar, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(8s8u, cvtScaleAbs_, schar, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(16u8u, cvtScaleAbs_, ushort, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(16s8u, cvtScaleAbs_, short, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(32s8u, cvtScaleAbs_, int, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(32f8u, cvtScaleAbs_, float, uchar, float); -DEF_CVT_SCALE_ABS_FUNC(64f8u, cvtScaleAbs_, double, uchar, float); +DEF_CVT_SCALE_ABS_FUNC(8u, cvtScaleAbs_, uchar, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(8s8u, cvtScaleAbs_, schar, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(16u8u, cvtScaleAbs_, ushort, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(16s8u, cvtScaleAbs_, short, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(32s8u, cvtScaleAbs_, int, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(32f8u, cvtScaleAbs_, float, uchar, float) +DEF_CVT_SCALE_ABS_FUNC(64f8u, cvtScaleAbs_, double, uchar, float) -DEF_CVT_SCALE_FUNC(8u, uchar, uchar, float); -DEF_CVT_SCALE_FUNC(8s8u, schar, uchar, float); -DEF_CVT_SCALE_FUNC(16u8u, ushort, uchar, float); -DEF_CVT_SCALE_FUNC(16s8u, short, uchar, float); -DEF_CVT_SCALE_FUNC(32s8u, int, uchar, float); -DEF_CVT_SCALE_FUNC(32f8u, float, uchar, float); -DEF_CVT_SCALE_FUNC(64f8u, double, uchar, float); +DEF_CVT_SCALE_FUNC(8u, uchar, uchar, float) +DEF_CVT_SCALE_FUNC(8s8u, schar, uchar, float) +DEF_CVT_SCALE_FUNC(16u8u, ushort, uchar, float) +DEF_CVT_SCALE_FUNC(16s8u, short, uchar, float) +DEF_CVT_SCALE_FUNC(32s8u, int, uchar, float) +DEF_CVT_SCALE_FUNC(32f8u, float, uchar, float) +DEF_CVT_SCALE_FUNC(64f8u, double, uchar, float) -DEF_CVT_SCALE_FUNC(8u8s, uchar, schar, float); -DEF_CVT_SCALE_FUNC(8s, schar, schar, float); -DEF_CVT_SCALE_FUNC(16u8s, ushort, schar, float); -DEF_CVT_SCALE_FUNC(16s8s, short, schar, float); -DEF_CVT_SCALE_FUNC(32s8s, int, schar, float); -DEF_CVT_SCALE_FUNC(32f8s, float, schar, float); -DEF_CVT_SCALE_FUNC(64f8s, double, schar, float); +DEF_CVT_SCALE_FUNC(8u8s, uchar, schar, float) +DEF_CVT_SCALE_FUNC(8s, schar, schar, float) +DEF_CVT_SCALE_FUNC(16u8s, ushort, schar, float) +DEF_CVT_SCALE_FUNC(16s8s, short, schar, float) +DEF_CVT_SCALE_FUNC(32s8s, int, schar, float) +DEF_CVT_SCALE_FUNC(32f8s, float, schar, float) +DEF_CVT_SCALE_FUNC(64f8s, double, schar, float) -DEF_CVT_SCALE_FUNC(8u16u, uchar, ushort, float); -DEF_CVT_SCALE_FUNC(8s16u, schar, ushort, float); -DEF_CVT_SCALE_FUNC(16u, ushort, ushort, float); -DEF_CVT_SCALE_FUNC(16s16u, short, ushort, float); -DEF_CVT_SCALE_FUNC(32s16u, int, ushort, float); -DEF_CVT_SCALE_FUNC(32f16u, float, ushort, float); -DEF_CVT_SCALE_FUNC(64f16u, double, ushort, float); +DEF_CVT_SCALE_FUNC(8u16u, uchar, ushort, float) +DEF_CVT_SCALE_FUNC(8s16u, schar, ushort, float) +DEF_CVT_SCALE_FUNC(16u, ushort, ushort, float) +DEF_CVT_SCALE_FUNC(16s16u, short, ushort, float) +DEF_CVT_SCALE_FUNC(32s16u, int, ushort, float) +DEF_CVT_SCALE_FUNC(32f16u, float, ushort, float) +DEF_CVT_SCALE_FUNC(64f16u, double, ushort, float) -DEF_CVT_SCALE_FUNC(8u16s, uchar, short, float); -DEF_CVT_SCALE_FUNC(8s16s, schar, short, float); -DEF_CVT_SCALE_FUNC(16u16s, ushort, short, float); -DEF_CVT_SCALE_FUNC(16s, short, short, float); -DEF_CVT_SCALE_FUNC(32s16s, int, short, float); -DEF_CVT_SCALE_FUNC(32f16s, float, short, float); -DEF_CVT_SCALE_FUNC(64f16s, double, short, float); +DEF_CVT_SCALE_FUNC(8u16s, uchar, short, float) +DEF_CVT_SCALE_FUNC(8s16s, schar, short, float) +DEF_CVT_SCALE_FUNC(16u16s, ushort, short, float) +DEF_CVT_SCALE_FUNC(16s, short, short, float) +DEF_CVT_SCALE_FUNC(32s16s, int, short, float) +DEF_CVT_SCALE_FUNC(32f16s, float, short, float) +DEF_CVT_SCALE_FUNC(64f16s, double, short, float) -DEF_CVT_SCALE_FUNC(8u32s, uchar, int, float); -DEF_CVT_SCALE_FUNC(8s32s, schar, int, float); -DEF_CVT_SCALE_FUNC(16u32s, ushort, int, float); -DEF_CVT_SCALE_FUNC(16s32s, short, int, float); -DEF_CVT_SCALE_FUNC(32s, int, int, double); -DEF_CVT_SCALE_FUNC(32f32s, float, int, float); -DEF_CVT_SCALE_FUNC(64f32s, double, int, double); +DEF_CVT_SCALE_FUNC(8u32s, uchar, int, float) +DEF_CVT_SCALE_FUNC(8s32s, schar, int, float) +DEF_CVT_SCALE_FUNC(16u32s, ushort, int, float) +DEF_CVT_SCALE_FUNC(16s32s, short, int, float) +DEF_CVT_SCALE_FUNC(32s, int, int, double) +DEF_CVT_SCALE_FUNC(32f32s, float, int, float) +DEF_CVT_SCALE_FUNC(64f32s, double, int, double) -DEF_CVT_SCALE_FUNC(8u32f, uchar, float, float); -DEF_CVT_SCALE_FUNC(8s32f, schar, float, float); -DEF_CVT_SCALE_FUNC(16u32f, ushort, float, float); -DEF_CVT_SCALE_FUNC(16s32f, short, float, float); -DEF_CVT_SCALE_FUNC(32s32f, int, float, double); -DEF_CVT_SCALE_FUNC(32f, float, float, float); -DEF_CVT_SCALE_FUNC(64f32f, double, float, double); +DEF_CVT_SCALE_FUNC(8u32f, uchar, float, float) +DEF_CVT_SCALE_FUNC(8s32f, schar, float, float) +DEF_CVT_SCALE_FUNC(16u32f, ushort, float, float) +DEF_CVT_SCALE_FUNC(16s32f, short, float, float) +DEF_CVT_SCALE_FUNC(32s32f, int, float, double) +DEF_CVT_SCALE_FUNC(32f, float, float, float) +DEF_CVT_SCALE_FUNC(64f32f, double, float, double) -DEF_CVT_SCALE_FUNC(8u64f, uchar, double, double); -DEF_CVT_SCALE_FUNC(8s64f, schar, double, double); -DEF_CVT_SCALE_FUNC(16u64f, ushort, double, double); -DEF_CVT_SCALE_FUNC(16s64f, short, double, double); -DEF_CVT_SCALE_FUNC(32s64f, int, double, double); -DEF_CVT_SCALE_FUNC(32f64f, float, double, double); -DEF_CVT_SCALE_FUNC(64f, double, double, double); +DEF_CVT_SCALE_FUNC(8u64f, uchar, double, double) +DEF_CVT_SCALE_FUNC(8s64f, schar, double, double) +DEF_CVT_SCALE_FUNC(16u64f, ushort, double, double) +DEF_CVT_SCALE_FUNC(16s64f, short, double, double) +DEF_CVT_SCALE_FUNC(32s64f, int, double, double) +DEF_CVT_SCALE_FUNC(32f64f, float, double, double) +DEF_CVT_SCALE_FUNC(64f, double, double, double) -DEF_CPY_FUNC(8u, uchar); -DEF_CVT_FUNC(8s8u, schar, uchar); -DEF_CVT_FUNC(16u8u, ushort, uchar); -DEF_CVT_FUNC(16s8u, short, uchar); -DEF_CVT_FUNC(32s8u, int, uchar); -DEF_CVT_FUNC(32f8u, float, uchar); -DEF_CVT_FUNC(64f8u, double, uchar); +DEF_CPY_FUNC(8u, uchar) +DEF_CVT_FUNC(8s8u, schar, uchar) +DEF_CVT_FUNC(16u8u, ushort, uchar) +DEF_CVT_FUNC(16s8u, short, uchar) +DEF_CVT_FUNC(32s8u, int, uchar) +DEF_CVT_FUNC(32f8u, float, uchar) +DEF_CVT_FUNC(64f8u, double, uchar) -DEF_CVT_FUNC(8u8s, uchar, schar); -DEF_CVT_FUNC(16u8s, ushort, schar); -DEF_CVT_FUNC(16s8s, short, schar); -DEF_CVT_FUNC(32s8s, int, schar); -DEF_CVT_FUNC(32f8s, float, schar); -DEF_CVT_FUNC(64f8s, double, schar); +DEF_CVT_FUNC(8u8s, uchar, schar) +DEF_CVT_FUNC(16u8s, ushort, schar) +DEF_CVT_FUNC(16s8s, short, schar) +DEF_CVT_FUNC(32s8s, int, schar) +DEF_CVT_FUNC(32f8s, float, schar) +DEF_CVT_FUNC(64f8s, double, schar) -DEF_CVT_FUNC(8u16u, uchar, ushort); -DEF_CVT_FUNC(8s16u, schar, ushort); -DEF_CPY_FUNC(16u, ushort); -DEF_CVT_FUNC(16s16u, short, ushort); -DEF_CVT_FUNC(32s16u, int, ushort); -DEF_CVT_FUNC(32f16u, float, ushort); -DEF_CVT_FUNC(64f16u, double, ushort); +DEF_CVT_FUNC(8u16u, uchar, ushort) +DEF_CVT_FUNC(8s16u, schar, ushort) +DEF_CPY_FUNC(16u, ushort) +DEF_CVT_FUNC(16s16u, short, ushort) +DEF_CVT_FUNC(32s16u, int, ushort) +DEF_CVT_FUNC(32f16u, float, ushort) +DEF_CVT_FUNC(64f16u, double, ushort) -DEF_CVT_FUNC(8u16s, uchar, short); -DEF_CVT_FUNC(8s16s, schar, short); -DEF_CVT_FUNC(16u16s, ushort, short); -DEF_CVT_FUNC(32s16s, int, short); -DEF_CVT_FUNC(32f16s, float, short); -DEF_CVT_FUNC(64f16s, double, short); +DEF_CVT_FUNC(8u16s, uchar, short) +DEF_CVT_FUNC(8s16s, schar, short) +DEF_CVT_FUNC(16u16s, ushort, short) +DEF_CVT_FUNC(32s16s, int, short) +DEF_CVT_FUNC(32f16s, float, short) +DEF_CVT_FUNC(64f16s, double, short) -DEF_CVT_FUNC(8u32s, uchar, int); -DEF_CVT_FUNC(8s32s, schar, int); -DEF_CVT_FUNC(16u32s, ushort, int); -DEF_CVT_FUNC(16s32s, short, int); -DEF_CPY_FUNC(32s, int); -DEF_CVT_FUNC(32f32s, float, int); -DEF_CVT_FUNC(64f32s, double, int); +DEF_CVT_FUNC(8u32s, uchar, int) +DEF_CVT_FUNC(8s32s, schar, int) +DEF_CVT_FUNC(16u32s, ushort, int) +DEF_CVT_FUNC(16s32s, short, int) +DEF_CPY_FUNC(32s, int) +DEF_CVT_FUNC(32f32s, float, int) +DEF_CVT_FUNC(64f32s, double, int) -DEF_CVT_FUNC(8u32f, uchar, float); -DEF_CVT_FUNC(8s32f, schar, float); -DEF_CVT_FUNC(16u32f, ushort, float); -DEF_CVT_FUNC(16s32f, short, float); -DEF_CVT_FUNC(32s32f, int, float); -DEF_CVT_FUNC(64f32f, double, float); +DEF_CVT_FUNC(8u32f, uchar, float) +DEF_CVT_FUNC(8s32f, schar, float) +DEF_CVT_FUNC(16u32f, ushort, float) +DEF_CVT_FUNC(16s32f, short, float) +DEF_CVT_FUNC(32s32f, int, float) +DEF_CVT_FUNC(64f32f, double, float) -DEF_CVT_FUNC(8u64f, uchar, double); -DEF_CVT_FUNC(8s64f, schar, double); -DEF_CVT_FUNC(16u64f, ushort, double); -DEF_CVT_FUNC(16s64f, short, double); -DEF_CVT_FUNC(32s64f, int, double); -DEF_CVT_FUNC(32f64f, float, double); -DEF_CPY_FUNC(64s, int64); +DEF_CVT_FUNC(8u64f, uchar, double) +DEF_CVT_FUNC(8s64f, schar, double) +DEF_CVT_FUNC(16u64f, ushort, double) +DEF_CVT_FUNC(16s64f, short, double) +DEF_CVT_FUNC(32s64f, int, double) +DEF_CVT_FUNC(32f64f, float, double) +DEF_CPY_FUNC(64s, int64) static BinaryFunc getCvtScaleAbsFunc(int depth) { diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index cc26b3eb3..b8d87fc22 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -166,16 +166,16 @@ static void copyMask##suffix(const uchar* src, size_t sstep, const uchar* mask, } -DEF_COPY_MASK(8u, uchar); -DEF_COPY_MASK(16u, ushort); -DEF_COPY_MASK(8uC3, Vec3b); -DEF_COPY_MASK(32s, int); -DEF_COPY_MASK(16uC3, Vec3s); -DEF_COPY_MASK(32sC2, Vec2i); -DEF_COPY_MASK(32sC3, Vec3i); -DEF_COPY_MASK(32sC4, Vec4i); -DEF_COPY_MASK(32sC6, Vec6i); -DEF_COPY_MASK(32sC8, Vec8i); +DEF_COPY_MASK(8u, uchar) +DEF_COPY_MASK(16u, ushort) +DEF_COPY_MASK(8uC3, Vec3b) +DEF_COPY_MASK(32s, int) +DEF_COPY_MASK(16uC3, Vec3s) +DEF_COPY_MASK(32sC2, Vec2i) +DEF_COPY_MASK(32sC3, Vec3i) +DEF_COPY_MASK(32sC4, Vec4i) +DEF_COPY_MASK(32sC6, Vec6i) +DEF_COPY_MASK(32sC8, Vec8i) BinaryFunc copyMaskTab[] = { @@ -232,10 +232,7 @@ void Mat::copyTo( OutputArray _dst ) const const uchar* sptr = data; uchar* dptr = dst.data; - // to handle the copying 1xn matrix => nx1 std vector. - Size sz = size() == dst.size() ? - getContinuousSize(*this, dst) : - getContinuousSize(*this); + Size sz = getContinuousSize(*this, dst); size_t len = sz.width*elemSize(); for( ; sz.height--; sptr += step, dptr += dst.step ) @@ -286,6 +283,7 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const if( dims <= 2 ) { + CV_Assert( size() == mask.size() ); Size sz = getContinuousSize(*this, dst, mask, mcn); copymask(data, step, mask.data, mask.step, dst.data, dst.step, sz, &esz); return; diff --git a/modules/core/src/gl_core_3_1.cpp b/modules/core/src/gl_core_3_1.cpp index bd1eb7ddd..4a83ba0ca 100644 --- a/modules/core/src/gl_core_3_1.cpp +++ b/modules/core/src/gl_core_3_1.cpp @@ -47,22 +47,27 @@ #include "gl_core_3_1.hpp" #ifdef HAVE_OPENGL - #if defined(__APPLE__) - #include + + #ifdef __APPLE__ + #include static void* AppleGLGetProcAddress (const char* name) { - static const struct mach_header* image = 0; - if (!image) - image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR); + static bool initialized = false; + static void * handle = NULL; + if (!handle) + { + if (!initialized) + { + initialized = true; + const char * const path = "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"; - // prepend a '_' for the Unix C symbol mangling convention - std::string symbolName = "_"; - symbolName += std::string(name); - - NSSymbol symbol = image ? NSLookupSymbolInImage(image, &symbolName[0], NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : 0; - - return symbol ? NSAddressOfSymbol(symbol) : 0; + handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + } + if (!handle) + return NULL; + } + return dlsym(handle, name); } #endif // __APPLE__ diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index 5dae4697d..96691919f 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -279,20 +279,19 @@ bool cv::gpu::TargetArchs::hasEqualOrGreater(int major, int minor) { return devi bool cv::gpu::TargetArchs::hasEqualOrGreaterPtx(int major, int minor) { return deviceInfoFuncTable()->hasEqualOrGreaterPtx(major, minor); } bool cv::gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor) { return deviceInfoFuncTable()->hasEqualOrGreaterBin(major, minor); } -size_t cv::gpu::DeviceInfo::sharedMemPerBlock() const { return deviceInfoFuncTable()->sharedMemPerBlock(); } -void cv::gpu::DeviceInfo::queryMemory(size_t& total_memory, size_t& free_memory) const { deviceInfoFuncTable()->queryMemory(total_memory, free_memory); } -size_t cv::gpu::DeviceInfo::freeMemory() const { return deviceInfoFuncTable()->freeMemory(); } -size_t cv::gpu::DeviceInfo::totalMemory() const { return deviceInfoFuncTable()->totalMemory(); } -bool cv::gpu::DeviceInfo::supports(FeatureSet feature_set) const { return deviceInfoFuncTable()->supports(feature_set); } -bool cv::gpu::DeviceInfo::isCompatible() const { return deviceInfoFuncTable()->isCompatible(); } +size_t cv::gpu::DeviceInfo::sharedMemPerBlock() const { return deviceInfoFuncTable()->sharedMemPerBlock(device_id_); } +void cv::gpu::DeviceInfo::queryMemory(size_t& total_memory, size_t& free_memory) const { deviceInfoFuncTable()->queryMemory(device_id_, total_memory, free_memory); } +size_t cv::gpu::DeviceInfo::freeMemory() const { return deviceInfoFuncTable()->freeMemory(device_id_); } +size_t cv::gpu::DeviceInfo::totalMemory() const { return deviceInfoFuncTable()->totalMemory(device_id_); } +bool cv::gpu::DeviceInfo::supports(FeatureSet feature_set) const { return deviceInfoFuncTable()->supports(device_id_, feature_set); } +bool cv::gpu::DeviceInfo::isCompatible() const { return deviceInfoFuncTable()->isCompatible(device_id_); } void cv::gpu::DeviceInfo::query() { - deviceInfoFuncTable()->query(); - name_ = deviceInfoFuncTable()->name(); - multi_processor_count_ = deviceInfoFuncTable()->multiProcessorCount(); - majorVersion_ = deviceInfoFuncTable()->majorVersion(); - minorVersion_ = deviceInfoFuncTable()->minorVersion(); + name_ = deviceInfoFuncTable()->name(device_id_); + multi_processor_count_ = deviceInfoFuncTable()->multiProcessorCount(device_id_); + majorVersion_ = deviceInfoFuncTable()->majorVersion(device_id_); + minorVersion_ = deviceInfoFuncTable()->minorVersion(device_id_); } void cv::gpu::printCudaDeviceInfo(int device) { deviceInfoFuncTable()->printCudaDeviceInfo(device); } @@ -621,11 +620,19 @@ void cv::gpu::GpuMat::copyTo(GpuMat& m) const void cv::gpu::GpuMat::copyTo(GpuMat& mat, const GpuMat& mask) const { if (mask.empty()) + { copyTo(mat); + } else { + uchar* data0 = mat.data; + mat.create(size(), type()); + // do not leave dst uninitialized + if (mat.data != data0) + mat.setTo(Scalar::all(0)); + gpuFuncTable()->copyWithMask(*this, mat, mask); } } diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 517ee9dac..8e32b0fbe 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2691,16 +2691,18 @@ double cv::kmeans( InputArray _data, int K, int flags, OutputArray _centers ) { const int SPP_TRIALS = 3; - Mat data = _data.getMat(); - bool isrow = data.rows == 1 && data.channels() > 1; - int N = !isrow ? data.rows : data.cols; - int dims = (!isrow ? data.cols : 1)*data.channels(); - int type = data.depth(); + Mat data0 = _data.getMat(); + bool isrow = data0.rows == 1 && data0.channels() > 1; + int N = !isrow ? data0.rows : data0.cols; + int dims = (!isrow ? data0.cols : 1)*data0.channels(); + int type = data0.depth(); attempts = std::max(attempts, 1); - CV_Assert( data.dims <= 2 && type == CV_32F && K > 0 ); + CV_Assert( data0.dims <= 2 && type == CV_32F && K > 0 ); CV_Assert( N >= K ); + Mat data(N, dims, CV_32F, data0.data, isrow ? dims * sizeof(float) : static_cast(data0.step)); + _bestLabels.create(N, 1, CV_32S, -1, true); Mat _labels, best_labels = _bestLabels.getMat(); diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index 65190c50e..a2894b700 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -148,7 +148,7 @@ public: void write(std::ostream& out, const Mat& m, const int*, int) const { out << "["; - writeMat(out, m, ';', ' ', m.cols == 1); + writeMat(out, m, ';', ' ', m.rows == 1); out << "]"; } @@ -165,7 +165,7 @@ public: void write(std::ostream& out, const Mat& m, const int*, int) const { out << "["; - writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1); + writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.rows*m.channels() == 1); out << "]"; } @@ -187,7 +187,7 @@ public: "uint8", "int8", "uint16", "int16", "int32", "float32", "float64", "uint64" }; out << "array(["; - writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.cols*m.channels() == 1); + writeMat(out, m, m.cols > 1 ? '[' : ' ', '[', m.rows*m.channels() == 1); out << "], type='" << numpyTypes[m.depth()] << "')"; } @@ -204,7 +204,7 @@ public: virtual ~CSVFormatter() {} void write(std::ostream& out, const Mat& m, const int*, int) const { - writeMat(out, m, ' ', ' ', m.cols*m.channels() == 1); + writeMat(out, m, ' ', ' ', m.rows*m.channels() == 1); if(m.rows > 1) out << "\n"; } @@ -223,7 +223,7 @@ public: void write(std::ostream& out, const Mat& m, const int*, int) const { out << "{"; - writeMat(out, m, ',', ' ', m.cols==1); + writeMat(out, m, ',', ' ', m.rows==1); out << "}"; } diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 7759f708b..6847eec34 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -4855,7 +4855,7 @@ cvRegisterType( const CvTypeInfo* _info ) "Type name should contain only letters, digits, - and _" ); } - info = (CvTypeInfo*)malloc( sizeof(*info) + len + 1 ); + info = (CvTypeInfo*)cvAlloc( sizeof(*info) + len + 1 ); *info = *_info; info->type_name = (char*)(info + 1); @@ -4893,7 +4893,7 @@ cvUnregisterType( const char* type_name ) if( !CvType::first || !CvType::last ) CvType::first = CvType::last = 0; - free( info ); + cvFree( &info ); } } diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index eb3e22900..8ad2aabb8 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -728,10 +728,10 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input dcn_stddev = (int)stddev.total(); pstddev = (Ipp64f *)stddev.data; } - for( int k = cn; k < dcn_mean; k++ ) - pmean[k] = 0; - for( int k = cn; k < dcn_stddev; k++ ) - pstddev[k] = 0; + for( int c = cn; c < dcn_mean; c++ ) + pmean[c] = 0; + for( int c = cn; c < dcn_stddev; c++ ) + pstddev[c] = 0; IppiSize sz = { cols, rows }; int type = src.type(); if( !mask.empty() ) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index b301d95db..68aff531f 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -87,10 +87,41 @@ #ifdef HAVE_WINRT #include +#ifndef __cplusplus_winrt +#include +#pragma comment(lib, "runtimeobject.lib") +#endif std::wstring GetTempPathWinRT() { +#ifdef __cplusplus_winrt return std::wstring(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data()); +#else + Microsoft::WRL::ComPtr appdataFactory; + Microsoft::WRL::ComPtr appdataRef; + Microsoft::WRL::ComPtr storagefolderRef; + Microsoft::WRL::ComPtr storageitemRef; + HSTRING str; + HSTRING_HEADER hstrHead; + std::wstring wstr; + if (FAILED(WindowsCreateStringReference(RuntimeClass_Windows_Storage_ApplicationData, + (UINT32)wcslen(RuntimeClass_Windows_Storage_ApplicationData), &hstrHead, &str))) + return wstr; + if (FAILED(RoGetActivationFactory(str, IID_PPV_ARGS(appdataFactory.ReleaseAndGetAddressOf())))) + return wstr; + if (FAILED(appdataFactory->get_Current(appdataRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(appdataRef->get_TemporaryFolder(storagefolderRef.ReleaseAndGetAddressOf()))) + return wstr; + if (FAILED(storagefolderRef.As(&storageitemRef))) + return wstr; + str = NULL; + if (FAILED(storageitemRef->get_Path(&str))) + return wstr; + wstr = WindowsGetStringRawBuffer(str, NULL); + WindowsDeleteString(str); + return wstr; +#endif } std::wstring GetTempFileNameWinRT(std::wstring prefix) @@ -392,27 +423,23 @@ string format( const char* fmt, ... ) string tempfile( const char* suffix ) { -#ifdef HAVE_WINRT - std::wstring temp_dir = L""; - const wchar_t* opencv_temp_dir = _wgetenv(L"OPENCV_TEMP_PATH"); - if (opencv_temp_dir) - temp_dir = std::wstring(opencv_temp_dir); -#else + string fname; +#ifndef HAVE_WINRT const char *temp_dir = getenv("OPENCV_TEMP_PATH"); #endif - string fname; #if defined WIN32 || defined _WIN32 #ifdef HAVE_WINRT RoInitialize(RO_INIT_MULTITHREADED); - std::wstring temp_dir2; - if (temp_dir.empty()) - temp_dir = GetTempPathWinRT(); + std::wstring temp_dir = L""; + const wchar_t* opencv_temp_dir = GetTempPathWinRT().c_str(); + if (opencv_temp_dir) + temp_dir = std::wstring(opencv_temp_dir); std::wstring temp_file; temp_file = GetTempFileNameWinRT(L"ocv"); if (temp_file.empty()) - return std::string(); + return string(); temp_file = temp_dir + std::wstring(L"\\") + temp_file; DeleteFileW(temp_file.c_str()); @@ -420,7 +447,7 @@ string tempfile( const char* suffix ) char aname[MAX_PATH]; size_t copied = wcstombs(aname, temp_file.c_str(), MAX_PATH); CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); - fname = std::string(aname); + fname = string(aname); RoUninitialize(); #else char temp_dir2[MAX_PATH] = { 0 }; @@ -951,7 +978,9 @@ public: }; #ifdef WIN32 +#ifdef _MSC_VER #pragma warning(disable:4505) // unreferenced local function has been removed +#endif #ifdef HAVE_WINRT // using C++11 thread attribute for local thread data @@ -1098,17 +1127,24 @@ public: } } }; -static TLSContainerStorage tlsContainerStorage; + +// This is a wrapper function that will ensure 'tlsContainerStorage' is constructed on first use. +// For more information: http://www.parashift.com/c++-faq/static-init-order-on-first-use.html +static TLSContainerStorage& getTLSContainerStorage() +{ + static TLSContainerStorage *tlsContainerStorage = new TLSContainerStorage(); + return *tlsContainerStorage; +} TLSDataContainer::TLSDataContainer() : key_(-1) { - key_ = tlsContainerStorage.allocateKey(this); + key_ = getTLSContainerStorage().allocateKey(this); } TLSDataContainer::~TLSDataContainer() { - tlsContainerStorage.releaseKey(key_, this); + getTLSContainerStorage().releaseKey(key_, this); key_ = -1; } @@ -1133,7 +1169,7 @@ TLSStorage::~TLSStorage() void*& data = tlsData_[i]; if (data) { - tlsContainerStorage.destroyData(i, data); + getTLSContainerStorage().destroyData(i, data); data = NULL; } } diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 664fa0204..f3faa57fc 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -115,7 +115,7 @@ struct BaseAddOp : public BaseElemWiseOp struct AddOp : public BaseAddOp { - AddOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {}; + AddOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( mask.empty() ) @@ -128,7 +128,7 @@ struct AddOp : public BaseAddOp struct SubOp : public BaseAddOp { - SubOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, -1, Scalar::all(0)) {}; + SubOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, -1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( mask.empty() ) @@ -141,7 +141,7 @@ struct SubOp : public BaseAddOp struct AddSOp : public BaseAddOp { - AddSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, 1, 0, Scalar::all(0)) {}; + AddSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, 1, 0, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( mask.empty() ) @@ -154,7 +154,7 @@ struct AddSOp : public BaseAddOp struct SubRSOp : public BaseAddOp { - SubRSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, -1, 0, Scalar::all(0)) {}; + SubRSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, -1, 0, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( mask.empty() ) @@ -167,7 +167,7 @@ struct SubRSOp : public BaseAddOp struct ScaleAddOp : public BaseAddOp { - ScaleAddOp() : BaseAddOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + ScaleAddOp() : BaseAddOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { scaleAdd(src[0], alpha, src[1], dst); @@ -181,7 +181,7 @@ struct ScaleAddOp : public BaseAddOp struct AddWeightedOp : public BaseAddOp { - AddWeightedOp() : BaseAddOp(2, REAL_GAMMA, 1, 1, Scalar::all(0)) {}; + AddWeightedOp() : BaseAddOp(2, REAL_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { addWeighted(src[0], alpha, src[1], beta, gamma[0], dst); @@ -194,7 +194,7 @@ struct AddWeightedOp : public BaseAddOp struct MulOp : public BaseElemWiseOp { - MulOp() : BaseElemWiseOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + MulOp() : BaseElemWiseOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void getValueRange(int depth, double& minval, double& maxval) { minval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? -1000000 : -1000.; @@ -218,7 +218,7 @@ struct MulOp : public BaseElemWiseOp struct DivOp : public BaseElemWiseOp { - DivOp() : BaseElemWiseOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + DivOp() : BaseElemWiseOp(2, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::divide(src[0], src[1], dst, alpha); @@ -235,7 +235,7 @@ struct DivOp : public BaseElemWiseOp struct RecipOp : public BaseElemWiseOp { - RecipOp() : BaseElemWiseOp(1, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + RecipOp() : BaseElemWiseOp(1, FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::divide(alpha, src[0], dst); @@ -252,7 +252,7 @@ struct RecipOp : public BaseElemWiseOp struct AbsDiffOp : public BaseAddOp { - AbsDiffOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, -1, Scalar::all(0)) {}; + AbsDiffOp() : BaseAddOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, -1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { absdiff(src[0], src[1], dst); @@ -265,7 +265,7 @@ struct AbsDiffOp : public BaseAddOp struct AbsDiffSOp : public BaseAddOp { - AbsDiffSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA, 1, 0, Scalar::all(0)) {}; + AbsDiffSOp() : BaseAddOp(1, FIX_ALPHA+FIX_BETA, 1, 0, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { absdiff(src[0], gamma, dst); @@ -278,7 +278,7 @@ struct AbsDiffSOp : public BaseAddOp struct LogicOp : public BaseElemWiseOp { - LogicOp(char _opcode) : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)), opcode(_opcode) {}; + LogicOp(char _opcode) : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)), opcode(_opcode) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( opcode == '&' ) @@ -309,7 +309,7 @@ struct LogicOp : public BaseElemWiseOp struct LogicSOp : public BaseElemWiseOp { LogicSOp(char _opcode) - : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+(_opcode != '~' ? SUPPORT_MASK : 0), 1, 1, Scalar::all(0)), opcode(_opcode) {}; + : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+(_opcode != '~' ? SUPPORT_MASK : 0), 1, 1, Scalar::all(0)), opcode(_opcode) {} void op(const vector& src, Mat& dst, const Mat& mask) { if( opcode == '&' ) @@ -341,7 +341,7 @@ struct LogicSOp : public BaseElemWiseOp struct MinOp : public BaseElemWiseOp { - MinOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + MinOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::min(src[0], src[1], dst); @@ -358,7 +358,7 @@ struct MinOp : public BaseElemWiseOp struct MaxOp : public BaseElemWiseOp { - MaxOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + MaxOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::max(src[0], src[1], dst); @@ -375,7 +375,7 @@ struct MaxOp : public BaseElemWiseOp struct MinSOp : public BaseElemWiseOp { - MinSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {}; + MinSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::min(src[0], gamma[0], dst); @@ -392,7 +392,7 @@ struct MinSOp : public BaseElemWiseOp struct MaxSOp : public BaseElemWiseOp { - MaxSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {}; + MaxSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::max(src[0], gamma[0], dst); @@ -409,7 +409,7 @@ struct MaxSOp : public BaseElemWiseOp struct CmpOp : public BaseElemWiseOp { - CmpOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + CmpOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void generateScalars(int depth, RNG& rng) { BaseElemWiseOp::generateScalars(depth, rng); @@ -437,7 +437,7 @@ struct CmpOp : public BaseElemWiseOp struct CmpSOp : public BaseElemWiseOp { - CmpSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {}; + CmpSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {} void generateScalars(int depth, RNG& rng) { BaseElemWiseOp::generateScalars(depth, rng); @@ -467,7 +467,7 @@ struct CmpSOp : public BaseElemWiseOp struct CopyOp : public BaseElemWiseOp { - CopyOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {}; + CopyOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat& mask) { src[0].copyTo(dst, mask); @@ -490,7 +490,7 @@ struct CopyOp : public BaseElemWiseOp struct SetOp : public BaseElemWiseOp { - SetOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {}; + SetOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {} void op(const vector&, Mat& dst, const Mat& mask) { dst.setTo(gamma, mask); @@ -651,7 +651,7 @@ static void inRangeS(const Mat& src, const Scalar& lb, const Scalar& rb, Mat& ds struct InRangeSOp : public BaseElemWiseOp { - InRangeSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA, 1, 1, Scalar::all(0)) {}; + InRangeSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::inRange(src[0], gamma, gamma1, dst); @@ -681,7 +681,7 @@ struct InRangeSOp : public BaseElemWiseOp struct InRangeOp : public BaseElemWiseOp { - InRangeOp() : BaseElemWiseOp(3, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + InRangeOp() : BaseElemWiseOp(3, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { Mat lb, rb; @@ -707,7 +707,7 @@ struct InRangeOp : public BaseElemWiseOp struct ConvertScaleOp : public BaseElemWiseOp { - ConvertScaleOp() : BaseElemWiseOp(1, FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)), ddepth(0) { }; + ConvertScaleOp() : BaseElemWiseOp(1, FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)), ddepth(0) { } void op(const vector& src, Mat& dst, const Mat&) { src[0].convertTo(dst, ddepth, alpha, gamma[0]); @@ -742,7 +742,7 @@ struct ConvertScaleOp : public BaseElemWiseOp struct ConvertScaleAbsOp : public BaseElemWiseOp { - ConvertScaleAbsOp() : BaseElemWiseOp(1, FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {}; + ConvertScaleAbsOp() : BaseElemWiseOp(1, FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector& src, Mat& dst, const Mat&) { cv::convertScaleAbs(src[0], dst, alpha, gamma[0]); @@ -810,7 +810,7 @@ static void setIdentity(Mat& dst, const Scalar& s) struct FlipOp : public BaseElemWiseOp { - FlipOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + FlipOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void getRandomSize(RNG& rng, vector& size) { cvtest::randomSize(rng, 2, 2, cvtest::ARITHM_MAX_SIZE_LOG, size); @@ -836,7 +836,7 @@ struct FlipOp : public BaseElemWiseOp struct TransposeOp : public BaseElemWiseOp { - TransposeOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + TransposeOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void getRandomSize(RNG& rng, vector& size) { cvtest::randomSize(rng, 2, 2, cvtest::ARITHM_MAX_SIZE_LOG, size); @@ -857,7 +857,7 @@ struct TransposeOp : public BaseElemWiseOp struct SetIdentityOp : public BaseElemWiseOp { - SetIdentityOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA, 1, 1, Scalar::all(0)) {}; + SetIdentityOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA, 1, 1, Scalar::all(0)) {} void getRandomSize(RNG& rng, vector& size) { cvtest::randomSize(rng, 2, 2, cvtest::ARITHM_MAX_SIZE_LOG, size); @@ -878,7 +878,7 @@ struct SetIdentityOp : public BaseElemWiseOp struct SetZeroOp : public BaseElemWiseOp { - SetZeroOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + SetZeroOp() : BaseElemWiseOp(0, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} void op(const vector&, Mat& dst, const Mat&) { dst = Scalar::all(0); @@ -954,7 +954,7 @@ static void log(const Mat& src, Mat& dst) struct ExpOp : public BaseElemWiseOp { - ExpOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + ExpOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} int getRandomType(RNG& rng) { return cvtest::randomType(rng, DEPTH_MASK_FLT, 1, ARITHM_MAX_CHANNELS); @@ -981,7 +981,7 @@ struct ExpOp : public BaseElemWiseOp struct LogOp : public BaseElemWiseOp { - LogOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {}; + LogOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} int getRandomType(RNG& rng) { return cvtest::randomType(rng, DEPTH_MASK_FLT, 1, ARITHM_MAX_CHANNELS); @@ -1363,7 +1363,6 @@ TEST_P(ElemWiseTest, accuracy) op->op(src, dst, mask); double maxErr = op->getMaxErr(depth); - vector pos; ASSERT_PRED_FORMAT2(cvtest::MatComparator(maxErr, op->context), dst0, dst) << "\nsrc[0] ~ " << cvtest::MatInfo(!src.empty() ? src[0] : Mat()) << "\ntestCase #" << testIdx << "\n"; } } @@ -1564,3 +1563,232 @@ TEST(Core_round, CvRound) ASSERT_EQ(-2, cvRound(-2.5)); ASSERT_EQ(-4, cvRound(-3.5)); } + + +typedef testing::TestWithParam Mul1; + +TEST_P(Mul1, One) +{ + Size size = GetParam(); + cv::Mat src(size, CV_32FC1, cv::Scalar::all(2)), dst, + ref_dst(size, CV_32FC1, cv::Scalar::all(6)); + + cv::multiply(3, src, dst); + + ASSERT_EQ(0, cv::norm(dst, ref_dst, cv::NORM_INF)); +} + +INSTANTIATE_TEST_CASE_P(Arithm, Mul1, testing::Values(Size(2, 2), Size(1, 1))); + +class SubtractOutputMatNotEmpty : public testing::TestWithParam< std::tr1::tuple > +{ +public: + cv::Size size; + int src_type; + int dst_depth; + bool fixed; + + void SetUp() + { + size = std::tr1::get<0>(GetParam()); + src_type = std::tr1::get<1>(GetParam()); + dst_depth = std::tr1::get<2>(GetParam()); + fixed = std::tr1::get<3>(GetParam()); + } +}; + +TEST_P(SubtractOutputMatNotEmpty, Mat_Mat) +{ + cv::Mat src1(size, src_type, cv::Scalar::all(16)); + cv::Mat src2(size, src_type, cv::Scalar::all(16)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(src1, src2, dst, cv::noArray(), dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src1.channels())); + cv::subtract(src1, src2, fixed_dst, cv::noArray(), dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src1.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src1.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Mat_Mat_WithMask) +{ + cv::Mat src1(size, src_type, cv::Scalar::all(16)); + cv::Mat src2(size, src_type, cv::Scalar::all(16)); + cv::Mat mask(size, CV_8UC1, cv::Scalar::all(255)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(src1, src2, dst, mask, dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src1.channels())); + cv::subtract(src1, src2, fixed_dst, mask, dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src1.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src1.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Mat_Mat_Expr) +{ + cv::Mat src1(size, src_type, cv::Scalar::all(16)); + cv::Mat src2(size, src_type, cv::Scalar::all(16)); + + cv::Mat dst = src1 - src2; + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src1.size(), dst.size()); + ASSERT_EQ(src1.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Mat_Scalar) +{ + cv::Mat src(size, src_type, cv::Scalar::all(16)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(src, cv::Scalar::all(16), dst, cv::noArray(), dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src.channels())); + cv::subtract(src, cv::Scalar::all(16), fixed_dst, cv::noArray(), dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Mat_Scalar_WithMask) +{ + cv::Mat src(size, src_type, cv::Scalar::all(16)); + cv::Mat mask(size, CV_8UC1, cv::Scalar::all(255)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(src, cv::Scalar::all(16), dst, mask, dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src.channels())); + cv::subtract(src, cv::Scalar::all(16), fixed_dst, mask, dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Scalar_Mat) +{ + cv::Mat src(size, src_type, cv::Scalar::all(16)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(cv::Scalar::all(16), src, dst, cv::noArray(), dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src.channels())); + cv::subtract(cv::Scalar::all(16), src, fixed_dst, cv::noArray(), dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Scalar_Mat_WithMask) +{ + cv::Mat src(size, src_type, cv::Scalar::all(16)); + cv::Mat mask(size, CV_8UC1, cv::Scalar::all(255)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(cv::Scalar::all(16), src, dst, mask, dst_depth); + } + else + { + const cv::Mat fixed_dst(size, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src.channels())); + cv::subtract(cv::Scalar::all(16), src, fixed_dst, mask, dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src.size(), dst.size()); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +TEST_P(SubtractOutputMatNotEmpty, Mat_Mat_3d) +{ + int dims[] = {5, size.height, size.width}; + + cv::Mat src1(3, dims, src_type, cv::Scalar::all(16)); + cv::Mat src2(3, dims, src_type, cv::Scalar::all(16)); + + cv::Mat dst; + + if (!fixed) + { + cv::subtract(src1, src2, dst, cv::noArray(), dst_depth); + } + else + { + const cv::Mat fixed_dst(3, dims, CV_MAKE_TYPE((dst_depth > 0 ? dst_depth : CV_16S), src1.channels())); + cv::subtract(src1, src2, fixed_dst, cv::noArray(), dst_depth); + dst = fixed_dst; + dst_depth = fixed_dst.depth(); + } + + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(src1.dims, dst.dims); + ASSERT_EQ(src1.size, dst.size); + ASSERT_EQ(dst_depth > 0 ? dst_depth : src1.depth(), dst.depth()); + ASSERT_EQ(0, cv::countNonZero(dst.reshape(1))); +} + +INSTANTIATE_TEST_CASE_P(Arithm, SubtractOutputMatNotEmpty, testing::Combine( + testing::Values(cv::Size(16, 16), cv::Size(13, 13), cv::Size(16, 13), cv::Size(13, 16)), + testing::Values(perf::MatType(CV_8UC1), CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3), + testing::Values(-1, CV_16S, CV_32S, CV_32F), + testing::Bool())); diff --git a/modules/core/test/test_ds.cpp b/modules/core/test/test_ds.cpp index cd76ca2fe..adc8f1a42 100644 --- a/modules/core/test/test_ds.cpp +++ b/modules/core/test/test_ds.cpp @@ -1357,7 +1357,7 @@ int Core_SetTest::test_set_ops( int iters ) (cvset->total == 0 || cvset->total >= prev_total), "The total number of cvset elements is not correct" ); - // CvSet and simple set do not neccessary have the same "total" (active & free) number, + // CvSet and simple set do not necessary have the same "total" (active & free) number, // so pass "set->total" to skip that check test_seq_block_consistence( struct_idx, (CvSeq*)cvset, cvset->total ); update_progressbar(); @@ -1779,7 +1779,7 @@ int Core_GraphTest::test_graph_ops( int iters ) (graph->edges->total == 0 || graph->edges->total >= prev_edge_total), "The total number of graph vertices is not correct" ); - // CvGraph and simple graph do not neccessary have the same "total" (active & free) number, + // CvGraph and simple graph do not necessary have the same "total" (active & free) number, // so pass "graph->total" (or "graph->edges->total") to skip that check test_seq_block_consistence( struct_idx, (CvSeq*)graph, graph->total ); test_seq_block_consistence( struct_idx, (CvSeq*)graph->edges, graph->edges->total ); diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 514b587d7..a6ebe152d 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -897,3 +897,24 @@ TEST(Core_Mat, reshape_1942) ); ASSERT_EQ(1, cn); } + +TEST(Core_Mat, copyNx1ToVector) +{ + cv::Mat_ src(5, 1); + cv::Mat_ ref_dst8; + cv::Mat_ ref_dst16; + std::vector dst8; + std::vector dst16; + + src << 1, 2, 3, 4, 5; + + src.copyTo(ref_dst8); + src.copyTo(dst8); + + ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst8, cv::Mat_(dst8)); + + src.convertTo(ref_dst16, CV_16U); + src.convertTo(dst16, CV_16U); + + ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_(dst16)); +} diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 3847afce6..5dec97e8c 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -2392,16 +2392,14 @@ TYPED_TEST_P(Core_CheckRange, Negative) double min_bound = 4.5; double max_bound = 16.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_FALSE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,1); - - delete bad_pt; + ASSERT_FALSE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 1); } TYPED_TEST_P(Core_CheckRange, Positive) @@ -2409,16 +2407,14 @@ TYPED_TEST_P(Core_CheckRange, Positive) double min_bound = -1; double max_bound = 16.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_TRUE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,0); - - delete bad_pt; + ASSERT_TRUE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 0); } TYPED_TEST_P(Core_CheckRange, Bounds) @@ -2426,16 +2422,14 @@ TYPED_TEST_P(Core_CheckRange, Bounds) double min_bound = 24.5; double max_bound = 1.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_FALSE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,0); - - delete bad_pt; + ASSERT_FALSE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 0); } TYPED_TEST_P(Core_CheckRange, Zero) @@ -2518,6 +2512,15 @@ TEST(Core_SVD, flt) // TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)), +enum +{ + MAT_N_DIM_C1, + MAT_N_1_CDIM, + MAT_1_N_CDIM, + MAT_N_DIM_C1_NONCONT, + MAT_N_1_CDIM_NONCONT, + VECTOR +}; class CV_KMeansSingularTest : public cvtest::BaseTest { @@ -2525,7 +2528,7 @@ public: CV_KMeansSingularTest() {} ~CV_KMeansSingularTest() {} protected: - void run(int) + void run(int inVariant) { int i, iter = 0, N = 0, N0 = 0, K = 0, dims = 0; Mat labels; @@ -2537,20 +2540,70 @@ protected: for( iter = 0; iter < maxIter; iter++ ) { ts->update_context(this, iter, true); - dims = rng.uniform(1, MAX_DIM+1); + dims = rng.uniform(inVariant == MAT_1_N_CDIM ? 2 : 1, MAX_DIM+1); N = rng.uniform(1, MAX_POINTS+1); N0 = rng.uniform(1, MAX(N/10, 2)); K = rng.uniform(1, N+1); - Mat data0(N0, dims, CV_32F); - rng.fill(data0, RNG::UNIFORM, -1, 1); + if (inVariant == VECTOR) + { + dims = 2; - Mat data(N, dims, CV_32F); - for( i = 0; i < N; i++ ) - data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + std::vector data0(N0); + rng.fill(data0, RNG::UNIFORM, -1, 1); - kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), - 5, KMEANS_PP_CENTERS); + std::vector data(N); + for( i = 0; i < N; i++ ) + data[i] = data0[rng.uniform(0, N0)]; + + kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), + 5, KMEANS_PP_CENTERS); + } + else + { + Mat data0(N0, dims, CV_32F); + rng.fill(data0, RNG::UNIFORM, -1, 1); + + Mat data; + + switch (inVariant) + { + case MAT_N_DIM_C1: + data.create(N, dims, CV_32F); + for( i = 0; i < N; i++ ) + data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + break; + + case MAT_N_1_CDIM: + data.create(N, 1, CV_32FC(dims)); + for( i = 0; i < N; i++ ) + memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + + case MAT_1_N_CDIM: + data.create(1, N, CV_32FC(dims)); + for( i = 0; i < N; i++ ) + memcpy(data.data + i * dims * sizeof(float), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + + case MAT_N_DIM_C1_NONCONT: + data.create(N, dims + 5, CV_32F); + data = data(Range(0, N), Range(0, dims)); + for( i = 0; i < N; i++ ) + data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + break; + + case MAT_N_1_CDIM_NONCONT: + data.create(N, 3, CV_32FC(dims)); + data = data.colRange(0, 1); + for( i = 0; i < N; i++ ) + memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + } + + kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), + 5, KMEANS_PP_CENTERS); + } Mat hist(K, 1, CV_32S, Scalar(0)); for( i = 0; i < N; i++ ) @@ -2574,7 +2627,19 @@ protected: } }; -TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(); } +TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(MAT_N_DIM_C1); } + +CV_ENUM(KMeansInputVariant, MAT_N_DIM_C1, MAT_N_1_CDIM, MAT_1_N_CDIM, MAT_N_DIM_C1_NONCONT, MAT_N_1_CDIM_NONCONT, VECTOR) + +typedef testing::TestWithParam Core_KMeans_InputVariants; + +TEST_P(Core_KMeans_InputVariants, singular) +{ + CV_KMeansSingularTest test; + test.safe_run(GetParam()); +} + +INSTANTIATE_TEST_CASE_P(AllVariants, Core_KMeans_InputVariants, KMeansInputVariant::all()); TEST(CovariationMatrixVectorOfMat, accuracy) { diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index 6b36883cf..fd14920a0 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -965,7 +965,7 @@ bool CV_OperationsTest::operations1() Vec v10dzero; for (int ii = 0; ii < 10; ++ii) { - if (!v10dzero[ii] == 0.0) + if (v10dzero[ii] != 0.0) throw test_excep(); } diff --git a/modules/dynamicuda/CMakeLists.txt b/modules/dynamicuda/CMakeLists.txt index b523bf0fd..75ace872a 100644 --- a/modules/dynamicuda/CMakeLists.txt +++ b/modules/dynamicuda/CMakeLists.txt @@ -9,7 +9,7 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wshadow) ocv_module_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include") set(OPENCV_MODULE_TYPE SHARED) if (BUILD_FAT_JAVA_LIB) - ocv_define_module(dynamicuda opencv_java PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) + ocv_define_module(dynamicuda INTERNAL opencv_java PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) else() - ocv_define_module(dynamicuda opencv_core PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) + ocv_define_module(dynamicuda INTERNAL opencv_core PRIVATE_REQUIRED ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) endif() diff --git a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp index 8973c5304..00f087303 100644 --- a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp +++ b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp @@ -9,18 +9,17 @@ class DeviceInfoFuncTable { public: // cv::DeviceInfo - virtual size_t sharedMemPerBlock() const = 0; - virtual void queryMemory(size_t&, size_t&) const = 0; - virtual size_t freeMemory() const = 0; - virtual size_t totalMemory() const = 0; - virtual bool supports(FeatureSet) const = 0; - virtual bool isCompatible() const = 0; - virtual void query() = 0; - virtual int deviceID() const = 0; - virtual std::string name() const = 0; - virtual int majorVersion() const = 0; - virtual int minorVersion() const = 0; - virtual int multiProcessorCount() const = 0; + virtual size_t sharedMemPerBlock(int id) const = 0; + virtual void queryMemory(int id, size_t&, size_t&) const = 0; + virtual size_t freeMemory(int id) const = 0; + virtual size_t totalMemory(int id) const = 0; + virtual bool supports(int id, FeatureSet) const = 0; + virtual bool isCompatible(int id) const = 0; + virtual std::string name(int id) const = 0; + virtual int majorVersion(int id) const = 0; + virtual int minorVersion(int id) const = 0; + virtual int multiProcessorCount(int id) const = 0; + virtual int getCudaEnabledDeviceCount() const = 0; virtual void setDevice(int) const = 0; virtual int getDevice() const = 0; @@ -46,8 +45,6 @@ public: class GpuFuncTable { public: - virtual ~GpuFuncTable() {} - // GpuMat routines virtual void copy(const Mat& src, GpuMat& dst) const = 0; virtual void copy(const GpuMat& src, Mat& dst) const = 0; @@ -64,23 +61,23 @@ public: virtual void mallocPitch(void** devPtr, size_t* step, size_t width, size_t height) const = 0; virtual void free(void* devPtr) const = 0; + + virtual ~GpuFuncTable() {} }; class EmptyDeviceInfoFuncTable: public DeviceInfoFuncTable { public: - size_t sharedMemPerBlock() const { throw_nogpu; return 0; } - void queryMemory(size_t&, size_t&) const { throw_nogpu; } - size_t freeMemory() const { throw_nogpu; return 0; } - size_t totalMemory() const { throw_nogpu; return 0; } - bool supports(FeatureSet) const { throw_nogpu; return false; } - bool isCompatible() const { throw_nogpu; return false; } - void query() { throw_nogpu; } - int deviceID() const { throw_nogpu; return -1; }; - std::string name() const { throw_nogpu; return std::string(); } - int majorVersion() const { throw_nogpu; return -1; } - int minorVersion() const { throw_nogpu; return -1; } - int multiProcessorCount() const { throw_nogpu; return -1; } + size_t sharedMemPerBlock(int) const { throw_nogpu; return 0; } + void queryMemory(int, size_t&, size_t&) const { throw_nogpu; } + size_t freeMemory(int) const { throw_nogpu; return 0; } + size_t totalMemory(int) const { throw_nogpu; return 0; } + bool supports(int, FeatureSet) const { throw_nogpu; return false; } + bool isCompatible(int) const { throw_nogpu; return false; } + std::string name(int) const { throw_nogpu; return std::string(); } + int majorVersion(int) const { throw_nogpu; return -1; } + int minorVersion(int) const { throw_nogpu; return -1; } + int multiProcessorCount(int) const { throw_nogpu; return -1; } int getCudaEnabledDeviceCount() const { return 0; } @@ -132,15 +129,20 @@ public: #if defined(USE_CUDA) -#define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__, CV_Func) -#define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, CV_Func) +// Disable NPP for this file +//#define USE_NPP +#undef USE_NPP +#define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__, CV_Func) inline void ___cudaSafeCall(cudaError_t err, const char *file, const int line, const char *func = "") { if (cudaSuccess != err) cv::gpu::error(cudaGetErrorString(err), file, line, func); } +#ifdef USE_NPP + +#define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, CV_Func) inline void ___nppSafeCall(int err, const char *file, const int line, const char *func = "") { if (err < 0) @@ -151,6 +153,8 @@ inline void ___nppSafeCall(int err, const char *file, const int line, const char } } +#endif + namespace cv { namespace gpu { namespace device { void copyToWithMask_gpu(PtrStepSzb src, PtrStepSzb dst, size_t elemSize1, int cn, PtrStepSzb mask, bool colorMask, cudaStream_t stream); @@ -176,6 +180,8 @@ template void kernelSetCaller(GpuMat& src, Scalar s, const GpuMat& cv::gpu::device::set_to_gpu(src, sf.val, mask, src.channels(), stream); } +#ifdef USE_NPP + template struct NPPTypeTraits; template<> struct NPPTypeTraits { typedef Npp8u npp_type; }; template<> struct NPPTypeTraits { typedef Npp8s npp_type; }; @@ -185,9 +191,13 @@ template<> struct NPPTypeTraits { typedef Npp32s npp_type; }; template<> struct NPPTypeTraits { typedef Npp32f npp_type; }; template<> struct NPPTypeTraits { typedef Npp64f npp_type; }; +#endif + ////////////////////////////////////////////////////////////////////////// // Convert +#ifdef USE_NPP + template struct NppConvertFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -235,9 +245,13 @@ template::func_ptr func> str } }; +#endif + ////////////////////////////////////////////////////////////////////////// // Set +#ifdef USE_NPP + template struct NppSetFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -342,9 +356,13 @@ template::func_ptr func> struct N } }; +#endif + ////////////////////////////////////////////////////////////////////////// // CopyMasked +#ifdef USE_NPP + template struct NppCopyMaskedFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -368,6 +386,8 @@ template::func_ptr func> struct N } }; +#endif + template static inline bool isAligned(const T* ptr, size_t size) { return reinterpret_cast(ptr) % size == 0; @@ -538,94 +558,84 @@ private: }; DeviceProps deviceProps; +const CudaArch cudaArch; class CudaDeviceInfoFuncTable : public DeviceInfoFuncTable { public: - size_t sharedMemPerBlock() const + size_t sharedMemPerBlock(int id) const { - return deviceProps.get(device_id_)->sharedMemPerBlock; + return deviceProps.get(id)->sharedMemPerBlock; } - void queryMemory(size_t& _totalMemory, size_t& _freeMemory) const + void queryMemory(int id, size_t& _totalMemory, size_t& _freeMemory) const { int prevDeviceID = getDevice(); - if (prevDeviceID != device_id_) - setDevice(device_id_); + if (prevDeviceID != id) + setDevice(id); cudaSafeCall( cudaMemGetInfo(&_freeMemory, &_totalMemory) ); - if (prevDeviceID != device_id_) + if (prevDeviceID != id) setDevice(prevDeviceID); } - size_t freeMemory() const + size_t freeMemory(int id) const { size_t _totalMemory, _freeMemory; - queryMemory(_totalMemory, _freeMemory); + queryMemory(id, _totalMemory, _freeMemory); return _freeMemory; } - size_t totalMemory() const + size_t totalMemory(int id) const { size_t _totalMemory, _freeMemory; - queryMemory(_totalMemory, _freeMemory); + queryMemory(id, _totalMemory, _freeMemory); return _totalMemory; } - bool supports(FeatureSet feature_set) const + bool supports(int id, FeatureSet feature_set) const { - int version = majorVersion_ * 10 + minorVersion_; + int version = majorVersion(id) * 10 + minorVersion(id); return version >= feature_set; } - bool isCompatible() const + bool isCompatible(int id) const { // Check PTX compatibility - if (hasEqualOrLessPtx(majorVersion_, minorVersion_)) + if (hasEqualOrLessPtx(majorVersion(id), minorVersion(id))) return true; // Check BIN compatibility - for (int i = minorVersion_; i >= 0; --i) - if (hasBin(majorVersion_, i)) + for (int i = minorVersion(id); i >= 0; --i) + if (hasBin(majorVersion(id), i)) return true; return false; } - void query() + std::string name(int id) const { - const cudaDeviceProp* prop = deviceProps.get(device_id_); - - name_ = prop->name; - multi_processor_count_ = prop->multiProcessorCount; - majorVersion_ = prop->major; - minorVersion_ = prop->minor; + const cudaDeviceProp* prop = deviceProps.get(id); + return prop->name; } - int deviceID() const + int majorVersion(int id) const { - return device_id_; + const cudaDeviceProp* prop = deviceProps.get(id); + return prop->major; } - std::string name() const + int minorVersion(int id) const { - return name_; + const cudaDeviceProp* prop = deviceProps.get(id); + return prop->minor; } - int majorVersion() const + int multiProcessorCount(int id) const { - return majorVersion_; - } - - int minorVersion() const - { - return minorVersion_; - } - - int multiProcessorCount() const - { - return multi_processor_count_; + const cudaDeviceProp* prop = deviceProps.get(id); + return prop->multiProcessorCount; } int getCudaEnabledDeviceCount() const @@ -836,15 +846,6 @@ public: } private: - int device_id_; - - std::string name_; - int multi_processor_count_; - int majorVersion_; - int minorVersion_; - - const CudaArch cudaArch; - int convertSMVer2Cores(int major, int minor) const { // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM @@ -899,6 +900,8 @@ public: } typedef void (*func_t)(const GpuMat& src, GpuMat& dst, const GpuMat& mask, cudaStream_t stream); + +#ifdef USE_NPP static const func_t funcs[7][4] = { /* 8U */ {NppCopyMasked::call, cv::gpu::device::copyWithMask, NppCopyMasked::call, NppCopyMasked::call}, @@ -911,6 +914,9 @@ public: }; const func_t func = mask.channels() == src.channels() ? funcs[src.depth()][src.channels() - 1] : cv::gpu::device::copyWithMask; +#else + const func_t func = cv::gpu::device::copyWithMask; +#endif func(src, dst, mask, 0); } @@ -918,6 +924,8 @@ public: void convert(const GpuMat& src, GpuMat& dst) const { typedef void (*func_t)(const GpuMat& src, GpuMat& dst); + +#ifdef USE_NPP static const func_t funcs[7][7][4] = { { @@ -984,6 +992,7 @@ public: /* 64F -> 64F */ {0,0,0,0} } }; +#endif CV_Assert(src.depth() <= CV_64F && src.channels() <= 4); CV_Assert(dst.depth() <= CV_64F); @@ -1002,8 +1011,12 @@ public: return; } +#ifdef USE_NPP const func_t func = funcs[src.depth()][dst.depth()][src.channels() - 1]; CV_DbgAssert(func != 0); +#else + const func_t func = cv::gpu::device::convertTo; +#endif func(src, dst); } @@ -1045,6 +1058,8 @@ public: } typedef void (*func_t)(GpuMat& src, Scalar s); + +#ifdef USE_NPP static const func_t funcs[7][4] = { {NppSet::call, cv::gpu::device::setTo , cv::gpu::device::setTo , NppSet::call}, @@ -1055,6 +1070,7 @@ public: {NppSet::call, cv::gpu::device::setTo , cv::gpu::device::setTo , NppSet::call}, {cv::gpu::device::setTo , cv::gpu::device::setTo , cv::gpu::device::setTo , cv::gpu::device::setTo } }; +#endif CV_Assert(m.depth() <= CV_64F && m.channels() <= 4); @@ -1064,14 +1080,22 @@ public: CV_Error(CV_StsUnsupportedFormat, "The device doesn't support double"); } +#ifdef USE_NPP + const func_t func = funcs[m.depth()][m.channels() - 1]; +#else + const func_t func = cv::gpu::device::setTo; +#endif + if (stream) cv::gpu::device::setTo(m, s, stream); else - funcs[m.depth()][m.channels() - 1](m, s); + func(m, s); } else { typedef void (*func_t)(GpuMat& src, Scalar s, const GpuMat& mask); + +#ifdef USE_NPP static const func_t funcs[7][4] = { {NppSetMask::call, cv::gpu::device::setTo, cv::gpu::device::setTo, NppSetMask::call}, @@ -1082,6 +1106,7 @@ public: {NppSetMask::call, cv::gpu::device::setTo, cv::gpu::device::setTo, NppSetMask::call}, {cv::gpu::device::setTo , cv::gpu::device::setTo, cv::gpu::device::setTo, cv::gpu::device::setTo } }; +#endif CV_Assert(m.depth() <= CV_64F && m.channels() <= 4); @@ -1091,10 +1116,16 @@ public: CV_Error(CV_StsUnsupportedFormat, "The device doesn't support double"); } +#ifdef USE_NPP + const func_t func = funcs[m.depth()][m.channels() - 1]; +#else + const func_t func = cv::gpu::device::setTo; +#endif + if (stream) cv::gpu::device::setTo(m, s, mask, stream); else - funcs[m.depth()][m.channels() - 1](m, s, mask); + func(m, s, mask); } } diff --git a/modules/features2d/doc/common_interfaces_of_descriptor_extractors.rst b/modules/features2d/doc/common_interfaces_of_descriptor_extractors.rst index 3639bd600..de3d99c85 100644 --- a/modules/features2d/doc/common_interfaces_of_descriptor_extractors.rst +++ b/modules/features2d/doc/common_interfaces_of_descriptor_extractors.rst @@ -66,7 +66,7 @@ Computes the descriptors for a set of keypoints detected in an image (first vari :param keypoints: Input collection of keypoints. Keypoints for which a descriptor cannot be computed are removed. Sometimes new keypoints can be added, for example: ``SIFT`` duplicates keypoint with several dominant orientations (for each orientation). - :param descriptors: Computed descriptors. In the second variant of the method ``descriptors[i]`` are descriptors computed for a ``keypoints[i]`. Row ``j`` is the ``keypoints`` (or ``keypoints[i]``) is the descriptor for keypoint ``j``-th keypoint. + :param descriptors: Computed descriptors. In the second variant of the method ``descriptors[i]`` are descriptors computed for a ``keypoints[i]``. Row ``j`` is the ``keypoints`` (or ``keypoints[i]``) is the descriptor for keypoint ``j``-th keypoint. DescriptorExtractor::create diff --git a/modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst b/modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst index 91c4110d2..933602b5c 100644 --- a/modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst +++ b/modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst @@ -277,7 +277,7 @@ Brute-force matcher constructor. :param normType: One of ``NORM_L1``, ``NORM_L2``, ``NORM_HAMMING``, ``NORM_HAMMING2``. ``L1`` and ``L2`` norms are preferable choices for SIFT and SURF descriptors, ``NORM_HAMMING`` should be used with ORB, BRISK and BRIEF, ``NORM_HAMMING2`` should be used with ORB when ``WTA_K==3`` or ``4`` (see ORB::ORB constructor description). - :param crossCheck: If it is false, this is will be default BFMatcher behaviour when it finds the k nearest neighbors for each query descriptor. If ``crossCheck==true``, then the ``knnMatch()`` method with ``k=1`` will only return pairs ``(i,j)`` such that for ``i-th`` query descriptor the ``j-th`` descriptor in the matcher's collection is the nearest and vice versa, i.e. the ``BFMathcher`` will only return consistent pairs. Such technique usually produces best results with minimal number of outliers when there are enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. + :param crossCheck: If it is false, this is will be default BFMatcher behaviour when it finds the k nearest neighbors for each query descriptor. If ``crossCheck==true``, then the ``knnMatch()`` method with ``k=1`` will only return pairs ``(i,j)`` such that for ``i-th`` query descriptor the ``j-th`` descriptor in the matcher's collection is the nearest and vice versa, i.e. the ``BFMatcher`` will only return consistent pairs. Such technique usually produces best results with minimal number of outliers when there are enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. FlannBasedMatcher diff --git a/modules/features2d/doc/feature_detection_and_description.rst b/modules/features2d/doc/feature_detection_and_description.rst index a0272026d..c05a71d34 100644 --- a/modules/features2d/doc/feature_detection_and_description.rst +++ b/modules/features2d/doc/feature_detection_and_description.rst @@ -11,9 +11,9 @@ FAST ---- Detects corners using the FAST algorithm -.. ocv:function:: void FAST( InputArray image, vector& keypoints, int threshold, bool nonmaxSupression=true ) +.. ocv:function:: void FAST( InputArray image, vector& keypoints, int threshold, bool nonmaxSuppression=true ) -.. ocv:function:: void FASTX( InputArray image, vector& keypoints, int threshold, bool nonmaxSupression, int type ) +.. ocv:function:: void FASTX( InputArray image, vector& keypoints, int threshold, bool nonmaxSuppression, int type ) :param image: grayscale image where keypoints (corners) are detected. @@ -21,7 +21,7 @@ Detects corners using the FAST algorithm :param threshold: threshold on difference between intensity of the central pixel and pixels of a circle around this pixel. - :param nonmaxSupression: if true, non-maximum suppression is applied to detected corners (keypoints). + :param nonmaxSuppression: if true, non-maximum suppression is applied to detected corners (keypoints). :param type: one of the three neighborhoods as defined in the paper: ``FastFeatureDetector::TYPE_9_16``, ``FastFeatureDetector::TYPE_7_12``, ``FastFeatureDetector::TYPE_5_8`` diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index d598ed6d7..7536128c7 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -566,10 +566,10 @@ protected: //! detects corners using FAST algorithm by E. Rosten CV_EXPORTS void FAST( InputArray image, CV_OUT vector& keypoints, - int threshold, bool nonmaxSupression=true ); + int threshold, bool nonmaxSuppression=true ); CV_EXPORTS void FASTX( InputArray image, CV_OUT vector& keypoints, - int threshold, bool nonmaxSupression, int type ); + int threshold, bool nonmaxSuppression, int type ); class CV_EXPORTS_W FastFeatureDetector : public FeatureDetector { diff --git a/modules/features2d/src/evaluation.cpp b/modules/features2d/src/evaluation.cpp index 44151c03c..52740e6e5 100644 --- a/modules/features2d/src/evaluation.cpp +++ b/modules/features2d/src/evaluation.cpp @@ -128,7 +128,7 @@ public: Point2f center; Scalar ellipse; // 3 elements a, b, c: ax^2+2bxy+cy^2=1 - Size_ axes; // half lenght of elipse axes + Size_ axes; // half length of ellipse axes Size_ boundingBox; // half sizes of bounding box which sides are parallel to the coordinate axes }; diff --git a/modules/features2d/src/features2d_init.cpp b/modules/features2d/src/features2d_init.cpp index 13ef0f8ae..e12310a3b 100644 --- a/modules/features2d/src/features2d_init.cpp +++ b/modules/features2d/src/features2d_init.cpp @@ -59,23 +59,23 @@ Ptr Feature2D::create( const string& feature2DType ) CV_INIT_ALGORITHM(BRISK, "Feature2D.BRISK", obj.info()->addParam(obj, "thres", obj.threshold); - obj.info()->addParam(obj, "octaves", obj.octaves)); + obj.info()->addParam(obj, "octaves", obj.octaves)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", - obj.info()->addParam(obj, "bytes", obj.bytes_)); + obj.info()->addParam(obj, "bytes", obj.bytes_)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", obj.info()->addParam(obj, "threshold", obj.threshold); - obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression)); + obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression)) CV_INIT_ALGORITHM(FastFeatureDetector2, "Feature2D.FASTX", obj.info()->addParam(obj, "threshold", obj.threshold); obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); - obj.info()->addParam(obj, "type", obj.type)); + obj.info()->addParam(obj, "type", obj.type)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -84,7 +84,7 @@ CV_INIT_ALGORITHM(StarDetector, "Feature2D.STAR", obj.info()->addParam(obj, "responseThreshold", obj.responseThreshold); obj.info()->addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected); obj.info()->addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized); - obj.info()->addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize)); + obj.info()->addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -97,7 +97,7 @@ CV_INIT_ALGORITHM(MSER, "Feature2D.MSER", obj.info()->addParam(obj, "maxEvolution", obj.maxEvolution); obj.info()->addParam(obj, "areaThreshold", obj.areaThreshold); obj.info()->addParam(obj, "minMargin", obj.minMargin); - obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize)); + obj.info()->addParam(obj, "edgeBlurSize", obj.edgeBlurSize)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -109,7 +109,7 @@ CV_INIT_ALGORITHM(ORB, "Feature2D.ORB", obj.info()->addParam(obj, "edgeThreshold", obj.edgeThreshold); obj.info()->addParam(obj, "patchSize", obj.patchSize); obj.info()->addParam(obj, "WTA_K", obj.WTA_K); - obj.info()->addParam(obj, "scoreType", obj.scoreType)); + obj.info()->addParam(obj, "scoreType", obj.scoreType)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -117,7 +117,7 @@ CV_INIT_ALGORITHM(FREAK, "Feature2D.FREAK", obj.info()->addParam(obj, "orientationNormalized", obj.orientationNormalized); obj.info()->addParam(obj, "scaleNormalized", obj.scaleNormalized); obj.info()->addParam(obj, "patternScale", obj.patternScale); - obj.info()->addParam(obj, "nbOctave", obj.nOctaves)); + obj.info()->addParam(obj, "nbOctave", obj.nOctaves)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,7 +126,7 @@ CV_INIT_ALGORITHM(GFTTDetector, "Feature2D.GFTT", obj.info()->addParam(obj, "qualityLevel", obj.qualityLevel); obj.info()->addParam(obj, "minDistance", obj.minDistance); obj.info()->addParam(obj, "useHarrisDetector", obj.useHarrisDetector); - obj.info()->addParam(obj, "k", obj.k)); + obj.info()->addParam(obj, "k", obj.k)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -146,7 +146,7 @@ CV_INIT_ALGORITHM(SimpleBlobDetector, "Feature2D.SimpleBlob", obj.info()->addParam(obj, "maxInertiaRatio", obj.params.maxInertiaRatio); obj.info()->addParam(obj, "filterByConvexity", obj.params.filterByConvexity); obj.info()->addParam(obj, "maxConvexity", obj.params.maxConvexity); - ); + ) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -167,7 +167,7 @@ CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS", obj.info()->addParam(obj, "qualityLevel", obj.qualityLevel); obj.info()->addParam(obj, "minDistance", obj.minDistance); obj.info()->addParam(obj, "useHarrisDetector", obj.useHarrisDetector); - obj.info()->addParam(obj, "k", obj.k)); + obj.info()->addParam(obj, "k", obj.k)) //////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -178,21 +178,21 @@ CV_INIT_ALGORITHM(DenseFeatureDetector, "Feature2D.Dense", obj.info()->addParam(obj, "initXyStep", obj.initXyStep); obj.info()->addParam(obj, "initImgBound", obj.initImgBound); obj.info()->addParam(obj, "varyXyStepWithScale", obj.varyXyStepWithScale); - obj.info()->addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale)); + obj.info()->addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale)) CV_INIT_ALGORITHM(GridAdaptedFeatureDetector, "Feature2D.Grid", obj.info()->addParam(obj, "detector", obj.detector, false, 0, 0); // Extra params added to avoid VS2013 fatal error in opencv2/core.hpp (decl. of addParam) obj.info()->addParam(obj, "maxTotalKeypoints", obj.maxTotalKeypoints); obj.info()->addParam(obj, "gridRows", obj.gridRows); - obj.info()->addParam(obj, "gridCols", obj.gridCols)); + obj.info()->addParam(obj, "gridCols", obj.gridCols)) //////////////////////////////////////////////////////////////////////////////////////////////////////////// CV_INIT_ALGORITHM(BFMatcher, "DescriptorMatcher.BFMatcher", obj.info()->addParam(obj, "normType", obj.normType); - obj.info()->addParam(obj, "crossCheck", obj.crossCheck)); + obj.info()->addParam(obj, "crossCheck", obj.crossCheck)) -CV_INIT_ALGORITHM(FlannBasedMatcher, "DescriptorMatcher.FlannBasedMatcher",); +CV_INIT_ALGORITHM(FlannBasedMatcher, "DescriptorMatcher.FlannBasedMatcher",) /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/modules/features2d/test/test_nearestneighbors.cpp b/modules/features2d/test/test_nearestneighbors.cpp index 45131eff2..8d1ecfd79 100644 --- a/modules/features2d/test/test_nearestneighbors.cpp +++ b/modules/features2d/test/test_nearestneighbors.cpp @@ -214,8 +214,6 @@ int CV_KDTreeTest_CPP::findNeighbors( Mat& points, Mat& neighbors ) const int emax = 20; Mat neighbors2( neighbors.size(), CV_32SC1 ); int j; - vector min(points.cols, static_cast(minValue)); - vector max(points.cols, static_cast(maxValue)); for( int pi = 0; pi < points.rows; pi++ ) { // 1st way diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index 8d531753e..2b9ca91a4 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -99,18 +99,22 @@ public: */ virtual void buildIndex() { + std::ostringstream stream; bestParams_ = estimateBuildParams(); + print_params(bestParams_, stream); Logger::info("----------------------------------------------------\n"); Logger::info("Autotuned parameters:\n"); - print_params(bestParams_); + Logger::info("%s", stream.str().c_str()); Logger::info("----------------------------------------------------\n"); bestIndex_ = create_index_by_type(dataset_, bestParams_, distance_); bestIndex_->buildIndex(); speedup_ = estimateSearchParams(bestSearchParams_); + stream.str(std::string()); + print_params(bestSearchParams_, stream); Logger::info("----------------------------------------------------\n"); Logger::info("Search parameters:\n"); - print_params(bestSearchParams_); + Logger::info("%s", stream.str().c_str()); Logger::info("----------------------------------------------------\n"); } diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 80ae2dc91..2afceb889 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -812,6 +812,66 @@ struct ZeroIterator }; + +/* + * Depending on processed distances, some of them are already squared (e.g. L2) + * and some are not (e.g.Hamming). In KMeans++ for instance we want to be sure + * we are working on ^2 distances, thus following templates to ensure that. + */ +template +struct squareDistance +{ + typedef typename Distance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist*dist; } +}; + + +template +struct squareDistance, ElementType> +{ + typedef typename L2_Simple::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename L2::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template +struct squareDistance, ElementType> +{ + typedef typename MinkowskiDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename HellingerDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename ChiSquareDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template +typename Distance::ResultType ensureSquareDistance( typename Distance::ResultType dist ) +{ + typedef typename Distance::ElementType ElementType; + + squareDistance dummy; + return dummy( dist ); +} + } #endif //OPENCV_FLANN_DIST_H_ diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index c27b64834..54cb8e55f 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -210,8 +210,11 @@ private: assert(index >=0 && index < n); centers[0] = dsindices[index]; + // Computing distance^2 will have the advantage of even higher probability further to pick new centers + // far from previous centers (and this complies to "k-means++: the advantages of careful seeding" article) for (int i = 0; i < n; i++) { closestDistSq[i] = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + closestDistSq[i] = ensureSquareDistance( closestDistSq[i] ); currentPot += closestDistSq[i]; } @@ -237,7 +240,10 @@ private: // Compute the new potential double newPot = 0; - for (int i = 0; i < n; i++) newPot += std::min( distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols), closestDistSq[i] ); + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + newPot += std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } // Store the best result if ((bestNewPot < 0)||(newPot < bestNewPot)) { @@ -249,7 +255,10 @@ private: // Add the appropriate center centers[centerCount] = dsindices[bestNewIndex]; currentPot = bestNewPot; - for (int i = 0; i < n; i++) closestDistSq[i] = std::min( distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols), closestDistSq[i] ); + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols); + closestDistSq[i] = std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } } centers_length = centerCount; @@ -414,12 +423,6 @@ public: void loadIndex(FILE* stream) { - load_value(stream, branching_); - load_value(stream, trees_); - load_value(stream, centers_init_); - load_value(stream, leaf_size_); - load_value(stream, memoryCounter); - free_elements(); if (root!=NULL) { @@ -430,6 +433,12 @@ public: delete[] indices; } + load_value(stream, branching_); + load_value(stream, trees_); + load_value(stream, centers_init_); + load_value(stream, leaf_size_); + load_value(stream, memoryCounter); + indices = new int*[trees_]; root = new NodePtr[trees_]; for (int i=0; i( closestDistSq[i] ); currentPot += closestDistSq[i]; } @@ -236,7 +237,10 @@ public: // Compute the new potential double newPot = 0; - for (int i = 0; i < n; i++) newPot += std::min( distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols), closestDistSq[i] ); + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols); + newPot += std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } // Store the best result if ((bestNewPot < 0)||(newPot < bestNewPot)) { @@ -248,7 +252,10 @@ public: // Add the appropriate center centers[centerCount] = indices[bestNewIndex]; currentPot = bestNewPot; - for (int i = 0; i < n; i++) closestDistSq[i] = std::min( distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols), closestDistSq[i] ); + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols); + closestDistSq[i] = std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } } centers_length = centerCount; @@ -759,10 +766,13 @@ private: for (int k=0; kfirst << " : " << it->second << std::endl; + stream << it->first << " : " << it->second << std::endl; } } - +inline void print_params(const IndexParams& params) +{ + print_params(params, std::cout); +} } diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 9171febc7..6de3e0efa 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -82,7 +82,7 @@ ocv_create_module(${cuda_link_libs}) if(HAVE_CUDA) install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2/${name} - COMPONENT main) + COMPONENT dev) endif() ocv_add_precompiled_headers(${the_module}) diff --git a/modules/gpu/doc/feature_detection_and_description.rst b/modules/gpu/doc/feature_detection_and_description.rst index 191b0ada0..66f425004 100644 --- a/modules/gpu/doc/feature_detection_and_description.rst +++ b/modules/gpu/doc/feature_detection_and_description.rst @@ -24,7 +24,7 @@ Class used for corner detection using the FAST algorithm. :: // all features have same size static const int FEATURE_SIZE = 7; - explicit FAST_GPU(int threshold, bool nonmaxSupression = true, + explicit FAST_GPU(int threshold, bool nonmaxSuppression = true, double keypointsRatio = 0.05); void operator ()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints); @@ -39,7 +39,7 @@ Class used for corner detection using the FAST algorithm. :: void release(); - bool nonmaxSupression; + bool nonmaxSuppression; int threshold; @@ -61,11 +61,11 @@ gpu::FAST_GPU::FAST_GPU ------------------------------------- Constructor. -.. ocv:function:: gpu::FAST_GPU::FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05) +.. ocv:function:: gpu::FAST_GPU::FAST_GPU(int threshold, bool nonmaxSuppression = true, double keypointsRatio = 0.05) :param threshold: Threshold on difference between intensity of the central pixel and pixels on a circle around this pixel. - :param nonmaxSupression: If it is true, non-maximum suppression is applied to detected corners (keypoints). + :param nonmaxSuppression: If it is true, non-maximum suppression is applied to detected corners (keypoints). :param keypointsRatio: Inner buffer size for keypoints store is determined as (keypointsRatio * image_width * image_height). @@ -115,7 +115,7 @@ Releases inner buffer memory. gpu::FAST_GPU::calcKeyPointsLocation ------------------------------------- -Find keypoints and compute it's response if ``nonmaxSupression`` is true. +Find keypoints and compute it's response if ``nonmaxSuppression`` is true. .. ocv:function:: int gpu::FAST_GPU::calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask) @@ -185,7 +185,7 @@ Class for extracting ORB features and descriptors from an image. :: int descriptorSize() const; void setParams(size_t n_features, const ORB::CommonParams& detector_params); - void setFastParams(int threshold, bool nonmaxSupression = true); + void setFastParams(int threshold, bool nonmaxSuppression = true); void release(); diff --git a/modules/gpu/doc/introduction.rst b/modules/gpu/doc/introduction.rst index eacfd61a8..776ed2fb4 100644 --- a/modules/gpu/doc/introduction.rst +++ b/modules/gpu/doc/introduction.rst @@ -43,7 +43,7 @@ Utilizing Multiple GPUs ----------------------- In the current version, each of the OpenCV GPU algorithms can use only a single GPU. So, to utilize multiple GPUs, you have to manually distribute the work between GPUs. -Switching active devie can be done using :ocv:func:`gpu::setDevice()` function. For more details please read Cuda C Programing Guide. +Switching active devie can be done using :ocv:func:`gpu::setDevice()` function. For more details please read Cuda C Programming Guide. While developing algorithms for multiple GPUs, note a data passing overhead. For primitive functions and small images, it can be significant, which may eliminate all the advantages of having multiple GPUs. But for high-level algorithms, consider using multi-GPU acceleration. For example, the Stereo Block Matching algorithm has been successfully parallelized using the following algorithm: diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index e2fc99b90..0ab0fb1cd 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -733,11 +733,11 @@ CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, Gp int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null()); //! performs per-element multiplication of two full (not packed) Fourier spectrums -//! supports 32FC2 matrixes only (interleaved format) +//! supports 32FC2 matrices only (interleaved format) CV_EXPORTS void mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false, Stream& stream = Stream::Null()); //! performs per-element multiplication of two full (not packed) Fourier spectrums -//! supports 32FC2 matrixes only (interleaved format) +//! supports 32FC2 matrices only (interleaved format) CV_EXPORTS void mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null()); //! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix. @@ -1580,7 +1580,7 @@ public: // all features have same size static const int FEATURE_SIZE = 7; - explicit FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05); + explicit FAST_GPU(int threshold, bool nonmaxSuppression = true, double keypointsRatio = 0.05); //! finds the keypoints using FAST detector //! supports only CV_8UC1 images @@ -1596,19 +1596,19 @@ public: //! release temporary buffer's memory void release(); - bool nonmaxSupression; + bool nonmaxSuppression; int threshold; //! max keypoints = keypointsRatio * img.size().area() double keypointsRatio; - //! find keypoints and compute it's response if nonmaxSupression is true + //! find keypoints and compute it's response if nonmaxSuppression is true //! return count of detected keypoints int calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask); //! get final array of keypoints - //! performs nonmax supression if needed + //! performs nonmax suppression if needed //! return final count of keypoints int getKeyPoints(GpuMat& keypoints); @@ -1670,10 +1670,10 @@ public: //! returns the descriptor size in bytes inline int descriptorSize() const { return kBytes; } - inline void setFastParams(int threshold, bool nonmaxSupression = true) + inline void setFastParams(int threshold, bool nonmaxSuppression = true) { fastDetector_.threshold = threshold; - fastDetector_.nonmaxSupression = nonmaxSupression; + fastDetector_.nonmaxSuppression = nonmaxSuppression; } //! release temporary buffer's memory @@ -2443,7 +2443,7 @@ public: Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0) Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0) Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2) - Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2) + Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) // UYVY (4:2:2) }; enum ChromaFormat @@ -2451,7 +2451,7 @@ public: Monochrome=0, YUV420, YUV422, - YUV444, + YUV444 }; struct FormatInfo diff --git a/modules/gpu/perf/perf_calib3d.cpp b/modules/gpu/perf/perf_calib3d.cpp index 91800649c..4a6740598 100644 --- a/modules/gpu/perf/perf_calib3d.cpp +++ b/modules/gpu/perf/perf_calib3d.cpp @@ -93,7 +93,7 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBM, ////////////////////////////////////////////////////////////////////// // StereoBeliefPropagation -PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, +PERF_TEST_P(ImagePair, DISABLED_Calib3D_StereoBeliefPropagation, Values(pair_string("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png"))) { declare.time(300.0); diff --git a/modules/gpu/perf/perf_core.cpp b/modules/gpu/perf/perf_core.cpp index e38196b99..ae6ed865b 100644 --- a/modules/gpu/perf/perf_core.cpp +++ b/modules/gpu/perf/perf_core.cpp @@ -1303,6 +1303,8 @@ PERF_TEST_P(Sz_3Depth, Core_AddWeighted, ////////////////////////////////////////////////////////////////////// // GEMM +#ifdef HAVE_CUBLAS + CV_FLAGS(GemmFlags, 0, GEMM_1_T, GEMM_2_T, GEMM_3_T) #define ALL_GEMM_FLAGS Values(0, CV_GEMM_A_T, CV_GEMM_B_T, CV_GEMM_C_T, CV_GEMM_A_T | CV_GEMM_B_T, CV_GEMM_A_T | CV_GEMM_C_T, CV_GEMM_A_T | CV_GEMM_B_T | CV_GEMM_C_T) @@ -1351,6 +1353,8 @@ PERF_TEST_P(Sz_Type_Flags, Core_GEMM, } } +#endif + ////////////////////////////////////////////////////////////////////// // Transpose diff --git a/modules/gpu/perf/perf_features2d.cpp b/modules/gpu/perf/perf_features2d.cpp index feee3a939..45823cef2 100644 --- a/modules/gpu/perf/perf_features2d.cpp +++ b/modules/gpu/perf/perf_features2d.cpp @@ -49,9 +49,9 @@ using namespace perf; ////////////////////////////////////////////////////////////////////// // FAST -DEF_PARAM_TEST(Image_Threshold_NonMaxSupression, string, int, bool); +DEF_PARAM_TEST(Image_Threshold_NonMaxSuppression, string, int, bool); -PERF_TEST_P(Image_Threshold_NonMaxSupression, Features2D_FAST, +PERF_TEST_P(Image_Threshold_NonMaxSuppression, Features2D_FAST, Combine(Values("gpu/perf/aloe.png"), Values(20), Bool())) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index d942bed61..01327d2a9 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -50,7 +50,7 @@ using namespace perf; // Remap enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH }; -CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH); +CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH) void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode) { @@ -851,6 +851,8 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, } } +#ifdef HAVE_CUFFT + ////////////////////////////////////////////////////////////////////// // Convolve @@ -941,7 +943,7 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate8U, CPU_SANITY_CHECK(dst); } -}; +} //////////////////////////////////////////////////////////////////////////////// // MatchTemplate32F @@ -981,7 +983,7 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate32F, CPU_SANITY_CHECK(dst); } -}; +} ////////////////////////////////////////////////////////////////////// // MulSpectrums @@ -1085,6 +1087,8 @@ PERF_TEST_P(Sz_Flags, ImgProc_Dft, } } +#endif + ////////////////////////////////////////////////////////////////////// // CornerHarris @@ -1538,7 +1542,7 @@ CV_ENUM(AlphaOp, ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_P DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp); -PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, +PERF_TEST_P(Sz_Type_Op, DISABLED_ImgProc_AlphaComp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC4, CV_16UC4, CV_32SC4, CV_32FC4), AlphaOp::all())) @@ -1559,7 +1563,14 @@ PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op); - GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); + if (CV_MAT_DEPTH(type) < CV_32F) + { + GPU_SANITY_CHECK(dst, 1); + } + else + { + GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); + } } else { @@ -1735,7 +1746,7 @@ PERF_TEST_P(Image, ImgProc_HoughLinesP, const float rho = 1.0f; const float theta = static_cast(CV_PI / 180.0); const int threshold = 100; - const int minLineLenght = 50; + const int minLineLength = 50; const int maxLineGap = 5; const cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE); @@ -1750,7 +1761,7 @@ PERF_TEST_P(Image, ImgProc_HoughLinesP, cv::gpu::GpuMat d_lines; cv::gpu::HoughLinesBuf d_buf; - TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); + TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLength, maxLineGap); cv::Mat gpu_lines(d_lines); cv::Vec4i* begin = gpu_lines.ptr(); @@ -1762,7 +1773,7 @@ PERF_TEST_P(Image, ImgProc_HoughLinesP, { std::vector cpu_lines; - TEST_CYCLE() cv::HoughLinesP(mask, cpu_lines, rho, theta, threshold, minLineLenght, maxLineGap); + TEST_CYCLE() cv::HoughLinesP(mask, cpu_lines, rho, theta, threshold, minLineLength, maxLineGap); SANITY_CHECK(cpu_lines); } @@ -1821,11 +1832,13 @@ PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles, ////////////////////////////////////////////////////////////////////// // GeneralizedHough -CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION); +#if !defined(__GNUC__) || (__GNUC__ * 10 + __GNUC_MINOR__ != 47) + +CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION) DEF_PARAM_TEST(Method_Sz, GHMethod, cv::Size); -PERF_TEST_P(Method_Sz, ImgProc_GeneralizedHough, +PERF_TEST_P(Method_Sz, DISABLED_ImgProc_GeneralizedHough, Combine(Values(GHMethod(cv::GHT_POSITION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE), GHMethod(cv::GHT_POSITION | cv::GHT_ROTATION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE | cv::GHT_ROTATION)), GPU_TYPICAL_MAT_SIZES)) { @@ -1907,3 +1920,5 @@ PERF_TEST_P(Method_Sz, ImgProc_GeneralizedHough, CPU_SANITY_CHECK(positions); } } + +#endif diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index 6e9fda605..6c7a64822 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -500,7 +500,7 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowBM, } } -PERF_TEST_P(ImagePair, Video_FastOpticalFlowBM, +PERF_TEST_P(ImagePair, DISABLED_Video_FastOpticalFlowBM, Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) { declare.time(400); diff --git a/modules/gpu/perf4au/main.cpp b/modules/gpu/perf4au/main.cpp index 8c68385e1..ceee61e1d 100644 --- a/modules/gpu/perf4au/main.cpp +++ b/modules/gpu/perf4au/main.cpp @@ -74,7 +74,7 @@ PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg")) const float rho = 1.f; const float theta = 1.f; const int threshold = 40; - const int minLineLenght = 20; + const int minLineLength = 20; const int maxLineGap = 5; cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE); @@ -85,11 +85,11 @@ PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg")) cv::gpu::GpuMat d_lines; cv::gpu::HoughLinesBuf d_buf; - cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); + cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLength, maxLineGap); TEST_CYCLE() { - cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); + cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLength, maxLineGap); } } else @@ -98,11 +98,11 @@ PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg")) cv::Canny(image, mask, 50, 100); std::vector lines; - cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLenght, maxLineGap); + cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLength, maxLineGap); TEST_CYCLE() { - cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLenght, maxLineGap); + cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLength, maxLineGap); } } diff --git a/modules/gpu/src/cascadeclassifier.cpp b/modules/gpu/src/cascadeclassifier.cpp index 7b95b6909..65b74a433 100644 --- a/modules/gpu/src/cascadeclassifier.cpp +++ b/modules/gpu/src/cascadeclassifier.cpp @@ -778,8 +778,6 @@ NCVStatus loadFromXML(const std::string &filename, haar.bNeedsTiltedII = false; Ncv32u curMaxTreeDepth; - std::vector xmlFileCont; - std::vector h_TmpClassifierNotRootNodes; haarStages.resize(0); haarClassifierNodes.resize(0); diff --git a/modules/gpu/src/cuda/bgfg_mog.cu b/modules/gpu/src/cuda/bgfg_mog.cu index 89ad5ff0b..055c9e041 100644 --- a/modules/gpu/src/cuda/bgfg_mog.cu +++ b/modules/gpu/src/cuda/bgfg_mog.cu @@ -489,7 +489,7 @@ namespace cv { namespace gpu { namespace device { //need only weight if fit is found float weight = alpha1 * gmm_weight(mode * frame.rows + y, x) + prune; - + int swap_count = 0; //fit not found yet if (!fitsPDF) { @@ -540,6 +540,7 @@ namespace cv { namespace gpu { namespace device if (weight < gmm_weight((i - 1) * frame.rows + y, x)) break; + swap_count++; //swap one up swap(gmm_weight, x, y, i - 1, frame.rows); swap(gmm_variance, x, y, i - 1, frame.rows); @@ -557,7 +558,7 @@ namespace cv { namespace gpu { namespace device nmodes--; } - gmm_weight(mode * frame.rows + y, x) = weight; //update weight by the calculated value + gmm_weight((mode - swap_count) * frame.rows + y, x) = weight; //update weight by the calculated value totalWeight += weight; } diff --git a/modules/gpu/src/cuda/build_point_list.cu b/modules/gpu/src/cuda/build_point_list.cu new file mode 100644 index 000000000..8a9c73b3f --- /dev/null +++ b/modules/gpu/src/cuda/build_point_list.cu @@ -0,0 +1,138 @@ +/*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*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + template + __global__ void buildPointList(const PtrStepSzb src, unsigned int* list) + { + __shared__ unsigned int s_queues[4][32 * PIXELS_PER_THREAD]; + __shared__ int s_qsize[4]; + __shared__ int s_globStart[4]; + + const int x = blockIdx.x * blockDim.x * PIXELS_PER_THREAD + threadIdx.x; + const int y = blockIdx.y * blockDim.y + threadIdx.y; + + if (threadIdx.x == 0) + s_qsize[threadIdx.y] = 0; + __syncthreads(); + + if (y < src.rows) + { + // fill the queue + const uchar* srcRow = src.ptr(y); + for (int i = 0, xx = x; i < PIXELS_PER_THREAD && xx < src.cols; ++i, xx += blockDim.x) + { + if (srcRow[xx]) + { + const unsigned int val = (y << 16) | xx; + const int qidx = Emulation::smem::atomicAdd(&s_qsize[threadIdx.y], 1); + s_queues[threadIdx.y][qidx] = val; + } + } + } + + __syncthreads(); + + // let one thread reserve the space required in the global list + if (threadIdx.x == 0 && threadIdx.y == 0) + { + // find how many items are stored in each list + int totalSize = 0; + for (int i = 0; i < blockDim.y; ++i) + { + s_globStart[i] = totalSize; + totalSize += s_qsize[i]; + } + + // calculate the offset in the global list + const int globalOffset = atomicAdd(&g_counter, totalSize); + for (int i = 0; i < blockDim.y; ++i) + s_globStart[i] += globalOffset; + } + + __syncthreads(); + + // copy local queues to global queue + const int qsize = s_qsize[threadIdx.y]; + int gidx = s_globStart[threadIdx.y] + threadIdx.x; + for(int i = threadIdx.x; i < qsize; i += blockDim.x, gidx += blockDim.x) + list[gidx] = s_queues[threadIdx.y][i]; + } + + int buildPointList_gpu(PtrStepSzb src, unsigned int* list) + { + const int PIXELS_PER_THREAD = 16; + + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 4); + const dim3 grid(divUp(src.cols, block.x * PIXELS_PER_THREAD), divUp(src.rows, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(buildPointList, cudaFuncCachePreferShared) ); + + buildPointList<<>>(src, list); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + return totalCount; + } + } +}}} + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/canny.cu b/modules/gpu/src/cuda/canny.cu index aab922f22..468eec417 100644 --- a/modules/gpu/src/cuda/canny.cu +++ b/modules/gpu/src/cuda/canny.cu @@ -42,8 +42,6 @@ #if !defined CUDA_DISABLER -#include -#include //std::swap #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/emulation.hpp" #include "opencv2/gpu/device/transform.hpp" @@ -239,30 +237,35 @@ namespace canny { __device__ int counter = 0; - __global__ void edgesHysteresisLocalKernel(PtrStepSzi map, ushort2* st) + __device__ __forceinline__ bool checkIdx(int y, int x, int rows, int cols) + { + return (y >= 0) && (y < rows) && (x >= 0) && (x < cols); + } + + __global__ void edgesHysteresisLocalKernel(PtrStepSzi map, short2* st) { __shared__ volatile int smem[18][18]; const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; - smem[threadIdx.y + 1][threadIdx.x + 1] = x < map.cols && y < map.rows ? map(y, x) : 0; + smem[threadIdx.y + 1][threadIdx.x + 1] = checkIdx(y, x, map.rows, map.cols) ? map(y, x) : 0; if (threadIdx.y == 0) - smem[0][threadIdx.x + 1] = y > 0 ? map(y - 1, x) : 0; + smem[0][threadIdx.x + 1] = checkIdx(y - 1, x, map.rows, map.cols) ? map(y - 1, x) : 0; if (threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][threadIdx.x + 1] = y + 1 < map.rows ? map(y + 1, x) : 0; + smem[blockDim.y + 1][threadIdx.x + 1] = checkIdx(y + 1, x, map.rows, map.cols) ? map(y + 1, x) : 0; if (threadIdx.x == 0) - smem[threadIdx.y + 1][0] = x > 0 ? map(y, x - 1) : 0; + smem[threadIdx.y + 1][0] = checkIdx(y, x - 1, map.rows, map.cols) ? map(y, x - 1) : 0; if (threadIdx.x == blockDim.x - 1) - smem[threadIdx.y + 1][blockDim.x + 1] = x + 1 < map.cols ? map(y, x + 1) : 0; + smem[threadIdx.y + 1][blockDim.x + 1] = checkIdx(y, x + 1, map.rows, map.cols) ? map(y, x + 1) : 0; if (threadIdx.x == 0 && threadIdx.y == 0) - smem[0][0] = y > 0 && x > 0 ? map(y - 1, x - 1) : 0; + smem[0][0] = checkIdx(y - 1, x - 1, map.rows, map.cols) ? map(y - 1, x - 1) : 0; if (threadIdx.x == blockDim.x - 1 && threadIdx.y == 0) - smem[0][blockDim.x + 1] = y > 0 && x + 1 < map.cols ? map(y - 1, x + 1) : 0; + smem[0][blockDim.x + 1] = checkIdx(y - 1, x + 1, map.rows, map.cols) ? map(y - 1, x + 1) : 0; if (threadIdx.x == 0 && threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][0] = y + 1 < map.rows && x > 0 ? map(y + 1, x - 1) : 0; + smem[blockDim.y + 1][0] = checkIdx(y + 1, x - 1, map.rows, map.cols) ? map(y + 1, x - 1) : 0; if (threadIdx.x == blockDim.x - 1 && threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][blockDim.x + 1] = y + 1 < map.rows && x + 1 < map.cols ? map(y + 1, x + 1) : 0; + smem[blockDim.y + 1][blockDim.x + 1] = checkIdx(y + 1, x + 1, map.rows, map.cols) ? map(y + 1, x + 1) : 0; __syncthreads(); @@ -290,8 +293,12 @@ namespace canny n += smem[threadIdx.y + 2][threadIdx.x + 2] == 2; } + __syncthreads(); + if (n > 0) smem[threadIdx.y + 1][threadIdx.x + 1] = 2; + + __syncthreads(); } const int e = smem[threadIdx.y + 1][threadIdx.x + 1]; @@ -317,11 +324,11 @@ namespace canny if (n > 0) { const int ind = ::atomicAdd(&counter, 1); - st[ind] = make_ushort2(x, y); + st[ind] = make_short2(x, y); } } - void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1) + void edgesHysteresisLocal(PtrStepSzi map, short2* st1) { void* counter_ptr; cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, counter) ); @@ -345,13 +352,13 @@ namespace canny __constant__ int c_dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; __constant__ int c_dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; - __global__ void edgesHysteresisGlobalKernel(PtrStepSzi map, ushort2* st1, ushort2* st2, const int count) + __global__ void edgesHysteresisGlobalKernel(PtrStepSzi map, short2* st1, short2* st2, const int count) { const int stack_size = 512; __shared__ int s_counter; __shared__ int s_ind; - __shared__ ushort2 s_st[stack_size]; + __shared__ short2 s_st[stack_size]; if (threadIdx.x == 0) s_counter = 0; @@ -363,14 +370,14 @@ namespace canny if (ind >= count) return; - ushort2 pos = st1[ind]; + short2 pos = st1[ind]; if (threadIdx.x < 8) { pos.x += c_dx[threadIdx.x]; pos.y += c_dy[threadIdx.x]; - if (pos.x > 0 && pos.x < map.cols && pos.y > 0 && pos.y < map.rows && map(pos.y, pos.x) == 1) + if (pos.x > 0 && pos.x < map.cols - 1 && pos.y > 0 && pos.y < map.rows - 1 && map(pos.y, pos.x) == 1) { map(pos.y, pos.x) = 2; @@ -402,7 +409,7 @@ namespace canny pos.x += c_dx[threadIdx.x & 7]; pos.y += c_dy[threadIdx.x & 7]; - if (pos.x > 0 && pos.x < map.cols && pos.y > 0 && pos.y < map.rows && map(pos.y, pos.x) == 1) + if (pos.x > 0 && pos.x < map.cols - 1 && pos.y > 0 && pos.y < map.rows - 1 && map(pos.y, pos.x) == 1) { map(pos.y, pos.x) = 2; @@ -419,8 +426,10 @@ namespace canny { if (threadIdx.x == 0) { - ind = ::atomicAdd(&counter, s_counter); - s_ind = ind - s_counter; + s_ind = ::atomicAdd(&counter, s_counter); + + if (s_ind + s_counter > map.cols * map.rows) + s_counter = 0; } __syncthreads(); @@ -432,7 +441,7 @@ namespace canny } } - void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2) + void edgesHysteresisGlobal(PtrStepSzi map, short2* st1, short2* st2) { void* counter_ptr; cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, canny::counter) ); @@ -454,7 +463,12 @@ namespace canny cudaSafeCall( cudaMemcpy(&count, counter_ptr, sizeof(int), cudaMemcpyDeviceToHost) ); - std::swap(st1, st2); + count = min(count, map.cols * map.rows); + + //std::swap(st1, st2); + short2* tmp = st1; + st1 = st2; + st2 = tmp; } } } diff --git a/modules/gpu/src/cuda/fast.cu b/modules/gpu/src/cuda/fast.cu index 9bf1f7ad9..f72b1fc04 100644 --- a/modules/gpu/src/cuda/fast.cu +++ b/modules/gpu/src/cuda/fast.cu @@ -318,9 +318,9 @@ namespace cv { namespace gpu { namespace device } /////////////////////////////////////////////////////////////////////////// - // nonmaxSupression + // nonmaxSuppression - __global__ void nonmaxSupression(const short2* kpLoc, int count, const PtrStepSzi scoreMat, short2* locFinal, float* responseFinal) + __global__ void nonmaxSuppression(const short2* kpLoc, int count, const PtrStepSzi scoreMat, short2* locFinal, float* responseFinal) { #if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 110) @@ -356,7 +356,7 @@ namespace cv { namespace gpu { namespace device #endif } - int nonmaxSupression_gpu(const short2* kpLoc, int count, PtrStepSzi score, short2* loc, float* response) + int nonmaxSuppression_gpu(const short2* kpLoc, int count, PtrStepSzi score, short2* loc, float* response) { void* counter_ptr; cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, g_counter) ); @@ -368,7 +368,7 @@ namespace cv { namespace gpu { namespace device cudaSafeCall( cudaMemset(counter_ptr, 0, sizeof(unsigned int)) ); - nonmaxSupression<<>>(kpLoc, count, score, loc, response); + nonmaxSuppression<<>>(kpLoc, count, score, loc, response); cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaDeviceSynchronize() ); diff --git a/modules/gpu/src/cuda/hough.cu b/modules/gpu/src/cuda/generalized_hough.cu similarity index 65% rename from modules/gpu/src/cuda/hough.cu rename to modules/gpu/src/cuda/generalized_hough.cu index 59eba2608..b07ef0f6b 100644 --- a/modules/gpu/src/cuda/hough.cu +++ b/modules/gpu/src/cuda/generalized_hough.cu @@ -40,654 +40,25 @@ // //M*/ +#if defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ == 47) +# define CUDA_DISABLER +#endif + #if !defined CUDA_DISABLER #include -#include +#include #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/emulation.hpp" #include "opencv2/gpu/device/vec_math.hpp" #include "opencv2/gpu/device/functional.hpp" -#include "opencv2/gpu/device/limits.hpp" -#include "opencv2/gpu/device/dynamic_smem.hpp" namespace cv { namespace gpu { namespace device { namespace hough { - __device__ int g_counter; - - //////////////////////////////////////////////////////////////////////// - // buildPointList - - template - __global__ void buildPointList(const PtrStepSzb src, unsigned int* list) - { - __shared__ unsigned int s_queues[4][32 * PIXELS_PER_THREAD]; - __shared__ int s_qsize[4]; - __shared__ int s_globStart[4]; - - const int x = blockIdx.x * blockDim.x * PIXELS_PER_THREAD + threadIdx.x; - const int y = blockIdx.y * blockDim.y + threadIdx.y; - - if (threadIdx.x == 0) - s_qsize[threadIdx.y] = 0; - __syncthreads(); - - if (y < src.rows) - { - // fill the queue - const uchar* srcRow = src.ptr(y); - for (int i = 0, xx = x; i < PIXELS_PER_THREAD && xx < src.cols; ++i, xx += blockDim.x) - { - if (srcRow[xx]) - { - const unsigned int val = (y << 16) | xx; - const int qidx = Emulation::smem::atomicAdd(&s_qsize[threadIdx.y], 1); - s_queues[threadIdx.y][qidx] = val; - } - } - } - - __syncthreads(); - - // let one thread reserve the space required in the global list - if (threadIdx.x == 0 && threadIdx.y == 0) - { - // find how many items are stored in each list - int totalSize = 0; - for (int i = 0; i < blockDim.y; ++i) - { - s_globStart[i] = totalSize; - totalSize += s_qsize[i]; - } - - // calculate the offset in the global list - const int globalOffset = atomicAdd(&g_counter, totalSize); - for (int i = 0; i < blockDim.y; ++i) - s_globStart[i] += globalOffset; - } - - __syncthreads(); - - // copy local queues to global queue - const int qsize = s_qsize[threadIdx.y]; - int gidx = s_globStart[threadIdx.y] + threadIdx.x; - for(int i = threadIdx.x; i < qsize; i += blockDim.x, gidx += blockDim.x) - list[gidx] = s_queues[threadIdx.y][i]; - } - - int buildPointList_gpu(PtrStepSzb src, unsigned int* list) - { - const int PIXELS_PER_THREAD = 16; - - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 4); - const dim3 grid(divUp(src.cols, block.x * PIXELS_PER_THREAD), divUp(src.rows, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(buildPointList, cudaFuncCachePreferShared) ); - - buildPointList<<>>(src, list); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // linesAccum - - __global__ void linesAccumGlobal(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) - { - const int n = blockIdx.x; - const float ang = n * theta; - - float sinVal; - float cosVal; - sincosf(ang, &sinVal, &cosVal); - sinVal *= irho; - cosVal *= irho; - - const int shift = (numrho - 1) / 2; - - int* accumRow = accum.ptr(n + 1); - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - const unsigned int val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - int r = __float2int_rn(x * cosVal + y * sinVal); - r += shift; - - ::atomicAdd(accumRow + r + 1, 1); - } - } - - __global__ void linesAccumShared(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) - { - int* smem = DynamicSharedMem(); - - for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) - smem[i] = 0; - - __syncthreads(); - - const int n = blockIdx.x; - const float ang = n * theta; - - float sinVal; - float cosVal; - sincosf(ang, &sinVal, &cosVal); - sinVal *= irho; - cosVal *= irho; - - const int shift = (numrho - 1) / 2; - - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - const unsigned int val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - int r = __float2int_rn(x * cosVal + y * sinVal); - r += shift; - - Emulation::smem::atomicAdd(&smem[r + 1], 1); - } - - __syncthreads(); - - int* accumRow = accum.ptr(n + 1); - for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) - accumRow[i] = smem[i]; - } - - void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20) - { - const dim3 block(has20 ? 1024 : 512); - const dim3 grid(accum.rows - 2); - - size_t smemSize = (accum.cols - 1) * sizeof(int); - - if (smemSize < sharedMemPerBlock - 1000) - linesAccumShared<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); - else - linesAccumGlobal<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); - - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - } - - //////////////////////////////////////////////////////////////////////// - // linesGetResult - - __global__ void linesGetResult(const PtrStepSzi accum, float2* out, int* votes, const int maxSize, const float rho, const float theta, const int threshold, const int numrho) - { - const int r = blockIdx.x * blockDim.x + threadIdx.x; - const int n = blockIdx.y * blockDim.y + threadIdx.y; - - if (r >= accum.cols - 2 || n >= accum.rows - 2) - return; - - const int curVotes = accum(n + 1, r + 1); - - if (curVotes > threshold && - curVotes > accum(n + 1, r) && - curVotes >= accum(n + 1, r + 2) && - curVotes > accum(n, r + 1) && - curVotes >= accum(n + 2, r + 1)) - { - const float radius = (r - (numrho - 1) * 0.5f) * rho; - const float angle = n * theta; - - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - { - out[ind] = make_float2(radius, angle); - votes[ind] = curVotes; - } - } - } - - int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(linesGetResult, cudaFuncCachePreferL1) ); - - linesGetResult<<>>(accum, out, votes, maxSize, rho, theta, threshold, accum.cols - 2); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxSize); - - if (doSort && totalCount > 0) - { - thrust::device_ptr outPtr(out); - thrust::device_ptr votesPtr(votes); - thrust::sort_by_key(votesPtr, votesPtr + totalCount, outPtr, thrust::greater()); - } - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // houghLinesProbabilistic - - texture tex_mask(false, cudaFilterModePoint, cudaAddressModeClamp); - - __global__ void houghLinesProbabilistic(const PtrStepSzi accum, - int4* out, const int maxSize, - const float rho, const float theta, - const int lineGap, const int lineLength, - const int rows, const int cols) - { - const int r = blockIdx.x * blockDim.x + threadIdx.x; - const int n = blockIdx.y * blockDim.y + threadIdx.y; - - if (r >= accum.cols - 2 || n >= accum.rows - 2) - return; - - const int curVotes = accum(n + 1, r + 1); - - if (curVotes >= lineLength && - curVotes > accum(n, r) && - curVotes > accum(n, r + 1) && - curVotes > accum(n, r + 2) && - curVotes > accum(n + 1, r) && - curVotes > accum(n + 1, r + 2) && - curVotes > accum(n + 2, r) && - curVotes > accum(n + 2, r + 1) && - curVotes > accum(n + 2, r + 2)) - { - const float radius = (r - (accum.cols - 2 - 1) * 0.5f) * rho; - const float angle = n * theta; - - float cosa; - float sina; - sincosf(angle, &sina, &cosa); - - float2 p0 = make_float2(cosa * radius, sina * radius); - float2 dir = make_float2(-sina, cosa); - - float2 pb[4] = {make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1)}; - float a; - - if (dir.x != 0) - { - a = -p0.x / dir.x; - pb[0].x = 0; - pb[0].y = p0.y + a * dir.y; - - a = (cols - 1 - p0.x) / dir.x; - pb[1].x = cols - 1; - pb[1].y = p0.y + a * dir.y; - } - if (dir.y != 0) - { - a = -p0.y / dir.y; - pb[2].x = p0.x + a * dir.x; - pb[2].y = 0; - - a = (rows - 1 - p0.y) / dir.y; - pb[3].x = p0.x + a * dir.x; - pb[3].y = rows - 1; - } - - if (pb[0].x == 0 && (pb[0].y >= 0 && pb[0].y < rows)) - { - p0 = pb[0]; - if (dir.x < 0) - dir = -dir; - } - else if (pb[1].x == cols - 1 && (pb[0].y >= 0 && pb[0].y < rows)) - { - p0 = pb[1]; - if (dir.x > 0) - dir = -dir; - } - else if (pb[2].y == 0 && (pb[2].x >= 0 && pb[2].x < cols)) - { - p0 = pb[2]; - if (dir.y < 0) - dir = -dir; - } - else if (pb[3].y == rows - 1 && (pb[3].x >= 0 && pb[3].x < cols)) - { - p0 = pb[3]; - if (dir.y > 0) - dir = -dir; - } - - float2 d; - if (::fabsf(dir.x) > ::fabsf(dir.y)) - { - d.x = dir.x > 0 ? 1 : -1; - d.y = dir.y / ::fabsf(dir.x); - } - else - { - d.x = dir.x / ::fabsf(dir.y); - d.y = dir.y > 0 ? 1 : -1; - } - - float2 line_end[2]; - int gap; - bool inLine = false; - - float2 p1 = p0; - if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) - return; - - for (;;) - { - if (tex2D(tex_mask, p1.x, p1.y)) - { - gap = 0; - - if (!inLine) - { - line_end[0] = p1; - line_end[1] = p1; - inLine = true; - } - else - { - line_end[1] = p1; - } - } - else if (inLine) - { - if (++gap > lineGap) - { - bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || - ::abs(line_end[1].y - line_end[0].y) >= lineLength; - - if (good_line) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); - } - - gap = 0; - inLine = false; - } - } - - p1 = p1 + d; - if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) - { - if (inLine) - { - bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || - ::abs(line_end[1].y - line_end[0].y) >= lineLength; - - if (good_line) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); - } - - } - break; - } - } - } - } - - int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - bindTexture(&tex_mask, mask); - - houghLinesProbabilistic<<>>(accum, - out, maxSize, - rho, theta, - lineGap, lineLength, - mask.rows, mask.cols); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxSize); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // circlesAccumCenters - - __global__ void circlesAccumCenters(const unsigned int* list, const int count, const PtrStepi dx, const PtrStepi dy, - PtrStepi accum, const int width, const int height, const int minRadius, const int maxRadius, const float idp) - { - const int SHIFT = 10; - const int ONE = 1 << SHIFT; - - const int tid = blockIdx.x * blockDim.x + threadIdx.x; - - if (tid >= count) - return; - - const unsigned int val = list[tid]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - const int vx = dx(y, x); - const int vy = dy(y, x); - - if (vx == 0 && vy == 0) - return; - - const float mag = ::sqrtf(vx * vx + vy * vy); - - const int x0 = __float2int_rn((x * idp) * ONE); - const int y0 = __float2int_rn((y * idp) * ONE); - - int sx = __float2int_rn((vx * idp) * ONE / mag); - int sy = __float2int_rn((vy * idp) * ONE / mag); - - // Step from minRadius to maxRadius in both directions of the gradient - for (int k1 = 0; k1 < 2; ++k1) - { - int x1 = x0 + minRadius * sx; - int y1 = y0 + minRadius * sy; - - for (int r = minRadius; r <= maxRadius; x1 += sx, y1 += sy, ++r) - { - const int x2 = x1 >> SHIFT; - const int y2 = y1 >> SHIFT; - - if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) - break; - - ::atomicAdd(accum.ptr(y2 + 1) + x2 + 1, 1); - } - - sx = -sx; - sy = -sy; - } - } - - void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp) - { - const dim3 block(256); - const dim3 grid(divUp(count, block.x)); - - cudaSafeCall( cudaFuncSetCacheConfig(circlesAccumCenters, cudaFuncCachePreferL1) ); - - circlesAccumCenters<<>>(list, count, dx, dy, accum, accum.cols - 2, accum.rows - 2, minRadius, maxRadius, idp); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - } - - //////////////////////////////////////////////////////////////////////// - // buildCentersList - - __global__ void buildCentersList(const PtrStepSzi accum, unsigned int* centers, const int threshold) - { - const int x = blockIdx.x * blockDim.x + threadIdx.x; - const int y = blockIdx.y * blockDim.y + threadIdx.y; - - if (x < accum.cols - 2 && y < accum.rows - 2) - { - const int top = accum(y, x + 1); - - const int left = accum(y + 1, x); - const int cur = accum(y + 1, x + 1); - const int right = accum(y + 1, x + 2); - - const int bottom = accum(y + 2, x + 1); - - if (cur > threshold && cur > top && cur >= bottom && cur > left && cur >= right) - { - const unsigned int val = (y << 16) | x; - const int idx = ::atomicAdd(&g_counter, 1); - centers[idx] = val; - } - } - } - - int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(buildCentersList, cudaFuncCachePreferL1) ); - - buildCentersList<<>>(accum, centers, threshold); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // circlesAccumRadius - - __global__ void circlesAccumRadius(const unsigned int* centers, const unsigned int* list, const int count, - float3* circles, const int maxCircles, const float dp, - const int minRadius, const int maxRadius, const int histSize, const int threshold) - { - int* smem = DynamicSharedMem(); - - for (int i = threadIdx.x; i < histSize + 2; i += blockDim.x) - smem[i] = 0; - __syncthreads(); - - unsigned int val = centers[blockIdx.x]; - - float cx = (val & 0xFFFF); - float cy = (val >> 16) & 0xFFFF; - - cx = (cx + 0.5f) * dp; - cy = (cy + 0.5f) * dp; - - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - const float rad = ::sqrtf((cx - x) * (cx - x) + (cy - y) * (cy - y)); - if (rad >= minRadius && rad <= maxRadius) - { - const int r = __float2int_rn(rad - minRadius); - - Emulation::smem::atomicAdd(&smem[r + 1], 1); - } - } - - __syncthreads(); - - for (int i = threadIdx.x; i < histSize; i += blockDim.x) - { - const int curVotes = smem[i + 1]; - - if (curVotes >= threshold && curVotes > smem[i] && curVotes >= smem[i + 2]) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxCircles) - circles[ind] = make_float3(cx, cy, i + minRadius); - } - } - } - - int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, - float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(has20 ? 1024 : 512); - const dim3 grid(centersCount); - - const int histSize = maxRadius - minRadius + 1; - size_t smemSize = (histSize + 2) * sizeof(int); - - circlesAccumRadius<<>>(centers, list, count, circles, maxCircles, dp, minRadius, maxRadius, histSize, threshold); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxCircles); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // Generalized Hough + __device__ static int g_counter; template __global__ void buildEdgePointList(const PtrStepSzb edges, const PtrStep dx, const PtrStep dy, unsigned int* coordList, float* thetaList) @@ -1706,5 +1077,4 @@ namespace cv { namespace gpu { namespace device } }}} - #endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_circles.cu b/modules/gpu/src/cuda/hough_circles.cu new file mode 100644 index 000000000..5df7887b0 --- /dev/null +++ b/modules/gpu/src/cuda/hough_circles.cu @@ -0,0 +1,254 @@ +/*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*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" +#include "opencv2/gpu/device/dynamic_smem.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + //////////////////////////////////////////////////////////////////////// + // circlesAccumCenters + + __global__ void circlesAccumCenters(const unsigned int* list, const int count, const PtrStepi dx, const PtrStepi dy, + PtrStepi accum, const int width, const int height, const int minRadius, const int maxRadius, const float idp) + { + const int SHIFT = 10; + const int ONE = 1 << SHIFT; + + const int tid = blockIdx.x * blockDim.x + threadIdx.x; + + if (tid >= count) + return; + + const unsigned int val = list[tid]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + const int vx = dx(y, x); + const int vy = dy(y, x); + + if (vx == 0 && vy == 0) + return; + + const float mag = ::sqrtf(vx * vx + vy * vy); + + const int x0 = __float2int_rn((x * idp) * ONE); + const int y0 = __float2int_rn((y * idp) * ONE); + + int sx = __float2int_rn((vx * idp) * ONE / mag); + int sy = __float2int_rn((vy * idp) * ONE / mag); + + // Step from minRadius to maxRadius in both directions of the gradient + for (int k1 = 0; k1 < 2; ++k1) + { + int x1 = x0 + minRadius * sx; + int y1 = y0 + minRadius * sy; + + for (int r = minRadius; r <= maxRadius; x1 += sx, y1 += sy, ++r) + { + const int x2 = x1 >> SHIFT; + const int y2 = y1 >> SHIFT; + + if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) + break; + + ::atomicAdd(accum.ptr(y2 + 1) + x2 + 1, 1); + } + + sx = -sx; + sy = -sy; + } + } + + void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp) + { + const dim3 block(256); + const dim3 grid(divUp(count, block.x)); + + cudaSafeCall( cudaFuncSetCacheConfig(circlesAccumCenters, cudaFuncCachePreferL1) ); + + circlesAccumCenters<<>>(list, count, dx, dy, accum, accum.cols - 2, accum.rows - 2, minRadius, maxRadius, idp); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + } + + //////////////////////////////////////////////////////////////////////// + // buildCentersList + + __global__ void buildCentersList(const PtrStepSzi accum, unsigned int* centers, const int threshold) + { + const int x = blockIdx.x * blockDim.x + threadIdx.x; + const int y = blockIdx.y * blockDim.y + threadIdx.y; + + if (x < accum.cols - 2 && y < accum.rows - 2) + { + const int top = accum(y, x + 1); + + const int left = accum(y + 1, x); + const int cur = accum(y + 1, x + 1); + const int right = accum(y + 1, x + 2); + + const int bottom = accum(y + 2, x + 1); + + if (cur > threshold && cur > top && cur >= bottom && cur > left && cur >= right) + { + const unsigned int val = (y << 16) | x; + const int idx = ::atomicAdd(&g_counter, 1); + centers[idx] = val; + } + } + } + + int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(buildCentersList, cudaFuncCachePreferL1) ); + + buildCentersList<<>>(accum, centers, threshold); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + return totalCount; + } + + //////////////////////////////////////////////////////////////////////// + // circlesAccumRadius + + __global__ void circlesAccumRadius(const unsigned int* centers, const unsigned int* list, const int count, + float3* circles, const int maxCircles, const float dp, + const int minRadius, const int maxRadius, const int histSize, const int threshold) + { + int* smem = DynamicSharedMem(); + + for (int i = threadIdx.x; i < histSize + 2; i += blockDim.x) + smem[i] = 0; + __syncthreads(); + + unsigned int val = centers[blockIdx.x]; + + float cx = (val & 0xFFFF); + float cy = (val >> 16) & 0xFFFF; + + cx = (cx + 0.5f) * dp; + cy = (cy + 0.5f) * dp; + + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + const float rad = ::sqrtf((cx - x) * (cx - x) + (cy - y) * (cy - y)); + if (rad >= minRadius && rad <= maxRadius) + { + const int r = __float2int_rn(rad - minRadius); + + Emulation::smem::atomicAdd(&smem[r + 1], 1); + } + } + + __syncthreads(); + + for (int i = threadIdx.x; i < histSize; i += blockDim.x) + { + const int curVotes = smem[i + 1]; + + if (curVotes >= threshold && curVotes > smem[i] && curVotes >= smem[i + 2]) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxCircles) + circles[ind] = make_float3(cx, cy, i + minRadius); + } + } + } + + int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, + float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(has20 ? 1024 : 512); + const dim3 grid(centersCount); + + const int histSize = maxRadius - minRadius + 1; + size_t smemSize = (histSize + 2) * sizeof(int); + + circlesAccumRadius<<>>(centers, list, count, circles, maxCircles, dp, minRadius, maxRadius, histSize, threshold); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxCircles); + + return totalCount; + } + } +}}} + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_lines.cu b/modules/gpu/src/cuda/hough_lines.cu new file mode 100644 index 000000000..2f2fe9a7e --- /dev/null +++ b/modules/gpu/src/cuda/hough_lines.cu @@ -0,0 +1,212 @@ +/*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*/ + +#if !defined CUDA_DISABLER + +#include +#include + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" +#include "opencv2/gpu/device/dynamic_smem.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + //////////////////////////////////////////////////////////////////////// + // linesAccum + + __global__ void linesAccumGlobal(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) + { + const int n = blockIdx.x; + const float ang = n * theta; + + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; + + const int shift = (numrho - 1) / 2; + + int* accumRow = accum.ptr(n + 1); + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + const unsigned int val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; + + ::atomicAdd(accumRow + r + 1, 1); + } + } + + __global__ void linesAccumShared(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) + { + int* smem = DynamicSharedMem(); + + for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) + smem[i] = 0; + + __syncthreads(); + + const int n = blockIdx.x; + const float ang = n * theta; + + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; + + const int shift = (numrho - 1) / 2; + + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + const unsigned int val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; + + Emulation::smem::atomicAdd(&smem[r + 1], 1); + } + + __syncthreads(); + + int* accumRow = accum.ptr(n + 1); + for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) + accumRow[i] = smem[i]; + } + + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20) + { + const dim3 block(has20 ? 1024 : 512); + const dim3 grid(accum.rows - 2); + + size_t smemSize = (accum.cols - 1) * sizeof(int); + + if (smemSize < sharedMemPerBlock - 1000) + linesAccumShared<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); + else + linesAccumGlobal<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); + + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + } + + //////////////////////////////////////////////////////////////////////// + // linesGetResult + + __global__ void linesGetResult(const PtrStepSzi accum, float2* out, int* votes, const int maxSize, const float rho, const float theta, const int threshold, const int numrho) + { + const int r = blockIdx.x * blockDim.x + threadIdx.x; + const int n = blockIdx.y * blockDim.y + threadIdx.y; + + if (r >= accum.cols - 2 || n >= accum.rows - 2) + return; + + const int curVotes = accum(n + 1, r + 1); + + if (curVotes > threshold && + curVotes > accum(n + 1, r) && + curVotes >= accum(n + 1, r + 2) && + curVotes > accum(n, r + 1) && + curVotes >= accum(n + 2, r + 1)) + { + const float radius = (r - (numrho - 1) * 0.5f) * rho; + const float angle = n * theta; + + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + { + out[ind] = make_float2(radius, angle); + votes[ind] = curVotes; + } + } + } + + int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(linesGetResult, cudaFuncCachePreferL1) ); + + linesGetResult<<>>(accum, out, votes, maxSize, rho, theta, threshold, accum.cols - 2); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxSize); + + if (doSort && totalCount > 0) + { + thrust::device_ptr outPtr(out); + thrust::device_ptr votesPtr(votes); + thrust::sort_by_key(votesPtr, votesPtr + totalCount, outPtr, thrust::greater()); + } + + return totalCount; + } + } +}}} + + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_segments.cu b/modules/gpu/src/cuda/hough_segments.cu new file mode 100644 index 000000000..f55bb4de9 --- /dev/null +++ b/modules/gpu/src/cuda/hough_segments.cu @@ -0,0 +1,249 @@ +/*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*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/vec_math.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ int g_counter; + + texture tex_mask(false, cudaFilterModePoint, cudaAddressModeClamp); + + __global__ void houghLinesProbabilistic(const PtrStepSzi accum, + int4* out, const int maxSize, + const float rho, const float theta, + const int lineGap, const int lineLength, + const int rows, const int cols) + { + const int r = blockIdx.x * blockDim.x + threadIdx.x; + const int n = blockIdx.y * blockDim.y + threadIdx.y; + + if (r >= accum.cols - 2 || n >= accum.rows - 2) + return; + + const int curVotes = accum(n + 1, r + 1); + + if (curVotes >= lineLength && + curVotes > accum(n, r) && + curVotes > accum(n, r + 1) && + curVotes > accum(n, r + 2) && + curVotes > accum(n + 1, r) && + curVotes > accum(n + 1, r + 2) && + curVotes > accum(n + 2, r) && + curVotes > accum(n + 2, r + 1) && + curVotes > accum(n + 2, r + 2)) + { + const float radius = (r - (accum.cols - 2 - 1) * 0.5f) * rho; + const float angle = n * theta; + + float cosa; + float sina; + sincosf(angle, &sina, &cosa); + + float2 p0 = make_float2(cosa * radius, sina * radius); + float2 dir = make_float2(-sina, cosa); + + float2 pb[4] = {make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1)}; + float a; + + if (dir.x != 0) + { + a = -p0.x / dir.x; + pb[0].x = 0; + pb[0].y = p0.y + a * dir.y; + + a = (cols - 1 - p0.x) / dir.x; + pb[1].x = cols - 1; + pb[1].y = p0.y + a * dir.y; + } + if (dir.y != 0) + { + a = -p0.y / dir.y; + pb[2].x = p0.x + a * dir.x; + pb[2].y = 0; + + a = (rows - 1 - p0.y) / dir.y; + pb[3].x = p0.x + a * dir.x; + pb[3].y = rows - 1; + } + + if (pb[0].x == 0 && (pb[0].y >= 0 && pb[0].y < rows)) + { + p0 = pb[0]; + if (dir.x < 0) + dir = -dir; + } + else if (pb[1].x == cols - 1 && (pb[0].y >= 0 && pb[0].y < rows)) + { + p0 = pb[1]; + if (dir.x > 0) + dir = -dir; + } + else if (pb[2].y == 0 && (pb[2].x >= 0 && pb[2].x < cols)) + { + p0 = pb[2]; + if (dir.y < 0) + dir = -dir; + } + else if (pb[3].y == rows - 1 && (pb[3].x >= 0 && pb[3].x < cols)) + { + p0 = pb[3]; + if (dir.y > 0) + dir = -dir; + } + + float2 d; + if (::fabsf(dir.x) > ::fabsf(dir.y)) + { + d.x = dir.x > 0 ? 1 : -1; + d.y = dir.y / ::fabsf(dir.x); + } + else + { + d.x = dir.x / ::fabsf(dir.y); + d.y = dir.y > 0 ? 1 : -1; + } + + float2 line_end[2]; + int gap; + bool inLine = false; + + float2 p1 = p0; + if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) + return; + + for (;;) + { + if (tex2D(tex_mask, p1.x, p1.y)) + { + gap = 0; + + if (!inLine) + { + line_end[0] = p1; + line_end[1] = p1; + inLine = true; + } + else + { + line_end[1] = p1; + } + } + else if (inLine) + { + if (++gap > lineGap) + { + bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || + ::abs(line_end[1].y - line_end[0].y) >= lineLength; + + if (good_line) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); + } + + gap = 0; + inLine = false; + } + } + + p1 = p1 + d; + if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) + { + if (inLine) + { + bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || + ::abs(line_end[1].y - line_end[0].y) >= lineLength; + + if (good_line) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); + } + + } + break; + } + } + } + } + + int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + bindTexture(&tex_mask, mask); + + houghLinesProbabilistic<<>>(accum, + out, maxSize, + rho, theta, + lineGap, lineLength, + mask.rows, mask.cols); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxSize); + + return totalCount; + } + } +}}} + + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/nlm.cu b/modules/gpu/src/cuda/nlm.cu index 922cba7e5..8789a4cf6 100644 --- a/modules/gpu/src/cuda/nlm.cu +++ b/modules/gpu/src/cuda/nlm.cu @@ -266,7 +266,7 @@ namespace cv { namespace gpu { namespace device __device__ __forceinline__ int calcDist(const uchar2& a, const uchar2& b) { return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y); } __device__ __forceinline__ int calcDist(const uchar3& a, const uchar3& b) { return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z); } - template struct FastNonLocalMenas + template struct FastNonLocalMeans { enum { @@ -290,7 +290,7 @@ namespace cv { namespace gpu { namespace device int block_window; float minus_h2_inv; - FastNonLocalMenas(int search_window_, int block_window_, float h) : search_radius(search_window_/2), block_radius(block_window_/2), + FastNonLocalMeans(int search_window_, int block_window_, float h) : search_radius(search_window_/2), block_radius(block_window_/2), search_window(search_window_), block_window(block_window_), minus_h2_inv(-1.f/(h * h * VecTraits::cn)) {} PtrStep src; @@ -394,7 +394,7 @@ namespace cv { namespace gpu { namespace device } } - __device__ __forceinline__ void convolve_window(int i, int j, const int* dist_sums, PtrStepi& col_sums, PtrStepi& up_col_sums, T& dst) const + __device__ __forceinline__ void convolve_window(int i, int j, const int* dist_sums, T& dst) const { typedef typename TypeVec::cn>::vec_type sum_type; @@ -471,18 +471,18 @@ namespace cv { namespace gpu { namespace device __syncthreads(); - convolve_window(i, j, dist_sums, col_sums, up_col_sums, dst(i, j)); + convolve_window(i, j, dist_sums, dst(i, j)); } } }; template - __global__ void fast_nlm_kernel(const FastNonLocalMenas fnlm, PtrStepSz dst) { fnlm(dst); } + __global__ void fast_nlm_kernel(const FastNonLocalMeans fnlm, PtrStepSz dst) { fnlm(dst); } void nln_fast_get_buffer_size(const PtrStepSzb& src, int search_window, int block_window, int& buffer_cols, int& buffer_rows) { - typedef FastNonLocalMenas FNLM; + typedef FastNonLocalMeans FNLM; dim3 grid(divUp(src.cols, FNLM::TILE_COLS), divUp(src.rows, FNLM::TILE_ROWS)); buffer_cols = search_window * search_window * grid.y; @@ -493,7 +493,7 @@ namespace cv { namespace gpu { namespace device void nlm_fast_gpu(const PtrStepSzb& src, PtrStepSzb dst, PtrStepi buffer, int search_window, int block_window, float h, cudaStream_t stream) { - typedef FastNonLocalMenas FNLM; + typedef FastNonLocalMeans FNLM; FNLM fnlm(search_window, block_window, h); fnlm.src = (PtrStepSz)src; diff --git a/modules/gpu/src/cuda/resize.cu b/modules/gpu/src/cuda/resize.cu index 110e62d03..fa13121f9 100644 --- a/modules/gpu/src/cuda/resize.cu +++ b/modules/gpu/src/cuda/resize.cu @@ -213,7 +213,7 @@ namespace cv { namespace gpu { namespace device const dim3 block(32, 8); const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); - resize_linear<<>>(src, dst, fy, fx); + resize_linear<<>>(src, dst, fy, fx); cudaSafeCall( cudaGetLastError() ); if (stream == 0) diff --git a/modules/gpu/src/fast.cpp b/modules/gpu/src/fast.cpp index a24a69962..37ca92dc4 100644 --- a/modules/gpu/src/fast.cpp +++ b/modules/gpu/src/fast.cpp @@ -59,8 +59,8 @@ int cv::gpu::FAST_GPU::getKeyPoints(GpuMat&) { throw_nogpu(); return 0; } #else /* !defined (HAVE_CUDA) */ -cv::gpu::FAST_GPU::FAST_GPU(int _threshold, bool _nonmaxSupression, double _keypointsRatio) : - nonmaxSupression(_nonmaxSupression), threshold(_threshold), keypointsRatio(_keypointsRatio), count_(0) +cv::gpu::FAST_GPU::FAST_GPU(int _threshold, bool _nonmaxSuppression, double _keypointsRatio) : + nonmaxSuppression(_nonmaxSuppression), threshold(_threshold), keypointsRatio(_keypointsRatio), count_(0) { } @@ -114,7 +114,7 @@ namespace cv { namespace gpu { namespace device namespace fast { int calcKeypoints_gpu(PtrStepSzb img, PtrStepSzb mask, short2* kpLoc, int maxKeypoints, PtrStepSzi score, int threshold); - int nonmaxSupression_gpu(const short2* kpLoc, int count, PtrStepSzi score, short2* loc, float* response); + int nonmaxSuppression_gpu(const short2* kpLoc, int count, PtrStepSzi score, short2* loc, float* response); } }}} @@ -129,13 +129,13 @@ int cv::gpu::FAST_GPU::calcKeyPointsLocation(const GpuMat& img, const GpuMat& ma ensureSizeIsEnough(1, maxKeypoints, CV_16SC2, kpLoc_); - if (nonmaxSupression) + if (nonmaxSuppression) { ensureSizeIsEnough(img.size(), CV_32SC1, score_); score_.setTo(Scalar::all(0)); } - count_ = calcKeypoints_gpu(img, mask, kpLoc_.ptr(), maxKeypoints, nonmaxSupression ? score_ : PtrStepSzi(), threshold); + count_ = calcKeypoints_gpu(img, mask, kpLoc_.ptr(), maxKeypoints, nonmaxSuppression ? score_ : PtrStepSzi(), threshold); count_ = std::min(count_, maxKeypoints); return count_; @@ -150,8 +150,8 @@ int cv::gpu::FAST_GPU::getKeyPoints(GpuMat& keypoints) ensureSizeIsEnough(ROWS_COUNT, count_, CV_32FC1, keypoints); - if (nonmaxSupression) - return nonmaxSupression_gpu(kpLoc_.ptr(), count_, score_, keypoints.ptr(LOCATION_ROW), keypoints.ptr(RESPONSE_ROW)); + if (nonmaxSuppression) + return nonmaxSuppression_gpu(kpLoc_.ptr(), count_, score_, keypoints.ptr(LOCATION_ROW), keypoints.ptr(RESPONSE_ROW)); GpuMat locRow(1, count_, kpLoc_.type(), keypoints.ptr(0)); kpLoc_.colRange(0, count_).copyTo(locRow); diff --git a/modules/gpu/src/hough.cpp b/modules/gpu/src/generalized_hough.cpp similarity index 79% rename from modules/gpu/src/hough.cpp rename to modules/gpu/src/generalized_hough.cpp index 09cf01850..6f48161c9 100644 --- a/modules/gpu/src/hough.cpp +++ b/modules/gpu/src/generalized_hough.cpp @@ -46,18 +46,12 @@ using namespace std; using namespace cv; using namespace cv::gpu; +#if defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ == 47) +# define CUDA_DISABLER +#endif + #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) -void cv::gpu::HoughLines(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); } -void cv::gpu::HoughLines(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, bool, int) { throw_nogpu(); } -void cv::gpu::HoughLinesDownload(const GpuMat&, OutputArray, OutputArray) { throw_nogpu(); } - -void cv::gpu::HoughLinesP(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, int, int) { throw_nogpu(); } - -void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, int, float, float, int, int, int, int, int) { throw_nogpu(); } -void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, HoughCirclesBuf&, int, float, float, int, int, int, int, int) { throw_nogpu(); } -void cv::gpu::HoughCirclesDownload(const GpuMat&, OutputArray) { throw_nogpu(); } - Ptr cv::gpu::GeneralizedHough_GPU::create(int) { throw_nogpu(); return Ptr(); } cv::gpu::GeneralizedHough_GPU::~GeneralizedHough_GPU() {} void cv::gpu::GeneralizedHough_GPU::setTemplate(const GpuMat&, int, Point) { throw_nogpu(); } @@ -77,299 +71,6 @@ namespace cv { namespace gpu { namespace device } }}} -////////////////////////////////////////////////////////// -// HoughLines - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); - int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort); - } -}}} - -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - HoughLinesBuf buf; - HoughLines(src, lines, buf, rho, theta, threshold, doSort, maxLines); -} - -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - using namespace cv::gpu::device::hough; - - CV_Assert(src.type() == CV_8UC1); - CV_Assert(src.cols < std::numeric_limits::max()); - CV_Assert(src.rows < std::numeric_limits::max()); - - ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(); - - const int pointsCount = buildPointList_gpu(src, srcPoints); - if (pointsCount == 0) - { - lines.release(); - return; - } - - const int numangle = cvRound(CV_PI / theta); - const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); - CV_Assert(numangle > 0 && numrho > 0); - - ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - DeviceInfo devInfo; - linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); - - ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); - - int linesCount = linesGetResult_gpu(buf.accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); - if (linesCount > 0) - lines.cols = linesCount; - else - lines.release(); -} - -void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_) -{ - if (d_lines.empty()) - { - h_lines_.release(); - if (h_votes_.needed()) - h_votes_.release(); - return; - } - - CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); - - h_lines_.create(1, d_lines.cols, CV_32FC2); - Mat h_lines = h_lines_.getMat(); - d_lines.row(0).download(h_lines); - - if (h_votes_.needed()) - { - h_votes_.create(1, d_lines.cols, CV_32SC1); - Mat h_votes = h_votes_.getMat(); - GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); - d_votes.download(h_votes); - } -} - -////////////////////////////////////////////////////////// -// HoughLinesP - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength); - } -}}} - -void cv::gpu::HoughLinesP(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines) -{ - using namespace cv::gpu::device::hough; - - CV_Assert( src.type() == CV_8UC1 ); - CV_Assert( src.cols < std::numeric_limits::max() ); - CV_Assert( src.rows < std::numeric_limits::max() ); - - ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(); - - const int pointsCount = buildPointList_gpu(src, srcPoints); - if (pointsCount == 0) - { - lines.release(); - return; - } - - const int numangle = cvRound(CV_PI / theta); - const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); - CV_Assert( numangle > 0 && numrho > 0 ); - - ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - DeviceInfo devInfo; - linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); - - ensureSizeIsEnough(1, maxLines, CV_32SC4, lines); - - int linesCount = houghLinesProbabilistic_gpu(src, buf.accum, lines.ptr(), maxLines, rho, theta, maxLineGap, minLineLength); - - if (linesCount > 0) - lines.cols = linesCount; - else - lines.release(); -} - -////////////////////////////////////////////////////////// -// HoughCircles - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp); - int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold); - int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, - float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20); - } -}}} - -void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) -{ - HoughCirclesBuf buf; - HoughCircles(src, circles, buf, method, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles); -} - -void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, - float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) -{ - using namespace cv::gpu::device::hough; - - CV_Assert(src.type() == CV_8UC1); - CV_Assert(src.cols < std::numeric_limits::max()); - CV_Assert(src.rows < std::numeric_limits::max()); - CV_Assert(method == CV_HOUGH_GRADIENT); - CV_Assert(dp > 0); - CV_Assert(minRadius > 0 && maxRadius > minRadius); - CV_Assert(cannyThreshold > 0); - CV_Assert(votesThreshold > 0); - CV_Assert(maxCircles > 0); - - const float idp = 1.0f / dp; - - cv::gpu::Canny(src, buf.cannyBuf, buf.edges, std::max(cannyThreshold / 2, 1), cannyThreshold); - - ensureSizeIsEnough(2, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(0); - unsigned int* centers = buf.list.ptr(1); - - const int pointsCount = buildPointList_gpu(buf.edges, srcPoints); - if (pointsCount == 0) - { - circles.release(); - return; - } - - ensureSizeIsEnough(cvCeil(src.rows * idp) + 2, cvCeil(src.cols * idp) + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - circlesAccumCenters_gpu(srcPoints, pointsCount, buf.cannyBuf.dx, buf.cannyBuf.dy, buf.accum, minRadius, maxRadius, idp); - - int centersCount = buildCentersList_gpu(buf.accum, centers, votesThreshold); - if (centersCount == 0) - { - circles.release(); - return; - } - - if (minDist > 1) - { - cv::AutoBuffer oldBuf_(centersCount); - cv::AutoBuffer newBuf_(centersCount); - int newCount = 0; - - ushort2* oldBuf = oldBuf_; - ushort2* newBuf = newBuf_; - - cudaSafeCall( cudaMemcpy(oldBuf, centers, centersCount * sizeof(ushort2), cudaMemcpyDeviceToHost) ); - - const int cellSize = cvRound(minDist); - const int gridWidth = (src.cols + cellSize - 1) / cellSize; - const int gridHeight = (src.rows + cellSize - 1) / cellSize; - - std::vector< std::vector > grid(gridWidth * gridHeight); - - const float minDist2 = minDist * minDist; - - for (int i = 0; i < centersCount; ++i) - { - ushort2 p = oldBuf[i]; - - bool good = true; - - int xCell = static_cast(p.x / cellSize); - int yCell = static_cast(p.y / cellSize); - - int x1 = xCell - 1; - int y1 = yCell - 1; - int x2 = xCell + 1; - int y2 = yCell + 1; - - // boundary check - x1 = std::max(0, x1); - y1 = std::max(0, y1); - x2 = std::min(gridWidth - 1, x2); - y2 = std::min(gridHeight - 1, y2); - - for (int yy = y1; yy <= y2; ++yy) - { - for (int xx = x1; xx <= x2; ++xx) - { - vector& m = grid[yy * gridWidth + xx]; - - for(size_t j = 0; j < m.size(); ++j) - { - float dx = (float)(p.x - m[j].x); - float dy = (float)(p.y - m[j].y); - - if (dx * dx + dy * dy < minDist2) - { - good = false; - goto break_out; - } - } - } - } - - break_out: - - if(good) - { - grid[yCell * gridWidth + xCell].push_back(p); - - newBuf[newCount++] = p; - } - } - - cudaSafeCall( cudaMemcpy(centers, newBuf, newCount * sizeof(unsigned int), cudaMemcpyHostToDevice) ); - centersCount = newCount; - } - - ensureSizeIsEnough(1, maxCircles, CV_32FC3, circles); - - const int circlesCount = circlesAccumRadius_gpu(centers, centersCount, srcPoints, pointsCount, circles.ptr(), maxCircles, - dp, minRadius, maxRadius, votesThreshold, deviceSupports(FEATURE_SET_COMPUTE_20)); - - if (circlesCount > 0) - circles.cols = circlesCount; - else - circles.release(); -} - -void cv::gpu::HoughCirclesDownload(const GpuMat& d_circles, cv::OutputArray h_circles_) -{ - if (d_circles.empty()) - { - h_circles_.release(); - return; - } - - CV_Assert(d_circles.rows == 1 && d_circles.type() == CV_32FC3); - - h_circles_.create(1, d_circles.cols, CV_32FC3); - Mat h_circles = h_circles_.getMat(); - d_circles.download(h_circles); -} - -////////////////////////////////////////////////////////// -// GeneralizedHough - namespace cv { namespace gpu { namespace device { namespace hough diff --git a/modules/gpu/src/hough_circles.cpp b/modules/gpu/src/hough_circles.cpp new file mode 100644 index 000000000..74aa7394f --- /dev/null +++ b/modules/gpu/src/hough_circles.cpp @@ -0,0 +1,223 @@ +/*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" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, int, float, float, int, int, int, int, int) { throw_nogpu(); } +void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, HoughCirclesBuf&, int, float, float, int, int, int, int, int) { throw_nogpu(); } +void cv::gpu::HoughCirclesDownload(const GpuMat&, OutputArray) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp); + int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold); + int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, + float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20); + } +}}} + +void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) +{ + HoughCirclesBuf buf; + HoughCircles(src, circles, buf, method, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles); +} + +void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, + float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) +{ + using namespace cv::gpu::device::hough; + + CV_Assert(src.type() == CV_8UC1); + CV_Assert(src.cols < std::numeric_limits::max()); + CV_Assert(src.rows < std::numeric_limits::max()); + CV_Assert(method == CV_HOUGH_GRADIENT); + CV_Assert(dp > 0); + CV_Assert(minRadius > 0 && maxRadius > minRadius); + CV_Assert(cannyThreshold > 0); + CV_Assert(votesThreshold > 0); + CV_Assert(maxCircles > 0); + + const float idp = 1.0f / dp; + + cv::gpu::Canny(src, buf.cannyBuf, buf.edges, std::max(cannyThreshold / 2, 1), cannyThreshold); + + ensureSizeIsEnough(2, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(0); + unsigned int* centers = buf.list.ptr(1); + + const int pointsCount = buildPointList_gpu(buf.edges, srcPoints); + if (pointsCount == 0) + { + circles.release(); + return; + } + + ensureSizeIsEnough(cvCeil(src.rows * idp) + 2, cvCeil(src.cols * idp) + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + circlesAccumCenters_gpu(srcPoints, pointsCount, buf.cannyBuf.dx, buf.cannyBuf.dy, buf.accum, minRadius, maxRadius, idp); + + int centersCount = buildCentersList_gpu(buf.accum, centers, votesThreshold); + if (centersCount == 0) + { + circles.release(); + return; + } + + if (minDist > 1) + { + cv::AutoBuffer oldBuf_(centersCount); + cv::AutoBuffer newBuf_(centersCount); + int newCount = 0; + + ushort2* oldBuf = oldBuf_; + ushort2* newBuf = newBuf_; + + cudaSafeCall( cudaMemcpy(oldBuf, centers, centersCount * sizeof(ushort2), cudaMemcpyDeviceToHost) ); + + const int cellSize = cvRound(minDist); + const int gridWidth = (src.cols + cellSize - 1) / cellSize; + const int gridHeight = (src.rows + cellSize - 1) / cellSize; + + std::vector< std::vector > grid(gridWidth * gridHeight); + + const float minDist2 = minDist * minDist; + + for (int i = 0; i < centersCount; ++i) + { + ushort2 p = oldBuf[i]; + + bool good = true; + + int xCell = static_cast(p.x / cellSize); + int yCell = static_cast(p.y / cellSize); + + int x1 = xCell - 1; + int y1 = yCell - 1; + int x2 = xCell + 1; + int y2 = yCell + 1; + + // boundary check + x1 = std::max(0, x1); + y1 = std::max(0, y1); + x2 = std::min(gridWidth - 1, x2); + y2 = std::min(gridHeight - 1, y2); + + for (int yy = y1; yy <= y2; ++yy) + { + for (int xx = x1; xx <= x2; ++xx) + { + vector& m = grid[yy * gridWidth + xx]; + + for(size_t j = 0; j < m.size(); ++j) + { + float dx = (float)(p.x - m[j].x); + float dy = (float)(p.y - m[j].y); + + if (dx * dx + dy * dy < minDist2) + { + good = false; + goto break_out; + } + } + } + } + + break_out: + + if(good) + { + grid[yCell * gridWidth + xCell].push_back(p); + + newBuf[newCount++] = p; + } + } + + cudaSafeCall( cudaMemcpy(centers, newBuf, newCount * sizeof(unsigned int), cudaMemcpyHostToDevice) ); + centersCount = newCount; + } + + ensureSizeIsEnough(1, maxCircles, CV_32FC3, circles); + + const int circlesCount = circlesAccumRadius_gpu(centers, centersCount, srcPoints, pointsCount, circles.ptr(), maxCircles, + dp, minRadius, maxRadius, votesThreshold, deviceSupports(FEATURE_SET_COMPUTE_20)); + + if (circlesCount > 0) + circles.cols = circlesCount; + else + circles.release(); +} + +void cv::gpu::HoughCirclesDownload(const GpuMat& d_circles, cv::OutputArray h_circles_) +{ + if (d_circles.empty()) + { + h_circles_.release(); + return; + } + + CV_Assert(d_circles.rows == 1 && d_circles.type() == CV_32FC3); + + h_circles_.create(1, d_circles.cols, CV_32FC3); + Mat h_circles = h_circles_.getMat(); + d_circles.download(h_circles); +} + +#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/hough_lines.cpp b/modules/gpu/src/hough_lines.cpp new file mode 100644 index 000000000..4cc4067b2 --- /dev/null +++ b/modules/gpu/src/hough_lines.cpp @@ -0,0 +1,142 @@ +/*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" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughLines(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); } +void cv::gpu::HoughLines(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, bool, int) { throw_nogpu(); } +void cv::gpu::HoughLinesDownload(const GpuMat&, OutputArray, OutputArray) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); + int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort); + } +}}} + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + HoughLinesBuf buf; + HoughLines(src, lines, buf, rho, theta, threshold, doSort, maxLines); +} + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + using namespace cv::gpu::device::hough; + + CV_Assert(src.type() == CV_8UC1); + CV_Assert(src.cols < std::numeric_limits::max()); + CV_Assert(src.rows < std::numeric_limits::max()); + + ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(); + + const int pointsCount = buildPointList_gpu(src, srcPoints); + if (pointsCount == 0) + { + lines.release(); + return; + } + + const int numangle = cvRound(CV_PI / theta); + const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); + CV_Assert(numangle > 0 && numrho > 0); + + ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + DeviceInfo devInfo; + linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); + + ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); + + int linesCount = linesGetResult_gpu(buf.accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); + if (linesCount > 0) + lines.cols = linesCount; + else + lines.release(); +} + +void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_) +{ + if (d_lines.empty()) + { + h_lines_.release(); + if (h_votes_.needed()) + h_votes_.release(); + return; + } + + CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); + + h_lines_.create(1, d_lines.cols, CV_32FC2); + Mat h_lines = h_lines_.getMat(); + d_lines.row(0).download(h_lines); + + if (h_votes_.needed()) + { + h_votes_.create(1, d_lines.cols, CV_32SC1); + Mat h_votes = h_votes_.getMat(); + GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); + d_votes.download(h_votes); + } +} + +#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/hough_segments.cpp b/modules/gpu/src/hough_segments.cpp new file mode 100644 index 000000000..c34f33a62 --- /dev/null +++ b/modules/gpu/src/hough_segments.cpp @@ -0,0 +1,110 @@ +/*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" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughLinesP(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, int, int) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); + int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength); + } +}}} + +void cv::gpu::HoughLinesP(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines) +{ + using namespace cv::gpu::device::hough; + + CV_Assert( src.type() == CV_8UC1 ); + CV_Assert( src.cols < std::numeric_limits::max() ); + CV_Assert( src.rows < std::numeric_limits::max() ); + + ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(); + + const int pointsCount = buildPointList_gpu(src, srcPoints); + if (pointsCount == 0) + { + lines.release(); + return; + } + + const int numangle = cvRound(CV_PI / theta); + const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); + CV_Assert( numangle > 0 && numrho > 0 ); + + ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + DeviceInfo devInfo; + linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); + + ensureSizeIsEnough(1, maxLines, CV_32SC4, lines); + + int linesCount = houghLinesProbabilistic_gpu(src, buf.accum, lines.ptr(), maxLines, rho, theta, maxLineGap, minLineLength); + + if (linesCount > 0) + lines.cols = linesCount; + else + lines.release(); +} + +#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 1904b6aad..66f838f77 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -244,6 +244,10 @@ void cv::gpu::reprojectImageTo3D(const GpuMat& disp, GpuMat& xyz, const Mat& Q, //////////////////////////////////////////////////////////////////////// // copyMakeBorder +// Disable NPP for this file +//#define USE_NPP +#undef USE_NPP + namespace cv { namespace gpu { namespace device { namespace imgproc @@ -279,6 +283,7 @@ void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom cudaStream_t stream = StreamAccessor::getStream(s); +#ifdef USE_NPP if (borderType == BORDER_CONSTANT && (src.type() == CV_8UC1 || src.type() == CV_8UC4 || src.type() == CV_32SC1 || src.type() == CV_32FC1)) { NppiSize srcsz; @@ -328,6 +333,7 @@ void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom cudaSafeCall( cudaDeviceSynchronize() ); } else +#endif { typedef void (*caller_t)(const PtrStepSzb& src, const PtrStepSzb& dst, int top, int left, int borderType, const Scalar& value, cudaStream_t stream); static const caller_t callers[6][4] = @@ -1485,6 +1491,8 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size) { + CV_Assert(image_size.width < std::numeric_limits::max() && image_size.height < std::numeric_limits::max()); + if (apperture_size > 0) { ensureSizeIsEnough(image_size, CV_32SC1, dx); @@ -1500,8 +1508,8 @@ void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size) ensureSizeIsEnough(image_size, CV_32FC1, mag); ensureSizeIsEnough(image_size, CV_32SC1, map); - ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st1); - ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st2); + ensureSizeIsEnough(1, image_size.area(), CV_16SC2, st1); + ensureSizeIsEnough(1, image_size.area(), CV_16SC2, st2); } void cv::gpu::CannyBuf::release() @@ -1521,9 +1529,9 @@ namespace canny void calcMap(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, PtrStepSzi map, float low_thresh, float high_thresh); - void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1); + void edgesHysteresisLocal(PtrStepSzi map, short2* st1); - void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2); + void edgesHysteresisGlobal(PtrStepSzi map, short2* st1, short2* st2); void getEdges(PtrStepSzi map, PtrStepSzb dst); } @@ -1537,9 +1545,9 @@ namespace buf.map.setTo(Scalar::all(0)); calcMap(dx, dy, buf.mag, buf.map, low_thresh, high_thresh); - edgesHysteresisLocal(buf.map, buf.st1.ptr()); + edgesHysteresisLocal(buf.map, buf.st1.ptr()); - edgesHysteresisGlobal(buf.map, buf.st1.ptr(), buf.st2.ptr()); + edgesHysteresisGlobal(buf.map, buf.st1.ptr(), buf.st2.ptr()); getEdges(buf.map, dst); } diff --git a/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp b/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp index 42552295d..1c0e691ba 100644 --- a/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp +++ b/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp @@ -98,7 +98,7 @@ bool TestHaarCascadeLoader::process() NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting()); NCV_SKIP_COND_BEGIN - const std::string testNvbinName = "test.nvbin"; + const std::string testNvbinName = cv::tempfile("test.nvbin"); ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures); ncvAssertReturn(ncvStat == NCV_SUCCESS, false); diff --git a/modules/gpu/test/test_bgfg.cpp b/modules/gpu/test/test_bgfg.cpp index 6ef93c51b..e08bfb399 100644 --- a/modules/gpu/test/test_bgfg.cpp +++ b/modules/gpu/test/test_bgfg.cpp @@ -336,7 +336,7 @@ GPU_TEST_P(MOG2, getBackgroundImage) cv::Mat background_gold; mog2_gold.getBackgroundImage(background_gold); - ASSERT_MAT_NEAR(background_gold, background, 0); + ASSERT_MAT_NEAR(background_gold, background, 1); } INSTANTIATE_TEST_CASE_P(GPU_Video, MOG2, testing::Combine( diff --git a/modules/gpu/test/test_color.cpp b/modules/gpu/test/test_color.cpp index 3f5a37fd0..321785ffe 100644 --- a/modules/gpu/test/test_color.cpp +++ b/modules/gpu/test/test_color.cpp @@ -715,7 +715,7 @@ GPU_TEST_P(CvtColor, BGR2YCrCb) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_BGR2YCrCb); - EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, RGB2YCrCb) @@ -728,7 +728,7 @@ GPU_TEST_P(CvtColor, RGB2YCrCb) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_RGB2YCrCb); - EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, BGR2YCrCb4) @@ -749,7 +749,7 @@ GPU_TEST_P(CvtColor, BGR2YCrCb4) cv::split(h_dst, channels); cv::merge(channels, 3, h_dst); - EXPECT_MAT_NEAR(dst_gold, h_dst, 1e-5); + EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, RGBA2YCrCb4) @@ -771,7 +771,7 @@ GPU_TEST_P(CvtColor, RGBA2YCrCb4) cv::split(h_dst, channels); cv::merge(channels, 3, h_dst); - EXPECT_MAT_NEAR(dst_gold, h_dst, 1e-5); + EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, YCrCb2BGR) diff --git a/modules/gpu/test/test_core.cpp b/modules/gpu/test/test_core.cpp index b622ad8ea..7ceeaedf0 100644 --- a/modules/gpu/test/test_core.cpp +++ b/modules/gpu/test/test_core.cpp @@ -2353,7 +2353,7 @@ GPU_TEST_P(AddWeighted, Accuracy) cv::Mat dst_gold; cv::addWeighted(src1, alpha, src2, beta, gamma, dst_gold, dst_depth); - EXPECT_MAT_NEAR(dst_gold, dst, dst_depth < CV_32F ? 1.0 : 1e-3); + EXPECT_MAT_NEAR(dst_gold, dst, dst_depth < CV_32F ? 2.0 : 1e-3); } } @@ -3582,7 +3582,7 @@ GPU_TEST_P(Normalize, WithOutMask) cv::Mat dst_gold; cv::normalize(src, dst_gold, alpha, beta, norm_type, type); - EXPECT_MAT_NEAR(dst_gold, dst, 1e-6); + EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4); } GPU_TEST_P(Normalize, WithMask) @@ -3598,7 +3598,7 @@ GPU_TEST_P(Normalize, WithMask) dst_gold.setTo(cv::Scalar::all(0)); cv::normalize(src, dst_gold, alpha, beta, norm_type, type, mask); - EXPECT_MAT_NEAR(dst_gold, dst, 1e-6); + EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4); } INSTANTIATE_TEST_CASE_P(GPU_Core, Normalize, testing::Combine( diff --git a/modules/gpu/test/test_denoising.cpp b/modules/gpu/test/test_denoising.cpp index e480cf468..e416e9259 100644 --- a/modules/gpu/test/test_denoising.cpp +++ b/modules/gpu/test/test_denoising.cpp @@ -114,6 +114,7 @@ GPU_TEST_P(BruteForceNonLocalMeans, Regression) cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR); ASSERT_FALSE(bgr.empty()); + cv::resize(bgr, bgr, cv::Size(256, 256)); cv::Mat gray; cv::cvtColor(bgr, gray, CV_BGR2GRAY); @@ -130,6 +131,8 @@ GPU_TEST_P(BruteForceNonLocalMeans, Regression) cv::Mat bgr_gold = readImage("denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR); cv::Mat gray_gold = readImage("denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty()); + cv::resize(bgr_gold, bgr_gold, cv::Size(256, 256)); + cv::resize(gray_gold, gray_gold, cv::Size(256, 256)); EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4); EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4); diff --git a/modules/gpu/test/test_features2d.cpp b/modules/gpu/test/test_features2d.cpp index dfa3afa38..697483657 100644 --- a/modules/gpu/test/test_features2d.cpp +++ b/modules/gpu/test/test_features2d.cpp @@ -52,20 +52,20 @@ using namespace cvtest; namespace { IMPLEMENT_PARAM_CLASS(FAST_Threshold, int) - IMPLEMENT_PARAM_CLASS(FAST_NonmaxSupression, bool) + IMPLEMENT_PARAM_CLASS(FAST_NonmaxSuppression, bool) } -PARAM_TEST_CASE(FAST, cv::gpu::DeviceInfo, FAST_Threshold, FAST_NonmaxSupression) +PARAM_TEST_CASE(FAST, cv::gpu::DeviceInfo, FAST_Threshold, FAST_NonmaxSuppression) { cv::gpu::DeviceInfo devInfo; int threshold; - bool nonmaxSupression; + bool nonmaxSuppression; virtual void SetUp() { devInfo = GET_PARAM(0); threshold = GET_PARAM(1); - nonmaxSupression = GET_PARAM(2); + nonmaxSuppression = GET_PARAM(2); cv::gpu::setDevice(devInfo.deviceID()); } @@ -77,7 +77,7 @@ GPU_TEST_P(FAST, Accuracy) ASSERT_FALSE(image.empty()); cv::gpu::FAST_GPU fast(threshold); - fast.nonmaxSupression = nonmaxSupression; + fast.nonmaxSuppression = nonmaxSuppression; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) { @@ -97,7 +97,7 @@ GPU_TEST_P(FAST, Accuracy) fast(loadMat(image), cv::gpu::GpuMat(), keypoints); std::vector keypoints_gold; - cv::FAST(image, keypoints_gold, threshold, nonmaxSupression); + cv::FAST(image, keypoints_gold, threshold, nonmaxSuppression); ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints); } @@ -106,7 +106,7 @@ GPU_TEST_P(FAST, Accuracy) INSTANTIATE_TEST_CASE_P(GPU_Features2D, FAST, testing::Combine( ALL_DEVICES, testing::Values(FAST_Threshold(25), FAST_Threshold(50)), - testing::Values(FAST_NonmaxSupression(false), FAST_NonmaxSupression(true)))); + testing::Values(FAST_NonmaxSuppression(false), FAST_NonmaxSuppression(true)))); ///////////////////////////////////////////////////////////////////////////////////////////////// // ORB diff --git a/modules/gpu/test/test_gpumat.cpp b/modules/gpu/test/test_gpumat.cpp index c7a0cabcb..fee264341 100644 --- a/modules/gpu/test/test_gpumat.cpp +++ b/modules/gpu/test/test_gpumat.cpp @@ -281,7 +281,7 @@ GPU_TEST_P(ConvertTo, WithOutScaling) cv::Mat dst_gold; src.convertTo(dst_gold, depth2); - EXPECT_MAT_NEAR(dst_gold, dst, 0.0); + EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4); } } diff --git a/modules/gpu/test/test_hough.cpp b/modules/gpu/test/test_hough.cpp index f876a7a2b..4ae00cfd0 100644 --- a/modules/gpu/test/test_hough.cpp +++ b/modules/gpu/test/test_hough.cpp @@ -185,6 +185,8 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughCircles, testing::Combine( /////////////////////////////////////////////////////////////////////////////////////////////////////// // GeneralizedHough +#if !defined(__GNUC__) || (__GNUC__ * 10 + __GNUC_MINOR__ != 47) + PARAM_TEST_CASE(GeneralizedHough, cv::gpu::DeviceInfo, UseRoi) { }; @@ -252,4 +254,6 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, GeneralizedHough, testing::Combine( ALL_DEVICES, WHOLE_SUBMAT)); +#endif + #endif // HAVE_CUDA diff --git a/modules/gpu/test/test_imgproc.cpp b/modules/gpu/test/test_imgproc.cpp index 811d1294c..9ce32d12b 100644 --- a/modules/gpu/test/test_imgproc.cpp +++ b/modules/gpu/test/test_imgproc.cpp @@ -563,6 +563,8 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Blend, testing::Combine( testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), WHOLE_SUBMAT)); +#ifdef HAVE_CUFFT + //////////////////////////////////////////////////////// // Convolve @@ -1090,6 +1092,8 @@ GPU_TEST_P(Dft, R2CThenC2R) INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Dft, ALL_DEVICES); +#endif + /////////////////////////////////////////////////////////////////////////////////////////////////////// // CornerHarris diff --git a/modules/gpu/test/test_objdetect.cpp b/modules/gpu/test/test_objdetect.cpp index aaeaa54e6..f5c4e1638 100644 --- a/modules/gpu/test/test_objdetect.cpp +++ b/modules/gpu/test/test_objdetect.cpp @@ -177,7 +177,7 @@ struct HOG : testing::TestWithParam, cv::gpu::HOGDescriptor }; // desabled while resize does not fixed -GPU_TEST_P(HOG, Detect) +GPU_TEST_P(HOG, DISABLED_Detect) { cv::Mat img_rgb = readImage("hog/road.png"); ASSERT_FALSE(img_rgb.empty()); diff --git a/modules/gpu/test/test_optflow.cpp b/modules/gpu/test/test_optflow.cpp index 53b93a096..571403d2a 100644 --- a/modules/gpu/test/test_optflow.cpp +++ b/modules/gpu/test/test_optflow.cpp @@ -483,13 +483,15 @@ GPU_TEST_P(OpticalFlowBM, Accuracy) cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame0.empty()); + cv::resize(frame0, frame0, cv::Size(), 0.5, 0.5); cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame1.empty()); + cv::resize(frame1, frame1, cv::Size(), 0.5, 0.5); - cv::Size block_size(16, 16); + cv::Size block_size(8, 8); cv::Size shift_size(1, 1); - cv::Size max_range(16, 16); + cv::Size max_range(8, 8); cv::gpu::GpuMat d_velx, d_vely, buf; cv::gpu::calcOpticalFlowBM(loadMat(frame0), loadMat(frame1), diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index fd2eec6a1..7d2547bcf 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -315,7 +315,7 @@ if(WIN32 AND WITH_FFMPEG) COMMENT "Copying ${ffmpeg_path} to the output directory") endif() - install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main RENAME "${ffmpeg_bare_name_ver}") + install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}") endif() ocv_add_accuracy_tests() diff --git a/modules/highgui/doc/reading_and_writing_images_and_video.rst b/modules/highgui/doc/reading_and_writing_images_and_video.rst index 02b196ab9..9ec0c15fb 100644 --- a/modules/highgui/doc/reading_and_writing_images_and_video.rst +++ b/modules/highgui/doc/reading_and_writing_images_and_video.rst @@ -141,7 +141,7 @@ Saves an image to a specified file. The function ``imwrite`` saves the image to the specified file. The image format is chosen based on the ``filename`` extension (see :ocv:func:`imread` for the list of extensions). Only 8-bit (or 16-bit unsigned (``CV_16U``) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use :ocv:func:`Mat::convertTo` , and -:ocv:func:`cvtColor` to convert it before saving. Or, use the universal XML I/O functions to save the image to XML or YAML format. +:ocv:func:`cvtColor` to convert it before saving. Or, use the universal :ocv:class:`FileStorage` I/O functions to save the image to XML or YAML format. It is possible to store PNG images with an alpha channel using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535. The sample below shows how to create such a BGRA image and store to PNG file. It also demonstrates how to set custom compression parameters :: @@ -496,7 +496,7 @@ VideoWriter constructors :param filename: Name of the output video file. - :param fourcc: 4-character code of codec used to compress the frames. For example, ``CV_FOURCC('P','I','M,'1')`` is a MPEG-1 codec, ``CV_FOURCC('M','J','P','G')`` is a motion-jpeg codec etc. List of codes can be obtained at `Video Codecs by FOURCC `_ page. + :param fourcc: 4-character code of codec used to compress the frames. For example, ``CV_FOURCC('P','I','M','1')`` is a MPEG-1 codec, ``CV_FOURCC('M','J','P','G')`` is a motion-jpeg codec etc. List of codes can be obtained at `Video Codecs by FOURCC `_ page. :param fps: Framerate of the created video stream. diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index 4f743ffec..1f86abb9d 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -454,6 +454,8 @@ enum CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006, CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007, CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008, + CV_CAP_PROP_ANDROID_EXPOSE_LOCK = 8009, + CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK = 8010, // Properties of cameras available through AVFOUNDATION interface CV_CAP_PROP_IOS_DEVICE_FOCUS = 9001, @@ -534,6 +536,7 @@ enum enum { CV_CAP_ANDROID_FOCUS_MODE_AUTO = 0, + CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_PICTURE, CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO, CV_CAP_ANDROID_FOCUS_MODE_EDOF, CV_CAP_ANDROID_FOCUS_MODE_FIXED, diff --git a/modules/highgui/src/bitstrm.hpp b/modules/highgui/src/bitstrm.hpp index e476d9c56..57956beb5 100644 --- a/modules/highgui/src/bitstrm.hpp +++ b/modules/highgui/src/bitstrm.hpp @@ -53,7 +53,7 @@ enum RBS_THROW_EOS=-123, // exception code RBS_THROW_FORB=-124, // exception code RBS_HUFF_FORB=2047, // forrbidden huffman code "value" - RBS_BAD_HEADER=-125, // invalid header + RBS_BAD_HEADER=-125 // invalid header }; typedef unsigned long ulong; diff --git a/modules/highgui/src/cap_android.cpp b/modules/highgui/src/cap_android.cpp index 2f3f388c0..a8d8c5b41 100644 --- a/modules/highgui/src/cap_android.cpp +++ b/modules/highgui/src/cap_android.cpp @@ -289,6 +289,10 @@ double CvCapture_Android::getProperty( int propIdx ) return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL); case CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR: return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR); + case CV_CAP_PROP_ANDROID_EXPOSE_LOCK: + return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK); + case CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK: + return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK); default: CV_Error( CV_StsOutOfRange, "Failed attempt to GET unsupported camera property." ); break; @@ -327,14 +331,23 @@ bool CvCapture_Android::setProperty( int propIdx, double propValue ) case CV_CAP_PROP_ANDROID_ANTIBANDING: m_activity->setProperty(ANDROID_CAMERA_PROPERTY_ANTIBANDING, propValue); break; + case CV_CAP_PROP_ANDROID_EXPOSE_LOCK: + m_activity->setProperty(ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK, propValue); + break; + case CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK: + m_activity->setProperty(ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK, propValue); + break; default: CV_Error( CV_StsOutOfRange, "Failed attempt to SET unsupported camera property." ); return false; } - if (propIdx != CV_CAP_PROP_AUTOGRAB) {// property for highgui class CvCapture_Android only + // Only changes in frame size require camera restart + if ((propIdx == CV_CAP_PROP_FRAME_WIDTH) || (propIdx == CV_CAP_PROP_FRAME_HEIGHT)) + { // property for highgui class CvCapture_Android only m_CameraParamsChanged = true; } + res = true; } diff --git a/modules/highgui/src/cap_avfoundation.mm b/modules/highgui/src/cap_avfoundation.mm index 35b52f08c..001ef025a 100644 --- a/modules/highgui/src/cap_avfoundation.mm +++ b/modules/highgui/src/cap_avfoundation.mm @@ -1313,6 +1313,8 @@ bool CvVideoWriter_AVFoundation::writeFrame(const IplImage* iplimage) { } //cleanup + CFRelease(cfData); + CVPixelBufferRelease(pixelBuffer); CGImageRelease(cgImage); CGDataProviderRelease(provider); CGColorSpaceRelease(colorSpace); diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index 151a0cac2..2b185595d 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -2066,7 +2066,7 @@ enum VideoCodec_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0) VideoCodec_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0) VideoCodec_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2) - VideoCodec_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2) + VideoCodec_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) // UYVY (4:2:2) }; enum @@ -2074,7 +2074,7 @@ enum VideoChromaFormat_Monochrome = 0, VideoChromaFormat_YUV420, VideoChromaFormat_YUV422, - VideoChromaFormat_YUV444, + VideoChromaFormat_YUV444 }; struct InputMediaStream_FFMPEG diff --git a/modules/highgui/src/cap_giganetix.cpp b/modules/highgui/src/cap_giganetix.cpp index ccbe7020f..e252a1643 100644 --- a/modules/highgui/src/cap_giganetix.cpp +++ b/modules/highgui/src/cap_giganetix.cpp @@ -711,13 +711,13 @@ CvCaptureCAM_Giganetix::setProperty( int property_id, double value ) INT64 w, wmax, val = (INT64)value; if((b_ret = m_device->GetIntegerNodeValue ("Width", w))) if((b_ret = m_device->GetIntegerNodeValue ("WidthMax", wmax))) - b_ret = m_device->SetIntegerNodeValue ("OffsetX", val w > wmax ? wmax - w : val); + b_ret = m_device->SetIntegerNodeValue ("OffsetX", (val + w) > wmax ? (wmax - w) : val); } break; case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y: { INT64 h, hmax, val = (INT64)value; if((b_ret = m_device->GetIntegerNodeValue ("Height", h))) if((b_ret = m_device->GetIntegerNodeValue ("HeightMax", hmax))) - b_ret = m_device->SetIntegerNodeValue ("OffsetY", val h > hmax ? hmax - h : val); + b_ret = m_device->SetIntegerNodeValue ("OffsetY", (val + h) > hmax ? (hmax - h) : val); b_ret = m_device->SetIntegerNodeValue ("OffsetY", (INT64)value); } break; diff --git a/modules/highgui/src/cap_gstreamer.cpp b/modules/highgui/src/cap_gstreamer.cpp index cafc803db..72e19b16f 100644 --- a/modules/highgui/src/cap_gstreamer.cpp +++ b/modules/highgui/src/cap_gstreamer.cpp @@ -400,6 +400,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename ) gst_app_sink_set_max_buffers (GST_APP_SINK(sink), 1); gst_app_sink_set_drop (GST_APP_SINK(sink), stream); caps = gst_caps_new_simple("video/x-raw-rgb", + "bpp", G_TYPE_INT, 24, "red_mask", G_TYPE_INT, 0x0000FF, "green_mask", G_TYPE_INT, 0x00FF00, "blue_mask", G_TYPE_INT, 0xFF0000, diff --git a/modules/highgui/src/cap_ios_abstract_camera.mm b/modules/highgui/src/cap_ios_abstract_camera.mm index a77e200a8..b40b3648d 100644 --- a/modules/highgui/src/cap_ios_abstract_camera.mm +++ b/modules/highgui/src/cap_ios_abstract_camera.mm @@ -278,8 +278,20 @@ { self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession]; - if ([self.captureVideoPreviewLayer isOrientationSupported]) { - [self.captureVideoPreviewLayer setOrientation:self.defaultAVCaptureVideoOrientation]; + if ([self.captureVideoPreviewLayer respondsToSelector:@selector(connection)]) + { + if ([self.captureVideoPreviewLayer.connection isVideoOrientationSupported]) + { + [self.captureVideoPreviewLayer.connection setVideoOrientation:self.defaultAVCaptureVideoOrientation]; + } + } + else + { + // Deprecated in 6.0; here for backward compatibility + if ([self.captureVideoPreviewLayer isOrientationSupported]) + { + [self.captureVideoPreviewLayer setOrientation:self.defaultAVCaptureVideoOrientation]; + } } if (parentView != nil) { @@ -290,9 +302,6 @@ NSLog(@"[Camera] created AVCaptureVideoPreviewLayer"); } - - - - (void)setDesiredCameraPosition:(AVCaptureDevicePosition)desiredPosition; { for (AVCaptureDevice *device in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp index 91047de1f..e7aa5b5df 100644 --- a/modules/highgui/src/cap_libv4l.cpp +++ b/modules/highgui/src/cap_libv4l.cpp @@ -321,7 +321,6 @@ typedef struct CvCaptureCAM_V4L struct v4l2_control control; enum v4l2_buf_type type; struct v4l2_queryctrl queryctrl; - struct v4l2_querymenu querymenu; /* V4L2 control variables */ v4l2_ctrl_range** v4l2_ctrl_ranges; @@ -491,25 +490,6 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName) } -static void v4l2_scan_controls_enumerate_menu(CvCaptureCAM_V4L* capture) -{ -// printf (" Menu items:\n"); - CLEAR (capture->querymenu); - capture->querymenu.id = capture->queryctrl.id; - for (capture->querymenu.index = capture->queryctrl.minimum; - (int)capture->querymenu.index <= capture->queryctrl.maximum; - capture->querymenu.index++) - { - if (0 == xioctl (capture->deviceHandle, VIDIOC_QUERYMENU, - &capture->querymenu)) - { - //printf (" %s\n", capture->querymenu.name); - } else { - perror ("VIDIOC_QUERYMENU"); - } - } -} - static void v4l2_free_ranges(CvCaptureCAM_V4L* capture) { int i; if (capture->v4l2_ctrl_ranges != NULL) { @@ -590,9 +570,6 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) { if(capture->queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) { continue; } - if (capture->queryctrl.type == V4L2_CTRL_TYPE_MENU) { - v4l2_scan_controls_enumerate_menu(capture); - } if(capture->queryctrl.type != V4L2_CTRL_TYPE_INTEGER && capture->queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN && capture->queryctrl.type != V4L2_CTRL_TYPE_MENU) { @@ -613,9 +590,6 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) { if(capture->queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) { continue; } - if (capture->queryctrl.type == V4L2_CTRL_TYPE_MENU) { - v4l2_scan_controls_enumerate_menu(capture); - } if(capture->queryctrl.type != V4L2_CTRL_TYPE_INTEGER && capture->queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN && capture->queryctrl.type != V4L2_CTRL_TYPE_MENU) { @@ -637,9 +611,6 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) { continue; } - if (capture->queryctrl.type == V4L2_CTRL_TYPE_MENU) { - v4l2_scan_controls_enumerate_menu(capture); - } if(capture->queryctrl.type != V4L2_CTRL_TYPE_INTEGER && capture->queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN && diff --git a/modules/highgui/src/cap_tyzx.cpp b/modules/highgui/src/cap_tyzx.cpp index 5f9c3f387..c4254597d 100644 --- a/modules/highgui/src/cap_tyzx.cpp +++ b/modules/highgui/src/cap_tyzx.cpp @@ -163,7 +163,7 @@ IplImage * CvCaptureCAM_TYZX::retrieveFrame(int) { if(!isOpened() || !g_tyzx_camera) return 0; - if(!image && !alocateImage()) + if(!image && !allocateImage()) return 0; // copy camera image into buffer. diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index 045c6f889..c9fca0581 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -325,7 +325,6 @@ typedef struct CvCaptureCAM_V4L struct v4l2_control control; enum v4l2_buf_type type; struct v4l2_queryctrl queryctrl; - struct v4l2_querymenu querymenu; struct timeval timestamp; @@ -641,24 +640,6 @@ static int autosetup_capture_mode_v4l(CvCaptureCAM_V4L* capture) #ifdef HAVE_CAMV4L2 -static void v4l2_scan_controls_enumerate_menu(CvCaptureCAM_V4L* capture) -{ -// printf (" Menu items:\n"); - CLEAR (capture->querymenu); - capture->querymenu.id = capture->queryctrl.id; - for (capture->querymenu.index = capture->queryctrl.minimum; - (int)capture->querymenu.index <= capture->queryctrl.maximum; - capture->querymenu.index++) - { - if (0 == ioctl (capture->deviceHandle, VIDIOC_QUERYMENU, - &capture->querymenu)) - { -// printf (" %s\n", capture->querymenu.name); - } else { - perror ("VIDIOC_QUERYMENU"); - } - } -} static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) { @@ -723,8 +704,6 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) capture->v4l2_exposure_max = capture->queryctrl.maximum; } - if (capture->queryctrl.type == V4L2_CTRL_TYPE_MENU) - v4l2_scan_controls_enumerate_menu(capture); } else { @@ -793,9 +772,6 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) capture->v4l2_exposure_max = capture->queryctrl.maximum; } - if (capture->queryctrl.type == V4L2_CTRL_TYPE_MENU) - v4l2_scan_controls_enumerate_menu(capture); - } else { if (errno == EINVAL) diff --git a/modules/highgui/src/cap_vfw.cpp b/modules/highgui/src/cap_vfw.cpp index d845953f8..46e070a13 100644 --- a/modules/highgui/src/cap_vfw.cpp +++ b/modules/highgui/src/cap_vfw.cpp @@ -318,7 +318,7 @@ public: virtual bool open( int index ); virtual void close(); virtual double getProperty(int); - virtual bool setProperty(int, double) { return false; } + virtual bool setProperty(int, double); virtual bool grabFrame(); virtual IplImage* retrieveFrame(int); virtual int getCaptureDomain() { return CV_CAP_VFW; } // Return the type of the capture object: CV_CAP_VFW, etc... @@ -332,6 +332,8 @@ protected: HWND capWnd; VIDEOHDR* hdr; DWORD fourcc; + int width, height; + int widthSet, heightSet; HIC hic; IplImage* frame; }; @@ -345,6 +347,8 @@ void CvCaptureCAM_VFW::init() fourcc = 0; hic = 0; frame = 0; + width = height = -1; + widthSet = heightSet = 0; } void CvCaptureCAM_VFW::closeHIC() @@ -407,16 +411,43 @@ bool CvCaptureCAM_VFW::open( int wIndex ) memset( &caps, 0, sizeof(caps)); capDriverGetCaps( hWndC, &caps, sizeof(caps)); - ::MoveWindow( hWndC, 0, 0, 320, 240, TRUE ); + CAPSTATUS status = {}; + capGetStatus(hWndC, &status, sizeof(status)); + ::SetWindowPos(hWndC, NULL, 0, 0, status.uiImageWidth, status.uiImageHeight, SWP_NOZORDER|SWP_NOMOVE); capSetUserData( hWndC, (size_t)this ); capSetCallbackOnFrame( hWndC, frameCallback ); CAPTUREPARMS p; capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS)); - p.dwRequestMicroSecPerFrame = 66667/2; + p.dwRequestMicroSecPerFrame = 66667/2; // 30 FPS capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS)); //capPreview( hWndC, 1 ); capPreviewScale(hWndC,FALSE); capPreviewRate(hWndC,1); + + // Get frame initial parameters. + const DWORD size = capGetVideoFormatSize(capWnd); + if( size > 0 ) + { + unsigned char *pbi = new unsigned char[size]; + if( pbi ) + { + if( capGetVideoFormat(capWnd, pbi, size) == size ) + { + BITMAPINFOHEADER& vfmt = ((BITMAPINFO*)pbi)->bmiHeader; + widthSet = vfmt.biWidth; + heightSet = vfmt.biHeight; + fourcc = vfmt.biCompression; + } + delete []pbi; + } + } + // And alternative way in case of failure. + if( widthSet == 0 || heightSet == 0 ) + { + widthSet = status.uiImageWidth; + heightSet = status.uiImageHeight; + } + } return capWnd != 0; } @@ -439,10 +470,8 @@ void CvCaptureCAM_VFW::close() bool CvCaptureCAM_VFW::grabFrame() { if( capWnd ) - { - SendMessage( capWnd, WM_CAP_GRAB_FRAME_NOSTOP, 0, 0 ); - return true; - } + return capGrabFrameNoStop(capWnd) == TRUE; + return false; } @@ -452,14 +481,13 @@ IplImage* CvCaptureCAM_VFW::retrieveFrame(int) BITMAPINFO vfmt; memset( &vfmt, 0, sizeof(vfmt)); BITMAPINFOHEADER& vfmt0 = vfmt.bmiHeader; - int sz, prevWidth, prevHeight; if( !capWnd ) return 0; - sz = capGetVideoFormat( capWnd, &vfmt, sizeof(vfmt)); - prevWidth = frame ? frame->width : 0; - prevHeight = frame ? frame->height : 0; + const DWORD sz = capGetVideoFormat( capWnd, &vfmt, sizeof(vfmt)); + const int prevWidth = frame ? frame->width : 0; + const int prevHeight = frame ? frame->height : 0; if( !hdr || hdr->lpData == 0 || sz == 0 ) return 0; @@ -470,8 +498,8 @@ IplImage* CvCaptureCAM_VFW::retrieveFrame(int) frame = cvCreateImage( cvSize( vfmt0.biWidth, vfmt0.biHeight ), 8, 3 ); } - if( vfmt.bmiHeader.biCompression != BI_RGB || - vfmt.bmiHeader.biBitCount != 24 ) + if( vfmt0.biCompression != BI_RGB || + vfmt0.biBitCount != 24 ) { BITMAPINFOHEADER vfmt1 = icvBitmapHeader( vfmt0.biWidth, vfmt0.biHeight, 24 ); @@ -518,15 +546,106 @@ double CvCaptureCAM_VFW::getProperty( int property_id ) switch( property_id ) { case CV_CAP_PROP_FRAME_WIDTH: - return frame ? frame->width : 0; + return widthSet; case CV_CAP_PROP_FRAME_HEIGHT: - return frame ? frame->height : 0; + return heightSet; case CV_CAP_PROP_FOURCC: return fourcc; + case CV_CAP_PROP_FPS: + { + CAPTUREPARMS params = {}; + if( capCaptureGetSetup(capWnd, ¶ms, sizeof(params)) ) + return 1e6 / params.dwRequestMicroSecPerFrame; + } + break; + default: + break; } return 0; } +bool CvCaptureCAM_VFW::setProperty(int property_id, double value) +{ + bool handledSize = false; + + switch( property_id ) + { + case CV_CAP_PROP_FRAME_WIDTH: + width = cvRound(value); + handledSize = true; + break; + case CV_CAP_PROP_FRAME_HEIGHT: + height = cvRound(value); + handledSize = true; + break; + case CV_CAP_PROP_FOURCC: + break; + case CV_CAP_PROP_FPS: + if( value > 0 ) + { + CAPTUREPARMS params; + if( capCaptureGetSetup(capWnd, ¶ms, sizeof(params)) ) + { + params.dwRequestMicroSecPerFrame = cvRound(1e6/value); + return capCaptureSetSetup(capWnd, ¶ms, sizeof(params)) == TRUE; + } + } + break; + default: + break; + } + + if ( handledSize ) + { + // If both width and height are set then change frame size. + if( width > 0 && height > 0 ) + { + const DWORD size = capGetVideoFormatSize(capWnd); + if( size == 0 ) + return false; + + unsigned char *pbi = new unsigned char[size]; + if( !pbi ) + return false; + + if( capGetVideoFormat(capWnd, pbi, size) != size ) + { + delete []pbi; + return false; + } + + BITMAPINFOHEADER& vfmt = ((BITMAPINFO*)pbi)->bmiHeader; + bool success = true; + if( width != vfmt.biWidth || height != vfmt.biHeight ) + { + // Change frame size. + vfmt.biWidth = width; + vfmt.biHeight = height; + vfmt.biSizeImage = height * ((width * vfmt.biBitCount + 31) / 32) * 4; + vfmt.biCompression = BI_RGB; + success = capSetVideoFormat(capWnd, pbi, size) == TRUE; + } + if( success ) + { + // Adjust capture window size. + CAPSTATUS status = {}; + capGetStatus(capWnd, &status, sizeof(status)); + ::SetWindowPos(capWnd, NULL, 0, 0, status.uiImageWidth, status.uiImageHeight, SWP_NOZORDER|SWP_NOMOVE); + // Store frame size. + widthSet = width; + heightSet = height; + } + delete []pbi; + width = height = -1; + + return success; + } + + return true; + } + + return false; +} CvCapture* cvCreateCameraCapture_VFW( int index ) { diff --git a/modules/highgui/src/grfmt_tiff.cpp b/modules/highgui/src/grfmt_tiff.cpp index 5179531f5..f40699f83 100644 --- a/modules/highgui/src/grfmt_tiff.cpp +++ b/modules/highgui/src/grfmt_tiff.cpp @@ -111,18 +111,21 @@ bool TiffDecoder::readHeader() bool result = false; close(); - TIFF* tif = TIFFOpen( m_filename.c_str(), "rb" ); + // TIFFOpen() mode flags are different to fopen(). A 'b' in mode "rb" has no effect when reading. + // http://www.remotesensing.org/libtiff/man/TIFFOpen.3tiff.html + TIFF* tif = TIFFOpen( m_filename.c_str(), "r" ); if( tif ) { - int wdth = 0, hght = 0, photometric = 0; + uint32 wdth = 0, hght = 0; + uint16 photometric = 0; m_tif = tif; if( TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &wdth ) && TIFFGetField( tif, TIFFTAG_IMAGELENGTH, &hght ) && TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photometric )) { - int bpp=8, ncn = photometric > 1 ? 3 : 1; + uint16 bpp=8, ncn = photometric > 1 ? 3 : 1; TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bpp ); TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &ncn ); @@ -175,12 +178,12 @@ bool TiffDecoder::readData( Mat& img ) if( m_tif && m_width && m_height ) { TIFF* tif = (TIFF*)m_tif; - int tile_width0 = m_width, tile_height0 = 0; + uint32 tile_width0 = m_width, tile_height0 = 0; int x, y, i; int is_tiled = TIFFIsTiled(tif); - int photometric; + uint16 photometric; TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photometric ); - int bpp = 8, ncn = photometric > 1 ? 3 : 1; + uint16 bpp = 8, ncn = photometric > 1 ? 3 : 1; TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bpp ); TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &ncn ); const int bitsPerByte = 8; @@ -235,11 +238,15 @@ bool TiffDecoder::readData( Mat& img ) { case 8: { + uchar * bstart = buffer; if( !is_tiled ) ok = TIFFReadRGBAStrip( tif, y, (uint32*)buffer ); else + { ok = TIFFReadRGBATile( tif, x, y, (uint32*)buffer ); - + //Tiles fill the buffer from the bottom up + bstart += (tile_height0 - tile_height) * tile_width0 * 4; + } if( !ok ) { close(); @@ -248,11 +255,11 @@ bool TiffDecoder::readData( Mat& img ) for( i = 0; i < tile_height; i++ ) if( color ) - icvCvt_BGRA2BGR_8u_C4C3R( buffer + i*tile_width*4, 0, + icvCvt_BGRA2BGR_8u_C4C3R( bstart + i*tile_width0*4, 0, data + x*3 + img.step*(tile_height - i - 1), 0, cvSize(tile_width,1), 2 ); else - icvCvt_BGRA2Gray_8u_C4C1R( buffer + i*tile_width*4, 0, + icvCvt_BGRA2Gray_8u_C4C1R( bstart + i*tile_width0*4, 0, data + x + img.step*(tile_height - i - 1), 0, cvSize(tile_width,1), 2 ); break; @@ -277,19 +284,19 @@ bool TiffDecoder::readData( Mat& img ) { if( ncn == 1 ) { - icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width*ncn, 0, + icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width0*ncn, 0, (ushort*)(data + img.step*i) + x*3, 0, cvSize(tile_width,1) ); } else if( ncn == 3 ) { - icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width*ncn, 0, + icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width0*ncn, 0, (ushort*)(data + img.step*i) + x*3, 0, cvSize(tile_width,1) ); } else { - icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width*ncn, 0, + icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, (ushort*)(data + img.step*i) + x*3, 0, cvSize(tile_width,1), 2 ); } @@ -299,12 +306,12 @@ bool TiffDecoder::readData( Mat& img ) if( ncn == 1 ) { memcpy((ushort*)(data + img.step*i)+x, - buffer16 + i*tile_width*ncn, + buffer16 + i*tile_width0*ncn, tile_width*sizeof(buffer16[0])); } else { - icvCvt_BGRA2Gray_16u_CnC1R(buffer16 + i*tile_width*ncn, 0, + icvCvt_BGRA2Gray_16u_CnC1R(buffer16 + i*tile_width0*ncn, 0, (ushort*)(data + img.step*i) + x, 0, cvSize(tile_width,1), ncn, 2 ); } @@ -332,13 +339,13 @@ bool TiffDecoder::readData( Mat& img ) if(dst_bpp == 32) { memcpy((float*)(data + img.step*i)+x, - buffer32 + i*tile_width*ncn, + buffer32 + i*tile_width0*ncn, tile_width*sizeof(buffer32[0])); } else { memcpy((double*)(data + img.step*i)+x, - buffer64 + i*tile_width*ncn, + buffer64 + i*tile_width0*ncn, tile_width*sizeof(buffer64[0])); } } diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 88ba8e4b2..af5383b14 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -57,6 +57,14 @@ #include #if defined WIN32 || defined WINCE + #if !defined _WIN32_WINNT + #ifdef HAVE_MSMF + #define _WIN32_WINNT 0x0600 // Windows Vista + #else + #define _WIN32_WINNT 0x0500 // Windows 2000 + #endif + #endif + #include #undef small #undef min diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index 84af3941a..64ebf0870 100644 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -1536,7 +1536,7 @@ CvWindow::CvWindow(QString name, int arg2) setWindowTitle(name); setObjectName(name); - setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not recieved without the explicit focus + setFocus( Qt::PopupFocusReason ); //#1695 arrow keys are not received without the explicit focus resize(400, 300); setMinimumSize(1, 1); diff --git a/modules/highgui/src/window_carbon.cpp b/modules/highgui/src/window_carbon.cpp index 722df2cdd..3d092e736 100644 --- a/modules/highgui/src/window_carbon.cpp +++ b/modules/highgui/src/window_carbon.cpp @@ -569,7 +569,7 @@ static int icvCreateTrackbar (const char* trackbar_name, //pad size maxvalue in pixel Point qdSize; - char valueinchar[strlen(trackbar_name)+1 +1 +1+nbDigit+1];//lenght+\n +space +(+nbDigit+) + char valueinchar[strlen(trackbar_name)+1 +1 +1+nbDigit+1];//length+\n +space +(+nbDigit+) sprintf(valueinchar, "%s (%d)",trackbar_name, trackbar->maxval); SInt16 baseline; CFStringRef text = CFStringCreateWithCString(NULL,valueinchar,kCFStringEncodingASCII); diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 7b78ebc81..b5cbc5565 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -43,31 +43,16 @@ #if defined WIN32 || defined _WIN32 -#define COMPILE_MULTIMON_STUBS // Required for multi-monitor support -#ifndef _MULTIMON_USE_SECURE_CRT -# define _MULTIMON_USE_SECURE_CRT 0 // some MinGW platforms have no strncpy_s -#endif - -#if defined SM_CMONITORS && !defined MONITOR_DEFAULTTONEAREST -# define MONITOR_DEFAULTTONULL 0x00000000 -# define MONITOR_DEFAULTTOPRIMARY 0x00000001 -# define MONITOR_DEFAULTTONEAREST 0x00000002 -# define MONITORINFOF_PRIMARY 0x00000001 -#endif -#ifndef __inout -# define __inout -#endif - #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" #endif #include -#include #include #include #include #include +#include #ifdef HAVE_OPENGL #include @@ -1451,8 +1436,6 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM if( window->on_mouse ) { POINT pt; - RECT rect; - SIZE size = {0,0}; int flags = (wParam & MK_LBUTTON ? CV_EVENT_FLAG_LBUTTON : 0)| (wParam & MK_RBUTTON ? CV_EVENT_FLAG_RBUTTON : 0)| @@ -1475,15 +1458,26 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM if( uMsg == WM_LBUTTONUP || uMsg == WM_RBUTTONUP || uMsg == WM_MBUTTONUP ) ReleaseCapture(); - pt.x = LOWORD( lParam ); - pt.y = HIWORD( lParam ); + pt.x = GET_X_LPARAM( lParam ); + pt.y = GET_Y_LPARAM( lParam ); - GetClientRect( window->hwnd, &rect ); - icvGetBitmapData( window, &size, 0, 0 ); + if (window->flags & CV_WINDOW_AUTOSIZE) + { + // As user can't change window size, do not scale window coordinates. Underlying windowing system + // may prevent full window from being displayed and in this case coordinates should not be scaled. + window->on_mouse( event, pt.x, pt.y, flags, window->on_mouse_param ); + } else { + // Full window is displayed using different size. Scale coordinates to match underlying positions. + RECT rect; + SIZE size = {0, 0}; - window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), - pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags, - window->on_mouse_param ); + GetClientRect( window->hwnd, &rect ); + icvGetBitmapData( window, &size, 0, 0 ); + + window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), + pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags, + window->on_mouse_param ); + } } break; diff --git a/modules/highgui/test/test_ffmpeg.cpp b/modules/highgui/test/test_ffmpeg.cpp index 30410eaab..55bf95221 100644 --- a/modules/highgui/test/test_ffmpeg.cpp +++ b/modules/highgui/test/test_ffmpeg.cpp @@ -88,7 +88,7 @@ public: stringstream s; s << tag; - const string filename = "output_"+s.str()+".avi"; + const string filename = tempfile((s.str()+".avi").c_str()); try { diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 86954e3e1..aa1a84506 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -392,7 +392,13 @@ TEST(Highgui_Jpeg, encode_empty) #define int64 int64_hack_ #include "tiff.h" +#ifdef ANDROID +// Test disabled as it uses a lot of memory. +// It is killed with SIGKILL by out of memory killer. +TEST(Highgui_Tiff, DISABLED_decode_tile16384x16384) +#else TEST(Highgui_Tiff, decode_tile16384x16384) +#endif { // see issue #2161 cv::Mat big(16384, 16384, CV_8UC1, cv::Scalar::all(0)); @@ -408,8 +414,8 @@ TEST(Highgui_Tiff, decode_tile16384x16384) try { - cv::imread(file3); - EXPECT_NO_THROW(cv::imread(file4)); + cv::imread(file3, CV_LOAD_IMAGE_UNCHANGED); + EXPECT_NO_THROW(cv::imread(file4, CV_LOAD_IMAGE_UNCHANGED)); } catch(const std::bad_alloc&) { @@ -419,4 +425,93 @@ TEST(Highgui_Tiff, decode_tile16384x16384) remove(file3.c_str()); remove(file4.c_str()); } + +TEST(Highgui_Tiff, write_read_16bit_big_little_endian) +{ + // see issue #2601 "16-bit Grayscale TIFF Load Failures Due to Buffer Underflow and Endianness" + + // Setup data for two minimal 16-bit grayscale TIFF files in both endian formats + uchar tiff_sample_data[2][86] = { { + // Little endian + 0x49, 0x49, 0x2a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xad, 0xde, 0xef, 0xbe, 0x06, 0x00, 0x00, 0x01, + 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, + 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x01, 0x04, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }, { + // Big endian + 0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x0c, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x06, 0x01, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, + 0x00, 0x00, 0x01, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x11, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x17, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x04 } + }; + + // Test imread() for both a little endian TIFF and big endian TIFF + for (int i = 0; i < 2; i++) + { + string filename = cv::tempfile(".tiff"); + + // Write sample TIFF file + FILE* fp = fopen(filename.c_str(), "wb"); + ASSERT_TRUE(fp != NULL); + ASSERT_EQ((size_t)1, fwrite(tiff_sample_data, 86, 1, fp)); + fclose(fp); + + Mat img = imread(filename, CV_LOAD_IMAGE_UNCHANGED); + + EXPECT_EQ(1, img.rows); + EXPECT_EQ(2, img.cols); + EXPECT_EQ(CV_16U, img.type()); + EXPECT_EQ(sizeof(ushort), img.elemSize()); + EXPECT_EQ(1, img.channels()); + EXPECT_EQ(0xDEAD, img.at(0,0)); + EXPECT_EQ(0xBEEF, img.at(0,1)); + + remove(filename.c_str()); + } +} + +class CV_GrfmtReadTifTiledWithNotFullTiles: public cvtest::BaseTest +{ +public: + void run(int) + { + try + { + /* see issue #3472 - dealing with tiled images where the tile size is + * not a multiple of image size. + * The tiled images were created with 'convert' from ImageMagick, + * using the command 'convert -define tiff:tile-geometry=128x128 -depth [8|16] + * Note that the conversion to 16 bits expands the range from 0-255 to 0-255*255, + * so the test converts back but rounding errors cause small differences. + */ + cv::Mat img = imread(string(ts->get_data_path()) + "readwrite/non_tiled.tif",-1); + if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + ASSERT_TRUE(img.channels() == 3); + cv::Mat tiled8 = imread(string(ts->get_data_path()) + "readwrite/tiled_8.tif", -1); + if (tiled8.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), img, tiled8); + + cv::Mat tiled16 = imread(string(ts->get_data_path()) + "readwrite/tiled_16.tif", -1); + if (tiled16.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + ASSERT_TRUE(tiled16.elemSize() == 6); + tiled16.convertTo(tiled8, CV_8UC3, 1./256.); + ASSERT_PRED_FORMAT2(cvtest::MatComparator(2, 0), img, tiled8); + // What about 32, 64 bit? + } + catch(...) + { + ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); + } + ts->set_failed_test_info(cvtest::TS::OK); + } +}; + +TEST(Highgui_Tiff, decode_tile_remainder) +{ + CV_GrfmtReadTifTiledWithNotFullTiles test; test.safe_run(); +} + #endif diff --git a/modules/highgui/test/test_video_io.cpp b/modules/highgui/test/test_video_io.cpp index cf47b73a6..755bcd067 100644 --- a/modules/highgui/test/test_video_io.cpp +++ b/modules/highgui/test/test_video_io.cpp @@ -332,9 +332,7 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt } } - printf("Before saved release for %s\n", tmp_name.c_str()); cvReleaseCapture( &saved ); - printf("After release\n"); ts->printf(ts->LOG, "end test function : ImagesVideo \n"); } diff --git a/modules/imgproc/doc/feature_detection.rst b/modules/imgproc/doc/feature_detection.rst index 4f922f2a7..861c16432 100644 --- a/modules/imgproc/doc/feature_detection.rst +++ b/modules/imgproc/doc/feature_detection.rst @@ -101,7 +101,7 @@ Harris edge detector. .. ocv:pyfunction:: cv2.cornerHarris(src, blockSize, ksize, k[, dst[, borderType]]) -> dst -.. ocv:cfunction:: void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 ) +.. ocv:cfunction:: void cvCornerHarris( const CvArr* image, CvArr* harris_response, int block_size, int aperture_size=3, double k=0.04 ) .. ocv:pyoldfunction:: cv.CornerHarris(image, harris_dst, blockSize, aperture_size=3, k=0.04) -> None diff --git a/modules/imgproc/doc/geometric_transformations.rst b/modules/imgproc/doc/geometric_transformations.rst index 229183e5f..602610b2f 100644 --- a/modules/imgproc/doc/geometric_transformations.rst +++ b/modules/imgproc/doc/geometric_transformations.rst @@ -256,6 +256,57 @@ The function computes an inverse affine transformation represented by The result is also a :math:`2 \times 3` matrix of the same type as ``M`` . +LinearPolar +----------- +Remaps an image to polar space. + +.. ocv:cfunction:: void cvLinearPolar( const CvArr* src, CvArr* dst, CvPoint2D32f center, double maxRadius, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS ) + + :param src: Source image + + :param dst: Destination image + + :param center: The transformation center; + + :param maxRadius: Inverse magnitude scale parameter. See below + + :param flags: A combination of interpolation methods and the following optional flags: + + * **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero + + * **CV_WARP_INVERSE_MAP** See below + +The function ``cvLinearPolar`` transforms the source image using the following transformation: + + * + Forward transformation (``CV_WARP_INVERSE_MAP`` is not set): + + .. math:: + + dst( \phi , \rho ) = src(x,y) + + + * + Inverse transformation (``CV_WARP_INVERSE_MAP`` is set): + + .. math:: + + dst(x,y) = src( \phi , \rho ) + + +where + + .. math:: + + \rho = (src.width/maxRadius) \cdot \sqrt{x^2 + y^2} , \phi =atan(y/x) + + +The function can not operate in-place. + +.. note:: + + * An example using the LinearPolar operation can be found at opencv_source_code/samples/c/polar_transforms.c + LogPolar @@ -264,7 +315,7 @@ Remaps an image to log-polar space. .. ocv:cfunction:: void cvLogPolar( const CvArr* src, CvArr* dst, CvPoint2D32f center, double M, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS ) -.. ocv:pyoldfunction:: cv.LogPolar(src, dst, center, M, flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS)-> None +.. ocv:pyoldfunction:: cv.LogPolar(src, dst, center, M, flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)-> None :param src: Source image @@ -320,7 +371,7 @@ Applies a generic geometrical transformation to an image. .. ocv:pyfunction:: cv2.remap(src, map1, map2, interpolation[, dst[, borderMode[, borderValue]]]) -> dst .. ocv:cfunction:: void cvRemap( const CvArr* src, CvArr* dst, const CvArr* mapx, const CvArr* mapy, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, CvScalar fillval=cvScalarAll(0) ) -.. ocv:pyoldfunction:: cv.Remap(src, dst, mapx, mapy, flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0))-> None +.. ocv:pyoldfunction:: cv.Remap(src, dst, mapx, mapy, flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0))-> None :param src: Source image. @@ -488,7 +539,7 @@ Applies a perspective transformation to an image. .. ocv:cfunction:: void cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, CvScalar fillval=cvScalarAll(0) ) -.. ocv:pyoldfunction:: cv.WarpPerspective(src, dst, mapMatrix, flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0))-> None +.. ocv:pyoldfunction:: cv.WarpPerspective(src, dst, mapMatrix, flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0))-> None :param src: input image. diff --git a/modules/imgproc/doc/miscellaneous_transformations.rst b/modules/imgproc/doc/miscellaneous_transformations.rst index e3c459d68..7825a2458 100644 --- a/modules/imgproc/doc/miscellaneous_transformations.rst +++ b/modules/imgproc/doc/miscellaneous_transformations.rst @@ -113,6 +113,8 @@ But in case of a non-linear transformation, an input RGB image should be normali If you use ``cvtColor`` with 8-bit images, the conversion will have some information lost. For many applications, this will not be noticeable but it is recommended to use 32-bit images in applications that need the full range of colors or that convert an image before an operation and then convert back. +If conversion adds the alpha channel, its value will set to the maximum of corresponding channel range: 255 for ``CV_8U``, 65535 for ``CV_16U``, 1 for ``CV_32F``. + The function can do the following transformations: * @@ -127,7 +129,7 @@ The function can do the following transformations: .. math:: - \text{Gray to RGB[A]:} \quad R \leftarrow Y, G \leftarrow Y, B \leftarrow Y, A \leftarrow 0 + \text{Gray to RGB[A]:} \quad R \leftarrow Y, G \leftarrow Y, B \leftarrow Y, A \leftarrow \max (ChannelRange) The conversion from a RGB image to gray is done with: @@ -502,7 +504,7 @@ Fills a connected component with the given color. :param image: Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the ``FLOODFILL_MASK_ONLY`` flag is set in the second variant of the function. See the details below. - :param mask: (For the second function only) Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function uses and updates the mask, so you take responsibility of initializing the ``mask`` content. Flood-filling cannot go across non-zero pixels in the mask. For example, an edge detector output can be used as a mask to stop filling at edges. It is possible to use the same mask in multiple calls to the function to make sure the filled area does not overlap. + :param mask: Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than ``image``. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in ``flags`` as described below. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap. .. note:: Since the mask is larger than the filled image, a pixel :math:`(x, y)` in ``image`` corresponds to the pixel :math:`(x+1, y+1)` in the ``mask`` . @@ -516,11 +518,11 @@ Fills a connected component with the given color. :param rect: Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain. - :param flags: Operation flags. Lower bits contain a connectivity value, 4 (default) or 8, used within the function. Connectivity determines which neighbors of a pixel are considered. Upper bits can be 0 or a combination of the following flags: + :param flags: Operation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the ``mask`` (the default value is 1). For example, ``4 | ( 255 << 8 )`` will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (``|``): * **FLOODFILL_FIXED_RANGE** If set, the difference between the current pixel and seed pixel is considered. Otherwise, the difference between neighbor pixels is considered (that is, the range is floating). - * **FLOODFILL_MASK_ONLY** If set, the function does not change the image ( ``newVal`` is ignored), but fills the mask. The flag can be used for the second variant only. + * **FLOODFILL_MASK_ONLY** If set, the function does not change the image ( ``newVal`` is ignored), and only fills the mask with the value specified in bits 8-16 of ``flags`` as described above. This option only make sense in function variants that have the ``mask`` parameter. The functions ``floodFill`` fill a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at :math:`(x,y)` is considered to belong to the repainted domain if: @@ -640,7 +642,7 @@ The functions calculate one or more integral images for the source image as foll \texttt{tilted} (X,Y) = \sum _{y contours - :param image: Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as ``binary`` . You can use :ocv:func:`compare` , :ocv:func:`inRange` , :ocv:func:`threshold` , :ocv:func:`adaptiveThreshold` , :ocv:func:`Canny` , and others to create a binary image out of a grayscale or color one. The function modifies the ``image`` while extracting the contours. + :param image: Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as ``binary`` . You can use :ocv:func:`compare` , :ocv:func:`inRange` , :ocv:func:`threshold` , :ocv:func:`adaptiveThreshold` , :ocv:func:`Canny` , and others to create a binary image out of a grayscale or color one. The function modifies the ``image`` while extracting the contours. If mode equals to ``CV_RETR_CCOMP`` or ``CV_RETR_FLOODFILL``, the input can also be a 32-bit integer image of labels (``CV_32SC1``). :param contours: Detected contours. Each contour is stored as a vector of points. diff --git a/modules/imgproc/include/opencv2/imgproc/imgproc_c.h b/modules/imgproc/include/opencv2/imgproc/imgproc_c.h index 4ba1b2b26..46d9f0139 100644 --- a/modules/imgproc/include/opencv2/imgproc/imgproc_c.h +++ b/modules/imgproc/include/opencv2/imgproc/imgproc_c.h @@ -304,7 +304,7 @@ CVAPI(int) cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_c int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), CvPoint offset CV_DEFAULT(cvPoint(0,0))); -/* Initalizes contour retrieving process. +/* Initializes contour retrieving process. Calls cvStartFindContours. Calls cvFindNextContour until null pointer is returned or some other condition becomes true. @@ -334,7 +334,7 @@ CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, int minimal_perimeter CV_DEFAULT(0), int recursive CV_DEFAULT(0)); -/* Initalizes Freeman chain reader. +/* Initializes Freeman chain reader. The reader is used to iteratively get coordinates of all the chain points. If the Freeman codes should be read as is, a simple sequence reader should be used */ CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader ); @@ -573,7 +573,7 @@ CVAPI(void) cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, /* Harris corner detector: Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */ -CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_responce, +CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_response, int block_size, int aperture_size CV_DEFAULT(3), double k CV_DEFAULT(0.04) ); diff --git a/modules/imgproc/perf/perf_filter2d.cpp b/modules/imgproc/perf/perf_filter2d.cpp index b897d6ac0..98992e98e 100644 --- a/modules/imgproc/perf/perf_filter2d.cpp +++ b/modules/imgproc/perf/perf_filter2d.cpp @@ -8,7 +8,7 @@ using std::tr1::make_tuple; using std::tr1::get; -CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101); +CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101) typedef TestBaseWithParam< tr1::tuple > TestFilter2d; typedef TestBaseWithParam< tr1::tuple > Image_KernelSize; diff --git a/modules/imgproc/src/approx.cpp b/modules/imgproc/src/approx.cpp index c2831ca70..8bd76c3cb 100644 --- a/modules/imgproc/src/approx.cpp +++ b/modules/imgproc/src/approx.cpp @@ -220,7 +220,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, current = temp.next; /* Pass 2. - Performs non-maxima supression */ + Performs non-maxima suppression */ do { int k2 = current->k >> 1; diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 44fd42a2a..2161db91c 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -171,7 +171,7 @@ void cv::Canny( InputArray _src, OutputArray _dst, #define CANNY_PUSH(d) *(d) = uchar(2), *stack_top++ = (d) #define CANNY_POP(d) (d) = *--stack_top - // calculate magnitude and angle of gradient, perform non-maxima supression. + // calculate magnitude and angle of gradient, perform non-maxima suppression. // fill the map with one of the following values: // 0 - the pixel might belong to an edge // 1 - the pixel can not belong to an edge diff --git a/modules/imgproc/src/clahe.cpp b/modules/imgproc/src/clahe.cpp index 4ce479713..9ecf792da 100644 --- a/modules/imgproc/src/clahe.cpp +++ b/modules/imgproc/src/clahe.cpp @@ -49,8 +49,8 @@ namespace class CLAHE_CalcLut_Body : public cv::ParallelLoopBody { public: - CLAHE_CalcLut_Body(const cv::Mat& src, cv::Mat& lut, cv::Size tileSize, int tilesX, int tilesY, int clipLimit, float lutScale) : - src_(src), lut_(lut), tileSize_(tileSize), tilesX_(tilesX), tilesY_(tilesY), clipLimit_(clipLimit), lutScale_(lutScale) + CLAHE_CalcLut_Body(const cv::Mat& src, cv::Mat& lut, cv::Size tileSize, int tilesX, int clipLimit, float lutScale) : + src_(src), lut_(lut), tileSize_(tileSize), tilesX_(tilesX), clipLimit_(clipLimit), lutScale_(lutScale) { } @@ -62,7 +62,6 @@ namespace cv::Size tileSize_; int tilesX_; - int tilesY_; int clipLimit_; float lutScale_; }; @@ -293,7 +292,7 @@ namespace clipLimit = std::max(clipLimit, 1); } - CLAHE_CalcLut_Body calcLutBody(srcForLut, lut_, tileSize, tilesX_, tilesY_, clipLimit, lutScale); + CLAHE_CalcLut_Body calcLutBody(srcForLut, lut_, tileSize, tilesX_, clipLimit, lutScale); cv::parallel_for_(cv::Range(0, tilesX_ * tilesY_), calcLutBody); CLAHE_Interpolation_Body interpolationBody(src, dst, lut_, tileSize, tilesX_, tilesY_); diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index 15c214ef9..a0ff714bb 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -301,6 +301,7 @@ static ippiReorderFunc ippiSwapChannelsC4RTab[] = 0, (ippiReorderFunc)ippiSwapChannels_32f_AC4R, 0, 0 }; +#if 0 static ippiColor2GrayFunc ippiColor2GrayC3Tab[] = { (ippiColor2GrayFunc)ippiColorToGray_8u_C3C1R, 0, (ippiColor2GrayFunc)ippiColorToGray_16u_C3C1R, 0, @@ -312,6 +313,7 @@ static ippiColor2GrayFunc ippiColor2GrayC4Tab[] = (ippiColor2GrayFunc)ippiColorToGray_8u_AC4C1R, 0, (ippiColor2GrayFunc)ippiColorToGray_16u_AC4C1R, 0, 0, (ippiColor2GrayFunc)ippiColorToGray_32f_AC4C1R, 0, 0 }; +#endif static ippiGeneralFunc ippiRGB2GrayC3Tab[] = { @@ -3214,7 +3216,7 @@ struct YUV420p2RGB888Invoker : ParallelLoopBody const int rangeBegin = range.start * 2; const int rangeEnd = range.end * 2; - size_t uvsteps[2] = {width/2, stride - width/2}; + int uvsteps[2] = {width/2, stride - width/2}; int usIdx = ustepIdx, vsIdx = vstepIdx; const uchar* y1 = my1 + rangeBegin * stride; @@ -3282,7 +3284,7 @@ struct YUV420p2RGBA8888Invoker : ParallelLoopBody int rangeBegin = range.start * 2; int rangeEnd = range.end * 2; - size_t uvsteps[2] = {width/2, stride - width/2}; + int uvsteps[2] = {width/2, stride - width/2}; int usIdx = ustepIdx, vsIdx = vstepIdx; const uchar* y1 = my1 + rangeBegin * stride; diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 1d05d3c2c..6cdcf3cfb 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -453,8 +453,11 @@ void FilterEngine::apply(const Mat& src, Mat& dst, dstOfs.y + srcRoi.height <= dst.rows ); int y = start(src, srcRoi, isolated); - proceed( src.data + y*src.step, (int)src.step, endY - startY, - dst.data + dstOfs.y*dst.step + dstOfs.x*dst.elemSize(), (int)dst.step ); + proceed( src.data + y*src.step + + srcRoi.x*src.elemSize(), + (int)src.step, endY - startY, + dst.data + dstOfs.y*dst.step + + dstOfs.x*dst.elemSize(), (int)dst.step ); } } diff --git a/modules/imgproc/src/floodfill.cpp b/modules/imgproc/src/floodfill.cpp index 74047676e..db2563dde 100644 --- a/modules/imgproc/src/floodfill.cpp +++ b/modules/imgproc/src/floodfill.cpp @@ -41,7 +41,7 @@ #include "precomp.hpp" -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic ignored "-Warray-bounds" #endif diff --git a/modules/imgproc/src/gcgraph.hpp b/modules/imgproc/src/gcgraph.hpp index 59c9744e7..92b9e124b 100644 --- a/modules/imgproc/src/gcgraph.hpp +++ b/modules/imgproc/src/gcgraph.hpp @@ -380,6 +380,6 @@ bool GCGraph::inSourceSegment( int i ) { CV_Assert( i>=0 && i<(int)vtcs.size() ); return vtcs[i].t == 0; -}; +} #endif diff --git a/modules/imgproc/src/generalized_hough.cpp b/modules/imgproc/src/generalized_hough.cpp index 846a55fe9..8d0ac753f 100644 --- a/modules/imgproc/src/generalized_hough.cpp +++ b/modules/imgproc/src/generalized_hough.cpp @@ -300,7 +300,7 @@ namespace obj.info()->addParam(obj, "votesThreshold", obj.votesThreshold, false, 0, 0, "The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected."); obj.info()->addParam(obj, "dp", obj.dp, false, 0, 0, - "Inverse ratio of the accumulator resolution to the image resolution.")); + "Inverse ratio of the accumulator resolution to the image resolution.")) GHT_Ballard_Pos::GHT_Ballard_Pos() { @@ -466,7 +466,7 @@ namespace obj.info()->addParam(obj, "maxScale", obj.maxScale, false, 0, 0, "Maximal scale to detect."); obj.info()->addParam(obj, "scaleStep", obj.scaleStep, false, 0, 0, - "Scale step.")); + "Scale step.")) GHT_Ballard_PosScale::GHT_Ballard_PosScale() { @@ -631,7 +631,7 @@ namespace obj.info()->addParam(obj, "maxAngle", obj.maxAngle, false, 0, 0, "Maximal rotation angle to detect in degrees."); obj.info()->addParam(obj, "angleStep", obj.angleStep, false, 0, 0, - "Angle step in degrees.")); + "Angle step in degrees.")) GHT_Ballard_PosRotation::GHT_Ballard_PosRotation() { @@ -878,7 +878,7 @@ namespace obj.info()->addParam(obj, "dp", obj.dp, false, 0, 0, "Inverse ratio of the accumulator resolution to the image resolution."); obj.info()->addParam(obj, "posThresh", obj.posThresh, false, 0, 0, - "Position threshold.")); + "Position threshold.")) GHT_Guil_Full::GHT_Guil_Full() { diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 2c87efe44..dcd718fb6 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -72,7 +72,7 @@ namespace cv return func(values, dataPointer, step, size) >= 0; } - bool IPPSet(const cv::Scalar &value, void *dataPointer, int step, IppiSize &size, int channels, int depth) + static bool IPPSet(const cv::Scalar &value, void *dataPointer, int step, IppiSize &size, int channels, int depth) { if( channels == 1 ) { @@ -1217,8 +1217,13 @@ public: alpha(_alpha), _beta(__beta), ssize(_ssize), dsize(_dsize), ksize(_ksize), xmin(_xmin), xmax(_xmax) { + CV_Assert(ksize <= MAX_ESIZE); } +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif virtual void operator() (const Range& range) const { int dy, cn = src.channels(); @@ -1267,6 +1272,9 @@ public: vresize( (const WT**)rows, (T*)(dst.data + dst.step*dy), beta, dsize.width ); } } +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +# pragma GCC diagnostic pop +#endif private: Mat src; @@ -1274,7 +1282,9 @@ private: const int* xofs, *yofs; const AT* alpha, *_beta; Size ssize, dsize; - int ksize, xmin, xmax; + const int ksize, xmin, xmax; + + resizeGeneric_Invoker& operator = (const resizeGeneric_Invoker&); }; template @@ -2201,15 +2211,15 @@ struct RemapVec_8u int operator()( const Mat& _src, void* _dst, const short* XY, const ushort* FXY, const void* _wtab, int width ) const { - int cn = _src.channels(); + int cn = _src.channels(), x = 0, sstep = (int)_src.step; - if( (cn != 1 && cn != 3 && cn != 4) || !checkHardwareSupport(CV_CPU_SSE2) ) + if( (cn != 1 && cn != 3 && cn != 4) || !checkHardwareSupport(CV_CPU_SSE2) || + sstep > 0x8000 ) return 0; const uchar *S0 = _src.data, *S1 = _src.data + _src.step; const short* wtab = cn == 1 ? (const short*)_wtab : &BilinearTab_iC4[0][0][0]; uchar* D = (uchar*)_dst; - int x = 0, sstep = (int)_src.step; __m128i delta = _mm_set1_epi32(INTER_REMAP_COEF_SCALE/2); __m128i xy2ofs = _mm_set1_epi32(cn + (sstep << 16)); __m128i z = _mm_setzero_si128(); @@ -3394,31 +3404,33 @@ class IPPwarpAffineInvoker : public ParallelLoopBody { public: - IPPwarpAffineInvoker(Mat &_src, Mat &_dst, double (&_coeffs)[2][3], int &_interpolation, int &_borderType, const Scalar &_borderValue, ippiWarpAffineBackFunc _func, bool *_ok) : - ParallelLoopBody(), src(_src), dst(_dst), mode(_interpolation), coeffs(_coeffs), borderType(_borderType), borderValue(_borderValue), func(_func), ok(_ok) - { - *ok = true; - } + IPPwarpAffineInvoker(Mat &_src, Mat &_dst, double (&_coeffs)[2][3], int &_interpolation, int &_borderType, + const Scalar &_borderValue, ippiWarpAffineBackFunc _func, bool *_ok) : + ParallelLoopBody(), src(_src), dst(_dst), coeffs(_coeffs), mode(_interpolation), borderType(_borderType), + borderValue(_borderValue), func(_func), ok(_ok) + { + *ok = true; + } - virtual void operator() (const Range& range) const - { - IppiSize srcsize = { src.cols, src.rows }; - IppiRect srcroi = { 0, 0, src.cols, src.rows }; - IppiRect dstroi = { 0, range.start, dst.cols, range.end - range.start }; - int cnn = src.channels(); - if( borderType == BORDER_CONSTANT ) - { - IppiSize setSize = { dst.cols, range.end - range.start }; - void *dataPointer = dst.data + dst.step[0] * range.start; - if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) - { - *ok = false; - return; - } - } - if( func( src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode ) < 0) ////Aug 2013: problem in IPP 7.1, 8.0 : sometimes function return ippStsCoeffErr - *ok = false; - } + virtual void operator() (const Range& range) const + { + IppiSize srcsize = { src.cols, src.rows }; + IppiRect srcroi = { 0, 0, src.cols, src.rows }; + IppiRect dstroi = { 0, range.start, dst.cols, range.end - range.start }; + int cnn = src.channels(); + if( borderType == BORDER_CONSTANT ) + { + IppiSize setSize = { dst.cols, range.end - range.start }; + void *dataPointer = dst.data + dst.step[0] * range.start; + if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) + { + *ok = false; + return; + } + } + if( func( src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode ) < 0) ////Aug 2013: problem in IPP 7.1, 8.0 : sometimes function return ippStsCoeffErr + *ok = false; + } private: Mat &src; Mat &dst; @@ -3542,7 +3554,6 @@ class warpPerspectiveInvoker : public ParallelLoopBody { public: - warpPerspectiveInvoker(const Mat &_src, Mat &_dst, double *_M, int _interpolation, int _borderType, const Scalar &_borderValue) : ParallelLoopBody(), src(_src), dst(_dst), M(_M), interpolation(_interpolation), @@ -3634,32 +3645,34 @@ class IPPwarpPerspectiveInvoker : public ParallelLoopBody { public: - IPPwarpPerspectiveInvoker(Mat &_src, Mat &_dst, double (&_coeffs)[3][3], int &_interpolation, int &_borderType, const Scalar &_borderValue, ippiWarpPerspectiveBackFunc _func, bool *_ok) : - ParallelLoopBody(), src(_src), dst(_dst), mode(_interpolation), coeffs(_coeffs), borderType(_borderType), borderValue(_borderValue), func(_func), ok(_ok) - { - *ok = true; - } + IPPwarpPerspectiveInvoker(Mat &_src, Mat &_dst, double (&_coeffs)[3][3], int &_interpolation, + int &_borderType, const Scalar &_borderValue, ippiWarpPerspectiveBackFunc _func, bool *_ok) : + ParallelLoopBody(), src(_src), dst(_dst), coeffs(_coeffs), mode(_interpolation), + borderType(_borderType), borderValue(_borderValue), func(_func), ok(_ok) + { + *ok = true; + } - virtual void operator() (const Range& range) const - { - IppiSize srcsize = {src.cols, src.rows}; - IppiRect srcroi = {0, 0, src.cols, src.rows}; - IppiRect dstroi = {0, range.start, dst.cols, range.end - range.start}; - int cnn = src.channels(); + virtual void operator() (const Range& range) const + { + IppiSize srcsize = {src.cols, src.rows}; + IppiRect srcroi = {0, 0, src.cols, src.rows}; + IppiRect dstroi = {0, range.start, dst.cols, range.end - range.start}; + int cnn = src.channels(); - if( borderType == BORDER_CONSTANT ) - { - IppiSize setSize = {dst.cols, range.end - range.start}; - void *dataPointer = dst.data + dst.step[0] * range.start; - if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) - { - *ok = false; - return; - } - } - if( func(src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode) < 0) - *ok = false; - } + if( borderType == BORDER_CONSTANT ) + { + IppiSize setSize = {dst.cols, range.end - range.start}; + void *dataPointer = dst.data + dst.step[0] * range.start; + if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) + { + *ok = false; + return; + } + } + if( func(src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode) < 0) + *ok = false; + } private: Mat &src; Mat &dst; diff --git a/modules/imgproc/src/moments.cpp b/modules/imgproc/src/moments.cpp index 784a61b8d..2fca862bc 100644 --- a/modules/imgproc/src/moments.cpp +++ b/modules/imgproc/src/moments.cpp @@ -197,6 +197,10 @@ static void icvContourMoments( CvSeq* contour, CvMoments* moments ) \****************************************************************************************/ template +#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 9 +// Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60196 +__attribute__((optimize("no-tree-vectorize"))) +#endif static void momentsInTile( const cv::Mat& img, double* moments ) { cv::Size size = img.size(); diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index 19636bc96..fa1f8acbf 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1234,7 +1234,7 @@ static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst, return false; } } - for( x = 0; y < kernel.cols; x++ ) + for( x = 0; x < kernel.cols; x++ ) { if( kernel.at(anchor.y, x) != 0 ) continue; diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index bbce3deed..c0ea05ea2 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -718,7 +718,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, ddepth = sdepth; _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) ); Mat dst = _dst.getMat(); - if( borderType != BORDER_CONSTANT && normalize ) + if( borderType != BORDER_CONSTANT && normalize && (borderType & BORDER_ISOLATED) != 0 ) { if( src.rows == 1 ) ksize.height = 1; @@ -837,7 +837,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); - if( borderType != BORDER_CONSTANT ) + if( borderType != BORDER_CONSTANT && (borderType & BORDER_ISOLATED) != 0 ) { if( src.rows == 1 ) ksize.height = 1; diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index e20b1a207..75fddfd04 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -1225,7 +1225,7 @@ CV_FitLineTest::CV_FitLineTest() max_noise = 0.05; } -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Warray-bounds" #endif @@ -1301,7 +1301,7 @@ void CV_FitLineTest::generate_point_set( void* pointsSet ) } } -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic pop #endif @@ -1329,7 +1329,7 @@ void CV_FitLineTest::run_func() cv::fitLine(cv::cvarrToMat(points), (cv::Vec6f&)line[0], dist_type, 0, reps, aeps); } -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Warray-bounds" #endif @@ -1412,7 +1412,7 @@ _exit_: return code; } -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic pop #endif diff --git a/modules/imgproc/test/test_cvtyuv.cpp b/modules/imgproc/test/test_cvtyuv.cpp index bd8d95dc7..0cce64cdb 100644 --- a/modules/imgproc/test/test_cvtyuv.cpp +++ b/modules/imgproc/test/test_cvtyuv.cpp @@ -603,7 +603,7 @@ CV_ENUM(YUVCVTS, CV_YUV2RGB_NV12, CV_YUV2BGR_NV12, CV_YUV2RGB_NV21, CV_YUV2BGR_N CV_YUV2RGBA_YUY2, CV_YUV2BGRA_YUY2, CV_YUV2RGBA_YVYU, CV_YUV2BGRA_YVYU, CV_YUV2GRAY_420, CV_YUV2GRAY_UYVY, CV_YUV2GRAY_YUY2, CV_YUV2BGR, CV_YUV2RGB, CV_RGB2YUV_YV12, CV_BGR2YUV_YV12, CV_RGBA2YUV_YV12, - CV_BGRA2YUV_YV12, CV_RGB2YUV_I420, CV_BGR2YUV_I420, CV_RGBA2YUV_I420, CV_BGRA2YUV_I420); + CV_BGRA2YUV_YV12, CV_RGB2YUV_I420, CV_BGR2YUV_I420, CV_RGBA2YUV_I420, CV_BGRA2YUV_I420) typedef ::testing::TestWithParam Imgproc_ColorYUV; diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index efbad9974..c860a6f11 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -1886,3 +1886,35 @@ protected: }; TEST(Imgproc_Filtering, supportedFormats) { CV_FilterSupportedFormatsTest test; test.safe_run(); } + +TEST(Imgproc_Blur, borderTypes) +{ + Size kernelSize(3, 3); + + /// ksize > src_roi.size() + Mat src(3, 3, CV_8UC1, cv::Scalar::all(255)), dst; + Mat src_roi = src(Rect(1, 1, 1, 1)); + src_roi.setTo(cv::Scalar::all(0)); + + // should work like !BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE); + EXPECT_EQ(227, dst.at(0, 0)); + + // should work like BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE | BORDER_ISOLATED); + EXPECT_EQ(0, dst.at(0, 0)); + + /// ksize <= src_roi.size() + src = Mat(5, 5, CV_8UC1, cv::Scalar(255)); + src_roi = src(Rect(1, 1, 3, 3)); + src_roi.setTo(0); + src.at(2, 2) = 255; + + // should work like !BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE); + Mat expected_dst = + (Mat_(3, 3) << 170, 113, 170, 113, 28, 113, 170, 113, 170); + EXPECT_EQ(expected_dst.type(), dst.type()); + EXPECT_EQ(expected_dst.size(), dst.size()); + EXPECT_DOUBLE_EQ(0.0, cvtest::norm(expected_dst, dst, NORM_INF)); +} diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 3a6ebe836..1ef2a1208 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -175,7 +175,7 @@ foreach(java_file ${step3_input_files}) if(ANDROID) get_filename_component(install_subdir "${java_file_name}" PATH) - install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT main) + install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT java) endif() endforeach() @@ -189,7 +189,7 @@ if(ANDROID) if(NOT file MATCHES "jni/.+") get_filename_component(install_subdir "${file}" PATH) - install(FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java) endif() endforeach() @@ -225,11 +225,11 @@ if(ANDROID AND ANDROID_EXECUTABLE) list(APPEND copied_files ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}") list(APPEND step3_input_files "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}") - install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main) - install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT java) + install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT java) # creating empty 'gen' and 'res' folders - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT main) - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT main) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT java) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT java) endif(ANDROID AND ANDROID_EXECUTABLE) set(step3_depends ${step2_depends} ${step3_input_files} ${copied_files}) @@ -266,7 +266,7 @@ if(ANDROID) else(ANDROID) set(JAR_NAME opencv-${LIB_NAME_SUFIX}.jar) set(JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OpenCV_BINARY_DIR}/build.xml" @ONLY) list(APPEND step3_depends "${OpenCV_BINARY_DIR}/build.xml") add_custom_command(OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper" @@ -282,7 +282,7 @@ else(ANDROID) else(WIN32) set(JAR_INSTALL_DIR share/OpenCV/java) endif(WIN32) - install(FILES ${JAR_FILE} DESTINATION ${JAR_INSTALL_DIR} COMPONENT main) + install(FILES ${JAR_FILE} DESTINATION ${JAR_INSTALL_DIR} COMPONENT java) endif(ANDROID) # step 5: build native part @@ -353,17 +353,17 @@ endif() if(ANDROID) ocv_install_target(${the_module} EXPORT OpenCVModules - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java) else() if(NOT INSTALL_CREATE_DISTRIB) ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${JAR_INSTALL_DIR} COMPONENT main - LIBRARY DESTINATION ${JAR_INSTALL_DIR} COMPONENT main) + RUNTIME DESTINATION ${JAR_INSTALL_DIR} COMPONENT java + LIBRARY DESTINATION ${JAR_INSTALL_DIR} COMPONENT java) else() ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT main - LIBRARY DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT main) + RUNTIME DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT java + LIBRARY DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT java) endif() endif() diff --git a/modules/java/generator/src/cpp/VideoCapture.cpp b/modules/java/generator/src/cpp/VideoCapture.cpp index a9d0a56c1..e4a8bc25a 100644 --- a/modules/java/generator/src/cpp/VideoCapture.cpp +++ b/modules/java/generator/src/cpp/VideoCapture.cpp @@ -329,7 +329,10 @@ JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPr VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL union {double prop; const char* name;} u; u.prop = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING); - return env->NewStringUTF(u.name); + // VideoCapture::get can return 0.0 or -1.0 if it doesn't support + // CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + if (u.prop != 0.0 && u.prop != -1.0) + return env->NewStringUTF(u.name); } catch(const std::exception &e) { throwJavaException(env, &e, method_name); } catch (...) { diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index 0acd85c19..c29ba2b6f 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -288,7 +288,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb } public Mat rgba() { - Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2BGR_NV12, 4); + Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2RGBA_NV21, 4); return mRgba; } diff --git a/modules/java/generator/src/java/android+NativeCameraView.java b/modules/java/generator/src/java/android+NativeCameraView.java index 62d077580..db146d8ae 100644 --- a/modules/java/generator/src/java/android+NativeCameraView.java +++ b/modules/java/generator/src/java/android+NativeCameraView.java @@ -22,6 +22,7 @@ public class NativeCameraView extends CameraBridgeViewBase { private Thread mThread; protected VideoCapture mCamera; + protected NativeCameraFrame mFrame; public NativeCameraView(Context context, int cameraId) { super(context, cameraId); @@ -97,6 +98,8 @@ public class NativeCameraView extends CameraBridgeViewBase { if (mCamera.isOpened() == false) return false; + mFrame = new NativeCameraFrame(mCamera); + java.util.List sizes = mCamera.getSupportedPreviewSizes(); /* Select the size that fits surface considering maximum size allowed */ @@ -127,9 +130,8 @@ public class NativeCameraView extends CameraBridgeViewBase { private void releaseCamera() { synchronized (this) { - if (mCamera != null) { - mCamera.release(); - } + if (mFrame != null) mFrame.release(); + if (mCamera != null) mCamera.release(); } } @@ -153,6 +155,11 @@ public class NativeCameraView extends CameraBridgeViewBase { mRgba = new Mat(); } + public void release() { + if (mGray != null) mGray.release(); + if (mRgba != null) mRgba.release(); + } + private VideoCapture mCapture; private Mat mRgba; private Mat mGray; @@ -167,8 +174,7 @@ public class NativeCameraView extends CameraBridgeViewBase { break; } - deliverAndDrawFrame(new NativeCameraFrame(mCamera)); - + deliverAndDrawFrame(mFrame); } while (!mStopThread); } } diff --git a/modules/java/generator/src/java/android+OpenCVLoader.java b/modules/java/generator/src/java/android+OpenCVLoader.java index 46e62eb34..13cd42849 100644 --- a/modules/java/generator/src/java/android+OpenCVLoader.java +++ b/modules/java/generator/src/java/android+OpenCVLoader.java @@ -42,13 +42,28 @@ public class OpenCVLoader */ public static final String OPENCV_VERSION_2_4_8 = "2.4.8"; + /** + * OpenCV Library version 2.4.9. + */ + public static final String OPENCV_VERSION_2_4_9 = "2.4.9"; + /** * Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java"). * @return Returns true is initialization of OpenCV was successful. */ public static boolean initDebug() { - return StaticHelper.initOpenCV(); + return StaticHelper.initOpenCV(false); + } + + /** + * Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java"). + * @param InitCuda load and initialize CUDA runtime libraries. + * @return Returns true is initialization of OpenCV was successful. + */ + public static boolean initDebug(boolean InitCuda) + { + return StaticHelper.initOpenCV(InitCuda); } /** diff --git a/modules/java/generator/src/java/android+StaticHelper.java b/modules/java/generator/src/java/android+StaticHelper.java index 8d0629c8d..10442c904 100644 --- a/modules/java/generator/src/java/android+StaticHelper.java +++ b/modules/java/generator/src/java/android+StaticHelper.java @@ -7,11 +7,21 @@ import android.util.Log; class StaticHelper { - public static boolean initOpenCV() + public static boolean initOpenCV(boolean InitCuda) { boolean result; String libs = ""; + if(InitCuda) + { + loadLibrary("cudart"); + loadLibrary("nppc"); + loadLibrary("nppi"); + loadLibrary("npps"); + loadLibrary("cufft"); + loadLibrary("cublas"); + } + Log.d(TAG, "Trying to get library list"); try @@ -52,7 +62,7 @@ class StaticHelper { try { System.loadLibrary(Name); - Log.d(TAG, "OpenCV libs init was ok!"); + Log.d(TAG, "Library " + Name + " loaded"); } catch(UnsatisfiedLinkError e) { diff --git a/modules/java/generator/src/java/core+TermCriteria.java b/modules/java/generator/src/java/core+TermCriteria.java index 98a5e3c39..c67e51ea8 100644 --- a/modules/java/generator/src/java/core+TermCriteria.java +++ b/modules/java/generator/src/java/core+TermCriteria.java @@ -87,7 +87,6 @@ public class TermCriteria { @Override public String toString() { - if (this == null) return "null"; return "{ type: " + type + ", maxCount: " + maxCount + ", epsilon: " + epsilon + "}"; } } diff --git a/modules/legacy/src/bgfg_gaussmix.cpp b/modules/legacy/src/bgfg_gaussmix.cpp index 3cb7a5af9..829e4fa14 100644 --- a/modules/legacy/src/bgfg_gaussmix.cpp +++ b/modules/legacy/src/bgfg_gaussmix.cpp @@ -415,7 +415,7 @@ CV_INLINE int _icvRemoveShadowGMM(float* data, int nD, //IEEE Trans. on Pattern Analysis and Machine Intelligence, vol.26, no.5, pages 651-656, 2004 //http://www.zoranz.net/Publications/zivkovic2004PAMI.pdf -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif @@ -608,7 +608,7 @@ CV_INLINE int _icvUpdateGMM(float* data, int nD, return bBackground; } -#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic pop #endif diff --git a/modules/legacy/src/blobtrack.cpp b/modules/legacy/src/blobtrack.cpp index 48b83ef91..00e4905cc 100644 --- a/modules/legacy/src/blobtrack.cpp +++ b/modules/legacy/src/blobtrack.cpp @@ -205,7 +205,7 @@ double CvVSModule::GetParam(const char* name) if(p->pInt) return p->pInt[0]; } return 0; -}; +} const char* CvVSModule::GetParamStr(const char* name) { diff --git a/modules/legacy/src/blobtrackanalysishist.cpp b/modules/legacy/src/blobtrackanalysishist.cpp index 0e349f9f4..c75c95491 100644 --- a/modules/legacy/src/blobtrackanalysishist.cpp +++ b/modules/legacy/src/blobtrackanalysishist.cpp @@ -730,12 +730,12 @@ private: m_pFViVarRes = (int*)cvAlloc(sizeof(int)*m_Dim); m_Sizes = (int*)cvAlloc(sizeof(int)*m_Dim); - { /* Create init sparce matrix: */ + { /* Create init sparse matrix: */ int i; for(i=0;iaddParam(obj, "epsilon", obj.epsilon); obj.info()->addParam(obj, "weights", obj.weights, true); obj.info()->addParam(obj, "means", obj.means, true); - obj.info()->addParam(obj, "covs", obj.covs, true)); + obj.info()->addParam(obj, "covs", obj.covs, true)) bool initModule_ml(void) { diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index 674365bb3..f15880521 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -2298,14 +2298,24 @@ void CvSVM::write_params( CvFileStorage* fs ) const } +static bool isSvmModelApplicable(int sv_total, int var_all, int var_count, int class_count) +{ + return (sv_total > 0 && var_count > 0 && var_count <= var_all && class_count >= 0); +} + + void CvSVM::write( CvFileStorage* fs, const char* name ) const { CV_FUNCNAME( "CvSVM::write" ); __BEGIN__; - int i, var_count = get_var_count(), df_count, class_count; + int i, var_count = get_var_count(), df_count; + int class_count = class_labels ? class_labels->cols : + params.svm_type == CvSVM::ONE_CLASS ? 1 : 0; const CvSVMDecisionFunc* df = decision_func; + if( !isSvmModelApplicable(sv_total, var_all, var_count, class_count) ) + CV_ERROR( CV_StsParseError, "SVM model data is invalid, check sv_count, var_* and class_count tags" ); cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_ML_SVM ); @@ -2314,9 +2324,6 @@ void CvSVM::write( CvFileStorage* fs, const char* name ) const cvWriteInt( fs, "var_all", var_all ); cvWriteInt( fs, "var_count", var_count ); - class_count = class_labels ? class_labels->cols : - params.svm_type == CvSVM::ONE_CLASS ? 1 : 0; - if( class_count ) { cvWriteInt( fs, "class_count", class_count ); @@ -2454,7 +2461,6 @@ void CvSVM::read_params( CvFileStorage* fs, CvFileNode* svm_node ) __END__; } - void CvSVM::read( CvFileStorage* fs, CvFileNode* svm_node ) { const double not_found_dbl = DBL_MAX; @@ -2483,7 +2489,7 @@ void CvSVM::read( CvFileStorage* fs, CvFileNode* svm_node ) var_count = cvReadIntByName( fs, svm_node, "var_count", var_all ); class_count = cvReadIntByName( fs, svm_node, "class_count", 0 ); - if( sv_total <= 0 || var_all <= 0 || var_count <= 0 || var_count > var_all || class_count < 0 ) + if( !isSvmModelApplicable(sv_total, var_all, var_count, class_count) ) CV_ERROR( CV_StsParseError, "SVM model data is invalid, check sv_count, var_* and class_count tags" ); CV_CALL( class_labels = (CvMat*)cvReadByName( fs, svm_node, "class_labels" )); diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 1ba94fcaf..8034fb099 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -1434,8 +1434,6 @@ void CvDTreeTrainData::read_params( CvFileStorage* fs, CvFileNode* node ) var_type->data.i[var_count] = cat_var_count; ord_var_count = ~ord_var_count; - if( cat_var_count != cat_var_count || ord_var_count != ord_var_count ) - CV_ERROR( CV_StsParseError, "var_type is inconsistent with cat_var_count and ord_var_count" ); ////// if( cat_var_count > 0 || is_classifier ) diff --git a/modules/ml/test/test_save_load.cpp b/modules/ml/test/test_save_load.cpp index 9fd31b9f2..7300185b4 100644 --- a/modules/ml/test/test_save_load.cpp +++ b/modules/ml/test/test_save_load.cpp @@ -155,6 +155,14 @@ TEST(ML_RTrees, save_load) { CV_SLMLTest test( CV_RTREES ); test.safe_run(); } TEST(ML_ERTrees, save_load) { CV_SLMLTest test( CV_ERTREES ); test.safe_run(); } +TEST(ML_SVM, throw_exception_when_save_untrained_model) +{ + SVM svm; + string filename = tempfile("svm.xml"); + ASSERT_THROW(svm.save(filename.c_str()), Exception); + remove(filename.c_str()); +} + TEST(DISABLED_ML_SVM, linear_save_load) { CvSVM svm1, svm2, svm3; diff --git a/modules/nonfree/CMakeLists.txt b/modules/nonfree/CMakeLists.txt index 5689a12e3..571614be0 100644 --- a/modules/nonfree/CMakeLists.txt +++ b/modules/nonfree/CMakeLists.txt @@ -3,5 +3,10 @@ if(BUILD_ANDROID_PACKAGE) endif() set(the_description "Functionality with possible limitations on the use") -ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) -ocv_define_module(nonfree opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_gpu opencv_ocl) +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wshadow) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) + ocv_define_module(nonfree EXCLUDE_CUDA opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_ocl) +else() + ocv_define_module(nonfree opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_gpu opencv_ocl) +endif() diff --git a/modules/nonfree/doc/feature_detection.rst b/modules/nonfree/doc/feature_detection.rst index f97dec100..fec396a74 100644 --- a/modules/nonfree/doc/feature_detection.rst +++ b/modules/nonfree/doc/feature_detection.rst @@ -110,6 +110,8 @@ Detects keypoints and computes SURF descriptors for them. .. ocv:pyfunction:: cv2.SURF.detect(image[, mask]) -> keypoints +.. ocv:pyfunction:: cv2.SURF.detectAndCompute(image[, mask]) -> keypoints, descriptors + .. ocv:cfunction:: void cvExtractSURF( const CvArr* image, const CvArr* mask, CvSeq** keypoints, CvSeq** descriptors, CvMemStorage* storage, CvSURFParams params ) .. ocv:pyoldfunction:: cv.ExtractSURF(image, mask, storage, params)-> (keypoints, descriptors) @@ -240,7 +242,7 @@ The class ``SURF_GPU`` uses some buffers and provides access to it. All buffers ocl::SURF_OCL ------------- -.. ocv:class:: ocl::SURF_OCL +.. ocv:class:: ocl::SURF_OCL : public Feature2D Class used for extracting Speeded Up Robust Features (SURF) from an image. :: diff --git a/modules/nonfree/include/opencv2/nonfree/gpu.hpp b/modules/nonfree/include/opencv2/nonfree/gpu.hpp index 3cb0b4762..722ef26a2 100644 --- a/modules/nonfree/include/opencv2/nonfree/gpu.hpp +++ b/modules/nonfree/include/opencv2/nonfree/gpu.hpp @@ -43,11 +43,7 @@ #ifndef __OPENCV_NONFREE_GPU_HPP__ #define __OPENCV_NONFREE_GPU_HPP__ -#include "opencv2/opencv_modules.hpp" - -#if defined(HAVE_OPENCV_GPU) - -#include "opencv2/gpu/gpu.hpp" +#include "opencv2/core/gpumat.hpp" namespace cv { namespace gpu { @@ -129,6 +125,4 @@ public: } // namespace cv -#endif // defined(HAVE_OPENCV_GPU) - #endif // __OPENCV_NONFREE_GPU_HPP__ diff --git a/modules/nonfree/include/opencv2/nonfree/ocl.hpp b/modules/nonfree/include/opencv2/nonfree/ocl.hpp index 78b6b466c..ba84d2443 100644 --- a/modules/nonfree/include/opencv2/nonfree/ocl.hpp +++ b/modules/nonfree/include/opencv2/nonfree/ocl.hpp @@ -53,7 +53,7 @@ namespace cv //! Speeded up robust features, port from GPU module. ////////////////////////////////// SURF ////////////////////////////////////////// - class CV_EXPORTS SURF_OCL + class CV_EXPORTS SURF_OCL : public cv::Feature2D { public: enum KeypointLayout @@ -72,10 +72,13 @@ namespace cv SURF_OCL(); //! the full constructor taking all the necessary parameters explicit SURF_OCL(double _hessianThreshold, int _nOctaves = 4, - int _nOctaveLayers = 2, bool _extended = false, float _keypointsRatio = 0.01f, bool _upright = false); + int _nOctaveLayers = 2, bool _extended = true, float _keypointsRatio = 0.01f, bool _upright = false); //! returns the descriptor size in float's (64 or 128) int descriptorSize() const; + + int descriptorType() const; + //! upload host keypoints to device memory void uploadKeypoints(const vector &keypoints, oclMat &keypointsocl); //! download keypoints from device to host memory @@ -103,6 +106,17 @@ namespace cv void operator()(const oclMat &img, const oclMat &mask, std::vector &keypoints, std::vector &descriptors, bool useProvidedKeypoints = false); + //! finds the keypoints using fast hessian detector used in SURF + void operator()(InputArray img, InputArray mask, + CV_OUT vector& keypoints) const; + //! finds the keypoints and computes their descriptors. Optionally it can compute descriptors for the user-provided keypoints + void operator()(InputArray img, InputArray mask, + CV_OUT vector& keypoints, + OutputArray descriptors, + bool useProvidedKeypoints=false) const; + + AlgorithmInfo* info() const; + void releaseMemory(); // SURF parameters @@ -116,7 +130,9 @@ namespace cv oclMat sum, mask1, maskSum, intBuffer; oclMat det, trace; oclMat maxPosBuffer; - + protected: + void detectImpl( const Mat& image, vector& keypoints, const Mat& mask) const; + void computeImpl( const Mat& image, vector& keypoints, Mat& descriptors) const; }; } } diff --git a/modules/nonfree/perf/perf_gpu.cpp b/modules/nonfree/perf/perf_gpu.cpp index 9f451deab..e29eeb2fa 100644 --- a/modules/nonfree/perf/perf_gpu.cpp +++ b/modules/nonfree/perf/perf_gpu.cpp @@ -42,7 +42,9 @@ #include "perf_precomp.hpp" -#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) +#include "cvconfig.h" + +#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/ts/gpu_perf.hpp" diff --git a/modules/nonfree/perf/perf_main.cpp b/modules/nonfree/perf/perf_main.cpp index d5f4a1a51..d46a36a13 100644 --- a/modules/nonfree/perf/perf_main.cpp +++ b/modules/nonfree/perf/perf_main.cpp @@ -4,8 +4,40 @@ static const char * impls[] = { #ifdef HAVE_CUDA "cuda", +#endif +#ifdef HAVE_OPENCV_OCL + "ocl", #endif "plain" }; -CV_PERF_TEST_MAIN_WITH_IMPLS(nonfree, impls, perf::printCudaInfo()) +#ifdef HAVE_OPENCL +#define DUMP_PROPERTY_XML(propertyName, propertyValue) \ + do { \ + std::stringstream ssName, ssValue;\ + ssName << propertyName;\ + ssValue << propertyValue; \ + ::testing::Test::RecordProperty(ssName.str(), ssValue.str()); \ + } while (false) + +#define DUMP_MESSAGE_STDOUT(msg) \ + do { \ + std::cout << msg << std::endl; \ + } while (false) + +#include "opencv2/ocl/private/opencl_dumpinfo.hpp" +#endif + +int main(int argc, char **argv) +{ + ::perf::TestBase::setPerformanceStrategy(::perf::PERF_STRATEGY_SIMPLE); +#if defined(HAVE_CUDA) && defined(HAVE_OPENCL) + CV_PERF_TEST_MAIN_INTERNALS(nonfree, impls, perf::printCudaInfo(), dumpOpenCLDevice()); +#elif defined(HAVE_CUDA) + CV_PERF_TEST_MAIN_INTERNALS(nonfree, impls, perf::printCudaInfo()); +#elif defined(HAVE_OPENCL) + CV_PERF_TEST_MAIN_INTERNALS(nonfree, impls, dumpOpenCLDevice()); +#else + CV_PERF_TEST_MAIN_INTERNALS(nonfree, impls) +#endif +} diff --git a/modules/nonfree/perf/perf_precomp.hpp b/modules/nonfree/perf/perf_precomp.hpp index addba7b00..57bbe16f0 100644 --- a/modules/nonfree/perf/perf_precomp.hpp +++ b/modules/nonfree/perf/perf_precomp.hpp @@ -9,6 +9,8 @@ #ifndef __OPENCV_PERF_PRECOMP_HPP__ #define __OPENCV_PERF_PRECOMP_HPP__ +#include "cvconfig.h" + #include "opencv2/ts/ts.hpp" #include "opencv2/nonfree/nonfree.hpp" diff --git a/modules/nonfree/perf/perf_surf.cpp b/modules/nonfree/perf/perf_surf.cpp index 20935a9a1..85b233951 100644 --- a/modules/nonfree/perf/perf_surf.cpp +++ b/modules/nonfree/perf/perf_surf.cpp @@ -16,9 +16,7 @@ PERF_TEST_P(surf, detect, testing::Values(SURF_IMAGES)) { String filename = getDataPath(GetParam()); Mat frame = imread(filename, IMREAD_GRAYSCALE); - - if (frame.empty()) - FAIL() << "Unable to load source image " << filename; + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; Mat mask; declare.in(frame).time(90); @@ -34,9 +32,7 @@ PERF_TEST_P(surf, extract, testing::Values(SURF_IMAGES)) { String filename = getDataPath(GetParam()); Mat frame = imread(filename, IMREAD_GRAYSCALE); - - if (frame.empty()) - FAIL() << "Unable to load source image " << filename; + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; Mat mask; declare.in(frame).time(90); @@ -55,9 +51,7 @@ PERF_TEST_P(surf, full, testing::Values(SURF_IMAGES)) { String filename = getDataPath(GetParam()); Mat frame = imread(filename, IMREAD_GRAYSCALE); - - if (frame.empty()) - FAIL() << "Unable to load source image " << filename; + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; Mat mask; declare.in(frame).time(90); diff --git a/modules/nonfree/perf/perf_surf_ocl.cpp b/modules/nonfree/perf/perf_surf_ocl.cpp new file mode 100644 index 000000000..788b52932 --- /dev/null +++ b/modules/nonfree/perf/perf_surf_ocl.cpp @@ -0,0 +1,213 @@ +/*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, Multicoreware, Inc., all rights reserved. +// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// @Authors +// Peng Xiao, pengxiao@multicorewareinc.com +// +// 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" + +#ifdef HAVE_OPENCV_OCL + +using namespace cv; +using namespace cv::ocl; +using namespace std; + +typedef perf::TestBaseWithParam OCL_SURF; + +#define SURF_IMAGES \ + "cv/detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\ + "stitching/a3.png" + +#define OCL_TEST_CYCLE() for( ; startTimer(), next(); cv::ocl::finish(), stopTimer()) + +PERF_TEST_P(OCL_SURF, DISABLED_with_data_transfer, testing::Values(SURF_IMAGES)) +{ + string filename = getDataPath(GetParam()); + Mat src = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(src.empty()); + + Mat cpu_kp, cpu_dp; + declare.time(60); + + if (getSelectedImpl() == "ocl") + { + SURF_OCL d_surf; + oclMat d_keypoints, d_descriptors; + + OCL_TEST_CYCLE() + { + oclMat d_src(src); + + d_surf(d_src, oclMat(), d_keypoints, d_descriptors); + + d_keypoints.download(cpu_kp); + d_descriptors.download(cpu_dp); + } + } + else if (getSelectedImpl() == "plain") + { + cv::SURF surf; + std::vector kp; + + TEST_CYCLE() surf(src, Mat(), kp, cpu_dp); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P(OCL_SURF, DISABLED_without_data_transfer, testing::Values(SURF_IMAGES)) +{ + string filename = getDataPath(GetParam()); + Mat src = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(src.empty()); + + Mat cpu_kp, cpu_dp; + declare.time(60); + + if (getSelectedImpl() == "ocl") + { + SURF_OCL d_surf; + oclMat d_keypoints, d_descriptors, d_src(src); + + OCL_TEST_CYCLE() d_surf(d_src, oclMat(), d_keypoints, d_descriptors); + } + else if (getSelectedImpl() == "plain") + { + cv::SURF surf; + std::vector kp; + + TEST_CYCLE() surf(src, Mat(), kp, cpu_dp); + } + + SANITY_CHECK_NOTHING(); +} + + + +PERF_TEST_P(OCL_SURF, DISABLED_detect, testing::Values(SURF_IMAGES)) +{ + String filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + declare.in(frame); + + Mat mask; + vector points; + Ptr detector; + + if (getSelectedImpl() == "plain") + { + detector = new SURF; + TEST_CYCLE() detector->operator()(frame, mask, points, noArray()); + } + else if (getSelectedImpl() == "ocl") + { + detector = new ocl::SURF_OCL; + OCL_TEST_CYCLE() detector->operator()(frame, mask, points, noArray()); + } + else CV_TEST_FAIL_NO_IMPL(); + + SANITY_CHECK_KEYPOINTS(points, 1e-3); +} + +PERF_TEST_P(OCL_SURF, DISABLED_extract, testing::Values(SURF_IMAGES)) +{ + String filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + declare.in(frame); + + Mat mask; + Ptr detector; + vector points; + vector descriptors; + + if (getSelectedImpl() == "plain") + { + detector = new SURF; + detector->operator()(frame, mask, points, noArray()); + TEST_CYCLE() detector->operator()(frame, mask, points, descriptors, true); + } + else if (getSelectedImpl() == "ocl") + { + detector = new ocl::SURF_OCL; + detector->operator()(frame, mask, points, noArray()); + OCL_TEST_CYCLE() detector->operator()(frame, mask, points, descriptors, true); + } + else CV_TEST_FAIL_NO_IMPL(); + + SANITY_CHECK(descriptors, 1e-4); +} + +PERF_TEST_P(OCL_SURF, DISABLED_full, testing::Values(SURF_IMAGES)) +{ + String filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + declare.in(frame).time(90); + + Mat mask; + Ptr detector; + vector points; + vector descriptors; + + if (getSelectedImpl() == "plain") + { + detector = new SURF; + TEST_CYCLE() detector->operator()(frame, mask, points, descriptors, false); + } + else if (getSelectedImpl() == "ocl") + { + detector = new ocl::SURF_OCL; + detector->operator()(frame, mask, points, noArray()); + OCL_TEST_CYCLE() detector->operator()(frame, mask, points, descriptors, false); + } + else CV_TEST_FAIL_NO_IMPL(); + + SANITY_CHECK_KEYPOINTS(points, 1e-3); + SANITY_CHECK(descriptors, 1e-4); +} + +#endif // HAVE_OPENCV_OCL diff --git a/modules/nonfree/src/cuda/surf.cu b/modules/nonfree/src/cuda/surf.cu index 2002f534d..65345a363 100644 --- a/modules/nonfree/src/cuda/surf.cu +++ b/modules/nonfree/src/cuda/surf.cu @@ -42,7 +42,7 @@ #include "opencv2/opencv_modules.hpp" -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/limits.hpp" diff --git a/modules/nonfree/src/nonfree_init.cpp b/modules/nonfree/src/nonfree_init.cpp index 3c530e325..136b362ca 100644 --- a/modules/nonfree/src/nonfree_init.cpp +++ b/modules/nonfree/src/nonfree_init.cpp @@ -52,7 +52,7 @@ CV_INIT_ALGORITHM(SURF, "Feature2D.SURF", obj.info()->addParam(obj, "nOctaves", obj.nOctaves); obj.info()->addParam(obj, "nOctaveLayers", obj.nOctaveLayers); obj.info()->addParam(obj, "extended", obj.extended); - obj.info()->addParam(obj, "upright", obj.upright)); + obj.info()->addParam(obj, "upright", obj.upright)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -61,7 +61,21 @@ CV_INIT_ALGORITHM(SIFT, "Feature2D.SIFT", obj.info()->addParam(obj, "nOctaveLayers", obj.nOctaveLayers); obj.info()->addParam(obj, "contrastThreshold", obj.contrastThreshold); obj.info()->addParam(obj, "edgeThreshold", obj.edgeThreshold); - obj.info()->addParam(obj, "sigma", obj.sigma)); + obj.info()->addParam(obj, "sigma", obj.sigma)) + +#ifdef HAVE_OPENCV_OCL + +namespace ocl { +CV_INIT_ALGORITHM(SURF_OCL, "Feature2D.SURF_OCL", + obj.info()->addParam(obj, "hessianThreshold", obj.hessianThreshold); + obj.info()->addParam(obj, "nOctaves", obj.nOctaves); + obj.info()->addParam(obj, "nOctaveLayers", obj.nOctaveLayers); + obj.info()->addParam(obj, "extended", obj.extended); + obj.info()->addParam(obj, "upright", obj.upright)) +} + +#endif + /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/modules/nonfree/src/opencl/surf.cl b/modules/nonfree/src/opencl/surf.cl index 405e48f02..7421095c0 100644 --- a/modules/nonfree/src/opencl/surf.cl +++ b/modules/nonfree/src/opencl/surf.cl @@ -956,7 +956,7 @@ void icvCalcOrientation( // This reduction searches for the longest wavelet response vector. The first // step uses all of the work items in the workgroup to narrow the search // down to the three candidates. It requires s_mod to have a few more - // elements alocated past the work-group size, which are pre-initialized to + // elements allocated past the work-group size, which are pre-initialized to // 0.0f above. for(int t = ORI_RESPONSE_REDUCTION_WIDTH; t >= 3; t /= 2) { if (tid < t) { diff --git a/modules/nonfree/src/precomp.hpp b/modules/nonfree/src/precomp.hpp index 5fbe446af..6311ee2aa 100644 --- a/modules/nonfree/src/precomp.hpp +++ b/modules/nonfree/src/precomp.hpp @@ -51,17 +51,14 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/internal.hpp" -#if defined(HAVE_OPENCV_GPU) - #include "opencv2/nonfree/gpu.hpp" +#include "opencv2/nonfree/gpu.hpp" - #if defined(HAVE_CUDA) - #include "opencv2/gpu/stream_accessor.hpp" - #include "opencv2/gpu/device/common.hpp" - - static inline void throw_nogpu() { CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform"); } - #else - static inline void throw_nogpu() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); } - #endif +#if defined(HAVE_CUDA) && defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) + #include "opencv2/gpu/stream_accessor.hpp" + #include "opencv2/gpu/device/common.hpp" + static inline void throw_nogpu() { CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform"); } +#else + static inline void throw_nogpu() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); } #endif #ifdef HAVE_OPENCV_OCL diff --git a/modules/nonfree/src/surf_gpu.cpp b/modules/nonfree/src/surf_gpu.cpp index bfc7e700f..b3c2ce22b 100644 --- a/modules/nonfree/src/surf_gpu.cpp +++ b/modules/nonfree/src/surf_gpu.cpp @@ -42,12 +42,10 @@ #include "precomp.hpp" -#if defined(HAVE_OPENCV_GPU) - using namespace cv; using namespace cv::gpu; -#if !defined (HAVE_CUDA) +#if !defined (HAVE_CUDA) || !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT) cv::gpu::SURF_GPU::SURF_GPU() { throw_nogpu(); } cv::gpu::SURF_GPU::SURF_GPU(double, int, int, bool, float, bool) { throw_nogpu(); } @@ -421,5 +419,3 @@ void cv::gpu::SURF_GPU::releaseMemory() } #endif // !defined (HAVE_CUDA) - -#endif // defined(HAVE_OPENCV_GPU) diff --git a/modules/nonfree/src/surf.ocl.cpp b/modules/nonfree/src/surf_ocl.cpp similarity index 91% rename from modules/nonfree/src/surf.ocl.cpp rename to modules/nonfree/src/surf_ocl.cpp index 293fd84b5..e6fd6eeb6 100644 --- a/modules/nonfree/src/surf.ocl.cpp +++ b/modules/nonfree/src/surf_ocl.cpp @@ -283,9 +283,9 @@ private: cv::ocl::SURF_OCL::SURF_OCL() { hessianThreshold = 100.0f; - extended = true; + extended = false; nOctaves = 4; - nOctaveLayers = 2; + nOctaveLayers = 3; keypointsRatio = 0.01f; upright = false; } @@ -305,6 +305,11 @@ int cv::ocl::SURF_OCL::descriptorSize() const return extended ? 128 : 64; } +int cv::ocl::SURF_OCL::descriptorType() const +{ + return CV_32F; +} + void cv::ocl::SURF_OCL::uploadKeypoints(const vector &keypoints, oclMat &keypointsGPU) { if (keypoints.empty()) @@ -447,6 +452,81 @@ void cv::ocl::SURF_OCL::operator()(const oclMat &img, const oclMat &mask, vector downloadDescriptors(descriptorsGPU, descriptors); } + +void cv::ocl::SURF_OCL::operator()(InputArray img, InputArray mask, + CV_OUT vector& keypoints) const +{ + this->operator()(img, mask, keypoints, noArray(), false); +} + +void cv::ocl::SURF_OCL::operator()(InputArray img, InputArray mask, vector &keypoints, + OutputArray descriptors, bool useProvidedKeypoints) const +{ + oclMat _img, _mask; + if(img.kind() == _InputArray::OCL_MAT) + _img = *(oclMat*)img.obj; + else + _img.upload(img.getMat()); + if(_img.channels() != 1) + { + oclMat temp; + cvtColor(_img, temp, COLOR_BGR2GRAY); + _img = temp; + } + + if( !mask.empty() ) + { + if(mask.kind() == _InputArray::OCL_MAT) + _mask = *(oclMat*)mask.obj; + else + _mask.upload(mask.getMat()); + } + + SURF_OCL_Invoker surf((SURF_OCL&)*this, _img, _mask); + oclMat keypointsGPU; + + if (!useProvidedKeypoints || !upright) + ((SURF_OCL*)this)->uploadKeypoints(keypoints, keypointsGPU); + + if (!useProvidedKeypoints) + surf.detectKeypoints(keypointsGPU); + else if (!upright) + surf.findOrientation(keypointsGPU); + if(keypointsGPU.cols*keypointsGPU.rows != 0) + ((SURF_OCL*)this)->downloadKeypoints(keypointsGPU, keypoints); + + if( descriptors.needed() ) + { + oclMat descriptorsGPU; + surf.computeDescriptors(keypointsGPU, descriptorsGPU, descriptorSize()); + Size sz = descriptorsGPU.size(); + if( descriptors.kind() == _InputArray::STD_VECTOR ) + { + CV_Assert(descriptors.type() == CV_32F); + std::vector* v = (std::vector*)descriptors.obj; + v->resize(sz.width*sz.height); + Mat m(sz, CV_32F, &v->at(0)); + descriptorsGPU.download(m); + } + else + { + descriptors.create(sz, CV_32F); + Mat m = descriptors.getMat(); + descriptorsGPU.download(m); + } + } +} + +void cv::ocl::SURF_OCL::detectImpl( const Mat& image, vector& keypoints, const Mat& mask) const +{ + (*this)(image, mask, keypoints, noArray(), false); +} + +void cv::ocl::SURF_OCL::computeImpl( const Mat& image, vector& keypoints, Mat& descriptors) const +{ + (*this)(image, Mat(), keypoints, descriptors, true); +} + void cv::ocl::SURF_OCL::releaseMemory() { sum.release(); diff --git a/modules/nonfree/test/test_features2d.cpp b/modules/nonfree/test/test_features2d.cpp index b680d948b..4b0b89770 100644 --- a/modules/nonfree/test/test_features2d.cpp +++ b/modules/nonfree/test/test_features2d.cpp @@ -50,6 +50,22 @@ const string DETECTOR_DIR = FEATURES2D_DIR + "/feature_detectors"; const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors"; const string IMAGE_FILENAME = "tsukuba.png"; +#if defined(HAVE_OPENCV_OCL) && 0 // unblock this to see SURF_OCL tests failures +static Ptr getSURF() +{ + ocl::PlatformsInfo p; + if(ocl::getOpenCLPlatforms(p) > 0) + return new ocl::SURF_OCL; + else + return new SURF; +} +#else +static Ptr getSURF() +{ + return new SURF; +} +#endif + /****************************************************************************************\ * Regression tests for feature detectors comparing keypoints. * \****************************************************************************************/ @@ -978,7 +994,7 @@ TEST( Features2d_Detector_SIFT, regression ) TEST( Features2d_Detector_SURF, regression ) { - CV_FeatureDetectorTest test( "detector-surf", FeatureDetector::create("SURF") ); + CV_FeatureDetectorTest test( "detector-surf", Ptr(getSURF()) ); test.safe_run(); } @@ -995,7 +1011,7 @@ TEST( Features2d_DescriptorExtractor_SIFT, regression ) TEST( Features2d_DescriptorExtractor_SURF, regression ) { CV_DescriptorExtractorTest > test( "descriptor-surf", 0.05f, - DescriptorExtractor::create("SURF") ); + Ptr(getSURF()) ); test.safe_run(); } @@ -1036,10 +1052,10 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression) const int sz = 100; const int k = 3; - Ptr ext = DescriptorExtractor::create("SURF"); + Ptr ext = Ptr(getSURF()); ASSERT_TRUE(ext != NULL); - Ptr det = FeatureDetector::create("SURF"); + Ptr det = Ptr(getSURF()); //"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n" ASSERT_TRUE(det != NULL); @@ -1096,7 +1112,11 @@ public: protected: void run(int) { - Ptr f = Algorithm::create("Feature2D." + fname); + Ptr f; + if(fname == "SURF") + f = getSURF(); + else + f = Algorithm::create("Feature2D." + fname); if(f.empty()) return; string path = string(ts->get_data_path()) + "detectors_descriptors_evaluation/planar/"; diff --git a/modules/nonfree/test/test_gpu.cpp b/modules/nonfree/test/test_gpu.cpp index 3f63eeddf..938bc1d32 100644 --- a/modules/nonfree/test/test_gpu.cpp +++ b/modules/nonfree/test/test_gpu.cpp @@ -42,7 +42,9 @@ #include "test_precomp.hpp" -#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) +#include "cvconfig.h" + +#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) && !defined(DYNAMIC_CUDA_SUPPORT) using namespace cvtest; diff --git a/modules/nonfree/test/test_rotation_and_scale_invariance.cpp b/modules/nonfree/test/test_rotation_and_scale_invariance.cpp index 7ca9e3dd7..02407f648 100644 --- a/modules/nonfree/test/test_rotation_and_scale_invariance.cpp +++ b/modules/nonfree/test/test_rotation_and_scale_invariance.cpp @@ -48,6 +48,12 @@ using namespace cv; const string IMAGE_TSUKUBA = "/features2d/tsukuba.png"; const string IMAGE_BIKES = "/detectors_descriptors_evaluation/images_datasets/bikes/img1.png"; +#if defined(HAVE_OPENCV_OCL) && 0 // unblock this to see SURF_OCL tests failures +#define SURF_NAME "Feature2D.SURF_OCL" +#else +#define SURF_NAME "Feature2D.SURF" +#endif + #define SHOW_DEBUG_LOG 0 static @@ -615,7 +621,7 @@ protected: */ TEST(Features2d_RotationInvariance_Detector_SURF, regression) { - DetectorRotationInvarianceTest test(Algorithm::create("Feature2D.SURF"), + DetectorRotationInvarianceTest test(Algorithm::create(SURF_NAME), 0.44f, 0.76f); test.safe_run(); @@ -634,8 +640,8 @@ TEST(Features2d_RotationInvariance_Detector_SIFT, DISABLED_regression) */ TEST(Features2d_RotationInvariance_Descriptor_SURF, regression) { - DescriptorRotationInvarianceTest test(Algorithm::create("Feature2D.SURF"), - Algorithm::create("Feature2D.SURF"), + DescriptorRotationInvarianceTest test(Algorithm::create(SURF_NAME), + Algorithm::create(SURF_NAME), NORM_L1, 0.83f); test.safe_run(); @@ -655,7 +661,7 @@ TEST(Features2d_RotationInvariance_Descriptor_SIFT, regression) */ TEST(Features2d_ScaleInvariance_Detector_SURF, regression) { - DetectorScaleInvarianceTest test(Algorithm::create("Feature2D.SURF"), + DetectorScaleInvarianceTest test(Algorithm::create(SURF_NAME), 0.64f, 0.84f); test.safe_run(); @@ -674,8 +680,8 @@ TEST(Features2d_ScaleInvariance_Detector_SIFT, regression) */ TEST(Features2d_ScaleInvariance_Descriptor_SURF, regression) { - DescriptorScaleInvarianceTest test(Algorithm::create("Feature2D.SURF"), - Algorithm::create("Feature2D.SURF"), + DescriptorScaleInvarianceTest test(Algorithm::create(SURF_NAME), + Algorithm::create(SURF_NAME), NORM_L1, 0.61f); test.safe_run(); diff --git a/modules/nonfree/test/test_surf.ocl.cpp b/modules/nonfree/test/test_surf_ocl.cpp similarity index 100% rename from modules/nonfree/test/test_surf.ocl.cpp rename to modules/nonfree/test/test_surf_ocl.cpp diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 7d22feed9..d8230d1df 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1317,9 +1317,9 @@ public: if( cascade->hid_cascade->ipp_stages ) { IppiRect iequRect = {equRect.x, equRect.y, equRect.width, equRect.height}; - ippiRectStdDev_32f_C1R(sum1.ptr(y1), sum1.step, - sqsum1.ptr(y1), sqsum1.step, - norm1->ptr(y1), norm1->step, + ippiRectStdDev_32f_C1R(sum1.ptr(y1), (int)sum1.step, + sqsum1.ptr(y1), (int)sqsum1.step, + norm1->ptr(y1), (int)norm1->step, ippiSize(ssz.width, ssz.height), iequRect ); int positive = (ssz.width/ystep)*((ssz.height + ystep-1)/ystep); @@ -1340,9 +1340,9 @@ public: for( int j = 0; j < cascade->count; j++ ) { if( ippiApplyHaarClassifier_32f_C1R( - sum1.ptr(y1), sum1.step, - norm1->ptr(y1), norm1->step, - mask1->ptr(y1), mask1->step, + sum1.ptr(y1), (int)sum1.step, + norm1->ptr(y1), (int)norm1->step, + mask1->ptr(y1), (int)mask1->step, ippiSize(ssz.width, ssz.height), &positive, cascade->hid_cascade->stage_classifier[j].threshold, (IppiHaarClassifier_32f*)cascade->hid_cascade->ipp_stages[j]) < 0 ) diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 41744f6d5..1c0fbf2ae 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -747,7 +747,7 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const float sum = 0; #ifdef HAVE_IPP - ippsDotProd_32f(hist,hist,sz,&sum); + ippsDotProd_32f(hist,hist,(int)sz,&sum); #else for( i = 0; i < sz; i++ ) sum += hist[i]*hist[i]; @@ -755,9 +755,9 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const float scale = 1.f/(std::sqrt(sum)+sz*0.1f), thresh = (float)descriptor->L2HysThreshold; #ifdef HAVE_IPP - ippsMulC_32f_I(scale,hist,sz); - ippsThreshold_32f_I( hist, sz, thresh, ippCmpGreater ); - ippsDotProd_32f(hist,hist,sz,&sum); + ippsMulC_32f_I(scale,hist,(int)sz); + ippsThreshold_32f_I( hist, (int)sz, thresh, ippCmpGreater ); + ippsDotProd_32f(hist,hist,(int)sz,&sum); #else for( i = 0, sum = 0; i < sz; i++ ) { @@ -768,7 +768,7 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const scale = 1.f/(std::sqrt(sum)+1e-3f); #ifdef HAVE_IPP - ippsMulC_32f_I(scale,hist,sz); + ippsMulC_32f_I(scale,hist,(int)sz); #else for( i = 0; i < sz; i++ ) hist[i] *= scale; @@ -2651,7 +2651,6 @@ void HOGDescriptor::groupRectangles(vector& rectList, vector& vector > rrects(nclasses); vector numInClass(nclasses, 0); vector foundWeights(nclasses, DBL_MIN); - vector totalFactorsPerClass(nclasses, 1); int i, j, nlabels = (int)labels.size(); for( i = 0; i < nlabels; i++ ) diff --git a/modules/objdetect/src/matching.cpp b/modules/objdetect/src/matching.cpp index 382f6312a..484605d05 100644 --- a/modules/objdetect/src/matching.cpp +++ b/modules/objdetect/src/matching.cpp @@ -524,7 +524,9 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by) float *new_map; sizeX = map->sizeX + 2 * bx; sizeY = map->sizeY + 2 * by; - new_map = (float *)malloc(sizeof(float) * sizeX * sizeY * map->numFeatures); + // fix for Windows Phone 8 ARM compiler + size_t size = sizeof(float) * sizeX * sizeY * map->numFeatures; + new_map = (float *)malloc(size); for (i = 0; i < sizeX * sizeY * map->numFeatures; i++) { new_map[i] = 0.0; diff --git a/modules/ocl/doc/image_processing.rst b/modules/ocl/doc/image_processing.rst index 100876a15..7dde475cc 100644 --- a/modules/ocl/doc/image_processing.rst +++ b/modules/ocl/doc/image_processing.rst @@ -65,15 +65,15 @@ ocl::integral ----------------- Computes an integral image. -.. ocv:function:: void ocl::integral(const oclMat &src, oclMat &sum, oclMat &sqsum, int sdepth=-1) +.. ocv:function:: void ocl::integral(const oclMat &src, oclMat &sum, oclMat &sqsum) -.. ocv:function:: void ocl::integral(const oclMat &src, oclMat &sum, int sdepth=-1) +.. ocv:function:: void ocl::integral(const oclMat &src, oclMat &sum) :param src: Source image. Only ``CV_8UC1`` images are supported for now. - :param sum: Integral image containing 32-bit unsigned integer or 32-bit floating-point . + :param sum: Integral image containing 32-bit unsigned integer values packed into ``CV_32SC1`` . - :param sqsum: Sqsum values is ``CV_32FC1`` or ``CV_64FC1`` type. + :param sqsum: Sqsum values is ``CV_32FC1`` type. .. seealso:: :ocv:func:`integral` diff --git a/modules/ocl/include/opencv2/ocl/ocl.hpp b/modules/ocl/include/opencv2/ocl/ocl.hpp index ff35d14e7..9039e4640 100644 --- a/modules/ocl/include/opencv2/ocl/ocl.hpp +++ b/modules/ocl/include/opencv2/ocl/ocl.hpp @@ -204,7 +204,7 @@ namespace cv CACHE_NONE = 0, // do not cache OpenCL binary CACHE_DEBUG = 0x1 << 0, // cache OpenCL binary when built in debug mode CACHE_RELEASE = 0x1 << 1, // default behavior, only cache when built in release mode - CACHE_ALL = CACHE_DEBUG | CACHE_RELEASE, // cache opencl binary + CACHE_ALL = CACHE_DEBUG | CACHE_RELEASE // cache opencl binary }; //! Enable or disable OpenCL program binary caching onto local disk // After a program (*.cl files in opencl/ folder) is built at runtime, we allow the @@ -859,10 +859,10 @@ namespace cv CV_EXPORTS void warpPerspective(const oclMat &src, oclMat &dst, const Mat &M, Size dsize, int flags = INTER_LINEAR); //! computes the integral image and integral for the squared image - // sum will support CV_32S, CV_32F, sqsum - support CV32F, CV_64F + // sum will have CV_32S type, sqsum - CV32F type // supports only CV_8UC1 source type - CV_EXPORTS void integral(const oclMat &src, oclMat &sum, oclMat &sqsum, int sdepth=-1 ); - CV_EXPORTS void integral(const oclMat &src, oclMat &sum, int sdepth=-1 ); + CV_EXPORTS void integral(const oclMat &src, oclMat &sum, oclMat &sqsum); + CV_EXPORTS void integral(const oclMat &src, oclMat &sum); CV_EXPORTS void cornerHarris(const oclMat &src, oclMat &dst, int blockSize, int ksize, double k, int bordertype = cv::BORDER_DEFAULT); CV_EXPORTS void cornerHarris_dxdy(const oclMat &src, oclMat &dst, oclMat &Dx, oclMat &Dy, int blockSize, int ksize, double k, int bordertype = cv::BORDER_DEFAULT); @@ -936,7 +936,7 @@ namespace cv Size m_maxSize; vector sizev; vector scalev; - oclMat gimg1, gsum, gsqsum, gsqsum_t; + oclMat gimg1, gsum, gsqsum; void * buffers; }; diff --git a/modules/ocl/include/opencv2/ocl/private/opencl_utils.hpp b/modules/ocl/include/opencv2/ocl/private/opencl_utils.hpp index 70c45d3dd..a737f75a5 100644 --- a/modules/ocl/include/opencv2/ocl/private/opencl_utils.hpp +++ b/modules/ocl/include/opencv2/ocl/private/opencl_utils.hpp @@ -108,7 +108,7 @@ inline cl_int getStringInfo(Functor f, ObjectType obj, cl_uint name, std::string } return CL_SUCCESS; -}; +} } // namespace cl_utils diff --git a/modules/ocl/perf/perf_arithm.cpp b/modules/ocl/perf/perf_arithm.cpp index 2699b44a7..3faedfcc7 100644 --- a/modules/ocl/perf/perf_arithm.cpp +++ b/modules/ocl/perf/perf_arithm.cpp @@ -54,22 +54,20 @@ using std::tr1::tuple; typedef Size_MatType LUTFixture; -PERF_TEST_P(LUTFixture, LUT, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC3))) +OCL_PERF_TEST_P(LUTFixture, LUT, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) { // getting params const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params); + const int type = get<1>(params), cn = CV_MAT_CN(type); // creating src data - Mat src(srcSize, type), lut(1, 256, CV_8UC1); + Mat src(srcSize, CV_8UC(cn)), lut(1, 256, type); int dstType = CV_MAKETYPE(lut.depth(), src.channels()); Mat dst(srcSize, dstType); - randu(lut, 0, 2); - declare.in(src, WARMUP_RNG).in(lut).out(dst); + declare.in(src, lut, WARMUP_RNG).out(dst); // select implementation if (RUN_OCL_IMPL) @@ -93,16 +91,19 @@ PERF_TEST_P(LUTFixture, LUT, ///////////// Exp //////////////////////// -typedef TestBaseWithParam ExpFixture; +typedef Size_MatType ExpFixture; -PERF_TEST_P(ExpFixture, Exp, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(ExpFixture, Exp, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { // getting params - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); const double eps = 1e-6; // creating src data - Mat src(srcSize, CV_32FC1), dst(srcSize, CV_32FC1); + Mat src(srcSize, type), dst(srcSize, type); declare.in(src).out(dst); randu(src, 5, 16); @@ -125,18 +126,21 @@ PERF_TEST_P(ExpFixture, Exp, OCL_TYPICAL_MAT_SIZES) SANITY_CHECK(dst, eps, ERROR_RELATIVE); } -///////////// LOG //////////////////////// +///////////// Log //////////////////////// -typedef TestBaseWithParam LogFixture; +typedef Size_MatType LogFixture; -PERF_TEST_P(LogFixture, Log, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(LogFixture, Log, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { // getting params - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); const double eps = 1e-6; // creating src data - Mat src(srcSize, CV_32F), dst(srcSize, src.type()); + Mat src(srcSize, type), dst(srcSize, type); randu(src, 1, 10); declare.in(src).out(dst); @@ -166,9 +170,8 @@ PERF_TEST_P(LogFixture, Log, OCL_TYPICAL_MAT_SIZES) typedef Size_MatType AddFixture; -PERF_TEST_P(AddFixture, Add, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(AddFixture, Add, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { // getting params const Size_MatType_t params = GetParam(); @@ -202,12 +205,51 @@ PERF_TEST_P(AddFixture, Add, OCL_PERF_ELSE } +///////////// Subtract //////////////////////// + +typedef Size_MatType SubtractFixture; + +OCL_PERF_TEST_P(SubtractFixture, Subtract, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) +{ + // getting params + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + // creating src data + Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type); + randu(src1, 0, 1); + randu(src2, 0, 1); + declare.in(src1, src2).out(dst); + + // select implementation + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type); + + OCL_TEST_CYCLE() cv::ocl::subtract(oclSrc1, oclSrc2, oclDst); + + oclDst.download(dst); + + SANITY_CHECK(dst); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::subtract(src1, src2, dst); + + SANITY_CHECK(dst); + } + else + OCL_PERF_ELSE +} + + ///////////// Mul //////////////////////// typedef Size_MatType MulFixture; -PERF_TEST_P(MulFixture, Mul, ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(MulFixture, Multiply, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { // getting params const Size_MatType_t params = GetParam(); @@ -245,9 +287,8 @@ PERF_TEST_P(MulFixture, Mul, ::testing::Combine(OCL_TYPICAL_MAT_SIZES, typedef Size_MatType DivFixture; -PERF_TEST_P(DivFixture, Div, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(DivFixture, Divide, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { // getting params const Size_MatType_t params = GetParam(); @@ -260,12 +301,6 @@ PERF_TEST_P(DivFixture, Div, randu(src1, 0, 256); randu(src2, 0, 256); - if ((srcSize == OCL_SIZE_4000 && type == CV_8UC1) || - (srcSize == OCL_SIZE_2000 && type == CV_8UC4)) - declare.time(4.2); - else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(16.6); - // select implementation if (RUN_OCL_IMPL) { @@ -275,13 +310,13 @@ PERF_TEST_P(DivFixture, Div, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::divide(src1, src2, dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } else OCL_PERF_ELSE @@ -291,9 +326,8 @@ PERF_TEST_P(DivFixture, Div, typedef Size_MatType AbsDiffFixture; -PERF_TEST_P(AbsDiffFixture, Absdiff, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(AbsDiffFixture, Absdiff, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -326,15 +360,18 @@ PERF_TEST_P(AbsDiffFixture, Absdiff, ///////////// CartToPolar //////////////////////// -typedef TestBaseWithParam CartToPolarFixture; +typedef Size_MatType CartToPolarFixture; -PERF_TEST_P(CartToPolarFixture, CartToPolar, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(CartToPolarFixture, CartToPolar, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); const double eps = 8e-3; - Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1), - dst1(srcSize, CV_32FC1), dst2(srcSize, CV_32FC1); + Mat src1(srcSize, type), src2(srcSize, type), + dst1(srcSize, type), dst2(srcSize, type); declare.in(src1, src2).out(dst1, dst2); randu(src1, 0, 256); randu(src2, 0, 256); @@ -368,14 +405,17 @@ PERF_TEST_P(CartToPolarFixture, CartToPolar, OCL_TYPICAL_MAT_SIZES) ///////////// PolarToCart //////////////////////// -typedef TestBaseWithParam PolarToCartFixture; +typedef Size_MatType PolarToCartFixture; -PERF_TEST_P(PolarToCartFixture, PolarToCart, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(PolarToCartFixture, PolarToCart, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); - Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1), - dst1(srcSize, CV_32FC1), dst2(srcSize, CV_32FC1); + Mat src1(srcSize, type), src2(srcSize, type), + dst1(srcSize, type), dst2(srcSize, type); declare.in(src1, src2).out(dst1, dst2); randu(src1, 0, 256); randu(src2, 0, 256); @@ -409,14 +449,17 @@ PERF_TEST_P(PolarToCartFixture, PolarToCart, OCL_TYPICAL_MAT_SIZES) ///////////// Magnitude //////////////////////// -typedef TestBaseWithParam MagnitudeFixture; +typedef Size_MatType MagnitudeFixture; -PERF_TEST_P(MagnitudeFixture, Magnitude, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(MagnitudeFixture, Magnitude, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); - Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1), - dst(srcSize, CV_32FC1); + Mat src1(srcSize, type), src2(srcSize, type), + dst(srcSize, type); randu(src1, 0, 1); randu(src2, 0, 1); declare.in(src1, src2).out(dst); @@ -446,9 +489,8 @@ PERF_TEST_P(MagnitudeFixture, Magnitude, OCL_TYPICAL_MAT_SIZES) typedef Size_MatType TransposeFixture; -PERF_TEST_P(TransposeFixture, Transpose, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(TransposeFixture, Transpose, ::testing::Combine( + OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -479,15 +521,24 @@ PERF_TEST_P(TransposeFixture, Transpose, ///////////// Flip //////////////////////// -typedef Size_MatType FlipFixture; - -PERF_TEST_P(FlipFixture, Flip, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +enum { - const Size_MatType_t params = GetParam(); + FLIP_BOTH = 0, FLIP_ROWS, FLIP_COLS +}; + +CV_ENUM(FlipType, FLIP_BOTH, FLIP_ROWS, FLIP_COLS) + +typedef std::tr1::tuple FlipParams; +typedef TestBaseWithParam FlipFixture; + +OCL_PERF_TEST_P(FlipFixture, Flip, + ::testing::Combine(OCL_TEST_SIZES, + OCL_TEST_TYPES, FlipType::all())) +{ + const FlipParams params = GetParam(); const Size srcSize = get<0>(params); const int type = get<1>(params); + const int flipType = get<2>(params); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); @@ -496,7 +547,7 @@ PERF_TEST_P(FlipFixture, Flip, { ocl::oclMat oclSrc(src), oclDst(srcSize, type); - OCL_TEST_CYCLE() cv::ocl::flip(oclSrc, oclDst, 0); + OCL_TEST_CYCLE() cv::ocl::flip(oclSrc, oclDst, flipType - 1); oclDst.download(dst); @@ -504,7 +555,7 @@ PERF_TEST_P(FlipFixture, Flip, } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::flip(src, dst, 0); + TEST_CYCLE() cv::flip(src, dst, flipType - 1); SANITY_CHECK(dst); } @@ -512,169 +563,18 @@ PERF_TEST_P(FlipFixture, Flip, OCL_PERF_ELSE } -///////////// minMax //////////////////////// - -typedef Size_MatType minMaxFixture; - -PERF_TEST_P(minMaxFixture, minMax, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) -{ - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params); - - Mat src(srcSize, type); - declare.in(src, WARMUP_RNG); - - double min_val = std::numeric_limits::max(), - max_val = std::numeric_limits::min(); - - if (RUN_OCL_IMPL) - { - ocl::oclMat oclSrc(src); - - OCL_TEST_CYCLE() cv::ocl::minMax(oclSrc, &min_val, &max_val); - - ASSERT_GE(max_val, min_val); - SANITY_CHECK(min_val); - SANITY_CHECK(max_val); - } - else if (RUN_PLAIN_IMPL) - { - Point min_loc, max_loc; - - TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc); - - ASSERT_GE(max_val, min_val); - SANITY_CHECK(min_val); - SANITY_CHECK(max_val); - } - else - OCL_PERF_ELSE -} - -///////////// minMaxLoc //////////////////////// - -typedef Size_MatType minMaxLocFixture; - -PERF_TEST_P(minMaxLocFixture, minMaxLoc, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) -{ - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params); - - Mat src(srcSize, type); - randu(src, 0, 1); - declare.in(src); - - double min_val = 0.0, max_val = 0.0; - Point min_loc, max_loc; - - if (RUN_OCL_IMPL) - { - ocl::oclMat oclSrc(src); - - OCL_TEST_CYCLE() cv::ocl::minMaxLoc(oclSrc, &min_val, &max_val, &min_loc, &max_loc); - - ASSERT_GE(max_val, min_val); - SANITY_CHECK(min_val); - SANITY_CHECK(max_val); - } - else if (RUN_PLAIN_IMPL) - { - TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc); - - ASSERT_GE(max_val, min_val); - SANITY_CHECK(min_val); - SANITY_CHECK(max_val); - } - else - OCL_PERF_ELSE -} - -///////////// Sum //////////////////////// - -typedef Size_MatType SumFixture; - -PERF_TEST_P(SumFixture, Sum, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32SC1))) -{ - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params); - - Mat src(srcSize, type); - Scalar result; - randu(src, 0, 60); - declare.in(src); - - if (RUN_OCL_IMPL) - { - ocl::oclMat oclSrc(src); - - OCL_TEST_CYCLE() result = cv::ocl::sum(oclSrc); - - SANITY_CHECK(result); - } - else if (RUN_PLAIN_IMPL) - { - TEST_CYCLE() result = cv::sum(src); - - SANITY_CHECK(result); - } - else - OCL_PERF_ELSE -} - -///////////// countNonZero //////////////////////// - -typedef Size_MatType countNonZeroFixture; - -PERF_TEST_P(countNonZeroFixture, countNonZero, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) -{ - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params); - - Mat src(srcSize, type); - int result = 0; - randu(src, 0, 256); - declare.in(src); - - if (RUN_OCL_IMPL) - { - ocl::oclMat oclSrc(src); - - OCL_TEST_CYCLE() result = cv::ocl::countNonZero(oclSrc); - - SANITY_CHECK(result); - } - else if (RUN_PLAIN_IMPL) - { - TEST_CYCLE() result = cv::countNonZero(src); - - SANITY_CHECK(result); - } - else - OCL_PERF_ELSE -} - ///////////// Phase //////////////////////// -typedef TestBaseWithParam PhaseFixture; +typedef Size_MatType PhaseFixture; -PERF_TEST_P(PhaseFixture, Phase, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(PhaseFixture, Phase, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); - Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1), - dst(srcSize, CV_32FC1); + Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type); declare.in(src1, src2).out(dst); randu(src1, 0, 256); randu(src2, 0, 256); @@ -704,9 +604,8 @@ PERF_TEST_P(PhaseFixture, Phase, OCL_TYPICAL_MAT_SIZES) typedef Size_MatType BitwiseAndFixture; -PERF_TEST_P(BitwiseAndFixture, bitwise_and, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32SC1))) +OCL_PERF_TEST_P(BitwiseAndFixture, Bitwise_and, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -741,9 +640,8 @@ PERF_TEST_P(BitwiseAndFixture, bitwise_and, typedef Size_MatType BitwiseXorFixture; -PERF_TEST_P(BitwiseXorFixture, bitwise_xor, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32SC1))) +OCL_PERF_TEST_P(BitwiseXorFixture, Bitwise_xor, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -778,9 +676,8 @@ PERF_TEST_P(BitwiseXorFixture, bitwise_xor, typedef Size_MatType BitwiseOrFixture; -PERF_TEST_P(BitwiseOrFixture, bitwise_or, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32SC1))) +OCL_PERF_TEST_P(BitwiseOrFixture, Bitwise_or, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -798,26 +695,25 @@ PERF_TEST_P(BitwiseOrFixture, bitwise_or, OCL_TEST_CYCLE() cv::ocl::bitwise_or(oclSrc1, oclSrc2, oclDst); oclDst.download(dst); - - SANITY_CHECK(dst); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::bitwise_or(src1, src2, dst); - - SANITY_CHECK(dst); } else OCL_PERF_ELSE + + if (CV_MAT_DEPTH(type) >= CV_32F) + cv::patchNaNs(dst, 17); + SANITY_CHECK(dst); } ///////////// bitwise_not//////////////////////// typedef Size_MatType BitwiseNotFixture; -PERF_TEST_P(BitwiseAndFixture, bitwise_not, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32SC1))) +OCL_PERF_TEST_P(BitwiseNotFixture, Bitwise_not, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -846,18 +742,57 @@ PERF_TEST_P(BitwiseAndFixture, bitwise_not, OCL_PERF_ELSE } -///////////// compare//////////////////////// +///////////// SetIdentity //////////////////////// -typedef Size_MatType CompareFixture; +typedef Size_MatType SetIdentityFixture; -PERF_TEST_P(CompareFixture, compare, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(SetIdentityFixture, SetIdentity, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); const int type = get<1>(params); + Mat src(srcSize, type); + Scalar s = Scalar::all(17); + declare.in(src, WARMUP_RNG).out(src); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() cv::ocl::setIdentity(oclSrc, s); + + oclSrc.download(src); + + SANITY_CHECK(src); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::setIdentity(src, s); + + SANITY_CHECK(src); + } + else + OCL_PERF_ELSE +} + +///////////// compare//////////////////////// + +CV_ENUM(CmpCode, CMP_LT, CMP_LE, CMP_EQ, CMP_NE, CMP_GE, CMP_GT) + +typedef std::tr1::tuple CompareParams; +typedef TestBaseWithParam CompareFixture; + +OCL_PERF_TEST_P(CompareFixture, Compare, + ::testing::Combine(OCL_TEST_SIZES, + OCL_PERF_ENUM(CV_8UC1, CV_32FC1), CmpCode::all())) +{ + const CompareParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + const int cmpCode = get<2>(params); + Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC1); declare.in(src1, src2, WARMUP_RNG).out(dst); @@ -865,7 +800,7 @@ PERF_TEST_P(CompareFixture, compare, { ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, CV_8UC1); - OCL_TEST_CYCLE() cv::ocl::compare(oclSrc1, oclSrc2, oclDst, CMP_EQ); + OCL_TEST_CYCLE() cv::ocl::compare(oclSrc1, oclSrc2, oclDst, cmpCode); oclDst.download(dst); @@ -873,7 +808,7 @@ PERF_TEST_P(CompareFixture, compare, } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::compare(src1, src2, dst, CMP_EQ); + TEST_CYCLE() cv::compare(src1, src2, dst, cmpCode); SANITY_CHECK(dst); } @@ -883,14 +818,17 @@ PERF_TEST_P(CompareFixture, compare, ///////////// pow //////////////////////// -typedef TestBaseWithParam PowFixture; +typedef Size_MatType PowFixture; -PERF_TEST_P(PowFixture, pow, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(PowFixture, Pow, ::testing::Combine( + OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); const double eps = 1e-6; - Mat src(srcSize, CV_32F), dst(srcSize, CV_32F); + Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); if (RUN_OCL_IMPL) @@ -915,9 +853,8 @@ PERF_TEST_P(PowFixture, pow, OCL_TYPICAL_MAT_SIZES) typedef Size_MatType AddWeightedFixture; -PERF_TEST_P(AddWeightedFixture, AddWeighted, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(AddWeightedFixture, AddWeighted, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -951,9 +888,8 @@ PERF_TEST_P(AddWeightedFixture, AddWeighted, typedef Size_MatType MinFixture; -PERF_TEST_P(MinFixture, Min, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(MinFixture, Min, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -986,9 +922,8 @@ PERF_TEST_P(MinFixture, Min, typedef Size_MatType MaxFixture; -PERF_TEST_P(MaxFixture, Max, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(MaxFixture, Max, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -1017,7 +952,7 @@ PERF_TEST_P(MaxFixture, Max, OCL_PERF_ELSE } -///////////// Max //////////////////////// +///////////// Abs //////////////////////// typedef Size_MatType AbsFixture; @@ -1056,9 +991,9 @@ PERF_TEST_P(AbsFixture, Abs, typedef Size_MatType RepeatFixture; -PERF_TEST_P(RepeatFixture, Repeat, - ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000), - OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4))) +OCL_PERF_TEST_P(RepeatFixture, Repeat, + ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); diff --git a/modules/ocl/perf/perf_bgfg.cpp b/modules/ocl/perf/perf_bgfg.cpp index b361a9232..c2a1941e9 100644 --- a/modules/ocl/perf/perf_bgfg.cpp +++ b/modules/ocl/perf/perf_bgfg.cpp @@ -165,11 +165,11 @@ PERF_TEST_P(VideoMOGFixture, MOG, ///////////// MOG2 //////////////////////// typedef tuple VideoMOG2ParamType; -typedef TestBaseWithParam VideoMOG2Fixture; +typedef TestBaseWithParam MOG2_Apply; -PERF_TEST_P(VideoMOG2Fixture, DISABLED_MOG2, // TODO Disabled: random hungs on buildslave - ::testing::Combine(::testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - ::testing::Values(1, 3))) +OCL_PERF_TEST_P(MOG2_Apply, Mog2, + testing::Combine(testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), + testing::Values(1, 3))) { VideoMOG2ParamType params = GetParam(); @@ -195,9 +195,7 @@ PERF_TEST_P(VideoMOG2Fixture, DISABLED_MOG2, // TODO Disabled: random hungs on b foreground.release(); for (int i = 0; i < nFrame; i++) - { mog2(frame_buffer[i], foreground); - } } SANITY_CHECK(foreground); } @@ -210,9 +208,7 @@ PERF_TEST_P(VideoMOG2Fixture, DISABLED_MOG2, // TODO Disabled: random hungs on b cv::ocl::MOG2 d_mog2; foreground_d.release(); for (int i = 0; i < nFrame; i++) - { d_mog2(frame_buffer_ocl[i], foreground_d); - } } foreground_d.download(foreground); SANITY_CHECK(foreground); @@ -223,11 +219,11 @@ PERF_TEST_P(VideoMOG2Fixture, DISABLED_MOG2, // TODO Disabled: random hungs on b ///////////// MOG2_GetBackgroundImage ////////////////// -typedef TestBaseWithParam Video_MOG2GetBackgroundImage; +typedef TestBaseWithParam MOG2_GetBackgroundImage; -PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2, - ::testing::Combine(::testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - ::testing::Values(3))) +OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, + testing::Combine(testing::Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), + testing::Values(3))) { VideoMOG2ParamType params = GetParam(); @@ -248,7 +244,7 @@ PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2, cv::ocl::oclMat foreground_d; cv::ocl::oclMat background_d; - if(RUN_PLAIN_IMPL) + if (RUN_PLAIN_IMPL) { TEST_CYCLE() { @@ -264,7 +260,7 @@ PERF_TEST_P(Video_MOG2GetBackgroundImage, MOG2, } SANITY_CHECK(background); } - else if(RUN_OCL_IMPL) + else if (RUN_OCL_IMPL) { prepareData(frame_buffer, frame_buffer_ocl); CV_Assert((int)(frame_buffer_ocl.size()) == nFrame); diff --git a/modules/ocl/perf/perf_blend.cpp b/modules/ocl/perf/perf_blend.cpp index 6f611bbc3..5471dee2e 100644 --- a/modules/ocl/perf/perf_blend.cpp +++ b/modules/ocl/perf/perf_blend.cpp @@ -88,10 +88,10 @@ typedef void (*blendFunction)(const Mat &img1, const Mat &img2, const Mat &weights1, const Mat &weights2, Mat &result_gold); -typedef Size_MatType blendLinearFixture; +typedef Size_MatType BlendLinearFixture; -PERF_TEST_P(blendLinearFixture, blendLinear, ::testing::Combine( - OCL_TYPICAL_MAT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_32FC1))) +OCL_PERF_TEST_P(BlendLinearFixture, BlendLinear, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); diff --git a/modules/ocl/perf/perf_brute_force_matcher.cpp b/modules/ocl/perf/perf_brute_force_matcher.cpp index d124428e9..b8ad81361 100644 --- a/modules/ocl/perf/perf_brute_force_matcher.cpp +++ b/modules/ocl/perf/perf_brute_force_matcher.cpp @@ -46,21 +46,23 @@ #include "perf_precomp.hpp" using namespace perf; - -#define OCL_BFMATCHER_TYPICAL_MAT_SIZES ::testing::Values(cv::Size(128, 500), cv::Size(128, 1000), cv::Size(128, 2000)) +using std::tr1::get; //////////////////// BruteForceMatch ///////////////// -typedef TestBaseWithParam BruteForceMatcherFixture; +typedef Size_MatType BruteForceMatcherFixture; -PERF_TEST_P(BruteForceMatcherFixture, match, - OCL_BFMATCHER_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(BruteForceMatcherFixture, Match, + ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + OCL_PERF_ENUM(MatType(CV_32FC1)))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); vector matches; - Mat query(srcSize, CV_32F), train(srcSize, CV_32F); - declare.in(query, train).time(srcSize.height == 2000 ? 9 : 4 ); + Mat query(srcSize, type), train(srcSize, type); + declare.in(query, train); randu(query, 0.0f, 1.0f); randu(train, 0.0f, 1.0f); @@ -75,12 +77,9 @@ PERF_TEST_P(BruteForceMatcherFixture, match, { ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist); ocl::oclMat oclQuery(query), oclTrain(train); - ocl::oclMat oclTrainIdx, oclDistance; OCL_TEST_CYCLE() - oclMatcher.matchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance); - - oclMatcher.matchDownload(oclTrainIdx, oclDistance, matches); + oclMatcher.match(oclQuery, oclTrain, matches); SANITY_CHECK_MATCHES(matches, 1e-5); } @@ -88,19 +87,20 @@ PERF_TEST_P(BruteForceMatcherFixture, match, OCL_PERF_ELSE } -PERF_TEST_P(BruteForceMatcherFixture, knnMatch, - OCL_BFMATCHER_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(BruteForceMatcherFixture, KnnMatch, + ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + OCL_PERF_ENUM(MatType(CV_32FC1)))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); vector > matches(2); - Mat query(srcSize, CV_32F), train(srcSize, CV_32F); + Mat query(srcSize, type), train(srcSize, type); randu(query, 0.0f, 1.0f); randu(train, 0.0f, 1.0f); declare.in(query, train); - if (srcSize.height == 2000) - declare.time(9); if (RUN_PLAIN_IMPL) { @@ -115,10 +115,10 @@ PERF_TEST_P(BruteForceMatcherFixture, knnMatch, { ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist); ocl::oclMat oclQuery(query), oclTrain(train); - ocl::oclMat oclTrainIdx, oclDistance, oclAllDist; + ocl::oclMat oclTrainIdx, oclDistance; OCL_TEST_CYCLE() - oclMatcher.knnMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclAllDist, 2); + oclMatcher.knnMatch(oclQuery, oclTrain, matches, 2); oclMatcher.knnMatchDownload(oclTrainIdx, oclDistance, matches); @@ -130,22 +130,22 @@ PERF_TEST_P(BruteForceMatcherFixture, knnMatch, OCL_PERF_ELSE } -PERF_TEST_P(BruteForceMatcherFixture, radiusMatch, - OCL_BFMATCHER_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(BruteForceMatcherFixture, RadiusMatch, + ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + OCL_PERF_ENUM(MatType(CV_32FC1)))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); const float max_distance = 2.0f; vector > matches(2); - Mat query(srcSize, CV_32F), train(srcSize, CV_32F); + Mat query(srcSize, type), train(srcSize, type); declare.in(query, train); randu(query, 0.0f, 1.0f); randu(train, 0.0f, 1.0f); - if (srcSize.height == 2000) - declare.time(9.15); - if (RUN_PLAIN_IMPL) { cv::BFMatcher matcher(NORM_L2); @@ -162,7 +162,7 @@ PERF_TEST_P(BruteForceMatcherFixture, radiusMatch, ocl::oclMat oclTrainIdx, oclDistance, oclNMatches; OCL_TEST_CYCLE() - oclMatcher.radiusMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclNMatches, max_distance); + oclMatcher.radiusMatch(oclQuery, oclTrain, matches, max_distance); oclMatcher.radiusMatchDownload(oclTrainIdx, oclDistance, oclNMatches, matches); @@ -173,5 +173,3 @@ PERF_TEST_P(BruteForceMatcherFixture, radiusMatch, else OCL_PERF_ELSE } - -#undef OCL_BFMATCHER_TYPICAL_MAT_SIZES diff --git a/modules/ocl/perf/perf_canny.cpp b/modules/ocl/perf/perf_canny.cpp index 33723daa3..96c444151 100644 --- a/modules/ocl/perf/perf_canny.cpp +++ b/modules/ocl/perf/perf_canny.cpp @@ -46,11 +46,21 @@ #include "perf_precomp.hpp" using namespace perf; +using std::tr1::tuple; +using std::tr1::get; ///////////// Canny //////////////////////// -PERF_TEST(CannyFixture, Canny) +typedef tuple CannyParams; +typedef TestBaseWithParam CannyFixture; + +OCL_PERF_TEST_P(CannyFixture, Canny, + ::testing::Combine(OCL_PERF_ENUM(3, 5), testing::Bool())) { + const CannyParams params = GetParam(); + int apertureSize = get<0>(params); + bool L2Grad = get<1>(params); + Mat img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE), edges(img.size(), CV_8UC1); ASSERT_TRUE(!img.empty()) << "can't open aloe-L.png"; @@ -61,16 +71,15 @@ PERF_TEST(CannyFixture, Canny) { ocl::oclMat oclImg(img), oclEdges(img.size(), CV_8UC1); - OCL_TEST_CYCLE() ocl::Canny(oclImg, oclEdges, 50.0, 100.0); + OCL_TEST_CYCLE() ocl::Canny(oclImg, oclEdges, 50.0, 100.0, apertureSize, L2Grad); oclEdges.download(edges); } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() Canny(img, edges, 50.0, 100.0); + TEST_CYCLE() Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad); } else OCL_PERF_ELSE - int value = 0; - SANITY_CHECK(value); + SANITY_CHECK_NOTHING(); } diff --git a/modules/ocl/perf/perf_color.cpp b/modules/ocl/perf/perf_color.cpp index 843331518..0797a87fd 100644 --- a/modules/ocl/perf/perf_color.cpp +++ b/modules/ocl/perf/perf_color.cpp @@ -52,36 +52,36 @@ using std::tr1::make_tuple; ///////////// cvtColor//////////////////////// -CV_ENUM(ConversionTypes, CV_RGB2GRAY, CV_RGB2BGR, CV_RGB2YUV, CV_YUV2RGB, CV_RGB2YCrCb, - CV_YCrCb2RGB, CV_RGB2XYZ, CV_XYZ2RGB, CV_RGB2HSV, CV_HSV2RGB, CV_RGB2HLS, - CV_HLS2RGB, CV_BGR5652BGR, CV_BGR2BGR565, CV_RGBA2mRGBA, CV_mRGBA2RGBA, CV_YUV2RGB_NV12) +CV_ENUM(ConversionTypes, COLOR_RGB2GRAY, COLOR_RGB2BGR, COLOR_RGB2YUV, COLOR_YUV2RGB, COLOR_RGB2YCrCb, + COLOR_YCrCb2RGB, COLOR_RGB2XYZ, COLOR_XYZ2RGB, COLOR_RGB2HSV, COLOR_HSV2RGB, COLOR_RGB2HLS, + COLOR_HLS2RGB, COLOR_BGR5652BGR, COLOR_BGR2BGR565, COLOR_RGBA2mRGBA, COLOR_mRGBA2RGBA, COLOR_YUV2RGB_NV12) -typedef tuple > cvtColorParams; -typedef TestBaseWithParam cvtColorFixture; +typedef tuple > CvtColorParams; +typedef TestBaseWithParam CvtColorFixture; -PERF_TEST_P(cvtColorFixture, cvtColor, testing::Combine( - testing::Values(Size(1000, 1002), Size(2000, 2004), Size(4000, 4008)), +OCL_PERF_TEST_P(CvtColorFixture, CvtColor, testing::Combine( + OCL_TEST_SIZES, testing::Values( - make_tuple(ConversionTypes(CV_RGB2GRAY), 3, 1), - make_tuple(ConversionTypes(CV_RGB2BGR), 3, 3), - make_tuple(ConversionTypes(CV_RGB2YUV), 3, 3), - make_tuple(ConversionTypes(CV_YUV2RGB), 3, 3), - make_tuple(ConversionTypes(CV_RGB2YCrCb), 3, 3), - make_tuple(ConversionTypes(CV_YCrCb2RGB), 3, 3), - make_tuple(ConversionTypes(CV_RGB2XYZ), 3, 3), - make_tuple(ConversionTypes(CV_XYZ2RGB), 3, 3), - make_tuple(ConversionTypes(CV_RGB2HSV), 3, 3), - make_tuple(ConversionTypes(CV_HSV2RGB), 3, 3), - make_tuple(ConversionTypes(CV_RGB2HLS), 3, 3), - make_tuple(ConversionTypes(CV_HLS2RGB), 3, 3), - make_tuple(ConversionTypes(CV_BGR5652BGR), 2, 3), - make_tuple(ConversionTypes(CV_BGR2BGR565), 3, 2), - make_tuple(ConversionTypes(CV_RGBA2mRGBA), 4, 4), - make_tuple(ConversionTypes(CV_mRGBA2RGBA), 4, 4), - make_tuple(ConversionTypes(CV_YUV2RGB_NV12), 1, 3) + make_tuple(ConversionTypes(COLOR_RGB2GRAY), 3, 1), + make_tuple(ConversionTypes(COLOR_RGB2BGR), 3, 3), + make_tuple(ConversionTypes(COLOR_RGB2YUV), 3, 3), + make_tuple(ConversionTypes(COLOR_YUV2RGB), 3, 3), + make_tuple(ConversionTypes(COLOR_RGB2YCrCb), 3, 3), + make_tuple(ConversionTypes(COLOR_YCrCb2RGB), 3, 3), + make_tuple(ConversionTypes(COLOR_RGB2XYZ), 3, 3), + make_tuple(ConversionTypes(COLOR_XYZ2RGB), 3, 3), + make_tuple(ConversionTypes(COLOR_RGB2HSV), 3, 3), + make_tuple(ConversionTypes(COLOR_HSV2RGB), 3, 3), + make_tuple(ConversionTypes(COLOR_RGB2HLS), 3, 3), + make_tuple(ConversionTypes(COLOR_HLS2RGB), 3, 3), + make_tuple(ConversionTypes(COLOR_BGR5652BGR), 2, 3), + make_tuple(ConversionTypes(COLOR_BGR2BGR565), 3, 2), + make_tuple(ConversionTypes(COLOR_RGBA2mRGBA), 4, 4), + make_tuple(ConversionTypes(COLOR_mRGBA2RGBA), 4, 4), + make_tuple(ConversionTypes(COLOR_YUV2RGB_NV12), 1, 3) ))) { - cvtColorParams params = GetParam(); + CvtColorParams params = GetParam(); const Size srcSize = get<0>(params); const tuple conversionParams = get<1>(params); const int code = get<0>(conversionParams), scn = get<1>(conversionParams), diff --git a/modules/ocl/perf/perf_fft.cpp b/modules/ocl/perf/perf_fft.cpp index 49da65936..95701b7da 100644 --- a/modules/ocl/perf/perf_fft.cpp +++ b/modules/ocl/perf/perf_fft.cpp @@ -47,6 +47,8 @@ #include "perf_precomp.hpp" using namespace perf; +using std::tr1::tuple; +using std::tr1::get; ///////////// dft //////////////////////// @@ -54,22 +56,26 @@ typedef TestBaseWithParam dftFixture; #ifdef HAVE_CLAMDFFT -PERF_TEST_P(dftFixture, dft, OCL_TYPICAL_MAT_SIZES) +typedef tuple DftParams; +typedef TestBaseWithParam DftFixture; + +OCL_PERF_TEST_P(DftFixture, Dft, ::testing::Combine(testing::Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + ::testing::Values((int)DFT_ROWS, (int)DFT_SCALE, (int)DFT_INVERSE, + (int)DFT_INVERSE | DFT_SCALE, (int)DFT_ROWS | DFT_INVERSE))) { - const Size srcSize = GetParam(); + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int flags = get<1>(params); Mat src(srcSize, CV_32FC2), dst; randu(src, 0.0f, 1.0f); declare.in(src); - if (srcSize == OCL_SIZE_4000) - declare.time(7.4); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst; - OCL_TEST_CYCLE() cv::ocl::dft(oclSrc, oclDst); + OCL_TEST_CYCLE() cv::ocl::dft(oclSrc, oclDst, Size(), flags | DFT_COMPLEX_OUTPUT); oclDst.download(dst); @@ -77,7 +83,7 @@ PERF_TEST_P(dftFixture, dft, OCL_TYPICAL_MAT_SIZES) } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::dft(src, dst); + TEST_CYCLE() cv::dft(src, dst, flags | DFT_COMPLEX_OUTPUT); SANITY_CHECK(dst); } diff --git a/modules/ocl/perf/perf_filters.cpp b/modules/ocl/perf/perf_filters.cpp index 7e5389df6..c542d647c 100644 --- a/modules/ocl/perf/perf_filters.cpp +++ b/modules/ocl/perf/perf_filters.cpp @@ -49,31 +49,30 @@ using namespace perf; using std::tr1::get; using std::tr1::tuple; +typedef tuple FilterParams; +typedef TestBaseWithParam FilterFixture; + ///////////// Blur//////////////////////// -typedef Size_MatType BlurFixture; +typedef FilterFixture BlurFixture; -PERF_TEST_P(BlurFixture, Blur, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(BlurFixture, Blur, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5))) { - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params), ksize(3, 3); - const int type = get<1>(params), bordertype = BORDER_CONSTANT; + const FilterParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), ksize = get<2>(params), bordertype = BORDER_CONSTANT; checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(5); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type); - OCL_TEST_CYCLE() cv::ocl::blur(oclSrc, oclDst, ksize, Point(-1, -1), bordertype); + OCL_TEST_CYCLE() cv::ocl::blur(oclSrc, oclDst, Size(ksize, ksize), Point(-1, -1), bordertype); oclDst.download(dst); @@ -81,7 +80,7 @@ PERF_TEST_P(BlurFixture, Blur, } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::blur(src, dst, ksize, Point(-1, -1), bordertype); + TEST_CYCLE() cv::blur(src, dst, Size(ksize, ksize), Point(-1, -1), bordertype); SANITY_CHECK(dst, 1 + DBL_EPSILON); } @@ -91,24 +90,20 @@ PERF_TEST_P(BlurFixture, Blur, ///////////// Laplacian//////////////////////// -typedef Size_MatType LaplacianFixture; +typedef FilterFixture LaplacianFixture; -PERF_TEST_P(LaplacianFixture, Laplacian, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(LaplacianFixture, Laplacian, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(1, 3))) { - const Size_MatType_t params = GetParam(); + const FilterParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params), ksize = 3; + const int type = get<1>(params), ksize = get<2>(params); checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(6); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type); @@ -117,13 +112,13 @@ PERF_TEST_P(LaplacianFixture, Laplacian, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-3); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize, 1); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-3); } else OCL_PERF_ELSE @@ -131,15 +126,14 @@ PERF_TEST_P(LaplacianFixture, Laplacian, ///////////// Erode //////////////////// -typedef Size_MatType ErodeFixture; +typedef FilterFixture ErodeFixture; -PERF_TEST_P(ErodeFixture, Erode, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4))) +OCL_PERF_TEST_P(ErodeFixture, Erode, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5))) { - const Size_MatType_t params = GetParam(); + const FilterParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params), ksize = 3; + const int type = get<1>(params), ksize = get<2>(params); const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize)); checkDeviceMaxMemoryAllocSize(srcSize, type); @@ -147,9 +141,6 @@ PERF_TEST_P(ErodeFixture, Erode, Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst).in(ker); - if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(5); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKer(ker); @@ -170,13 +161,89 @@ PERF_TEST_P(ErodeFixture, Erode, OCL_PERF_ELSE } +///////////// Dilate //////////////////// + +typedef FilterFixture DilateFixture; + +OCL_PERF_TEST_P(DilateFixture, Dilate, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5))) +{ + const FilterParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), ksize = get<2>(params); + const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize)); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + Mat src(srcSize, type), dst(srcSize, type); + declare.in(src, WARMUP_RNG).out(dst).in(ker); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKer(ker); + + OCL_TEST_CYCLE() cv::ocl::dilate(oclSrc, oclDst, oclKer); + + oclDst.download(dst); + + SANITY_CHECK(dst); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::dilate(src, dst, ker); + + SANITY_CHECK(dst); + } + else + OCL_PERF_ELSE +} + +///////////// MorphologyEx //////////////////// + +CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT) + +typedef tuple MorphologyExParams; +typedef TestBaseWithParam MorphologyExFixture; + +OCL_PERF_TEST_P(MorphologyExFixture, MorphologyEx, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, MorphOp::all(), OCL_PERF_ENUM(3, 5))) +{ + const MorphologyExParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), op = get<2>(params), ksize = get<3>(params); + const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize)); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + Mat src(srcSize, type), dst(srcSize, type); + declare.in(src, WARMUP_RNG).out(dst).in(ker); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKer(ker); + + OCL_TEST_CYCLE() cv::ocl::morphologyEx(oclSrc, oclDst, op, oclKer); + + oclDst.download(dst); + + SANITY_CHECK(dst); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::morphologyEx(src, dst, op, ker); + + SANITY_CHECK(dst); + } + else + OCL_PERF_ELSE +} + ///////////// Sobel //////////////////////// typedef Size_MatType SobelFixture; -PERF_TEST_P(SobelFixture, Sobel, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(SobelFixture, Sobel, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -187,12 +254,6 @@ PERF_TEST_P(SobelFixture, Sobel, Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) || - (srcSize == OCL_SIZE_4000 && type == CV_8UC1)) - declare.time(5.5); - else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(20); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type); @@ -201,13 +262,13 @@ PERF_TEST_P(SobelFixture, Sobel, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-3); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::Sobel(src, dst, -1, dx, dy); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-3); } else OCL_PERF_ELSE @@ -217,9 +278,8 @@ PERF_TEST_P(SobelFixture, Sobel, typedef Size_MatType ScharrFixture; -PERF_TEST_P(ScharrFixture, Scharr, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(ScharrFixture, Scharr, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -230,12 +290,6 @@ PERF_TEST_P(ScharrFixture, Scharr, Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) || - (srcSize == OCL_SIZE_4000 && type == CV_8UC1)) - declare.time(5.5); - else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(21); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type); @@ -244,7 +298,7 @@ PERF_TEST_P(ScharrFixture, Scharr, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-2); } else if (RUN_PLAIN_IMPL) { @@ -258,22 +312,21 @@ PERF_TEST_P(ScharrFixture, Scharr, ///////////// GaussianBlur //////////////////////// -typedef Size_MatType GaussianBlurFixture; +typedef FilterFixture GaussianBlurFixture; -PERF_TEST_P(GaussianBlurFixture, GaussianBlur, - ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000), - OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4))) +OCL_PERF_TEST_P(GaussianBlurFixture, GaussianBlur, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5, 7))) { - const Size_MatType_t params = GetParam(); + const FilterParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params), ksize = 7; + const int type = get<1>(params), ksize = get<2>(params); checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - const double eps = src.depth() == CV_8U ? 1 + DBL_EPSILON : 3e-4; + const double eps = src.depth() == CV_8U ? 1 + DBL_EPSILON : 5e-4; if (RUN_OCL_IMPL) { @@ -297,15 +350,14 @@ PERF_TEST_P(GaussianBlurFixture, GaussianBlur, ///////////// filter2D//////////////////////// -typedef Size_MatType filter2DFixture; +typedef FilterFixture Filter2DFixture; -PERF_TEST_P(filter2DFixture, filter2D, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(Filter2DFixture, Filter2D, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5))) { - const Size_MatType_t params = GetParam(); + const FilterParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params), ksize = 3; + const int type = get<1>(params), ksize = get<2>(params); checkDeviceMaxMemoryAllocSize(srcSize, type); @@ -313,9 +365,6 @@ PERF_TEST_P(filter2DFixture, filter2D, declare.in(src, WARMUP_RNG).in(kernel).out(dst); randu(kernel, -3.0, 3.0); - if (srcSize == OCL_SIZE_4000 && type == CV_8UC4) - declare.time(8); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKernel(kernel); @@ -324,13 +373,13 @@ PERF_TEST_P(filter2DFixture, filter2D, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 3e-2); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::filter2D(src, dst, -1, kernel); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-2); } else OCL_PERF_ELSE @@ -338,28 +387,22 @@ PERF_TEST_P(filter2DFixture, filter2D, ///////////// Bilateral//////////////////////// -typedef Size_MatType BilateralFixture; +typedef TestBaseWithParam BilateralFixture; -PERF_TEST_P(BilateralFixture, Bilateral, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC3))) +OCL_PERF_TEST_P(BilateralFixture, Bilateral, OCL_TEST_SIZES) { - const Size_MatType_t params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params), d = 7; + const Size srcSize = GetParam(); + const int d = 7; const double sigmacolor = 50.0, sigmaspace = 50.0; - checkDeviceMaxMemoryAllocSize(srcSize, type); + checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1); - Mat src(srcSize, type), dst(srcSize, type); + Mat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1); declare.in(src, WARMUP_RNG).out(dst); - if (srcSize == OCL_SIZE_4000) - declare.time(type == CV_8UC3 ? 8 : 4.5); - if (RUN_OCL_IMPL) { - ocl::oclMat oclSrc(src), oclDst(srcSize, type); + ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8UC1); OCL_TEST_CYCLE() cv::ocl::bilateralFilter(oclSrc, oclDst, d, sigmacolor, sigmaspace); @@ -377,37 +420,35 @@ PERF_TEST_P(BilateralFixture, Bilateral, OCL_PERF_ELSE } -///////////// adaptiveBilateral//////////////////////// +///////////// MedianBlur//////////////////////// -typedef Size_MatType adaptiveBilateralFixture; +typedef tuple MedianBlurParams; +typedef TestBaseWithParam MedianBlurFixture; -PERF_TEST_P(adaptiveBilateralFixture, adaptiveBilateral, - ::testing::Combine(::testing::Values(OCL_SIZE_1000), OCL_PERF_ENUM(CV_8UC1, CV_8UC3))) +OCL_PERF_TEST_P(MedianBlurFixture, Bilateral, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(3, 5))) { - const Size_MatType_t params = GetParam(); + MedianBlurParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params); - const double sigmaspace = 10.0; - Size ksize(9, 9); + const int ksize = get<1>(params); - checkDeviceMaxMemoryAllocSize(srcSize, type); + checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1); - Mat src(srcSize, type), dst(srcSize, type); + Mat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1); declare.in(src, WARMUP_RNG).out(dst); if (RUN_OCL_IMPL) { - ocl::oclMat oclSrc(src), oclDst(srcSize, type); + ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8UC1); - OCL_TEST_CYCLE() cv::ocl::adaptiveBilateralFilter(oclSrc, oclDst, ksize, sigmaspace); + OCL_TEST_CYCLE() cv::ocl::medianFilter(oclSrc, oclDst, ksize); oclDst.download(dst); - SANITY_CHECK(dst, 1.0); + SANITY_CHECK(dst); } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::adaptiveBilateralFilter(src, dst, ksize, sigmaspace); + TEST_CYCLE() cv::medianBlur(src, dst, ksize); SANITY_CHECK(dst); } diff --git a/modules/ocl/perf/perf_gemm.cpp b/modules/ocl/perf/perf_gemm.cpp index 4dcd5d4d6..69db3a099 100644 --- a/modules/ocl/perf/perf_gemm.cpp +++ b/modules/ocl/perf/perf_gemm.cpp @@ -46,30 +46,39 @@ #include "perf_precomp.hpp" using namespace perf; +using std::tr1::get; +using std::tr1::tuple; ///////////// gemm //////////////////////// -typedef TestBaseWithParam gemmFixture; - #ifdef HAVE_CLAMDBLAS -PERF_TEST_P(gemmFixture, gemm, ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000)) +typedef tuple GemmParams; +typedef TestBaseWithParam GemmFixture; + +OCL_PERF_TEST_P(GemmFixture, Gemm, ::testing::Combine( + ::testing::Values(Size(1000, 1000), Size(1500, 1500)), + ::testing::Values((int)cv::GEMM_1_T, (int)cv::GEMM_1_T | (int)cv::GEMM_2_T))) { - const Size srcSize = GetParam(); + const GemmParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1), src3(srcSize, CV_32FC1), dst(srcSize, CV_32FC1); - declare.in(src1, src2, src3).out(dst).time(srcSize == OCL_SIZE_2000 ? 65 : 8); + randu(src1, -10.0f, 10.0f); randu(src2, -10.0f, 10.0f); randu(src3, -10.0f, 10.0f); + declare.in(src1, src2, src3).out(dst); + if (RUN_OCL_IMPL) { ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclSrc3(src3), oclDst(srcSize, CV_32FC1); - OCL_TEST_CYCLE() cv::ocl::gemm(oclSrc1, oclSrc2, 1.0, oclSrc3, 1.0, oclDst); + OCL_TEST_CYCLE() cv::ocl::gemm(oclSrc1, oclSrc2, 1.0, oclSrc3, 1.0, oclDst, type); oclDst.download(dst); @@ -77,7 +86,7 @@ PERF_TEST_P(gemmFixture, gemm, ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000)) } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst); + TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst, type); SANITY_CHECK(dst, 0.01); } diff --git a/modules/ocl/perf/perf_gftt.cpp b/modules/ocl/perf/perf_gftt.cpp index af24c3489..688d24316 100644 --- a/modules/ocl/perf/perf_gftt.cpp +++ b/modules/ocl/perf/perf_gftt.cpp @@ -52,22 +52,21 @@ using std::tr1::get; ///////////// GoodFeaturesToTrack //////////////////////// -typedef tuple GoodFeaturesToTrackParams; +typedef tuple GoodFeaturesToTrackParams; typedef TestBaseWithParam GoodFeaturesToTrackFixture; -PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack, - ::testing::Combine(::testing::Values(string("gpu/opticalflow/rubberwhale1.png"), - string("gpu/stereobm/aloe-L.png")), - ::testing::Range(0.0, 4.0, 3.0))) +OCL_PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack, + ::testing::Combine(OCL_PERF_ENUM(String("gpu/opticalflow/rubberwhale1.png")), + OCL_PERF_ENUM(0.0, 3.0), testing::Bool())) { + const GoodFeaturesToTrackParams params = GetParam(); + const String fileName = get<0>(params); + const double minDistance = get<1>(params), qualityLevel = 0.01; + const bool harrisDetector = get<2>(params); + const int maxCorners = 1000; - const GoodFeaturesToTrackParams param = GetParam(); - const string fileName = getDataPath(get<0>(param)); - const int maxCorners = 2000; - const double qualityLevel = 0.01, minDistance = get<1>(param); - - Mat frame = imread(fileName, IMREAD_GRAYSCALE); - ASSERT_TRUE(!frame.empty()) << "no input image"; + Mat frame = imread(getDataPath(fileName), IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "no input image"; vector pts_gold; declare.in(frame); @@ -75,7 +74,8 @@ PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack, if (RUN_OCL_IMPL) { ocl::oclMat oclFrame(frame), pts_oclmat; - ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance); + ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance, 3, + harrisDetector); OCL_TEST_CYCLE() detector(oclFrame, pts_oclmat); @@ -86,7 +86,7 @@ PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack, else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::goodFeaturesToTrack(frame, pts_gold, - maxCorners, qualityLevel, minDistance); + maxCorners, qualityLevel, minDistance, noArray(), 3, harrisDetector); SANITY_CHECK(pts_gold); } diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index b7a1dd1a4..6b5100b6f 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -46,8 +46,13 @@ #include "perf_precomp.hpp" using namespace perf; +using namespace std; +using namespace cv; +using std::tr1::make_tuple; +using std::tr1::get; ///////////// Haar //////////////////////// + PERF_TEST(HaarFixture, Haar) { vector faces; @@ -83,3 +88,63 @@ PERF_TEST(HaarFixture, Haar) else OCL_PERF_ELSE } + +typedef std::tr1::tuple Cascade_Image_MinSize_t; +typedef perf::TestBaseWithParam Cascade_Image_MinSize; + +OCL_PERF_TEST_P(Cascade_Image_MinSize, CascadeClassifier, + testing::Combine(testing::Values( string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml"), + string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt2.xml") ), + testing::Values( string("cv/shared/lena.png"), + string("cv/cascadeandhog/images/bttf301.png"), + string("cv/cascadeandhog/images/class57.png") ), + testing::Values(30, 64, 90))) +{ + const string cascasePath = get<0>(GetParam()); + const string imagePath = get<1>(GetParam()); + const int min_size = get<2>(GetParam()); + Size minSize(min_size, min_size); + vector faces; + + Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()) << "Can't load source image: " << getDataPath(imagePath); + equalizeHist(img, img); + declare.in(img); + + if (RUN_PLAIN_IMPL) + { + CascadeClassifier cc; + ASSERT_TRUE(cc.load(getDataPath(cascasePath))) << "Can't load cascade file: " << getDataPath(cascasePath); + + while (next()) + { + faces.clear(); + + startTimer(); + cc.detectMultiScale(img, faces, 1.1, 3, CV_HAAR_SCALE_IMAGE, minSize); + stopTimer(); + } + } + else if (RUN_OCL_IMPL) + { + ocl::oclMat uimg(img); + ocl::OclCascadeClassifier cc; + ASSERT_TRUE(cc.load(getDataPath(cascasePath))) << "Can't load cascade file: " << getDataPath(cascasePath); + + while (next()) + { + faces.clear(); + ocl::finish(); + + startTimer(); + cc.detectMultiScale(uimg, faces, 1.1, 3, CV_HAAR_SCALE_IMAGE, minSize); + stopTimer(); + } + } + else + OCL_PERF_ELSE + + //sort(faces.begin(), faces.end(), comparators::RectLess()); + SANITY_CHECK_NOTHING();//(faces, min_size/5); + // using SANITY_CHECK_NOTHING() since OCL and PLAIN version may find different faces number +} diff --git a/modules/ocl/perf/perf_hog.cpp b/modules/ocl/perf/perf_hog.cpp index 2a6731117..497b73d69 100644 --- a/modules/ocl/perf/perf_hog.cpp +++ b/modules/ocl/perf/perf_hog.cpp @@ -43,7 +43,9 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ + #include "perf_precomp.hpp" +#include using namespace perf; @@ -66,13 +68,13 @@ struct RectLess : } }; -PERF_TEST(HOGFixture, HOG) +OCL_PERF_TEST(HOGFixture, HOG) { Mat src = imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE); ASSERT_TRUE(!src.empty()) << "can't open input image road.png"; vector found_locations; - declare.in(src).time(5); + declare.in(src); if (RUN_PLAIN_IMPL) { diff --git a/modules/ocl/perf/perf_imgproc.cpp b/modules/ocl/perf/perf_imgproc.cpp index e0ffe56e7..6d859a94c 100644 --- a/modules/ocl/perf/perf_imgproc.cpp +++ b/modules/ocl/perf/perf_imgproc.cpp @@ -51,9 +51,9 @@ using std::tr1::get; ///////////// equalizeHist //////////////////////// -typedef TestBaseWithParam equalizeHistFixture; +typedef TestBaseWithParam EqualizeHistFixture; -PERF_TEST_P(equalizeHistFixture, equalizeHist, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES) { const Size srcSize = GetParam(); const double eps = 1 + DBL_EPSILON; @@ -81,18 +81,54 @@ PERF_TEST_P(equalizeHistFixture, equalizeHist, OCL_TYPICAL_MAT_SIZES) OCL_PERF_ELSE } +///////////// CalcHist //////////////////////// + +typedef TestBaseWithParam CalcHistFixture; + +OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES) +{ + const Size srcSize = GetParam(); + const std::vector channels(1, 0); + std::vector ranges(2); + std::vector histSize(1, 256); + ranges[0] = 0; + ranges[1] = 256; + + Mat src(srcSize, CV_8UC1), dst(srcSize, CV_32FC1); + declare.in(src, WARMUP_RNG).out(dst); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32SC1); + + OCL_TEST_CYCLE() cv::ocl::calcHist(oclSrc, oclDst); + + oclDst.download(dst); + SANITY_CHECK(dst); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::calcHist(std::vector(1, src), channels, + noArray(), dst, histSize, ranges, false); + + dst.convertTo(dst, CV_32S); + dst = dst.reshape(1, 1); + + SANITY_CHECK(dst); + } + else + OCL_PERF_ELSE +} + /////////// CopyMakeBorder ////////////////////// -CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, - BORDER_WRAP, BORDER_REFLECT_101) +CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101) typedef tuple CopyMakeBorderParamType; typedef TestBaseWithParam CopyMakeBorderFixture; -PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4), - Border::all())) +OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, Border::all())) { const CopyMakeBorderParamType params = GetParam(); const Size srcSize = get<0>(params); @@ -125,11 +161,10 @@ PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder, ///////////// cornerMinEigenVal //////////////////////// -typedef Size_MatType cornerMinEigenValFixture; +typedef Size_MatType CornerMinEigenValFixture; -PERF_TEST_P(cornerMinEigenValFixture, cornerMinEigenVal, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -137,8 +172,7 @@ PERF_TEST_P(cornerMinEigenValFixture, cornerMinEigenVal, const int blockSize = 7, apertureSize = 1 + 2 * 3; Mat src(srcSize, type), dst(srcSize, CV_32FC1); - declare.in(src, WARMUP_RNG).out(dst) - .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3); + declare.in(src, WARMUP_RNG).out(dst); const int depth = CV_MAT_DEPTH(type); const ERROR_TYPE errorType = depth == CV_8U ? ERROR_ABSOLUTE : ERROR_RELATIVE; @@ -165,11 +199,10 @@ PERF_TEST_P(cornerMinEigenValFixture, cornerMinEigenVal, ///////////// cornerHarris //////////////////////// -typedef Size_MatType cornerHarrisFixture; +typedef Size_MatType CornerHarrisFixture; -PERF_TEST_P(cornerHarrisFixture, cornerHarris, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -177,8 +210,7 @@ PERF_TEST_P(cornerHarrisFixture, cornerHarris, Mat src(srcSize, type), dst(srcSize, CV_32FC1); randu(src, 0, 1); - declare.in(src).out(dst) - .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3); + declare.in(src).out(dst); if (RUN_OCL_IMPL) { @@ -202,11 +234,14 @@ PERF_TEST_P(cornerHarrisFixture, cornerHarris, ///////////// integral //////////////////////// -typedef TestBaseWithParam integralFixture; +typedef tuple IntegralParams; +typedef TestBaseWithParam IntegralFixture; -PERF_TEST_P(integralFixture, integral, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(IntegralFixture, DISABLED_Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F))) { - const Size srcSize = GetParam(); + const IntegralParams params = GetParam(); + const Size srcSize = get<0>(params); + const int sdepth = get<1>(params); Mat src(srcSize, CV_8UC1), dst; declare.in(src, WARMUP_RNG); @@ -215,17 +250,17 @@ PERF_TEST_P(integralFixture, integral, OCL_TYPICAL_MAT_SIZES) { ocl::oclMat oclSrc(src), oclDst; - OCL_TEST_CYCLE() cv::ocl::integral(oclSrc, oclDst); +// OCL_TEST_CYCLE() cv::ocl::integral(oclSrc, oclDst, sdepth); oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } else if (RUN_PLAIN_IMPL) { - TEST_CYCLE() cv::integral(src, dst); + TEST_CYCLE() cv::integral(src, dst, sdepth); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } else OCL_PERF_ELSE @@ -233,15 +268,13 @@ PERF_TEST_P(integralFixture, integral, OCL_TYPICAL_MAT_SIZES) ///////////// threshold//////////////////////// -CV_ENUM(ThreshType, THRESH_BINARY, THRESH_TOZERO_INV) +CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV) typedef tuple ThreshParams; typedef TestBaseWithParam ThreshFixture; -PERF_TEST_P(ThreshFixture, threshold, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC4, CV_32FC1), - ThreshType::all())) +OCL_PERF_TEST_P(ThreshFixture, Threshold, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all())) { const ThreshParams params = GetParam(); const Size srcSize = get<0>(params); @@ -463,9 +496,9 @@ static void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr } } -typedef TestBaseWithParam meanShiftFilteringFixture; +typedef TestBaseWithParam MeanShiftFilteringFixture; -PERF_TEST_P(meanShiftFilteringFixture, meanShiftFiltering, +PERF_TEST_P(MeanShiftFilteringFixture, MeanShiftFiltering, OCL_TYPICAL_MAT_SIZES) { const Size srcSize = GetParam(); @@ -473,9 +506,7 @@ PERF_TEST_P(meanShiftFilteringFixture, meanShiftFiltering, cv::TermCriteria crit(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1); Mat src(srcSize, CV_8UC4), dst(srcSize, CV_8UC4); - declare.in(src, WARMUP_RNG).out(dst) - .time(srcSize == OCL_SIZE_4000 ? - 56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8); + declare.in(src, WARMUP_RNG).out(dst); if (RUN_PLAIN_IMPL) { @@ -556,9 +587,9 @@ static void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, i } -typedef TestBaseWithParam meanShiftProcFixture; +typedef TestBaseWithParam MeanShiftProcFixture; -PERF_TEST_P(meanShiftProcFixture, meanShiftProc, +PERF_TEST_P(MeanShiftProcFixture, MeanShiftProc, OCL_TYPICAL_MAT_SIZES) { const Size srcSize = GetParam(); @@ -566,9 +597,7 @@ PERF_TEST_P(meanShiftProcFixture, meanShiftProc, Mat src(srcSize, CV_8UC4), dst1(srcSize, CV_8UC4), dst2(srcSize, CV_16SC2); - declare.in(src, WARMUP_RNG).out(dst1, dst2) - .time(srcSize == OCL_SIZE_4000 ? - 56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8);; + declare.in(src, WARMUP_RNG).out(dst1, dst2); if (RUN_PLAIN_IMPL) { @@ -598,18 +627,14 @@ PERF_TEST_P(meanShiftProcFixture, meanShiftProc, typedef TestBaseWithParam CLAHEFixture; -PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES) { const Size srcSize = GetParam(); - const string impl = getSelectedImpl(); Mat src(srcSize, CV_8UC1), dst; const double clipLimit = 40.0; declare.in(src, WARMUP_RNG); - if (srcSize == OCL_SIZE_4000) - declare.time(11); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst; @@ -632,9 +657,9 @@ PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TYPICAL_MAT_SIZES) OCL_PERF_ELSE } -///////////// columnSum//////////////////////// +///////////// ColumnSum//////////////////////// -typedef TestBaseWithParam columnSumFixture; +typedef TestBaseWithParam ColumnSumFixture; static void columnSumPerfTest(const Mat & src, Mat & dst) { @@ -646,16 +671,13 @@ static void columnSumPerfTest(const Mat & src, Mat & dst) dst.at(i, j) = dst.at(i - 1 , j) + src.at(i , j); } -PERF_TEST_P(columnSumFixture, columnSum, OCL_TYPICAL_MAT_SIZES) +PERF_TEST_P(ColumnSumFixture, ColumnSum, OCL_TYPICAL_MAT_SIZES) { const Size srcSize = GetParam(); Mat src(srcSize, CV_32FC1), dst(srcSize, CV_32FC1); declare.in(src, WARMUP_RNG).out(dst); - if (srcSize == OCL_SIZE_4000) - declare.time(5); - if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1); @@ -680,8 +702,8 @@ PERF_TEST_P(columnSumFixture, columnSum, OCL_TYPICAL_MAT_SIZES) CV_ENUM(DistType, NORM_L1, NORM_L2SQR) -typedef tuple distanceToCentersParameters; -typedef TestBaseWithParam distanceToCentersFixture; +typedef tuple DistanceToCentersParams; +typedef TestBaseWithParam DistanceToCentersFixture; static void distanceToCentersPerfTest(Mat& src, Mat& centers, Mat& dists, Mat& labels, int distType) { @@ -706,10 +728,11 @@ static void distanceToCentersPerfTest(Mat& src, Mat& centers, Mat& dists, Mat& l Mat(labels_v).copyTo(labels); } -PERF_TEST_P(distanceToCentersFixture, distanceToCenters, ::testing::Combine(::testing::Values(cv::Size(256,256), cv::Size(512,512)), DistType::all()) ) +PERF_TEST_P(DistanceToCentersFixture, DistanceToCenters, ::testing::Combine(::testing::Values(cv::Size(256,256), cv::Size(512,512)), DistType::all()) ) { - Size size = get<0>(GetParam()); - int distType = get<1>(GetParam()); + const DistanceToCentersParams params = GetParam(); + Size size = get<0>(params); + int distType = get<1>(params); Mat src(size, CV_32FC1), centers(size, CV_32FC1); Mat dists(src.rows, 1, CV_32FC1), labels(src.rows, 1, CV_32SC1); diff --git a/modules/ocl/perf/perf_imgwarp.cpp b/modules/ocl/perf/perf_imgwarp.cpp index e768d6621..56d55c03c 100644 --- a/modules/ocl/perf/perf_imgwarp.cpp +++ b/modules/ocl/perf/perf_imgwarp.cpp @@ -51,11 +51,13 @@ using std::tr1::get; ///////////// WarpAffine //////////////////////// -typedef Size_MatType WarpAffineFixture; +CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR) -PERF_TEST_P(WarpAffineFixture, WarpAffine, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +typedef tuple WarpAffineParams; +typedef TestBaseWithParam WarpAffineFixture; + +OCL_PERF_TEST_P(WarpAffineFixture, WarpAffine, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all())) { static const double coeffs[2][3] = { @@ -63,11 +65,12 @@ PERF_TEST_P(WarpAffineFixture, WarpAffine, { sin(CV_PI / 6), cos(CV_PI / 6), -100.0 } }; Mat M(2, 3, CV_64F, (void *)coeffs); - const int interpolation = INTER_NEAREST; - const Size_MatType_t params = GetParam(); + const WarpAffineParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params); + const int type = get<1>(params), interpolation = get<2>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); @@ -80,13 +83,13 @@ PERF_TEST_P(WarpAffineFixture, WarpAffine, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else OCL_PERF_ELSE @@ -94,11 +97,11 @@ PERF_TEST_P(WarpAffineFixture, WarpAffine, ///////////// WarpPerspective //////////////////////// -typedef Size_MatType WarpPerspectiveFixture; +typedef WarpAffineParams WarpPerspectiveParams; +typedef TestBaseWithParam WarpPerspectiveFixture; -PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all())) { static const double coeffs[3][3] = { @@ -107,15 +110,15 @@ PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective, {0.0, 0.0, 1.0} }; Mat M(3, 3, CV_64F, (void *)coeffs); - const int interpolation = INTER_LINEAR; - const Size_MatType_t params = GetParam(); + const WarpPerspectiveParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params); + const int type = get<1>(params), interpolation = get<2>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type), dst(srcSize, type); - declare.in(src, WARMUP_RNG).out(dst) - .time(srcSize == OCL_SIZE_4000 ? 18 : srcSize == OCL_SIZE_2000 ? 5 : 2); + declare.in(src, WARMUP_RNG).out(dst); if (RUN_OCL_IMPL) { @@ -125,32 +128,28 @@ PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else OCL_PERF_ELSE } -///////////// resize //////////////////////// +///////////// Resize //////////////////////// -CV_ENUM(resizeInterType, INTER_NEAREST, INTER_LINEAR) +typedef tuple ResizeParams; +typedef TestBaseWithParam ResizeFixture; -typedef tuple resizeParams; -typedef TestBaseWithParam resizeFixture; - -PERF_TEST_P(resizeFixture, resize, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4), - resizeInterType::all(), - ::testing::Values(0.5, 2.0))) +OCL_PERF_TEST_P(ResizeFixture, Resize, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, + InterType::all(), ::testing::Values(0.5, 2.0))) { - const resizeParams params = GetParam(); + const ResizeParams params = GetParam(); const Size srcSize = get<0>(params); const int type = get<1>(params), interType = get<2>(params); double scale = get<3>(params); @@ -162,8 +161,6 @@ PERF_TEST_P(resizeFixture, resize, Mat src(srcSize, type), dst; dst.create(dstSize, type); declare.in(src, WARMUP_RNG).out(dst); - if (interType == INTER_LINEAR && type == CV_8UC4 && OCL_SIZE_4000 == srcSize) - declare.time(11); if (RUN_OCL_IMPL) { @@ -185,15 +182,13 @@ PERF_TEST_P(resizeFixture, resize, OCL_PERF_ELSE } -typedef tuple resizeAreaParams; -typedef TestBaseWithParam resizeAreaFixture; +typedef tuple ResizeAreaParams; +typedef TestBaseWithParam ResizeAreaFixture; -PERF_TEST_P(resizeAreaFixture, resize, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), - ::testing::Values(0.3, 0.5, 0.6))) +OCL_PERF_TEST_P(ResizeAreaFixture, Resize, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, ::testing::Values(0.3, 0.5, 0.6))) { - const resizeAreaParams params = GetParam(); + const ResizeAreaParams params = GetParam(); const Size srcSize = get<0>(params); const int type = get<1>(params); double scale = get<2>(params); @@ -225,28 +220,21 @@ PERF_TEST_P(resizeAreaFixture, resize, OCL_PERF_ELSE } -///////////// remap//////////////////////// +///////////// Remap //////////////////////// -CV_ENUM(RemapInterType, INTER_NEAREST, INTER_LINEAR) +typedef tuple RemapParams; +typedef TestBaseWithParam RemapFixture; -typedef tuple remapParams; -typedef TestBaseWithParam remapFixture; - -PERF_TEST_P(remapFixture, remap, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4), - RemapInterType::all())) +OCL_PERF_TEST_P(RemapFixture, Remap, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, InterType::all())) { - const remapParams params = GetParam(); + const RemapParams params = GetParam(); const Size srcSize = get<0>(params); const int type = get<1>(params), interpolation = get<2>(params); Mat src(srcSize, type), dst(srcSize, type); declare.in(src, WARMUP_RNG).out(dst); - if (srcSize == OCL_SIZE_4000 && interpolation == INTER_LINEAR) - declare.time(9); - Mat xmap, ymap; xmap.create(srcSize, CV_32FC1); ymap.create(srcSize, CV_32FC1); @@ -287,7 +275,7 @@ PERF_TEST_P(remapFixture, remap, } -///////////// buildWarpPerspectiveMaps //////////////////////// +///////////// BuildWarpPerspectiveMaps //////////////////////// static void buildWarpPerspectiveMaps(const Mat &M, bool inverse, Size dsize, Mat &xmap, Mat &ymap) { @@ -323,9 +311,9 @@ static void buildWarpPerspectiveMaps(const Mat &M, bool inverse, Size dsize, Mat } } -typedef TestBaseWithParam buildWarpPerspectiveMapsFixture; +typedef TestBaseWithParam BuildWarpPerspectiveMapsFixture; -PERF_TEST_P(buildWarpPerspectiveMapsFixture, Inverse, OCL_TYPICAL_MAT_SIZES) +PERF_TEST_P(BuildWarpPerspectiveMapsFixture, Inverse, OCL_TYPICAL_MAT_SIZES) { static const double coeffs[3][3] = { diff --git a/modules/ocl/perf/perf_match_template.cpp b/modules/ocl/perf/perf_match_template.cpp index 3ee038a84..7378dda54 100644 --- a/modules/ocl/perf/perf_match_template.cpp +++ b/modules/ocl/perf/perf_match_template.cpp @@ -43,6 +43,7 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ + #include "perf_precomp.hpp" using namespace perf; @@ -53,8 +54,8 @@ using std::tr1::get; typedef Size_MatType CV_TM_CCORRFixture; -PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate, - ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000), +OCL_PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate, + ::testing::Combine(::testing::Values(Size(1000, 1000), Size(2000, 2000)), OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) { const Size_MatType_t params = GetParam(); @@ -66,7 +67,7 @@ PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate, Mat dst(dstSize, CV_32F); randu(src, 0.0f, 1.0f); randu(templ, 0.0f, 1.0f); - declare.time(srcSize == OCL_SIZE_2000 ? 20 : 6).in(src, templ).out(dst); + declare.in(src, templ).out(dst); if (RUN_OCL_IMPL) { @@ -90,15 +91,15 @@ PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate, typedef TestBaseWithParam CV_TM_CCORR_NORMEDFixture; -PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate, OCL_TYPICAL_MAT_SIZES) +OCL_PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate, + ::testing::Values(Size(1000, 1000), Size(2000, 2000), Size(4000, 4000))) { const Size srcSize = GetParam(), templSize(5, 5); Mat src(srcSize, CV_8UC1), templ(templSize, CV_8UC1), dst; const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1); dst.create(dstSize, CV_8UC1); - declare.in(src, templ, WARMUP_RNG).out(dst) - .time(srcSize == OCL_SIZE_2000 ? 10 : srcSize == OCL_SIZE_4000 ? 23 : 2); + declare.in(src, templ, WARMUP_RNG).out(dst); if (RUN_OCL_IMPL) { @@ -108,14 +109,71 @@ PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate, OCL_TYPICAL_MAT_SIZES) oclDst.download(dst); - SANITY_CHECK(dst, 3e-2); + SANITY_CHECK(dst, 2e-2); } else if (RUN_PLAIN_IMPL) { TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED); - SANITY_CHECK(dst, 3e-2); + SANITY_CHECK(dst, 2e-2); } else OCL_PERF_ELSE } + +CV_ENUM(MethodType, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED) + +typedef std::tr1::tuple ImgSize_TmplSize_Method_t; +typedef TestBaseWithParam ImgSize_TmplSize_Method; + +OCL_PERF_TEST_P(ImgSize_TmplSize_Method, MatchTemplate, + ::testing::Combine( + testing::Values(szSmall128, cv::Size(320, 240), + cv::Size(640, 480), cv::Size(800, 600), + cv::Size(1024, 768), cv::Size(1280, 1024)), + testing::Values(cv::Size(12, 12), cv::Size(28, 9), + cv::Size(8, 30), cv::Size(16, 16)), + MethodType::all() + ) + ) +{ + Size imgSz = get<0>(GetParam()); + Size tmplSz = get<1>(GetParam()); + int method = get<2>(GetParam()); + + Mat img(imgSz, CV_8UC1); + Mat tmpl(tmplSz, CV_8UC1); + Mat result(imgSz - tmplSz + Size(1, 1), CV_32F); + + bool isNormed = + method == TM_CCORR_NORMED || + method == TM_SQDIFF_NORMED || + method == TM_CCOEFF_NORMED; + + declare.in(img, tmpl, WARMUP_RNG).out(result).time(30); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclImg(img), oclTmpl(tmpl), oclResult(result.size(), CV_32F); + + OCL_TEST_CYCLE() matchTemplate(oclImg, oclTmpl, oclResult, method); + + oclResult.download(result); + } + else if (RUN_PLAIN_IMPL) + { + OCL_TEST_CYCLE() matchTemplate(img, tmpl, result, method); + } + else + OCL_PERF_ELSE + + double eps = isNormed ? 3e-2 + : 255 * 255 * tmpl.total() * 1e-4; + + if (method == TM_SQDIFF_NORMED) + SANITY_CHECK_NOTHING(); + else if (isNormed) + SANITY_CHECK(result, eps, ERROR_RELATIVE); + else + SANITY_CHECK(result, eps); +} diff --git a/modules/ocl/perf/perf_matrix_operation.cpp b/modules/ocl/perf/perf_matrix_operation.cpp index 5ca322e22..434f134ca 100644 --- a/modules/ocl/perf/perf_matrix_operation.cpp +++ b/modules/ocl/perf/perf_matrix_operation.cpp @@ -53,9 +53,7 @@ using std::tr1::get; typedef Size_MatType ConvertToFixture; -PERF_TEST_P(ConvertToFixture, ConvertTo, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(ConvertToFixture, ConvertTo, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -92,11 +90,9 @@ PERF_TEST_P(ConvertToFixture, ConvertTo, ///////////// copyTo//////////////////////// -typedef Size_MatType copyToFixture; +typedef Size_MatType CopyToFixture; -PERF_TEST_P(copyToFixture, copyTo, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(CopyToFixture, CopyTo, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -127,11 +123,9 @@ PERF_TEST_P(copyToFixture, copyTo, ///////////// setTo//////////////////////// -typedef Size_MatType setToFixture; +typedef Size_MatType SetToFixture; -PERF_TEST_P(setToFixture, setTo, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(SetToFixture, SetTo, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -164,16 +158,16 @@ PERF_TEST_P(setToFixture, setTo, /////////////////// upload /////////////////////////// -typedef tuple uploadParams; -typedef TestBaseWithParam uploadFixture; +typedef tuple UploadParams; +typedef TestBaseWithParam UploadFixture; -PERF_TEST_P(uploadFixture, upload, +PERF_TEST_P(UploadFixture, Upload, testing::Combine( OCL_TYPICAL_MAT_SIZES, testing::Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F), testing::Range(1, 5))) { - const uploadParams params = GetParam(); + const UploadParams params = GetParam(); const Size srcSize = get<0>(params); const int depth = get<1>(params), cn = get<2>(params); const int type = CV_MAKE_TYPE(depth, cn); @@ -201,15 +195,15 @@ PERF_TEST_P(uploadFixture, upload, /////////////////// download /////////////////////////// -typedef TestBaseWithParam downloadFixture; +typedef TestBaseWithParam DownloadFixture; -PERF_TEST_P(downloadFixture, download, +PERF_TEST_P(DownloadFixture, Download, testing::Combine( OCL_TYPICAL_MAT_SIZES, testing::Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F), testing::Range(1, 5))) { - const uploadParams params = GetParam(); + const UploadParams params = GetParam(); const Size srcSize = get<0>(params); const int depth = get<1>(params), cn = get<2>(params); const int type = CV_MAKE_TYPE(depth, cn); diff --git a/modules/ocl/perf/perf_ml.cpp b/modules/ocl/perf/perf_ml.cpp index db45eceb8..680045673 100644 --- a/modules/ocl/perf/perf_ml.cpp +++ b/modules/ocl/perf/perf_ml.cpp @@ -55,7 +55,7 @@ static void genData(Mat& trainData, Size size, Mat& trainLabel = Mat().setTo(Sca trainData.create(size, CV_32FC1); randu(trainData, 1.0, 100.0); - if(nClasses != 0) + if (nClasses != 0) { trainLabel.create(size.height, 1, CV_8UC1); randu(trainLabel, 0, nClasses - 1); @@ -82,7 +82,7 @@ PERF_TEST_P(KNNFixture, KNN, genData(testData, size); Mat best_label; - if(RUN_PLAIN_IMPL) + if (RUN_PLAIN_IMPL) { TEST_CYCLE() { @@ -90,7 +90,8 @@ PERF_TEST_P(KNNFixture, KNN, knn_cpu.train(trainData, trainLabels); knn_cpu.find_nearest(testData, k, &best_label); } - }else if(RUN_OCL_IMPL) + } + else if (RUN_OCL_IMPL) { cv::ocl::oclMat best_label_ocl; cv::ocl::oclMat testdata; @@ -103,7 +104,112 @@ PERF_TEST_P(KNNFixture, KNN, knn_ocl.find_nearest(testdata, k, best_label_ocl); } best_label_ocl.download(best_label); - }else + } + else OCL_PERF_ELSE SANITY_CHECK(best_label); -} \ No newline at end of file +} + + +typedef TestBaseWithParam > SVMFixture; + +// code is based on: samples\cpp\tutorial_code\ml\non_linear_svms\non_linear_svms.cpp +PERF_TEST_P(SVMFixture, DISABLED_SVM, + testing::Values(50, 100)) +{ + + const int NTRAINING_SAMPLES = get<0>(GetParam()); // Number of training samples per class + + #define FRAC_LINEAR_SEP 0.9f // Fraction of samples which compose the linear separable part + + const int WIDTH = 512, HEIGHT = 512; + + Mat trainData(2*NTRAINING_SAMPLES, 2, CV_32FC1); + Mat labels (2*NTRAINING_SAMPLES, 1, CV_32FC1); + + RNG rng(100); // Random value generation class + + // Set up the linearly separable part of the training data + int nLinearSamples = (int) (FRAC_LINEAR_SEP * NTRAINING_SAMPLES); + + // Generate random points for the class 1 + Mat trainClass = trainData.rowRange(0, nLinearSamples); + // The x coordinate of the points is in [0, 0.4) + Mat c = trainClass.colRange(0, 1); + rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(0.4 * WIDTH)); + // The y coordinate of the points is in [0, 1) + c = trainClass.colRange(1,2); + rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT)); + + // Generate random points for the class 2 + trainClass = trainData.rowRange(2*NTRAINING_SAMPLES-nLinearSamples, 2*NTRAINING_SAMPLES); + // The x coordinate of the points is in [0.6, 1] + c = trainClass.colRange(0 , 1); + rng.fill(c, RNG::UNIFORM, Scalar(0.6*WIDTH), Scalar(WIDTH)); + // The y coordinate of the points is in [0, 1) + c = trainClass.colRange(1,2); + rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT)); + + //------------------ Set up the non-linearly separable part of the training data --------------- + + // Generate random points for the classes 1 and 2 + trainClass = trainData.rowRange( nLinearSamples, 2*NTRAINING_SAMPLES-nLinearSamples); + // The x coordinate of the points is in [0.4, 0.6) + c = trainClass.colRange(0,1); + rng.fill(c, RNG::UNIFORM, Scalar(0.4*WIDTH), Scalar(0.6*WIDTH)); + // The y coordinate of the points is in [0, 1) + c = trainClass.colRange(1,2); + rng.fill(c, RNG::UNIFORM, Scalar(1), Scalar(HEIGHT)); + + //------------------------- Set up the labels for the classes --------------------------------- + labels.rowRange( 0, NTRAINING_SAMPLES).setTo(1); // Class 1 + labels.rowRange(NTRAINING_SAMPLES, 2*NTRAINING_SAMPLES).setTo(2); // Class 2 + + //------------------------ Set up the support vector machines parameters -------------------- + CvSVMParams params; + params.svm_type = SVM::C_SVC; + params.C = 0.1; + params.kernel_type = SVM::LINEAR; + params.term_crit = TermCriteria(CV_TERMCRIT_ITER, (int)1e7, 1e-6); + + Mat dst = Mat::zeros(HEIGHT, WIDTH, CV_8UC1); + + Mat samples(WIDTH*HEIGHT, 2, CV_32FC1); + int k = 0; + for (int i = 0; i < HEIGHT; ++i) + { + for (int j = 0; j < WIDTH; ++j) + { + samples.at(k, 0) = (float)i; + samples.at(k, 0) = (float)j; + k++; + } + } + Mat results(WIDTH*HEIGHT, 1, CV_32FC1); + + CvMat samples_ = samples; + CvMat results_ = results; + + if (RUN_PLAIN_IMPL) + { + CvSVM svm; + svm.train(trainData, labels, Mat(), Mat(), params); + TEST_CYCLE() + { + svm.predict(&samples_, &results_); + } + } + else if (RUN_OCL_IMPL) + { + CvSVM_OCL svm; + svm.train(trainData, labels, Mat(), Mat(), params); + OCL_TEST_CYCLE() + { + svm.predict(&samples_, &results_); + } + } + else + OCL_PERF_ELSE + + SANITY_CHECK_NOTHING(); +} diff --git a/modules/ocl/perf/perf_moments.cpp b/modules/ocl/perf/perf_moments.cpp index 631031ecb..d6a9b5c20 100644 --- a/modules/ocl/perf/perf_moments.cpp +++ b/modules/ocl/perf/perf_moments.cpp @@ -55,22 +55,19 @@ using namespace cvtest; using namespace testing; using namespace std; - ///////////// Moments //////////////////////// -//*! performance of image -typedef tuple MomentsParamType; -typedef TestBaseWithParam MomentsFixture; -PERF_TEST_P(MomentsFixture, Moments, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_16SC1, CV_16UC1, CV_32FC1), ::testing::Bool())) +typedef tuple MomentsParams; +typedef TestBaseWithParam MomentsFixture; + +OCL_PERF_TEST_P(MomentsFixture, Moments, + ::testing::Combine(OCL_TEST_SIZES, ::testing::Bool())) { - const MomentsParamType params = GetParam(); + const MomentsParams params = GetParam(); const Size srcSize = get<0>(params); - const int type = get<1>(params); - const bool binaryImage = get<2>(params); + const bool binaryImage = get<1>(params); - Mat src(srcSize, type), dst(7, 1, CV_64F); + Mat src(srcSize, CV_8UC1), dst(7, 1, CV_64F); randu(src, 0, 255); cv::Moments mom; @@ -85,6 +82,7 @@ PERF_TEST_P(MomentsFixture, Moments, } else OCL_PERF_ELSE + cv::HuMoments(mom, dst); SANITY_CHECK(dst, 2e-1); } diff --git a/modules/ocl/perf/perf_opticalflow.cpp b/modules/ocl/perf/perf_opticalflow.cpp index bc1761b49..67079f392 100644 --- a/modules/ocl/perf/perf_opticalflow.cpp +++ b/modules/ocl/perf/perf_opticalflow.cpp @@ -52,55 +52,27 @@ using std::tr1::get; using std::tr1::tuple; using std::tr1::make_tuple; -CV_ENUM(LoadMode, IMREAD_GRAYSCALE, IMREAD_COLOR) +typedef TestBaseWithParam > PyrLKOpticalFlowFixture; -typedef tuple > PyrLKOpticalFlowParamType; -typedef TestBaseWithParam PyrLKOpticalFlowFixture; - -PERF_TEST_P(PyrLKOpticalFlowFixture, - PyrLKOpticalFlow, - ::testing::Combine( - ::testing::Values(1000, 2000, 4000), - ::testing::Values( - make_tuple - ( - string("gpu/opticalflow/rubberwhale1.png"), - string("gpu/opticalflow/rubberwhale2.png"), - LoadMode(IMREAD_COLOR) - ), - make_tuple - ( - string("gpu/stereobm/aloe-L.png"), - string("gpu/stereobm/aloe-R.png"), - LoadMode(IMREAD_GRAYSCALE) - ) - ) - ) - ) +OCL_PERF_TEST_P(PyrLKOpticalFlowFixture, + PyrLKOpticalFlow, ::testing::Values(1000, 2000, 4000)) { - PyrLKOpticalFlowParamType params = GetParam(); - tuple fileParam = get<1>(params); - const int pointsCount = get<0>(params); - const int openMode = static_cast(get<2>(fileParam)); - const string fileName0 = get<0>(fileParam), fileName1 = get<1>(fileParam); - Mat frame0 = imread(getDataPath(fileName0), openMode); - Mat frame1 = imread(getDataPath(fileName1), openMode); + const int pointsCount = get<0>(GetParam()); + + const string fileName0 = "gpu/opticalflow/rubberwhale1.png", + fileName1 = "gpu/opticalflow/rubberwhale2.png"; + Mat frame0 = imread(getDataPath(fileName0), cv::IMREAD_GRAYSCALE); + Mat frame1 = imread(getDataPath(fileName1), cv::IMREAD_GRAYSCALE); declare.in(frame0, frame1); ASSERT_FALSE(frame0.empty()) << "can't load " << fileName0; ASSERT_FALSE(frame1.empty()) << "can't load " << fileName1; - Mat grayFrame; - if (openMode == IMREAD_COLOR) - cvtColor(frame0, grayFrame, COLOR_BGR2GRAY); - else - grayFrame = frame0; - vector pts, nextPts; vector status; vector err; - goodFeaturesToTrack(grayFrame, pts, pointsCount, 0.01, 0.0); + goodFeaturesToTrack(frame0, pts, pointsCount, 0.01, 0.0); Mat ptsMat(1, static_cast(pts.size()), CV_32FC2, (void *)&pts[0]); if (RUN_PLAIN_IMPL) @@ -136,7 +108,7 @@ PERF_TEST(tvl1flowFixture, tvl1flow) const Size srcSize = frame0.size(); const double eps = 1.2; Mat flow(srcSize, CV_32FC2), flow1(srcSize, CV_32FC1), flow2(srcSize, CV_32FC1); - declare.in(frame0, frame1).out(flow1, flow2).time(159); + declare.in(frame0, frame1).out(flow1, flow2); if (RUN_PLAIN_IMPL) { @@ -178,12 +150,11 @@ CV_ENUM(farneFlagType, 0, OPTFLOW_FARNEBACK_GAUSSIAN) typedef tuple, farneFlagType, bool> FarnebackOpticalFlowParams; typedef TestBaseWithParam FarnebackOpticalFlowFixture; -PERF_TEST_P(FarnebackOpticalFlowFixture, FarnebackOpticalFlow, - ::testing::Combine( - ::testing::Values(make_tuple(5, 1.1), - make_tuple(7, 1.5)), - farneFlagType::all(), - ::testing::Bool())) +OCL_PERF_TEST_P(FarnebackOpticalFlowFixture, FarnebackOpticalFlow, + ::testing::Combine( + ::testing::Values(make_tuple(5, 1.1), + make_tuple(7, 1.5)), + farneFlagType::all(), ::testing::Bool())) { Mat frame0 = imread(getDataPath("gpu/opticalflow/rubberwhale1.png"), cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame0.empty()) << "can't load rubberwhale1.png"; diff --git a/modules/ocl/perf/perf_precomp.hpp b/modules/ocl/perf/perf_precomp.hpp index a8663df99..5f92be820 100644 --- a/modules/ocl/perf/perf_precomp.hpp +++ b/modules/ocl/perf/perf_precomp.hpp @@ -70,8 +70,7 @@ #include "opencv2/ocl/ocl.hpp" #include "opencv2/ts/ts.hpp" -using namespace std; -using namespace cv; +// TODO remove it #define OCL_SIZE_1000 Size(1000, 1000) #define OCL_SIZE_2000 Size(2000, 2000) @@ -79,6 +78,19 @@ using namespace cv; #define OCL_TYPICAL_MAT_SIZES ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000, OCL_SIZE_4000) +using namespace std; +using namespace cv; + +#define OCL_SIZE_1 szVGA +#define OCL_SIZE_2 sz720p +#define OCL_SIZE_3 sz1080p +#define OCL_SIZE_4 sz2160p + +#define OCL_TEST_SIZES ::testing::Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3, OCL_SIZE_4) +#define OCL_TEST_TYPES ::testing::Values(CV_8UC1, CV_32FC1, CV_8UC4, CV_32FC4) +#define OCL_TEST_TYPES_14 OCL_TEST_TYPES +#define OCL_TEST_TYPES_134 ::testing::Values(CV_8UC1, CV_32FC1, CV_8UC3, CV_32FC3, CV_8UC4, CV_32FC4) + #define OCL_PERF_ENUM(type, ...) ::testing::Values(type, ## __VA_ARGS__ ) #define IMPL_OCL "ocl" @@ -103,6 +115,31 @@ using namespace cv; CV_TEST_FAIL_NO_IMPL(); #endif +#define OCL_PERF_TEST(fixture, name) \ + class OCL##_##fixture##_##name : \ + public ::perf::TestBase \ + { \ + public: \ + OCL##_##fixture##_##name() { } \ + protected: \ + virtual void PerfTestBody(); \ + }; \ + TEST_F(OCL##_##fixture##_##name, name) { RunPerfTestBody(); } \ + void OCL##_##fixture##_##name::PerfTestBody() + +#define OCL_PERF_TEST_P(fixture, name, params) \ + class OCL##_##fixture##_##name : \ + public fixture \ + { \ + public: \ + OCL##_##fixture##_##name() { } \ + protected: \ + virtual void PerfTestBody(); \ + }; \ + TEST_P(OCL##_##fixture##_##name, name) { RunPerfTestBody(); } \ + INSTANTIATE_TEST_CASE_P(/*none*/, OCL##_##fixture##_##name, params); \ + void OCL##_##fixture##_##name::PerfTestBody() + #define OCL_TEST_CYCLE_N(n) for(declare.iterations(n); startTimer(), next(); cv::ocl::finish(), stopTimer()) #define OCL_TEST_CYCLE() for(; startTimer(), next(); cv::ocl::finish(), stopTimer()) #define OCL_TEST_CYCLE_MULTIRUN(runsNum) for(declare.runs(runsNum); startTimer(), next(); stopTimer()) for(int r = 0; r < runsNum; cv::ocl::finish(), ++r) diff --git a/modules/ocl/perf/perf_pyramid.cpp b/modules/ocl/perf/perf_pyramid.cpp index 820dd6062..b4ca25356 100644 --- a/modules/ocl/perf/perf_pyramid.cpp +++ b/modules/ocl/perf/perf_pyramid.cpp @@ -51,11 +51,10 @@ using std::tr1::get; ///////////// pyrDown ////////////////////// -typedef Size_MatType pyrDownFixture; +typedef Size_MatType PyrDownFixture; -PERF_TEST_P(pyrDownFixture, pyrDown, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(PyrDownFixture, PyrDown, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -77,7 +76,7 @@ PERF_TEST_P(pyrDownFixture, pyrDown, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else if (RUN_PLAIN_IMPL) { @@ -91,11 +90,10 @@ PERF_TEST_P(pyrDownFixture, pyrDown, ///////////// pyrUp //////////////////////// -typedef Size_MatType pyrUpFixture; +typedef Size_MatType PyrUpFixture; -PERF_TEST_P(pyrUpFixture, pyrUp, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +OCL_PERF_TEST_P(PyrUpFixture, PyrUp, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) { const Size_MatType_t params = GetParam(); const Size srcSize = get<0>(params); @@ -117,7 +115,7 @@ PERF_TEST_P(pyrUpFixture, pyrUp, oclDst.download(dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 5e-4); } else if (RUN_PLAIN_IMPL) { diff --git a/modules/ocl/perf/perf_split_merge.cpp b/modules/ocl/perf/perf_split_merge.cpp index ecfc49e33..ab3f82f58 100644 --- a/modules/ocl/perf/perf_split_merge.cpp +++ b/modules/ocl/perf/perf_split_merge.cpp @@ -51,21 +51,22 @@ using std::tr1::get; ///////////// Merge//////////////////////// -typedef Size_MatType MergeFixture; +typedef tuple MergeParams; +typedef TestBaseWithParam MergeFixture; -PERF_TEST_P(MergeFixture, Merge, - ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000), - OCL_PERF_ENUM(CV_8U, CV_32F))) +OCL_PERF_TEST_P(MergeFixture, Merge, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), + OCL_PERF_ENUM(2, 3))) { - const Size_MatType_t params = GetParam(); + const MergeParams params = GetParam(); const Size srcSize = get<0>(params); - const int depth = get<1>(params), channels = 3; - const int dstType = CV_MAKE_TYPE(depth, channels); + const int depth = get<1>(params), cn = get<2>(params), + dtype = CV_MAKE_TYPE(depth, cn); - checkDeviceMaxMemoryAllocSize(srcSize, dstType); + checkDeviceMaxMemoryAllocSize(srcSize, dtype); - Mat dst(srcSize, dstType); - vector src(channels); + Mat dst(srcSize, dtype); + vector src(cn); for (vector::iterator i = src.begin(), end = src.end(); i != end; ++i) { i->create(srcSize, CV_MAKE_TYPE(depth, 1)); @@ -75,7 +76,7 @@ PERF_TEST_P(MergeFixture, Merge, if (RUN_OCL_IMPL) { - ocl::oclMat oclDst(srcSize, dstType); + ocl::oclMat oclDst(srcSize, dtype); vector oclSrc(src.size()); for (vector::size_type i = 0, end = src.size(); i < end; ++i) oclSrc[i] = src[i]; @@ -98,49 +99,69 @@ PERF_TEST_P(MergeFixture, Merge, ///////////// Split//////////////////////// -typedef Size_MatType SplitFixture; +typedef MergeParams SplitParams; +typedef TestBaseWithParam SplitFixture; -PERF_TEST_P(SplitFixture, Split, - ::testing::Combine(OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8U, CV_32F))) +OCL_PERF_TEST_P(SplitFixture, Split, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), + OCL_PERF_ENUM(2, 3))) { - const Size_MatType_t params = GetParam(); + const SplitParams params = GetParam(); const Size srcSize = get<0>(params); - const int depth = get<1>(params), channels = 3; - const int type = CV_MAKE_TYPE(depth, channels); + const int depth = get<1>(params), cn = get<2>(params); + const int type = CV_MAKE_TYPE(depth, cn); checkDeviceMaxMemoryAllocSize(srcSize, type); Mat src(srcSize, type); + Mat dst0, dst1, dst2; declare.in(src, WARMUP_RNG); + ASSERT_TRUE(cn == 3 || cn == 2); + if (RUN_OCL_IMPL) { ocl::oclMat oclSrc(src); - vector oclDst(channels, ocl::oclMat(srcSize, CV_MAKE_TYPE(depth, 1))); + vector oclDst(cn); + oclDst[0] = ocl::oclMat(srcSize, depth); + oclDst[1] = ocl::oclMat(srcSize, depth); + if (cn == 3) + oclDst[2] = ocl::oclMat(srcSize, depth); OCL_TEST_CYCLE() cv::ocl::split(oclSrc, oclDst); - ASSERT_EQ(3, channels); - Mat dst0, dst1, dst2; oclDst[0].download(dst0); oclDst[1].download(dst1); - oclDst[2].download(dst2); - SANITY_CHECK(dst0); - SANITY_CHECK(dst1); - SANITY_CHECK(dst2); + if (cn == 3) + oclDst[2].download(dst2); } else if (RUN_PLAIN_IMPL) { - vector dst(channels, Mat(srcSize, CV_MAKE_TYPE(depth, 1))); + vector dst(cn); + dst[0] = Mat(srcSize, depth); + dst[1] = Mat(srcSize, depth); + if (cn == 3) + dst[2] = Mat(srcSize, depth); + TEST_CYCLE() cv::split(src, dst); - ASSERT_EQ(3, channels); - Mat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2]; + dst0 = dst[0]; + dst1 = dst[1]; + if (cn == 3) + dst2 = dst[2]; + } + else + OCL_PERF_ELSE + + if (cn == 2) + { + SANITY_CHECK(dst0); + SANITY_CHECK(dst1); + } + else if (cn == 3) + { SANITY_CHECK(dst0); SANITY_CHECK(dst1); SANITY_CHECK(dst2); } - else - OCL_PERF_ELSE } diff --git a/modules/ocl/perf/perf_stat.cpp b/modules/ocl/perf/perf_stat.cpp new file mode 100644 index 000000000..a48cacb59 --- /dev/null +++ b/modules/ocl/perf/perf_stat.cpp @@ -0,0 +1,276 @@ +/*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, Multicoreware, Inc., all rights reserved. +// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// @Authors +// Fangfang Bai, fangfang@multicorewareinc.com +// Jin Ma, jin@multicorewareinc.com +// +// 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" + +using namespace perf; +using std::tr1::tuple; +using std::tr1::get; + + +///////////// MinMax //////////////////////// + +typedef Size_MatType MinMaxFixture; + +PERF_TEST_P(MinMaxFixture, MinMax, + ::testing::Combine(OCL_TYPICAL_MAT_SIZES, + OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + Mat src(srcSize, type); + declare.in(src, WARMUP_RNG); + + double min_val = std::numeric_limits::max(), + max_val = std::numeric_limits::min(); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() cv::ocl::minMax(oclSrc, &min_val, &max_val); + + ASSERT_GE(max_val, min_val); + SANITY_CHECK(min_val); + SANITY_CHECK(max_val); + } + else if (RUN_PLAIN_IMPL) + { + Point min_loc, max_loc; + + TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc); + + ASSERT_GE(max_val, min_val); + SANITY_CHECK(min_val); + SANITY_CHECK(max_val); + } + else + OCL_PERF_ELSE +} + +///////////// MinMaxLoc //////////////////////// + +typedef Size_MatType MinMaxLocFixture; + +OCL_PERF_TEST_P(MinMaxLocFixture, MinMaxLoc, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + Mat src(srcSize, type); + randu(src, 0, 1); + declare.in(src); + + double min_val = 0.0, max_val = 0.0; + Point min_loc, max_loc; + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() cv::ocl::minMaxLoc(oclSrc, &min_val, &max_val, &min_loc, &max_loc); + + ASSERT_GE(max_val, min_val); + SANITY_CHECK(min_val); + SANITY_CHECK(max_val); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc); + + ASSERT_GE(max_val, min_val); + SANITY_CHECK(min_val); + SANITY_CHECK(max_val); + } + else + OCL_PERF_ELSE +} + +///////////// Sum //////////////////////// + +typedef Size_MatType SumFixture; + +OCL_PERF_TEST_P(SumFixture, Sum, + ::testing::Combine(OCL_TEST_SIZES, + OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + Mat src(srcSize, type); + Scalar result; + randu(src, 0, 60); + declare.in(src); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() result = cv::ocl::sum(oclSrc); + + SANITY_CHECK(result, 1e-6, ERROR_RELATIVE); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() result = cv::sum(src); + + SANITY_CHECK(result, 1e-6, ERROR_RELATIVE); + } + else + OCL_PERF_ELSE +} + +///////////// countNonZero //////////////////////// + +typedef Size_MatType CountNonZeroFixture; + +OCL_PERF_TEST_P(CountNonZeroFixture, CountNonZero, + ::testing::Combine(OCL_TEST_SIZES, + OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + Mat src(srcSize, type); + int result = 0; + randu(src, 0, 256); + declare.in(src); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() result = cv::ocl::countNonZero(oclSrc); + + SANITY_CHECK(result); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() result = cv::countNonZero(src); + + SANITY_CHECK(result); + } + else + OCL_PERF_ELSE +} + +///////////// meanStdDev //////////////////////// + +typedef Size_MatType MeanStdDevFixture; + +OCL_PERF_TEST_P(MeanStdDevFixture, MeanStdDev, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + Mat src(srcSize, type); + Scalar mean, stddev; + randu(src, 0, 256); + declare.in(src); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc(src); + + OCL_TEST_CYCLE() cv::ocl::meanStdDev(oclSrc, mean, stddev); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() cv::meanStdDev(src, mean, stddev); + } + else + OCL_PERF_ELSE + + SANITY_CHECK_NOTHING(); +// SANITY_CHECK(mean, 1e-6, ERROR_RELATIVE); +// SANITY_CHECK(stddev, 1e-6, ERROR_RELATIVE); +} + +///////////// norm//////////////////////// + +CV_ENUM(NormType, NORM_INF, NORM_L1, NORM_L2) + +typedef std::tr1::tuple NormParams; +typedef TestBaseWithParam NormFixture; + +OCL_PERF_TEST_P(NormFixture, Norm, + ::testing::Combine(OCL_PERF_ENUM(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3), + OCL_TEST_TYPES, NormType::all())) +{ + const NormParams params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + const int normType = get<2>(params); + perf::ERROR_TYPE errorType = type != NORM_INF ? ERROR_RELATIVE : ERROR_ABSOLUTE; + double eps = 1e-5, value; + + Mat src1(srcSize, type), src2(srcSize, type); + declare.in(src1, src2, WARMUP_RNG); + + if (RUN_OCL_IMPL) + { + ocl::oclMat oclSrc1(src1), oclSrc2(src2); + + OCL_TEST_CYCLE() value = cv::ocl::norm(oclSrc1, oclSrc2, normType); + + SANITY_CHECK(value, eps, errorType); + } + else if (RUN_PLAIN_IMPL) + { + TEST_CYCLE() value = cv::norm(src1, src2, normType); + + SANITY_CHECK(value, eps, errorType); + } + else + OCL_PERF_ELSE +} diff --git a/modules/ocl/src/arithm.cpp b/modules/ocl/src/arithm.cpp index 0b316c5ea..e7638ecc4 100644 --- a/modules/ocl/src/arithm.cpp +++ b/modules/ocl/src/arithm.cpp @@ -313,32 +313,28 @@ void cv::ocl::compare(const oclMat &src1, const oclMat &src2, oclMat &dst , int enum { SUM = 0, ABS_SUM, SQR_SUM }; -static void arithmetic_sum_buffer_run(const oclMat &src, cl_mem &dst, int groupnum, int type, int ddepth) +static void arithmetic_sum_buffer_run(const oclMat &src, cl_mem &dst, int groupnum, int type, int ddepth, int vlen) { - int ochannels = src.oclchannels(); - int all_cols = src.step / src.elemSize(); - int pre_cols = (src.offset % src.step) / src.elemSize(); - int sec_cols = all_cols - (src.offset % src.step + src.cols * src.elemSize() - 1) / src.elemSize() - 1; - int invalid_cols = pre_cols + sec_cols; - int cols = all_cols - invalid_cols , elemnum = cols * src.rows;; - int offset = src.offset / src.elemSize(); + int vElemSize = vlen * src.elemSize(); + int src_offset = src.offset / vElemSize, src_step = src.step / vElemSize; + int src_cols = src.cols / vlen, total = src.size().area() / vlen; + + vlen *= src.oclchannels(); const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" }; const char * const funcMap[] = { "FUNC_SUM", "FUNC_ABS_SUM", "FUNC_SQR_SUM" }; - const char * const channelMap[] = { " ", " ", "2", "4", "4" }; + const char * const channelMap[] = { " ", " ", "2", "4", "4", "", "", "", "8" }; string buildOptions = format("-D srcT=%s%s -D dstT=%s%s -D convertToDstT=convert_%s%s -D %s", - typeMap[src.depth()], channelMap[ochannels], - typeMap[ddepth], channelMap[ochannels], - typeMap[ddepth], channelMap[ochannels], - funcMap[type]); + typeMap[src.depth()], channelMap[vlen], typeMap[ddepth], + channelMap[vlen], typeMap[ddepth], channelMap[vlen], funcMap[type]); vector > args; - args.push_back( make_pair( sizeof(cl_int) , (void *)&cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&invalid_cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&offset)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&elemnum)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum)); args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_cols )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&total )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum )); args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst )); size_t globalThreads[3] = { groupnum * 256, 1, 1 }; @@ -360,7 +356,11 @@ Scalar arithmetic_sum(const oclMat &src, int type, int ddepth) size_t groupnum = src.clCxt->getDeviceInfo().maxComputeUnits; CV_Assert(groupnum != 0); - int dbsize = groupnum * src.oclchannels(); + int vlen = 8 / src.channels(), vElemSize = vlen * src.elemSize1(); + while (src.offset % vElemSize != 0 || src.step % vElemSize != 0 || src.cols % vlen != 0) + vlen >>= 1, vElemSize >>= 1; + + int dbsize = groupnum * src.oclchannels() * vlen; Context *clCxt = src.clCxt; AutoBuffer _buf(dbsize); @@ -368,12 +368,12 @@ Scalar arithmetic_sum(const oclMat &src, int type, int ddepth) memset(p, 0, dbsize * sizeof(T)); cl_mem dstBuffer = openCLCreateBuffer(clCxt, CL_MEM_WRITE_ONLY, dbsize * sizeof(T)); - arithmetic_sum_buffer_run(src, dstBuffer, groupnum, type, ddepth); + arithmetic_sum_buffer_run(src, dstBuffer, groupnum, type, ddepth, vlen); openCLReadBuffer(clCxt, dstBuffer, (void *)p, dbsize * sizeof(T)); openCLFree(dstBuffer); Scalar s = Scalar::all(0.0); - for (int i = 0; i < dbsize;) + for (int i = 0; i < dbsize; ) for (int j = 0; j < src.oclchannels(); j++, i++) s.val[j] += p[i]; @@ -473,20 +473,13 @@ void cv::ocl::meanStdDev(const oclMat &src, Scalar &mean, Scalar &stddev) ////////////////////////////////////////////////////////////////////////////// template -static void arithmetic_minMax_run(const oclMat &src, const oclMat & mask, cl_mem &dst, int groupnum, string kernelName) +static void arithmetic_minMax_run(const oclMat &src, const oclMat & mask, cl_mem &dst, int vlen, int groupnum) { - int all_cols = src.step / src.elemSize(); - int pre_cols = (src.offset % src.step) / src.elemSize(); - int sec_cols = all_cols - (src.offset % src.step + src.cols * src.elemSize() - 1) / src.elemSize() - 1; - int invalid_cols = pre_cols + sec_cols; - int cols = all_cols - invalid_cols , elemnum = cols * src.rows; - int offset = src.offset / src.elemSize(); - const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" }; - const char * const channelMap[] = { " ", " ", "2", "4", "4" }; + const char * const channelMap[] = { " ", " ", "2", "4", "4", "", "", "", "8" }; ostringstream stream; - stream << "-D T=" << typeMap[src.depth()] << channelMap[src.channels()]; + stream << "-D T=" << typeMap[src.depth()] << channelMap[vlen]; if (numeric_limits::is_integer) { stream << " -D MAX_VAL=" << (WT)numeric_limits::max(); @@ -494,38 +487,38 @@ static void arithmetic_minMax_run(const oclMat &src, const oclMat & mask, cl_mem } else stream << " -D DEPTH_" << src.depth(); + stream << " -D vlen=" << vlen; std::string buildOptions = stream.str(); + int vElemSize = src.elemSize1() * vlen, src_cols = src.cols / vlen; + int src_step = src.step / vElemSize, src_offset = src.offset / vElemSize; + int mask_step = mask.step / vlen, mask_offset = mask.offset / vlen; + int total = src.size().area() / vlen; + vector > args; args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data)); - args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&invalid_cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&offset)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&elemnum)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_cols )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&total)); args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum)); + args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst)); - int minvalid_cols = 0, moffset = 0; if (!mask.empty()) { - int mall_cols = mask.step / mask.elemSize(); - int mpre_cols = (mask.offset % mask.step) / mask.elemSize(); - int msec_cols = mall_cols - (mask.offset % mask.step + mask.cols * mask.elemSize() - 1) / mask.elemSize() - 1; - minvalid_cols = mpre_cols + msec_cols; - moffset = mask.offset / mask.elemSize(); - args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&minvalid_cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&moffset )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&mask_step )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&mask_offset )); - kernelName += "_mask"; + buildOptions += " -D WITH_MASK"; } - size_t globalThreads[3] = {groupnum * 256, 1, 1}; - size_t localThreads[3] = {256, 1, 1}; + size_t globalThreads[3] = { groupnum * 256, 1, 1 }; + size_t localThreads[3] = { 256, 1, 1 }; - // kernel use fixed grid size, replace lt on NULL is imposible without kernel changes - openCLExecuteKernel(src.clCxt, &arithm_minMax, kernelName, globalThreads, localThreads, + // kernel use fixed grid size, replace lt on NULL is impossible without kernel changes + openCLExecuteKernel(src.clCxt, &arithm_minMax, "arithm_op_minMax", globalThreads, localThreads, args, -1, -1, buildOptions.c_str()); } @@ -535,25 +528,33 @@ void arithmetic_minMax(const oclMat &src, double *minVal, double *maxVal, const size_t groupnum = src.clCxt->getDeviceInfo().maxComputeUnits; CV_Assert(groupnum != 0); - int dbsize = groupnum * 2 * src.elemSize(); + int vlen = mask.empty() ? 8 : 1, vElemSize = vlen * src.elemSize1(); + while (src.offset % vElemSize != 0 || src.step % vElemSize != 0 || src.cols % vlen != 0) + { + vlen >>= 1; + vElemSize >>= 1; + } + + int dbsize = groupnum * 2 * vElemSize; oclMat buf; ensureSizeIsEnough(1, dbsize, CV_8UC1, buf); cl_mem buf_data = reinterpret_cast(buf.data); - arithmetic_minMax_run(src, mask, buf_data, groupnum, "arithm_op_minMax"); + arithmetic_minMax_run(src, mask, buf_data, vlen, groupnum); Mat matbuf = Mat(buf); T *p = matbuf.ptr(); + if (minVal != NULL) { *minVal = std::numeric_limits::max(); - for (int i = 0, end = src.oclchannels() * (int)groupnum; i < end; i++) + for (int i = 0, end = vlen * (int)groupnum; i < end; i++) *minVal = *minVal < p[i] ? *minVal : p[i]; } if (maxVal != NULL) { *maxVal = -std::numeric_limits::max(); - for (int i = src.oclchannels() * (int)groupnum, end = i << 1; i < end; i++) + for (int i = vlen * (int)groupnum, end = i << 1; i < end; i++) *maxVal = *maxVal > p[i] ? *maxVal : p[i]; } } @@ -564,7 +565,7 @@ void cv::ocl::minMax(const oclMat &src, double *minVal, double *maxVal, const oc { CV_Assert(src.channels() == 1); CV_Assert(src.size() == mask.size() || mask.empty()); - CV_Assert(src.step % src.elemSize() == 0); + CV_Assert(src.step % src.elemSize1() == 0); if (minVal == NULL && maxVal == NULL) return; @@ -1139,7 +1140,7 @@ static void arithmetic_minMaxLoc_run(const oclMat &src, cl_mem &dst, int vlen , sprintf(build_options, "-D DEPTH_%d -D REPEAT_S%d -D REPEAT_E%d", src.depth(), repeat_s, repeat_e); size_t gt[3] = {groupnum * 256, 1, 1}, lt[3] = {256, 1, 1}; - // kernel use fixed grid size, replace lt on NULL is imposible without kernel changes + // kernel use fixed grid size, replace lt on NULL is impossible without kernel changes openCLExecuteKernel(src.clCxt, &arithm_minMaxLoc, "arithm_op_minMaxLoc", gt, lt, args, -1, -1, build_options); } @@ -1169,7 +1170,7 @@ static void arithmetic_minMaxLoc_mask_run(const oclMat &src, const oclMat &mask, args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data )); args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst )); - // kernel use fixed grid size, replace lt on NULL is imposible without kernel changes + // kernel use fixed grid size, replace lt on NULL is impossible without kernel changes openCLExecuteKernel(src.clCxt, &arithm_minMaxLoc_mask, "arithm_op_minMaxLoc_mask", gt, lt, args, -1, -1, build_options); } } @@ -1262,38 +1263,35 @@ void cv::ocl::minMaxLoc(const oclMat &src, double *minVal, double *maxVal, ///////////////////////////// countNonZero /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -static void arithmetic_countNonZero_run(const oclMat &src, cl_mem &dst, int groupnum, string kernelName) +static void arithmetic_countNonZero_run(const oclMat &src, cl_mem &dst, int groupnum, int vlen) { - int ochannels = src.oclchannels(); - int all_cols = src.step / src.elemSize(); - int pre_cols = (src.offset % src.step) / src.elemSize(); - int sec_cols = all_cols - (src.offset % src.step + src.cols * src.elemSize() - 1) / src.elemSize() - 1; - int invalid_cols = pre_cols + sec_cols; - int cols = all_cols - invalid_cols , elemnum = cols * src.rows;; - int offset = src.offset / src.elemSize(); + int vElemSize = vlen * src.elemSize1(); + int src_step = src.step / vElemSize, src_offset = src.offset / vElemSize; + int src_cols = src.cols / vlen, total = src.size().area() / vlen; const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" }; - const char * const channelMap[] = { " ", " ", "2", "4", "4" }; - string buildOptions = format("-D srcT=%s%s -D dstT=int%s", typeMap[src.depth()], channelMap[ochannels], - channelMap[ochannels]); + const char * const channelMap[] = { "", "", "2", "4", "4", "", "", "", "8" }; + string buildOptions = format("-D srcT=%s%s -D dstT=int%s -D convertToDstT=convert_int%s", + typeMap[src.depth()], channelMap[vlen], + channelMap[vlen], channelMap[vlen]); vector > args; - args.push_back( make_pair( sizeof(cl_int) , (void *)&cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&invalid_cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&offset)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&elemnum)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum)); args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_cols )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&total )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum )); args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst )); size_t globalThreads[3] = { groupnum * 256, 1, 1 }; #ifdef ANDROID - openCLExecuteKernel(src.clCxt, &arithm_nonzero, kernelName, globalThreads, NULL, + openCLExecuteKernel(src.clCxt, &arithm_nonzero, "arithm_op_nonzero", globalThreads, NULL, args, -1, -1, buildOptions.c_str()); #else size_t localThreads[3] = { 256, 1, 1 }; - openCLExecuteKernel(src.clCxt, &arithm_nonzero, kernelName, globalThreads, localThreads, + openCLExecuteKernel(src.clCxt, &arithm_nonzero, "arithm_op_nonzero", globalThreads, localThreads, args, -1, -1, buildOptions.c_str()); #endif } @@ -1310,18 +1308,20 @@ int cv::ocl::countNonZero(const oclMat &src) return -1; } + int vlen = 8, vElemSize = src.elemSize1() * vlen; + while (src.offset % vElemSize != 0 || src.step % vElemSize != 0 || src.cols % vlen != 0) + vlen >>= 1, vElemSize >>= 1; + size_t groupnum = src.clCxt->getDeviceInfo().maxComputeUnits; CV_Assert(groupnum != 0); - int dbsize = groupnum; - - string kernelName = "arithm_op_nonzero"; + int dbsize = groupnum * vlen; AutoBuffer _buf(dbsize); int *p = (int*)_buf, nonzero = 0; memset(p, 0, dbsize * sizeof(int)); cl_mem dstBuffer = openCLCreateBuffer(clCxt, CL_MEM_WRITE_ONLY, dbsize * sizeof(int)); - arithmetic_countNonZero_run(src, dstBuffer, groupnum, kernelName); + arithmetic_countNonZero_run(src, dstBuffer, groupnum, vlen); openCLReadBuffer(clCxt, dstBuffer, (void *)p, dbsize * sizeof(int)); for (int i = 0; i < dbsize; i++) @@ -1336,157 +1336,118 @@ int cv::ocl::countNonZero(const oclMat &src) ////////////////////////////////bitwise_op//////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -static void bitwise_unary_run(const oclMat &src1, oclMat &dst, string kernelName, const cv::ocl::ProgramEntry* source) +enum { AND = 0, OR, XOR, NOT }; + +static void bitwise_run(const oclMat & src1, const oclMat & src2, const Scalar & src3, const oclMat & mask, + oclMat & dst, int operationType) { - dst.create(src1.size(), src1.type()); - - int channels = dst.oclchannels(); - int depth = dst.depth(); - - int vector_lengths[4][7] = {{4, 4, 4, 4, 1, 1, 1}, - {4, 4, 4, 4, 1, 1, 1}, - {4, 4, 4, 4, 1, 1, 1}, - {4, 4, 4, 4, 1, 1, 1} - }; - - size_t vector_length = vector_lengths[channels - 1][depth]; - int offset_cols = (dst.offset / dst.elemSize1()) & (vector_length - 1); - int cols = divUp(dst.cols * channels + offset_cols, vector_length); - -#ifdef ANDROID - size_t localThreads[3] = { 64, 2, 1 }; -#else - size_t localThreads[3] = { 64, 4, 1 }; -#endif - size_t globalThreads[3] = { cols, dst.rows, 1 }; - - int dst_step1 = dst.cols * dst.elemSize(); - vector > args; - args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.step )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.offset )); - args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data )); - args.push_back( make_pair( sizeof(cl_int), (void *)&dst.step )); - args.push_back( make_pair( sizeof(cl_int), (void *)&dst.offset )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.rows )); - args.push_back( make_pair( sizeof(cl_int), (void *)&cols )); - args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step1 )); - - openCLExecuteKernel(src1.clCxt, source, kernelName, globalThreads, localThreads, args, -1, depth); -} - -enum { AND = 0, OR, XOR }; - -static void bitwise_binary_run(const oclMat &src1, const oclMat &src2, const Scalar& src3, const oclMat &mask, - oclMat &dst, int operationType) -{ - CV_Assert(operationType >= AND && operationType <= XOR); - CV_Assert(src2.empty() || (!src2.empty() && src1.type() == src2.type() && src1.size() == src2.size())); - CV_Assert(mask.empty() || (!mask.empty() && mask.type() == CV_8UC1 && mask.size() == src1.size())); + CV_Assert(operationType >= AND && operationType <= NOT); + CV_Assert(src2.empty() || (src1.type() == src2.type() && src1.size() == src2.size())); + CV_Assert(mask.empty() || (mask.type() == CV_8UC1 && mask.size() == src1.size())); dst.create(src1.size(), src1.type()); - oclMat m; + double scalar[4]; - const char operationMap[] = { '&', '|', '^' }; - std::string kernelName("arithm_bitwise_binary"); + bool haveScalar = src2.empty() && operationType != NOT, haveMask = !mask.empty(); + int ocn = dst.oclchannels(), depth = dst.depth(); + const char operationMap[] = { '&', '|', '^', '~' }; + const char * const typeMap[] = { "uchar", "uchar", "ushort", "ushort", "int", "int", "ulong" }; + const char * const channelMap[] = { "", "", "2", "4", "4", "", "", "", "8", "", "", "", "", "", "", "", "16" }; + const int preferredVectorWidth[] = { 4, 4, 2, 2, 1, 1, 1 }; + int kercn = haveMask || haveScalar ? ocn : preferredVectorWidth[depth]; - int vlen = std::min(8, src1.elemSize1() * src1.oclchannels()); - std::string vlenstr = vlen > 1 ? format("%d", vlen) : ""; - std::string buildOptions = format("-D Operation=%c -D vloadn=vload%s -D vstoren=vstore%s -D elemSize=%d -D vlen=%d" - " -D ucharv=uchar%s", - operationMap[operationType], vlenstr.c_str(), vlenstr.c_str(), - (int)src1.elemSize(), vlen, vlenstr.c_str()); - -#ifdef ANDROID - size_t localThreads[3] = { 16, 10, 1 }; -#else - size_t localThreads[3] = { 16, 16, 1 }; -#endif - size_t globalThreads[3] = { dst.cols, dst.rows, 1 }; - - vector > args; - args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.step )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.offset )); - - if (src2.empty()) + if (!haveScalar && !haveMask) { - m.create(1, 1, dst.type()); - m.setTo(src3); - - args.push_back( make_pair( sizeof(cl_mem), (void *)&m.data )); - - kernelName += "_scalar"; + int velemsize = dst.elemSize1() * kercn; + while (src1.offset % velemsize != 0 || src1.step % velemsize != 0 || src1.cols * ocn % kercn != 0 || + src2.offset % velemsize != 0 || src2.step % velemsize != 0 || src2.cols * ocn % kercn != 0 || + dst.offset % velemsize != 0 || dst.step % velemsize != 0 || dst.cols * ocn % kercn != 0) + kercn >>= 1, velemsize >>= 1; } - else + + int cols = dst.cols * ocn / kercn; + + std::string buildOptions = format("-D Operation=%c -D T=%s%s", operationMap[operationType], + typeMap[depth], channelMap[kercn]); + + vector > args; + args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data )); + args.push_back( make_pair( sizeof(cl_int), (void *)&src1.step )); + args.push_back( make_pair( sizeof(cl_int), (void *)&src1.offset )); + + if (haveScalar) + { + int sctype = CV_MAKE_TYPE(dst.depth(), ocn); + cv::scalarToRawData(src3, scalar, sctype); + + args.push_back( make_pair( CV_ELEM_SIZE(sctype), (void *)scalar )); + + buildOptions += " -D HAVE_SCALAR"; + } + else if (operationType != NOT) { args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data )); args.push_back( make_pair( sizeof(cl_int), (void *)&src2.step )); args.push_back( make_pair( sizeof(cl_int), (void *)&src2.offset )); + + buildOptions += " -D OP_BINARY"; } - if (!mask.empty()) + if (haveMask) { args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data )); args.push_back( make_pair( sizeof(cl_int), (void *)&mask.step )); args.push_back( make_pair( sizeof(cl_int), (void *)&mask.offset )); - kernelName += "_mask"; + buildOptions += " -D HAVE_MASK"; } args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data )); args.push_back( make_pair( sizeof(cl_int), (void *)&dst.step )); args.push_back( make_pair( sizeof(cl_int), (void *)&dst.offset )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.cols )); - args.push_back( make_pair( sizeof(cl_int), (void *)&src1.rows )); + args.push_back( make_pair( sizeof(cl_int), (void *)&dst.rows )); + args.push_back( make_pair( sizeof(cl_int), (void *)&cols )); - openCLExecuteKernel(src1.clCxt, mask.empty() ? (!src2.empty() ? &arithm_bitwise_binary : &arithm_bitwise_binary_scalar) : - (!src2.empty() ? &arithm_bitwise_binary_mask : &arithm_bitwise_binary_scalar_mask), - kernelName, globalThreads, localThreads, + size_t globalsize[3] = { dst.cols * ocn / kercn, dst.rows, 1 }; + globalsize[0] = divUp(globalsize[0], 256) * 256; + openCLExecuteKernel(src1.clCxt, &arithm_bitwise, "arithm_bitwise", globalsize, NULL, args, -1, -1, buildOptions.c_str()); } void cv::ocl::bitwise_not(const oclMat &src, oclMat &dst) { - if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F) - { - CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double"); - return; - } - - dst.create(src.size(), src.type()); - bitwise_unary_run(src, dst, "arithm_bitwise_not", &arithm_bitwise_not); + bitwise_run(src, oclMat(), Scalar(), oclMat(), dst, NOT); } void cv::ocl::bitwise_or(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, src2, Scalar(), mask, dst, OR); + bitwise_run(src1, src2, Scalar(), mask, dst, OR); } void cv::ocl::bitwise_or(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, oclMat(), src2, mask, dst, OR); + bitwise_run(src1, oclMat(), src2, mask, dst, OR); } void cv::ocl::bitwise_and(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, src2, Scalar(), mask, dst, AND); + bitwise_run(src1, src2, Scalar(), mask, dst, AND); } void cv::ocl::bitwise_and(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, oclMat(), src2, mask, dst, AND); + bitwise_run(src1, oclMat(), src2, mask, dst, AND); } void cv::ocl::bitwise_xor(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, src2, Scalar(), mask, dst, XOR); + bitwise_run(src1, src2, Scalar(), mask, dst, XOR); } void cv::ocl::bitwise_xor(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask) { - bitwise_binary_run(src1, oclMat(), src2, mask, dst, XOR); + bitwise_run(src1, oclMat(), src2, mask, dst, XOR); } oclMat cv::ocl::operator ~ (const oclMat &src) diff --git a/modules/ocl/src/cl_context.cpp b/modules/ocl/src/cl_context.cpp index 37d6bb33b..156fa9916 100644 --- a/modules/ocl/src/cl_context.cpp +++ b/modules/ocl/src/cl_context.cpp @@ -596,9 +596,16 @@ protected: CV_Assert(this != currentContext); #ifdef CL_VERSION_1_2 - if (supportsFeature(FEATURE_CL_VER_1_2)) +#ifdef WIN32 + // if process is on termination stage (ExitProcess was called and other threads were terminated) + // then disable device release because it may cause program hang + if (!__termination) +#endif { - openCLSafeCall(clReleaseDevice(clDeviceID)); + if (supportsFeature(FEATURE_CL_VER_1_2)) + { + openCLSafeCall(clReleaseDevice(clDeviceID)); + } } #endif if (deviceInfoImpl._id < 0) // not in the global registry, so we should cleanup it @@ -617,7 +624,7 @@ protected: #ifdef WIN32 // if process is on termination stage (ExitProcess was called and other threads were terminated) - // then disable command queue release because it may cause program hang + // then disable context release because it may cause program hang if (!__termination) #endif { diff --git a/modules/ocl/src/cl_runtime/cl_runtime.cpp b/modules/ocl/src/cl_runtime/cl_runtime.cpp index a0d967c0b..c3a31ccc3 100644 --- a/modules/ocl/src/cl_runtime/cl_runtime.cpp +++ b/modules/ocl/src/cl_runtime/cl_runtime.cpp @@ -45,7 +45,7 @@ #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(linux) +#if defined(__linux__) #include #include diff --git a/modules/ocl/src/cl_runtime/clamdblas_runtime.cpp b/modules/ocl/src/cl_runtime/clamdblas_runtime.cpp index 0a077db69..1256000c8 100644 --- a/modules/ocl/src/cl_runtime/clamdblas_runtime.cpp +++ b/modules/ocl/src/cl_runtime/clamdblas_runtime.cpp @@ -27,7 +27,7 @@ #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(linux) +#if defined(__linux__) #include #include diff --git a/modules/ocl/src/cl_runtime/clamdfft_runtime.cpp b/modules/ocl/src/cl_runtime/clamdfft_runtime.cpp index 60cbecef2..f0fa769b7 100644 --- a/modules/ocl/src/cl_runtime/clamdfft_runtime.cpp +++ b/modules/ocl/src/cl_runtime/clamdfft_runtime.cpp @@ -27,7 +27,7 @@ #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(linux) +#if defined(__linux__) #include #include diff --git a/modules/ocl/src/cl_runtime/generator/template/clamdblas_runtime.cpp.in b/modules/ocl/src/cl_runtime/generator/template/clamdblas_runtime.cpp.in index 8492edda9..0cf33bb7e 100644 --- a/modules/ocl/src/cl_runtime/generator/template/clamdblas_runtime.cpp.in +++ b/modules/ocl/src/cl_runtime/generator/template/clamdblas_runtime.cpp.in @@ -24,7 +24,7 @@ #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(linux) +#if defined(__linux__) #include #include diff --git a/modules/ocl/src/cl_runtime/generator/template/clamdfft_runtime.cpp.in b/modules/ocl/src/cl_runtime/generator/template/clamdfft_runtime.cpp.in index aee6bd8ab..8e8fb42c4 100644 --- a/modules/ocl/src/cl_runtime/generator/template/clamdfft_runtime.cpp.in +++ b/modules/ocl/src/cl_runtime/generator/template/clamdfft_runtime.cpp.in @@ -24,7 +24,7 @@ #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(linux) +#if defined(__linux__) #include #include diff --git a/modules/ocl/src/filtering.cpp b/modules/ocl/src/filtering.cpp index 35aa226de..77052ffbf 100644 --- a/modules/ocl/src/filtering.cpp +++ b/modules/ocl/src/filtering.cpp @@ -774,12 +774,12 @@ static void sepFilter2D_SinglePass(const oclMat &src, oclMat &dst, option += " -D KERNEL_MATRIX_X="; for(int i=0; i( &row_kernel.at(i) ) ); + option += cv::format("DIG(0x%x)", *reinterpret_cast( &row_kernel.at(i) ) ); option += "0x0"; option += " -D KERNEL_MATRIX_Y="; for(int i=0; i( &col_kernel.at(i) ) ); + option += cv::format("DIG(0x%x)", *reinterpret_cast( &col_kernel.at(i) ) ); option += "0x0"; switch(src.type()) @@ -1410,7 +1410,7 @@ Ptr cv::ocl::createSeparableLinearFilter_GPU(int srcType, int //if image size is non-degenerate and large enough //and if filter support is reasonable to satisfy larger local memory requirements, //then we can use single pass routine to avoid extra runtime calls overhead - if( clCxt && clCxt->supportsFeature(FEATURE_CL_INTEL_DEVICE) && + if( clCxt && rowKernel.rows <= 21 && columnKernel.rows <= 21 && (rowKernel.rows & 1) == 1 && (columnKernel.rows & 1) == 1 && imgSize.width > optimizedSepFilterLocalSize + (rowKernel.rows>>1) && diff --git a/modules/ocl/src/gftt.cpp b/modules/ocl/src/gftt.cpp index a82196d78..4f204d6f4 100644 --- a/modules/ocl/src/gftt.cpp +++ b/modules/ocl/src/gftt.cpp @@ -110,7 +110,6 @@ static void findCorners_caller( oclMat& counter) //output value with number of detected corners, have to be 0 before call { string opt; - std::vector k; Context * cxt = Context::getContext(); std::vector< std::pair > args; @@ -146,34 +145,33 @@ static void minMaxEig_caller(const oclMat &src, oclMat &dst, oclMat & tozero) CV_Assert(groupnum != 0); int dbsize = groupnum * 2 * src.elemSize(); - ensureSizeIsEnough(1, dbsize, CV_8UC1, dst); cl_mem dst_data = reinterpret_cast(dst.data); - int all_cols = src.step / src.elemSize(); - int pre_cols = (src.offset % src.step) / src.elemSize(); - int sec_cols = all_cols - (src.offset % src.step + src.cols * src.elemSize() - 1) / src.elemSize() - 1; - int invalid_cols = pre_cols + sec_cols; - int cols = all_cols - invalid_cols , elemnum = cols * src.rows; - int offset = src.offset / src.elemSize(); + int vElemSize = src.elemSize1(); + int src_step = src.step / vElemSize, src_offset = src.offset / vElemSize; + int total = src.size().area(); - {// first parallel pass + { + // first parallel pass vector > args; args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data)); - args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst_data )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&invalid_cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&offset)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&elemnum)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset)); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); + args.push_back( make_pair( sizeof(cl_int) , (void *)&total)); args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum)); + args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst_data )); size_t globalThreads[3] = {groupnum * 256, 1, 1}; size_t localThreads[3] = {256, 1, 1}; openCLExecuteKernel(src.clCxt, &arithm_minMax, "arithm_op_minMax", globalThreads, localThreads, - args, -1, -1, "-D T=float -D DEPTH_5"); + args, -1, -1, "-D T=float -D DEPTH_5 -D vlen=1"); } - {// run final "serial" kernel to find accumulate results from threads and reset corner counter + { + // run final "serial" kernel to find accumulate results from threads and reset corner counter vector > args; args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst_data )); args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum )); @@ -208,7 +206,7 @@ void cv::ocl::GoodFeaturesToTrackDetector_OCL::operator ()(const oclMat& image, if(!use_cpu_sorter) { // round to 2^n unsigned int n=1; - for(n=1;n<(unsigned int)corner_array_size;n<<=1); + for(n=1;n<(unsigned int)corner_array_size;n<<=1) ; corner_array_size = (int)n; ensureSizeIsEnough(1, corner_array_size , CV_32FC2, tmpCorners_); diff --git a/modules/ocl/src/haar.cpp b/modules/ocl/src/haar.cpp index e334ad913..17835f236 100644 --- a/modules/ocl/src/haar.cpp +++ b/modules/ocl/src/haar.cpp @@ -747,15 +747,6 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS oclMat gsum(totalheight + 4, gimg.cols + 1, CV_32SC1); oclMat gsqsum(totalheight + 4, gimg.cols + 1, CV_32FC1); - int sdepth = 0; - if(Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE)) - sdepth = CV_64FC1; - else - sdepth = CV_32FC1; - sdepth = CV_MAT_DEPTH(sdepth); - int type = CV_MAKE_TYPE(sdepth, 1); - oclMat gsqsum_t(totalheight + 4, gimg.cols + 1, type); - cl_mem stagebuffer; cl_mem nodebuffer; cl_mem candidatebuffer; @@ -763,7 +754,6 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS cv::Rect roi, roi2; cv::Mat imgroi, imgroisq; cv::ocl::oclMat resizeroi, gimgroi, gimgroisq; - int grp_per_CU = 12; size_t blocksize = 8; @@ -783,7 +773,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS roi2 = Rect(0, 0, sz.width - 1, sz.height - 1); resizeroi = gimg1(roi2); gimgroi = gsum(roi); - gimgroisq = gsqsum_t(roi); + gimgroisq = gsqsum(roi); int width = gimgroi.cols - 1 - cascade->orig_window_size.width; int height = gimgroi.rows - 1 - cascade->orig_window_size.height; scaleinfo[i].width_height = (width << 16) | height; @@ -797,13 +787,8 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS scaleinfo[i].factor = factor; cv::ocl::resize(gimg, resizeroi, Size(sz.width - 1, sz.height - 1), 0, 0, INTER_LINEAR); cv::ocl::integral(resizeroi, gimgroi, gimgroisq); - indexy += sz.height; } - if(gsqsum_t.depth() == CV_64F) - gsqsum_t.convertTo(gsqsum, CV_32FC1); - else - gsqsum = gsqsum_t; gcascade = (GpuHidHaarClassifierCascade *)cascade->hid_cascade; stage = (GpuHidHaarStageClassifier *)(gcascade + 1); @@ -888,12 +873,12 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS for(int y=0;y=(Height-cascade->orig_window_size.height)) + if(gy>=Height) continue; // no data to process for(int x=0;x=(Width-cascade->orig_window_size.width)) + if(gx>=Width) continue; // no data to process if(scaleinfo[z].factor<=2) @@ -1040,12 +1025,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS int n_factors = 0; oclMat gsum; oclMat gsqsum; - oclMat gsqsum_t; - cv::ocl::integral(gimg, gsum, gsqsum_t); - if(gsqsum_t.depth() == CV_64F) - gsqsum_t.convertTo(gsqsum, CV_32FC1); - else - gsqsum = gsqsum_t; + cv::ocl::integral(gimg, gsum, gsqsum); CvSize sz; vector sizev; vector scalev; @@ -1320,16 +1300,12 @@ void cv::ocl::OclCascadeClassifierBuf::detectMultiScale(oclMat &gimg, CV_OUT std roi2 = Rect(0, 0, sz.width - 1, sz.height - 1); resizeroi = gimg1(roi2); gimgroi = gsum(roi); - gimgroisq = gsqsum_t(roi); + gimgroisq = gsqsum(roi); cv::ocl::resize(gimg, resizeroi, Size(sz.width - 1, sz.height - 1), 0, 0, INTER_LINEAR); cv::ocl::integral(resizeroi, gimgroi, gimgroisq); indexy += sz.height; } - if(gsqsum_t.depth() == CV_64F) - gsqsum_t.convertTo(gsqsum, CV_32FC1); - else - gsqsum = gsqsum_t; gcascade = (GpuHidHaarClassifierCascade *)(cascade->hid_cascade); stage = (GpuHidHaarStageClassifier *)(gcascade + 1); @@ -1391,11 +1367,7 @@ void cv::ocl::OclCascadeClassifierBuf::detectMultiScale(oclMat &gimg, CV_OUT std } else { - cv::ocl::integral(gimg, gsum, gsqsum_t); - if(gsqsum_t.depth() == CV_64F) - gsqsum_t.convertTo(gsqsum, CV_32FC1); - else - gsqsum = gsqsum_t; + cv::ocl::integral(gimg, gsum, gsqsum); gcascade = (GpuHidHaarClassifierCascade *)cascade->hid_cascade; @@ -1621,7 +1593,6 @@ void cv::ocl::OclCascadeClassifierBuf::CreateFactorRelatedBufs( gimg1.release(); gsum.release(); gsqsum.release(); - gsqsum_t.release(); } else if (!(m_flags & CV_HAAR_SCALE_IMAGE) && (flags & CV_HAAR_SCALE_IMAGE)) { @@ -1696,16 +1667,6 @@ void cv::ocl::OclCascadeClassifierBuf::CreateFactorRelatedBufs( gsum.create(totalheight + 4, cols + 1, CV_32SC1); gsqsum.create(totalheight + 4, cols + 1, CV_32FC1); - int sdepth = 0; - if(Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE)) - sdepth = CV_64FC1; - else - sdepth = CV_32FC1; - sdepth = CV_MAT_DEPTH(sdepth); - int type = CV_MAKE_TYPE(sdepth, 1); - - gsqsum_t.create(totalheight + 4, cols + 1, type); - scaleinfo = (detect_piramid_info *)malloc(sizeof(detect_piramid_info) * loopcount); for( int i = 0; i < loopcount; i++ ) { diff --git a/modules/ocl/src/imgproc.cpp b/modules/ocl/src/imgproc.cpp index 3ce7ba62a..703b36de6 100644 --- a/modules/ocl/src/imgproc.cpp +++ b/modules/ocl/src/imgproc.cpp @@ -898,7 +898,7 @@ namespace cv //////////////////////////////////////////////////////////////////////// // integral - void integral(const oclMat &src, oclMat &sum, oclMat &sqsum, int sdepth) + void integral(const oclMat &src, oclMat &sum, oclMat &sqsum) { CV_Assert(src.type() == CV_8UC1); if (!src.clCxt->supportsFeature(ocl::FEATURE_CL_DOUBLE) && src.depth() == CV_64F) @@ -907,11 +907,6 @@ namespace cv return; } - if( sdepth <= 0 ) - sdepth = CV_32S; - sdepth = CV_MAT_DEPTH(sdepth); - int type = CV_MAKE_TYPE(sdepth, 1); - int vlen = 4; int offset = src.offset / vlen; int pre_invalid = src.offset % vlen; @@ -919,26 +914,17 @@ namespace cv oclMat t_sum , t_sqsum; int w = src.cols + 1, h = src.rows + 1; - - char build_option[250]; - if(Context::getContext()->supportsFeature(ocl::FEATURE_CL_DOUBLE)) - { - t_sqsum.create(src.cols, src.rows, CV_64FC1); - sqsum.create(h, w, CV_64FC1); - sprintf(build_option, "-D TYPE=double -D TYPE4=double4 -D convert_TYPE4=convert_double4"); - } - else - { - t_sqsum.create(src.cols, src.rows, CV_32FC1); - sqsum.create(h, w, CV_32FC1); - sprintf(build_option, "-D TYPE=float -D TYPE4=float4 -D convert_TYPE4=convert_float4"); - } + int depth = src.depth() == CV_8U ? CV_32S : CV_64F; + int type = CV_MAKE_TYPE(depth, 1); t_sum.create(src.cols, src.rows, type); sum.create(h, w, type); - int sum_offset = sum.offset / sum.elemSize(); - int sqsum_offset = sqsum.offset / sqsum.elemSize(); + t_sqsum.create(src.cols, src.rows, CV_32FC1); + sqsum.create(h, w, CV_32FC1); + + int sum_offset = sum.offset / vlen; + int sqsum_offset = sqsum.offset / vlen; vector > args; args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data )); @@ -950,9 +936,8 @@ namespace cv args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.step )); args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sum.step)); - args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sqsum.step)); size_t gt[3] = {((vcols + 1) / 2) * 256, 1, 1}, lt[3] = {256, 1, 1}; - openCLExecuteKernel(src.clCxt, &imgproc_integral, "integral_cols", gt, lt, args, -1, sdepth, build_option); + openCLExecuteKernel(src.clCxt, &imgproc_integral, "integral_cols", gt, lt, args, -1, depth); args.clear(); args.push_back( make_pair( sizeof(cl_mem) , (void *)&t_sum.data )); @@ -962,16 +947,15 @@ namespace cv args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sum.rows )); args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sum.cols )); args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sum.step )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sqsum.step)); args.push_back( make_pair( sizeof(cl_int) , (void *)&sum.step)); args.push_back( make_pair( sizeof(cl_int) , (void *)&sqsum.step)); args.push_back( make_pair( sizeof(cl_int) , (void *)&sum_offset)); args.push_back( make_pair( sizeof(cl_int) , (void *)&sqsum_offset)); size_t gt2[3] = {t_sum.cols * 32, 1, 1}, lt2[3] = {256, 1, 1}; - openCLExecuteKernel(src.clCxt, &imgproc_integral, "integral_rows", gt2, lt2, args, -1, sdepth, build_option); + openCLExecuteKernel(src.clCxt, &imgproc_integral, "integral_rows", gt2, lt2, args, -1, depth); } - void integral(const oclMat &src, oclMat &sum, int sdepth) + void integral(const oclMat &src, oclMat &sum) { CV_Assert(src.type() == CV_8UC1); int vlen = 4; @@ -979,13 +963,10 @@ namespace cv int pre_invalid = src.offset % vlen; int vcols = (pre_invalid + src.cols + vlen - 1) / vlen; - if( sdepth <= 0 ) - sdepth = CV_32S; - sdepth = CV_MAT_DEPTH(sdepth); - int type = CV_MAKE_TYPE(sdepth, 1); - oclMat t_sum; int w = src.cols + 1, h = src.rows + 1; + int depth = src.depth() == CV_8U ? CV_32S : CV_32F; + int type = CV_MAKE_TYPE(depth, 1); t_sum.create(src.cols, src.rows, type); sum.create(h, w, type); @@ -1001,7 +982,7 @@ namespace cv args.push_back( make_pair( sizeof(cl_int) , (void *)&src.step )); args.push_back( make_pair( sizeof(cl_int) , (void *)&t_sum.step)); size_t gt[3] = {((vcols + 1) / 2) * 256, 1, 1}, lt[3] = {256, 1, 1}; - openCLExecuteKernel(src.clCxt, &imgproc_integral_sum, "integral_sum_cols", gt, lt, args, -1, sdepth); + openCLExecuteKernel(src.clCxt, &imgproc_integral_sum, "integral_sum_cols", gt, lt, args, -1, depth); args.clear(); args.push_back( make_pair( sizeof(cl_mem) , (void *)&t_sum.data )); @@ -1012,7 +993,7 @@ namespace cv args.push_back( make_pair( sizeof(cl_int) , (void *)&sum.step)); args.push_back( make_pair( sizeof(cl_int) , (void *)&sum_offset)); size_t gt2[3] = {t_sum.cols * 32, 1, 1}, lt2[3] = {256, 1, 1}; - openCLExecuteKernel(src.clCxt, &imgproc_integral_sum, "integral_sum_rows", gt2, lt2, args, -1, sdepth); + openCLExecuteKernel(src.clCxt, &imgproc_integral_sum, "integral_sum_rows", gt2, lt2, args, -1, depth); } /////////////////////// corner ////////////////////////////// diff --git a/modules/ocl/src/match_template.cpp b/modules/ocl/src/match_template.cpp index 28397b608..afd68ffe4 100644 --- a/modules/ocl/src/match_template.cpp +++ b/modules/ocl/src/match_template.cpp @@ -245,15 +245,12 @@ namespace cv void matchTemplate_CCORR_NORMED( const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf) { - cv::ocl::oclMat temp; matchTemplate_CCORR(image, templ, result, buf); buf.image_sums.resize(1); buf.image_sqsums.resize(1); - integral(image.reshape(1), buf.image_sums[0], temp); - if(temp.depth() == CV_64F) - temp.convertTo(buf.image_sqsums[0], CV_32FC1); - else - buf.image_sqsums[0] = temp; + + integral(image.reshape(1), buf.image_sums[0], buf.image_sqsums[0]); + unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0]; Context *clCxt = image.clCxt; @@ -419,12 +416,7 @@ namespace cv { buf.image_sums.resize(1); buf.image_sqsums.resize(1); - cv::ocl::oclMat temp; - integral(image, buf.image_sums[0], temp); - if(temp.depth() == CV_64F) - temp.convertTo(buf.image_sqsums[0], CV_32FC1); - else - buf.image_sqsums[0] = temp; + integral(image, buf.image_sums[0], buf.image_sqsums[0]); templ_sum[0] = (float)sum(templ)[0]; @@ -460,14 +452,10 @@ namespace cv templ_sum *= scale; buf.image_sums.resize(buf.images.size()); buf.image_sqsums.resize(buf.images.size()); - cv::ocl::oclMat temp; + for(int i = 0; i < image.oclchannels(); i ++) { - integral(buf.images[i], buf.image_sums[i], temp); - if(temp.depth() == CV_64F) - temp.convertTo(buf.image_sqsums[i], CV_32FC1); - else - buf.image_sqsums[i] = temp; + integral(buf.images[i], buf.image_sums[i], buf.image_sqsums[i]); } switch(image.oclchannels()) diff --git a/modules/ocl/src/moments.cpp b/modules/ocl/src/moments.cpp index f11d381c9..216e9ab29 100644 --- a/modules/ocl/src/moments.cpp +++ b/modules/ocl/src/moments.cpp @@ -266,7 +266,7 @@ namespace cv int src_step = (int)(src.step/src.elemSize()); int dstm_step = (int)(dst_m.step/dst_m.elemSize()); - vector > args,args_sum; + vector > args; args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data )); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); @@ -384,4 +384,4 @@ namespace cv return mom; } } -} \ No newline at end of file +} diff --git a/modules/ocl/src/opencl/arithm_bitwise_binary.cl b/modules/ocl/src/opencl/arithm_bitwise.cl similarity index 67% rename from modules/ocl/src/opencl/arithm_bitwise_binary.cl rename to modules/ocl/src/opencl/arithm_bitwise.cl index 56cd745d2..899d41970 100644 --- a/modules/ocl/src/opencl/arithm_bitwise_binary.cl +++ b/modules/ocl/src/opencl/arithm_bitwise.cl @@ -48,35 +48,46 @@ /////////////////////////////////////////// bitwise_binary ////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// -__kernel void arithm_bitwise_binary(__global uchar * src1, int src1_step, int src1_offset, - __global uchar * src2, int src2_step, int src2_offset, - __global uchar * dst, int dst_step, int dst_offset, - int cols, int rows) +__kernel void arithm_bitwise(__global uchar * src1ptr, int src1_step, int src1_offset, +#ifdef OP_BINARY + __global uchar * src2ptr, int src2_step, int src2_offset, +#elif defined HAVE_SCALAR + T scalar, +#endif +#ifdef HAVE_MASK + __global uchar * mask, int mask_step, int mask_offset, +#endif + __global uchar * dstptr, int dst_step, int dst_offset, int dst_rows, int dst_cols) { int x = get_global_id(0); int y = get_global_id(1); - if (x < cols && y < rows) + if (x < dst_cols && y < dst_rows) { -#if elemSize > 1 - x *= elemSize; +#ifdef HAVE_MASK + mask += mad24(y, mask_step, x + mask_offset); + if (mask[0]) #endif - int src1_index = mad24(y, src1_step, x + src1_offset); - int src2_index = mad24(y, src2_step, x + src2_offset); - int dst_index = mad24(y, dst_step, x + dst_offset); - -#if elemSize > 1 - #pragma unroll - for (int i = 0; i < elemSize; i += vlen) { - ucharv t0 = vloadn(0, src1 + src1_index + i); - ucharv t1 = vloadn(0, src2 + src2_index + i); - ucharv t2 = t0 Operation t1; - - vstoren(t2, 0, dst + dst_index + i); - } -#else - dst[dst_index] = src1[src1_index] Operation src2[src2_index]; + int src1_index = mad24(y, src1_step, mad24(x, (int)sizeof(T), src1_offset)); +#ifdef OP_BINARY + int src2_index = mad24(y, src2_step, mad24(x, (int)sizeof(T), src2_offset)); #endif + int dst_index = mad24(y, dst_step, mad24(x, (int)sizeof(T), dst_offset)); + + __global const T * src1 = (__global const T *)(src1ptr + src1_index); +#ifdef OP_BINARY + __global const T * src2 = (__global const T *)(src2ptr + src2_index); +#endif + __global T * dst = (__global T *)(dstptr + dst_index); + +#ifdef OP_BINARY + dst[0] = src1[0] Operation src2[0]; +#elif defined HAVE_SCALAR + dst[0] = src1[0] Operation scalar; +#else + dst[0] = Operation src1[0]; +#endif + } } } diff --git a/modules/ocl/src/opencl/arithm_bitwise_not.cl b/modules/ocl/src/opencl/arithm_bitwise_not.cl deleted file mode 100644 index b6f76d606..000000000 --- a/modules/ocl/src/opencl/arithm_bitwise_not.cl +++ /dev/null @@ -1,253 +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 -// Jiang Liyuan, jlyuan001.good@163.com -// -// 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*/ - -#ifdef DOUBLE_SUPPORT -#ifdef cl_amd_fp64 -#pragma OPENCL EXTENSION cl_amd_fp64:enable -#elif defined (cl_khr_fp64) -#pragma OPENCL EXTENSION cl_khr_fp64:enable -#endif -#endif - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////BITWISE_NOT//////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////// - -__kernel void arithm_bitwise_not_D0 (__global uchar *src1, int src1_step, int src1_offset, - __global uchar *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - x = x << 2; - int src1_index = mad24(y, src1_step, x + src1_offset); - - int dst_end = mad24(y, dst_step, dst_offset + dst_step1); - int dst_index = mad24(y, dst_step, dst_offset + x); - - uchar4 src1_data = vload4(0, src1 + src1_index); - uchar4 dst_data = vload4(0, dst + dst_index); - uchar4 tmp_data = ~src1_data; - - dst_data.x = dst_index + 0 < dst_end ? tmp_data.x : dst_data.x; - dst_data.y = dst_index + 1 < dst_end ? tmp_data.y : dst_data.y; - dst_data.z = dst_index + 2 < dst_end ? tmp_data.z : dst_data.z; - dst_data.w = dst_index + 3 < dst_end ? tmp_data.w : dst_data.w; - - vstore4(dst_data, 0, dst + dst_index); - } -} - - -__kernel void arithm_bitwise_not_D1 (__global char *src1, int src1_step, int src1_offset, - __global char *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - x = x << 2; - int src1_index = mad24(y, src1_step, x + src1_offset); - - int dst_end = mad24(y, dst_step, dst_offset + dst_step1); - int dst_index = mad24(y, dst_step, dst_offset + x); - - char4 src1_data = vload4(0, src1 + src1_index); - char4 dst_data = vload4(0, dst + dst_index); - char4 tmp_data = ~src1_data; - - dst_data.x = dst_index + 0 < dst_end ? tmp_data.x : dst_data.x; - dst_data.y = dst_index + 1 < dst_end ? tmp_data.y : dst_data.y; - dst_data.z = dst_index + 2 < dst_end ? tmp_data.z : dst_data.z; - dst_data.w = dst_index + 3 < dst_end ? tmp_data.w : dst_data.w; - - vstore4(dst_data, 0, dst + dst_index); - } -} - - -__kernel void arithm_bitwise_not_D2 (__global ushort *src1, int src1_step, int src1_offset, - __global ushort *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) - -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - x = x << 2; - -#ifdef dst_align -#undef dst_align -#endif -#define dst_align ((dst_offset >> 1) & 3) - int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1)); - - int dst_start = mad24(y, dst_step, dst_offset); - int dst_end = mad24(y, dst_step, dst_offset + dst_step1); - int dst_index = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffff8); - - ushort4 src1_data = vload4(0, (__global ushort *)((__global char *)src1 + src1_index)); - - ushort4 dst_data = *((__global ushort4 *)((__global char *)dst + dst_index)); - ushort4 tmp_data = ~ src1_data; - - dst_data.x = ((dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : dst_data.x; - dst_data.y = ((dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.y : dst_data.y; - dst_data.z = ((dst_index + 4 >= dst_start) && (dst_index + 4 < dst_end)) ? tmp_data.z : dst_data.z; - dst_data.w = ((dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end)) ? tmp_data.w : dst_data.w; - - *((__global ushort4 *)((__global char *)dst + dst_index)) = dst_data; - } -} - - - -__kernel void arithm_bitwise_not_D3 (__global short *src1, int src1_step, int src1_offset, - __global short *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) - -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - x = x << 2; - -#ifdef dst_align -#undef dst_align -#endif -#define dst_align ((dst_offset >> 1) & 3) - int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1)); - - int dst_start = mad24(y, dst_step, dst_offset); - int dst_end = mad24(y, dst_step, dst_offset + dst_step1); - int dst_index = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffff8); - - short4 src1_data = vload4(0, (__global short *)((__global char *)src1 + src1_index)); - - short4 dst_data = *((__global short4 *)((__global char *)dst + dst_index)); - short4 tmp_data = ~ src1_data; - - dst_data.x = ((dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : dst_data.x; - dst_data.y = ((dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.y : dst_data.y; - dst_data.z = ((dst_index + 4 >= dst_start) && (dst_index + 4 < dst_end)) ? tmp_data.z : dst_data.z; - dst_data.w = ((dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end)) ? tmp_data.w : dst_data.w; - - *((__global short4 *)((__global char *)dst + dst_index)) = dst_data; - } -} - - - -__kernel void arithm_bitwise_not_D4 (__global int *src1, int src1_step, int src1_offset, - __global int *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - int src1_index = mad24(y, src1_step, (x << 2) + src1_offset); - int dst_index = mad24(y, dst_step, (x << 2) + dst_offset); - - int data1 = *((__global int *)((__global char *)src1 + src1_index)); - int tmp = ~ data1; - - *((__global int *)((__global char *)dst + dst_index)) = tmp; - } -} - -__kernel void arithm_bitwise_not_D5 (__global char *src, int src_step, int src_offset, - __global char *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - int src_index = mad24(y, src_step, (x << 2) + src_offset); - int dst_index = mad24(y, dst_step, (x << 2) + dst_offset); - - char4 data; - - data = *((__global char4 *)((__global char *)src + src_index)); - data = ~ data; - - *((__global char4 *)((__global char *)dst + dst_index)) = data; - } -} - -#if defined (DOUBLE_SUPPORT) -__kernel void arithm_bitwise_not_D6 (__global char *src, int src_step, int src_offset, - __global char *dst, int dst_step, int dst_offset, - int rows, int cols, int dst_step1) -{ - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) - { - int src_index = mad24(y, src_step, (x << 3) + src_offset); - int dst_index = mad24(y, dst_step, (x << 3) + dst_offset); - - char8 data; - - data = *((__global char8 *)((__global char *)src + src_index)); - data = ~ data; - - *((__global char8 *)((__global char *)dst + dst_index)) = data; - } -} -#endif diff --git a/modules/ocl/src/opencl/arithm_minMax.cl b/modules/ocl/src/opencl/arithm_minMax.cl index 01db7d064..b0cd1c8b6 100644 --- a/modules/ocl/src/opencl/arithm_minMax.cl +++ b/modules/ocl/src/opencl/arithm_minMax.cl @@ -63,81 +63,31 @@ /**************************************Array minMax**************************************/ -__kernel void arithm_op_minMax(__global const T * src, __global T * dst, - int cols, int invalid_cols, int offset, int elemnum, int groupnum) +__kernel void arithm_op_minMax(__global const T * src, int src_step, int src_offset, int src_rows, int src_cols, + int total, int groupnum, __global T * dst +#ifdef WITH_MASK + , __global const uchar * mask, int mask_step, int mask_offset +#endif +) { int lid = get_local_id(0); int gid = get_group_id(0); int id = get_global_id(0); - int idx = offset + id + (id / cols) * invalid_cols; - __local T localmem_max[128], localmem_min[128]; T minval = (T)(MAX_VAL), maxval = (T)(MIN_VAL), temp; + int y, x; - for (int grainSize = groupnum << 8; id < elemnum; id += grainSize) + for (int grainSize = groupnum << 8; id < total; id += grainSize) { - idx = offset + id + (id / cols) * invalid_cols; - temp = src[idx]; - minval = min(minval, temp); - maxval = max(maxval, temp); - } + y = id / src_cols; + x = id % src_cols; - if (lid > 127) - { - localmem_min[lid - 128] = minval; - localmem_max[lid - 128] = maxval; - } - barrier(CLK_LOCAL_MEM_FENCE); - - if (lid < 128) - { - localmem_min[lid] = min(minval, localmem_min[lid]); - localmem_max[lid] = max(maxval, localmem_max[lid]); - } - barrier(CLK_LOCAL_MEM_FENCE); - - for (int lsize = 64; lsize > 0; lsize >>= 1) - { - if (lid < lsize) +#ifdef WITH_MASK + if (mask[mad24(y, mask_step, x + mask_offset)]) +#endif { - int lid2 = lsize + lid; - localmem_min[lid] = min(localmem_min[lid], localmem_min[lid2]); - localmem_max[lid] = max(localmem_max[lid], localmem_max[lid2]); - } - barrier(CLK_LOCAL_MEM_FENCE); - } - - if (lid == 0) - { - dst[gid] = localmem_min[0]; - dst[gid + groupnum] = localmem_max[0]; - } -} - -__kernel void arithm_op_minMax_mask(__global const T * src, __global T * dst, - int cols, int invalid_cols, int offset, - int elemnum, int groupnum, - const __global uchar * mask, int minvalid_cols, int moffset) -{ - int lid = get_local_id(0); - int gid = get_group_id(0); - int id = get_global_id(0); - - int idx = offset + id + (id / cols) * invalid_cols; - int midx = moffset + id + (id / cols) * minvalid_cols; - - __local T localmem_max[128], localmem_min[128]; - T minval = (T)(MAX_VAL), maxval = (T)(MIN_VAL), temp; - - for (int grainSize = groupnum << 8; id < elemnum; id += grainSize) - { - idx = offset + id + (id / cols) * invalid_cols; - midx = moffset + id + (id / cols) * minvalid_cols; - - if (mask[midx]) - { - temp = src[idx]; + temp = src[mad24(y, src_step, x + src_offset)]; minval = min(minval, temp); maxval = max(maxval, temp); } diff --git a/modules/ocl/src/opencl/arithm_nonzero.cl b/modules/ocl/src/opencl/arithm_nonzero.cl index 3180c26e8..6a21f27e0 100644 --- a/modules/ocl/src/opencl/arithm_nonzero.cl +++ b/modules/ocl/src/opencl/arithm_nonzero.cl @@ -52,23 +52,18 @@ /**************************************Count NonZero**************************************/ -__kernel void arithm_op_nonzero(int cols, int invalid_cols, int offset, int elemnum, int groupnum, - __global srcT *src, __global dstT *dst) +__kernel void arithm_op_nonzero(__global srcT * src, int src_step, int src_offset, int src_cols, + int total, int groupnum, __global dstT * dst) { int lid = get_local_id(0); int gid = get_group_id(0); int id = get_global_id(0); - int idx = offset + id + (id / cols) * invalid_cols; __local dstT localmem_nonzero[128]; dstT nonzero = (dstT)(0); - srcT zero = (srcT)(0), one = (srcT)(1); - for (int grain = groupnum << 8; id < elemnum; id += grain) - { - idx = offset + id + (id / cols) * invalid_cols; - nonzero += src[idx] == zero ? zero : one; - } + for (int grain = groupnum << 8; id < total; id += grain) + nonzero += convertToDstT(src[mad24(id / src_cols, src_step, id % src_cols + src_offset)] == (srcT)(0)) ? (dstT)(0) : (dstT)(1); if (lid > 127) localmem_nonzero[lid - 128] = nonzero; diff --git a/modules/ocl/src/opencl/arithm_pow.cl b/modules/ocl/src/opencl/arithm_pow.cl index 385e4cc15..fe24553e9 100644 --- a/modules/ocl/src/opencl/arithm_pow.cl +++ b/modules/ocl/src/opencl/arithm_pow.cl @@ -66,7 +66,7 @@ __kernel void arithm_pow(__global VT * src, int src_step, int src_offset, int dst_index = mad24(y, dst_step, x + dst_offset); VT src_data = src[src_index]; - VT tmp = src_data > 0 ? exp(p * log(src_data)) : (src_data == 0 ? 0 : exp(p * log(fabs(src_data)))); + VT tmp = src_data > (VT)0 ? (VT)exp(p * log(src_data)) : (src_data == (VT)0 ? (VT)0 : (VT)exp(p * log(fabs(src_data)))); dst[dst_index] = tmp; } diff --git a/modules/ocl/src/opencl/arithm_sum.cl b/modules/ocl/src/opencl/arithm_sum.cl index 514cf2a7f..86015cfe9 100644 --- a/modules/ocl/src/opencl/arithm_sum.cl +++ b/modules/ocl/src/opencl/arithm_sum.cl @@ -63,21 +63,19 @@ /**************************************Array buffer SUM**************************************/ -__kernel void arithm_op_sum(int cols,int invalid_cols,int offset,int elemnum,int groupnum, - __global srcT *src, __global dstT *dst) +__kernel void arithm_op_sum(__global srcT * src, int src_step, int src_offset, int src_cols, + int total, int groupnum, __global dstT * dst) { int lid = get_local_id(0); int gid = get_group_id(0); int id = get_global_id(0); - int idx = offset + id + (id / cols) * invalid_cols; __local dstT localmem_sum[128]; dstT sum = (dstT)(0), temp; - for (int grainSize = groupnum << 8; id < elemnum; id += grainSize) + for (int grainSize = groupnum << 8; id < total; id += grainSize) { - idx = offset + id + (id / cols) * invalid_cols; - temp = convertToDstT(src[idx]); + temp = convertToDstT(src[mad24(id / src_cols, src_step, id % src_cols + src_offset)]); FUNC(temp, sum); } diff --git a/modules/ocl/src/opencl/bgfg_mog.cl b/modules/ocl/src/opencl/bgfg_mog.cl index 6a95316f0..a7479b929 100644 --- a/modules/ocl/src/opencl/bgfg_mog.cl +++ b/modules/ocl/src/opencl/bgfg_mog.cl @@ -376,7 +376,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob for (int mode = 0; mode < nmodes; ++mode) { float _weight = alpha1 * weight[(mode * frame_row + y) * weight_step + x] + prune; - + int swap_count = 0; if (!fitsPDF) { float var = variance[(mode * frame_row + y) * var_step + x]; @@ -404,6 +404,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob { if (_weight < weight[((i - 1) * frame_row + y) * weight_step + x]) break; + swap_count++; swap(weight, x, y, i - 1, frame_row, weight_step); swap(variance, x, y, i - 1, frame_row, var_step); #if defined (CN1) @@ -421,7 +422,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob nmodes--; } - weight[(mode * frame_row + y) * weight_step + x] = _weight; //update weight by the calculated value + weight[((mode - swap_count) * frame_row + y) * weight_step + x] = _weight; //update weight by the calculated value totalWeight += _weight; } diff --git a/modules/ocl/src/opencl/filtering_sep_filter_singlepass.cl b/modules/ocl/src/opencl/filtering_sep_filter_singlepass.cl index c6555bff0..c5f490284 100644 --- a/modules/ocl/src/opencl/filtering_sep_filter_singlepass.cl +++ b/modules/ocl/src/opencl/filtering_sep_filter_singlepass.cl @@ -84,6 +84,8 @@ #define DST(_x,_y) (((global DSTTYPE*)(Dst+DstOffset+(_y)*DstPitch))[_x]) +#define DIG(a) a, + //horizontal and vertical filter kernels //should be defined on host during compile time to avoid overhead __constant uint mat_kernelX[] = {KERNEL_MATRIX_X}; diff --git a/modules/ocl/src/opencl/haarobjectdetect.cl b/modules/ocl/src/opencl/haarobjectdetect.cl index d6e5fb9ba..2b834c2e5 100644 --- a/modules/ocl/src/opencl/haarobjectdetect.cl +++ b/modules/ocl/src/opencl/haarobjectdetect.cl @@ -62,13 +62,13 @@ typedef struct __attribute__((aligned (128) )) GpuHidHaarTreeNode GpuHidHaarTreeNode; -//typedef struct __attribute__((aligned (32))) GpuHidHaarClassifier -//{ -// int count __attribute__((aligned (4))); -// GpuHidHaarTreeNode* node __attribute__((aligned (8))); -// float* alpha __attribute__((aligned (8))); -//} -//GpuHidHaarClassifier; +typedef struct __attribute__((aligned (32))) GpuHidHaarClassifier +{ + int count __attribute__((aligned (4))); + GpuHidHaarTreeNode* node __attribute__((aligned (8))); + float* alpha __attribute__((aligned (8))); +} +GpuHidHaarClassifier; typedef struct __attribute__((aligned (64))) GpuHidHaarStageClassifier @@ -84,22 +84,22 @@ typedef struct __attribute__((aligned (64))) GpuHidHaarStageClassifier GpuHidHaarStageClassifier; -//typedef struct __attribute__((aligned (64))) GpuHidHaarClassifierCascade -//{ -// int count __attribute__((aligned (4))); -// int is_stump_based __attribute__((aligned (4))); -// int has_tilted_features __attribute__((aligned (4))); -// int is_tree __attribute__((aligned (4))); -// int pq0 __attribute__((aligned (4))); -// int pq1 __attribute__((aligned (4))); -// int pq2 __attribute__((aligned (4))); -// int pq3 __attribute__((aligned (4))); -// int p0 __attribute__((aligned (4))); -// int p1 __attribute__((aligned (4))); -// int p2 __attribute__((aligned (4))); -// int p3 __attribute__((aligned (4))); -// float inv_window_area __attribute__((aligned (4))); -//} GpuHidHaarClassifierCascade; +typedef struct __attribute__((aligned (64))) GpuHidHaarClassifierCascade +{ + int count __attribute__((aligned (4))); + int is_stump_based __attribute__((aligned (4))); + int has_tilted_features __attribute__((aligned (4))); + int is_tree __attribute__((aligned (4))); + int pq0 __attribute__((aligned (4))); + int pq1 __attribute__((aligned (4))); + int pq2 __attribute__((aligned (4))); + int pq3 __attribute__((aligned (4))); + int p0 __attribute__((aligned (4))); + int p1 __attribute__((aligned (4))); + int p2 __attribute__((aligned (4))); + int p3 __attribute__((aligned (4))); + float inv_window_area __attribute__((aligned (4))); +} GpuHidHaarClassifierCascade; #ifdef PACKED_CLASSIFIER @@ -150,8 +150,8 @@ __kernel void gpuRunHaarClassifierCascadePacked( int index = i+lid; // index in shared local memory if(indexcount; - float stagethreshold = stageinfo->threshold; - for(int nodeloop = 0; nodeloop < stagecount; nodecounter++,nodeloop++ ) + int2 stageinfo = *(global int2*)(stagecascadeptr+stageloop); + float stagethreshold = as_float(stageinfo.y); + int lcl_off = (lid_y*DATA_SIZE_X)+(lid_x); + for(int nodeloop = 0; nodeloop < stageinfo.x; nodecounter++,nodeloop++ ) { // simple macro to extract shorts from int #define M0(_t) ((_t)&0xFFFF) @@ -217,7 +215,7 @@ __kernel void gpuRunHaarClassifierCascadePacked( (SumL[M0(n0.x)+lcl_off] - SumL[M1(n0.x)+lcl_off] - SumL[M0(n0.y)+lcl_off] + SumL[M1(n0.y)+lcl_off]) * as_float(n1.z) + (SumL[M0(n0.z)+lcl_off] - SumL[M1(n0.z)+lcl_off] - SumL[M0(n0.w)+lcl_off] + SumL[M1(n0.w)+lcl_off]) * as_float(n1.w) + (SumL[M0(n1.x)+lcl_off] - SumL[M1(n1.x)+lcl_off] - SumL[M0(n1.y)+lcl_off] + SumL[M1(n1.y)+lcl_off]) * as_float(n2.x); - //accumulate stage responce + //accumulate stage response stage_sum += (classsum >= nodethreshold) ? as_float(n2.w) : as_float(n2.z); } result = (stage_sum >= stagethreshold); @@ -357,17 +355,14 @@ __kernel void __attribute__((reqd_work_group_size(8,8,1)))gpuRunHaarClassifierCa variance_norm_factor = variance_norm_factor * correction - mean * mean; variance_norm_factor = variance_norm_factor >=0.f ? sqrt(variance_norm_factor) : 1.f; - for(int stageloop = start_stage; (stageloop < split_stage) && result; stageloop++ ) + for(int stageloop = start_stage; (stageloop < split_stage) && result; stageloop++ ) { float stage_sum = 0.f; - __global GpuHidHaarStageClassifier* stageinfo = (__global GpuHidHaarStageClassifier*) - ((__global uchar*)stagecascadeptr+stageloop*sizeof(GpuHidHaarStageClassifier)); - int stagecount = stageinfo->count; - float stagethreshold = stageinfo->threshold; - for(int nodeloop = 0; nodeloop < stagecount; ) + int2 stageinfo = *(global int2*)(stagecascadeptr+stageloop); + float stagethreshold = as_float(stageinfo.y); + for(int nodeloop = 0; nodeloop < stageinfo.x; ) { - __global GpuHidHaarTreeNode* currentnodeptr = (__global GpuHidHaarTreeNode*) - (((__global uchar*)nodeptr) + nodecounter * sizeof(GpuHidHaarTreeNode)); + __global GpuHidHaarTreeNode* currentnodeptr = (nodeptr + nodecounter); int4 info1 = *(__global int4*)(&(currentnodeptr->p[0][0])); int4 info2 = *(__global int4*)(&(currentnodeptr->p[1][0])); @@ -423,7 +418,7 @@ __kernel void __attribute__((reqd_work_group_size(8,8,1)))gpuRunHaarClassifierCa #endif } - result = (stage_sum >= stagethreshold) ? 1 : 0; + result = (stage_sum >= stagethreshold); } if(factor < 2) { @@ -452,17 +447,14 @@ __kernel void __attribute__((reqd_work_group_size(8,8,1)))gpuRunHaarClassifierCa lclcount[0]=0; barrier(CLK_LOCAL_MEM_FENCE); - //int2 stageinfo = *(global int2*)(stagecascadeptr+stageloop); - __global GpuHidHaarStageClassifier* stageinfo = (__global GpuHidHaarStageClassifier*) - ((__global uchar*)stagecascadeptr+stageloop*sizeof(GpuHidHaarStageClassifier)); - int stagecount = stageinfo->count; - float stagethreshold = stageinfo->threshold; + int2 stageinfo = *(global int2*)(stagecascadeptr+stageloop); + float stagethreshold = as_float(stageinfo.y); int perfscale = queuecount > 4 ? 3 : 2; int queuecount_loop = (queuecount + (1<> perfscale; int lcl_compute_win = lcl_sz >> perfscale; int lcl_compute_win_id = (lcl_id >>(6-perfscale)); - int lcl_loops = (stagecount + lcl_compute_win -1) >> (6-perfscale); + int lcl_loops = (stageinfo.x + lcl_compute_win -1) >> (6-perfscale); int lcl_compute_id = lcl_id - (lcl_compute_win_id << (6-perfscale)); for(int queueloop=0; queueloopp[0][0])); int4 info2 = *(__global int4*)(&(currentnodeptr->p[1][0])); @@ -557,7 +549,7 @@ __kernel void __attribute__((reqd_work_group_size(8,8,1)))gpuRunHaarClassifierCa queuecount = lclcount[0]; barrier(CLK_LOCAL_MEM_FENCE); - nodecounter += stagecount; + nodecounter += stageinfo.x; }//end for(int stageloop = splitstage; stageloop< endstage && queuecount>0;stageloop++) if(lcl_id> 16; int totalgrp = scaleinfo1.y & 0xffff; float factor = as_float(scaleinfo1.w); @@ -173,18 +174,15 @@ __kernel void gpuRunHaarClassifierCascade_scaled2( for (int stageloop = start_stage; (stageloop < end_stage) && result; stageloop++) { float stage_sum = 0.f; - __global GpuHidHaarStageClassifier* stageinfo = (__global GpuHidHaarStageClassifier*) - (((__global uchar*)stagecascadeptr_)+stageloop*sizeof(GpuHidHaarStageClassifier)); - int stagecount = stageinfo->count; + int stagecount = stagecascadeptr[stageloop].count; for (int nodeloop = 0; nodeloop < stagecount;) { - __global GpuHidHaarTreeNode* currentnodeptr = (__global GpuHidHaarTreeNode*) - (((__global uchar*)nodeptr_) + nodecounter * sizeof(GpuHidHaarTreeNode)); + __global GpuHidHaarTreeNode *currentnodeptr = (nodeptr + nodecounter); int4 info1 = *(__global int4 *)(&(currentnodeptr->p[0][0])); int4 info2 = *(__global int4 *)(&(currentnodeptr->p[1][0])); int4 info3 = *(__global int4 *)(&(currentnodeptr->p[2][0])); float4 w = *(__global float4 *)(&(currentnodeptr->weight[0])); - float3 alpha3 = *(__global float3*)(&(currentnodeptr->alpha[0])); + float3 alpha3 = *(__global float3 *)(&(currentnodeptr->alpha[0])); float nodethreshold = w.w * variance_norm_factor; info1.x += p_offset; @@ -206,7 +204,7 @@ __kernel void gpuRunHaarClassifierCascade_scaled2( sum[clamp(mad24(info3.w, step, info3.x), 0, max_idx)] + sum[clamp(mad24(info3.w, step, info3.z), 0, max_idx)]) * w.z; - bool passThres = (classsum >= nodethreshold) ? 1 : 0; + bool passThres = classsum >= nodethreshold; #if STUMP_BASED stage_sum += passThres ? alpha3.y : alpha3.x; @@ -236,8 +234,7 @@ __kernel void gpuRunHaarClassifierCascade_scaled2( } #endif } - - result = (stage_sum >= stageinfo->threshold) ? 1 : 0; + result = (int)(stage_sum >= stagecascadeptr[stageloop].threshold); } barrier(CLK_LOCAL_MEM_FENCE); @@ -284,14 +281,11 @@ __kernel void gpuRunHaarClassifierCascade_scaled2( } } } -__kernel void gpuscaleclassifier(global GpuHidHaarTreeNode *orinode, global GpuHidHaarTreeNode *newnode, float scale, float weight_scale, const int nodenum) +__kernel void gpuscaleclassifier(global GpuHidHaarTreeNode *orinode, global GpuHidHaarTreeNode *newnode, float scale, float weight_scale, int nodenum) { - const int counter = get_global_id(0); + int counter = get_global_id(0); int tr_x[3], tr_y[3], tr_h[3], tr_w[3], i = 0; - GpuHidHaarTreeNode t1 = *(__global GpuHidHaarTreeNode*) - (((__global uchar*)orinode) + counter * sizeof(GpuHidHaarTreeNode)); - __global GpuHidHaarTreeNode* pNew = (__global GpuHidHaarTreeNode*) - (((__global uchar*)newnode) + (counter + nodenum) * sizeof(GpuHidHaarTreeNode)); + GpuHidHaarTreeNode t1 = *(orinode + counter); #pragma unroll for (i = 0; i < 3; i++) @@ -303,21 +297,22 @@ __kernel void gpuscaleclassifier(global GpuHidHaarTreeNode *orinode, global GpuH } t1.weight[0] = -(t1.weight[1] * tr_h[1] * tr_w[1] + t1.weight[2] * tr_h[2] * tr_w[2]) / (tr_h[0] * tr_w[0]); + counter += nodenum; #pragma unroll for (i = 0; i < 3; i++) { - pNew->p[i][0] = tr_x[i]; - pNew->p[i][1] = tr_y[i]; - pNew->p[i][2] = tr_x[i] + tr_w[i]; - pNew->p[i][3] = tr_y[i] + tr_h[i]; - pNew->weight[i] = t1.weight[i] * weight_scale; + newnode[counter].p[i][0] = tr_x[i]; + newnode[counter].p[i][1] = tr_y[i]; + newnode[counter].p[i][2] = tr_x[i] + tr_w[i]; + newnode[counter].p[i][3] = tr_y[i] + tr_h[i]; + newnode[counter].weight[i] = t1.weight[i] * weight_scale; } - pNew->left = t1.left; - pNew->right = t1.right; - pNew->threshold = t1.threshold; - pNew->alpha[0] = t1.alpha[0]; - pNew->alpha[1] = t1.alpha[1]; - pNew->alpha[2] = t1.alpha[2]; + newnode[counter].left = t1.left; + newnode[counter].right = t1.right; + newnode[counter].threshold = t1.threshold; + newnode[counter].alpha[0] = t1.alpha[0]; + newnode[counter].alpha[1] = t1.alpha[1]; + newnode[counter].alpha[2] = t1.alpha[2]; } diff --git a/modules/ocl/src/opencl/imgproc_canny.cl b/modules/ocl/src/opencl/imgproc_canny.cl index 0a54f1468..2ddfdae5f 100644 --- a/modules/ocl/src/opencl/imgproc_canny.cl +++ b/modules/ocl/src/opencl/imgproc_canny.cl @@ -381,8 +381,8 @@ struct PtrStepSz { int step; int rows, cols; }; -inline int get(struct PtrStepSz data, int y, int x) { return *((__global int *)((__global char*)data.ptr + data.step * y + sizeof(int) * x)); } -inline void set(struct PtrStepSz data, int y, int x, int value) { *((__global int *)((__global char*)data.ptr + data.step * y + sizeof(int) * x)) = value; } +inline int get(struct PtrStepSz data, int y, int x) { return *((__global int *)((__global char*)data.ptr + data.step * (y + 1) + sizeof(int) * (x + 1))); } +inline void set(struct PtrStepSz data, int y, int x, int value) { *((__global int *)((__global char*)data.ptr + data.step * (y + 1) + sizeof(int) * (x + 1))) = value; } ////////////////////////////////////////////////////////////////////////////////////////// // do Hysteresis for pixel whose edge type is 1 @@ -494,7 +494,7 @@ edgesHysteresisLocal } } #else - struct PtrStepSz map = {((__global int *)((__global char*)map_ptr + map_offset)), map_step, rows, cols}; + struct PtrStepSz map = {((__global int *)((__global char*)map_ptr + map_offset)), map_step, rows + 1, cols + 1}; __local int smem[18][18]; @@ -507,13 +507,13 @@ edgesHysteresisLocal smem[threadIdx.y + 1][threadIdx.x + 1] = x < map.cols && y < map.rows ? get(map, y, x) : 0; if (threadIdx.y == 0) - smem[0][threadIdx.x + 1] = y > 0 ? get(map, y - 1, x) : 0; + smem[0][threadIdx.x + 1] = x < map.cols ? get(map, y - 1, x) : 0; if (threadIdx.y == blockDim.y - 1) smem[blockDim.y + 1][threadIdx.x + 1] = y + 1 < map.rows ? get(map, y + 1, x) : 0; if (threadIdx.x == 0) - smem[threadIdx.y + 1][0] = x > 0 ? get(map, y, x - 1) : 0; + smem[threadIdx.y + 1][0] = y < map.rows ? get(map, y, x - 1) : 0; if (threadIdx.x == blockDim.x - 1) - smem[threadIdx.y + 1][blockDim.x + 1] = x + 1 < map.cols ? get(map, y, x + 1) : 0; + smem[threadIdx.y + 1][blockDim.x + 1] = x + 1 < map.cols && y < map.rows ? get(map, y, x + 1) : 0; if (threadIdx.x == 0 && threadIdx.y == 0) smem[0][0] = y > 0 && x > 0 ? get(map, y - 1, x - 1) : 0; if (threadIdx.x == blockDim.x - 1 && threadIdx.y == 0) @@ -525,7 +525,7 @@ edgesHysteresisLocal barrier(CLK_LOCAL_MEM_FENCE); - if (x >= map.cols || y >= map.rows) + if (x >= cols || y >= rows) return; int n; @@ -576,7 +576,7 @@ edgesHysteresisLocal if (n > 0) { const int ind = atomic_inc(counter); - st[ind] = (ushort2)(x, y); + st[ind] = (ushort2)(x + 1, y + 1); } #endif } diff --git a/modules/ocl/src/opencl/imgproc_integral.cl b/modules/ocl/src/opencl/imgproc_integral.cl index 1d90e507f..a8102e54a 100644 --- a/modules/ocl/src/opencl/imgproc_integral.cl +++ b/modules/ocl/src/opencl/imgproc_integral.cl @@ -49,9 +49,6 @@ #elif defined (cl_khr_fp64) #pragma OPENCL EXTENSION cl_khr_fp64:enable #endif -#define CONVERT(step) ((step)>>1) -#else -#define CONVERT(step) ((step)) #endif #define LSIZE 256 @@ -64,17 +61,17 @@ #define GET_CONFLICT_OFFSET(lid) ((lid) >> LOG_NUM_BANKS) -kernel void integral_cols_D4(__global uchar4 *src,__global int *sum ,__global TYPE *sqsum, - int src_offset,int pre_invalid,int rows,int cols,int src_step,int dst_step,int dst1_step) +kernel void integral_cols_D4(__global uchar4 *src,__global int *sum ,__global float *sqsum, + int src_offset,int pre_invalid,int rows,int cols,int src_step,int dst_step) { int lid = get_local_id(0); int gid = get_group_id(0); int4 src_t[2], sum_t[2]; - TYPE4 sqsum_t[2]; + float4 sqsum_t[2]; __local int4 lm_sum[2][LSIZE + LOG_LSIZE]; - __local TYPE4 lm_sqsum[2][LSIZE + LOG_LSIZE]; + __local float4 lm_sqsum[2][LSIZE + LOG_LSIZE]; __local int* sum_p; - __local TYPE* sqsum_p; + __local float* sqsum_p; src_step = src_step >> 2; gid = gid << 1; for(int i = 0; i < rows; i =i + LSIZE_1) @@ -83,237 +80,17 @@ kernel void integral_cols_D4(__global uchar4 *src,__global int *sum ,__global TY src_t[1] = (i + lid < rows ? convert_int4(src[src_offset + (lid+i) * src_step + min(gid + 1, cols - 1)]) : 0); sum_t[0] = (i == 0 ? 0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); - sqsum_t[0] = (i == 0 ? (TYPE4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); + sqsum_t[0] = (i == 0 ? (float4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); sum_t[1] = (i == 0 ? 0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); - sqsum_t[1] = (i == 0 ? (TYPE4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); + sqsum_t[1] = (i == 0 ? (float4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); barrier(CLK_LOCAL_MEM_FENCE); int bf_loc = lid + GET_CONFLICT_OFFSET(lid); lm_sum[0][bf_loc] = src_t[0]; - lm_sqsum[0][bf_loc] = convert_TYPE4(src_t[0] * src_t[0]); + lm_sqsum[0][bf_loc] = convert_float4(src_t[0] * src_t[0]); lm_sum[1][bf_loc] = src_t[1]; - lm_sqsum[1][bf_loc] = convert_TYPE4(src_t[1] * src_t[1]); - - int offset = 1; - for(int d = LSIZE >> 1 ; d > 0; d>>=1) - { - barrier(CLK_LOCAL_MEM_FENCE); - int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; - ai += GET_CONFLICT_OFFSET(ai); - bi += GET_CONFLICT_OFFSET(bi); - - if((lid & 127) < d) - { - lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; - lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; - } - offset <<= 1; - } - barrier(CLK_LOCAL_MEM_FENCE); - if(lid < 2) - { - lm_sum[lid][LSIZE_2 + LOG_LSIZE] = 0; - lm_sqsum[lid][LSIZE_2 + LOG_LSIZE] = 0; - } - for(int d = 1; d < LSIZE; d <<= 1) - { - barrier(CLK_LOCAL_MEM_FENCE); - offset >>= 1; - int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; - ai += GET_CONFLICT_OFFSET(ai); - bi += GET_CONFLICT_OFFSET(bi); - - if((lid & 127) < d) - { - lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; - lm_sum[lid >> 7][ai] = lm_sum[lid >> 7][bi] - lm_sum[lid >> 7][ai]; - - lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; - lm_sqsum[lid >> 7][ai] = lm_sqsum[lid >> 7][bi] - lm_sqsum[lid >> 7][ai]; - } - } - barrier(CLK_LOCAL_MEM_FENCE); - int loc_s0 = gid * dst_step + i + lid - 1 - pre_invalid * dst_step /4, loc_s1 = loc_s0 + dst_step ; - int loc_sq0 = gid * CONVERT(dst1_step) + i + lid - 1 - pre_invalid * dst1_step / sizeof(TYPE),loc_sq1 = loc_sq0 + CONVERT(dst1_step); - if(lid > 0 && (i+lid) <= rows) - { - lm_sum[0][bf_loc] += sum_t[0]; - lm_sum[1][bf_loc] += sum_t[1]; - lm_sqsum[0][bf_loc] += sqsum_t[0]; - lm_sqsum[1][bf_loc] += sqsum_t[1]; - sum_p = (__local int*)(&(lm_sum[0][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[0][bf_loc])); - for(int k = 0; k < 4; k++) - { - if(gid * 4 + k >= cols + pre_invalid || gid * 4 + k < pre_invalid) continue; - sum[loc_s0 + k * dst_step / 4] = sum_p[k]; - sqsum[loc_sq0 + k * dst1_step / sizeof(TYPE)] = sqsum_p[k]; - } - sum_p = (__local int*)(&(lm_sum[1][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[1][bf_loc])); - for(int k = 0; k < 4; k++) - { - if(gid * 4 + k + 4 >= cols + pre_invalid) break; - sum[loc_s1 + k * dst_step / 4] = sum_p[k]; - sqsum[loc_sq1 + k * dst1_step / sizeof(TYPE)] = sqsum_p[k]; - } - } - barrier(CLK_LOCAL_MEM_FENCE); - } -} - - -kernel void integral_rows_D4(__global int4 *srcsum,__global TYPE4 * srcsqsum,__global int *sum , - __global TYPE *sqsum,int rows,int cols,int src_step,int src1_step,int sum_step, - int sqsum_step,int sum_offset,int sqsum_offset) -{ - int lid = get_local_id(0); - int gid = get_group_id(0); - int4 src_t[2], sum_t[2]; - TYPE4 sqsrc_t[2],sqsum_t[2]; - __local int4 lm_sum[2][LSIZE + LOG_LSIZE]; - __local TYPE4 lm_sqsum[2][LSIZE + LOG_LSIZE]; - __local int *sum_p; - __local TYPE *sqsum_p; - src_step = src_step >> 4; - src1_step = (src1_step / sizeof(TYPE)) >> 2 ; - gid <<= 1; - for(int i = 0; i < rows; i =i + LSIZE_1) - { - src_t[0] = i + lid < rows ? srcsum[(lid+i) * src_step + gid ] : (int4)0; - sqsrc_t[0] = i + lid < rows ? srcsqsum[(lid+i) * src1_step + gid ] : (TYPE4)0; - src_t[1] = i + lid < rows ? srcsum[(lid+i) * src_step + gid + 1] : (int4)0; - sqsrc_t[1] = i + lid < rows ? srcsqsum[(lid+i) * src1_step + gid + 1] : (TYPE4)0; - - sum_t[0] = (i == 0 ? 0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); - sqsum_t[0] = (i == 0 ? (TYPE4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); - sum_t[1] = (i == 0 ? 0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); - sqsum_t[1] = (i == 0 ? (TYPE4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); - barrier(CLK_LOCAL_MEM_FENCE); - - int bf_loc = lid + GET_CONFLICT_OFFSET(lid); - lm_sum[0][bf_loc] = src_t[0]; - lm_sqsum[0][bf_loc] = sqsrc_t[0]; - - lm_sum[1][bf_loc] = src_t[1]; - lm_sqsum[1][bf_loc] = sqsrc_t[1]; - - int offset = 1; - for(int d = LSIZE >> 1 ; d > 0; d>>=1) - { - barrier(CLK_LOCAL_MEM_FENCE); - int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; - ai += GET_CONFLICT_OFFSET(ai); - bi += GET_CONFLICT_OFFSET(bi); - - if((lid & 127) < d) - { - lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; - lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; - } - offset <<= 1; - } - barrier(CLK_LOCAL_MEM_FENCE); - if(lid < 2) - { - lm_sum[lid][LSIZE_2 + LOG_LSIZE] = 0; - lm_sqsum[lid][LSIZE_2 + LOG_LSIZE] = 0; - } - for(int d = 1; d < LSIZE; d <<= 1) - { - barrier(CLK_LOCAL_MEM_FENCE); - offset >>= 1; - int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; - ai += GET_CONFLICT_OFFSET(ai); - bi += GET_CONFLICT_OFFSET(bi); - - if((lid & 127) < d) - { - lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; - lm_sum[lid >> 7][ai] = lm_sum[lid >> 7][bi] - lm_sum[lid >> 7][ai]; - - lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; - lm_sqsum[lid >> 7][ai] = lm_sqsum[lid >> 7][bi] - lm_sqsum[lid >> 7][ai]; - } - } - barrier(CLK_LOCAL_MEM_FENCE); - if(gid == 0 && (i + lid) <= rows) - { - sum[sum_offset + i + lid] = 0; - sqsum[sqsum_offset + i + lid] = 0; - } - if(i + lid == 0) - { - int loc0 = gid * sum_step; - int loc1 = gid * CONVERT(sqsum_step); - for(int k = 1; k <= 8; k++) - { - if(gid * 4 + k > cols) break; - sum[sum_offset + loc0 + k * sum_step / 4] = 0; - sqsum[sqsum_offset + loc1 + k * sqsum_step / sizeof(TYPE)] = 0; - } - } - int loc_s0 = sum_offset + gid * sum_step + sum_step / 4 + i + lid, loc_s1 = loc_s0 + sum_step ; - int loc_sq0 = sqsum_offset + gid * CONVERT(sqsum_step) + sqsum_step / sizeof(TYPE) + i + lid, loc_sq1 = loc_sq0 + CONVERT(sqsum_step) ; - - if(lid > 0 && (i+lid) <= rows) - { - lm_sum[0][bf_loc] += sum_t[0]; - lm_sum[1][bf_loc] += sum_t[1]; - lm_sqsum[0][bf_loc] += sqsum_t[0]; - lm_sqsum[1][bf_loc] += sqsum_t[1]; - sum_p = (__local int*)(&(lm_sum[0][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[0][bf_loc])); - for(int k = 0; k < 4; k++) - { - if(gid * 4 + k >= cols) break; - sum[loc_s0 + k * sum_step / 4] = sum_p[k]; - sqsum[loc_sq0 + k * sqsum_step / sizeof(TYPE)] = sqsum_p[k]; - } - sum_p = (__local int*)(&(lm_sum[1][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[1][bf_loc])); - for(int k = 0; k < 4; k++) - { - if(gid * 4 + 4 + k >= cols) break; - sum[loc_s1 + k * sum_step / 4] = sum_p[k]; - sqsum[loc_sq1 + k * sqsum_step / sizeof(TYPE)] = sqsum_p[k]; - } - } - barrier(CLK_LOCAL_MEM_FENCE); - } -} - -kernel void integral_cols_D5(__global uchar4 *src,__global float *sum ,__global TYPE *sqsum, - int src_offset,int pre_invalid,int rows,int cols,int src_step,int dst_step, int dst1_step) -{ - int lid = get_local_id(0); - int gid = get_group_id(0); - float4 src_t[2], sum_t[2]; - TYPE4 sqsum_t[2]; - __local float4 lm_sum[2][LSIZE + LOG_LSIZE]; - __local TYPE4 lm_sqsum[2][LSIZE + LOG_LSIZE]; - __local float* sum_p; - __local TYPE* sqsum_p; - src_step = src_step >> 2; - gid = gid << 1; - for(int i = 0; i < rows; i =i + LSIZE_1) - { - src_t[0] = (i + lid < rows ? convert_float4(src[src_offset + (lid+i) * src_step + min(gid, cols - 1)]) : (float4)0); - src_t[1] = (i + lid < rows ? convert_float4(src[src_offset + (lid+i) * src_step + min(gid + 1, cols - 1)]) : (float4)0); - - sum_t[0] = (i == 0 ? (float4)0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); - sqsum_t[0] = (i == 0 ? (TYPE4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); - sum_t[1] = (i == 0 ? (float4)0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); - sqsum_t[1] = (i == 0 ? (TYPE4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); - barrier(CLK_LOCAL_MEM_FENCE); - - int bf_loc = lid + GET_CONFLICT_OFFSET(lid); - lm_sum[0][bf_loc] = src_t[0]; - lm_sqsum[0][bf_loc] = convert_TYPE4(src_t[0] * src_t[0]); - - lm_sum[1][bf_loc] = src_t[1]; - lm_sqsum[1][bf_loc] = convert_TYPE4(src_t[1] * src_t[1]); + lm_sqsum[1][bf_loc] = convert_float4(src_t[1] * src_t[1]); int offset = 1; for(int d = LSIZE >> 1 ; d > 0; d>>=1) @@ -355,28 +132,27 @@ kernel void integral_cols_D5(__global uchar4 *src,__global float *sum ,__global } barrier(CLK_LOCAL_MEM_FENCE); int loc_s0 = gid * dst_step + i + lid - 1 - pre_invalid * dst_step / 4, loc_s1 = loc_s0 + dst_step ; - int loc_sq0 = gid * CONVERT(dst1_step) + i + lid - 1 - pre_invalid * dst1_step / sizeof(TYPE), loc_sq1 = loc_sq0 + CONVERT(dst1_step); if(lid > 0 && (i+lid) <= rows) { lm_sum[0][bf_loc] += sum_t[0]; lm_sum[1][bf_loc] += sum_t[1]; lm_sqsum[0][bf_loc] += sqsum_t[0]; lm_sqsum[1][bf_loc] += sqsum_t[1]; - sum_p = (__local float*)(&(lm_sum[0][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[0][bf_loc])); + sum_p = (__local int*)(&(lm_sum[0][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[0][bf_loc])); for(int k = 0; k < 4; k++) { if(gid * 4 + k >= cols + pre_invalid || gid * 4 + k < pre_invalid) continue; sum[loc_s0 + k * dst_step / 4] = sum_p[k]; - sqsum[loc_sq0 + k * dst1_step / sizeof(TYPE)] = sqsum_p[k]; + sqsum[loc_s0 + k * dst_step / 4] = sqsum_p[k]; } - sum_p = (__local float*)(&(lm_sum[1][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[1][bf_loc])); + sum_p = (__local int*)(&(lm_sum[1][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[1][bf_loc])); for(int k = 0; k < 4; k++) { if(gid * 4 + k + 4 >= cols + pre_invalid) break; sum[loc_s1 + k * dst_step / 4] = sum_p[k]; - sqsum[loc_sq1 + k * dst1_step / sizeof(TYPE)] = sqsum_p[k]; + sqsum[loc_s1 + k * dst_step / 4] = sqsum_p[k]; } } barrier(CLK_LOCAL_MEM_FENCE); @@ -384,31 +160,30 @@ kernel void integral_cols_D5(__global uchar4 *src,__global float *sum ,__global } -kernel void integral_rows_D5(__global float4 *srcsum,__global TYPE4 * srcsqsum,__global float *sum , - __global TYPE *sqsum,int rows,int cols,int src_step,int src1_step, int sum_step, +kernel void integral_rows_D4(__global int4 *srcsum,__global float4 * srcsqsum,__global int *sum , + __global float *sqsum,int rows,int cols,int src_step,int sum_step, int sqsum_step,int sum_offset,int sqsum_offset) { int lid = get_local_id(0); int gid = get_group_id(0); - float4 src_t[2], sum_t[2]; - TYPE4 sqsrc_t[2],sqsum_t[2]; - __local float4 lm_sum[2][LSIZE + LOG_LSIZE]; - __local TYPE4 lm_sqsum[2][LSIZE + LOG_LSIZE]; - __local float *sum_p; - __local TYPE *sqsum_p; + int4 src_t[2], sum_t[2]; + float4 sqsrc_t[2],sqsum_t[2]; + __local int4 lm_sum[2][LSIZE + LOG_LSIZE]; + __local float4 lm_sqsum[2][LSIZE + LOG_LSIZE]; + __local int *sum_p; + __local float *sqsum_p; src_step = src_step >> 4; - src1_step = (src1_step / sizeof(TYPE)) >> 2; for(int i = 0; i < rows; i =i + LSIZE_1) { - src_t[0] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2] : (float4)0; - sqsrc_t[0] = i + lid < rows ? srcsqsum[(lid+i) * src1_step + gid * 2] : (TYPE4)0; - src_t[1] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2 + 1] : (float4)0; - sqsrc_t[1] = i + lid < rows ? srcsqsum[(lid+i) * src1_step + gid * 2 + 1] : (TYPE4)0; + src_t[0] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2] : (int4)0; + sqsrc_t[0] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2] : (float4)0; + src_t[1] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2 + 1] : (int4)0; + sqsrc_t[1] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2 + 1] : (float4)0; - sum_t[0] = (i == 0 ? (float4)0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); - sqsum_t[0] = (i == 0 ? (TYPE4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); - sum_t[1] = (i == 0 ? (float4)0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); - sqsum_t[1] = (i == 0 ? (TYPE4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); + sum_t[0] = (i == 0 ? 0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); + sqsum_t[0] = (i == 0 ? (float4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); + sum_t[1] = (i == 0 ? 0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); + sqsum_t[1] = (i == 0 ? (float4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); barrier(CLK_LOCAL_MEM_FENCE); int bf_loc = lid + GET_CONFLICT_OFFSET(lid); @@ -465,16 +240,114 @@ kernel void integral_rows_D5(__global float4 *srcsum,__global TYPE4 * srcsqsum,_ if(i + lid == 0) { int loc0 = gid * 2 * sum_step; - int loc1 = gid * 2 * CONVERT(sqsum_step); + int loc1 = gid * 2 * sqsum_step; for(int k = 1; k <= 8; k++) { if(gid * 8 + k > cols) break; sum[sum_offset + loc0 + k * sum_step / 4] = 0; - sqsum[sqsum_offset + loc1 + k * sqsum_step / sizeof(TYPE)] = 0; + sqsum[sqsum_offset + loc1 + k * sqsum_step / 4] = 0; } } int loc_s0 = sum_offset + gid * 2 * sum_step + sum_step / 4 + i + lid, loc_s1 = loc_s0 + sum_step ; - int loc_sq0 = sqsum_offset + gid * 2 * CONVERT(sqsum_step) + sqsum_step / sizeof(TYPE) + i + lid, loc_sq1 = loc_sq0 + CONVERT(sqsum_step) ; + int loc_sq0 = sqsum_offset + gid * 2 * sqsum_step + sqsum_step / 4 + i + lid, loc_sq1 = loc_sq0 + sqsum_step ; + if(lid > 0 && (i+lid) <= rows) + { + lm_sum[0][bf_loc] += sum_t[0]; + lm_sum[1][bf_loc] += sum_t[1]; + lm_sqsum[0][bf_loc] += sqsum_t[0]; + lm_sqsum[1][bf_loc] += sqsum_t[1]; + sum_p = (__local int*)(&(lm_sum[0][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[0][bf_loc])); + for(int k = 0; k < 4; k++) + { + if(gid * 8 + k >= cols) break; + sum[loc_s0 + k * sum_step / 4] = sum_p[k]; + sqsum[loc_sq0 + k * sqsum_step / 4] = sqsum_p[k]; + } + sum_p = (__local int*)(&(lm_sum[1][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[1][bf_loc])); + for(int k = 0; k < 4; k++) + { + if(gid * 8 + 4 + k >= cols) break; + sum[loc_s1 + k * sum_step / 4] = sum_p[k]; + sqsum[loc_sq1 + k * sqsum_step / 4] = sqsum_p[k]; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + } +} + +kernel void integral_cols_D5(__global uchar4 *src,__global float *sum ,__global float *sqsum, + int src_offset,int pre_invalid,int rows,int cols,int src_step,int dst_step) +{ + int lid = get_local_id(0); + int gid = get_group_id(0); + float4 src_t[2], sum_t[2]; + float4 sqsum_t[2]; + __local float4 lm_sum[2][LSIZE + LOG_LSIZE]; + __local float4 lm_sqsum[2][LSIZE + LOG_LSIZE]; + __local float* sum_p; + __local float* sqsum_p; + src_step = src_step >> 2; + gid = gid << 1; + for(int i = 0; i < rows; i =i + LSIZE_1) + { + src_t[0] = (i + lid < rows ? convert_float4(src[src_offset + (lid+i) * src_step + min(gid, cols - 1)]) : (float4)0); + src_t[1] = (i + lid < rows ? convert_float4(src[src_offset + (lid+i) * src_step + min(gid + 1, cols - 1)]) : (float4)0); + + sum_t[0] = (i == 0 ? (float4)0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); + sqsum_t[0] = (i == 0 ? (float4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); + sum_t[1] = (i == 0 ? (float4)0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); + sqsum_t[1] = (i == 0 ? (float4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); + barrier(CLK_LOCAL_MEM_FENCE); + + int bf_loc = lid + GET_CONFLICT_OFFSET(lid); + lm_sum[0][bf_loc] = src_t[0]; + lm_sqsum[0][bf_loc] = convert_float4(src_t[0] * src_t[0]); + + lm_sum[1][bf_loc] = src_t[1]; + lm_sqsum[1][bf_loc] = convert_float4(src_t[1] * src_t[1]); + + int offset = 1; + for(int d = LSIZE >> 1 ; d > 0; d>>=1) + { + barrier(CLK_LOCAL_MEM_FENCE); + int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; + ai += GET_CONFLICT_OFFSET(ai); + bi += GET_CONFLICT_OFFSET(bi); + + if((lid & 127) < d) + { + lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; + lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; + } + offset <<= 1; + } + barrier(CLK_LOCAL_MEM_FENCE); + if(lid < 2) + { + lm_sum[lid][LSIZE_2 + LOG_LSIZE] = 0; + lm_sqsum[lid][LSIZE_2 + LOG_LSIZE] = 0; + } + for(int d = 1; d < LSIZE; d <<= 1) + { + barrier(CLK_LOCAL_MEM_FENCE); + offset >>= 1; + int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; + ai += GET_CONFLICT_OFFSET(ai); + bi += GET_CONFLICT_OFFSET(bi); + + if((lid & 127) < d) + { + lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; + lm_sum[lid >> 7][ai] = lm_sum[lid >> 7][bi] - lm_sum[lid >> 7][ai]; + + lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; + lm_sqsum[lid >> 7][ai] = lm_sqsum[lid >> 7][bi] - lm_sqsum[lid >> 7][ai]; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + int loc_s0 = gid * dst_step + i + lid - 1 - pre_invalid * dst_step / 4, loc_s1 = loc_s0 + dst_step ; if(lid > 0 && (i+lid) <= rows) { lm_sum[0][bf_loc] += sum_t[0]; @@ -482,20 +355,138 @@ kernel void integral_rows_D5(__global float4 *srcsum,__global TYPE4 * srcsqsum,_ lm_sqsum[0][bf_loc] += sqsum_t[0]; lm_sqsum[1][bf_loc] += sqsum_t[1]; sum_p = (__local float*)(&(lm_sum[0][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[0][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[0][bf_loc])); for(int k = 0; k < 4; k++) { - if(gid * 8 + k >= cols) break; - sum[loc_s0 + k * sum_step / 4] = sum_p[k]; - sqsum[loc_sq0 + k * sqsum_step / sizeof(TYPE)] = sqsum_p[k]; + if(gid * 4 + k >= cols + pre_invalid || gid * 4 + k < pre_invalid) continue; + sum[loc_s0 + k * dst_step / 4] = sum_p[k]; + sqsum[loc_s0 + k * dst_step / 4] = sqsum_p[k]; } sum_p = (__local float*)(&(lm_sum[1][bf_loc])); - sqsum_p = (__local TYPE*)(&(lm_sqsum[1][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[1][bf_loc])); for(int k = 0; k < 4; k++) { - if(gid * 8 + 4 + k >= cols) break; - sum[loc_s1 + k * sum_step / 4] = sum_p[k]; - sqsum[loc_sq1 + k * sqsum_step / sizeof(TYPE)] = sqsum_p[k]; + if(gid * 4 + k + 4 >= cols + pre_invalid) break; + sum[loc_s1 + k * dst_step / 4] = sum_p[k]; + sqsum[loc_s1 + k * dst_step / 4] = sqsum_p[k]; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + } +} + + +kernel void integral_rows_D5(__global float4 *srcsum,__global float4 * srcsqsum,__global float *sum , + __global float *sqsum,int rows,int cols,int src_step,int sum_step, + int sqsum_step,int sum_offset,int sqsum_offset) +{ + int lid = get_local_id(0); + int gid = get_group_id(0); + float4 src_t[2], sum_t[2]; + float4 sqsrc_t[2],sqsum_t[2]; + __local float4 lm_sum[2][LSIZE + LOG_LSIZE]; + __local float4 lm_sqsum[2][LSIZE + LOG_LSIZE]; + __local float *sum_p; + __local float *sqsum_p; + src_step = src_step >> 4; + for(int i = 0; i < rows; i =i + LSIZE_1) + { + src_t[0] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2] : (float4)0; + sqsrc_t[0] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2] : (float4)0; + src_t[1] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2 + 1] : (float4)0; + sqsrc_t[1] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2 + 1] : (float4)0; + + sum_t[0] = (i == 0 ? (float4)0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]); + sqsum_t[0] = (i == 0 ? (float4)0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]); + sum_t[1] = (i == 0 ? (float4)0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]); + sqsum_t[1] = (i == 0 ? (float4)0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]); + barrier(CLK_LOCAL_MEM_FENCE); + + int bf_loc = lid + GET_CONFLICT_OFFSET(lid); + lm_sum[0][bf_loc] = src_t[0]; + lm_sqsum[0][bf_loc] = sqsrc_t[0]; + + lm_sum[1][bf_loc] = src_t[1]; + lm_sqsum[1][bf_loc] = sqsrc_t[1]; + + int offset = 1; + for(int d = LSIZE >> 1 ; d > 0; d>>=1) + { + barrier(CLK_LOCAL_MEM_FENCE); + int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; + ai += GET_CONFLICT_OFFSET(ai); + bi += GET_CONFLICT_OFFSET(bi); + + if((lid & 127) < d) + { + lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; + lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; + } + offset <<= 1; + } + barrier(CLK_LOCAL_MEM_FENCE); + if(lid < 2) + { + lm_sum[lid][LSIZE_2 + LOG_LSIZE] = 0; + lm_sqsum[lid][LSIZE_2 + LOG_LSIZE] = 0; + } + for(int d = 1; d < LSIZE; d <<= 1) + { + barrier(CLK_LOCAL_MEM_FENCE); + offset >>= 1; + int ai = offset * (((lid & 127)<<1) +1) - 1,bi = ai + offset; + ai += GET_CONFLICT_OFFSET(ai); + bi += GET_CONFLICT_OFFSET(bi); + + if((lid & 127) < d) + { + lm_sum[lid >> 7][bi] += lm_sum[lid >> 7][ai]; + lm_sum[lid >> 7][ai] = lm_sum[lid >> 7][bi] - lm_sum[lid >> 7][ai]; + + lm_sqsum[lid >> 7][bi] += lm_sqsum[lid >> 7][ai]; + lm_sqsum[lid >> 7][ai] = lm_sqsum[lid >> 7][bi] - lm_sqsum[lid >> 7][ai]; + } + } + barrier(CLK_LOCAL_MEM_FENCE); + if(gid == 0 && (i + lid) <= rows) + { + sum[sum_offset + i + lid] = 0; + sqsum[sqsum_offset + i + lid] = 0; + } + if(i + lid == 0) + { + int loc0 = gid * 2 * sum_step; + int loc1 = gid * 2 * sqsum_step; + for(int k = 1; k <= 8; k++) + { + if(gid * 8 + k > cols) break; + sum[sum_offset + loc0 + k * sum_step / 4] = 0; + sqsum[sqsum_offset + loc1 + k * sqsum_step / 4] = 0; + } + } + int loc_s0 = sum_offset + gid * 2 * sum_step + sum_step / 4 + i + lid, loc_s1 = loc_s0 + sum_step ; + int loc_sq0 = sqsum_offset + gid * 2 * sqsum_step + sqsum_step / 4 + i + lid, loc_sq1 = loc_sq0 + sqsum_step ; + if(lid > 0 && (i+lid) <= rows) + { + lm_sum[0][bf_loc] += sum_t[0]; + lm_sum[1][bf_loc] += sum_t[1]; + lm_sqsum[0][bf_loc] += sqsum_t[0]; + lm_sqsum[1][bf_loc] += sqsum_t[1]; + sum_p = (__local float*)(&(lm_sum[0][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[0][bf_loc])); + for(int k = 0; k < 4; k++) + { + if(gid * 8 + k >= cols) break; + sum[loc_s0 + k * sum_step / 4] = sum_p[k]; + sqsum[loc_sq0 + k * sqsum_step / 4] = sqsum_p[k]; + } + sum_p = (__local float*)(&(lm_sum[1][bf_loc])); + sqsum_p = (__local float*)(&(lm_sqsum[1][bf_loc])); + for(int k = 0; k < 4; k++) + { + if(gid * 8 + 4 + k >= cols) break; + sum[loc_s1 + k * sum_step / 4] = sum_p[k]; + sqsum[loc_sq1 + k * sqsum_step / 4] = sqsum_p[k]; } } barrier(CLK_LOCAL_MEM_FENCE); diff --git a/modules/ocl/src/opencl/imgproc_resize.cl b/modules/ocl/src/opencl/imgproc_resize.cl index ebf8c712b..100d68773 100644 --- a/modules/ocl/src/opencl/imgproc_resize.cl +++ b/modules/ocl/src/opencl/imgproc_resize.cl @@ -83,10 +83,10 @@ __kernel void resizeLN_C1_D0(__global uchar * dst, __global uchar const * restri int y = floor(sy); float v = sy - y; - u = x < 0 ? 0 : u; - u = (x >= src_cols) ? 0 : u; - x = x < 0 ? 0 : x; - x = (x >= src_cols) ? src_cols-1 : x; + u = x < (int4)0 ? (float4)0 : u; + u = (x >= (int4)src_cols) ? (float4)0 : u; + x = x < (int4)0 ? (int4)0 : x; + x = (x >= (int4)src_cols) ? (int4)(src_cols-1) : x; y<0 ? y=0,v=0 : y; y>=src_rows ? y=src_rows-1,v=0 : y; diff --git a/modules/ocl/test/test_arithm.cpp b/modules/ocl/test/test_arithm.cpp index 17260580d..29976b6e4 100644 --- a/modules/ocl/test/test_arithm.cpp +++ b/modules/ocl/test/test_arithm.cpp @@ -198,7 +198,7 @@ PARAM_TEST_CASE(ArithmTestBase, MatDepth, Channels, bool) Size roiSize = randomSize(1, MAX_VALUE); Border src1Border = randomBorder(0, use_roi ? MAX_VALUE : 0); - randomSubMat(src1, src1_roi, roiSize, src1Border, type, 2, 11); + randomSubMat(src1, src1_roi, roiSize, src1Border, type, -11, 11); Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0); randomSubMat(src2, src2_roi, roiSize, src2Border, type, -1540, 1740); @@ -1163,7 +1163,7 @@ OCL_TEST_P(CountNonZero, MAT) int cpures = cv::countNonZero(src1_roi); int gpures = cv::ocl::countNonZero(gsrc1_roi); - EXPECT_DOUBLE_EQ((double)cpures, (double)gpures); + EXPECT_EQ(cpures, gpures); } } diff --git a/modules/ocl/test/test_canny.cpp b/modules/ocl/test/test_canny.cpp index 82286031f..6bd7f26ad 100644 --- a/modules/ocl/test/test_canny.cpp +++ b/modules/ocl/test/test_canny.cpp @@ -48,8 +48,8 @@ //////////////////////////////////////////////////////// // Canny -IMPLEMENT_PARAM_CLASS(AppertureSize, int); -IMPLEMENT_PARAM_CLASS(L2gradient, bool); +IMPLEMENT_PARAM_CLASS(AppertureSize, int) +IMPLEMENT_PARAM_CLASS(L2gradient, bool) PARAM_TEST_CASE(Canny, AppertureSize, L2gradient) { diff --git a/modules/ocl/test/test_filters.cpp b/modules/ocl/test/test_filters.cpp index b2caeaf6f..d39c27204 100644 --- a/modules/ocl/test/test_filters.cpp +++ b/modules/ocl/test/test_filters.cpp @@ -334,7 +334,7 @@ OCL_TEST_P(Bilateral, Mat) typedef FilterTestBase AdaptiveBilateral; -OCL_TEST_P(AdaptiveBilateral, Mat) +OCL_TEST_P(AdaptiveBilateral, DISABLED_Mat) { const Size kernelSize(ksize, ksize); diff --git a/modules/ocl/test/test_imgproc.cpp b/modules/ocl/test/test_imgproc.cpp index 9b25d9f9c..961e26227 100644 --- a/modules/ocl/test/test_imgproc.cpp +++ b/modules/ocl/test/test_imgproc.cpp @@ -295,33 +295,23 @@ OCL_TEST_P(CornerHarris, Mat) //////////////////////////////////integral///////////////////////////////////////////////// -struct Integral : - public ImgprocTestBase -{ - int sdepth; +typedef ImgprocTestBase Integral; - virtual void SetUp() - { - type = GET_PARAM(0); - blockSize = GET_PARAM(1); - sdepth = GET_PARAM(2); - useRoi = GET_PARAM(3); - } -}; OCL_TEST_P(Integral, Mat1) { for (int j = 0; j < LOOP_TIMES; j++) { random_roi(); - ocl::integral(gsrc_roi, gdst_roi, sdepth); - integral(src_roi, dst_roi, sdepth); + ocl::integral(gsrc_roi, gdst_roi); + integral(src_roi, dst_roi); Near(); } } -OCL_TEST_P(Integral, Mat2) +// TODO wrong output type +OCL_TEST_P(Integral, DISABLED_Mat2) { Mat dst1; ocl::oclMat gdst1; @@ -330,12 +320,10 @@ OCL_TEST_P(Integral, Mat2) { random_roi(); - integral(src_roi, dst_roi, dst1, sdepth); - ocl::integral(gsrc_roi, gdst_roi, gdst1, sdepth); + integral(src_roi, dst1, dst_roi); + ocl::integral(gsrc_roi, gdst1, gdst_roi); Near(); - if(gdst1.clCxt->supportsFeature(ocl::FEATURE_CL_DOUBLE)) - EXPECT_MAT_NEAR(dst1, Mat(gdst1), 0.); } } @@ -575,7 +563,7 @@ INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine( Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F Values(0), // not used - Values((MatType)CV_32SC1, (MatType)CV_32FC1), + Values(0), // not used Bool())); INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine( diff --git a/modules/ocl/test/test_match_template.cpp b/modules/ocl/test/test_match_template.cpp index edbc36a3f..aa63f3d9e 100644 --- a/modules/ocl/test/test_match_template.cpp +++ b/modules/ocl/test/test_match_template.cpp @@ -50,7 +50,7 @@ // MatchTemplate #define ALL_TEMPLATE_METHODS testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR), TemplateMethod(cv::TM_CCOEFF), TemplateMethod(cv::TM_SQDIFF_NORMED), TemplateMethod(cv::TM_CCORR_NORMED), TemplateMethod(cv::TM_CCOEFF_NORMED)) -IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size); +IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size) #define MTEMP_SIZES testing::Values(cv::Size(128, 256), cv::Size(1024, 768)) diff --git a/modules/ocl/test/test_objdetect.cpp b/modules/ocl/test/test_objdetect.cpp index 89f45b07c..ea639a244 100644 --- a/modules/ocl/test/test_objdetect.cpp +++ b/modules/ocl/test/test_objdetect.cpp @@ -181,7 +181,7 @@ INSTANTIATE_TEST_CASE_P(OCL_ObjDetect, HOG, testing::Combine( testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); ///////////////////////////// Haar ////////////////////////////// -IMPLEMENT_PARAM_CLASS(CascadeName, std::string); +IMPLEMENT_PARAM_CLASS(CascadeName, std::string) CascadeName cascade_frontalface_alt(std::string("haarcascade_frontalface_alt.xml")); CascadeName cascade_frontalface_alt2(std::string("haarcascade_frontalface_alt2.xml")); struct getRect @@ -226,7 +226,7 @@ OCL_TEST_P(Haar, FaceDetect) flags, Size(30, 30), Size(0, 0)); - EXPECT_LT(checkRectSimilarity(img.size(), faces, oclfaces), 1.0); + EXPECT_LT(checkRectSimilarity(img.size(), faces, oclfaces), 0.1); } OCL_TEST_P(Haar, FaceDetectUseBuf) @@ -247,7 +247,7 @@ OCL_TEST_P(Haar, FaceDetectUseBuf) Size(30, 30)); cascadebuf.release(); - EXPECT_LT(checkRectSimilarity(img.size(), faces, oclfaces), 1.0); + EXPECT_LT(checkRectSimilarity(img.size(), faces, oclfaces), 0.1); } INSTANTIATE_TEST_CASE_P(OCL_ObjDetect, Haar, diff --git a/modules/ocl/test/utility.hpp b/modules/ocl/test/utility.hpp index a1fe3ffb7..6591456ee 100644 --- a/modules/ocl/test/utility.hpp +++ b/modules/ocl/test/utility.hpp @@ -266,7 +266,7 @@ CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA) CV_ENUM(Border, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP) CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED) -CV_FLAGS(GemmFlags, GEMM_1_T, GEMM_2_T, GEMM_3_T); +CV_FLAGS(GemmFlags, GEMM_1_T, GEMM_2_T, GEMM_3_T) CV_FLAGS(WarpFlags, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, WARP_INVERSE_MAP) CV_FLAGS(DftFlags, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT) diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index 4762eda31..a673e5820 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -133,7 +133,7 @@ static void fastNlMeansDenoisingMultiCheckPreconditions( { CV_Error(CV_StsBadArg, "imgToDenoiseIndex and temporalWindowSize " - "should be choosen corresponding srcImgs size!"); + "should be chosen corresponding srcImgs size!"); } for (int i = 1; i < src_imgs_size; i++) { diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 2c44a3906..bab8b061b 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -108,17 +108,17 @@ endif() if(WIN32) set(PYTHON_INSTALL_ARCHIVE "") else() - set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main) + set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python) endif() if(NOT INSTALL_CREATE_DISTRIB) install(TARGETS ${the_module} ${PYTHON_INSTALL_CONFIGURATIONS} - RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main - LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main + RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python + LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python ${PYTHON_INSTALL_ARCHIVE} ) - install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main) + install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python) else() if(DEFINED PYTHON_VERSION_MAJOR) set(__ver "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") @@ -127,7 +127,7 @@ else() endif() install(TARGETS ${the_module} CONFIGURATIONS Release - RUNTIME DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT main - LIBRARY DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT main + RUNTIME DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python + LIBRARY DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python ) endif() diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 6e9a35ba7..fc8b2fcf9 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,6 +1,7 @@ set(the_description "Images stitching") -if (ENABLE_DYNAMIC_CUDA) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_nonfree) else() ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu opencv_nonfree) -endif() \ No newline at end of file +endif() diff --git a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp index 108cd0fac..af7439fba 100644 --- a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp @@ -44,11 +44,12 @@ #define __OPENCV_STITCHING_MATCHERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) +#if defined(HAVE_OPENCV_NONFREE) #include "opencv2/nonfree/gpu.hpp" #endif @@ -104,7 +105,7 @@ private: }; -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) +#if defined(HAVE_OPENCV_NONFREE) class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp index 9301dc5eb..5034c8004 100644 --- a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp @@ -45,7 +45,7 @@ #include #include "opencv2/core/core.hpp" -#include "opencv2/opencv_modules.hpp" +#include "opencv2/core/gpumat.hpp" namespace cv { namespace detail { @@ -227,7 +227,6 @@ private: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder { public: @@ -251,7 +250,6 @@ private: float terminal_cost_; float bad_region_penalty_; }; -#endif } // namespace detail } // namespace cv diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index d44bfe69e..60d5e5418 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -44,11 +44,8 @@ #define __OPENCV_STITCHING_WARPERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) -# include "opencv2/gpu/gpu.hpp" -#endif namespace cv { namespace detail { @@ -331,7 +328,6 @@ public: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS PlaneWarperGpu : public PlaneWarper { public: @@ -448,7 +444,6 @@ public: private: gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; }; -#endif struct SphericalPortraitProjector : ProjectorBase diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index 87efa7e80..11e012ff0 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -145,7 +145,6 @@ public: -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class PlaneWarperGpu: public WarperCreator { public: @@ -165,7 +164,6 @@ class SphericalWarperGpu: public WarperCreator public: Ptr create(float scale) const { return new detail::SphericalWarperGpu(scale); } }; -#endif } // namespace cv diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index fb3c0d666..316263e99 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -189,7 +189,7 @@ Rect FeatherBlender::createWeightMaps(const vector &masks, const vector &pyr) void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) pyr.resize(num_levels + 1); vector gpu_pyr(num_levels + 1); @@ -512,6 +512,7 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) (void)img; (void)num_levels; (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } @@ -531,7 +532,7 @@ void restoreImageFromLaplacePyr(vector &pyr) void restoreImageFromLaplacePyrGpu(vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (pyr.empty()) return; @@ -549,6 +550,7 @@ void restoreImageFromLaplacePyrGpu(vector &pyr) gpu_pyr[0].download(pyr[0]); #else (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index d86206233..ac29d7ca2 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -45,10 +45,7 @@ using namespace std; using namespace cv; using namespace cv::detail; - -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) using namespace cv::gpu; -#endif #ifdef HAVE_OPENCV_NONFREE #include "opencv2/nonfree/nonfree.hpp" @@ -129,7 +126,7 @@ private: float match_conf_; }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) class GpuMatcher : public FeaturesMatcher { public: @@ -204,7 +201,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat LOG("1->2 & 2->1 matches: " << matches_info.matches.size() << endl); } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info) { matches_info.matches.clear(); @@ -432,7 +429,7 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) } } -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, int num_octaves_descr, int num_layers_descr) { @@ -478,6 +475,29 @@ void SurfFeaturesFinderGpu::collectGarbage() keypoints_.release(); descriptors_.release(); } +#elif defined(HAVE_OPENCV_NONFREE) +SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, + int num_octaves_descr, int num_layers_descr) +{ + (void)hess_thresh; + (void)num_octaves; + (void)num_layers; + (void)num_octaves_descr; + (void)num_layers_descr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void SurfFeaturesFinderGpu::find(const Mat &image, ImageFeatures &features) +{ + (void)image; + (void)features; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + +void SurfFeaturesFinderGpu::collectGarbage() +{ +} #endif @@ -533,7 +553,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && getCudaEnabledDeviceCount() > 0) impl_ = new GpuMatcher(match_conf); else diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index 54b672143..699f19c38 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -68,7 +68,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_OPENCV_NONFREE diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index a198c1ebb..234f2047e 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -1318,7 +1318,7 @@ void GraphCutSeamFinder::find(const vector &src, const vector &corne } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, vector &masks) { @@ -1642,6 +1642,62 @@ void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( } } } +#else +void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, + vector &masks) +{ + (void)src; + (void)corners; + (void)masks; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::findInPair(size_t first, size_t second, Rect roi) +{ + (void)first; + (void)second; + (void)roi; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColor(const Mat &img1, const Mat &img2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( + const Mat &img1, const Mat &img2, const Mat &dx1, const Mat &dx2, + const Mat &dy1, const Mat &dy2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)dx1; + (void)dx2; + (void)dy1; + (void)dy2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} #endif } // namespace detail diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index 4a36ab0a4..83ea60954 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -58,7 +58,7 @@ Stitcher Stitcher::createDefault(bool try_use_gpu) stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu)); stitcher.setBundleAdjuster(new detail::BundleAdjusterRay()); -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && gpu::getCudaEnabledDeviceCount() > 0) { #if defined(HAVE_OPENCV_NONFREE) diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp index 935831950..3b1d9c228 100644 --- a/modules/stitching/src/warpers.cpp +++ b/modules/stitching/src/warpers.cpp @@ -212,7 +212,7 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); @@ -294,6 +294,96 @@ Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode); return dst_roi.tl(); } +#else +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); +} + +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)T; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst); +} + + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)T; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point SphericalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} #endif void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) diff --git a/modules/superres/CMakeLists.txt b/modules/superres/CMakeLists.txt index 3da8dc2c6..8e3d7b2f2 100644 --- a/modules/superres/CMakeLists.txt +++ b/modules/superres/CMakeLists.txt @@ -1,7 +1,12 @@ -if(ANDROID OR IOS) +if(IOS) ocv_module_disable(superres) endif() set(the_description "Super Resolution") -ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 -Wundef) -ocv_define_module(superres opencv_imgproc opencv_video OPTIONAL opencv_gpu opencv_highgui opencv_ocl ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 -Wundef -Wshadow) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) + ocv_define_module(superres EXCLUDE_CUDA opencv_imgproc opencv_video OPTIONAL opencv_highgui opencv_ocl) +else() + ocv_define_module(superres opencv_imgproc opencv_video OPTIONAL opencv_gpu opencv_highgui opencv_ocl ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) +endif() diff --git a/modules/superres/src/btv_l1.cpp b/modules/superres/src/btv_l1.cpp index 0d96a9d17..d49bcf32b 100644 --- a/modules/superres/src/btv_l1.cpp +++ b/modules/superres/src/btv_l1.cpp @@ -488,7 +488,7 @@ namespace obj.info()->addParam(obj, "blurKernelSize", obj.blurKernelSize_, false, 0, 0, "Gaussian blur kernel size."); obj.info()->addParam(obj, "blurSigma", obj.blurSigma_, false, 0, 0, "Gaussian blur sigma."); obj.info()->addParam(obj, "temporalAreaRadius", obj.temporalAreaRadius_, false, 0, 0, "Radius of the temporal search area."); - obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")); + obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")) BTVL1::BTVL1() { diff --git a/modules/superres/src/btv_l1_gpu.cpp b/modules/superres/src/btv_l1_gpu.cpp index b93bcfd57..2f40fa377 100644 --- a/modules/superres/src/btv_l1_gpu.cpp +++ b/modules/superres/src/btv_l1_gpu.cpp @@ -51,7 +51,7 @@ using namespace cv::gpu; using namespace cv::superres; using namespace cv::superres::detail; -#if !defined(HAVE_CUDA) || !defined(HAVE_OPENCV_GPU) +#if !defined(HAVE_CUDA) || !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT) Ptr cv::superres::createSuperResolution_BTVL1_GPU() { diff --git a/modules/superres/src/btv_l1_ocl.cpp b/modules/superres/src/btv_l1_ocl.cpp index b4f4acdaf..69564ef0d 100644 --- a/modules/superres/src/btv_l1_ocl.cpp +++ b/modules/superres/src/btv_l1_ocl.cpp @@ -580,7 +580,7 @@ namespace obj.info()->addParam(obj, "blurKernelSize", obj.blurKernelSize_, false, 0, 0, "Gaussian blur kernel size."); obj.info()->addParam(obj, "blurSigma", obj.blurSigma_, false, 0, 0, "Gaussian blur sigma."); obj.info()->addParam(obj, "temporalAreaRadius", obj.temporalAreaRadius_, false, 0, 0, "Radius of the temporal search area."); - obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")); + obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")) BTVL1_OCL::BTVL1_OCL() { diff --git a/modules/superres/src/cuda/btv_l1_gpu.cu b/modules/superres/src/cuda/btv_l1_gpu.cu index b4d96190a..4b0ebdc59 100644 --- a/modules/superres/src/cuda/btv_l1_gpu.cu +++ b/modules/superres/src/cuda/btv_l1_gpu.cu @@ -42,7 +42,7 @@ #include "opencv2/opencv_modules.hpp" -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/transform.hpp" diff --git a/modules/superres/src/frame_source.cpp b/modules/superres/src/frame_source.cpp index 20e45d951..5f59a98b8 100644 --- a/modules/superres/src/frame_source.cpp +++ b/modules/superres/src/frame_source.cpp @@ -200,7 +200,7 @@ Ptr cv::superres::createFrameSource_Camera(int deviceId) ////////////////////////////////////////////////////// // VideoFrameSource_GPU -#ifndef HAVE_OPENCV_GPU +#if !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT) Ptr cv::superres::createFrameSource_Video_GPU(const string& fileName) { diff --git a/modules/superres/src/input_array_utility.cpp b/modules/superres/src/input_array_utility.cpp index 075cf9514..10fc1c96e 100644 --- a/modules/superres/src/input_array_utility.cpp +++ b/modules/superres/src/input_array_utility.cpp @@ -207,7 +207,7 @@ namespace switch (src.kind()) { case _InputArray::GPU_MAT: - #ifdef HAVE_OPENCV_GPU + #if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) gpu::cvtColor(src.getGpuMat(), dst.getGpuMatRef(), code, cn); #else CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform"); diff --git a/modules/superres/src/optical_flow.cpp b/modules/superres/src/optical_flow.cpp index 9df4c3b79..617f83a5e 100644 --- a/modules/superres/src/optical_flow.cpp +++ b/modules/superres/src/optical_flow.cpp @@ -149,7 +149,7 @@ namespace obj.info()->addParam(obj, "numIters", obj.numIters_); obj.info()->addParam(obj, "polyN", obj.polyN_); obj.info()->addParam(obj, "polySigma", obj.polySigma_); - obj.info()->addParam(obj, "flags", obj.flags_)); + obj.info()->addParam(obj, "flags", obj.flags_)) Farneback::Farneback() : CpuOpticalFlow(CV_8UC1) { @@ -217,7 +217,7 @@ namespace obj.info()->addParam(obj, "upscaleAveragingRadius", obj.upscaleAveragingRadius_); obj.info()->addParam(obj, "upscaleSigmaDist", obj.upscaleSigmaDist_); obj.info()->addParam(obj, "upscaleSigmaColor", obj.upscaleSigmaColor_); - obj.info()->addParam(obj, "speedUpThr", obj.speedUpThr_)); + obj.info()->addParam(obj, "speedUpThr", obj.speedUpThr_)) Simple::Simple() : CpuOpticalFlow(CV_8UC3) { @@ -300,7 +300,7 @@ namespace obj.info()->addParam(obj, "warps", obj.warps_); obj.info()->addParam(obj, "epsilon", obj.epsilon_); obj.info()->addParam(obj, "iterations", obj.iterations_); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)); + obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)) DualTVL1::DualTVL1() : CpuOpticalFlow(CV_8UC1) { @@ -344,7 +344,7 @@ Ptr cv::superres::createOptFlow_DualTVL1() /////////////////////////////////////////////////////////////////// // GpuOpticalFlow -#ifndef HAVE_OPENCV_GPU +#if !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT) Ptr cv::superres::createOptFlow_Farneback_GPU() { @@ -471,7 +471,7 @@ namespace obj.info()->addParam(obj, "scaleFactor", obj.scaleFactor_, false, 0, 0, "Pyramid scale factor"); obj.info()->addParam(obj, "innerIterations", obj.innerIterations_, false, 0, 0, "Number of lagged non-linearity iterations (inner loop)"); obj.info()->addParam(obj, "outerIterations", obj.outerIterations_, false, 0, 0, "Number of warping iterations (number of pyramid levels)"); - obj.info()->addParam(obj, "solverIterations", obj.solverIterations_, false, 0, 0, "Number of linear system solver iterations")); + obj.info()->addParam(obj, "solverIterations", obj.solverIterations_, false, 0, 0, "Number of linear system solver iterations")) Brox_GPU::Brox_GPU() : GpuOpticalFlow(CV_32FC1), alg_(0.197f, 50.0f, 0.8f, 10, 77, 10) { @@ -535,7 +535,7 @@ namespace CV_INIT_ALGORITHM(PyrLK_GPU, "DenseOpticalFlowExt.PyrLK_GPU", obj.info()->addParam(obj, "winSize", obj.winSize_); obj.info()->addParam(obj, "maxLevel", obj.maxLevel_); - obj.info()->addParam(obj, "iterations", obj.iterations_)); + obj.info()->addParam(obj, "iterations", obj.iterations_)) PyrLK_GPU::PyrLK_GPU() : GpuOpticalFlow(CV_8UC1) { @@ -602,7 +602,7 @@ namespace obj.info()->addParam(obj, "numIters", obj.numIters_); obj.info()->addParam(obj, "polyN", obj.polyN_); obj.info()->addParam(obj, "polySigma", obj.polySigma_); - obj.info()->addParam(obj, "flags", obj.flags_)); + obj.info()->addParam(obj, "flags", obj.flags_)) Farneback_GPU::Farneback_GPU() : GpuOpticalFlow(CV_8UC1) { @@ -678,7 +678,7 @@ namespace obj.info()->addParam(obj, "warps", obj.warps_); obj.info()->addParam(obj, "epsilon", obj.epsilon_); obj.info()->addParam(obj, "iterations", obj.iterations_); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)); + obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)) DualTVL1_GPU::DualTVL1_GPU() : GpuOpticalFlow(CV_8UC1) { @@ -800,7 +800,7 @@ namespace CV_INIT_ALGORITHM(PyrLK_OCL, "DenseOpticalFlowExt.PyrLK_OCL", obj.info()->addParam(obj, "winSize", obj.winSize_); obj.info()->addParam(obj, "maxLevel", obj.maxLevel_); - obj.info()->addParam(obj, "iterations", obj.iterations_)); + obj.info()->addParam(obj, "iterations", obj.iterations_)) PyrLK_OCL::PyrLK_OCL() : oclOpticalFlow(CV_8UC1) { @@ -869,7 +869,7 @@ namespace obj.info()->addParam(obj, "warps", obj.warps_); obj.info()->addParam(obj, "epsilon", obj.epsilon_); obj.info()->addParam(obj, "iterations", obj.iterations_); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)); + obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)) DualTVL1_OCL::DualTVL1_OCL() : oclOpticalFlow(CV_8UC1) { @@ -946,7 +946,7 @@ namespace obj.info()->addParam(obj, "numIters", obj.numIters_); obj.info()->addParam(obj, "polyN", obj.polyN_); obj.info()->addParam(obj, "polySigma", obj.polySigma_); - obj.info()->addParam(obj, "flags", obj.flags_)); + obj.info()->addParam(obj, "flags", obj.flags_)) FarneBack_OCL::FarneBack_OCL() : oclOpticalFlow(CV_8UC1) { diff --git a/modules/superres/src/precomp.hpp b/modules/superres/src/precomp.hpp index 4cf49411b..65fc7c850 100644 --- a/modules/superres/src/precomp.hpp +++ b/modules/superres/src/precomp.hpp @@ -56,7 +56,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/video/tracking.hpp" -#ifdef HAVE_OPENCV_GPU +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_CUDA #include "opencv2/gpu/stream_accessor.hpp" diff --git a/modules/ts/include/opencv2/ts/ts.hpp b/modules/ts/include/opencv2/ts/ts.hpp index 8ea1ad93b..f4cd3ffbc 100644 --- a/modules/ts/include/opencv2/ts/ts.hpp +++ b/modules/ts/include/opencv2/ts/ts.hpp @@ -372,7 +372,7 @@ public: // processing time (in this case there should be possibility to interrupt such a function FAIL_HANG=-13, - // unexpected responce on passing bad arguments to the tested function + // unexpected response on passing bad arguments to the tested function // (the function crashed, proceed succesfully (while it should not), or returned // error code that is different from what is expected) FAIL_BAD_ARG_CHECK=-14, diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index 9238b3e34..088479aa8 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -209,7 +209,7 @@ private: #define SANITY_CHECK(array, ...) ::perf::Regression::add(this, #array, array , ## __VA_ARGS__) #define SANITY_CHECK_KEYPOINTS(array, ...) ::perf::Regression::addKeypoints(this, #array, array , ## __VA_ARGS__) #define SANITY_CHECK_MATCHES(array, ...) ::perf::Regression::addMatches(this, #array, array , ## __VA_ARGS__) -#define SANITY_CHECK_NOTHING() this->setVerified(); +#define SANITY_CHECK_NOTHING() this->setVerified() class CV_EXPORTS GpuPerf { @@ -258,7 +258,7 @@ typedef struct CV_EXPORTS performance_metrics enum PERF_STRATEGY { PERF_STRATEGY_BASE = 0, - PERF_STRATEGY_SIMPLE = 1, + PERF_STRATEGY_SIMPLE = 1 }; diff --git a/modules/ts/misc/chart.py b/modules/ts/misc/chart.py index 39a60eb2e..2663c7875 100755 --- a/modules/ts/misc/chart.py +++ b/modules/ts/misc/chart.py @@ -168,7 +168,7 @@ if __name__ == "__main__": print >> sys.stderr, "%4s: %s" % (i, name) i += 1 if names1: - print >> sys.stderr, "Other suits in this log (can not be choosen):" + print >> sys.stderr, "Other suits in this log (can not be chosen):" for name in sorted(names1): print >> sys.stderr, "%4s: %s" % (i, name) i += 1 diff --git a/modules/ts/misc/summary.py b/modules/ts/misc/summary.py index 4e0cb7e7f..968269985 100755 --- a/modules/ts/misc/summary.py +++ b/modules/ts/misc/summary.py @@ -40,10 +40,12 @@ if __name__ == "__main__": parser.add_option("", "--with-cycles-reduction", action="store_true", dest="calc_cr", default=False, help="output cycle reduction percentages") parser.add_option("", "--with-score", action="store_true", dest="calc_score", default=False, help="output automatic classification of speedups") parser.add_option("", "--progress", action="store_true", dest="progress_mode", default=False, help="enable progress mode") + parser.add_option("", "--regressions", dest="regressions", default=None, metavar="LIST", help="comma-separated custom regressions map: \"[r][c]#current-#reference\" (indexes of columns are 0-based, \"r\" - reverse flag, \"c\" - color flag for base data)") parser.add_option("", "--show-all", action="store_true", dest="showall", default=False, help="also include empty and \"notrun\" lines") parser.add_option("", "--match", dest="match", default=None) parser.add_option("", "--match-replace", dest="match_replace", default="") parser.add_option("", "--regressions-only", dest="regressionsOnly", default=None, metavar="X-FACTOR", help="show only tests with performance regressions not") + parser.add_option("", "--intersect-logs", dest="intersect_logs", default=False, help="show only tests present in all log files") (options, args) = parser.parse_args() options.generateHtml = detectHtmlOutputType(options.format) @@ -55,6 +57,24 @@ if __name__ == "__main__": if options.columns: options.columns = [s.strip().replace("\\n", "\n") for s in options.columns.split(",")] + if options.regressions: + assert not options.progress_mode, 'unsupported mode' + + def parseRegressionColumn(s): + """ Format: '[r][c]-' """ + reverse = s.startswith('r') + if reverse: + s = s[1:] + addColor = s.startswith('c') + if addColor: + s = s[1:] + parts = s.split('-', 1) + link = (int(parts[0]), int(parts[1]), reverse, addColor) + assert link[0] != link[1] + return link + + options.regressions = [parseRegressionColumn(s) for s in options.regressions.split(',')] + # expand wildcards and filter duplicates files = [] seen = set() @@ -89,8 +109,18 @@ if __name__ == "__main__": sys.stderr.write("Error: no test data found" + os.linesep) quit() - # find matches setsCount = len(test_sets) + + if options.regressions is None: + reference = -1 if options.progress_mode else 0 + options.regressions = [(i, reference, False, True) for i in range(1, len(test_sets))] + + for link in options.regressions: + (i, ref, reverse, addColor) = link + assert i >= 0 and i < setsCount + assert ref < setsCount + + # find matches test_cases = {} name_extractor = lambda name: str(name) @@ -116,29 +146,29 @@ if __name__ == "__main__": # header tbl.newColumn("name", "Name of Test", align = "left", cssclass = "col_name") - i = 0 - for set in test_sets: - tbl.newColumn(str(i), getSetName(set, i, options.columns, False), align = "center") - i += 1 - metric_sets = test_sets[1:] + for i in range(setsCount): + tbl.newColumn(str(i), getSetName(test_sets[i], i, options.columns, False), align = "center") + + def addHeaderColumns(suffix, description, cssclass): + for link in options.regressions: + (i, ref, reverse, addColor) = link + if reverse: + i, ref = ref, i + current_set = test_sets[i] + current = getSetName(current_set, i, options.columns) + if ref >= 0: + reference_set = test_sets[ref] + reference = getSetName(reference_set, ref, options.columns) + else: + reference = 'previous' + tbl.newColumn(str(i) + '-' + str(ref) + suffix, '%s\nvs\n%s\n(%s)' % (current, reference, description), align='center', cssclass=cssclass) + if options.calc_cr: - i = 1 - for set in metric_sets: - reference = getSetName(test_sets[0], 0, options.columns) if not options.progress_mode else 'previous' - tbl.newColumn(str(i) + "$", getSetName(set, i, options.columns) + "\nvs\n" + reference + "\n(cycles reduction)", align = "center", cssclass = "col_cr") - i += 1 + addHeaderColumns(suffix='$', description='cycles reduction', cssclass='col_cr') if options.calc_relatives: - i = 1 - for set in metric_sets: - reference = getSetName(test_sets[0], 0, options.columns) if not options.progress_mode else 'previous' - tbl.newColumn(str(i) + "%", getSetName(set, i, options.columns) + "\nvs\n" + reference + "\n(x-factor)", align = "center", cssclass = "col_rel") - i += 1 + addHeaderColumns(suffix='%', description='x-factor', cssclass='col_rel') if options.calc_score: - i = 1 - for set in metric_sets: - reference = getSetName(test_sets[0], 0, options.columns) if not options.progress_mode else 'previous' - tbl.newColumn(str(i) + "S", getSetName(set, i, options.columns) + "\nvs\n" + reference + "\n(score)", align = "center", cssclass = "col_name") - i += 1 + addHeaderColumns(suffix='S', description='score', cssclass='col_name') # rows prevGroupName = None @@ -162,67 +192,90 @@ if __name__ == "__main__": for i in range(setsCount): case = cases[i] if case is None: + if options.intersect_logs: + needNewRow = False + break tbl.newCell(str(i), "-") - if options.calc_relatives and i > 0: - tbl.newCell(str(i) + "%", "-") - if options.calc_cr and i > 0: - tbl.newCell(str(i) + "$", "-") - if options.calc_score and i > 0: - tbl.newCell(str(i) + "$", "-") else: status = case.get("status") if status != "run": - tbl.newCell(str(i), status, color = "red") - if status != "notrun": - needNewRow = True - if options.calc_relatives and i > 0: - tbl.newCell(str(i) + "%", "-", color = "red") - if options.calc_cr and i > 0: - tbl.newCell(str(i) + "$", "-", color = "red") - if options.calc_score and i > 0: - tbl.newCell(str(i) + "S", "-", color = "red") + tbl.newCell(str(i), status, color="red") else: val = getter(case, cases[0], options.units) - def getter_fn(fn): - if fn and i > 0 and val: - for j in reversed(range(i)) if options.progress_mode else [0]: - r = cases[j] - if r is not None and r.get("status") == 'run': - return fn(case, r, options.units) - return None - valp = getter_fn(getter_p) if options.calc_relatives or options.progress_mode else None - valcr = getter_fn(getter_cr) if options.calc_cr else None - val_score = getter_fn(getter_score) if options.calc_score else None - if not valp or i == 0: - color = None - elif valp > 1.05: - color = "green" - elif valp < 0.95: - color = "red" - else: - color = None if val: needNewRow = True - tbl.newCell(str(i), formatValue(val, options.metric, options.units), val, color = color) - if options.calc_relatives and i > 0: - tbl.newCell(str(i) + "%", formatValue(valp, "%"), valp, color = color, bold = color) - if options.calc_cr and i > 0: - tbl.newCell(str(i) + "$", formatValue(valcr, "$"), valcr, color = color, bold = color) - if options.calc_score and i > 0: - tbl.newCell(str(i) + "S", formatValue(val_score, "S"), val_score, color = color, bold = color) + tbl.newCell(str(i), formatValue(val, options.metric, options.units), val) + + if needNewRow: + for link in options.regressions: + (i, reference, reverse, addColor) = link + if reverse: + i, reference = reference, i + tblCellID = str(i) + '-' + str(reference) + case = cases[i] + if case is None: + if options.calc_relatives: + tbl.newCell(tblCellID + "%", "-") + if options.calc_cr: + tbl.newCell(tblCellID + "$", "-") + if options.calc_score: + tbl.newCell(tblCellID + "$", "-") + else: + status = case.get("status") + if status != "run": + tbl.newCell(str(i), status, color="red") + if status != "notrun": + needNewRow = True + if options.calc_relatives: + tbl.newCell(tblCellID + "%", "-", color="red") + if options.calc_cr: + tbl.newCell(tblCellID + "$", "-", color="red") + if options.calc_score: + tbl.newCell(tblCellID + "S", "-", color="red") + else: + val = getter(case, cases[0], options.units) + def getRegression(fn): + if fn and val: + for j in reversed(range(i)) if reference < 0 else [reference]: + r = cases[j] + if r is not None and r.get("status") == 'run': + return fn(case, r, options.units) + valp = getRegression(getter_p) if options.calc_relatives or options.progress_mode else None + valcr = getRegression(getter_cr) if options.calc_cr else None + val_score = getRegression(getter_score) if options.calc_score else None + if not valp: + color = None + elif valp > 1.05: + color = 'green' + elif valp < 0.95: + color = 'red' + else: + color = None + if addColor: + if not reverse: + tbl.newCell(str(i), formatValue(val, options.metric, options.units), val, color=color) + else: + r = cases[reference] + if r is not None and r.get("status") == 'run': + val = getter(r, cases[0], options.units) + tbl.newCell(str(reference), formatValue(val, options.metric, options.units), val, color=color) + if options.calc_relatives: + tbl.newCell(tblCellID + "%", formatValue(valp, "%"), valp, color=color, bold=color) + if options.calc_cr: + tbl.newCell(tblCellID + "$", formatValue(valcr, "$"), valcr, color=color, bold=color) + if options.calc_score: + tbl.newCell(tblCellID + "S", formatValue(val_score, "S"), val_score, color = color, bold = color) + if not needNewRow: tbl.trimLastRow() if options.regressionsOnly: for r in reversed(range(len(tbl.rows))): - delete = True - i = 1 - for set in metric_sets: - val = tbl.rows[r].cells[len(tbl.rows[r].cells)-i].value + for i in range(1, len(options.regressions) + 1): + val = tbl.rows[r].cells[len(tbl.rows[r].cells) - i].value if val is not None and val < float(options.regressionsOnly): - delete = False - i += 1 - if (delete): + break + else: tbl.rows.pop(r) # output table diff --git a/modules/ts/misc/table_formatter.py b/modules/ts/misc/table_formatter.py index 9baff0f79..2e1467b80 100755 --- a/modules/ts/misc/table_formatter.py +++ b/modules/ts/misc/table_formatter.py @@ -426,7 +426,7 @@ class table(object): if r == 0: css = css[:-1] + "border-top:2px solid #6678B1;\"" out.write(" \n" % (attr, css)) - if th is not None: + if td is not None: out.write(" %s\n" % htmlEncode(td.text)) out.write(" \n") i += colspan diff --git a/modules/ts/misc/xls-report.py b/modules/ts/misc/xls-report.py index e71a7f66c..6b90b5924 100755 --- a/modules/ts/misc/xls-report.py +++ b/modules/ts/misc/xls-report.py @@ -97,6 +97,9 @@ re_data_type = re.compile(r'^ (?: 8 | 16 | 32 | 64 ) [USF] C [1234] $', re.VERBO time_style = xlwt.easyxf(num_format_str='#0.00') no_time_style = xlwt.easyxf('pattern: pattern solid, fore_color gray25') +failed_style = xlwt.easyxf('pattern: pattern solid, fore_color red') +noimpl_style = xlwt.easyxf('pattern: pattern solid, fore_color orange') +style_dict = {"failed": failed_style, "noimpl":noimpl_style} speedup_style = time_style good_speedup_style = xlwt.easyxf('font: color green', num_format_str='#0.00') @@ -328,7 +331,7 @@ def main(): for c in config_names: if c in configs: - sheet.write(row, col, configs[c], time_style) + sheet.write(row, col, configs[c], style_dict.get(configs[c], time_style)) else: sheet.write(row, col, None, no_time_style) col += 1 diff --git a/modules/ts/src/ts_arrtest.cpp b/modules/ts/src/ts_arrtest.cpp index ec3f18330..cdfbe23b3 100644 --- a/modules/ts/src/ts_arrtest.cpp +++ b/modules/ts/src/ts_arrtest.cpp @@ -122,7 +122,7 @@ void ArrayTest::get_test_array_types_and_sizes( int /*test_case_idx*/, vector Path_Win_Deriv_Border_Reuse_t; typedef TestBaseWithParam Path_Win_Deriv_Border_Reuse; diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index 6bbb96048..9700dfebd 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -319,7 +319,7 @@ struct MOG2Invoker : ParallelLoopBody for( int mode = 0; mode < nmodes; mode++, mean_m += nchannels ) { float weight = alpha1*gmm[mode].weight + prune;//need only weight if fit is found - + int swap_count = 0; //// //fit not found yet if( !fitsPDF ) @@ -384,6 +384,7 @@ struct MOG2Invoker : ParallelLoopBody if( weight < gmm[i-1].weight ) break; + swap_count++; //swap one up std::swap(gmm[i], gmm[i-1]); for( int c = 0; c < nchannels; c++ ) @@ -401,7 +402,7 @@ struct MOG2Invoker : ParallelLoopBody nmodes--; } - gmm[mode].weight = weight;//update weight by the calculated value + gmm[mode-swap_count].weight = weight;//update weight by the calculated value totalWeight += weight; } //go through all modes @@ -576,54 +577,48 @@ void BackgroundSubtractorMOG2::operator()(InputArray _image, OutputArray _fgmask void BackgroundSubtractorMOG2::getBackgroundImage(OutputArray backgroundImage) const { int nchannels = CV_MAT_CN(frameType); - CV_Assert( nchannels == 3 ); - Mat meanBackground(frameSize, CV_8UC3, Scalar::all(0)); - + CV_Assert(nchannels == 1 || nchannels == 3); + Mat meanBackground(frameSize, CV_MAKETYPE(CV_8U, nchannels), Scalar::all(0)); int firstGaussianIdx = 0; const GMM* gmm = (GMM*)bgmodel.data; - const Vec3f* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); + const float* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); + std::vector meanVal(nchannels, 0.f); for(int row=0; row(row, col); - Vec3f meanVal; float totalWeight = 0.f; for(int gaussianIdx = firstGaussianIdx; gaussianIdx < firstGaussianIdx + nmodes; gaussianIdx++) { GMM gaussian = gmm[gaussianIdx]; - meanVal += gaussian.weight * mean[gaussianIdx]; + size_t meanPosition = gaussianIdx*nchannels; + for(int chn = 0; chn < nchannels; chn++) + { + meanVal[chn] += gaussian.weight * mean[meanPosition + chn]; + } totalWeight += gaussian.weight; if(totalWeight > backgroundRatio) break; } - - meanVal *= (1.f / totalWeight); - meanBackground.at(row, col) = Vec3b(meanVal); + float invWeight = 1.f/totalWeight; + switch(nchannels) + { + case 1: + meanBackground.at(row, col) = (uchar)(meanVal[0] * invWeight); + meanVal[0] = 0.f; + break; + case 3: + Vec3f& meanVec = *reinterpret_cast(&meanVal[0]); + meanBackground.at(row, col) = Vec3b(meanVec * invWeight); + meanVec = 0.f; + break; + } firstGaussianIdx += nmixtures; } } - - switch(CV_MAT_CN(frameType)) - { - case 1: - { - vector channels; - split(meanBackground, channels); - channels[0].copyTo(backgroundImage); - break; - } - - case 3: - { - meanBackground.copyTo(backgroundImage); - break; - } - - default: - CV_Error(CV_StsUnsupportedFormat, ""); - } + meanBackground.copyTo(backgroundImage); } } diff --git a/modules/video/src/kalman.cpp b/modules/video/src/kalman.cpp index b4b4c7435..16ab7745f 100644 --- a/modules/video/src/kalman.cpp +++ b/modules/video/src/kalman.cpp @@ -297,4 +297,4 @@ const Mat& KalmanFilter::correct(const Mat& measurement) return statePost; } -}; +} diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 291cb86a2..e807db2d1 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -87,6 +87,30 @@ static void calcSharrDeriv(const cv::Mat& src, cv::Mat& dst) _mm_store_si128((__m128i*)(trow1 + x), t1); } #endif + +#if CV_NEON + + const uint16x8_t q8 = vdupq_n_u16(3); + const uint8x8_t d18 = vdup_n_u8(10); + + const int16x8_t q8i = vdupq_n_s16(3); + const int16x8_t q9 = vdupq_n_s16(10); + + for( ; x <= colsn - 8; x += 8) + { + uint8x8_t d0 = vld1_u8((const uint8_t*)&srow0[x]); + uint8x8_t d1 = vld1_u8((const uint8_t*)&srow1[x]); + uint8x8_t d2 = vld1_u8((const uint8_t*)&srow2[x]); + uint16x8_t q4 = vaddl_u8(d0, d2); + uint16x8_t q11 = vsubl_u8(d2, d0); + uint16x8_t q5 = vmulq_u16(q4, q8); + uint16x8_t q6 = vmull_u8(d1, d18); + uint16x8_t q10 = vaddq_u16(q6, q5); + vst1q_u16((uint16_t*)&trow0[x], q10); + vst1q_u16((uint16_t*)&trow1[x], q11); + + } +#endif for( ; x < colsn; x++ ) { int t0 = (srow0[x] + srow2[x])*3 + srow1[x]*10; @@ -123,6 +147,35 @@ static void calcSharrDeriv(const cv::Mat& src, cv::Mat& dst) _mm_storeu_si128((__m128i*)(drow + x*2 + 8), t0); } #endif + +#if CV_NEON + for( ; x <= colsn - 8; x += 8 ) + { + + int16x8_t q0 = vld1q_s16((const int16_t*)&trow0[x+cn]); + int16x8_t q1 = vld1q_s16((const int16_t*)&trow0[x-cn]); + int16x8_t q2 = vld1q_s16((const int16_t*)&trow1[x+cn]); + int16x8_t q3 = vld1q_s16((const int16_t*)&trow1[x-cn]); + int16x8_t q5 = vsubq_s16(q0, q1); + int16x8_t q6 = vaddq_s16(q2, q3); + int16x8_t q4 = vld1q_s16((const int16_t*)&trow1[x]); + int16x8_t q7 = vmulq_s16(q6, q8i); + int16x8_t q10 = vmulq_s16(q4, q9); + int16x8_t q11 = vaddq_s16(q7, q10); + int16x4_t d22 = vget_low_s16(q11); + int16x4_t d23 = vget_high_s16(q11); + int16x4_t d11 = vget_high_s16(q5); + int16x4_t d10 = vget_low_s16(q5); + int16x4x2_t q5x2, q11x2; + q5x2.val[0] = d10; q5x2.val[1] = d22; + q11x2.val[0] = d11; q11x2.val[1] = d23; + vst2_s16((int16_t*)&drow[x*2], q5x2); + vst2_s16((int16_t*)&drow[(x*2)+8], q11x2); + + } + +#endif + for( ; x < colsn; x++ ) { deriv_type t0 = (deriv_type)(trow0[x+cn] - trow0[x-cn]); @@ -226,6 +279,21 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const __m128 qA11 = _mm_setzero_ps(), qA12 = _mm_setzero_ps(), qA22 = _mm_setzero_ps(); #endif +#if CV_NEON + + int CV_DECL_ALIGNED(16) nA11[] = {0, 0, 0, 0}, nA12[] = {0, 0, 0, 0}, nA22[] = {0, 0, 0, 0}; + const int shifter1 = -(W_BITS - 5); //negative so it shifts right + const int shifter2 = -(W_BITS); + + const int16x4_t d26 = vdup_n_s16((int16_t)iw00); + const int16x4_t d27 = vdup_n_s16((int16_t)iw01); + const int16x4_t d28 = vdup_n_s16((int16_t)iw10); + const int16x4_t d29 = vdup_n_s16((int16_t)iw11); + const int32x4_t q11 = vdupq_n_s32((int32_t)shifter1); + const int32x4_t q12 = vdupq_n_s32((int32_t)shifter2); + +#endif + // extract the patch from the first image, compute covariation matrix of derivatives int x, y; for( y = 0; y < winSize.height; y++ ) @@ -279,6 +347,92 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const } #endif +#if CV_NEON + + for( ; x <= winSize.width*cn - 4; x += 4, dsrc += 4*2, dIptr += 4*2 ) + { + + uint8x8_t d0 = vld1_u8(&src[x]); + uint8x8_t d2 = vld1_u8(&src[x+cn]); + uint16x8_t q0 = vmovl_u8(d0); + uint16x8_t q1 = vmovl_u8(d2); + + int32x4_t q5 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q0)), d26); + int32x4_t q6 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q1)), d27); + + uint8x8_t d4 = vld1_u8(&src[x + stepI]); + uint8x8_t d6 = vld1_u8(&src[x + stepI + cn]); + uint16x8_t q2 = vmovl_u8(d4); + uint16x8_t q3 = vmovl_u8(d6); + + int32x4_t q7 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q2)), d28); + int32x4_t q8 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q3)), d29); + + q5 = vaddq_s32(q5, q6); + q7 = vaddq_s32(q7, q8); + q5 = vaddq_s32(q5, q7); + + int16x4x2_t d0d1 = vld2_s16(dsrc); + int16x4x2_t d2d3 = vld2_s16(&dsrc[cn2]); + + q5 = vqrshlq_s32(q5, q11); + + int32x4_t q4 = vmull_s16(d0d1.val[0], d26); + q6 = vmull_s16(d0d1.val[1], d26); + + int16x4_t nd0 = vmovn_s32(q5); + + q7 = vmull_s16(d2d3.val[0], d27); + q8 = vmull_s16(d2d3.val[1], d27); + + vst1_s16(&Iptr[x], nd0); + + int16x4x2_t d4d5 = vld2_s16(&dsrc[dstep]); + int16x4x2_t d6d7 = vld2_s16(&dsrc[dstep+cn2]); + + q4 = vaddq_s32(q4, q7); + q6 = vaddq_s32(q6, q8); + + q7 = vmull_s16(d4d5.val[0], d28); + int32x4_t nq0 = vmull_s16(d4d5.val[1], d28); + q8 = vmull_s16(d6d7.val[0], d29); + int32x4_t q15 = vmull_s16(d6d7.val[1], d29); + + q7 = vaddq_s32(q7, q8); + nq0 = vaddq_s32(nq0, q15); + + q4 = vaddq_s32(q4, q7); + q6 = vaddq_s32(q6, nq0); + + int32x4_t nq1 = vld1q_s32(nA12); + int32x4_t nq2 = vld1q_s32(nA22); + nq0 = vld1q_s32(nA11); + + q4 = vqrshlq_s32(q4, q12); + q6 = vqrshlq_s32(q6, q12); + + q7 = vmulq_s32(q4, q4); + q8 = vmulq_s32(q4, q6); + q15 = vmulq_s32(q6, q6); + + nq0 = vaddq_s32(nq0, q7); + nq1 = vaddq_s32(nq1, q8); + nq2 = vaddq_s32(nq2, q15); + + vst1q_s32(nA11, nq0); + vst1q_s32(nA12, nq1); + vst1q_s32(nA22, nq2); + + int16x4_t d8 = vmovn_s32(q4); + int16x4_t d12 = vmovn_s32(q6); + + int16x4x2_t d8d12; + d8d12.val[0] = d8; d8d12.val[1] = d12; + vst2_s16(dIptr, d8d12); + } + +#endif + for( ; x < winSize.width*cn; x++, dsrc += 2, dIptr += 2 ) { int ival = CV_DESCALE(src[x]*iw00 + src[x+cn]*iw01 + @@ -308,6 +462,12 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const A22 += A22buf[0] + A22buf[1] + A22buf[2] + A22buf[3]; #endif +#if CV_NEON + A11 += (float)(nA11[0] + nA11[1] + nA11[2] + nA11[3]); + A12 += (float)(nA12[0] + nA12[1] + nA12[2] + nA12[3]); + A22 += (float)(nA22[0] + nA22[1] + nA22[2] + nA22[3]); +#endif + A11 *= FLT_SCALE; A12 *= FLT_SCALE; A22 *= FLT_SCALE; @@ -357,6 +517,17 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const __m128 qb0 = _mm_setzero_ps(), qb1 = _mm_setzero_ps(); #endif +#if CV_NEON + + int CV_DECL_ALIGNED(16) nB1[] = {0,0,0,0}, nB2[] = {0,0,0,0}; + + const int16x4_t d26_2 = vdup_n_s16((int16_t)iw00); + const int16x4_t d27_2 = vdup_n_s16((int16_t)iw01); + const int16x4_t d28_2 = vdup_n_s16((int16_t)iw10); + const int16x4_t d29_2 = vdup_n_s16((int16_t)iw11); + +#endif + for( y = 0; y < winSize.height; y++ ) { const uchar* Jptr = (const uchar*)J.data + (y + inextPt.y)*stepJ + inextPt.x*cn; @@ -400,6 +571,80 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const } #endif +#if CV_NEON + + for( ; x <= winSize.width*cn - 8; x += 8, dIptr += 8*2 ) + { + + uint8x8_t d0 = vld1_u8(&Jptr[x]); + uint8x8_t d2 = vld1_u8(&Jptr[x+cn]); + uint8x8_t d4 = vld1_u8(&Jptr[x+stepJ]); + uint8x8_t d6 = vld1_u8(&Jptr[x+stepJ+cn]); + + uint16x8_t q0 = vmovl_u8(d0); + uint16x8_t q1 = vmovl_u8(d2); + uint16x8_t q2 = vmovl_u8(d4); + uint16x8_t q3 = vmovl_u8(d6); + + int32x4_t nq4 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q0)), d26_2); + int32x4_t nq5 = vmull_s16(vget_high_s16(vreinterpretq_s16_u16(q0)), d26_2); + + int32x4_t nq6 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q1)), d27_2); + int32x4_t nq7 = vmull_s16(vget_high_s16(vreinterpretq_s16_u16(q1)), d27_2); + + int32x4_t nq8 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q2)), d28_2); + int32x4_t nq9 = vmull_s16(vget_high_s16(vreinterpretq_s16_u16(q2)), d28_2); + + int32x4_t nq10 = vmull_s16(vget_low_s16(vreinterpretq_s16_u16(q3)), d29_2); + int32x4_t nq11 = vmull_s16(vget_high_s16(vreinterpretq_s16_u16(q3)), d29_2); + + nq4 = vaddq_s32(nq4, nq6); + nq5 = vaddq_s32(nq5, nq7); + nq8 = vaddq_s32(nq8, nq10); + nq9 = vaddq_s32(nq9, nq11); + + int16x8_t q6 = vld1q_s16(&Iptr[x]); + + nq4 = vaddq_s32(nq4, nq8); + nq5 = vaddq_s32(nq5, nq9); + + nq8 = vmovl_s16(vget_high_s16(q6)); + nq6 = vmovl_s16(vget_low_s16(q6)); + + nq4 = vqrshlq_s32(nq4, q11); + nq5 = vqrshlq_s32(nq5, q11); + + int16x8x2_t q0q1 = vld2q_s16(dIptr); + nq11 = vld1q_s32(nB1); + int32x4_t nq15 = vld1q_s32(nB2); + + nq4 = vsubq_s32(nq4, nq6); + nq5 = vsubq_s32(nq5, nq8); + + int32x4_t nq2 = vmovl_s16(vget_low_s16(q0q1.val[0])); + int32x4_t nq3 = vmovl_s16(vget_high_s16(q0q1.val[0])); + + nq7 = vmovl_s16(vget_low_s16(q0q1.val[1])); + nq8 = vmovl_s16(vget_high_s16(q0q1.val[1])); + + nq9 = vmulq_s32(nq4, nq2); + nq10 = vmulq_s32(nq5, nq3); + + nq4 = vmulq_s32(nq4, nq7); + nq5 = vmulq_s32(nq5, nq8); + + nq9 = vaddq_s32(nq9, nq10); + nq4 = vaddq_s32(nq4, nq5); + + nq11 = vaddq_s32(nq11, nq9); + nq15 = vaddq_s32(nq15, nq4); + + vst1q_s32(nB1, nq11); + vst1q_s32(nB2, nq15); + } + +#endif + for( ; x < winSize.width*cn; x++, dIptr += 2 ) { int diff = CV_DESCALE(Jptr[x]*iw00 + Jptr[x+cn]*iw01 + @@ -417,6 +662,13 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const b2 += bbuf[1] + bbuf[3]; #endif +#if CV_NEON + + b1 += (float)(nB1[0] + nB1[1] + nB1[2] + nB1[3]); + b2 += (float)(nB2[0] + nB2[1] + nB2[2] + nB2[3]); + +#endif + b1 *= FLT_SCALE; b2 *= FLT_SCALE; diff --git a/modules/video/src/precomp.hpp b/modules/video/src/precomp.hpp index 9b6077f1e..ced9a3761 100644 --- a/modules/video/src/precomp.hpp +++ b/modules/video/src/precomp.hpp @@ -49,6 +49,7 @@ #include "opencv2/video/background_segm.hpp" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/internal.hpp" +#include "opencv2/core/core.hpp" #include diff --git a/modules/video/src/tvl1flow.cpp b/modules/video/src/tvl1flow.cpp index ddcdabdd3..eb0ff2351 100644 --- a/modules/video/src/tvl1flow.cpp +++ b/modules/video/src/tvl1flow.cpp @@ -928,7 +928,7 @@ CV_INIT_ALGORITHM(OpticalFlowDual_TVL1, "DenseOpticalFlow.DualTVL1", "Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time"); obj.info()->addParam(obj, "iterations", obj.iterations, false, 0, 0, "Stopping criterion iterations number used in the numerical scheme"); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow)); + obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow)) } // namespace diff --git a/modules/video/src/video_init.cpp b/modules/video/src/video_init.cpp index 7ec860fbd..69928c398 100644 --- a/modules/video/src/video_init.cpp +++ b/modules/video/src/video_init.cpp @@ -52,7 +52,7 @@ CV_INIT_ALGORITHM(BackgroundSubtractorMOG, "BackgroundSubtractor.MOG", obj.info()->addParam(obj, "history", obj.history); obj.info()->addParam(obj, "nmixtures", obj.nmixtures); obj.info()->addParam(obj, "backgroundRatio", obj.backgroundRatio); - obj.info()->addParam(obj, "noiseSigma", obj.noiseSigma)); + obj.info()->addParam(obj, "noiseSigma", obj.noiseSigma)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -68,7 +68,7 @@ CV_INIT_ALGORITHM(BackgroundSubtractorMOG2, "BackgroundSubtractor.MOG2", obj.info()->addParam(obj, "fVarMax", obj.fVarMax); obj.info()->addParam(obj, "fCT", obj.fCT); obj.info()->addParam(obj, "nShadowDetection", obj.nShadowDetection); - obj.info()->addParam(obj, "fTau", obj.fTau)); + obj.info()->addParam(obj, "fTau", obj.fTau)) /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -88,7 +88,7 @@ CV_INIT_ALGORITHM(BackgroundSubtractorGMG, "BackgroundSubtractor.GMG", obj.info()->addParam(obj, "decisionThreshold", obj.decisionThreshold,false,0,0, "Threshold for FG decision rule. Pixel is FG if posterior probability exceeds threshold."); obj.info()->addParam(obj, "updateBackgroundModel", obj.updateBackgroundModel,false,0,0, - "Perform background model update.")); + "Perform background model update.")) bool initModule_video(void) { diff --git a/modules/videostab/src/deblurring.cpp b/modules/videostab/src/deblurring.cpp index 813e908be..be9fd5c0f 100644 --- a/modules/videostab/src/deblurring.cpp +++ b/modules/videostab/src/deblurring.cpp @@ -57,7 +57,7 @@ float calcBlurriness(const Mat &frame) Sobel(frame, Gx, CV_32F, 1, 0); Sobel(frame, Gy, CV_32F, 0, 1); double normGx = norm(Gx); - double normGy = norm(Gx); + double normGy = norm(Gy); double sumSq = normGx*normGx + normGy*normGy; return static_cast(1. / (sumSq / frame.size().area() + 1e-6)); } diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt new file mode 100644 index 000000000..d839491c1 --- /dev/null +++ b/modules/viz/CMakeLists.txt @@ -0,0 +1,15 @@ +if(NOT WITH_VTK OR NOT DEFINED HAVE_VTK OR NOT HAVE_VTK) + ocv_module_disable(viz) +endif() + +include(${VTK_USE_FILE}) +set(the_description "Viz") +ocv_define_module(viz opencv_core ${VTK_LIBRARIES}) + +if(APPLE AND BUILD_opencv_viz) + target_link_libraries(opencv_viz "-framework Cocoa") +endif() + +if(TARGET opencv_test_viz) + set_target_properties(opencv_test_viz PROPERTIES MACOSX_BUNDLE TRUE) +endif() diff --git a/modules/viz/doc/images/cpw1.png b/modules/viz/doc/images/cpw1.png new file mode 100644 index 000000000..985b1eeaf Binary files /dev/null and b/modules/viz/doc/images/cpw1.png differ diff --git a/modules/viz/doc/images/cpw2.png b/modules/viz/doc/images/cpw2.png new file mode 100644 index 000000000..5733a6af6 Binary files /dev/null and b/modules/viz/doc/images/cpw2.png differ diff --git a/modules/viz/doc/images/cpw3.png b/modules/viz/doc/images/cpw3.png new file mode 100644 index 000000000..585b836b6 Binary files /dev/null and b/modules/viz/doc/images/cpw3.png differ diff --git a/modules/viz/doc/images/cube_widget.png b/modules/viz/doc/images/cube_widget.png new file mode 100644 index 000000000..ffe56811a Binary files /dev/null and b/modules/viz/doc/images/cube_widget.png differ diff --git a/modules/viz/doc/viz.rst b/modules/viz/doc/viz.rst new file mode 100644 index 000000000..1d8c743ad --- /dev/null +++ b/modules/viz/doc/viz.rst @@ -0,0 +1,9 @@ +*********************** +viz. 3D Visualizer +*********************** + +.. toctree:: + :maxdepth: 2 + + viz3d.rst + widget.rst diff --git a/modules/viz/doc/viz3d.rst b/modules/viz/doc/viz3d.rst new file mode 100644 index 000000000..d0e24ae8e --- /dev/null +++ b/modules/viz/doc/viz3d.rst @@ -0,0 +1,637 @@ +Viz +=== + +.. highlight:: cpp + +This section describes 3D visualization window as well as classes and methods +that are used to interact with it. + +3D visualization window (see :ocv:class:`Viz3d`) is used to display widgets (see :ocv:class:`Widget`), and it provides +several methods to interact with scene and widgets. + +viz::makeTransformToGlobal +-------------------------- +Takes coordinate frame data and builds transform to global coordinate frame. + +.. ocv:function:: Affine3d viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0)) + + :param axis_x: X axis vector in global coordinate frame. + :param axis_y: Y axis vector in global coordinate frame. + :param axis_z: Z axis vector in global coordinate frame. + :param origin: Origin of the coordinate frame in global coordinate frame. + +This function returns affine transform that describes transformation between global coordinate frame and a given coordinate frame. + +viz::makeCameraPose +------------------- +Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation). + +.. ocv:function:: Affine3d makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir) + + :param position: Position of the camera in global coordinate frame. + :param focal_point: Focal point of the camera in global coordinate frame. + :param y_dir: Up vector of the camera in global coordinate frame. + +This function returns pose of the camera in global coordinate frame. + +viz::getWindowByName +-------------------- +Retrieves a window by its name. + +.. ocv:function:: Viz3d getWindowByName(const String &window_name) + + :param window_name: Name of the window that is to be retrieved. + +This function returns a :ocv:class:`Viz3d` object with the given name. + +.. note:: If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned. + +.. note:: Window names are automatically prefixed by "Viz - " if it is not done by the user. + + .. code-block:: cpp + + /// window and window_2 are the same windows. + viz::Viz3d window = viz::getWindowByName("myWindow"); + viz::Viz3d window_2 = viz::getWindowByName("Viz - myWindow"); + +viz::isNan +---------- +Checks **float/double** value for nan. + + .. ocv:function:: bool isNan(float x) + + .. ocv:function:: bool isNan(double x) + + :param x: return true if nan. + +Checks **vector** for nan. + + .. ocv:function:: bool isNan(const Vec<_Tp, cn>& v) + + :param v: return true if **any** of the elements of the vector is *nan*. + +Checks **point** for nan + + .. ocv:function:: bool isNan(const Point3_<_Tp>& p) + + :param p: return true if **any** of the elements of the point is *nan*. + +viz::Viz3d +---------- +.. ocv:class:: Viz3d + +The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :: + + class CV_EXPORTS Viz3d + { + public: + typedef cv::Ptr Ptr; + typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); + typedef void (*MouseCallback)(const MouseEvent&, void*); + + Viz3d(const String& window_name = String()); + Viz3d(const Viz3d&); + Viz3d& operator=(const Viz3d&); + ~Viz3d(); + + void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; + void removeAllWidgets(); + + void setWidgetPose(const String &id, const Affine3d &pose); + void updateWidgetPose(const String &id, const Affine3d &pose); + Affine3d getWidgetPose(const String &id) const; + + void showImage(InputArray image, const Size& window_size = Size(-1, -1)); + + void setCamera(const Camera &camera); + Camera getCamera() const; + Affine3d getViewerPose(); + void setViewerPose(const Affine3d &pose); + + void resetCameraViewpoint (const String &id); + void resetCamera(); + + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); + void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); + + Size getWindowSize() const; + void setWindowSize(const Size &window_size); + String getWindowName() const; + void saveScreenshot (const String &file); + void setWindowPosition (int x, int y); + void setFullScreen (bool mode); + void setBackgroundColor(const Color& color = Color::black()); + + void spin(); + void spinOnce(int time = 1, bool force_redraw = false); + bool wasStopped() const; + + void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); + void registerMouseCallback(MouseCallback callback, void* cookie = 0); + + void setRenderingProperty(const String &id, int property, double value); + double getRenderingProperty(const String &id, int property); + + + void setRepresentation(int representation); + private: + /* hidden */ + }; + +viz::Viz3d::Viz3d +----------------- +The constructors. + +.. ocv:function:: Viz3d::Viz3d(const String& window_name = String()) + + :param window_name: Name of the window. + +viz::Viz3d::showWidget +---------------------- +Shows a widget in the window. + +.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()) + + :param id: A unique id for the widget. + :param widget: The widget to be displayed in the window. + :param pose: Pose of the widget. + +viz::Viz3d::removeWidget +------------------------ +Removes a widget from the window. + +.. ocv:function:: void removeWidget(const String &id) + + :param id: The id of the widget that will be removed. + +viz::Viz3d::getWidget +--------------------- +Retrieves a widget from the window. A widget is implicitly shared; +that is, if the returned widget is modified, the changes will be +immediately visible in the window. + +.. ocv:function:: Widget getWidget(const String &id) const + + :param id: The id of the widget that will be returned. + +viz::Viz3d::removeAllWidgets +---------------------------- +Removes all widgets from the window. + +.. ocv:function:: void removeAllWidgets() + +viz::Viz3d::showImage +--------------------- +Removed all widgets and displays image scaled to whole window area. + +.. ocv:function:: void showImage(InputArray image, const Size& window_size = Size(-1, -1)) + + :param image: Image to be displayed. + :param size: Size of Viz3d window. Default value means no change. + +viz::Viz3d::setWidgetPose +------------------------- +Sets pose of a widget in the window. + +.. ocv:function:: void setWidgetPose(const String &id, const Affine3d &pose) + + :param id: The id of the widget whose pose will be set. + :param pose: The new pose of the widget. + +viz::Viz3d::updateWidgetPose +---------------------------- +Updates pose of a widget in the window by pre-multiplying its current pose. + +.. ocv:function:: void updateWidgetPose(const String &id, const Affine3d &pose) + + :param id: The id of the widget whose pose will be updated. + :param pose: The pose that the current pose of the widget will be pre-multiplied by. + +viz::Viz3d::getWidgetPose +------------------------- +Returns the current pose of a widget in the window. + +.. ocv:function:: Affine3d getWidgetPose(const String &id) const + + :param id: The id of the widget whose pose will be returned. + +viz::Viz3d::setCamera +--------------------- +Sets the intrinsic parameters of the viewer using Camera. + +.. ocv:function:: void setCamera(const Camera &camera) + + :param camera: Camera object wrapping intrinsinc parameters. + +viz::Viz3d::getCamera +--------------------- +Returns a camera object that contains intrinsic parameters of the current viewer. + +.. ocv:function:: Camera getCamera() const + +viz::Viz3d::getViewerPose +------------------------- +Returns the current pose of the viewer. + +..ocv:function:: Affine3d getViewerPose() + +viz::Viz3d::setViewerPose +------------------------- +Sets pose of the viewer. + +.. ocv:function:: void setViewerPose(const Affine3d &pose) + + :param pose: The new pose of the viewer. + +viz::Viz3d::resetCameraViewpoint +-------------------------------- +Resets camera viewpoint to a 3D widget in the scene. + +.. ocv:function:: void resetCameraViewpoint (const String &id) + + :param pose: Id of a 3D widget. + +viz::Viz3d::resetCamera +----------------------- +Resets camera. + +.. ocv:function:: void resetCamera() + +viz::Viz3d::convertToWindowCoordinates +-------------------------------------- +Transforms a point in world coordinate system to window coordinate system. + +.. ocv:function:: void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) + + :param pt: Point in world coordinate system. + :param window_coord: Output point in window coordinate system. + +viz::Viz3d::converTo3DRay +------------------------- +Transforms a point in window coordinate system to a 3D ray in world coordinate system. + +.. ocv:function:: void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) + + :param window_coord: Point in window coordinate system. + :param origin: Output origin of the ray. + :param direction: Output direction of the ray. + +viz::Viz3d::getWindowSize +------------------------- +Returns the current size of the window. + +.. ocv:function:: Size getWindowSize() const + +viz::Viz3d::setWindowSize +------------------------- +Sets the size of the window. + +.. ocv:function:: void setWindowSize(const Size &window_size) + + :param window_size: New size of the window. + +viz::Viz3d::getWindowName +------------------------- +Returns the name of the window which has been set in the constructor. + +.. ocv:function:: String getWindowName() const + +viz::Viz3d::saveScreenshot +-------------------------- +Saves screenshot of the current scene. + +.. ocv:function:: void saveScreenshot(const String &file) + + :param file: Name of the file. + +viz::Viz3d::setWindowPosition +----------------------------- +Sets the position of the window in the screen. + +.. ocv:function:: void setWindowPosition(int x, int y) + + :param x: x coordinate of the window + :param y: y coordinate of the window + +viz::Viz3d::setFullScreen +------------------------- +Sets or unsets full-screen rendering mode. + +.. ocv:function:: void setFullScreen(bool mode) + + :param mode: If true, window will use full-screen mode. + +viz::Viz3d::setBackgroundColor +------------------------------ +Sets background color. + +.. ocv:function:: void setBackgroundColor(const Color& color = Color::black()) + +viz::Viz3d::spin +---------------- +The window renders and starts the event loop. + +.. ocv:function:: void spin() + +viz::Viz3d::spinOnce +-------------------- +Starts the event loop for a given time. + +.. ocv:function:: void spinOnce(int time = 1, bool force_redraw = false) + + :param time: Amount of time in milliseconds for the event loop to keep running. + :param force_draw: If true, window renders. + +viz::Viz3d::wasStopped +---------------------- +Returns whether the event loop has been stopped. + +.. ocv:function:: bool wasStopped() + +viz::Viz3d::registerKeyboardCallback +------------------------------------ +Sets keyboard handler. + +.. ocv:function:: void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0) + + :param callback: Keyboard callback ``(void (*KeyboardCallbackFunction(const KeyboardEvent&, void*))``. + :param cookie: The optional parameter passed to the callback. + +viz::Viz3d::registerMouseCallback +--------------------------------- +Sets mouse handler. + +.. ocv:function:: void registerMouseCallback(MouseCallback callback, void* cookie = 0) + + :param callback: Mouse callback ``(void (*MouseCallback)(const MouseEvent&, void*))``. + :param cookie: The optional parameter passed to the callback. + +viz::Viz3d::setRenderingProperty +-------------------------------- +Sets rendering property of a widget. + +.. ocv:function:: void setRenderingProperty(const String &id, int property, double value) + + :param id: Id of the widget. + :param property: Property that will be modified. + :param value: The new value of the property. + + **Rendering property** can be one of the following: + + * **POINT_SIZE** + * **OPACITY** + * **LINE_WIDTH** + * **FONT_SIZE** + * **REPRESENTATION**: Expected values are + * **REPRESENTATION_POINTS** + * **REPRESENTATION_WIREFRAME** + * **REPRESENTATION_SURFACE** + * **IMMEDIATE_RENDERING**: + * Turn on immediate rendering by setting the value to ``1``. + * Turn off immediate rendering by setting the value to ``0``. + * **SHADING**: Expected values are + * **SHADING_FLAT** + * **SHADING_GOURAUD** + * **SHADING_PHONG** + +viz::Viz3d::getRenderingProperty +-------------------------------- +Returns rendering property of a widget. + +.. ocv:function:: double getRenderingProperty(const String &id, int property) + + :param id: Id of the widget. + :param property: Property. + + **Rendering property** can be one of the following: + + * **POINT_SIZE** + * **OPACITY** + * **LINE_WIDTH** + * **FONT_SIZE** + * **REPRESENTATION**: Expected values are + * **REPRESENTATION_POINTS** + * **REPRESENTATION_WIREFRAME** + * **REPRESENTATION_SURFACE** + * **IMMEDIATE_RENDERING**: + * Turn on immediate rendering by setting the value to ``1``. + * Turn off immediate rendering by setting the value to ``0``. + * **SHADING**: Expected values are + * **SHADING_FLAT** + * **SHADING_GOURAUD** + * **SHADING_PHONG** + +viz::Viz3d::setRepresentation +----------------------------- +Sets geometry representation of the widgets to surface, wireframe or points. + +.. ocv:function:: void setRepresentation(int representation) + + :param representation: Geometry representation which can be one of the following: + + * **REPRESENTATION_POINTS** + * **REPRESENTATION_WIREFRAME** + * **REPRESENTATION_SURFACE** + +viz::Color +---------- +.. ocv:class:: Color + +This class a represents BGR color. :: + + class CV_EXPORTS Color : public Scalar + { + public: + Color(); + Color(double gray); + Color(double blue, double green, double red); + + Color(const Scalar& color); + + static Color black(); + static Color blue(); + static Color green(); + static Color cyan(); + + static Color red(); + static Color magenta(); + static Color yellow(); + static Color white(); + + static Color gray(); + }; + +viz::Mesh +----------- +.. ocv:class:: Mesh + +This class wraps mesh attributes, and it can load a mesh from a ``ply`` file. :: + + class CV_EXPORTS Mesh + { + public: + + Mat cloud, colors, normals; + + //! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...) + //! where n is the number of points in the poligon, and id is a zero-offset index into an associated cloud. + Mat polygons; + + //! Loads mesh from a given ply file + static Mesh load(const String& file); + }; + +viz::Mesh::load +--------------------- +Loads a mesh from a ``ply`` file. + +.. ocv:function:: static Mesh load(const String& file) + + :param file: File name (for no only PLY is supported) + + +viz::KeyboardEvent +------------------ +.. ocv:class:: KeyboardEvent + +This class represents a keyboard event. :: + + class CV_EXPORTS KeyboardEvent + { + public: + enum { ALT = 1, CTRL = 2, SHIFT = 4 }; + enum Action { KEY_UP = 0, KEY_DOWN = 1 }; + + KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers); + + Action action; + String symbol; + unsigned char code; + int modifiers; + }; + +viz::KeyboardEvent::KeyboardEvent +--------------------------------- +Constructs a KeyboardEvent. + +.. ocv:function:: KeyboardEvent (Action action, const String& symbol, unsigned char code, Modifiers modifiers) + + :param action: Signals if key is pressed or released. + :param symbol: Name of the key. + :param code: Code of the key. + :param modifiers: Signals if ``alt``, ``ctrl`` or ``shift`` are pressed or their combination. + + +viz::MouseEvent +--------------- +.. ocv:class:: MouseEvent + +This class represents a mouse event. :: + + class CV_EXPORTS MouseEvent + { + public: + enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; + enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; + + MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers); + + Type type; + MouseButton button; + Point pointer; + int modifiers; + }; + +viz::MouseEvent::MouseEvent +--------------------------- +Constructs a MouseEvent. + +.. ocv:function:: MouseEvent (const Type& type, const MouseButton& button, const Point& p, Modifiers modifiers) + + :param type: Type of the event. This can be **MouseMove**, **MouseButtonPress**, **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**. + :param button: Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, **RightButton**, **VScroll**. + :param p: Position of the event. + :param modifiers: Signals if ``alt``, ``ctrl`` or ``shift`` are pressed or their combination. + +viz::Camera +----------- +.. ocv:class:: Camera + +This class wraps intrinsic parameters of a camera. It provides several constructors +that can extract the intrinsic parameters from ``field of view``, ``intrinsic matrix`` and +``projection matrix``. :: + + class CV_EXPORTS Camera + { + public: + Camera(double f_x, double f_y, double c_x, double c_y, const Size &window_size); + Camera(const Vec2d &fov, const Size &window_size); + Camera(const Matx33d &K, const Size &window_size); + Camera(const Matx44d &proj, const Size &window_size); + + inline const Vec2d & getClip() const; + inline void setClip(const Vec2d &clip); + + inline const Size & getWindowSize() const; + void setWindowSize(const Size &window_size); + + inline const Vec2d & getFov() const; + inline void setFov(const Vec2d & fov); + + inline const Vec2d & getPrincipalPoint() const; + inline const Vec2d & getFocalLength() const; + + void computeProjectionMatrix(Matx44d &proj) const; + + static Camera KinectCamera(const Size &window_size); + + private: + /* hidden */ + }; + +viz::Camera::Camera +------------------- +Constructs a Camera. + +.. ocv:function:: Camera(double f_x, double f_y, double c_x, double c_y, const Size &window_size) + + :param f_x: Horizontal focal length. + :param f_y: Vertical focal length. + :param c_x: x coordinate of the principal point. + :param c_y: y coordinate of the principal point. + :param window_size: Size of the window. This together with focal length and principal point determines the field of view. + +.. ocv:function:: Camera(const Vec2d &fov, const Size &window_size) + + :param fov: Field of view (horizontal, vertical) + :param window_size: Size of the window. + + Principal point is at the center of the window by default. + +.. ocv:function:: Camera(const Matx33d &K, const Size &window_size) + + :param K: Intrinsic matrix of the camera. + :param window_size: Size of the window. This together with intrinsic matrix determines the field of view. + +.. ocv:function:: Camera(const Matx44d &proj, const Size &window_size) + + :param proj: Projection matrix of the camera. + :param window_size: Size of the window. This together with projection matrix determines the field of view. + +viz::Camera::computeProjectionMatrix +------------------------------------ +Computes projection matrix using intrinsic parameters of the camera. + +.. ocv:function:: void computeProjectionMatrix(Matx44d &proj) const + + :param proj: Output projection matrix. + +viz::Camera::KinectCamera +------------------------- +Creates a Kinect Camera. + +.. ocv:function:: static Camera KinectCamera(const Size &window_size) + + :param window_size: Size of the window. This together with intrinsic matrix of a Kinect Camera determines the field of view. diff --git a/modules/viz/doc/widget.rst b/modules/viz/doc/widget.rst new file mode 100644 index 000000000..751838d75 --- /dev/null +++ b/modules/viz/doc/widget.rst @@ -0,0 +1,1087 @@ +Widget +====== + +.. highlight:: cpp + +In this section, the widget framework is explained. Widgets represent +2D or 3D objects, varying from simple ones such as lines to complex one such as +point clouds and meshes. + +Widgets are **implicitly shared**. Therefore, one can add a widget to the scene, +and modify the widget without re-adding the widget. + +.. code-block:: cpp + + ... + /// Create a cloud widget + viz::WCloud cw(cloud, viz::Color::red()); + /// Display it in a window + myWindow.showWidget("CloudWidget1", cw); + /// Modify it, and it will be modified in the window. + cw.setColor(viz::Color::yellow()); + ... + +viz::Widget +----------- +.. ocv:class:: Widget + +Base class of all widgets. Widget is implicitly shared. :: + + class CV_EXPORTS Widget + { + public: + Widget(); + Widget(const Widget& other); + Widget& operator=(const Widget& other); + ~Widget(); + + //! Create a widget directly from ply file + static Widget fromPlyFile(const String &file_name); + + //! Rendering properties of this particular widget + void setRenderingProperty(int property, double value); + double getRenderingProperty(int property) const; + + //! Casting between widgets + template _W cast(); + private: + /* hidden */ + }; + +viz::Widget::fromPlyFile +------------------------ +Creates a widget from ply file. + +.. ocv:function:: static Widget fromPlyFile(const String &file_name) + + :param file_name: Ply file name. + +viz::Widget::setRenderingProperty +--------------------------------- +Sets rendering property of the widget. + +.. ocv:function:: void setRenderingProperty(int property, double value) + + :param property: Property that will be modified. + :param value: The new value of the property. + + **Rendering property** can be one of the following: + + * **POINT_SIZE** + * **OPACITY** + * **LINE_WIDTH** + * **FONT_SIZE** + * **REPRESENTATION**: Expected values are + * **REPRESENTATION_POINTS** + * **REPRESENTATION_WIREFRAME** + * **REPRESENTATION_SURFACE** + * **IMMEDIATE_RENDERING**: + * Turn on immediate rendering by setting the value to ``1``. + * Turn off immediate rendering by setting the value to ``0``. + * **SHADING**: Expected values are + * **SHADING_FLAT** + * **SHADING_GOURAUD** + * **SHADING_PHONG** + +viz::Widget::getRenderingProperty +--------------------------------- +Returns rendering property of the widget. + +.. ocv:function:: double getRenderingProperty(int property) const + + :param property: Property. + + **Rendering property** can be one of the following: + + * **POINT_SIZE** + * **OPACITY** + * **LINE_WIDTH** + * **FONT_SIZE** + * **REPRESENTATION**: Expected values are + * **REPRESENTATION_POINTS** + * **REPRESENTATION_WIREFRAME** + * **REPRESENTATION_SURFACE** + * **IMMEDIATE_RENDERING**: + * Turn on immediate rendering by setting the value to ``1``. + * Turn off immediate rendering by setting the value to ``0``. + * **SHADING**: Expected values are + * **SHADING_FLAT** + * **SHADING_GOURAUD** + * **SHADING_PHONG** + +viz::Widget::cast +----------------- +Casts a widget to another. + +.. ocv:function:: template _W cast() + +.. code-block:: cpp + + // Create a sphere widget + viz::WSphere sw(Point3f(0.0f,0.0f,0.0f), 0.5f); + // Cast sphere widget to cloud widget + viz::WCloud cw = sw.cast(); + +.. note:: 3D Widgets can only be cast to 3D Widgets. 2D Widgets can only be cast to 2D Widgets. + +viz::WidgetAccessor +------------------- +.. ocv:class:: WidgetAccessor + +This class is for users who want to develop their own widgets using VTK library API. :: + + struct CV_EXPORTS WidgetAccessor + { + static vtkSmartPointer getProp(const Widget &widget); + static void setProp(Widget &widget, vtkSmartPointer prop); + }; + +viz::WidgetAccessor::getProp +---------------------------- +Returns ``vtkProp`` of a given widget. + +.. ocv:function:: static vtkSmartPointer getProp(const Widget &widget) + + :param widget: Widget whose ``vtkProp`` is to be returned. + +.. note:: vtkProp has to be down cast appropriately to be modified. + + .. code-block:: cpp + + vtkActor * actor = vtkActor::SafeDownCast(viz::WidgetAccessor::getProp(widget)); + +viz::WidgetAccessor::setProp +---------------------------- +Sets ``vtkProp`` of a given widget. + +.. ocv:function:: static void setProp(Widget &widget, vtkSmartPointer prop) + + :param widget: Widget whose ``vtkProp`` is to be set. + :param prop: A ``vtkProp``. + +viz::Widget3D +------------- +.. ocv:class:: Widget3D + +Base class of all 3D widgets. :: + + class CV_EXPORTS Widget3D : public Widget + { + public: + Widget3D() {} + + //! widget position manipulation, i.e. place where it is rendered. + void setPose(const Affine3d &pose); + void updatePose(const Affine3d &pose); + Affine3d getPose() const; + + //! updates internal widget data, i.e. points, normals, etc. + void applyTransform(const Affine3d &transform); + + void setColor(const Color &color); + + }; + +viz::Widget3D::setPose +---------------------- +Sets pose of the widget. + +.. ocv:function:: void setPose(const Affine3d &pose) + + :param pose: The new pose of the widget. + +viz::Widget3D::updateWidgetPose +------------------------------- +Updates pose of the widget by pre-multiplying its current pose. + +.. ocv:function:: void updateWidgetPose(const Affine3d &pose) + + :param pose: The pose that the current pose of the widget will be pre-multiplied by. + +viz::Widget3D::getPose +---------------------- +Returns the current pose of the widget. + +.. ocv:function:: Affine3d getWidgetPose() const + + +viz::Widget3D::applyTransform +------------------------------- +Transforms internal widget data (i.e. points, normals) using the given transform. + +.. ocv:function:: void applyTransform(const Affine3d &transform) + + :param transform: Specified transformation to apply. + +viz::Widget3D::setColor +----------------------- +Sets the color of the widget. + +.. ocv:function:: void setColor(const Color &color) + + :param color: color of type :ocv:class:`Color` + +viz::Widget2D +------------- +.. ocv:class:: Widget2D + +Base class of all 2D widgets. :: + + class CV_EXPORTS Widget2D : public Widget + { + public: + Widget2D() {} + + void setColor(const Color &color); + }; + +viz::Widget2D::setColor +----------------------- +Sets the color of the widget. + +.. ocv:function:: void setColor(const Color &color) + + :param color: color of type :ocv:class:`Color` + +viz::WLine +---------- +.. ocv:class:: WLine + +This 3D Widget defines a finite line. :: + + class CV_EXPORTS WLine : public Widget3D + { + public: + WLine(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); + }; + +viz::WLine::WLine +----------------- +Constructs a WLine. + +.. ocv:function:: WLine(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()) + + :param pt1: Start point of the line. + :param pt2: End point of the line. + :param color: :ocv:class:`Color` of the line. + +viz::WPlane +----------- +.. ocv:class:: WPlane + +This 3D Widget defines a finite plane. :: + + class CV_EXPORTS WPlane : public Widget3D + { + public: + //! created default plane with center point at origin and normal oriented along z-axis + WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + + //! repositioned plane + WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_plane_yaxis,const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + }; + +viz::WPlane::WPlane +------------------- +Constructs a default plane with center point at origin and normal oriented along z-axis. + +.. ocv:function:: WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()) + + :param size: Size of the plane + :param color: :ocv:class:`Color` of the plane. + +viz::WPlane::WPlane +------------------- +Constructs a repositioned plane + +.. ocv:function:: WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis,const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()) + + :param center: Center of the plane + :param normal: Plane normal orientation + :param new_yaxis: Up-vector. New orientation of plane y-axis. + :param color: :ocv:class:`Color` of the plane. + +viz::WSphere +------------ +.. ocv:class:: WSphere + +This 3D Widget defines a sphere. :: + + class CV_EXPORTS WSphere : public Widget3D + { + public: + WSphere(const cv::Point3f ¢er, double radius, int sphere_resolution = 10, const Color &color = Color::white()) + }; + +viz::WSphere::WSphere +--------------------- +Constructs a WSphere. + +.. ocv:function:: WSphere(const cv::Point3f ¢er, double radius, int sphere_resolution = 10, const Color &color = Color::white()) + + :param center: Center of the sphere. + :param radius: Radius of the sphere. + :param sphere_resolution: Resolution of the sphere. + :param color: :ocv:class:`Color` of the sphere. + +viz::WArrow +---------------- +.. ocv:class:: WArrow + +This 3D Widget defines an arrow. :: + + class CV_EXPORTS WArrow : public Widget3D + { + public: + WArrow(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()); + }; + +viz::WArrow::WArrow +----------------------------- +Constructs an WArrow. + +.. ocv:function:: WArrow(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()) + + :param pt1: Start point of the arrow. + :param pt2: End point of the arrow. + :param thickness: Thickness of the arrow. Thickness of arrow head is also adjusted accordingly. + :param color: :ocv:class:`Color` of the arrow. + +Arrow head is located at the end point of the arrow. + +viz::WCircle +----------------- +.. ocv:class:: WCircle + +This 3D Widget defines a circle. :: + + class CV_EXPORTS WCircle : public Widget3D + { + public: + //! creates default planar circle centred at origin with plane normal along z-axis + WCircle(double radius, double thickness = 0.01, const Color &color = Color::white()); + + //! creates repositioned circle + WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white()); + }; + +viz::WCircle::WCircle +------------------------------- +Constructs default planar circle centred at origin with plane normal along z-axis + +.. ocv:function:: WCircle(double radius, double thickness = 0.01, const Color &color = Color::white()) + + :param radius: Radius of the circle. + :param thickness: Thickness of the circle. + :param color: :ocv:class:`Color` of the circle. + +viz::WCircle::WCircle +------------------------------- +Constructs repositioned planar circle. + +.. ocv:function:: WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white()) + + :param radius: Radius of the circle. + :param center: Center of the circle. + :param normal: Normal of the plane in which the circle lies. + :param thickness: Thickness of the circle. + :param color: :ocv:class:`Color` of the circle. + +viz::WCone +------------------------------- +.. ocv:class:: WCone + +This 3D Widget defines a cone. :: + + class CV_EXPORTS WCone : public Widget3D + { + public: + //! create default cone, oriented along x-axis with center of its base located at origin + WCone(double length, double radius, int resolution = 6.0, const Color &color = Color::white()); + + //! creates repositioned cone + WCone(double radius, const Point3d& center, const Point3d& tip, int resolution = 6.0, const Color &color = Color::white()); + }; + +viz::WCone::WCone +------------------------------- +Constructs default cone oriented along x-axis with center of its base located at origin + +.. ocv:function:: WCone(double length, double radius, int resolution = 6.0, const Color &color = Color::white()) + + :param length: Length of the cone. + :param radius: Radius of the cone. + :param resolution: Resolution of the cone. + :param color: :ocv:class:`Color` of the cone. + +viz::WCone::WCone +------------------------------- +Constructs repositioned planar cone. + +.. ocv:function:: WCone(double radius, const Point3d& center, const Point3d& tip, int resolution = 6.0, const Color &color = Color::white()) + + :param radius: Radius of the cone. + :param center: Center of the cone base. + :param tip: Tip of the cone. + :param resolution: Resolution of the cone. + :param color: :ocv:class:`Color` of the cone. + +viz::WCylinder +-------------- +.. ocv:class:: WCylinder + +This 3D Widget defines a cylinder. :: + + class CV_EXPORTS WCylinder : public Widget3D + { + public: + WCylinder(const Point3d& axis_point1, const Point3d& axis_point2, double radius, int numsides = 30, const Color &color = Color::white()); + }; + +viz::WCylinder::WCylinder +----------------------------------- +Constructs a WCylinder. + +.. ocv:function:: WCylinder(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()) + + :param axis_point1: A point1 on the axis of the cylinder. + :param axis_point2: A point2 on the axis of the cylinder. + :param radius: Radius of the cylinder. + :param numsides: Resolution of the cylinder. + :param color: :ocv:class:`Color` of the cylinder. + +viz::WCube +---------- +.. ocv:class:: WCube + +This 3D Widget defines a cube. :: + + class CV_EXPORTS WCube : public Widget3D + { + public: + WCube(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); + }; + +viz::WCube::WCube +--------------------------- +Constructs a WCube. + +.. ocv:function:: WCube(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()) + + :param pt_min: Specifies minimum point of the bounding box. + :param pt_max: Specifies maximum point of the bounding box. + :param wire_frame: If true, cube is represented as wireframe. + :param color: :ocv:class:`Color` of the cube. + +.. image:: images/cube_widget.png + :alt: Cube Widget + :align: center + +viz::WCoordinateSystem +---------------------- +.. ocv:class:: WCoordinateSystem + +This 3D Widget represents a coordinate system. :: + + class CV_EXPORTS WCoordinateSystem : public Widget3D + { + public: + WCoordinateSystem(double scale = 1.0); + }; + +viz::WCoordinateSystem::WCoordinateSystem +--------------------------------------------------- +Constructs a WCoordinateSystem. + +.. ocv:function:: WCoordinateSystem(double scale = 1.0) + + :param scale: Determines the size of the axes. + +viz::WPolyLine +-------------- +.. ocv:class:: WPolyLine + +This 3D Widget defines a poly line. :: + + class CV_EXPORTS WPolyLine : public Widget3D + { + public: + WPolyLine(InputArray points, const Color &color = Color::white()); + }; + +viz::WPolyLine::WPolyLine +----------------------------------- +Constructs a WPolyLine. + +.. ocv:function:: WPolyLine(InputArray points, const Color &color = Color::white()) + + :param points: Point set. + :param color: :ocv:class:`Color` of the poly line. + +viz::WGrid +---------- +.. ocv:class:: WGrid + +This 3D Widget defines a grid. :: + + class CV_EXPORTS WGrid : public Widget3D + { + public: + //! Creates grid at the origin and normal oriented along z-axis + WGrid(const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); + + //! Creates repositioned grid + WGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, + const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); + }; + +viz::WGrid::WGrid +--------------------------- +Constructs a WGrid. + +.. ocv:function:: WGrid(const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()) + + :param cells: Number of cell columns and rows, respectively. + :param cells_spacing: Size of each cell, respectively. + :param color: :ocv:class:`Color` of the grid. + +.. ocv:function: WGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, Vec2i &cells, const Vec2d &cells_spacing, const Color &color; + + :param center: Center of the grid + :param normal: Grid normal orientation + :param new_yaxis: Up-vector. New orientation of grid y-axis. + :param cells: Number of cell columns and rows, respectively. + :param cells_spacing: Size of each cell, respectively. + :param color: :ocv:class:`Color` of the grid.. + +viz::WText3D +------------ +.. ocv:class:: WText3D + +This 3D Widget represents 3D text. The text always faces the camera. :: + + class CV_EXPORTS WText3D : public Widget3D + { + public: + WText3D(const String &text, const Point3f &position, double text_scale = 1.0, bool face_camera = true, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + +viz::WText3D::WText3D +------------------------------- +Constructs a WText3D. + +.. ocv:function:: WText3D(const String &text, const Point3f &position, double text_scale = 1.0, bool face_camera = true, const Color &color = Color::white()) + + :param text: Text content of the widget. + :param position: Position of the text. + :param text_scale: Size of the text. + :param face_camera: If true, text always faces the camera. + :param color: :ocv:class:`Color` of the text. + +viz::WText3D::setText +--------------------- +Sets the text content of the widget. + +.. ocv:function:: void setText(const String &text) + + :param text: Text content of the widget. + +viz::WText3D::getText +--------------------- +Returns the current text content of the widget. + +.. ocv:function:: String getText() const + +viz::WText +---------- +.. ocv:class:: WText + +This 2D Widget represents text overlay. :: + + class CV_EXPORTS WText : public Widget2D + { + public: + WText(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + +viz::WText::WText +----------------- +Constructs a WText. + +.. ocv:function:: WText(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()) + + :param text: Text content of the widget. + :param pos: Position of the text. + :param font_size: Font size. + :param color: :ocv:class:`Color` of the text. + +viz::WText::setText +------------------- +Sets the text content of the widget. + +.. ocv:function:: void setText(const String &text) + + :param text: Text content of the widget. + +viz::WText::getText +------------------- +Returns the current text content of the widget. + +.. ocv:function:: String getText() const + +viz::WImageOverlay +------------------ +.. ocv:class:: WImageOverlay + +This 2D Widget represents an image overlay. :: + + class CV_EXPORTS WImageOverlay : public Widget2D + { + public: + WImageOverlay(InputArray image, const Rect &rect); + + void setImage(InputArray image); + }; + +viz::WImageOverlay::WImageOverlay +--------------------------------- +Constructs an WImageOverlay. + +.. ocv:function:: WImageOverlay(InputArray image, const Rect &rect) + + :param image: BGR or Gray-Scale image. + :param rect: Image is scaled and positioned based on rect. + +viz::WImageOverlay::setImage +---------------------------- +Sets the image content of the widget. + +.. ocv:function:: void setImage(InputArray image) + + :param image: BGR or Gray-Scale image. + +viz::WImage3D +------------- +.. ocv:class:: WImage3D + +This 3D Widget represents an image in 3D space. :: + + class CV_EXPORTS WImage3D : public Widget3D + { + public: + //! Creates 3D image at the origin + WImage3D(InputArray image, const Size2d &size); + //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation + WImage3D(InputArray image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector); + + void setImage(InputArray image); + }; + +viz::WImage3D::WImage3D +----------------------- +Constructs an WImage3D. + +.. ocv:function:: WImage3D(InputArray image, const Size2d &size) + + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + +.. ocv:function:: WImage3D(InputArray image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector) + + :param position: Position of the image. + :param normal: Normal of the plane that represents the image. + :param up_vector: Determines orientation of the image. + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + +viz::WImage3D::setImage +----------------------- +Sets the image content of the widget. + +.. ocv:function:: void setImage(InputArray image) + + :param image: BGR or Gray-Scale image. + +viz::WCameraPosition +-------------------- +.. ocv:class:: WCameraPosition + +This 3D Widget represents camera position in a scene by its axes or viewing frustum. :: + + class CV_EXPORTS WCameraPosition : public Widget3D + { + public: + //! Creates camera coordinate frame (axes) at the origin + WCameraPosition(double scale = 1.0); + //! Creates frustum based on the intrinsic marix K at the origin + WCameraPosition(const Matx33d &K, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum based on the field of view at the origin + WCameraPosition(const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + WCameraPosition(const Matx33d &K, InputArray image, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + WCameraPosition(const Vec2d &fov, InputArray image, double scale = 1.0, const Color &color = Color::white()); + }; + +viz::WCameraPosition::WCameraPosition +------------------------------------- +Constructs a WCameraPosition. + +- **Display camera coordinate frame.** + + .. ocv:function:: WCameraPosition(double scale = 1.0) + + Creates camera coordinate frame at the origin. + + .. image:: images/cpw1.png + :alt: Camera coordinate frame + :align: center + +- **Display the viewing frustum.** + + .. ocv:function:: WCameraPosition(const Matx33d &K, double scale = 1.0, const Color &color = Color::white()) + + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustum. + :param color: :ocv:class:`Color` of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K. + + .. ocv:function:: WCameraPosition(const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()) + + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustum. + :param color: :ocv:class:`Color` of the frustum. + + Creates viewing frustum of the camera based on its field of view fov. + + .. image:: images/cpw2.png + :alt: Camera viewing frustum + :align: center + +- **Display image on the far plane of the viewing frustum.** + + .. ocv:function:: WCameraPosition(const Matx33d &K, InputArray image, double scale = 1.0, const Color &color = Color::white()) + + :param K: Intrinsic matrix of the camera. + :param img: BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum. + :param scale: Scale of the frustum and image. + :param color: :ocv:class:`Color` of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane. + + .. ocv:function:: WCameraPosition(const Vec2d &fov, InputArray image, double scale = 1.0, const Color &color = Color::white()) + + :param fov: Field of view of the camera (horizontal, vertical). + :param img: BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum. + :param scale: Scale of the frustum and image. + :param color: :ocv:class:`Color` of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane. + + .. image:: images/cpw3.png + :alt: Camera viewing frustum with image + :align: center + +viz::WTrajectory +---------------- +.. ocv:class:: WTrajectory + +This 3D Widget represents a trajectory. :: + + class CV_EXPORTS WTrajectory : public Widget3D + { + public: + enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH}; + + //! Displays trajectory of the given path either by coordinate frames or polyline + WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.0, const Color &color = Color::white(),; + }; + +viz::WTrajectory::WTrajectory +----------------------------- +Constructs a WTrajectory. + +.. ocv:function:: WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.0, const Color &color = Color::white()) + + :param path: List of poses on a trajectory. Takes std::vector> with T == [float | double] + :param display_mode: Display mode. This can be PATH, FRAMES, and BOTH. + :param scale: Scale of the frames. Polyline is not affected. + :param color: :ocv:class:`Color` of the polyline that represents path. Frames are not affected. + + Displays trajectory of the given path as follows: + + * PATH : Displays a poly line that represents the path. + * FRAMES : Displays coordinate frames at each pose. + * PATH & FRAMES : Displays both poly line and coordinate frames. + +viz::WTrajectoryFrustums +------------------------ +.. ocv:class:: WTrajectoryFrustums + +This 3D Widget represents a trajectory. :: + + class CV_EXPORTS WTrajectoryFrustums : public Widget3D + { + public: + //! Displays trajectory of the given path by frustums + WTrajectoryFrustums(InputArray path, const Matx33d &K, double scale = 1.0, const Color &color = Color::white()); + //! Displays trajectory of the given path by frustums + WTrajectoryFrustums(InputArray path, const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()); + }; + +viz::WTrajectoryFrustums::WTrajectoryFrustums +--------------------------------------------- +Constructs a WTrajectoryFrustums. + +.. ocv:function:: WTrajectoryFrustums(const std::vector &path, const Matx33d &K, double scale = 1.0, const Color &color = Color::white()) + + :param path: List of poses on a trajectory. Takes std::vector> with T == [float | double] + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustums. + :param color: :ocv:class:`Color` of the frustums. + + Displays frustums at each pose of the trajectory. + +.. ocv:function:: WTrajectoryFrustums(const std::vector &path, const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()) + + :param path: List of poses on a trajectory. Takes std::vector> with T == [float | double] + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustums. + :param color: :ocv:class:`Color` of the frustums. + + Displays frustums at each pose of the trajectory. + +viz::WTrajectorySpheres +----------------------- +.. ocv:class:: WTrajectorySpheres + +This 3D Widget represents a trajectory using spheres and lines, where spheres represent the positions of the camera, and lines +represent the direction from previous position to the current. :: + + class CV_EXPORTS WTrajectorySpheres : public Widget3D + { + public: + WTrajectorySpheres(InputArray path, double line_length = 0.05, double radius = 0.007, + const Color &from = Color::red(), const Color &to = Color::white()); + }; + +viz::WTrajectorySpheres::WTrajectorySpheres +------------------------------------------- +Constructs a WTrajectorySpheres. + +.. ocv:function:: WTrajectorySpheres(InputArray path, double line_length = 0.05, double radius = 0.007, const Color &from = Color::red(), const Color &to = Color::white()) + + :param path: List of poses on a trajectory. Takes std::vector> with T == [float | double] + :param line_length: Max length of the lines which point to previous position + :param sphere_radius: Radius of the spheres. + :param from: :ocv:class:`Color` for first sphere. + :param to: :ocv:class:`Color` for last sphere. Intermediate spheres will have interpolated color. + +viz::WCloud +----------- +.. ocv:class:: WCloud + +This 3D Widget defines a point cloud. :: + + class CV_EXPORTS WCloud : public Widget3D + { + public: + //! Each point in cloud is mapped to a color in colors + WCloud(InputArray cloud, InputArray colors); + //! All points in cloud have the same color + WCloud(InputArray cloud, const Color &color = Color::white()); + //! Each point in cloud is mapped to a color in colors, normals are used for shading + WCloud(InputArray cloud, InputArray colors, InputArray normals); + //! All points in cloud have the same color, normals are used for shading + WCloud(InputArray cloud, const Color &color, InputArray normals); + }; + +viz::WCloud::WCloud +------------------- +Constructs a WCloud. + +.. ocv:function:: WCloud(InputArray cloud, InputArray colors) + + :param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param colors: Set of colors. It has to be of the same size with cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: WCloud(InputArray cloud, const Color &color = Color::white()) + + :param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param color: A single :ocv:class:`Color` for the whole cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: WCloud(InputArray cloud, InputArray colors, InputArray normals) + + :param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param colors: Set of colors. It has to be of the same size with cloud. + :param normals: Normals for each point in cloud. Size and type should match with the cloud parameter. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: WCloud(InputArray cloud, const Color &color, InputArray normals) + + :param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param color: A single :ocv:class:`Color` for the whole cloud. + :param normals: Normals for each point in cloud. Size and type should match with the cloud parameter. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. note:: In case there are four channels in the cloud, fourth channel is ignored. + +viz::WCloudCollection +--------------------- +.. ocv:class:: WCloudCollection + +This 3D Widget defines a collection of clouds. :: + + class CV_EXPORTS WCloudCollection : public Widget3D + { + public: + WCloudCollection(); + + //! Each point in cloud is mapped to a color in colors + void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()); + //! All points in cloud have the same color + void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3d &pose = Affine3d::Identity()); + //! Repacks internal structure to single cloud + void finalize(); + }; + +viz::WCloudCollection::WCloudCollection +--------------------------------------- +Constructs a WCloudCollection. + +.. ocv:function:: WCloudCollection() + +viz::WCloudCollection::addCloud +------------------------------- +Adds a cloud to the collection. + +.. ocv:function:: void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()) + + :param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param colors: Set of colors. It has to be of the same size with cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3d &pose = Affine3d::Identity()) + + :param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param colors: A single :ocv:class:`Color` for the whole cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. note:: In case there are four channels in the cloud, fourth channel is ignored. + +viz::WCloudCollection::finalize +------------------------------- +Finalizes cloud data by repacking to single cloud. Useful for large cloud collections to reduce memory usage + +.. ocv:function:: void finalize() + +viz::WCloudNormals +------------------ +.. ocv:class:: WCloudNormals + +This 3D Widget represents normals of a point cloud. :: + + class CV_EXPORTS WCloudNormals : public Widget3D + { + public: + WCloudNormals(InputArray cloud, InputArray normals, int level = 100, double scale = 0.02f, const Color &color = Color::white()); + }; + +viz::WCloudNormals::WCloudNormals +--------------------------------- +Constructs a WCloudNormals. + +.. ocv:function:: WCloudNormals(InputArray cloud, InputArray normals, int level = 100, double scale = 0.02f, const Color &color = Color::white()) + + :param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``. + :param normals: A set of normals that has to be of same type with cloud. + :param level: Display only every ``level`` th normal. + :param scale: Scale of the arrows that represent normals. + :param color: :ocv:class:`Color` of the arrows that represent normals. + +.. note:: In case there are four channels in the cloud, fourth channel is ignored. + +viz::WMesh +---------- +.. ocv:class:: WMesh + +This 3D Widget defines a mesh. :: + + class CV_EXPORTS WMesh : public Widget3D + { + public: + WMesh(const Mesh &mesh); + WMesh(InputArray cloud, InputArray polygons, InputArray colors = noArray(), InputArray normals = noArray()); + }; + +viz::WMesh::WMesh +----------------- +Constructs a WMesh. + +.. ocv:function:: WMesh(const Mesh &mesh) + + :param mesh: :ocv:class:`Mesh` object that will be displayed. + +.. ocv:function:: WMesh(InputArray cloud, InputArray polygons, InputArray colors = noArray(), InputArray normals = noArray()) + + :param cloud: Points of the mesh object. + :param polygons: Points of the mesh object. + :param colors: Point colors. + :param normals: Point normals. + +viz::WWidgetMerger +--------------------- +.. ocv:class:: WWidgetMerger + +This class allows to merge several widgets to single one. It has quite limited functionality and can't merge widgets with different attributes. For instance, +if widgetA has color array and widgetB has only global color defined, then result of merge won't have color at all. The class is suitable for merging large amount of similar widgets. :: + + class CV_EXPORTS WWidgetMerger : public Widget3D + { + public: + WWidgetMerger(); + + //! Add widget to merge with optional position change + void addWidget(const Widget3D& widget, const Affine3d &pose = Affine3d::Identity()); + + //! Repacks internal structure to single widget + void finalize(); + }; + +viz::WWidgetMerger::WWidgetMerger +--------------------------------------- +Constructs a WWidgetMerger. + +.. ocv:function:: WWidgetMerger() + +viz::WWidgetMerger::addCloud +------------------------------- +Adds a cloud to the collection. + +.. ocv:function:: void addWidget(const Widget3D& widget, const Affine3d &pose = Affine3d::Identity()) + + :param widget: Widget to merge. + :param pose: Pose of the widget. + +viz::WWidgetMerger::finalize +------------------------------- +Finalizes merger data and constructs final merged widget + +.. ocv:function:: void finalize() diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp new file mode 100644 index 000000000..3e8e87c65 --- /dev/null +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -0,0 +1,240 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_TYPES_HPP__ +#define __OPENCV_VIZ_TYPES_HPP__ + +#include +#include +#include + +namespace cv +{ + namespace viz + { + class Color : public Scalar + { + public: + Color(); + Color(double gray); + Color(double blue, double green, double red); + + Color(const Scalar& color); + + operator Vec3b() const; + + static Color black(); + static Color blue(); + static Color green(); + static Color cyan(); + + static Color red(); + static Color magenta(); + static Color yellow(); + static Color white(); + + static Color gray(); + + static Color mlab(); + + static Color navy(); + static Color olive(); + static Color maroon(); + static Color teal(); + static Color rose(); + static Color azure(); + static Color lime(); + static Color gold(); + static Color brown(); + static Color orange(); + static Color chartreuse(); + static Color orange_red(); + static Color purple(); + static Color indigo(); + + static Color pink(); + static Color cherry(); + static Color bluberry(); + static Color raspberry(); + static Color silver(); + static Color violet(); + static Color apricot(); + static Color turquoise(); + static Color celestial_blue(); + static Color amethyst(); + + static Color not_set(); + }; + + class CV_EXPORTS Mesh + { + public: + Mat cloud, colors, normals; + + //! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...) + //! where n is the number of points in the poligon, and id is a zero-offset index into an associated cloud. + Mat polygons; + + Mat texture, tcoords; + + //! Loads mesh from a given ply file (no texture load support for now) + static Mesh load(const String& file); + }; + + class CV_EXPORTS Camera + { + public: + Camera(double fx, double fy, double cx, double cy, const Size &window_size); + explicit Camera(const Vec2d &fov, const Size &window_size); + explicit Camera(const Matx33d &K, const Size &window_size); + explicit Camera(const Matx44d &proj, const Size &window_size); + + const Vec2d & getClip() const { return clip_; } + void setClip(const Vec2d &clip) { clip_ = clip; } + + const Size & getWindowSize() const { return window_size_; } + void setWindowSize(const Size &window_size); + + const Vec2d& getFov() const { return fov_; } + void setFov(const Vec2d& fov) { fov_ = fov; } + + const Vec2d& getPrincipalPoint() const { return principal_point_; } + const Vec2d& getFocalLength() const { return focal_; } + + void computeProjectionMatrix(Matx44d &proj) const; + + static Camera KinectCamera(const Size &window_size); + + private: + void init(double fx, double fy, double cx, double cy, const Size &window_size); + + Vec2d clip_; + Vec2d fov_; + Size window_size_; + Vec2d principal_point_; + Vec2d focal_; + }; + + class CV_EXPORTS KeyboardEvent + { + public: + enum { NONE = 0, ALT = 1, CTRL = 2, SHIFT = 4 }; + enum Action { KEY_UP = 0, KEY_DOWN = 1 }; + + KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers); + + Action action; + String symbol; + unsigned char code; + int modifiers; + }; + + class CV_EXPORTS MouseEvent + { + public: + enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; + enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; + + MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers); + + Type type; + MouseButton button; + Point pointer; + int modifiers; + }; + } /* namespace viz */ +} /* namespace cv */ + +////////////////////////////////////////////////////////////////////////////////////////////////////// +/// cv::viz::Color + +inline cv::viz::Color::Color() : Scalar(0, 0, 0) {} +inline cv::viz::Color::Color(double _gray) : Scalar(_gray, _gray, _gray) {} +inline cv::viz::Color::Color(double _blue, double _green, double _red) : Scalar(_blue, _green, _red) {} +inline cv::viz::Color::Color(const Scalar& color) : Scalar(color) {} + +inline cv::viz::Color::operator cv::Vec3b() const { return cv::Vec3d(val); } + +inline cv::viz::Color cv::viz::Color::black() { return Color( 0, 0, 0); } +inline cv::viz::Color cv::viz::Color::green() { return Color( 0, 255, 0); } +inline cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } +inline cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } +inline cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } +inline cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); } +inline cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); } +inline cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } +inline cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } + +inline cv::viz::Color cv::viz::Color::mlab() { return Color(255, 128, 128); } + +inline cv::viz::Color cv::viz::Color::navy() { return Color(0, 0, 128); } +inline cv::viz::Color cv::viz::Color::olive() { return Color(0, 128, 128); } +inline cv::viz::Color cv::viz::Color::maroon() { return Color(0, 0, 128); } +inline cv::viz::Color cv::viz::Color::teal() { return Color(128, 128, 0); } +inline cv::viz::Color cv::viz::Color::rose() { return Color(128, 0, 255); } +inline cv::viz::Color cv::viz::Color::azure() { return Color(255, 128, 0); } +inline cv::viz::Color cv::viz::Color::lime() { return Color(0, 255, 191); } +inline cv::viz::Color cv::viz::Color::gold() { return Color(0, 215, 255); } +inline cv::viz::Color cv::viz::Color::brown() { return Color(0, 75, 150); } +inline cv::viz::Color cv::viz::Color::orange() { return Color(0, 165, 255); } +inline cv::viz::Color cv::viz::Color::chartreuse() { return Color(0, 255, 128); } +inline cv::viz::Color cv::viz::Color::orange_red() { return Color(0, 69, 255); } +inline cv::viz::Color cv::viz::Color::purple() { return Color(128, 0, 128); } +inline cv::viz::Color cv::viz::Color::indigo() { return Color(130, 0, 75); } + +inline cv::viz::Color cv::viz::Color::pink() { return Color(203, 192, 255); } +inline cv::viz::Color cv::viz::Color::cherry() { return Color( 99, 29, 222); } +inline cv::viz::Color cv::viz::Color::bluberry() { return Color(247, 134, 79); } +inline cv::viz::Color cv::viz::Color::raspberry() { return Color( 92, 11, 227); } +inline cv::viz::Color cv::viz::Color::silver() { return Color(192, 192, 192); } +inline cv::viz::Color cv::viz::Color::violet() { return Color(226, 43, 138); } +inline cv::viz::Color cv::viz::Color::apricot() { return Color(177, 206, 251); } +inline cv::viz::Color cv::viz::Color::turquoise() { return Color(208, 224, 64); } +inline cv::viz::Color cv::viz::Color::celestial_blue() { return Color(208, 151, 73); } +inline cv::viz::Color cv::viz::Color::amethyst() { return Color(204, 102, 153); } + +inline cv::viz::Color cv::viz::Color::not_set() { return Color(-1, -1, -1); } + +#endif diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp new file mode 100644 index 000000000..1be748c8c --- /dev/null +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -0,0 +1,133 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_VIZ3D_HPP__ +#define __OPENCV_VIZ_VIZ3D_HPP__ + +#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED && !defined CVAPI_EXPORTS + //#error "Viz is in beta state now. Please define macro above to use it" +#endif + +#include +#include +#include + +namespace cv +{ + namespace viz + { + class CV_EXPORTS Viz3d + { + public: + typedef cv::viz::Color Color; + typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); + typedef void (*MouseCallback)(const MouseEvent&, void*); + + Viz3d(const String& window_name = String()); + Viz3d(const Viz3d&); + Viz3d& operator=(const Viz3d&); + ~Viz3d(); + + void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; + void removeAllWidgets(); + + void showImage(InputArray image, const Size& window_size = Size(-1, -1)); + + void setWidgetPose(const String &id, const Affine3d &pose); + void updateWidgetPose(const String &id, const Affine3d &pose); + Affine3d getWidgetPose(const String &id) const; + + void setCamera(const Camera &camera); + Camera getCamera() const; + Affine3d getViewerPose(); + void setViewerPose(const Affine3d &pose); + + void resetCameraViewpoint(const String &id); + void resetCamera(); + + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); + void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); + + Size getWindowSize() const; + void setWindowSize(const Size &window_size); + String getWindowName() const; + void saveScreenshot(const String &file); + void setWindowPosition(const Point& window_position); + void setFullScreen(bool mode = true); + void setBackgroundColor(const Color& color = Color::black(), const Color& color2 = Color::not_set()); + void setBackgroundTexture(InputArray image = noArray()); + void setBackgroundMeshLab(); + + void spin(); + void spinOnce(int time = 1, bool force_redraw = false); + bool wasStopped() const; + void close(); + + void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); + void registerMouseCallback(MouseCallback callback, void* cookie = 0); + + void setRenderingProperty(const String &id, int property, double value); + double getRenderingProperty(const String &id, int property); + + void setRepresentation(int representation); + + void setGlobalWarnings(bool enabled = false); + private: + + struct VizImpl; + VizImpl* impl_; + + void create(const String &window_name); + void release(); + + friend class VizStorage; + }; + + } /* namespace viz */ +} /* namespace cv */ + +#endif diff --git a/modules/viz/include/opencv2/viz/vizcore.hpp b/modules/viz/include/opencv2/viz/vizcore.hpp new file mode 100644 index 000000000..0fde95b2f --- /dev/null +++ b/modules/viz/include/opencv2/viz/vizcore.hpp @@ -0,0 +1,127 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZCORE_HPP__ +#define __OPENCV_VIZCORE_HPP__ + +#include +#include +#include + +namespace cv +{ + namespace viz + { + //! takes coordiante frame data and builds transfrom to global coordinate frame + CV_EXPORTS Affine3d makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin = Vec3d::all(0)); + + //! constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation) + CV_EXPORTS Affine3d makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir); + + //! retrieves a window by its name. If no window with such name, then it creates new. + CV_EXPORTS Viz3d getWindowByName(const String &window_name); + + //! Unregisters all Viz windows from internal database. After it 'getWindowByName()' will create new windows instead getting existing from the database. + CV_EXPORTS void unregisterAllWindows(); + + //! Displays image in specified window + CV_EXPORTS Viz3d imshow(const String& window_name, InputArray image, const Size& window_size = Size(-1, -1)); + + //! checks float value for Nan + inline bool isNan(float x) + { + unsigned int *u = reinterpret_cast(&x); + return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff); + } + + //! checks double value for Nan + inline bool isNan(double x) + { + unsigned int *u = reinterpret_cast(&x); + return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0); + } + + //! checks vectors for Nans + template inline bool isNan(const Vec<_Tp, cn>& v) + { return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); } + + //! checks point for Nans + template inline bool isNan(const Point3_<_Tp>& p) + { return isNan(p.x) || isNan(p.y) || isNan(p.z); } + + + /////////////////////////////////////////////////////////////////////////////////////////////// + /// Read/write clouds. Supported formats: ply, xyz, obj and stl (readonly) + + CV_EXPORTS void writeCloud(const String& file, InputArray cloud, InputArray colors = noArray(), InputArray normals = noArray(), bool binary = false); + CV_EXPORTS Mat readCloud (const String& file, OutputArray colors = noArray(), OutputArray normals = noArray()); + + /////////////////////////////////////////////////////////////////////////////////////////////// + /// Reads mesh. Only ply format is supported now and no texture load support + + CV_EXPORTS Mesh readMesh(const String& file); + + /////////////////////////////////////////////////////////////////////////////////////////////// + /// Read/write poses and trajectories + + CV_EXPORTS bool readPose(const String& file, Affine3d& pose, const String& tag = "pose"); + CV_EXPORTS void writePose(const String& file, const Affine3d& pose, const String& tag = "pose"); + + //! takes vector> with T = float/dobule and writes to a sequence of files with given filename format + CV_EXPORTS void writeTrajectory(InputArray traj, const String& files_format = "pose%05d.xml", int start = 0, const String& tag = "pose"); + + //! takes vector> with T = float/dobule and loads poses from sequence of files + CV_EXPORTS void readTrajectory(OutputArray traj, const String& files_format = "pose%05d.xml", int start = 0, int end = INT_MAX, const String& tag = "pose"); + + + /////////////////////////////////////////////////////////////////////////////////////////////// + /// Computing normals for mesh + + CV_EXPORTS void computeNormals(const Mesh& mesh, OutputArray normals); + + } /* namespace viz */ +} /* namespace cv */ + +#endif /* __OPENCV_VIZCORE_HPP__ */ diff --git a/modules/ocl/src/opencl/arithm_bitwise_binary_scalar.cl b/modules/viz/include/opencv2/viz/widget_accessor.hpp similarity index 55% rename from modules/ocl/src/opencl/arithm_bitwise_binary_scalar.cl rename to modules/viz/include/opencv2/viz/widget_accessor.hpp index 434bd5eca..734f6ce55 100644 --- a/modules/ocl/src/opencl/arithm_bitwise_binary_scalar.cl +++ b/modules/viz/include/opencv2/viz/widget_accessor.hpp @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////////////// +/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // @@ -10,14 +10,9 @@ // 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. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // -// @Authors -// Jiang Liyuan, jlyuan001.good@163.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: // @@ -31,7 +26,7 @@ // * 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 +// 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, @@ -42,41 +37,33 @@ // 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. // +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // +//M*/ -/////////////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////bitwise_binary///////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////// +#ifndef __OPENCV_VIZ_WIDGET_ACCESSOR_HPP__ +#define __OPENCV_VIZ_WIDGET_ACCESSOR_HPP__ -__kernel void arithm_bitwise_binary_scalar( - __global uchar *src1, int src1_step, int src1_offset, - __global uchar *src2, - __global uchar *dst, int dst_step, int dst_offset, - int cols, int rows) +#include +#include +#include + +namespace cv { - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) + namespace viz { -#if elemSize > 1 - x *= elemSize; -#endif - int src1_index = mad24(y, src1_step, src1_offset + x); - int dst_index = mad24(y, dst_step, dst_offset + x); + class Widget; -#if elemSize > 1 - #pragma unroll - for (int i = 0; i < elemSize; i += vlen) + //The class is only that depends on VTK in its interface. + //It is indended for those users who want to develop own widgets system using VTK library API. + struct CV_EXPORTS WidgetAccessor { - ucharv t0 = vloadn(0, src1 + src1_index + i); - ucharv t1 = vloadn(0, src2 + i); - ucharv t2 = t0 Operation t1; - - vstoren(t2, 0, dst + dst_index + i); - } -#else - dst[dst_index] = src1[src1_index] Operation src2[0]; -#endif + static vtkSmartPointer getProp(const Widget &widget); + static void setProp(Widget &widget, vtkSmartPointer prop); + }; } } + +#endif diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp new file mode 100644 index 000000000..611db5449 --- /dev/null +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -0,0 +1,419 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_WIDGETS_HPP__ +#define __OPENCV_VIZ_WIDGETS_HPP__ + +#include + +namespace cv +{ + namespace viz + { + ///////////////////////////////////////////////////////////////////////////// + /// Widget rendering properties + enum RenderingProperties + { + POINT_SIZE, + OPACITY, + LINE_WIDTH, + FONT_SIZE, + REPRESENTATION, + IMMEDIATE_RENDERING, + SHADING + }; + + enum RepresentationValues + { + REPRESENTATION_POINTS, + REPRESENTATION_WIREFRAME, + REPRESENTATION_SURFACE + }; + + enum ShadingValues + { + SHADING_FLAT, + SHADING_GOURAUD, + SHADING_PHONG + }; + + ///////////////////////////////////////////////////////////////////////////// + /// The base class for all widgets + class CV_EXPORTS Widget + { + public: + Widget(); + Widget(const Widget& other); + Widget& operator=(const Widget& other); + ~Widget(); + + //! Create a widget directly from ply file + static Widget fromPlyFile(const String &file_name); + + //! Rendering properties of this particular widget + void setRenderingProperty(int property, double value); + double getRenderingProperty(int property) const; + + //! Casting between widgets + template _W cast(); + private: + class Impl; + Impl *impl_; + friend struct WidgetAccessor; + }; + + ///////////////////////////////////////////////////////////////////////////// + /// The base class for all 3D widgets + class CV_EXPORTS Widget3D : public Widget + { + public: + Widget3D() {} + + //! widget position manipulation, i.e. place where it is rendered + void setPose(const Affine3d &pose); + void updatePose(const Affine3d &pose); + Affine3d getPose() const; + + //! update internal widget data, i.e. points, normals, etc. + void applyTransform(const Affine3d &transform); + + void setColor(const Color &color); + + }; + + ///////////////////////////////////////////////////////////////////////////// + /// The base class for all 2D widgets + class CV_EXPORTS Widget2D : public Widget + { + public: + Widget2D() {} + + void setColor(const Color &color); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Simple widgets + + class CV_EXPORTS WLine : public Widget3D + { + public: + WLine(const Point3d &pt1, const Point3d &pt2, const Color &color = Color::white()); + }; + + class CV_EXPORTS WPlane : public Widget3D + { + public: + //! created default plane with center point at origin and normal oriented along z-axis + WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + + //! repositioned plane + WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, + const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + }; + + class CV_EXPORTS WSphere : public Widget3D + { + public: + WSphere(const cv::Point3d ¢er, double radius, int sphere_resolution = 10, const Color &color = Color::white()); + }; + + class CV_EXPORTS WArrow : public Widget3D + { + public: + WArrow(const Point3d& pt1, const Point3d& pt2, double thickness = 0.03, const Color &color = Color::white()); + }; + + class CV_EXPORTS WCircle : public Widget3D + { + public: + //! creates default planar circle centred at origin with plane normal along z-axis + WCircle(double radius, double thickness = 0.01, const Color &color = Color::white()); + + //! creates repositioned circle + WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white()); + }; + + class CV_EXPORTS WCone : public Widget3D + { + public: + //! create default cone, oriented along x-axis with center of its base located at origin + WCone(double length, double radius, int resolution = 6.0, const Color &color = Color::white()); + + //! creates repositioned cone + WCone(double radius, const Point3d& center, const Point3d& tip, int resolution = 6.0, const Color &color = Color::white()); + }; + + class CV_EXPORTS WCylinder : public Widget3D + { + public: + WCylinder(const Point3d& axis_point1, const Point3d& axis_point2, double radius, int numsides = 30, const Color &color = Color::white()); + }; + + class CV_EXPORTS WCube : public Widget3D + { + public: + WCube(const Point3d& min_point = Vec3d::all(-0.5), const Point3d& max_point = Vec3d::all(0.5), + bool wire_frame = true, const Color &color = Color::white()); + }; + + class CV_EXPORTS WPolyLine : public Widget3D + { + public: + WPolyLine(InputArray points, InputArray colors); + WPolyLine(InputArray points, const Color &color = Color::white()); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Text and image widgets + + class CV_EXPORTS WText : public Widget2D + { + public: + WText(const String &text, const Point &pos, int font_size = 20, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + + class CV_EXPORTS WText3D : public Widget3D + { + public: + //! creates text label in 3D. If face_camera = false, text plane normal is oriented along z-axis. Use widget pose to orient it properly + WText3D(const String &text, const Point3d &position, double text_scale = 1., bool face_camera = true, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + + class CV_EXPORTS WImageOverlay : public Widget2D + { + public: + WImageOverlay(InputArray image, const Rect &rect); + void setImage(InputArray image); + }; + + class CV_EXPORTS WImage3D : public Widget3D + { + public: + //! Creates 3D image in a plane centered at the origin with normal orientaion along z-axis, + //! image x- and y-axes are oriented along x- and y-axes of 3d world + WImage3D(InputArray image, const Size2d &size); + + //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation + WImage3D(InputArray image, const Size2d &size, const Vec3d ¢er, const Vec3d &normal, const Vec3d &up_vector); + + void setImage(InputArray image); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Compond widgets + + class CV_EXPORTS WCoordinateSystem : public Widget3D + { + public: + WCoordinateSystem(double scale = 1.0); + }; + + class CV_EXPORTS WGrid : public Widget3D + { + public: + //! Creates grid at the origin and normal oriented along z-axis + WGrid(const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); + + //! Creates repositioned grid + WGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, + const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); + }; + + class CV_EXPORTS WCameraPosition : public Widget3D + { + public: + //! Creates camera coordinate frame (axes) at the origin + WCameraPosition(double scale = 1.0); + //! Creates frustum based on the intrinsic marix K at the origin + WCameraPosition(const Matx33d &K, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum based on the field of view at the origin + WCameraPosition(const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + WCameraPosition(const Matx33d &K, InputArray image, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + WCameraPosition(const Vec2d &fov, InputArray image, double scale = 1.0, const Color &color = Color::white()); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Trajectories + + class CV_EXPORTS WTrajectory : public Widget3D + { + public: + enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH }; + + //! Takes vector> and displays trajectory of the given path either by coordinate frames or polyline + WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.0, const Color &color = Color::white()); + }; + + class CV_EXPORTS WTrajectoryFrustums : public Widget3D + { + public: + //! Takes vector> and displays trajectory of the given path by frustums + WTrajectoryFrustums(InputArray path, const Matx33d &K, double scale = 1., const Color &color = Color::white()); + + //! Takes vector> and displays trajectory of the given path by frustums + WTrajectoryFrustums(InputArray path, const Vec2d &fov, double scale = 1., const Color &color = Color::white()); + }; + + class CV_EXPORTS WTrajectorySpheres: public Widget3D + { + public: + //! Takes vector> and displays trajectory of the given path + WTrajectorySpheres(InputArray path, double line_length = 0.05, double radius = 0.007, + const Color &from = Color::red(), const Color &to = Color::white()); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Clouds + + class CV_EXPORTS WCloud: public Widget3D + { + public: + //! Each point in cloud is mapped to a color in colors + WCloud(InputArray cloud, InputArray colors); + + //! All points in cloud have the same color + WCloud(InputArray cloud, const Color &color = Color::white()); + + //! Each point in cloud is mapped to a color in colors, normals are used for shading + WCloud(InputArray cloud, InputArray colors, InputArray normals); + + //! All points in cloud have the same color, normals are used for shading + WCloud(InputArray cloud, const Color &color, InputArray normals); + }; + + class CV_EXPORTS WPaintedCloud: public Widget3D + { + public: + //! Paint cloud with default gradient between cloud bounds points + WPaintedCloud(InputArray cloud); + + //! Paint cloud with default gradient between given points + WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2); + + //! Paint cloud with gradient specified by given colors between given points + WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2, const Color& c1, const Color c2); + }; + + class CV_EXPORTS WCloudCollection : public Widget3D + { + public: + WCloudCollection(); + + //! Each point in cloud is mapped to a color in colors + void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()); + //! All points in cloud have the same color + void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3d &pose = Affine3d::Identity()); + //! Repacks internal structure to single cloud + void finalize(); + }; + + class CV_EXPORTS WCloudNormals : public Widget3D + { + public: + WCloudNormals(InputArray cloud, InputArray normals, int level = 64, double scale = 0.1, const Color &color = Color::white()); + }; + + class CV_EXPORTS WMesh : public Widget3D + { + public: + WMesh(const Mesh &mesh); + WMesh(InputArray cloud, InputArray polygons, InputArray colors = noArray(), InputArray normals = noArray()); + }; + + class CV_EXPORTS WWidgetMerger : public Widget3D + { + public: + WWidgetMerger(); + + //! Add widget to merge with optional position change + void addWidget(const Widget3D& widget, const Affine3d &pose = Affine3d::Identity()); + + //! Repacks internal structure to single widget + void finalize(); + }; + + ///////////////////////////////////////////////////////////////////////////// + /// Utility exports + + template<> CV_EXPORTS Widget2D Widget::cast(); + template<> CV_EXPORTS Widget3D Widget::cast(); + template<> CV_EXPORTS WLine Widget::cast(); + template<> CV_EXPORTS WPlane Widget::cast(); + template<> CV_EXPORTS WSphere Widget::cast(); + template<> CV_EXPORTS WCylinder Widget::cast(); + template<> CV_EXPORTS WArrow Widget::cast(); + template<> CV_EXPORTS WCircle Widget::cast(); + template<> CV_EXPORTS WCone Widget::cast(); + template<> CV_EXPORTS WCube Widget::cast(); + template<> CV_EXPORTS WCoordinateSystem Widget::cast(); + template<> CV_EXPORTS WPolyLine Widget::cast(); + template<> CV_EXPORTS WGrid Widget::cast(); + template<> CV_EXPORTS WText3D Widget::cast(); + template<> CV_EXPORTS WText Widget::cast(); + template<> CV_EXPORTS WImageOverlay Widget::cast(); + template<> CV_EXPORTS WImage3D Widget::cast(); + template<> CV_EXPORTS WCameraPosition Widget::cast(); + template<> CV_EXPORTS WTrajectory Widget::cast(); + template<> CV_EXPORTS WTrajectoryFrustums Widget::cast(); + template<> CV_EXPORTS WTrajectorySpheres Widget::cast(); + template<> CV_EXPORTS WCloud Widget::cast(); + template<> CV_EXPORTS WPaintedCloud Widget::cast(); + template<> CV_EXPORTS WCloudCollection Widget::cast(); + template<> CV_EXPORTS WCloudNormals Widget::cast(); + template<> CV_EXPORTS WMesh Widget::cast(); + template<> CV_EXPORTS WWidgetMerger Widget::cast(); + + } /* namespace viz */ +} /* namespace cv */ + +#endif diff --git a/modules/viz/src/clouds.cpp b/modules/viz/src/clouds.cpp new file mode 100644 index 000000000..48d057d2a --- /dev/null +++ b/modules/viz/src/clouds.cpp @@ -0,0 +1,518 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Point Cloud Widget implementation + +cv::viz::WCloud::WCloud(InputArray cloud, InputArray colors) +{ + WCloud cloud_widget(cloud, colors, cv::noArray()); + *this = cloud_widget; +} + +cv::viz::WCloud::WCloud(InputArray cloud, const Color &color) +{ + WCloud cloud_widget(cloud, Mat(cloud.size(), CV_8UC3, color)); + *this = cloud_widget; +} + +cv::viz::WCloud::WCloud(InputArray cloud, const Color &color, InputArray normals) +{ + WCloud cloud_widget(cloud, Mat(cloud.size(), CV_8UC3, color), normals); + *this = cloud_widget; +} + +cv::viz::WCloud::WCloud(cv::InputArray cloud, cv::InputArray colors, cv::InputArray normals) +{ + CV_Assert(!cloud.empty() && !colors.empty()); + + vtkSmartPointer cloud_source = vtkSmartPointer::New(); + cloud_source->SetColorCloudNormals(cloud, colors, normals); + cloud_source->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, cloud_source->GetOutput()); + mapper->SetScalarModeToUsePointData(); + mapper->ImmediateModeRenderingOff(); + mapper->SetScalarRange(0, 255); + mapper->ScalarVisibilityOn(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); + +} + + +template<> cv::viz::WCloud cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Painted Cloud Widget implementation + +cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud) +{ + vtkSmartPointer cloud_source = vtkSmartPointer::New(); + cloud_source->SetCloud(cloud); + cloud_source->Update(); + + Vec6d bounds(cloud_source->GetOutput()->GetPoints()->GetBounds()); + + vtkSmartPointer elevation = vtkSmartPointer::New(); + elevation->SetInputConnection(cloud_source->GetOutputPort()); + elevation->SetLowPoint(bounds[0], bounds[2], bounds[4]); + elevation->SetHighPoint(bounds[1], bounds[3], bounds[5]); + elevation->SetScalarRange(0.0, 1.0); + elevation->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); + mapper->ImmediateModeRenderingOff(); + mapper->ScalarVisibilityOn(); + mapper->SetColorModeToMapScalars(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2) +{ + vtkSmartPointer cloud_source = vtkSmartPointer::New(); + cloud_source->SetCloud(cloud); + + vtkSmartPointer elevation = vtkSmartPointer::New(); + elevation->SetInputConnection(cloud_source->GetOutputPort()); + elevation->SetLowPoint(p1.x, p1.y, p1.z); + elevation->SetHighPoint(p2.x, p2.y, p2.z); + elevation->SetScalarRange(0.0, 1.0); + elevation->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); + mapper->ImmediateModeRenderingOff(); + mapper->ScalarVisibilityOn(); + mapper->SetColorModeToMapScalars(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2, const Color& c1, const Color c2) +{ + vtkSmartPointer cloud_source = vtkSmartPointer::New(); + cloud_source->SetCloud(cloud); + + vtkSmartPointer elevation = vtkSmartPointer::New(); + elevation->SetInputConnection(cloud_source->GetOutputPort()); + elevation->SetLowPoint(p1.x, p1.y, p1.z); + elevation->SetHighPoint(p2.x, p2.y, p2.z); + elevation->SetScalarRange(0.0, 1.0); + elevation->Update(); + + Color vc1 = vtkcolor(c1), vc2 = vtkcolor(c2); + vtkSmartPointer color_transfer = vtkSmartPointer::New(); + color_transfer->SetColorSpaceToRGB(); + color_transfer->AddRGBPoint(0.0, vc1[0], vc1[1], vc1[2]); + color_transfer->AddRGBPoint(1.0, vc2[0], vc2[1], vc2[2]); + color_transfer->SetScaleToLinear(); + color_transfer->Build(); + + //if in future some need to replace color table with real scalars, then this can be done usine next calls: + //vtkDataArray *float_scalars = vtkPolyData::SafeDownCast(elevation->GetOutput())->GetPointData()->GetArray("Elevation"); + //vtkSmartPointer polydata = cloud_source->GetOutput(); + //polydata->GetPointData()->SetScalars(color_transfer->MapScalars(float_scalars, VTK_COLOR_MODE_DEFAULT, 0)); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); + mapper->ImmediateModeRenderingOff(); + mapper->ScalarVisibilityOn(); + mapper->SetColorModeToMapScalars(); + mapper->SetLookupTable(color_transfer); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WPaintedCloud cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Cloud Collection Widget implementation + +cv::viz::WCloudCollection::WCloudCollection() +{ + vtkSmartPointer append_filter = vtkSmartPointer::New(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(append_filter->GetOutputPort()); + mapper->SetScalarModeToUsePointData(); + mapper->ImmediateModeRenderingOff(); + mapper->SetScalarRange(0, 255); + mapper->ScalarVisibilityOn(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetNumberOfCloudPoints(1); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, const Affine3d &pose) +{ + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetColorCloud(cloud, colors); + + vtkSmartPointer polydata = VtkUtils::TransformPolydata(source->GetOutputPort(), pose); + + vtkSmartPointer actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Correctness check." && actor); + + vtkSmartPointer producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); + vtkSmartPointer append_filter = vtkAppendPolyData::SafeDownCast(producer); + VtkUtils::AddInputData(append_filter, polydata); + + actor->SetNumberOfCloudPoints(std::max(1, actor->GetNumberOfCloudPoints() + polydata->GetNumberOfPoints()/10)); +} + +void cv::viz::WCloudCollection::addCloud(InputArray cloud, const Color &color, const Affine3d &pose) +{ + addCloud(cloud, Mat(cloud.size(), CV_8UC3, color), pose); +} + +void cv::viz::WCloudCollection::finalize() +{ + vtkSmartPointer actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Incompatible widget type." && actor); + + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("Need to add at least one cloud." && mapper); + + vtkSmartPointer producer = mapper->GetInputConnection(0, 0)->GetProducer(); + vtkSmartPointer append_filter = vtkAppendPolyData::SafeDownCast(producer); + append_filter->Update(); + + vtkSmartPointer polydata = append_filter->GetOutput(); + mapper->RemoveInputConnection(0, 0); + VtkUtils::SetInputData(mapper, polydata); +} + +template<> cv::viz::WCloudCollection cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Cloud Normals Widget implementation + +cv::viz::WCloudNormals::WCloudNormals(InputArray _cloud, InputArray _normals, int level, double scale, const Color &color) +{ + Mat cloud = _cloud.getMat(); + Mat normals = _normals.getMat(); + + CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); + CV_Assert(cloud.size() == normals.size() && cloud.type() == normals.type()); + + int sqlevel = (int)std::sqrt((double)level); + int ystep = (cloud.cols > 1 && cloud.rows > 1) ? sqlevel : 1; + int xstep = (cloud.cols > 1 && cloud.rows > 1) ? sqlevel : level; + + vtkSmartPointer points = vtkSmartPointer::New(); + points->SetDataType(cloud.depth() == CV_32F ? VTK_FLOAT : VTK_DOUBLE); + + vtkSmartPointer lines = vtkSmartPointer::New(); + + int s_chs = cloud.channels(); + int n_chs = normals.channels(); + int total = 0; + + for(int y = 0; y < cloud.rows; y += ystep) + { + if (cloud.depth() == CV_32F) + { + const float *srow = cloud.ptr(y); + const float *send = srow + cloud.cols * s_chs; + const float *nrow = normals.ptr(y); + + for (; srow < send; srow += xstep * s_chs, nrow += xstep * n_chs) + if (!isNan(srow) && !isNan(nrow)) + { + Vec3f endp = Vec3f(srow) + Vec3f(nrow) * (float)scale; + + points->InsertNextPoint(srow); + points->InsertNextPoint(endp.val); + + lines->InsertNextCell(2); + lines->InsertCellPoint(total++); + lines->InsertCellPoint(total++); + } + } + else + { + const double *srow = cloud.ptr(y); + const double *send = srow + cloud.cols * s_chs; + const double *nrow = normals.ptr(y); + + for (; srow < send; srow += xstep * s_chs, nrow += xstep * n_chs) + if (!isNan(srow) && !isNan(nrow)) + { + Vec3d endp = Vec3d(srow) + Vec3d(nrow) * (double)scale; + + points->InsertNextPoint(srow); + points->InsertNextPoint(endp.val); + + lines->InsertNextCell(2); + lines->InsertCellPoint(total++); + lines->InsertCellPoint(total++); + } + } + } + + vtkSmartPointer polydata = vtkSmartPointer::New(); + polydata->SetPoints(points); + polydata->SetLines(lines); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WCloudNormals cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Mesh Widget implementation + +cv::viz::WMesh::WMesh(const Mesh &mesh) +{ + CV_Assert(mesh.cloud.rows == 1 && mesh.polygons.type() == CV_32SC1); + + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetColorCloudNormalsTCoords(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords); + source->Update(); + + Mat lookup_buffer(1, (int)mesh.cloud.total(), CV_32SC1); + int *lookup = lookup_buffer.ptr(); + for(int y = 0, index = 0; y < mesh.cloud.rows; ++y) + { + int s_chs = mesh.cloud.channels(); + + if (mesh.cloud.depth() == CV_32F) + { + const float* srow = mesh.cloud.ptr(y); + const float* send = srow + mesh.cloud.cols * s_chs; + + for (; srow != send; srow += s_chs, ++lookup) + if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2])) + *lookup = index++; + } + + if (mesh.cloud.depth() == CV_64F) + { + const double* srow = mesh.cloud.ptr(y); + const double* send = srow + mesh.cloud.cols * s_chs; + + for (; srow != send; srow += s_chs, ++lookup) + if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2])) + *lookup = index++; + } + } + lookup = lookup_buffer.ptr(); + + vtkSmartPointer polydata = source->GetOutput(); + polydata->SetVerts(0); + + const int * polygons = mesh.polygons.ptr(); + vtkSmartPointer cell_array = vtkSmartPointer::New(); + + int idx = 0; + size_t polygons_size = mesh.polygons.total(); + for (size_t i = 0; i < polygons_size; ++idx) + { + int n_points = polygons[i++]; + + cell_array->InsertNextCell(n_points); + for (int j = 0; j < n_points; ++j, ++idx) + cell_array->InsertCellPoint(lookup[polygons[i++]]); + } + cell_array->GetData()->SetNumberOfValues(idx); + cell_array->Squeeze(); + polydata->SetStrips(cell_array); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetScalarModeToUsePointData(); + mapper->ImmediateModeRenderingOff(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + //actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10)); + actor->GetProperty()->SetRepresentationToSurface(); + actor->GetProperty()->BackfaceCullingOff(); // Backface culling is off for higher efficiency + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->EdgeVisibilityOff(); + actor->GetProperty()->ShadingOff(); + actor->SetMapper(mapper); + + if (!mesh.texture.empty()) + { + vtkSmartPointer image_source = vtkSmartPointer::New(); + image_source->SetImage(mesh.texture); + + vtkSmartPointer texture = vtkSmartPointer::New(); + texture->SetInputConnection(image_source->GetOutputPort()); + actor->SetTexture(texture); + } + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WMesh::WMesh(InputArray cloud, InputArray polygons, InputArray colors, InputArray normals) +{ + Mesh mesh; + mesh.cloud = cloud.getMat(); + mesh.colors = colors.getMat(); + mesh.normals = normals.getMat(); + mesh.polygons = polygons.getMat(); + *this = WMesh(mesh); +} + +template<> CV_EXPORTS cv::viz::WMesh cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Widget Merger implementation + +cv::viz::WWidgetMerger::WWidgetMerger() +{ + vtkSmartPointer append_filter = vtkSmartPointer::New(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(append_filter->GetOutputPort()); + mapper->SetScalarModeToUsePointData(); + mapper->ImmediateModeRenderingOff(); + mapper->SetScalarRange(0, 255); + mapper->ScalarVisibilityOn(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +void cv::viz::WWidgetMerger::addWidget(const Widget3D& widget, const Affine3d &pose) +{ + vtkActor *widget_actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(widget)); + CV_Assert("Widget is not 3D actor." && widget_actor); + + vtkSmartPointer widget_mapper = vtkPolyDataMapper::SafeDownCast(widget_actor->GetMapper()); + CV_Assert("Widget doesn't have a polydata mapper" && widget_mapper); + widget_mapper->Update(); + + vtkSmartPointer actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + vtkSmartPointer producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); + vtkSmartPointer append_filter = vtkAppendPolyData::SafeDownCast(producer); + CV_Assert("Correctness check" && append_filter); + + VtkUtils::AddInputData(append_filter, VtkUtils::TransformPolydata(widget_mapper->GetInput(), pose)); +} + +void cv::viz::WWidgetMerger::finalize() +{ + vtkSmartPointer actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + vtkSmartPointer producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); + vtkSmartPointer append_filter = vtkAppendPolyData::SafeDownCast(producer); + CV_Assert("Correctness check" && append_filter); + append_filter->Update(); + + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + mapper->RemoveInputConnection(0, 0); + VtkUtils::SetInputData(mapper, append_filter->GetOutput()); + mapper->Modified(); +} + +template<> CV_EXPORTS cv::viz::WWidgetMerger cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp new file mode 100644 index 000000000..feaca852e --- /dev/null +++ b/modules/viz/src/precomp.hpp @@ -0,0 +1,340 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_PRECOMP_HPP__ +#define __OPENCV_VIZ_PRECOMP_HPP__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vtkCallbackCommand.h" + +#if !defined(_WIN32) || defined(__CYGWIN__) +# include /* unlink */ +#else +# include /* unlink */ +#endif + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include + + +namespace cv +{ + namespace viz + { + typedef std::map > WidgetActorMap; + + struct VizMap + { + typedef std::map type; + typedef type::iterator iterator; + + type m; + ~VizMap(); + void replace_clear(); + }; + + class VizStorage + { + public: + static void unregisterAll(); + + //! window names automatically have Viz - prefix even though not provided by the users + static String generateWindowName(const String &window_name); + + private: + VizStorage(); // Static + + static void add(const Viz3d& window); + static Viz3d& get(const String &window_name); + static void remove(const String &window_name); + static bool windowExists(const String &window_name); + static void removeUnreferenced(); + + static VizMap storage; + friend class Viz3d; + + static VizStorage init; + }; + + template inline _Tp normalized(const _Tp& v) { return v * 1/norm(v); } + + template inline bool isNan(const _Tp* data) + { + return isNan(data[0]) || isNan(data[1]) || isNan(data[2]); + } + + inline vtkSmartPointer getActor(const Widget3D& widget) + { + return vtkActor::SafeDownCast(WidgetAccessor::getProp(widget)); + } + + inline vtkSmartPointer getPolyData(const Widget3D& widget) + { + vtkSmartPointer mapper = getActor(widget)->GetMapper(); + return vtkPolyData::SafeDownCast(mapper->GetInput()); + } + + inline vtkSmartPointer vtkmatrix(const cv::Matx44d &matrix) + { + vtkSmartPointer vtk_matrix = vtkSmartPointer::New(); + vtk_matrix->DeepCopy(matrix.val); + return vtk_matrix; + } + + inline Color vtkcolor(const Color& color) + { + Color scaled_color = color * (1.0/255.0); + std::swap(scaled_color[0], scaled_color[2]); + return scaled_color; + } + + inline Vec3d get_random_vec(double from = -10.0, double to = 10.0) + { + RNG& rng = theRNG(); + return Vec3d(rng.uniform(from, to), rng.uniform(from, to), rng.uniform(from, to)); + } + + struct VtkUtils + { + template + static void SetInputData(vtkSmartPointer filter, vtkPolyData* polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polydata); + #else + filter->SetInputData(polydata); + #endif + } + template + static void SetSourceData(vtkSmartPointer filter, vtkPolyData* polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetSource(polydata); + #else + filter->SetSourceData(polydata); + #endif + } + + template + static void SetInputData(vtkSmartPointer filter, vtkImageData* polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polydata); + #else + filter->SetInputData(polydata); + #endif + } + + template + static void AddInputData(vtkSmartPointer filter, vtkPolyData *polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->AddInput(polydata); + #else + filter->AddInputData(polydata); + #endif + } + + static vtkSmartPointer FillScalars(size_t size, const Color& color) + { + Vec3b rgb = Vec3d(color[2], color[1], color[0]); + Vec3b* color_data = new Vec3b[size]; + std::fill(color_data, color_data + size, rgb); + + vtkSmartPointer scalars = vtkSmartPointer::New(); + scalars->SetName("Colors"); + scalars->SetNumberOfComponents(3); + scalars->SetNumberOfTuples((vtkIdType)size); + scalars->SetArray(color_data->val, (vtkIdType)(size * 3), 0); + return scalars; + } + + static vtkSmartPointer FillScalars(vtkSmartPointer polydata, const Color& color) + { + return polydata->GetPointData()->SetScalars(FillScalars(polydata->GetNumberOfPoints(), color)), polydata; + } + + static vtkSmartPointer ComputeNormals(vtkSmartPointer polydata) + { + vtkSmartPointer normals_generator = vtkSmartPointer::New(); + normals_generator->ComputePointNormalsOn(); + normals_generator->ComputeCellNormalsOff(); + normals_generator->SetFeatureAngle(0.1); + normals_generator->SetSplitting(0); + normals_generator->SetConsistency(1); + normals_generator->SetAutoOrientNormals(0); + normals_generator->SetFlipNormals(0); + normals_generator->SetNonManifoldTraversal(1); + VtkUtils::SetInputData(normals_generator, polydata); + normals_generator->Update(); + return normals_generator->GetOutput(); + } + + static vtkSmartPointer TransformPolydata(vtkSmartPointer algorithm_output_port, const Affine3d& pose) + { + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->SetMatrix(vtkmatrix(pose.matrix)); + + vtkSmartPointer transform_filter = vtkSmartPointer::New(); + transform_filter->SetTransform(transform); + transform_filter->SetInputConnection(algorithm_output_port); + transform_filter->Update(); + return transform_filter->GetOutput(); + } + + static vtkSmartPointer TransformPolydata(vtkSmartPointer polydata, const Affine3d& pose) + { + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->SetMatrix(vtkmatrix(pose.matrix)); + + vtkSmartPointer transform_filter = vtkSmartPointer::New(); + VtkUtils::SetInputData(transform_filter, polydata); + transform_filter->SetTransform(transform); + transform_filter->Update(); + return transform_filter->GetOutput(); + } + }; + + vtkSmartPointer vtkCocoaRenderWindowInteractorNew(); + } +} + +#include "vtk/vtkVizInteractorStyle.hpp" +#include "vizimpl.hpp" + +#endif diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp new file mode 100644 index 000000000..4dd77038e --- /dev/null +++ b/modules/viz/src/shapes.cpp @@ -0,0 +1,1089 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// line widget implementation +cv::viz::WLine::WLine(const Point3d &pt1, const Point3d &pt2, const Color &color) +{ + vtkSmartPointer line = vtkSmartPointer::New(); + line->SetPoint1(pt1.x, pt1.y, pt1.z); + line->SetPoint2(pt2.x, pt2.y, pt2.z); + line->Update(); + + vtkSmartPointer polydata = line->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WLine cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// sphere widget implementation + +cv::viz::WSphere::WSphere(const Point3d ¢er, double radius, int sphere_resolution, const Color &color) +{ + vtkSmartPointer sphere = vtkSmartPointer::New(); + sphere->SetRadius(radius); + sphere->SetCenter(center.x, center.y, center.z); + sphere->SetPhiResolution(sphere_resolution); + sphere->SetThetaResolution(sphere_resolution); + sphere->LatLongTessellationOff(); + sphere->Update(); + + vtkSmartPointer polydata = sphere->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WSphere cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// plane widget implementation + +cv::viz::WPlane::WPlane(const Size2d& size, const Color &color) +{ + vtkSmartPointer plane = vtkSmartPointer::New(); + plane->SetOrigin(-0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint1( 0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint2(-0.5 * size.width, 0.5 * size.height, 0.0); + plane->Update(); + + vtkSmartPointer polydata = plane->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->GetProperty()->LightingOff(); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WPlane::WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, const Size2d& size, const Color &color) +{ + Vec3d zvec = normalize(normal); + Vec3d xvec = normalize(new_yaxis.cross(zvec)); + Vec3d yvec = zvec.cross(xvec); + + WPlane plane(size, color); + plane.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center)); + *this = plane; +} + +template<> cv::viz::WPlane cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// arrow widget implementation + +cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness, const Color &color) +{ + vtkSmartPointer arrow_source = vtkSmartPointer::New(); + arrow_source->SetShaftRadius(thickness); + arrow_source->SetTipRadius(thickness * 3.0); + arrow_source->SetTipLength(thickness * 10.0); + + Vec3d arbitrary = get_random_vec(); + Vec3d start_point(pt1.x, pt1.y, pt1.z), end_point(pt2.x, pt2.y, pt2.z); + + double length = norm(end_point - start_point); + + Vec3d xvec = normalized(end_point - start_point); + Vec3d zvec = normalized(xvec.cross(arbitrary)); + Vec3d yvec = zvec.cross(xvec); + + Matx33d R = makeTransformToGlobal(xvec, yvec, zvec).rotation(); + Affine3d transform_with_scale(R * length, start_point); + + vtkSmartPointer polydata = VtkUtils::TransformPolydata(arrow_source->GetOutputPort(), transform_with_scale); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WArrow cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// circle widget implementation + +cv::viz::WCircle::WCircle(double radius, double thickness, const Color &color) +{ + vtkSmartPointer disk = vtkSmartPointer::New(); + disk->SetCircumferentialResolution(30); + disk->SetInnerRadius(radius - thickness); + disk->SetOuterRadius(radius + thickness); + disk->Update(); + + vtkSmartPointer polydata = disk->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->LightingOff(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCircle::WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness, const Color &color) +{ + Vec3d arbitrary = get_random_vec(); + Vec3d zvec = normalized(normal); + Vec3d xvec = normalized(zvec.cross(arbitrary)); + Vec3d yvec = zvec.cross(xvec); + + WCircle circle(radius, thickness, color); + circle.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center)); + *this = circle; +} + +template<> cv::viz::WCircle cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// WCone widget implementation + +cv::viz::WCone::WCone(double length, double radius, int resolution, const Color &color) +{ + vtkSmartPointer cone_source = vtkSmartPointer::New(); + cone_source->SetCenter(length*0.5, 0.0, 0.0); + cone_source->SetHeight(length); + cone_source->SetRadius(radius); + cone_source->SetResolution(resolution); + cone_source->Update(); + + vtkSmartPointer polydata = cone_source->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCone::WCone(double radius, const Point3d& center, const Point3d& tip, int resolution, const Color &color) +{ + Vec3d arbitrary = get_random_vec(); + Vec3d xvec = normalized(Vec3d(tip - center)); + Vec3d zvec = normalized(xvec.cross(arbitrary)); + Vec3d yvec = zvec.cross(xvec); + + WCone circle(norm(tip - center), radius, resolution, color); + circle.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center)); + *this = circle; +} + +template<> cv::viz::WCone cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// cylinder widget implementation + +cv::viz::WCylinder::WCylinder(const Point3d& axis_point1, const Point3d& axis_point2, double radius, int numsides, const Color &color) +{ + vtkSmartPointer line = vtkSmartPointer::New(); + line->SetPoint1(axis_point1.x, axis_point1.y, axis_point1.z); + line->SetPoint2(axis_point2.x, axis_point2.y, axis_point2.z); + + vtkSmartPointer tuber = vtkSmartPointer::New(); + tuber->SetInputConnection(line->GetOutputPort()); + tuber->SetNumberOfSides(numsides); + tuber->SetRadius(radius); + tuber->Update(); + + vtkSmartPointer polydata = tuber->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WCylinder cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// cylinder widget implementation + +cv::viz::WCube::WCube(const Point3d& min_point, const Point3d& max_point, bool wire_frame, const Color &color) +{ + double bounds[6]; + bounds[0] = std::min(min_point.x, max_point.x); + bounds[1] = std::max(min_point.x, max_point.x); + bounds[2] = std::min(min_point.y, max_point.y); + bounds[3] = std::max(min_point.y, max_point.y); + bounds[4] = std::min(min_point.z, max_point.z); + bounds[5] = std::max(min_point.z, max_point.z); + + vtkSmartPointer cube; + if (wire_frame) + { + cube = vtkSmartPointer::New(); + vtkOutlineSource::SafeDownCast(cube)->SetBounds(bounds); + } + else + { + cube = vtkSmartPointer::New(); + vtkCubeSource::SafeDownCast(cube)->SetBounds(bounds); + } + cube->Update(); + vtkSmartPointer polydata =cube->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WCube cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// coordinate system widget implementation + +cv::viz::WCoordinateSystem::WCoordinateSystem(double scale) +{ + vtkSmartPointer axes = vtkSmartPointer::New(); + axes->SetOrigin(0, 0, 0); + axes->SetScaleFactor(scale); + axes->Update(); + + vtkSmartPointer colors = vtkSmartPointer::New(); + colors->SetNumberOfComponents(3); + colors->InsertNextTuple3(255, 0, 0); + colors->InsertNextTuple3(255, 0, 0); + colors->InsertNextTuple3(0, 255, 0); + colors->InsertNextTuple3(0, 255, 0); + colors->InsertNextTuple3(0, 0, 255); + colors->InsertNextTuple3(0, 0, 255); + + vtkSmartPointer polydata = axes->GetOutput(); + polydata->GetPointData()->SetScalars(colors); + + vtkSmartPointer tube_filter = vtkSmartPointer::New(); + VtkUtils::SetInputData(tube_filter, polydata); + tube_filter->SetRadius(axes->GetScaleFactor() / 50.0); + tube_filter->SetNumberOfSides(6); + tube_filter->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetScalarModeToUsePointData(); + VtkUtils::SetInputData(mapper, tube_filter->GetOutput()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WCoordinateSystem cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// polyline widget implementation + +cv::viz::WPolyLine::WPolyLine(InputArray points, InputArray colors) +{ + vtkSmartPointer cloud_source = vtkSmartPointer::New(); + cloud_source->SetColorCloud(points, colors); + cloud_source->Update(); + + vtkSmartPointer polydata = cloud_source->GetOutput(); + + vtkSmartPointer cell_array = vtkSmartPointer::New(); + cell_array->Allocate(cell_array->EstimateSize(1, polydata->GetNumberOfPoints())); + cell_array->InsertNextCell(polydata->GetNumberOfPoints()); + for(vtkIdType i = 0; i < polydata->GetNumberOfPoints(); ++i) + cell_array->InsertCellPoint(i); + + polydata->SetLines(cell_array); + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + mapper->SetScalarRange(0, 255); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WPolyLine::WPolyLine(InputArray points, const Color &color) +{ + WPolyLine polyline(points, Mat(points.size(), CV_8UC3, color)); + *this = polyline; +} + +template<> cv::viz::WPolyLine cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// grid widget implementation + + +cv::viz::WGrid::WGrid(const Vec2i &cells, const Vec2d &cells_spacing, const Color &color) +{ + vtkSmartPointer grid_data = vtkSmartPointer::New(); + + // Add 1 to dimensions because in ImageData dimensions is the number of lines + // - however here it means number of cells + grid_data->SetDimensions(cells[0]+1, cells[1]+1, 1); + grid_data->SetSpacing(cells_spacing[0], cells_spacing[1], 0.); + + // Set origin of the grid to be the middle of the grid + grid_data->SetOrigin(cells[0] * cells_spacing[0] * (-0.5), cells[1] * cells_spacing[1] * (-0.5), 0); + + // Extract the edges so we have the grid + vtkSmartPointer extract_edges = vtkSmartPointer::New(); + VtkUtils::SetInputData(extract_edges, grid_data); + extract_edges->Update(); + + vtkSmartPointer polydata = extract_edges->GetOutput(); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WGrid::WGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, const Vec2i &cells, const Vec2d &cells_spacing, const Color &color) +{ + Vec3d zvec = normalize(normal); + Vec3d xvec = normalize(new_yaxis.cross(zvec)); + Vec3d yvec = zvec.cross(xvec); + + WGrid grid(cells, cells_spacing, color); + grid.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center)); + *this = grid; +} + +template<> cv::viz::WGrid cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// text3D widget implementation + +cv::viz::WText3D::WText3D(const String &text, const Point3d &position, double text_scale, bool face_camera, const Color &color) +{ + vtkSmartPointer textSource = vtkSmartPointer::New(); + textSource->SetText(text.c_str()); + textSource->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(textSource->GetOutputPort()); + + if (face_camera) + { + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->SetPosition(position.x, position.y, position.z); + actor->SetScale(text_scale); + WidgetAccessor::setProp(*this, actor); + } + else + { + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->SetPosition(position.x, position.y, position.z); + actor->SetScale(text_scale); + actor->GetProperty()->LightingOff(); + WidgetAccessor::setProp(*this, actor); + } + + setColor(color); +} + +void cv::viz::WText3D::setText(const String &text) +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support text." && actor); + + // Update text source + vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); + CV_Assert("This widget does not support text." && textSource); + + textSource->SetText(text.c_str()); + textSource->Modified(); + textSource->Update(); +} + +cv::String cv::viz::WText3D::getText() const +{ + vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support text." && actor); + + vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); + CV_Assert("This widget does not support text." && textSource); + + return textSource->GetText(); +} + +template<> cv::viz::WText3D cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// text widget implementation + +cv::viz::WText::WText(const String &text, const Point &pos, int font_size, const Color &color) +{ + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetDisplayPosition(pos.x, pos.y); + actor->SetInput(text.c_str()); + + actor->GetProperty()->SetDisplayLocationToForeground(); + + vtkSmartPointer tprop = actor->GetTextProperty(); + tprop->SetFontSize(font_size); + tprop->SetFontFamilyToCourier(); + tprop->SetJustificationToLeft(); + tprop->BoldOn(); + + Color c = vtkcolor(color); + tprop->SetColor(c.val); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WText cv::viz::Widget::cast() +{ + Widget2D widget = this->cast(); + return static_cast(widget); +} + +void cv::viz::WText::setText(const String &text) +{ + vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support text." && actor); + actor->SetInput(text.c_str()); +} + +cv::String cv::viz::WText::getText() const +{ + vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support text." && actor); + return actor->GetInput(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// image overlay widget implementation + +cv::viz::WImageOverlay::WImageOverlay(InputArray image, const Rect &rect) +{ + CV_Assert(!image.empty() && image.depth() == CV_8U); + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetImage(image); + Size sz = image.size(); + + // Scale the image based on the Rect, and flip to match y-ais orientation + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->Scale(sz.width/(double)rect.width, sz.height/(double)rect.height, 1.0); + transform->RotateX(180); + + vtkSmartPointer image_reslice = vtkSmartPointer::New(); + image_reslice->SetResliceTransform(transform); + image_reslice->SetInputConnection(source->GetOutputPort()); + image_reslice->SetOutputDimensionality(2); + image_reslice->InterpolateOn(); + image_reslice->AutoCropOutputOn(); + image_reslice->Update(); + + vtkSmartPointer image_mapper = vtkSmartPointer::New(); + image_mapper->SetInputConnection(image_reslice->GetOutputPort()); + image_mapper->SetColorWindow(255); // OpenCV color + image_mapper->SetColorLevel(127.5); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(image_mapper); + actor->SetPosition(rect.x, rect.y); + actor->GetProperty()->SetDisplayLocationToForeground(); + + WidgetAccessor::setProp(*this, actor); +} + +void cv::viz::WImageOverlay::setImage(InputArray image) +{ + CV_Assert(!image.empty() && image.depth() == CV_8U); + + vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support overlay image." && actor); + + vtkImageMapper *mapper = vtkImageMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("This widget does not support overlay image." && mapper); + \ + Vec6i extent; + mapper->GetInput()->GetExtent(extent.val); + Size size(extent[1], extent[3]); + + // Create the vtk image and set its parameters based on input image + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetImage(image); + Size sz = image.size(); + + // Scale the image based on the Rect, and flip to match y-ais orientation + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->Scale(sz.width/(double)size.width, sz.height/(double)size.height, 1.0); + transform->RotateX(180); + + vtkSmartPointer image_reslice = vtkSmartPointer::New(); + image_reslice->SetResliceTransform(transform); + image_reslice->SetInputConnection(source->GetOutputPort()); + image_reslice->SetOutputDimensionality(2); + image_reslice->InterpolateOn(); + image_reslice->AutoCropOutputOn(); + image_reslice->Update(); + + mapper->SetInputConnection(image_reslice->GetOutputPort()); +} + +template<> cv::viz::WImageOverlay cv::viz::Widget::cast() +{ + Widget2D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// image 3D widget implementation + +cv::viz::WImage3D::WImage3D(InputArray image, const Size2d &size) +{ + CV_Assert(!image.empty() && image.depth() == CV_8U); + + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetImage(image); + + vtkSmartPointer texture = vtkSmartPointer::New(); + texture->SetInputConnection(source->GetOutputPort()); + + vtkSmartPointer plane = vtkSmartPointer::New(); + plane->SetOrigin(-0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint1( 0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint2(-0.5 * size.width, 0.5 * size.height, 0.0); + + vtkSmartPointer textured_plane = vtkSmartPointer::New(); + textured_plane->SetInputConnection(plane->GetOutputPort()); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(textured_plane->GetOutputPort()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->SetTexture(texture); + actor->GetProperty()->ShadingOff(); + actor->GetProperty()->LightingOff(); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WImage3D::WImage3D(InputArray image, const Size2d &size, const Vec3d ¢er, const Vec3d &normal, const Vec3d &up_vector) +{ + CV_Assert(!image.empty() && image.depth() == CV_8U); + + // Compute the transformation matrix for drawing the camera frame in a scene + Vec3d n = normalize(normal); + Vec3d u = normalize(up_vector.cross(n)); + Vec3d v = n.cross(u); + Affine3d pose = makeTransformToGlobal(u, v, n, center); + + WImage3D image3d(image, size); + image3d.applyTransform(pose); + *this = image3d; +} + +void cv::viz::WImage3D::setImage(InputArray image) +{ + CV_Assert(!image.empty() && image.depth() == CV_8U); + + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("This widget does not support 3D image." && actor); + + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetImage(image); + + vtkSmartPointer texture = vtkSmartPointer::New(); + texture->SetInputConnection(source->GetOutputPort()); + + actor->SetTexture(texture); +} + +template<> cv::viz::WImage3D cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// camera position widget implementation + +namespace cv { namespace viz { namespace +{ + struct CameraPositionUtils + { + static vtkSmartPointer createFrustum(double aspect_ratio, double fovy, double scale) + { + vtkSmartPointer camera = vtkSmartPointer::New(); + camera->SetViewAngle(fovy); + camera->SetPosition(0.0, 0.0, 0.0); + camera->SetViewUp(0.0, 1.0, 0.0); + camera->SetFocalPoint(0.0, 0.0, 1.0); + camera->SetClippingRange(1e-9, scale); + + double planes_array[24]; + camera->GetFrustumPlanes(aspect_ratio, planes_array); + + vtkSmartPointer planes = vtkSmartPointer::New(); + planes->SetFrustumPlanes(planes_array); + + vtkSmartPointer frustumSource = vtkSmartPointer::New(); + frustumSource->SetPlanes(planes); + + vtkSmartPointer extract_edges = vtkSmartPointer::New(); + extract_edges->SetInputConnection(frustumSource->GetOutputPort()); + extract_edges->Update(); + + return extract_edges->GetOutput(); + } + + static Mat ensureColorImage(InputArray image) + { + Mat color(image.size(), CV_8UC3); + if (image.channels() == 1) + { + Vec3b *drow = color.ptr(); + for(int y = 0; y < color.rows; ++y) + { + const unsigned char *srow = image.getMat().ptr(y); + const unsigned char *send = srow + color.cols; + for(;srow < send;) + *drow++ = Vec3b::all(*srow++); + } + } + else + image.getMat().copyTo(color); + return color; + } + }; +}}} + +cv::viz::WCameraPosition::WCameraPosition(double scale) +{ + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, getPolyData(WCoordinateSystem(scale))); + mapper->SetScalarModeToUsePointData(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const Color &color) +{ + double f_x = K(0,0), f_y = K(1,1), c_y = K(1,2); + + // Assuming that this is an ideal camera (c_y and c_x are at the center of the image) + double fovy = 2.0 * atan2(c_y, f_y) * 180 / CV_PI; + double aspect_ratio = f_y / f_x; + + vtkSmartPointer polydata = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const Color &color) +{ + double aspect_ratio = tan(fov[0] * 0.5) / tan(fov[1] * 0.5); + double fovy = fov[1] * 180 / CV_PI; + + vtkSmartPointer polydata = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale); + VtkUtils::FillScalars(polydata, color); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, polydata); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, InputArray _image, double scale, const Color &color) +{ + CV_Assert(!_image.empty() && _image.depth() == CV_8U); + Mat image = CameraPositionUtils::ensureColorImage(_image); + image.at(0, 0) = Vec3d(color.val); //workaround of VTK limitation + + double f_y = K(1,1), c_y = K(1,2); + // Assuming that this is an ideal camera (c_y and c_x are at the center of the image) + double fovy = 2.0 * atan2(c_y, f_y) * 180.0 / CV_PI; + double far_end_height = 2.00 * c_y * scale / f_y; + double aspect_ratio = image.cols/(double)image.rows; + double image_scale = far_end_height/image.rows; + + WImage3D image_widget(image, Size2d(image.cols, image.rows) * image_scale); + image_widget.applyTransform(Affine3d().translate(Vec3d(0, 0, scale))); + vtkSmartPointer plane = getPolyData(image_widget); + + vtkSmartPointer frustum = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale); + + // Frustum needs to be textured or else it can't be combined with image + vtkSmartPointer frustum_texture = vtkSmartPointer::New(); + VtkUtils::SetInputData(frustum_texture, frustum); + frustum_texture->SetSRange(0.0, 0.0); // Texture mapping with only one pixel + frustum_texture->SetTRange(0.0, 0.0); // from the image to have constant color + + vtkSmartPointer append_filter = vtkSmartPointer::New(); + append_filter->AddInputConnection(frustum_texture->GetOutputPort()); + VtkUtils::AddInputData(append_filter, plane); + + vtkSmartPointer actor = getActor(image_widget); + actor->GetMapper()->SetInputConnection(append_filter->GetOutputPort()); + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, InputArray _image, double scale, const Color &color) +{ + CV_Assert(!_image.empty() && _image.depth() == CV_8U); + Mat image = CameraPositionUtils::ensureColorImage(_image); + image.at(0, 0) = Vec3d(color.val); //workaround of VTK limitation + + double fovy = fov[1] * 180.0 / CV_PI; + double far_end_height = 2.0 * scale * tan(fov[1] * 0.5); + double aspect_ratio = image.cols/(double)image.rows; + double image_scale = far_end_height/image.rows; + + WImage3D image_widget(image, Size2d(image.cols, image.rows) * image_scale); + image_widget.applyTransform(Affine3d().translate(Vec3d(0, 0, scale))); + vtkSmartPointer plane = getPolyData(image_widget); + + vtkSmartPointer frustum = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale); + + // Frustum needs to be textured or else it can't be combined with image + vtkSmartPointer frustum_texture = vtkSmartPointer::New(); + VtkUtils::SetInputData(frustum_texture, frustum); + frustum_texture->SetSRange(0.0, 0.0); // Texture mapping with only one pixel + frustum_texture->SetTRange(0.0, 0.0); // from the image to have constant color + + vtkSmartPointer append_filter = vtkSmartPointer::New(); + append_filter->AddInputConnection(frustum_texture->GetOutputPort()); + VtkUtils::AddInputData(append_filter, plane); + + vtkSmartPointer actor = getActor(image_widget); + actor->GetMapper()->SetInputConnection(append_filter->GetOutputPort()); + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WCameraPosition cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// trajectory widget implementation + +cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double scale, const Color &color) +{ + vtkSmartPointer append_filter = vtkSmartPointer::New(); + + // Bitwise and with 3 in order to limit the domain to 2 bits + if (display_mode & WTrajectory::PATH) + { + Mat points = vtkTrajectorySource::ExtractPoints(_path); + vtkSmartPointer polydata = getPolyData(WPolyLine(points, color)); + VtkUtils::AddInputData(append_filter, polydata); + } + + if (display_mode & WTrajectory::FRAMES) + { + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetTrajectory(_path); + + vtkSmartPointer glyph = getPolyData(WCoordinateSystem(scale)); + + vtkSmartPointer tensor_glyph = vtkSmartPointer::New(); + tensor_glyph->SetInputConnection(source->GetOutputPort()); + VtkUtils::SetSourceData(tensor_glyph, glyph); + tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues + tensor_glyph->ThreeGlyphsOff(); + tensor_glyph->SymmetricOff(); + tensor_glyph->ColorGlyphsOff(); + + append_filter->AddInputConnection(tensor_glyph->GetOutputPort()); + } + append_filter->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, append_filter->GetOutput()); + mapper->SetScalarModeToUsePointData(); + mapper->SetScalarRange(0, 255); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WTrajectory cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// WTrajectoryFrustums widget implementation + +cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Matx33d &K, double scale, const Color &color) +{ + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetTrajectory(_path); + + vtkSmartPointer glyph = getPolyData(WCameraPosition(K, scale)); + VtkUtils::FillScalars(glyph, color); + + vtkSmartPointer tensor_glyph = vtkSmartPointer::New(); + tensor_glyph->SetInputConnection(source->GetOutputPort()); + VtkUtils::SetSourceData(tensor_glyph, glyph); + tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues + tensor_glyph->ThreeGlyphsOff(); + tensor_glyph->SymmetricOff(); + tensor_glyph->ColorGlyphsOff(); + tensor_glyph->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Vec2d &fov, double scale, const Color &color) +{ + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetTrajectory(_path); + + vtkSmartPointer glyph = getPolyData(WCameraPosition(fov, scale)); + VtkUtils::FillScalars(glyph, color); + + vtkSmartPointer tensor_glyph = vtkSmartPointer::New(); + tensor_glyph->SetInputConnection(source->GetOutputPort()); + VtkUtils::SetSourceData(tensor_glyph, glyph); + tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues + tensor_glyph->ThreeGlyphsOff(); + tensor_glyph->SymmetricOff(); + tensor_glyph->ColorGlyphsOff(); + tensor_glyph->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WTrajectoryFrustums cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// WTrajectorySpheres widget implementation + +cv::viz::WTrajectorySpheres::WTrajectorySpheres(InputArray _path, double line_length, double radius, const Color &from, const Color &to) +{ + CV_Assert(_path.kind() == _InputArray::STD_VECTOR || _path.kind() == _InputArray::MAT); + CV_Assert(_path.type() == CV_32FC(16) || _path.type() == CV_64FC(16)); + + Mat path64; + _path.getMat().convertTo(path64, CV_64F); + Affine3d *traj = path64.ptr(); + size_t total = path64.total(); + + vtkSmartPointer append_filter = vtkSmartPointer::New(); + + for(size_t i = 0; i < total; ++i) + { + Vec3d curr = traj[i].translation(); + + vtkSmartPointer sphere_source = vtkSmartPointer::New(); + sphere_source->SetCenter(curr.val); + sphere_source->SetRadius( (i == 0) ? 2 * radius : radius ); + sphere_source->Update(); + + double alpha = static_cast(i)/total; + Color c = from * (1 - alpha) + to * alpha; + + vtkSmartPointer polydata = sphere_source->GetOutput(); + polydata->GetCellData()->SetScalars(VtkUtils::FillScalars(polydata->GetNumberOfCells(), c)); + VtkUtils::AddInputData(append_filter, polydata); + + if (i > 0) + { + Vec3d prev = traj[i-1].translation(); + Vec3d lvec = prev - curr; + + if(norm(lvec) > line_length) + lvec = normalize(lvec) * line_length; + + Vec3d lend = curr + lvec; + + vtkSmartPointer line_source = vtkSmartPointer::New(); + line_source->SetPoint1(curr.val); + line_source->SetPoint2(lend.val); + line_source->Update(); + vtkSmartPointer polydata_ = line_source->GetOutput(); + polydata_->GetCellData()->SetScalars(VtkUtils::FillScalars(polydata_->GetNumberOfCells(), c)); + VtkUtils::AddInputData(append_filter, polydata_); + } + } + append_filter->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetScalarModeToUseCellData(); + VtkUtils::SetInputData(mapper, append_filter->GetOutput()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + WidgetAccessor::setProp(*this, actor); +} + +template<> cv::viz::WTrajectorySpheres cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp new file mode 100644 index 000000000..2e32a6327 --- /dev/null +++ b/modules/viz/src/types.cpp @@ -0,0 +1,206 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +//////////////////////////////////////////////////////////////////// +/// Events + +cv::viz::KeyboardEvent::KeyboardEvent(Action _action, const String& _symbol, unsigned char _code, int _modifiers) + : action(_action), symbol(_symbol), code(_code), modifiers(_modifiers) {} + +cv::viz::MouseEvent::MouseEvent(const Type& _type, const MouseButton& _button, const Point& _pointer, int _modifiers) + : type(_type), button(_button), pointer(_pointer), modifiers(_modifiers) {} + +//////////////////////////////////////////////////////////////////// +/// cv::viz::Mesh3d + +cv::viz::Mesh cv::viz::Mesh::load(const String& file) +{ + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName(file.c_str()); + reader->Update(); + + vtkSmartPointer polydata = reader->GetOutput(); + CV_Assert("File does not exist or file format is not supported." && polydata); + + Mesh mesh; + vtkSmartPointer sink = vtkSmartPointer::New(); + sink->SetOutput(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords); + sink->SetInputConnection(reader->GetOutputPort()); + sink->Write(); + + // Now handle the polygons + vtkSmartPointer polygons = polydata->GetPolys(); + mesh.polygons.create(1, polygons->GetSize(), CV_32SC1); + int* poly_ptr = mesh.polygons.ptr(); + + polygons->InitTraversal(); + vtkIdType nr_cell_points, *cell_points; + while (polygons->GetNextCell(nr_cell_points, cell_points)) + { + *poly_ptr++ = nr_cell_points; + for (vtkIdType i = 0; i < nr_cell_points; ++i) + *poly_ptr++ = (int)cell_points[i]; + } + + return mesh; +} + +//////////////////////////////////////////////////////////////////// +/// Camera implementation + +cv::viz::Camera::Camera(double fx, double fy, double cx, double cy, const Size &window_size) +{ + init(fx, fy, cx, cy, window_size); +} + +cv::viz::Camera::Camera(const Vec2d &fov, const Size &window_size) +{ + CV_Assert(window_size.width > 0 && window_size.height > 0); + setClip(Vec2d(0.01, 1000.01)); // Default clipping + setFov(fov); + window_size_ = window_size; + // Principal point at the center + principal_point_ = Vec2f(static_cast(window_size.width)*0.5f, static_cast(window_size.height)*0.5f); + focal_ = Vec2f(principal_point_[0] / tan(fov_[0]*0.5f), principal_point_[1] / tan(fov_[1]*0.5f)); +} + +cv::viz::Camera::Camera(const cv::Matx33d & K, const Size &window_size) +{ + double f_x = K(0,0); + double f_y = K(1,1); + double c_x = K(0,2); + double c_y = K(1,2); + init(f_x, f_y, c_x, c_y, window_size); +} + +cv::viz::Camera::Camera(const Matx44d &proj, const Size &window_size) +{ + CV_Assert(window_size.width > 0 && window_size.height > 0); + + double near = proj(2,3) / (proj(2,2) - 1.0); + double far = near * (proj(2,2) - 1.0) / (proj(2,2) + 1.0); + double left = near * (proj(0,2)-1) / proj(0,0); + double right = 2.0 * near / proj(0,0) + left; + double bottom = near * (proj(1,2)-1) / proj(1,1); + double top = 2.0 * near / proj(1,1) + bottom; + + double epsilon = 2.2204460492503131e-16; + + principal_point_[0] = fabs(left-right) < epsilon ? window_size.width * 0.5 : (left * window_size.width) / (left - right); + principal_point_[1] = fabs(top-bottom) < epsilon ? window_size.height * 0.5 : (top * window_size.height) / (top - bottom); + + focal_[0] = -near * principal_point_[0] / left; + focal_[1] = near * principal_point_[1] / top; + + setClip(Vec2d(near, far)); + fov_[0] = atan2(principal_point_[0], focal_[0]) + atan2(window_size.width-principal_point_[0], focal_[0]); + fov_[1] = atan2(principal_point_[1], focal_[1]) + atan2(window_size.height-principal_point_[1], focal_[1]); + + window_size_ = window_size; +} + +void cv::viz::Camera::init(double fx, double fy, double cx, double cy, const Size &window_size) +{ + CV_Assert(window_size.width > 0 && window_size.height > 0); + setClip(Vec2d(0.01, 1000.01));// Default clipping + + fov_[0] = atan2(cx, fx) + atan2(window_size.width - cx, fx); + fov_[1] = atan2(cy, fy) + atan2(window_size.height - cy, fy); + + principal_point_[0] = cx; + principal_point_[1] = cy; + + focal_[0] = fx; + focal_[1] = fy; + + window_size_ = window_size; +} + +void cv::viz::Camera::setWindowSize(const Size &window_size) +{ + CV_Assert(window_size.width > 0 && window_size.height > 0); + + // Get the scale factor and update the principal points + float scalex = static_cast(window_size.width) / static_cast(window_size_.width); + float scaley = static_cast(window_size.height) / static_cast(window_size_.height); + + principal_point_[0] *= scalex; + principal_point_[1] *= scaley; + focal_ *= scaley; + // Vertical field of view is fixed! Update horizontal field of view + fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0])); + + window_size_ = window_size; +} + +void cv::viz::Camera::computeProjectionMatrix(Matx44d &proj) const +{ + double top = clip_[0] * principal_point_[1] / focal_[1]; + double left = -clip_[0] * principal_point_[0] / focal_[0]; + double right = clip_[0] * (window_size_.width - principal_point_[0]) / focal_[0]; + double bottom = -clip_[0] * (window_size_.height - principal_point_[1]) / focal_[1]; + + double temp1 = 2.0 * clip_[0]; + double temp2 = 1.0 / (right - left); + double temp3 = 1.0 / (top - bottom); + double temp4 = 1.0 / (clip_[0] - clip_[1]); + + proj = Matx44d::zeros(); + proj(0,0) = temp1 * temp2; + proj(1,1) = temp1 * temp3; + proj(0,2) = (right + left) * temp2; + proj(1,2) = (top + bottom) * temp3; + proj(2,2) = (clip_[1]+clip_[0]) * temp4; + proj(3,2) = -1.0; + proj(2,3) = (temp1 * clip_[1]) * temp4; +} + +cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size) +{ + Matx33d K(525.0, 0.0, 320.0, 0.0, 525.0, 240.0, 0.0, 0.0, 1.0); + return Camera(K, window_size); +} diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp new file mode 100644 index 000000000..6e7dfcae7 --- /dev/null +++ b/modules/viz/src/viz3d.cpp @@ -0,0 +1,150 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); } + +cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_) +{ + if (impl_) + CV_XADD(&impl_->ref_counter, 1); +} + +cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other) +{ + if (this != &other) + { + release(); + impl_ = other.impl_; + if (impl_) + CV_XADD(&impl_->ref_counter, 1); + } + return *this; +} + +cv::viz::Viz3d::~Viz3d() { release(); } + +void cv::viz::Viz3d::create(const String &window_name) +{ + if (impl_) + release(); + + if (VizStorage::windowExists(window_name)) + *this = VizStorage::get(window_name); + else + { + impl_ = new VizImpl(window_name); + impl_->ref_counter = 1; + + // Register the window + VizStorage::add(*this); + } +} + +void cv::viz::Viz3d::release() +{ + if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) + { + delete impl_; + impl_ = 0; + } + + if (impl_ && impl_->ref_counter == 1) + VizStorage::removeUnreferenced(); + + impl_ = 0; +} + +void cv::viz::Viz3d::spin() { impl_->spin(); } +void cv::viz::Viz3d::spinOnce(int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); } +bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } +void cv::viz::Viz3d::close() { impl_->close(); } + +void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* cookie) +{ impl_->registerKeyboardCallback(callback, cookie); } + +void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) +{ impl_->registerMouseCallback(callback, cookie); } + +void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose) { impl_->showWidget(id, widget, pose); } +void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } +cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } +void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); } + +void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size) { impl_->showImage(image, window_size); } + +void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); } +void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); } +cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } + +void cv::viz::Viz3d::setCamera(const Camera &camera) { impl_->setCamera(camera); } +cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); } +void cv::viz::Viz3d::setViewerPose(const Affine3d &pose) { impl_->setViewerPose(pose); } +cv::Affine3d cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); } + +void cv::viz::Viz3d::resetCameraViewpoint(const String &id) { impl_->resetCameraViewpoint(id); } +void cv::viz::Viz3d::resetCamera() { impl_->resetCamera(); } + +void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) { impl_->convertToWindowCoordinates(pt, window_coord); } +void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); } + +cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); } +void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size); } +cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } +void cv::viz::Viz3d::saveScreenshot(const String &file) { impl_->saveScreenshot(file); } +void cv::viz::Viz3d::setWindowPosition(const Point& window_position) { impl_->setWindowPosition(window_position); } +void cv::viz::Viz3d::setFullScreen(bool mode) { impl_->setFullScreen(mode); } +void cv::viz::Viz3d::setBackgroundColor(const Color& color, const Color& color2) { impl_->setBackgroundColor(color, color2); } + +void cv::viz::Viz3d::setBackgroundTexture(InputArray image) { impl_->setBackgroundTexture(image); } +void cv::viz::Viz3d::setBackgroundMeshLab() {impl_->setBackgroundMeshLab(); } + +void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double value) { getWidget(id).setRenderingProperty(property, value); } +double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); } + +void cv::viz::Viz3d::setRepresentation(int representation) { impl_->setRepresentation(representation); } + +void cv::viz::Viz3d::setGlobalWarnings(bool enabled) { vtkObject::SetGlobalWarningDisplay(enabled ? 1 : 0); } diff --git a/modules/viz/src/vizcore.cpp b/modules/viz/src/vizcore.cpp new file mode 100644 index 000000000..a33a192c6 --- /dev/null +++ b/modules/viz/src/vizcore.cpp @@ -0,0 +1,352 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +cv::Affine3d cv::viz::makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin) +{ + Affine3d::Mat3 R(axis_x[0], axis_y[0], axis_z[0], + axis_x[1], axis_y[1], axis_z[1], + axis_x[2], axis_y[2], axis_z[2]); + + return Affine3d(R, origin); +} + +cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir) +{ + // Compute the transformation matrix for drawing the camera frame in a scene + Vec3d n = normalize(focal_point - position); + Vec3d u = normalize(y_dir.cross(n)); + Vec3d v = n.cross(u); + + return makeTransformToGlobal(u, v, n, position); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// VizStorage implementation + +#if defined(_WIN32) && !defined(__CYGWIN__) + + #include + + static BOOL WINAPI ConsoleHandlerRoutine(DWORD /*dwCtrlType*/) + { + vtkObject::GlobalWarningDisplayOff(); + return FALSE; + } + + static void register_console_handler() + { + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO hOutInfo; + if (GetConsoleScreenBufferInfo(hOut, &hOutInfo)) + SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE); + } + +#else + + void register_console_handler(); + void register_console_handler() {} + +#endif + + +cv::viz::VizStorage cv::viz::VizStorage::init; +cv::viz::VizMap cv::viz::VizStorage::storage; + +void cv::viz::VizMap::replace_clear() { type().swap(m); } +cv::viz::VizMap::~VizMap() { replace_clear(); } + +cv::viz::VizStorage::VizStorage() +{ + register_console_handler(); +} +void cv::viz::VizStorage::unregisterAll() { storage.replace_clear(); } + +cv::viz::Viz3d& cv::viz::VizStorage::get(const String &window_name) +{ + String name = generateWindowName(window_name); + VizMap::iterator vm_itr = storage.m.find(name); + CV_Assert(vm_itr != storage.m.end()); + return vm_itr->second; +} + +void cv::viz::VizStorage::add(const Viz3d& window) +{ + String window_name = window.getWindowName(); + VizMap::iterator vm_itr = storage.m.find(window_name); + CV_Assert(vm_itr == storage.m.end()); + storage.m.insert(std::make_pair(window_name, window)); +} + +bool cv::viz::VizStorage::windowExists(const String &window_name) +{ + String name = generateWindowName(window_name); + return storage.m.find(name) != storage.m.end(); +} + +void cv::viz::VizStorage::removeUnreferenced() +{ + for(VizMap::iterator pos = storage.m.begin(); pos != storage.m.end();) + if(pos->second.impl_->ref_counter == 1) + storage.m.erase(pos++); + else + ++pos; +} + +cv::String cv::viz::VizStorage::generateWindowName(const String &window_name) +{ + String output = "Viz"; + // Already is Viz + if (window_name == output) + return output; + + String prefixed = output + " - "; + if (window_name.substr(0, prefixed.length()) == prefixed) + output = window_name; // Already has "Viz - " + else if (window_name.substr(0, output.length()) == output) + output = prefixed + window_name; // Doesn't have prefix + else + output = (window_name == "" ? output : prefixed + window_name); + + return output; +} + +cv::viz::Viz3d cv::viz::getWindowByName(const String &window_name) { return Viz3d (window_name); } +void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); } + +cv::viz::Viz3d cv::viz::imshow(const String& window_name, InputArray image, const Size& window_size) +{ + Viz3d viz = getWindowByName(window_name); + viz.showImage(image, window_size); + return viz; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Read/write clouds. Supported formats: ply, stl, xyz, obj + +void cv::viz::writeCloud(const String& file, InputArray cloud, InputArray colors, InputArray normals, bool binary) +{ + CV_Assert(file.size() > 4 && "Extention is required"); + String extention = file.substr(file.size()-4); + + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetColorCloudNormals(cloud, colors, normals); + + vtkSmartPointer writer; + if (extention == ".xyz") + { + writer = vtkSmartPointer::New(); + vtkXYZWriter::SafeDownCast(writer)->SetFileName(file.c_str()); + } + else if (extention == ".ply") + { + writer = vtkSmartPointer::New(); + vtkPLYWriter::SafeDownCast(writer)->SetFileName(file.c_str()); + vtkPLYWriter::SafeDownCast(writer)->SetFileType(binary ? VTK_BINARY : VTK_ASCII); + vtkPLYWriter::SafeDownCast(writer)->SetArrayName("Colors"); + } + else if (extention == ".obj") + { + writer = vtkSmartPointer::New(); + vtkOBJWriter::SafeDownCast(writer)->SetFileName(file.c_str()); + } + else + CV_Assert(!"Unsupported format"); + + writer->SetInputConnection(source->GetOutputPort()); + writer->Write(); +} + +cv::Mat cv::viz::readCloud(const String& file, OutputArray colors, OutputArray normals) +{ + CV_Assert(file.size() > 4 && "Extention is required"); + String extention = file.substr(file.size()-4); + + vtkSmartPointer reader; + if (extention == ".xyz") + { + reader = vtkSmartPointer::New(); + vtkXYZReader::SafeDownCast(reader)->SetFileName(file.c_str()); + } + else if (extention == ".ply") + { + reader = vtkSmartPointer::New(); + CV_Assert(vtkPLYReader::CanReadFile(file.c_str())); + vtkPLYReader::SafeDownCast(reader)->SetFileName(file.c_str()); + } + else if (extention == ".obj") + { + reader = vtkSmartPointer::New(); + vtkOBJReader::SafeDownCast(reader)->SetFileName(file.c_str()); + } + else if (extention == ".stl") + { + reader = vtkSmartPointer::New(); + vtkSTLReader::SafeDownCast(reader)->SetFileName(file.c_str()); + } + else + CV_Assert(!"Unsupported format"); + + cv::Mat cloud; + + vtkSmartPointer sink = vtkSmartPointer::New(); + sink->SetInputConnection(reader->GetOutputPort()); + sink->SetOutput(cloud, colors, normals); + sink->Write(); + + return cloud; +} + +cv::viz::Mesh cv::viz::readMesh(const String& file) { return Mesh::load(file); } + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Read/write poses and trajectories + +bool cv::viz::readPose(const String& file, Affine3d& pose, const String& tag) +{ + FileStorage fs(file, FileStorage::READ); + if (!fs.isOpened()) + return false; + + Mat hdr(pose.matrix, false); + fs[tag] >> hdr; + if (hdr.empty() || hdr.cols != pose.matrix.cols || hdr.rows != pose.matrix.rows) + return false; + + hdr.convertTo(pose.matrix, CV_64F); + return true; +} + +void cv::viz::writePose(const String& file, const Affine3d& pose, const String& tag) +{ + FileStorage fs(file, FileStorage::WRITE); + fs << tag << Mat(pose.matrix, false); +} + +void cv::viz::readTrajectory(OutputArray _traj, const String& files_format, int start, int end, const String& tag) +{ + CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); + + start = max(0, std::min(start, end)); + end = std::max(start, end); + + std::vector traj; + + for(int i = start; i < end; ++i) + { + Affine3d affine; + bool ok = readPose(cv::format(files_format.c_str(), i), affine, tag); + if (!ok) + break; + + traj.push_back(affine); + } + + Mat(traj).convertTo(_traj, _traj.depth()); +} + +void cv::viz::writeTrajectory(InputArray _traj, const String& files_format, int start, const String& tag) +{ + if (_traj.kind() == _InputArray::STD_VECTOR_MAT) + { +#if CV_MAJOR_VERSION < 3 + std::vector& v = *(std::vector*)_traj.obj; +#else + std::vector& v = *(std::vector*)_traj.getObj(); +#endif + + for(size_t i = 0, index = max(0, start); i < v.size(); ++i, ++index) + { + Affine3d affine; + Mat pose = v[i]; + CV_Assert(pose.type() == CV_32FC(16) || pose.type() == CV_64FC(16)); + pose.copyTo(affine.matrix); + writePose(cv::format(files_format.c_str(), index), affine, tag); + } + return; + } + + if (_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT) + { + CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); + + Mat traj = _traj.getMat(); + + if (traj.depth() == CV_32F) + for(size_t i = 0, index = max(0, start); i < traj.total(); ++i, ++index) + writePose(cv::format(files_format.c_str(), index), traj.at((int)i), tag); + + if (traj.depth() == CV_64F) + for(size_t i = 0, index = max(0, start); i < traj.total(); ++i, ++index) + writePose(cv::format(files_format.c_str(), index), traj.at((int)i), tag); + return; + } + + CV_Assert(!"Unsupported array kind"); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// Computing normals for mesh + +void cv::viz::computeNormals(const Mesh& mesh, OutputArray _normals) +{ + vtkSmartPointer polydata = getPolyData(WMesh(mesh)); + vtkSmartPointer with_normals = VtkUtils::ComputeNormals(polydata); + + vtkSmartPointer generic_normals = with_normals->GetPointData()->GetNormals(); + if(generic_normals) + { + Mat normals(1, generic_normals->GetNumberOfTuples(), CV_64FC3); + Vec3d *optr = normals.ptr(); + + for(int i = 0; i < generic_normals->GetNumberOfTuples(); ++i, ++optr) + generic_normals->GetTuple(i, optr->val); + + normals.convertTo(_normals, mesh.cloud.type()); + } + else + _normals.release(); +} diff --git a/modules/viz/src/vizimpl.cpp b/modules/viz/src/vizimpl.cpp new file mode 100644 index 000000000..ab621ad16 --- /dev/null +++ b/modules/viz/src/vizimpl.cpp @@ -0,0 +1,553 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false), + window_position_(Vec2i(std::numeric_limits::min())), widget_actor_map_(new WidgetActorMap) +{ + renderer_ = vtkSmartPointer::New(); + window_name_ = VizStorage::generateWindowName(name); + + // Create render window + window_ = vtkSmartPointer::New(); + cv::Vec2i window_size = cv::Vec2i(window_->GetScreenSize()) / 2; + window_->SetSize(window_size.val); + window_->AddRenderer(renderer_); + + // Create the interactor style + style_ = vtkSmartPointer::New(); + style_->setWidgetActorMap(widget_actor_map_); + style_->UseTimersOn(); + + timer_callback_ = vtkSmartPointer::New(); + exit_callback_ = vtkSmartPointer::New(); + exit_callback_->viz = this; + + setBackgroundMeshLab(); +} + +cv::viz::Viz3d::VizImpl::~VizImpl() { close(); } + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie) +{ + if (event_id == vtkCommand::TimerEvent && timer_id == *reinterpret_cast(cookie)) + { + vtkSmartPointer interactor = vtkRenderWindowInteractor::SafeDownCast(caller); + interactor->TerminateApp(); + } +} + +void cv::viz::Viz3d::VizImpl::ExitCallback::Execute(vtkObject*, unsigned long event_id, void*) +{ + if (event_id == vtkCommand::ExitEvent) + { + viz->interactor_->TerminateApp(); + viz->interactor_ = 0; + } +} + +///////////////////////////////////////////////////////////////////////////////////////////// + +bool cv::viz::Viz3d::VizImpl::wasStopped() const +{ + bool stopped = spin_once_state_ ? interactor_ == 0 : false; + spin_once_state_ &= !stopped; + return stopped; +} + +void cv::viz::Viz3d::VizImpl::close() +{ + if (!interactor_) + return; + interactor_->GetRenderWindow()->Finalize(); + interactor_->TerminateApp(); // This tends to close the window... + interactor_ = 0; +} + +void cv::viz::Viz3d::VizImpl::recreateRenderWindow() +{ +#if !defined _MSC_VER && !defined __APPLE__ + //recreating is workaround for Ubuntu -- a crash in x-server + Vec2i window_size(window_->GetSize()); + int fullscreen = window_->GetFullScreen(); + + window_->Finalize(); + window_ = vtkSmartPointer::New(); + if (window_position_[0] != std::numeric_limits::min()) //also workaround + window_->SetPosition(window_position_.val); + + window_->SetSize(window_size.val); + window_->SetFullScreen(fullscreen); + window_->AddRenderer(renderer_); +#endif +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::spin() +{ + recreateRenderWindow(); +#if defined __APPLE__ + interactor_ = vtkCocoaRenderWindowInteractorNew(); +#else + interactor_ = vtkSmartPointer::New(); +#endif + interactor_->SetRenderWindow(window_); + interactor_->SetInteractorStyle(style_); + window_->AlphaBitPlanesOff(); + window_->PointSmoothingOff(); + window_->LineSmoothingOff(); + window_->PolygonSmoothingOff(); + window_->SwapBuffersOn(); + window_->SetStereoTypeToAnaglyph(); + window_->Render(); + window_->SetWindowName(window_name_.c_str()); + interactor_->Start(); + interactor_ = 0; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::spinOnce(int time, bool force_redraw) +{ + if (interactor_ == 0) + { + spin_once_state_ = true; + recreateRenderWindow(); +#if defined __APPLE__ + interactor_ = vtkCocoaRenderWindowInteractorNew(); +#else + interactor_ = vtkSmartPointer::New(); +#endif + interactor_->SetRenderWindow(window_); + interactor_->SetInteractorStyle(style_); + interactor_->AddObserver(vtkCommand::TimerEvent, timer_callback_); + interactor_->AddObserver(vtkCommand::ExitEvent, exit_callback_); + window_->AlphaBitPlanesOff(); + window_->PointSmoothingOff(); + window_->LineSmoothingOff(); + window_->PolygonSmoothingOff(); + window_->SwapBuffersOn(); + window_->SetStereoTypeToAnaglyph(); + window_->Render(); + window_->SetWindowName(window_name_.c_str()); + } + + vtkSmartPointer local = interactor_; + + if (force_redraw) + local->Render(); + + timer_callback_->timer_id = local->CreateRepeatingTimer(std::max(1, time)); + local->Start(); + local->DestroyTimer(timer_callback_->timer_id); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3d &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + if (exists) + { + // Remove it if it exists and add it again + removeActorFromRenderer(wam_itr->second); + } + // Get the actor and set the user matrix + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); + if (actor) + { + // If the actor is 3D, apply pose + vtkSmartPointer matrix = vtkmatrix(pose.matrix); + actor->SetUserMatrix(matrix); + actor->Modified(); + } + // If the actor is a vtkFollower, then it should always face the camera + vtkFollower *follower = vtkFollower::SafeDownCast(actor); + if (follower) + { + follower->SetCamera(renderer_->GetActiveCamera()); + } + + renderer_->AddActor(WidgetAccessor::getProp(widget)); + (*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert("Widget does not exist." && exists); + CV_Assert("Widget could not be removed." && removeActorFromRenderer(wam_itr->second)); + widget_actor_map_->erase(wam_itr); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const +{ + WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert("Widget does not exist." && exists); + + Widget widget; + WidgetAccessor::setProp(widget, wam_itr->second); + return widget; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3d &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert("Widget does not exist." && exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert("Widget is not 3D." && actor); + + vtkSmartPointer matrix = vtkmatrix(pose.matrix); + actor->SetUserMatrix(matrix); + actor->Modified(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3d &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert("Widget does not exist." && exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert("Widget is not 3D." && actor); + + vtkSmartPointer matrix = actor->GetUserMatrix(); + if (!matrix) + { + setWidgetPose(id, pose); + return ; + } + Affine3d updated_pose = pose * Affine3d(*matrix->Element); + matrix = vtkmatrix(updated_pose.matrix); + + actor->SetUserMatrix(matrix); + actor->Modified(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::Affine3d cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const +{ + WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert("Widget does not exist." && exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert("Widget is not 3D." && actor); + + return Affine3d(*actor->GetUserMatrix()->Element); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::saveScreenshot(const String &file) { style_->saveScreenshot(file.c_str()); } + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::registerMouseCallback(MouseCallback callback, void* cookie) +{ style_->registerMouseCallback(callback, cookie); } + +void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(KeyboardCallback callback, void* cookie) +{ style_->registerKeyboardCallback(callback, cookie); } + + +////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::removeAllWidgets() +{ + widget_actor_map_->clear(); + renderer_->RemoveAllViewProps(); +} +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::showImage(InputArray image, const Size& window_size) +{ + removeAllWidgets(); + if (window_size.width > 0 && window_size.height > 0) + setWindowSize(window_size); + + showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize()))); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer(vtkSmartPointer actor) +{ + vtkPropCollection* actors = renderer_->GetViewProps(); + actors->InitTraversal(); + vtkProp* current_actor = NULL; + while ((current_actor = actors->GetNextProp()) != NULL) + if (current_actor == actor) + { + renderer_->RemoveActor(actor); + return true; + } + return false; +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color, const Color& color2) +{ + Color c = vtkcolor(color), c2 = vtkcolor(color2); + bool gradient = color2[0] >= 0 && color2[1] >= 0 && color2[2] >= 0; + + if (gradient) + { + renderer_->SetBackground(c2.val); + renderer_->SetBackground2(c.val); + renderer_->GradientBackgroundOn(); + } + else + { + renderer_->SetBackground(c.val); + renderer_->GradientBackgroundOff(); + } +} + +void cv::viz::Viz3d::VizImpl::setBackgroundMeshLab() +{ setBackgroundColor(Color(2, 1, 1), Color(240, 120, 120)); } + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setBackgroundTexture(InputArray image) +{ + if (image.empty()) + { + renderer_->SetBackgroundTexture(0); + renderer_->TexturedBackgroundOff(); + return; + } + + vtkSmartPointer source = vtkSmartPointer::New(); + source->SetImage(image); + + vtkSmartPointer image_flip = vtkSmartPointer::New(); + image_flip->SetFilteredAxis(1); // Vertical flip + image_flip->SetInputConnection(source->GetOutputPort()); + + vtkSmartPointer texture = vtkSmartPointer::New(); + texture->SetInputConnection(image_flip->GetOutputPort()); + //texture->Update(); + + renderer_->SetBackgroundTexture(texture); + renderer_->TexturedBackgroundOn(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) +{ + vtkSmartPointer active_camera = renderer_->GetActiveCamera(); + + // Set the intrinsic parameters of the camera + window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height); + double aspect_ratio = static_cast(camera.getWindowSize().width)/static_cast(camera.getWindowSize().height); + + Matx44d proj_mat; + camera.computeProjectionMatrix(proj_mat); + + // Use the intrinsic parameters of the camera to simulate more realistically + vtkSmartPointer vtk_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0, 1.0); + Matx44d old_proj_mat(*vtk_matrix->Element); + + // This is a hack around not being able to set Projection Matrix + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->SetMatrix(vtkmatrix(proj_mat * old_proj_mat.inv())); + active_camera->SetUserTransform(transform); + + renderer_->ResetCameraClippingRange(); + renderer_->Render(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const +{ + vtkSmartPointer active_camera = renderer_->GetActiveCamera(); + + Size window_size(renderer_->GetRenderWindow()->GetSize()[0], + renderer_->GetRenderWindow()->GetSize()[1]); + double aspect_ratio = window_size.width / (double)window_size.height; + + vtkSmartPointer proj_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f); + return Camera(Matx44d(*proj_matrix->Element), window_size); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3d &pose) +{ + vtkCamera& camera = *renderer_->GetActiveCamera(); + + // Position = extrinsic translation + cv::Vec3d pos_vec = pose.translation(); + + // Rotate the view vector + cv::Matx33d rotation = pose.rotation(); + cv::Vec3d y_axis(0.0, -1.0, 0.0); // In Computer Vision Camera Y-axis is oriented down + cv::Vec3d up_vec(rotation * y_axis); + + // Compute the new focal point + cv::Vec3d z_axis(0.0, 0.0, 1.0); + cv::Vec3d focal_vec = pose * z_axis; + + camera.SetPosition(pos_vec.val); + camera.SetFocalPoint(focal_vec.val); + camera.SetViewUp(up_vec.val); + + renderer_->ResetCameraClippingRange(); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::Affine3d cv::viz::Viz3d::VizImpl::getViewerPose() +{ + vtkCamera& camera = *renderer_->GetActiveCamera(); + + Vec3d pos(camera.GetPosition()); + Vec3d view_up(camera.GetViewUp()); + Vec3d focal(camera.GetFocalPoint()); + + Vec3d y_axis = normalized(-view_up); // In Computer Vision Camera Y-axis is oriented down + Vec3d z_axis = normalized(focal - pos); + Vec3d x_axis = normalized(y_axis.cross(z_axis)); + + return makeTransformToGlobal(x_axis, y_axis, z_axis, pos); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) +{ + Vec3d window_pt; + vtkInteractorObserver::ComputeWorldToDisplay(renderer_, pt.x, pt.y, pt.z, window_pt.val); + window_coord = window_pt; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) +{ + Vec4d world_pt; + vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val); + Vec3d cam_pos(renderer_->GetActiveCamera()->GetPosition()); + origin = cam_pos; + direction = normalize(Vec3d(world_pt.val) - cam_pos); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::resetCameraViewpoint(const String &id) +{ + vtkSmartPointer camera_pose; + static WidgetActorMap::iterator it = widget_actor_map_->find(id); + if (it != widget_actor_map_->end()) + { + vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); + CV_Assert("Widget is not 3D." && actor); + camera_pose = actor->GetUserMatrix(); + } + else + return; + + // Prevent a segfault + if (!camera_pose) return; + + vtkSmartPointer cam = renderer_->GetActiveCamera(); + cam->SetPosition(camera_pose->GetElement(0, 3), + camera_pose->GetElement(1, 3), + camera_pose->GetElement(2, 3)); + + cam->SetFocalPoint(camera_pose->GetElement(0, 3) - camera_pose->GetElement(0, 2), + camera_pose->GetElement(1, 3) - camera_pose->GetElement(1, 2), + camera_pose->GetElement(2, 3) - camera_pose->GetElement(2, 2)); + + cam->SetViewUp(camera_pose->GetElement(0, 1), + camera_pose->GetElement(1, 1), + camera_pose->GetElement(2, 1)); + + renderer_->SetActiveCamera(cam); + renderer_->ResetCameraClippingRange(); + renderer_->Render(); +} + +/////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::resetCamera() +{ + renderer_->ResetCamera(); +} + +/////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setRepresentation(int representation) +{ + vtkActorCollection * actors = renderer_->GetActors(); + actors->InitTraversal(); + vtkActor * actor; + switch (representation) + { + case REPRESENTATION_POINTS: + { + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToPoints(); + break; + } + case REPRESENTATION_SURFACE: + { + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToSurface(); + break; + } + case REPRESENTATION_WIREFRAME: + { + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToWireframe(); + break; + } + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +cv::String cv::viz::Viz3d::VizImpl::getWindowName() const { return window_name_; } +void cv::viz::Viz3d::VizImpl::setFullScreen(bool mode) { window_->SetFullScreen(mode); } +void cv::viz::Viz3d::VizImpl::setWindowPosition(const Point& position) { window_position_ = position; window_->SetPosition(position.x, position.y); } +void cv::viz::Viz3d::VizImpl::setWindowSize(const Size& window_size) { window_->SetSize(window_size.width, window_size.height); } +cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(Point(Vec2i(window_->GetSize()))); } diff --git a/modules/viz/src/vizimpl.hpp b/modules/viz/src/vizimpl.hpp new file mode 100644 index 000000000..92113afa0 --- /dev/null +++ b/modules/viz/src/vizimpl.hpp @@ -0,0 +1,138 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__ +#define __OPENCV_VIZ_VIZ3D_IMPL_HPP__ + +struct cv::viz::Viz3d::VizImpl +{ +public: + typedef Viz3d::KeyboardCallback KeyboardCallback; + typedef Viz3d::MouseCallback MouseCallback; + + int ref_counter; + + VizImpl(const String &name); + virtual ~VizImpl(); + + bool wasStopped() const; + void close(); + + void spin(); + void spinOnce(int time = 1, bool force_redraw = false); + + void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; + void removeAllWidgets(); + + void showImage(InputArray image, const Size& window_size); + + void setWidgetPose(const String &id, const Affine3d &pose); + void updateWidgetPose(const String &id, const Affine3d &pose); + Affine3d getWidgetPose(const String &id) const; + + void setRepresentation(int representation); + + void setCamera(const Camera &camera); + Camera getCamera() const; + + /** \brief Reset the camera to a given widget */ + void resetCameraViewpoint(const String& id); + void resetCamera(); + + void setViewerPose(const Affine3d &pose); + Affine3d getViewerPose(); + + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); + void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); + + void saveScreenshot(const String &file); + void setWindowPosition(const Point& position); + Size getWindowSize() const; + void setWindowSize(const Size& window_size); + void setFullScreen(bool mode); + String getWindowName() const; + void setBackgroundColor(const Color& color, const Color& color2); + void setBackgroundTexture(InputArray image); + void setBackgroundMeshLab(); + + void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); + void registerMouseCallback(MouseCallback callback, void* cookie = 0); + +private: + struct TimerCallback : public vtkCommand + { + static TimerCallback* New() { return new TimerCallback; } + virtual void Execute(vtkObject* caller, unsigned long event_id, void* cookie); + int timer_id; + }; + + struct ExitCallback : public vtkCommand + { + static ExitCallback* New() { return new ExitCallback; } + virtual void Execute(vtkObject*, unsigned long event_id, void*); + VizImpl* viz; + }; + + mutable bool spin_once_state_; + vtkSmartPointer interactor_; + + vtkSmartPointer window_; + String window_name_; + Vec2i window_position_; + + vtkSmartPointer timer_callback_; + vtkSmartPointer exit_callback_; + + vtkSmartPointer renderer_; + vtkSmartPointer style_; + Ptr widget_actor_map_; + + bool removeActorFromRenderer(vtkSmartPointer actor); + void recreateRenderWindow(); +}; + +#endif diff --git a/modules/viz/src/vtk/vtkCloudMatSink.cpp b/modules/viz/src/vtk/vtkCloudMatSink.cpp new file mode 100644 index 000000000..8bd101132 --- /dev/null +++ b/modules/viz/src/vtk/vtkCloudMatSink.cpp @@ -0,0 +1,174 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkCloudMatSink); +}} + +cv::viz::vtkCloudMatSink::vtkCloudMatSink() {} +cv::viz::vtkCloudMatSink::~vtkCloudMatSink() {} + +void cv::viz::vtkCloudMatSink::SetOutput(OutputArray _cloud, OutputArray _colors, OutputArray _normals, OutputArray _tcoords) +{ + cloud = _cloud; + colors = _colors; + normals = _normals; + tcoords = _tcoords; +} + +void cv::viz::vtkCloudMatSink::WriteData() +{ + vtkPolyData *input = this->GetInput(); + if (!input) + return; + + vtkSmartPointer points_Data = input->GetPoints(); + + if (cloud.needed() && points_Data) + { + int vtktype = points_Data->GetDataType(); + CV_Assert(vtktype == VTK_FLOAT || vtktype == VTK_DOUBLE); + + cloud.create(1, points_Data->GetNumberOfPoints(), vtktype == VTK_FLOAT ? CV_32FC3 : CV_64FC3); + Vec3d *ddata = cloud.getMat().ptr(); + Vec3f *fdata = cloud.getMat().ptr(); + + if (cloud.depth() == CV_32F) + for(size_t i = 0; i < cloud.total(); ++i) + *fdata++ = Vec3d(points_Data->GetPoint((vtkIdType)i)); + + if (cloud.depth() == CV_64F) + for(size_t i = 0; i < cloud.total(); ++i) + *ddata++ = Vec3d(points_Data->GetPoint((vtkIdType)i)); + } + else + cloud.release(); + + vtkSmartPointer scalars_data = input->GetPointData() ? input->GetPointData()->GetScalars() : 0; + + if (colors.needed() && scalars_data) + { + int channels = scalars_data->GetNumberOfComponents(); + int vtktype = scalars_data->GetDataType(); + + CV_Assert((channels == 3 || channels == 4) && "Only 3- or 4-channel color data support is implemented"); + CV_Assert(cloud.total() == (size_t)scalars_data->GetNumberOfTuples()); + + Mat buffer(cloud.size(), CV_64FC(channels)); + Vec3d *cptr = buffer.ptr(); + for(size_t i = 0; i < buffer.total(); ++i) + *cptr++ = Vec3d(scalars_data->GetTuple((vtkIdType)i)); + + buffer.convertTo(colors, CV_8U, vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE ? 255.0 : 1.0); + } + else + colors.release(); + + vtkSmartPointer normals_data = input->GetPointData() ? input->GetPointData()->GetNormals() : 0; + + if (normals.needed() && normals_data) + { + int channels = normals_data->GetNumberOfComponents(); + int vtktype = normals_data->GetDataType(); + + CV_Assert((vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE) && (channels == 3 || channels == 4)); + CV_Assert(cloud.total() == (size_t)normals_data->GetNumberOfTuples()); + + Mat buffer(cloud.size(), CV_64FC(channels)); + Vec3d *cptr = buffer.ptr(); + for(size_t i = 0; i < buffer.total(); ++i) + *cptr++ = Vec3d(normals_data->GetTuple((vtkIdType)i)); + + buffer.convertTo(normals, vtktype == VTK_FLOAT ? CV_32F : CV_64F); + } + else + normals.release(); + + vtkSmartPointer coords_data = input->GetPointData() ? input->GetPointData()->GetTCoords() : 0; + + if (tcoords.needed() && coords_data) + { + int vtktype = coords_data->GetDataType(); + + CV_Assert(vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE); + CV_Assert(cloud.total() == (size_t)coords_data->GetNumberOfTuples()); + + Mat buffer(cloud.size(), CV_64FC2); + Vec2d *cptr = buffer.ptr(); + for(size_t i = 0; i < buffer.total(); ++i) + *cptr++ = Vec2d(coords_data->GetTuple((vtkIdType)i)); + + buffer.convertTo(tcoords, vtktype == VTK_FLOAT ? CV_32F : CV_64F); + + } + else + tcoords.release(); +} + +void cv::viz::vtkCloudMatSink::PrintSelf(ostream& os, vtkIndent indent) +{ + Superclass::PrintSelf(os, indent); + os << indent << "Cloud: " << cloud.needed() << "\n"; + os << indent << "Colors: " << colors.needed() << "\n"; + os << indent << "Normals: " << normals.needed() << "\n"; +} + +int cv::viz::vtkCloudMatSink::FillInputPortInformation(int, vtkInformation *info) +{ + info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); + return 1; +} + +vtkPolyData* cv::viz::vtkCloudMatSink::GetInput() +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); +} + +vtkPolyData* cv::viz::vtkCloudMatSink::GetInput(int port) +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); +} diff --git a/modules/ocl/perf/perf_norm.cpp b/modules/viz/src/vtk/vtkCloudMatSink.h similarity index 61% rename from modules/ocl/perf/perf_norm.cpp rename to modules/viz/src/vtk/vtkCloudMatSink.h index ff49eb4ed..b3fd3eb71 100644 --- a/modules/ocl/perf/perf_norm.cpp +++ b/modules/viz/src/vtk/vtkCloudMatSink.h @@ -10,14 +10,9 @@ // License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. -// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // -// @Authors -// Fangfang Bai, fangfang@multicorewareinc.com -// Jin Ma, jin@multicorewareinc.com -// // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // @@ -31,7 +26,7 @@ // * 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 +// 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, @@ -42,45 +37,49 @@ // 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. // +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// //M*/ -#include "perf_precomp.hpp" -using namespace perf; -using std::tr1::tuple; -using std::tr1::get; +#ifndef __vtkCloudMatSink_h +#define __vtkCloudMatSink_h -///////////// norm//////////////////////// +#include +#include -typedef tuple normParams; -typedef TestBaseWithParam normFixture; - -PERF_TEST_P(normFixture, norm, testing::Combine( - OCL_TYPICAL_MAT_SIZES, - OCL_PERF_ENUM(CV_8UC1, CV_32FC1))) +namespace cv { - const normParams params = GetParam(); - const Size srcSize = get<0>(params); - const int type = get<1>(params); - double value = 0.0; - const double eps = CV_MAT_DEPTH(type) == CV_8U ? DBL_EPSILON : 1e-3; - - Mat src1(srcSize, type), src2(srcSize, type); - declare.in(src1, src2, WARMUP_RNG); - - if (RUN_OCL_IMPL) + namespace viz { - ocl::oclMat oclSrc1(src1), oclSrc2(src2); + class vtkCloudMatSink : public vtkWriter + { + public: + static vtkCloudMatSink *New(); + vtkTypeMacro(vtkCloudMatSink,vtkWriter) + void PrintSelf(ostream& os, vtkIndent indent); - OCL_TEST_CYCLE() value = cv::ocl::norm(oclSrc1, oclSrc2, NORM_INF); + void SetOutput(OutputArray cloud, OutputArray colors = noArray(), OutputArray normals = noArray(), OutputArray tcoords = noArray()); - SANITY_CHECK(value, eps); + // Description: + // Get the input to this writer. + vtkPolyData* GetInput(); + vtkPolyData* GetInput(int port); + + protected: + vtkCloudMatSink(); + ~vtkCloudMatSink(); + + void WriteData(); + int FillInputPortInformation(int port, vtkInformation *info); + + _OutputArray cloud, colors, normals, tcoords; + + private: + vtkCloudMatSink(const vtkCloudMatSink&); // Not implemented. + void operator=(const vtkCloudMatSink&); // Not implemented. + }; } - else if (RUN_PLAIN_IMPL) - { - TEST_CYCLE() value = cv::norm(src1, src2, NORM_INF); - - SANITY_CHECK(value); - } - else - OCL_PERF_ELSE } + +#endif diff --git a/modules/viz/src/vtk/vtkCloudMatSource.cpp b/modules/viz/src/vtk/vtkCloudMatSource.cpp new file mode 100644 index 000000000..1d8ab7894 --- /dev/null +++ b/modules/viz/src/vtk/vtkCloudMatSource.cpp @@ -0,0 +1,286 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkCloudMatSource); + + template struct VtkDepthTraits; + + template<> struct VtkDepthTraits + { + const static int data_type = VTK_FLOAT; + typedef vtkFloatArray array_type; + }; + + template<> struct VtkDepthTraits + { + const static int data_type = VTK_DOUBLE; + typedef vtkDoubleArray array_type; + }; +}} + +cv::viz::vtkCloudMatSource::vtkCloudMatSource() { SetNumberOfInputPorts(0); } +cv::viz::vtkCloudMatSource::~vtkCloudMatSource() {} + +int cv::viz::vtkCloudMatSource::SetCloud(InputArray _cloud) +{ + CV_Assert(_cloud.depth() == CV_32F || _cloud.depth() == CV_64F); + CV_Assert(_cloud.channels() == 3 || _cloud.channels() == 4); + + Mat cloud = _cloud.getMat(); + + int total = _cloud.depth() == CV_32F ? filterNanCopy(cloud) : filterNanCopy(cloud); + + vertices = vtkSmartPointer::New(); + vertices->Allocate(vertices->EstimateSize(1, total)); + vertices->InsertNextCell(total); + for(int i = 0; i < total; ++i) + vertices->InsertCellPoint(i); + + return total; +} + +int cv::viz::vtkCloudMatSource::SetColorCloud(InputArray _cloud, InputArray _colors) +{ + int total = SetCloud(_cloud); + + if (_colors.empty()) + return total; + + CV_Assert(_colors.depth() == CV_8U && _colors.channels() <= 4 && _colors.channels() != 2); + CV_Assert(_colors.size() == _cloud.size()); + + Mat cloud = _cloud.getMat(); + Mat colors = _colors.getMat(); + + if (cloud.depth() == CV_32F) + filterNanColorsCopy(colors, cloud, total); + else if (cloud.depth() == CV_64F) + filterNanColorsCopy(colors, cloud, total); + + return total; +} + +int cv::viz::vtkCloudMatSource::SetColorCloudNormals(InputArray _cloud, InputArray _colors, InputArray _normals) +{ + int total = SetColorCloud(_cloud, _colors); + + if (_normals.empty()) + return total; + + CV_Assert(_normals.depth() == CV_32F || _normals.depth() == CV_64F); + CV_Assert(_normals.channels() == 3 || _normals.channels() == 4); + CV_Assert(_normals.size() == _cloud.size()); + + Mat c = _cloud.getMat(); + Mat n = _normals.getMat(); + + if (n.depth() == CV_32F && c.depth() == CV_32F) + filterNanNormalsCopy(n, c, total); + else if (n.depth() == CV_32F && c.depth() == CV_64F) + filterNanNormalsCopy(n, c, total); + else if (n.depth() == CV_64F && c.depth() == CV_32F) + filterNanNormalsCopy(n, c, total); + else if (n.depth() == CV_64F && c.depth() == CV_64F) + filterNanNormalsCopy(n, c, total); + else + CV_Assert(!"Unsupported normals/cloud type"); + + return total; +} + +int cv::viz::vtkCloudMatSource::SetColorCloudNormalsTCoords(InputArray _cloud, InputArray _colors, InputArray _normals, InputArray _tcoords) +{ + int total = SetColorCloudNormals(_cloud, _colors, _normals); + + if (_tcoords.empty()) + return total; + + CV_Assert(_tcoords.depth() == CV_32F || _tcoords.depth() == CV_64F); + CV_Assert(_tcoords.channels() == 2 && _tcoords.size() == _cloud.size()); + + Mat cl = _cloud.getMat(); + Mat tc = _tcoords.getMat(); + + if (tc.depth() == CV_32F && cl.depth() == CV_32F) + filterNanTCoordsCopy(tc, cl, total); + else if (tc.depth() == CV_32F && cl.depth() == CV_64F) + filterNanTCoordsCopy(tc, cl, total); + else if (tc.depth() == CV_64F && cl.depth() == CV_32F) + filterNanTCoordsCopy(tc, cl, total); + else if (tc.depth() == CV_64F && cl.depth() == CV_64F) + filterNanTCoordsCopy(tc, cl, total); + else + CV_Assert(!"Unsupported tcoords/cloud type"); + + return total; +} + +int cv::viz::vtkCloudMatSource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) +{ + vtkInformation *outInfo = outputVector->GetInformationObject(0); + vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); + + output->SetPoints(points); + output->SetVerts(vertices); + if (scalars) + output->GetPointData()->SetScalars(scalars); + + if (normals) + output->GetPointData()->SetNormals(normals); + + if (tcoords) + output->GetPointData()->SetTCoords(tcoords); + + return 1; +} + +template +int cv::viz::vtkCloudMatSource::filterNanCopy(const Mat& cloud) +{ + CV_DbgAssert(DataType<_Tp>::depth == cloud.depth()); + points = vtkSmartPointer::New(); + points->SetDataType(VtkDepthTraits<_Tp>::data_type); + points->Allocate((vtkIdType)cloud.total()); + points->SetNumberOfPoints((vtkIdType)cloud.total()); + + int s_chs = cloud.channels(); + int total = 0; + for (int y = 0; y < cloud.rows; ++y) + { + const _Tp* srow = cloud.ptr<_Tp>(y); + const _Tp* send = srow + cloud.cols * s_chs; + + for (; srow != send; srow += s_chs) + if (!isNan(srow)) + points->SetPoint(total++, srow); + } + points->SetNumberOfPoints(total); + points->Squeeze(); + return total; +} + +template +void cv::viz::vtkCloudMatSource::filterNanColorsCopy(const Mat& cloud_colors, const Mat& mask, int total) +{ + Vec3b* array = new Vec3b[total]; + Vec3b* pos = array; + + int s_chs = cloud_colors.channels(); + int m_chs = mask.channels(); + for (int y = 0; y < cloud_colors.rows; ++y) + { + const unsigned char* srow = cloud_colors.ptr(y); + const unsigned char* send = srow + cloud_colors.cols * s_chs; + const _Msk* mrow = mask.ptr<_Msk>(y); + + if (cloud_colors.channels() == 1) + { + for (; srow != send; srow += s_chs, mrow += m_chs) + if (!isNan(mrow)) + *pos++ = Vec3b(srow[0], srow[0], srow[0]); + } + else + for (; srow != send; srow += s_chs, mrow += m_chs) + if (!isNan(mrow)) + *pos++ = Vec3b(srow[2], srow[1], srow[0]); + + } + + scalars = vtkSmartPointer::New(); + scalars->SetName("Colors"); + scalars->SetNumberOfComponents(3); + scalars->SetNumberOfTuples(total); + scalars->SetArray(array->val, total * 3, 0); +} + +template +void cv::viz::vtkCloudMatSource::filterNanNormalsCopy(const Mat& cloud_normals, const Mat& mask, int total) +{ + normals = vtkSmartPointer< typename VtkDepthTraits<_Tn>::array_type >::New(); + normals->SetName("Normals"); + normals->SetNumberOfComponents(3); + normals->SetNumberOfTuples(total); + + int s_chs = cloud_normals.channels(); + int m_chs = mask.channels(); + + int pos = 0; + for (int y = 0; y < cloud_normals.rows; ++y) + { + const _Tn* srow = cloud_normals.ptr<_Tn>(y); + const _Tn* send = srow + cloud_normals.cols * s_chs; + + const _Msk* mrow = mask.ptr<_Msk>(y); + + for (; srow != send; srow += s_chs, mrow += m_chs) + if (!isNan(mrow)) + normals->SetTuple(pos++, srow); + } +} + +template +void cv::viz::vtkCloudMatSource::filterNanTCoordsCopy(const Mat& _tcoords, const Mat& mask, int total) +{ + typedef Vec<_Tn, 2> Vec2; + tcoords = vtkSmartPointer< typename VtkDepthTraits<_Tn>::array_type >::New(); + tcoords->SetName("TextureCoordinates"); + tcoords->SetNumberOfComponents(2); + tcoords->SetNumberOfTuples(total); + + int pos = 0; + for (int y = 0; y < mask.rows; ++y) + { + const Vec2* srow = _tcoords.ptr(y); + const Vec2* send = srow + _tcoords.cols; + const _Msk* mrow = mask.ptr<_Msk>(y); + + for (; srow != send; ++srow, mrow += mask.channels()) + if (!isNan(mrow)) + tcoords->SetTuple(pos++, srow->val); + } +} diff --git a/modules/viz/src/vtk/vtkCloudMatSource.h b/modules/viz/src/vtk/vtkCloudMatSource.h new file mode 100644 index 000000000..4097f9cc8 --- /dev/null +++ b/modules/viz/src/vtk/vtkCloudMatSource.h @@ -0,0 +1,96 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __vtkCloudMatSource_h +#define __vtkCloudMatSource_h + +#include +#include +#include +#include +#include + +namespace cv +{ + namespace viz + { + class vtkCloudMatSource : public vtkPolyDataAlgorithm + { + public: + static vtkCloudMatSource *New(); + vtkTypeMacro(vtkCloudMatSource,vtkPolyDataAlgorithm) + + virtual int SetCloud(InputArray cloud); + virtual int SetColorCloud(InputArray cloud, InputArray colors); + virtual int SetColorCloudNormals(InputArray cloud, InputArray colors, InputArray normals); + virtual int SetColorCloudNormalsTCoords(InputArray cloud, InputArray colors, InputArray normals, InputArray tcoords); + + protected: + vtkCloudMatSource(); + ~vtkCloudMatSource(); + + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + + vtkSmartPointer points; + vtkSmartPointer vertices; + vtkSmartPointer scalars; + vtkSmartPointer normals; + vtkSmartPointer tcoords; + private: + vtkCloudMatSource(const vtkCloudMatSource&); // Not implemented. + void operator=(const vtkCloudMatSource&); // Not implemented. + + template int filterNanCopy(const Mat& cloud); + template void filterNanColorsCopy(const Mat& cloud_colors, const Mat& mask, int total); + + template + void filterNanNormalsCopy(const Mat& cloud_normals, const Mat& mask, int total); + + template + void filterNanTCoordsCopy(const Mat& tcoords, const Mat& mask, int total); + }; + } +} + +#endif diff --git a/modules/viz/src/vtk/vtkCocoaInteractorFix.mm b/modules/viz/src/vtk/vtkCocoaInteractorFix.mm new file mode 100644 index 000000000..dad41b073 --- /dev/null +++ b/modules/viz/src/vtk/vtkCocoaInteractorFix.mm @@ -0,0 +1,211 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +// This workaround code was taken from PCL library(www.pointclouds.org) +// +//M*/ + +#import +#include +#include +#include +#include + +//---------------------------------------------------------------------------- +@interface vtkCocoaServerFix : NSObject +{ + vtkCocoaRenderWindow* renWin; +} + ++ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow*)inRenderWindow; + +- (void)start; +- (void)stop; +- (void)breakEventLoop; + +@end + +//---------------------------------------------------------------------------- +@implementation vtkCocoaServerFix + +//---------------------------------------------------------------------------- +- (id)initWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow +{ + self = [super init]; + if (self) + renWin = inRenderWindow; + return self; +} + +//---------------------------------------------------------------------------- ++ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow +{ + vtkCocoaServerFix *server = [[[vtkCocoaServerFix alloc] initWithRenderWindow:inRenderWindow] autorelease]; + return server; +} + +//---------------------------------------------------------------------------- +- (void)start +{ + // Retrieve the NSWindow. + NSWindow *win = nil; + if (renWin) + { + win = reinterpret_cast (renWin->GetRootWindow ()); + + // We don't want to be informed of every window closing, so check for nil. + if (win != nil) + { + // Register for the windowWillClose notification in order to stop the run loop if the window closes. + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:win]; + } + } + // Start the NSApplication's run loop + NSApplication* application = [NSApplication sharedApplication]; + [application run]; +} + +//---------------------------------------------------------------------------- +- (void)stop +{ + [self breakEventLoop]; +} + +//---------------------------------------------------------------------------- +- (void)breakEventLoop +{ + NSApplication* application = [NSApplication sharedApplication]; + [application stop:application]; + + NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined + location:NSMakePoint(0.0,0.0) + modifierFlags:0 + timestamp:0 + windowNumber:-1 + context:nil + subtype:0 + data1:0 + data2:0]; + [application postEvent:event atStart:YES]; +} + +//---------------------------------------------------------------------------- +- (void)windowWillClose:(NSNotification*)aNotification +{ + (void)aNotification; + + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc removeObserver:self name:NSWindowWillCloseNotification object:nil]; + + if (renWin) + { + int windowCreated = renWin->GetWindowCreated (); + if (windowCreated) + { + [self breakEventLoop]; + + // The NSWindow is closing, so prevent anyone from accidently using it + renWin->SetRootWindow(NULL); + } + } +} + +@end + +//---------------------------------------------------------------------------- + +namespace cv { namespace viz +{ + class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor + { + public: + static vtkCocoaRenderWindowInteractorFix *New (); + vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor) + + virtual void Start (); + virtual void TerminateApp (); + + protected: + vtkCocoaRenderWindowInteractorFix () {} + ~vtkCocoaRenderWindowInteractorFix () {} + + private: + vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented. + void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented. + }; + + vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix) + + vtkSmartPointer vtkCocoaRenderWindowInteractorNew(); +}} + +void cv::viz::vtkCocoaRenderWindowInteractorFix::Start () +{ + vtkCocoaRenderWindow* renWin = vtkCocoaRenderWindow::SafeDownCast(this->GetRenderWindow ()); + if (renWin != NULL) + { + vtkCocoaServerFix *server = reinterpret_cast (this->GetCocoaServer ()); + if (!this->GetCocoaServer ()) + { + server = [vtkCocoaServerFix cocoaServerWithRenderWindow:renWin]; + this->SetCocoaServer (reinterpret_cast (server)); + } + + [server start]; + } +} + +void cv::viz::vtkCocoaRenderWindowInteractorFix::TerminateApp () +{ + vtkCocoaRenderWindow *renWin = vtkCocoaRenderWindow::SafeDownCast (this->RenderWindow); + if (renWin) + { + vtkCocoaServerFix *server = reinterpret_cast (this->GetCocoaServer ()); + [server stop]; + } +} + +vtkSmartPointer cv::viz::vtkCocoaRenderWindowInteractorNew() +{ + return vtkSmartPointer::New(); +} diff --git a/modules/viz/src/vtk/vtkImageMatSource.cpp b/modules/viz/src/vtk/vtkImageMatSource.cpp new file mode 100644 index 000000000..58a5642d4 --- /dev/null +++ b/modules/viz/src/vtk/vtkImageMatSource.cpp @@ -0,0 +1,143 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkImageMatSource); +}} + +cv::viz::vtkImageMatSource::vtkImageMatSource() +{ + this->SetNumberOfInputPorts(0); + this->ImageData = vtkImageData::New(); +} + +int cv::viz::vtkImageMatSource::RequestInformation(vtkInformation *, vtkInformationVector**, vtkInformationVector *outputVector) +{ + vtkInformation* outInfo = outputVector->GetInformationObject(0); + + outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->ImageData->GetExtent(), 6); + outInfo->Set(vtkDataObject::SPACING(), 1.0, 1.0, 1.0); + outInfo->Set(vtkDataObject::ORIGIN(), 0.0, 0.0, 0.0); + + vtkDataObject::SetPointDataActiveScalarInfo(outInfo, this->ImageData->GetScalarType(), this->ImageData->GetNumberOfScalarComponents()); + return 1; +} + +int cv::viz::vtkImageMatSource::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector *outputVector) +{ + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + vtkImageData *output = vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()) ); + output->ShallowCopy(this->ImageData); + return 1; +} + +void cv::viz::vtkImageMatSource::SetImage(InputArray _image) +{ + CV_Assert(_image.depth() == CV_8U && (_image.channels() == 1 || _image.channels() == 3 || _image.channels() == 4)); + + Mat image = _image.getMat(); + + this->ImageData->SetDimensions(image.cols, image.rows, 1); +#if VTK_MAJOR_VERSION <= 5 + this->ImageData->SetNumberOfScalarComponents(image.channels()); + this->ImageData->SetScalarTypeToUnsignedChar(); + this->ImageData->AllocateScalars(); +#else + this->ImageData->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels()); +#endif + + switch(image.channels()) + { + case 1: copyGrayImage(image, this->ImageData); break; + case 3: copyRGBImage (image, this->ImageData); break; + case 4: copyRGBAImage(image, this->ImageData); break; + } + this->ImageData->Modified(); +} + +void cv::viz::vtkImageMatSource::copyGrayImage(const Mat &source, vtkSmartPointer output) +{ + unsigned char* dptr = reinterpret_cast(output->GetScalarPointer()); + size_t elem_step = output->GetIncrements()[1]/sizeof(unsigned char); + + for (int y = 0; y < source.rows; ++y) + { + unsigned char* drow = dptr + elem_step * y; + const unsigned char *srow = source.ptr(y); + for (int x = 0; x < source.cols; ++x) + drow[x] = *srow++; + } +} + +void cv::viz::vtkImageMatSource::copyRGBImage(const Mat &source, vtkSmartPointer output) +{ + Vec3b* dptr = reinterpret_cast(output->GetScalarPointer()); + size_t elem_step = output->GetIncrements()[1]/sizeof(Vec3b); + + for (int y = 0; y < source.rows; ++y) + { + Vec3b* drow = dptr + elem_step * y; + const unsigned char *srow = source.ptr(y); + for (int x = 0; x < source.cols; ++x, srow += source.channels()) + drow[x] = Vec3b(srow[2], srow[1], srow[0]); + } +} + +void cv::viz::vtkImageMatSource::copyRGBAImage(const Mat &source, vtkSmartPointer output) +{ + Vec4b* dptr = reinterpret_cast(output->GetScalarPointer()); + size_t elem_step = output->GetIncrements()[1]/sizeof(Vec4b); + + for (int y = 0; y < source.rows; ++y) + { + Vec4b* drow = dptr + elem_step * y; + const unsigned char *srow = source.ptr(y); + for (int x = 0; x < source.cols; ++x, srow += source.channels()) + drow[x] = Vec4b(srow[2], srow[1], srow[0], srow[3]); + } +} diff --git a/modules/ocl/src/opencl/arithm_bitwise_binary_scalar_mask.cl b/modules/viz/src/vtk/vtkImageMatSource.h similarity index 55% rename from modules/ocl/src/opencl/arithm_bitwise_binary_scalar_mask.cl rename to modules/viz/src/vtk/vtkImageMatSource.h index 756f20165..db0c093ed 100644 --- a/modules/ocl/src/opencl/arithm_bitwise_binary_scalar_mask.cl +++ b/modules/viz/src/vtk/vtkImageMatSource.h @@ -10,13 +10,9 @@ // 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. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // -// @Authors -// Jiang Liyuan, jlyuan001.good@163.com -// // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // @@ -30,7 +26,7 @@ // * 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 +// 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, @@ -41,46 +37,46 @@ // 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. // +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// //M*/ -////////////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////bitwise_binary//////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////////////////////////////// +#include "precomp.hpp" -__kernel void arithm_bitwise_binary_scalar_mask(__global uchar *src1, int src1_step, int src1_offset, - __global uchar *src2, - __global uchar *mask, int mask_step, int mask_offset, - __global uchar *dst, int dst_step, int dst_offset, - int cols, int rows) +#ifndef __vtkImageMatSource_h +#define __vtkImageMatSource_h + +namespace cv { - int x = get_global_id(0); - int y = get_global_id(1); - - if (x < cols && y < rows) + namespace viz { - int mask_index = mad24(y, mask_step, x + mask_offset); - - if (mask[mask_index]) + class vtkImageMatSource : public vtkImageAlgorithm { -#if elemSize > 1 - x *= elemSize; -#endif - int src1_index = mad24(y, src1_step, x + src1_offset); - int dst_index = mad24(y, dst_step, x + dst_offset); + public: + static vtkImageMatSource *New(); + vtkTypeMacro(vtkImageMatSource,vtkImageAlgorithm); -#if elemSize > 1 - #pragma unroll - for (int i = 0; i < elemSize; i += vlen) - { - ucharv t0 = vloadn(0, src1 + src1_index + i); - ucharv t1 = vloadn(0, src2 + i); - ucharv t2 = t0 Operation t1; + void SetImage(InputArray image); - vstoren(t2, 0, dst + dst_index + i); - } -#else - dst[dst_index] = src1[src1_index] Operation src2[0]; -#endif - } + protected: + vtkImageMatSource(); + ~vtkImageMatSource() {} + + vtkSmartPointer ImageData; + + int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*); + int RequestData (vtkInformation*, vtkInformationVector**, vtkInformationVector*); + private: + vtkImageMatSource(const vtkImageMatSource&); // Not implemented. + void operator=(const vtkImageMatSource&); // Not implemented. + + static void copyGrayImage(const Mat &source, vtkSmartPointer output); + static void copyRGBImage (const Mat &source, vtkSmartPointer output); + static void copyRGBAImage(const Mat &source, vtkSmartPointer output); + }; } } + + +#endif diff --git a/modules/viz/src/vtk/vtkOBJWriter.cpp b/modules/viz/src/vtk/vtkOBJWriter.cpp new file mode 100644 index 000000000..7480b11ac --- /dev/null +++ b/modules/viz/src/vtk/vtkOBJWriter.cpp @@ -0,0 +1,270 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkOBJWriter); +}} + +cv::viz::vtkOBJWriter::vtkOBJWriter() +{ + std::ofstream fout; // only used to extract the default precision + this->DecimalPrecision = fout.precision(); + this->FileName = NULL; +} + +cv::viz::vtkOBJWriter::~vtkOBJWriter(){} + +void cv::viz::vtkOBJWriter::WriteData() +{ + vtkPolyData *input = this->GetInput(); + if (!input) + return; + + if (!this->FileName ) + { + vtkErrorMacro(<< "No FileName specified! Can't write!"); + this->SetErrorCode(vtkErrorCode::NoFileNameError); + return; + } + + vtkDebugMacro(<<"Opening vtk file for writing..."); + ostream *outfilep = new ofstream(this->FileName, ios::out); + if (outfilep->fail()) + { + vtkErrorMacro(<< "Unable to open file: "<< this->FileName); + this->SetErrorCode(vtkErrorCode::CannotOpenFileError); + delete outfilep; + return; + } + + std::ostream& outfile = *outfilep; + + //write header + outfile << "# wavefront obj file written by opencv viz module" << std::endl << std::endl; + outfile << "mtllib NONE" << std::endl << std::endl; + + // write out the points + for (int i = 0; i < input->GetNumberOfPoints(); i++) + { + Vec3d p; + input->GetPoint(i, p.val); + outfile << std::setprecision(this->DecimalPrecision) << "v " << p[0] << " " << p[1] << " " << p[2] << std::endl; + } + + const int idStart = 1; + + // write out the point data + vtkSmartPointer normals = input->GetPointData()->GetNormals(); + if(normals) + { + for (int i = 0; i < normals->GetNumberOfTuples(); i++) + { + Vec3d p; + normals->GetTuple(i, p.val); + outfile << std::setprecision(this->DecimalPrecision) << "vn " << p[0] << " " << p[1] << " " << p[2] << std::endl; + } + } + + vtkSmartPointer tcoords = input->GetPointData()->GetTCoords(); + if (tcoords) + { + for (int i = 0; i < tcoords->GetNumberOfTuples(); i++) + { + Vec2d p; + tcoords->GetTuple(i, p.val); + outfile << std::setprecision(this->DecimalPrecision) << "vt " << p[0] << " " << p[1] << std::endl; + } + } + + // write out a group name and material + outfile << std::endl << "g grp" << idStart << std::endl; + outfile << "usemtl mtlNONE" << std::endl; + + // write out verts if any + if (input->GetNumberOfVerts() > 0) + { + vtkIdType npts = 0, *index = 0; + vtkCellArray *cells = input->GetVerts(); + for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) + { + outfile << "p "; + for (int i = 0; i < npts; i++) + outfile << index[i] + idStart << " "; + outfile << std::endl; + } + } + + // write out lines if any + if (input->GetNumberOfLines() > 0) + { + vtkIdType npts = 0, *index = 0; + vtkCellArray *cells = input->GetLines(); + for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) + { + outfile << "l "; + if (tcoords) + { + for (int i = 0; i < npts; i++) + outfile << index[i] + idStart << "/" << index[i] + idStart << " "; + } + else + for (int i = 0; i < npts; i++) + outfile << index[i] + idStart << " "; + + outfile << std::endl; + } + } + + // write out polys if any + if (input->GetNumberOfPolys() > 0) + { + vtkIdType npts = 0, *index = 0; + vtkCellArray *cells = input->GetPolys(); + for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) + { + outfile << "f "; + for (int i = 0; i < npts; i++) + { + if (normals) + { + if (tcoords) + outfile << index[i] + idStart << "/" << index[i] + idStart << "/" << index[i] + idStart << " "; + else + outfile << index[i] + idStart << "//" << index[i] + idStart << " "; + } + else + { + if (tcoords) + outfile << index[i] + idStart << " " << index[i] + idStart << " "; + else + outfile << index[i] + idStart << " "; + } + } + outfile << std::endl; + } + } + + // write out tstrips if any + if (input->GetNumberOfStrips() > 0) + { + vtkIdType npts = 0, *index = 0; + vtkCellArray *cells = input->GetStrips(); + for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) + { + for (int i = 2, i1, i2; i < npts; ++i) + { + if (i % 2) + { + i1 = i - 1; + i2 = i - 2; + } + else + { + i1 = i - 1; + i2 = i - 2; + } + + if(normals) + { + if (tcoords) + { + outfile << "f " << index[i1] + idStart << "/" << index[i1] + idStart << "/" << index[i1] + idStart << " " + << index[i2]+ idStart << "/" << index[i2] + idStart << "/" << index[i2] + idStart << " " + << index[i] + idStart << "/" << index[i] + idStart << "/" << index[i] + idStart << std::endl; + } + else + { + outfile << "f " << index[i1] + idStart << "//" << index[i1] + idStart << " " << index[i2] + idStart + << "//" << index[i2] + idStart << " " << index[i] + idStart << "//" << index[i] + idStart << std::endl; + } + } + else + { + if (tcoords) + { + outfile << "f " << index[i1] + idStart << "/" << index[i1] + idStart << " " << index[i2] + idStart + << "/" << index[i2] + idStart << " " << index[i] + idStart << "/" << index[i] + idStart << std::endl; + } + else + outfile << "f " << index[i1] + idStart << " " << index[i2] + idStart << " " << index[i] + idStart << std::endl; + } + } /* for (int i = 2; i < npts; ++i) */ + } + } /* if (input->GetNumberOfStrips() > 0) */ + + vtkDebugMacro(<<"Closing vtk file\n"); + delete outfilep; + + // Delete the file if an error occurred + if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError) + { + vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName); + unlink(this->FileName); + } +} + +void cv::viz::vtkOBJWriter::PrintSelf(ostream& os, vtkIndent indent) +{ + Superclass::PrintSelf(os, indent); + os << indent << "DecimalPrecision: " << DecimalPrecision << "\n"; +} + +int cv::viz::vtkOBJWriter::FillInputPortInformation(int, vtkInformation *info) +{ + info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); + return 1; +} + +vtkPolyData* cv::viz::vtkOBJWriter::GetInput() +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); +} + +vtkPolyData* cv::viz::vtkOBJWriter::GetInput(int port) +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); +} diff --git a/modules/viz/src/vtk/vtkOBJWriter.h b/modules/viz/src/vtk/vtkOBJWriter.h new file mode 100644 index 000000000..7ad0f17b1 --- /dev/null +++ b/modules/viz/src/vtk/vtkOBJWriter.h @@ -0,0 +1,91 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __vtkOBJWriter_h +#define __vtkOBJWriter_h + +#include + +namespace cv +{ + namespace viz + { + class vtkOBJWriter : public vtkWriter + { + public: + static vtkOBJWriter *New(); + vtkTypeMacro(vtkOBJWriter,vtkWriter) + void PrintSelf(ostream& os, vtkIndent indent); + + vtkGetMacro(DecimalPrecision, int) + vtkSetMacro(DecimalPrecision, int) + + // Description: + // Specify file name of data file to write. + vtkSetStringMacro(FileName) + vtkGetStringMacro(FileName) + + // Description: + // Get the input to this writer. + vtkPolyData* GetInput(); + vtkPolyData* GetInput(int port); + + protected: + vtkOBJWriter(); + ~vtkOBJWriter(); + + void WriteData(); + int FillInputPortInformation(int port, vtkInformation *info); + + int DecimalPrecision; + char *FileName; + + private: + vtkOBJWriter(const vtkOBJWriter&); // Not implemented. + void operator=(const vtkOBJWriter&); // Not implemented. + }; + } +} + +#endif diff --git a/modules/viz/src/vtk/vtkTrajectorySource.cpp b/modules/viz/src/vtk/vtkTrajectorySource.cpp new file mode 100644 index 000000000..2036e09af --- /dev/null +++ b/modules/viz/src/vtk/vtkTrajectorySource.cpp @@ -0,0 +1,110 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkTrajectorySource); +}} + +cv::viz::vtkTrajectorySource::vtkTrajectorySource() { SetNumberOfInputPorts(0); } +cv::viz::vtkTrajectorySource::~vtkTrajectorySource() {} + +void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj) +{ + CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); + CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); + + Mat traj; + _traj.getMat().convertTo(traj, CV_64F); + const Affine3d* dpath = traj.ptr(); + size_t total = traj.total(); + + points = vtkSmartPointer::New(); + points->SetDataType(VTK_DOUBLE); + points->SetNumberOfPoints((vtkIdType)total); + + tensors = vtkSmartPointer::New(); + tensors->SetNumberOfComponents(9); + tensors->SetNumberOfTuples((vtkIdType)total); + + for(size_t i = 0; i < total; ++i, ++dpath) + { + Matx33d R = dpath->rotation().t(); // transposed because of + tensors->SetTuple((vtkIdType)i, R.val); // column major order + + Vec3d p = dpath->translation(); + points->SetPoint((vtkIdType)i, p.val); + } +} + +cv::Mat cv::viz::vtkTrajectorySource::ExtractPoints(InputArray _traj) +{ + CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); + CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); + + Mat points(1, (int)_traj.total(), CV_MAKETYPE(_traj.depth(), 3)); + const Affine3d* dpath = _traj.getMat().ptr(); + const Affine3f* fpath = _traj.getMat().ptr(); + + if (_traj.depth() == CV_32F) + for(int i = 0; i < points.cols; ++i) + points.at(i) = fpath[i].translation(); + + if (_traj.depth() == CV_64F) + for(int i = 0; i < points.cols; ++i) + points.at(i) = dpath[i].translation(); + + return points; +} + +int cv::viz::vtkTrajectorySource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) +{ + vtkInformation *outInfo = outputVector->GetInformationObject(0); + vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); + output->SetPoints(points); + output->GetPointData()->SetTensors(tensors); + return 1; +} diff --git a/modules/viz/src/vtk/vtkTrajectorySource.h b/modules/viz/src/vtk/vtkTrajectorySource.h new file mode 100644 index 000000000..f6c9c77b9 --- /dev/null +++ b/modules/viz/src/vtk/vtkTrajectorySource.h @@ -0,0 +1,84 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __vtkTrajectorySource_h +#define __vtkTrajectorySource_h + +#include +#include +#include +#include +#include + +namespace cv +{ + namespace viz + { + class vtkTrajectorySource : public vtkPolyDataAlgorithm + { + public: + static vtkTrajectorySource *New(); + vtkTypeMacro(vtkTrajectorySource,vtkPolyDataAlgorithm) + + virtual void SetTrajectory(InputArray trajectory); + + static Mat ExtractPoints(InputArray trajectory); + + protected: + vtkTrajectorySource(); + ~vtkTrajectorySource(); + + vtkSmartPointer points; + vtkSmartPointer tensors; + + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + private: + vtkTrajectorySource(const vtkTrajectorySource&); // Not implemented. + void operator=(const vtkTrajectorySource&); // Not implemented. + + }; + } +} + +#endif diff --git a/modules/viz/src/vtk/vtkVizInteractorStyle.cpp b/modules/viz/src/vtk/vtkVizInteractorStyle.cpp new file mode 100644 index 000000000..9b5eca2b0 --- /dev/null +++ b/modules/viz/src/vtk/vtkVizInteractorStyle.cpp @@ -0,0 +1,1076 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkVizInteractorStyle) +}} + +////////////////////////////////////////////////////////////////////////////////////////////// + +cv::viz::vtkVizInteractorStyle::vtkVizInteractorStyle() +{ + FlyMode = false; + MotionFactor = 10.0; + + keyboardCallback_ = 0; + keyboard_callback_cookie_ = 0; + + mouseCallback_ = 0; + mouse_callback_cookie_ = 0; + + // Set windows size (width, height) to unknown (-1) + win_size_ = Vec2i(-1, -1); + win_pos_ = Vec2i(0, 0); + max_win_size_ = Vec2i(-1, -1); + + stereo_anaglyph_redblue_ = true; + + //from fly + KeysDown = 0; + UseTimers = 1; + + DiagonalLength = 1.0; + MotionStepSize = 1.0/100.0; + MotionUserScale = 1.0; // +/- key adjustment + MotionAccelerationFactor = 10.0; + AngleStepSize = 1.0; +} + +cv::viz::vtkVizInteractorStyle::~vtkVizInteractorStyle() {} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::saveScreenshot(const String &file) +{ + FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); + + vtkSmartPointer wif = vtkSmartPointer::New(); + wif->SetInput(Interactor->GetRenderWindow()); + + vtkSmartPointer snapshot_writer = vtkSmartPointer::New(); + snapshot_writer->SetInputConnection(wif->GetOutputPort()); + snapshot_writer->SetFileName(file.c_str()); + snapshot_writer->Write(); + + cout << "Screenshot successfully captured (" << file.c_str() << ")" << endl; +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::exportScene(const String &file) +{ + vtkSmartPointer exporter; + if (file.size() > 5 && file.substr(file.size() - 5) == ".vrml") + { + exporter = vtkSmartPointer::New(); + vtkVRMLExporter::SafeDownCast(exporter)->SetFileName(file.c_str()); + } + else + { + exporter = vtkSmartPointer::New(); + vtkOBJExporter::SafeDownCast(exporter)->SetFilePrefix(file.c_str()); + } + + exporter->SetInput(Interactor->GetRenderWindow()); + exporter->Write(); + + cout << "Scene successfully exported (" << file.c_str() << ")" << endl; +} + +void cv::viz::vtkVizInteractorStyle::exportScene() +{ + // Export scene as in obj or vrml format + String format = Interactor->GetAltKey() ? "scene-%d.vrml" : "scene-%d"; + exportScene(cv::format(format.c_str(), (unsigned int)time(0))); +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::changePointsSize(float delta) +{ + vtkSmartPointer ac = CurrentRenderer->GetActors(); + vtkCollectionSimpleIterator ait; + + for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) + for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) + { + vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); + float psize = apart->GetProperty()->GetPointSize() + delta; + psize = std::max(1.f, std::min(63.f, psize)); + apart->GetProperty()->SetPointSize(psize); + } +} + +void cv::viz::vtkVizInteractorStyle::setRepresentationToPoints() +{ + vtkSmartPointer ac = CurrentRenderer->GetActors(); + vtkCollectionSimpleIterator ait; + for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) + for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) + { + vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); + apart->GetProperty()->SetRepresentationToPoints(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::printCameraParams() +{ + vtkSmartPointer cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); + + Vec2d clip(cam->GetClippingRange()); + Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp()); + Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition()); + Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); + double angle = cam->GetViewAngle () / 180.0 * CV_PI; + + String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)", + clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2], + angle, win_size[0], win_size[1], win_pos[0], win_pos[1]); + + std::cout << data.c_str() << std::endl; +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::toggleFullScreen() +{ + Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize()); + Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); + + // Is window size = max? + if (win_size == max_win_size_) + { + Interactor->GetRenderWindow()->SetSize(win_size_.val); + Interactor->GetRenderWindow()->SetPosition(win_pos_.val); + Interactor->Render(); + } + // Set to max + else + { + win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition()); + win_size_ = win_size; + + Interactor->GetRenderWindow()->SetSize(screen_size.val); + Interactor->Render(); + max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::resetViewerPose() +{ + WidgetActorMap::iterator it = widget_actor_map_->begin(); + // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. + for (; it != widget_actor_map_->end(); ++it) + { + vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); + if (actor && actor->GetUserMatrix()) + break; + } + + vtkSmartPointer cam = CurrentRenderer->GetActiveCamera(); + + // if a valid transformation was found, use it otherwise fall back to default view point. + if (it != widget_actor_map_->end()) + { + vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix(); + + cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2), + m->GetElement(1, 3) - m->GetElement(1, 2), + m->GetElement(2, 3) - m->GetElement(2, 2)); + + cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1)); + cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3)); + } + else + { + cam->SetPosition(0, 0, 0); + cam->SetFocalPoint(0, 0, 1); + cam->SetViewUp(0, -1, 0); + } + + // go to the next actor for the next key-press event. + if (it != widget_actor_map_->end()) + ++it; + else + it = widget_actor_map_->begin(); + + CurrentRenderer->SetActiveCamera(cam); + CurrentRenderer->ResetCameraClippingRange(); + Interactor->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::toggleStereo() +{ + vtkSmartPointer window = Interactor->GetRenderWindow(); + if (!window->GetStereoRender()) + { + static Vec2i red_blue(4, 3), magenta_green(2, 5); + window->SetAnaglyphColorMask (stereo_anaglyph_redblue_ ? red_blue.val : magenta_green.val); + stereo_anaglyph_redblue_ = !stereo_anaglyph_redblue_; + } + window->SetStereoRender(!window->GetStereoRender()); + Interactor->Render(); + +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::printHelp() +{ + std::cout << "| Help:\n" + "-------\n" + " p, P : switch to a point-based representation\n" + " w, W : switch to a wireframe-based representation (where available)\n" + " s, S : switch to a surface-based representation (where available)\n" + "\n" + " j, J : take a .PNG snapshot of the current window view\n" + " k, K : export scene to Wavefront .obj format\n" + " ALT + k, K : export scene to VRML format\n" + " c, C : display current camera/window parameters\n" + " F5 : enable/disable fly mode (changes control style)\n" + "\n" + " e, E : exit the interactor\n" + " q, Q : stop and call VTK's TerminateApp\n" + "\n" + " +/- : increment/decrement overall point size\n" + " +/- [+ ALT] : zoom in/out \n" + "\n" + " r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n" + "\n" + " ALT + s, S : turn stereo mode on/off\n" + " ALT + f, F : switch between maximized window mode and original size\n" + "\n" + << std::endl; +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::zoomIn() +{ + FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); + // Zoom in + StartDolly(); + double factor = 10.0 * 0.2 * .5; + Dolly(std::pow(1.1, factor)); + EndDolly(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::zoomOut() +{ + FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); + // Zoom out + StartDolly(); + double factor = 10.0 * -0.2 * .5; + Dolly(std::pow(1.1, factor)); + EndDolly(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnChar() +{ + FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); + + String key(Interactor->GetKeySym()); + if (key.find("XF86ZoomIn") != String::npos) + zoomIn(); + else if (key.find("XF86ZoomOut") != String::npos) + zoomOut(); + + switch (Interactor->GetKeyCode()) + { +// // All of the options below simply exit +// case 'l': case 'L': case 'j': case 'J': case 'c': case 'C': case 'q': case 'Q': +// case 'f': case 'F': case 'g': case 'G': case 'o': case 'O': case 'u': case 'U': + case 'p': case 'P': + break; + + case '+': + if (FlyMode) + MotionUserScale = std::min(16.0, MotionUserScale*2.0); + break; + case '-': + if (FlyMode) + MotionUserScale = std::max(MotionUserScale * 0.5, 0.0625); + break; + + case 'r': case 'R': case 's': case 'S': + if (!Interactor->GetAltKey()) + Superclass::OnChar(); + break; + default: + Superclass::OnChar(); + break; + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie) +{ + mouseCallback_ = callback; + mouse_callback_cookie_ = cookie; +} + +void cv::viz::vtkVizInteractorStyle::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void *cookie) +{ + keyboardCallback_ = callback; + keyboard_callback_cookie_ = cookie; +} + +////////////////////////////////////////////////////////////////////////////////////////////// +int cv::viz::vtkVizInteractorStyle::getModifiers() +{ + int modifiers = KeyboardEvent::NONE; + + if (Interactor->GetAltKey()) + modifiers |= KeyboardEvent::ALT; + + if (Interactor->GetControlKey()) + modifiers |= KeyboardEvent::CTRL; + + if (Interactor->GetShiftKey()) + modifiers |= KeyboardEvent::SHIFT; + return modifiers; +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnKeyDown() +{ + FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); + + String key(Interactor->GetKeySym()); + if (key.find("XF86ZoomIn") != String::npos) + zoomIn(); + else if (key.find("XF86ZoomOut") != String::npos) + zoomOut(); + else if (key.find("F5") != String::npos) + { + FlyMode = !FlyMode; + std::cout << (FlyMode ? "Fly mode: on" : "Fly mode: off") << std::endl; + } + + // Save the initial windows width/height + if (win_size_[0] == -1 || win_size_[1] == -1) + win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); + + switch (Interactor->GetKeyCode()) + { + case 'a': case 'A' : KeysDown |=16; break; + case 'z': case 'Z' : KeysDown |=32; break; + case 'h': case 'H' : printHelp(); break; + case 'p': case 'P' : setRepresentationToPoints(); break; + case 'k': case 'K' : exportScene(); break; + case 'j': case 'J' : saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break; + case 'c': case 'C' : printCameraParams(); break; + case '=': zoomIn(); break; + case 43: // KEY_PLUS + { + if (FlyMode) + break; + if (Interactor->GetAltKey()) + zoomIn(); + else + changePointsSize(+1.f); + break; + } + case 45: // KEY_MINUS + { + if (FlyMode) + break; + if (Interactor->GetAltKey()) + zoomOut(); + else + changePointsSize(-1.f); + break; + } + // Switch between maximize and original window size + case 'f': case 'F': + { + if (Interactor->GetAltKey()) + toggleFullScreen(); + break; + } + // 's'/'S' w/out ALT + case 's': case 'S': + { + if (Interactor->GetAltKey()) + toggleStereo(); + break; + } + + case 'o': case 'O': + { + vtkSmartPointer cam = CurrentRenderer->GetActiveCamera(); + cam->SetParallelProjection(!cam->GetParallelProjection()); + Interactor->Render(); + break; + } + + // Overwrite the camera reset + case 'r': case 'R': + { + if (Interactor->GetAltKey()) + resetViewerPose(); + break; + } + case 'q': case 'Q': + Interactor->ExitCallback(); return; + default: + Superclass::OnKeyDown(); break; + } + + KeyboardEvent event(KeyboardEvent::KEY_DOWN, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers()); + if (keyboardCallback_) + keyboardCallback_(event, keyboard_callback_cookie_); + + if (FlyMode && (KeysDown & (32+16)) == (32+16)) + { + if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY) + StopState(); + } + else if (FlyMode && (KeysDown & 32) == 32) + { + if (State == VTKIS_FORWARDFLY) + StopState(); + + if (State == VTKIS_NONE) + StartState(VTKIS_REVERSEFLY); + } + else if (FlyMode && (KeysDown & 16) == 16) + { + if (State == VTKIS_REVERSEFLY) + StopState(); + + if (State == VTKIS_NONE) + StartState(VTKIS_FORWARDFLY); + } + + Interactor->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnKeyUp() +{ + KeyboardEvent event(KeyboardEvent::KEY_UP, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers()); + if (keyboardCallback_) + keyboardCallback_(event, keyboard_callback_cookie_); + + switch (Interactor->GetKeyCode()) + { + case 'a': case 'A' : KeysDown &= ~16; break; + case 'z': case 'Z' : KeysDown &= ~32; break; + } + + if (State == VTKIS_FORWARDFLY && (KeysDown & 16) == 0) + StopState(); + + if (State == VTKIS_REVERSEFLY && (KeysDown & 32) == 0) + StopState(); + + Superclass::OnKeyUp(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnMouseMove() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseMove, MouseEvent::NoButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + FindPokedRenderer(p[0], p[1]); + + if (State == VTKIS_ROTATE || State == VTKIS_PAN || State == VTKIS_DOLLY || State == VTKIS_SPIN) + { + switch (State) + { + case VTKIS_ROTATE: Rotate(); break; + case VTKIS_PAN: Pan(); break; + case VTKIS_DOLLY: Dolly(); break; + case VTKIS_SPIN: Spin(); break; + } + + InvokeEvent(vtkCommand::InteractionEvent, NULL); + } + + if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY) + { + vtkCamera *cam = CurrentRenderer->GetActiveCamera(); + Vec2i thispos(Interactor->GetEventPosition()); + Vec2i lastpos(Interactor->GetLastEventPosition()); + + // we want to steer by an amount proportional to window viewangle and size + // compute dx and dy increments relative to last mouse click + Vec2i size(Interactor->GetSize()); + double scalefactor = 5*cam->GetViewAngle()/size[0]; + + double dx = - (thispos[0] - lastpos[0])*scalefactor*AngleStepSize; + double dy = (thispos[1] - lastpos[1])*scalefactor*AngleStepSize; + + // Temporary until I get smooth flight working + DeltaPitch = dy; + DeltaYaw = dx; + + InvokeEvent(vtkCommand::InteractionEvent, NULL); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnLeftButtonDown() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; + MouseEvent event(type, MouseEvent::LeftButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + FindPokedRenderer(p[0], p[1]); + if (!CurrentRenderer) + return; + + GrabFocus(EventCallbackCommand); + + if (FlyMode) + { + if(State == VTKIS_REVERSEFLY) + State = VTKIS_FORWARDFLY; + else + { + SetupMotionVars(); + if (State == VTKIS_NONE) + StartState(VTKIS_FORWARDFLY); + } + } + else + { + if (Interactor->GetShiftKey()) + { + if (Interactor->GetControlKey()) + StartDolly(); + else + StartPan(); + } + else + { + if (Interactor->GetControlKey()) + StartSpin(); + else + StartRotate(); + } + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnLeftButtonUp() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::LeftButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + switch (State) + { + case VTKIS_DOLLY: EndDolly(); break; + case VTKIS_PAN: EndPan(); break; + case VTKIS_SPIN: EndSpin(); break; + case VTKIS_ROTATE: EndRotate(); break; + case VTKIS_FORWARDFLY: StopState(); break; + } + + if (Interactor ) + ReleaseFocus(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnMiddleButtonDown() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; + MouseEvent event(type, MouseEvent::MiddleButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + FindPokedRenderer(p[0], p[1]); + if (!CurrentRenderer) + return; + + GrabFocus(EventCallbackCommand); + StartPan(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnMiddleButtonUp() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::MiddleButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if (State == VTKIS_PAN) + { + EndPan(); + if (Interactor) + ReleaseFocus(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnRightButtonDown() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; + MouseEvent event(type, MouseEvent::RightButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + FindPokedRenderer(p[0], p[1]); + if (!CurrentRenderer) + return; + + GrabFocus(EventCallbackCommand); + + if (FlyMode) + { + if (State == VTKIS_FORWARDFLY) + State = VTKIS_REVERSEFLY; + else + { + SetupMotionVars(); + if (State == VTKIS_NONE) + StartState(VTKIS_REVERSEFLY); + } + + } + else + StartDolly(); +} + + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnRightButtonUp() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::RightButton, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if(State == VTKIS_DOLLY) + { + EndDolly(); + if (Interactor) + ReleaseFocus(); + } + + if (State == VTKIS_REVERSEFLY) + { + StopState(); + if (Interactor) + ReleaseFocus(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnMouseWheelForward() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseScrollUp, MouseEvent::VScroll, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + if (Interactor->GetRepeatCount() && mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if (Interactor->GetAltKey()) + { + // zoom + vtkSmartPointer cam = CurrentRenderer->GetActiveCamera(); + double opening_angle = cam->GetViewAngle(); + if (opening_angle > 15.0) + opening_angle -= 1.0; + + cam->SetViewAngle(opening_angle); + cam->Modified(); + CurrentRenderer->ResetCameraClippingRange(); + CurrentRenderer->Modified(); + Interactor->Render(); + } + else + { + FindPokedRenderer(p[0], p[1]); + if (!CurrentRenderer) + return; + + GrabFocus(EventCallbackCommand); + StartDolly(); + Dolly(pow(1.1, MotionFactor * 0.2 * MouseWheelMotionFactor)); + EndDolly(); + ReleaseFocus(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnMouseWheelBackward() +{ + Vec2i p(Interactor->GetEventPosition()); + MouseEvent event(MouseEvent::MouseScrollDown, MouseEvent::VScroll, p, getModifiers()); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if (Interactor->GetRepeatCount() && mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if (Interactor->GetAltKey()) + { + // zoom + vtkSmartPointer cam = CurrentRenderer->GetActiveCamera(); + double opening_angle = cam->GetViewAngle(); + if (opening_angle < 170.0) + opening_angle += 1.0; + + cam->SetViewAngle(opening_angle); + cam->Modified(); + CurrentRenderer->ResetCameraClippingRange(); + CurrentRenderer->Modified(); + Interactor->Render(); + } + else + { + FindPokedRenderer(p[0], p[1]); + if (!CurrentRenderer) + return; + + GrabFocus(EventCallbackCommand); + StartDolly(); + Dolly(pow(1.1, MotionFactor * -0.2 * MouseWheelMotionFactor)); + EndDolly(); + ReleaseFocus(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::OnTimer() +{ + if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY) + Fly(); + + Interactor->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::Rotate() +{ + if (!CurrentRenderer) + return; + + Vec2i dxy = Vec2i(Interactor->GetEventPosition()) - Vec2i(Interactor->GetLastEventPosition()); + Vec2i size(CurrentRenderer->GetRenderWindow()->GetSize()); + + double delta_elevation = -20.0 / size[1]; + double delta_azimuth = -20.0 / size[0]; + + double rxf = dxy[0] * delta_azimuth * MotionFactor; + double ryf = dxy[1] * delta_elevation * MotionFactor; + + vtkCamera *camera = CurrentRenderer->GetActiveCamera(); + camera->Azimuth(rxf); + camera->Elevation(ryf); + camera->OrthogonalizeViewUp(); + + if (AutoAdjustCameraClippingRange) + CurrentRenderer->ResetCameraClippingRange(); + + if (Interactor->GetLightFollowCamera()) + CurrentRenderer->UpdateLightsGeometryToFollowCamera(); + + Interactor->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::Spin() +{ + if (!CurrentRenderer) + return; + + vtkRenderWindowInteractor *rwi = Interactor; + + double *center = CurrentRenderer->GetCenter(); + + double newAngle = vtkMath::DegreesFromRadians( atan2( rwi->GetEventPosition()[1] - center[1], rwi->GetEventPosition()[0] - center[0] ) ); + double oldAngle = vtkMath::DegreesFromRadians( atan2( rwi->GetLastEventPosition()[1] - center[1], rwi->GetLastEventPosition()[0] - center[0] ) ); + + vtkCamera *camera = CurrentRenderer->GetActiveCamera(); + camera->Roll( newAngle - oldAngle ); + camera->OrthogonalizeViewUp(); + + rwi->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::vtkVizInteractorStyle::Pan() +{ + if (!CurrentRenderer) + return; + + vtkRenderWindowInteractor *rwi = Interactor; + + double viewFocus[4], focalDepth, viewPoint[3]; + double newPickPoint[4], oldPickPoint[4], motionVector[3]; + + // Calculate the focal depth since we'll be using it a lot + + vtkCamera *camera = CurrentRenderer->GetActiveCamera(); + camera->GetFocalPoint(viewFocus); + ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2], viewFocus); + focalDepth = viewFocus[2]; + + ComputeDisplayToWorld(rwi->GetEventPosition()[0], rwi->GetEventPosition()[1], focalDepth, newPickPoint); + + // Has to recalc old mouse point since the viewport has moved, so can't move it outside the loop + ComputeDisplayToWorld(rwi->GetLastEventPosition()[0], rwi->GetLastEventPosition()[1], focalDepth, oldPickPoint); + + // Camera motion is reversed + motionVector[0] = oldPickPoint[0] - newPickPoint[0]; + motionVector[1] = oldPickPoint[1] - newPickPoint[1]; + motionVector[2] = oldPickPoint[2] - newPickPoint[2]; + + camera->GetFocalPoint(viewFocus); + camera->GetPosition(viewPoint); + camera->SetFocalPoint(motionVector[0] + viewFocus[0], motionVector[1] + viewFocus[1], motionVector[2] + viewFocus[2]); + camera->SetPosition( motionVector[0] + viewPoint[0], motionVector[1] + viewPoint[1], motionVector[2] + viewPoint[2]); + + if (Interactor->GetLightFollowCamera()) + CurrentRenderer->UpdateLightsGeometryToFollowCamera(); + + Interactor->Render(); +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::Dolly() +{ + if (!CurrentRenderer) + return; + + int dy = Interactor->GetEventPosition()[1] - Interactor->GetLastEventPosition()[1]; + Dolly(pow(1.1, MotionFactor * dy / CurrentRenderer->GetCenter()[1])); +} + +void cv::viz::vtkVizInteractorStyle::Dolly(double factor) +{ + if (!CurrentRenderer) + return; + + vtkCamera *camera = CurrentRenderer->GetActiveCamera(); + if (camera->GetParallelProjection()) + camera->SetParallelScale(camera->GetParallelScale() / factor); + else + { + camera->Dolly(factor); + if (AutoAdjustCameraClippingRange) + CurrentRenderer->ResetCameraClippingRange(); + } + + if (Interactor->GetLightFollowCamera()) + CurrentRenderer->UpdateLightsGeometryToFollowCamera(); + + Interactor->Render(); +} +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::Fly() +{ + if (CurrentRenderer == NULL) + return; + + if (KeysDown) + FlyByKey(); + else + FlyByMouse(); + + CurrentRenderer->GetActiveCamera()->OrthogonalizeViewUp(); + + if (AutoAdjustCameraClippingRange) + CurrentRenderer->ResetCameraClippingRange(); + + if (Interactor->GetLightFollowCamera()) + CurrentRenderer->UpdateLightsGeometryToFollowCamera(); +} + +void cv::viz::vtkVizInteractorStyle::SetupMotionVars() +{ + Vec6d bounds; + CurrentRenderer->ComputeVisiblePropBounds(bounds.val); + + if ( !vtkMath::AreBoundsInitialized(bounds.val) ) + DiagonalLength = 1.0; + else + DiagonalLength = norm(Vec3d(bounds[0], bounds[2], bounds[4]) - Vec3d(bounds[1], bounds[3], bounds[5])); +} + +void cv::viz::vtkVizInteractorStyle::MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam) +{ + // move camera and focus along DirectionOfProjection + Vec3d campos = Vec3d(cam->GetPosition()) - amount * vector; + Vec3d camfoc = Vec3d(cam->GetFocalPoint()) - amount * vector; + + cam->SetPosition(campos.val); + cam->SetFocalPoint(camfoc.val); +} + +void cv::viz::vtkVizInteractorStyle::FlyByMouse() +{ + vtkCamera* cam = CurrentRenderer->GetActiveCamera(); + double speed = DiagonalLength * MotionStepSize * MotionUserScale; + speed = speed * ( Interactor->GetShiftKey() ? MotionAccelerationFactor : 1.0); + + // Sidestep + if (Interactor->GetAltKey()) + { + if (DeltaYaw!=0.0) + { + vtkMatrix4x4 *vtm = cam->GetViewTransformMatrix(); + Vec3d a_vector(vtm->GetElement(0,0), vtm->GetElement(0,1), vtm->GetElement(0,2)); + + MotionAlongVector(a_vector, -DeltaYaw*speed, cam); + } + if (DeltaPitch!=0.0) + { + Vec3d a_vector(cam->GetViewUp()); + MotionAlongVector(a_vector, DeltaPitch*speed, cam); + } + } + else + { + cam->Yaw(DeltaYaw); + cam->Pitch(DeltaPitch); + DeltaYaw = 0; + DeltaPitch = 0; + } + // + if (!Interactor->GetControlKey()) + { + Vec3d a_vector(cam->GetDirectionOfProjection()); // reversed (use -speed) + switch (State) + { + case VTKIS_FORWARDFLY: MotionAlongVector(a_vector, -speed, cam); break; + case VTKIS_REVERSEFLY: MotionAlongVector(a_vector, speed, cam); break; + } + } +} + +void cv::viz::vtkVizInteractorStyle::FlyByKey() +{ + vtkCamera* cam = CurrentRenderer->GetActiveCamera(); + + double speed = DiagonalLength * MotionStepSize * MotionUserScale; + speed = speed * ( Interactor->GetShiftKey() ? MotionAccelerationFactor : 1.0); + + // Left and right + if (Interactor->GetAltKey()) + { // Sidestep + vtkMatrix4x4 *vtm = cam->GetViewTransformMatrix(); + Vec3d a_vector(vtm->GetElement(0,0), vtm->GetElement(0,1), vtm->GetElement(0,2)); + + if (KeysDown & 1) + MotionAlongVector(a_vector, -speed, cam); + + if (KeysDown & 2) + MotionAlongVector(a_vector, speed, cam); + } + else + { + if (KeysDown & 1) + cam->Yaw( AngleStepSize); + + if (KeysDown & 2) + cam->Yaw(-AngleStepSize); + } + + // Up and Down + if (Interactor->GetControlKey()) + { // Sidestep + Vec3d a_vector = Vec3d(cam->GetViewUp()); + if (KeysDown & 4) + MotionAlongVector(a_vector,-speed, cam); + + if (KeysDown & 8) + MotionAlongVector(a_vector, speed, cam); + } + else + { + if (KeysDown & 4) + cam->Pitch(-AngleStepSize); + + if (KeysDown & 8) + cam->Pitch( AngleStepSize); + } + + // forward and backward + Vec3d a_vector(cam->GetDirectionOfProjection()); + if (KeysDown & 16) + MotionAlongVector(a_vector, speed, cam); + + if (KeysDown & 32) + MotionAlongVector(a_vector,-speed, cam); +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +void cv::viz::vtkVizInteractorStyle::PrintSelf(ostream& os, vtkIndent indent) +{ + Superclass::PrintSelf(os, indent); + os << indent << "MotionFactor: " << MotionFactor << "\n"; + os << indent << "MotionStepSize: " << MotionStepSize << "\n"; + os << indent << "MotionAccelerationFactor: "<< MotionAccelerationFactor << "\n"; + os << indent << "AngleStepSize: " << AngleStepSize << "\n"; + os << indent << "MotionUserScale: "<< MotionUserScale << "\n"; +} diff --git a/modules/viz/src/vtk/vtkVizInteractorStyle.hpp b/modules/viz/src/vtk/vtkVizInteractorStyle.hpp new file mode 100644 index 000000000..3588a3b6c --- /dev/null +++ b/modules/viz/src/vtk/vtkVizInteractorStyle.hpp @@ -0,0 +1,169 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__ +#define __OPENCV_VIZ_INTERACTOR_STYLE_H__ + +#include + +namespace cv +{ + namespace viz + { + class vtkVizInteractorStyle : public vtkInteractorStyle + { + public: + static vtkVizInteractorStyle *New(); + vtkTypeMacro(vtkVizInteractorStyle, vtkInteractorStyle) + void PrintSelf(ostream& os, vtkIndent indent); + + virtual void OnChar(); + virtual void OnKeyDown(); + virtual void OnKeyUp(); + + virtual void OnMouseMove(); + virtual void OnLeftButtonDown(); + virtual void OnLeftButtonUp(); + virtual void OnMiddleButtonDown(); + virtual void OnMiddleButtonUp(); + virtual void OnRightButtonDown(); + virtual void OnRightButtonUp(); + virtual void OnMouseWheelForward(); + virtual void OnMouseWheelBackward(); + virtual void OnTimer(); + + virtual void Rotate(); + virtual void Spin(); + virtual void Pan(); + virtual void Dolly(); + + vtkSetMacro(FlyMode,bool) + vtkGetMacro(FlyMode,bool) + + + vtkSetMacro(MotionFactor, double) + vtkGetMacro(MotionFactor, double) + + void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); + void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); + + void setWidgetActorMap(const Ptr& actors) { widget_actor_map_ = actors; } + void saveScreenshot(const String &file); + void exportScene(const String &file); + void exportScene(); + void changePointsSize(float delta); + void setRepresentationToPoints(); + void printCameraParams(); + void toggleFullScreen(); + void resetViewerPose(); + void toggleStereo(); + void printHelp(); + + // Set the basic unit step size : by default 1/250 of bounding diagonal + vtkSetMacro(MotionStepSize,double) + vtkGetMacro(MotionStepSize,double) + + // Set acceleration factor when shift key is applied : default 10 + vtkSetMacro(MotionAccelerationFactor,double) + vtkGetMacro(MotionAccelerationFactor,double) + + // Set the basic angular unit for turning : efault 1 degree + vtkSetMacro(AngleStepSize,double) + vtkGetMacro(AngleStepSize,double) + + private: + Ptr widget_actor_map_; + + Vec2i win_size_; + Vec2i win_pos_; + Vec2i max_win_size_; + + void zoomIn(); + void zoomOut(); + + protected: + vtkVizInteractorStyle(); + ~vtkVizInteractorStyle(); + + virtual void Dolly(double factor); + + void Fly(); + void FlyByMouse(); + void FlyByKey(); + void SetupMotionVars(); + void MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam); + + private: + vtkVizInteractorStyle(const vtkVizInteractorStyle&); + vtkVizInteractorStyle& operator=(const vtkVizInteractorStyle&); + + //! True for red-blue colors, false for magenta-green. + bool stereo_anaglyph_redblue_; + + void (*keyboardCallback_)(const KeyboardEvent&, void*); + void *keyboard_callback_cookie_; + + void (*mouseCallback_)(const MouseEvent&, void*); + void *mouse_callback_cookie_; + + bool FlyMode; + double MotionFactor; + + int getModifiers(); + + // from fly + unsigned char KeysDown; + double DiagonalLength; + double MotionStepSize; + double MotionUserScale; + double MotionAccelerationFactor; + double AngleStepSize; + double DeltaYaw; + double DeltaPitch; + }; + } +} + +#endif diff --git a/modules/nonfree/perf/perf_surf.ocl.cpp b/modules/viz/src/vtk/vtkXYZReader.cpp similarity index 53% rename from modules/nonfree/perf/perf_surf.ocl.cpp rename to modules/viz/src/vtk/vtkXYZReader.cpp index cc48aa28c..283a59248 100644 --- a/modules/nonfree/perf/perf_surf.ocl.cpp +++ b/modules/viz/src/vtk/vtkXYZReader.cpp @@ -10,13 +10,9 @@ // License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. -// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // -// @Authors -// Peng Xiao, pengxiao@multicorewareinc.com -// // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // @@ -30,7 +26,7 @@ // * 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 +// 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, @@ -41,71 +37,71 @@ // 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. // +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// //M*/ -#include "perf_precomp.hpp" +#include "precomp.hpp" -#ifdef HAVE_OPENCV_OCL - -using namespace cv; -using namespace cv::ocl; -using namespace std; - -typedef perf::TestBaseWithParam OCL_SURF; - -#define SURF_IMAGES \ - "cv/detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\ - "stitching/a3.png" - -PERF_TEST_P(OCL_SURF, DISABLED_with_data_transfer, testing::Values(SURF_IMAGES)) +namespace cv { namespace viz { - string filename = getDataPath(GetParam()); - Mat img = imread(filename, IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); + vtkStandardNewMacro(vtkXYZReader); +}} - SURF_OCL d_surf; - oclMat d_keypoints; - oclMat d_descriptors; - Mat cpu_kp; - Mat cpu_dp; - declare.time(60); +cv::viz::vtkXYZReader::vtkXYZReader() +{ + this->FileName = 0; + this->SetNumberOfInputPorts(0); +} - TEST_CYCLE() +cv::viz::vtkXYZReader::~vtkXYZReader() +{ + this->SetFileName(0); +} + +void cv::viz::vtkXYZReader::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + os << indent << "FileName: " << (this->FileName ? this->FileName : "(none)") << "\n"; +} + +int cv::viz::vtkXYZReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) +{ + // Make sure we have a file to read. + if(!this->FileName) { - oclMat d_src(img); - - d_surf(d_src, oclMat(), d_keypoints, d_descriptors); - - d_keypoints.download(cpu_kp); - d_descriptors.download(cpu_dp); + vtkErrorMacro("A FileName must be specified."); + return 0; } - SANITY_CHECK(cpu_kp, 1); - SANITY_CHECK(cpu_dp, 1); + // Open the input file. + ifstream fin(this->FileName); + if(!fin) + { + vtkErrorMacro("Error opening file " << this->FileName); + return 0; + } + + // Allocate objects to hold points and vertex cells. + vtkSmartPointer points = vtkSmartPointer::New(); + vtkSmartPointer verts = vtkSmartPointer::New(); + + // Read points from the file. + vtkDebugMacro("Reading points from file " << this->FileName); + double x[3]; + while(fin >> x[0] >> x[1] >> x[2]) + { + vtkIdType id = points->InsertNextPoint(x); + verts->InsertNextCell(1, &id); + } + vtkDebugMacro("Read " << points->GetNumberOfPoints() << " points."); + + // Store the points and cells in the output data object. + vtkPolyData* output = vtkPolyData::GetData(outputVector); + output->SetPoints(points); + output->SetVerts(verts); + + return 1; } - -PERF_TEST_P(OCL_SURF, DISABLED_without_data_transfer, testing::Values(SURF_IMAGES)) -{ - string filename = getDataPath(GetParam()); - Mat img = imread(filename, IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - SURF_OCL d_surf; - oclMat d_keypoints; - oclMat d_descriptors; - oclMat d_src(img); - - declare.time(60); - - TEST_CYCLE() d_surf(d_src, oclMat(), d_keypoints, d_descriptors); - - Mat cpu_kp; - Mat cpu_dp; - d_keypoints.download(cpu_kp); - d_descriptors.download(cpu_dp); - SANITY_CHECK(cpu_kp, 1); - SANITY_CHECK(cpu_dp, 1); -} - -#endif // HAVE_OPENCV_OCL diff --git a/modules/viz/src/vtk/vtkXYZReader.h b/modules/viz/src/vtk/vtkXYZReader.h new file mode 100644 index 000000000..13ae048ec --- /dev/null +++ b/modules/viz/src/vtk/vtkXYZReader.h @@ -0,0 +1,80 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __vtkXYZReader_h +#define __vtkXYZReader_h + +#include "vtkPolyDataAlgorithm.h" + +namespace cv +{ + namespace viz + { + class vtkXYZReader : public vtkPolyDataAlgorithm + { + public: + static vtkXYZReader* New(); + vtkTypeMacro(vtkXYZReader,vtkPolyDataAlgorithm) + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Set/Get the name of the file from which to read points. + vtkSetStringMacro(FileName) + vtkGetStringMacro(FileName) + + protected: + vtkXYZReader(); + ~vtkXYZReader(); + + char* FileName; + + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*); + private: + vtkXYZReader(const vtkXYZReader&); // Not implemented. + void operator=(const vtkXYZReader&); // Not implemented. + }; + } +} + +#endif diff --git a/modules/viz/src/vtk/vtkXYZWriter.cpp b/modules/viz/src/vtk/vtkXYZWriter.cpp new file mode 100644 index 000000000..5a3d7d5c8 --- /dev/null +++ b/modules/viz/src/vtk/vtkXYZWriter.cpp @@ -0,0 +1,122 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +namespace cv { namespace viz +{ + vtkStandardNewMacro(vtkXYZWriter); +}} + +cv::viz::vtkXYZWriter::vtkXYZWriter() +{ + std::ofstream fout; // only used to extract the default precision + this->DecimalPrecision = fout.precision(); +} + +void cv::viz::vtkXYZWriter::WriteData() +{ + vtkPolyData *input = this->GetInput(); + if (!input) + return; + + if (!this->FileName ) + { + vtkErrorMacro(<< "No FileName specified! Can't write!"); + this->SetErrorCode(vtkErrorCode::NoFileNameError); + return; + } + + vtkDebugMacro(<<"Opening vtk file for writing..."); + ostream *outfilep = new ofstream(this->FileName, ios::out); + if (outfilep->fail()) + { + vtkErrorMacro(<< "Unable to open file: "<< this->FileName); + this->SetErrorCode(vtkErrorCode::CannotOpenFileError); + delete outfilep; + return; + } + + ostream &outfile = *outfilep; + + for(vtkIdType i = 0; i < input->GetNumberOfPoints(); ++i) + { + Vec3d p; + input->GetPoint(i, p.val); + outfile << std::setprecision(this->DecimalPrecision) << p[0] << " " << p[1] << " " << p[2] << std::endl; + } + + // Close the file + vtkDebugMacro(<<"Closing vtk file\n"); + delete outfilep; + + // Delete the file if an error occurred + if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError) + { + vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName); + unlink(this->FileName); + } +} + +int cv::viz::vtkXYZWriter::FillInputPortInformation(int, vtkInformation *info) +{ + info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); + return 1; +} + +void cv::viz::vtkXYZWriter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + os << indent << "DecimalPrecision: " << this->DecimalPrecision << "\n"; +} + +vtkPolyData* cv::viz::vtkXYZWriter::GetInput() +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); +} + +vtkPolyData* cv::viz::vtkXYZWriter::GetInput(int port) +{ + return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); +} diff --git a/modules/viz/src/vtk/vtkXYZWriter.h b/modules/viz/src/vtk/vtkXYZWriter.h new file mode 100644 index 000000000..91d0c8f6b --- /dev/null +++ b/modules/viz/src/vtk/vtkXYZWriter.h @@ -0,0 +1,90 @@ +/*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 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. +// +// Authors: +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#ifndef __vtkXYZWriter_h +#define __vtkXYZWriter_h + +#include "vtkWriter.h" + +namespace cv +{ + namespace viz + { + class vtkXYZWriter : public vtkWriter + { + public: + static vtkXYZWriter *New(); + vtkTypeMacro(vtkXYZWriter,vtkWriter) + void PrintSelf(ostream& os, vtkIndent indent); + + vtkGetMacro(DecimalPrecision, int) + vtkSetMacro(DecimalPrecision, int) + + // Description: + // Specify file name of data file to write. + vtkSetStringMacro(FileName) + vtkGetStringMacro(FileName) + + // Description: + // Get the input to this writer. + vtkPolyData* GetInput(); + vtkPolyData* GetInput(int port); + + protected: + vtkXYZWriter(); + ~vtkXYZWriter(){} + + void WriteData(); + int FillInputPortInformation(int port, vtkInformation *info); + + int DecimalPrecision; + char *FileName; + + private: + vtkXYZWriter(const vtkXYZWriter&); // Not implemented. + void operator=(const vtkXYZWriter&); // Not implemented. + }; + } +} +#endif diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp new file mode 100644 index 000000000..33b467ebc --- /dev/null +++ b/modules/viz/src/widget.cpp @@ -0,0 +1,327 @@ +/*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 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. +// +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// +//M*/ + +#include "precomp.hpp" + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// widget implementation + +class cv::viz::Widget::Impl +{ +public: + vtkSmartPointer prop; + Impl() : prop(0) {} +}; + +cv::viz::Widget::Widget() : impl_( new Impl() ) { } + +cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() ) +{ + if (other.impl_ && other.impl_->prop) + impl_->prop = other.impl_->prop; +} + +cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other) +{ + if (!impl_) + impl_ = new Impl(); + + if (other.impl_) + impl_->prop = other.impl_->prop; + return *this; +} + +cv::viz::Widget::~Widget() +{ + if (impl_) + { + delete impl_; + impl_ = 0; + } +} + +cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) +{ + CV_Assert(vtkPLYReader::CanReadFile(file_name.c_str())); + + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName(file_name.c_str()); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection( reader->GetOutputPort() ); + mapper->ImmediateModeRenderingOff(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->GetProperty()->SetInterpolationToFlat(); + actor->GetProperty()->BackfaceCullingOn(); + actor->SetMapper(mapper); + + Widget widget; + WidgetAccessor::setProp(widget, actor); + return widget; +} + +void cv::viz::Widget::setRenderingProperty(int property, double value) +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget type is not supported." && actor); + + switch (property) + { + case POINT_SIZE: actor->GetProperty()->SetPointSize(float(value)); break; + case OPACITY: actor->GetProperty()->SetOpacity(value); break; + case LINE_WIDTH: actor->GetProperty()->SetLineWidth(float(value)); break; + case IMMEDIATE_RENDERING: actor->GetMapper()->SetImmediateModeRendering(int(value)); break; + case FONT_SIZE: + { + vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor); + CV_Assert("Widget does not have text content." && text_actor); + text_actor->GetTextProperty()->SetFontSize(int(value)); + break; + } + case REPRESENTATION: + { + switch (int(value)) + { + case REPRESENTATION_POINTS: actor->GetProperty()->SetRepresentationToPoints(); break; + case REPRESENTATION_WIREFRAME: actor->GetProperty()->SetRepresentationToWireframe(); break; + case REPRESENTATION_SURFACE: actor->GetProperty()->SetRepresentationToSurface(); break; + } + break; + } + case SHADING: + { + switch (int(value)) + { + case SHADING_FLAT: actor->GetProperty()->SetInterpolationToFlat(); break; + case SHADING_GOURAUD: + { + if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) + { + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("Can't set shading property for such type of widget" && mapper); + + vtkSmartPointer with_normals = VtkUtils::ComputeNormals(mapper->GetInput()); + VtkUtils::SetInputData(mapper, with_normals); + } + actor->GetProperty()->SetInterpolationToGouraud(); + break; + } + case SHADING_PHONG: + { + if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) + { + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("Can't set shading property for such type of widget" && mapper); + + vtkSmartPointer with_normals = VtkUtils::ComputeNormals(mapper->GetInput()); + VtkUtils::SetInputData(mapper, with_normals); + } + actor->GetProperty()->SetInterpolationToPhong(); + break; + } + } + break; + } + default: + CV_Assert("setPointCloudRenderingProperties: Unknown property"); + } + actor->Modified(); +} + +double cv::viz::Widget::getRenderingProperty(int property) const +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget type is not supported." && actor); + + double value = 0.0; + switch (property) + { + case POINT_SIZE: value = actor->GetProperty()->GetPointSize(); break; + case OPACITY: value = actor->GetProperty()->GetOpacity(); break; + case LINE_WIDTH: value = actor->GetProperty()->GetLineWidth(); break; + case IMMEDIATE_RENDERING: value = actor->GetMapper()->GetImmediateModeRendering(); break; + + case FONT_SIZE: + { + vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor); + CV_Assert("Widget does not have text content." && text_actor); + value = text_actor->GetTextProperty()->GetFontSize();; + break; + } + case REPRESENTATION: + { + switch (actor->GetProperty()->GetRepresentation()) + { + case VTK_POINTS: value = REPRESENTATION_POINTS; break; + case VTK_WIREFRAME: value = REPRESENTATION_WIREFRAME; break; + case VTK_SURFACE: value = REPRESENTATION_SURFACE; break; + } + break; + } + case SHADING: + { + switch (actor->GetProperty()->GetInterpolation()) + { + case VTK_FLAT: value = SHADING_FLAT; break; + case VTK_GOURAUD: value = SHADING_GOURAUD; break; + case VTK_PHONG: value = SHADING_PHONG; break; + } + break; + } + default: + CV_Assert("getPointCloudRenderingProperties: Unknown property"); + } + return value; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// widget accessor implementaion + +vtkSmartPointer cv::viz::WidgetAccessor::getProp(const Widget& widget) +{ + return widget.impl_->prop; +} + +void cv::viz::WidgetAccessor::setProp(Widget& widget, vtkSmartPointer prop) +{ + widget.impl_->prop = prop; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// widget3D implementation + +void cv::viz::Widget3D::setPose(const Affine3d &pose) +{ + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget is not 3D." && actor); + + vtkSmartPointer matrix = vtkmatrix(pose.matrix); + actor->SetUserMatrix(matrix); + actor->Modified(); +} + +void cv::viz::Widget3D::updatePose(const Affine3d &pose) +{ + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget is not 3D." && actor); + + vtkSmartPointer matrix = actor->GetUserMatrix(); + if (!matrix) + { + setPose(pose); + return; + } + + Affine3d updated_pose = pose * Affine3d(*matrix->Element); + matrix = vtkmatrix(updated_pose.matrix); + + actor->SetUserMatrix(matrix); + actor->Modified(); +} + +cv::Affine3d cv::viz::Widget3D::getPose() const +{ + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget is not 3D." && actor); + return Affine3d(*actor->GetUserMatrix()->Element); +} + +void cv::viz::Widget3D::applyTransform(const Affine3d &transform) +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget is not 3D actor." && actor); + + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("Widget doesn't have a polydata mapper" && mapper); + mapper->Update(); + + VtkUtils::SetInputData(mapper, VtkUtils::TransformPolydata(mapper->GetInput(), transform)); +} + +void cv::viz::Widget3D::setColor(const Color &color) +{ + // Cast to actor instead of prop3d since prop3d doesn't provide getproperty + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget type is not supported." && actor); + + Color c = vtkcolor(color); + actor->GetMapper()->ScalarVisibilityOff(); + actor->GetProperty()->SetColor(c.val); + actor->GetProperty()->SetEdgeColor(c.val); + actor->Modified(); +} + +template<> cv::viz::Widget3D cv::viz::Widget::cast() +{ + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget cannot be cast." && actor); + + Widget3D widget; + WidgetAccessor::setProp(widget, actor); + return widget; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +/// widget2D implementation + +void cv::viz::Widget2D::setColor(const Color &color) +{ + vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget type is not supported." && actor); + Color c = vtkcolor(color); + actor->GetProperty()->SetColor(c.val); + actor->Modified(); +} + +template<> cv::viz::Widget2D cv::viz::Widget::cast() +{ + vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Widget cannot be cast." && actor); + + Widget2D widget; + WidgetAccessor::setProp(widget, actor); + return widget; +} diff --git a/modules/viz/test/test_main.cpp b/modules/viz/test/test_main.cpp new file mode 100644 index 000000000..e737d2db3 --- /dev/null +++ b/modules/viz/test/test_main.cpp @@ -0,0 +1,3 @@ +#include "test_precomp.hpp" + +CV_TEST_MAIN("viz") diff --git a/modules/viz/test/test_precomp.cpp b/modules/viz/test/test_precomp.cpp new file mode 100644 index 000000000..c2673fee6 --- /dev/null +++ b/modules/viz/test/test_precomp.cpp @@ -0,0 +1,24 @@ +#include "test_precomp.hpp" + +cv::String cv::Path::combine(const String& item1, const String& item2) +{ + if (item1.empty()) + return item2; + + if (item2.empty()) + return item1; + + char last = item1[item1.size()-1]; + + bool need_append = last != '/' && last != '\\'; + return item1 + (need_append ? "/" : "") + item2; +} + +cv::String cv::Path::combine(const String& item1, const String& item2, const String& item3) +{ return combine(combine(item1, item2), item3); } + +cv::String cv::Path::change_extension(const String& file, const String& ext) +{ + String::size_type pos = file.find_last_of('.'); + return pos == String::npos ? file : file.substr(0, pos+1) + ext; +} diff --git a/modules/ocl/src/opencl/arithm_bitwise_binary_mask.cl b/modules/viz/test/test_precomp.hpp similarity index 50% rename from modules/ocl/src/opencl/arithm_bitwise_binary_mask.cl rename to modules/viz/test/test_precomp.hpp index 328ccd91a..05914e284 100644 --- a/modules/ocl/src/opencl/arithm_bitwise_binary_mask.cl +++ b/modules/viz/test/test_precomp.hpp @@ -10,14 +10,9 @@ // 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. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // -// @Authors -// Jiang Liyuan, jlyuan001.good@163.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: // @@ -31,7 +26,7 @@ // * 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 +// 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, @@ -42,47 +37,76 @@ // 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. // +// Authors: +// * Ozan Tonkal, ozantonkal@gmail.com +// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com +// //M*/ -////////////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////bitwise_binary//////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////////////////////////////// +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif -__kernel void arithm_bitwise_binary_mask(__global uchar * src1, int src1_step, int src1_offset, - __global uchar * src2, int src2_step, int src2_offset, - __global uchar * mask, int mask_step, int mask_offset, - __global uchar * dst, int dst_step, int dst_offset, - int cols1, int rows) +#ifndef __OPENCV_TEST_PRECOMP_HPP__ +#define __OPENCV_TEST_PRECOMP_HPP__ + +#include +#include + +namespace cv { - int x = get_global_id(0); - int y = get_global_id(1); + Mat imread(const String& filename, int flags = 1); +} - if (x < cols1 && y < rows) - { - int mask_index = mad24(y, mask_step, mask_offset + x); - - if (mask[mask_index]) - { -#if elemSize > 1 - x *= elemSize; -#endif - int src1_index = mad24(y, src1_step, x + src1_offset); - int src2_index = mad24(y, src2_step, x + src2_offset); - int dst_index = mad24(y, dst_step, x + dst_offset); - -#if elemSize > 1 - #pragma unroll - for (int i = 0; i < elemSize; i += vlen) - { - ucharv t0 = vloadn(0, src1 + src1_index + i); - ucharv t1 = vloadn(0, src2 + src2_index + i); - ucharv t2 = t0 Operation t1; - - vstoren(t2, 0, dst + dst_index + i); - } +#if CV_MAJOR_VERSION < 3 + #include "opencv2/ts/ts.hpp" #else - dst[dst_index] = src1[src1_index] Operation src2[src2_index]; + #include "opencv2/ts.hpp" #endif + +#include +#include +#include +#include + +namespace cv +{ + struct Path + { + static String combine(const String& item1, const String& item2); + static String combine(const String& item1, const String& item2, const String& item3); + static String change_extension(const String& file, const String& ext); + }; + + inline cv::String get_dragon_ply_file_path() + { + return Path::combine(cvtest::TS::ptr()->get_data_path(), "dragon.ply"); + } + + template + inline std::vector< Affine3<_Tp> > generate_test_trajectory() + { + std::vector< Affine3<_Tp> > result; + + for (int i = 0, j = 0; i <= 270; i += 3, j += 10) + { + double x = 2 * cos(i * 3 * CV_PI/180.0) * (1.0 + 0.5 * cos(1.2 + i * 1.2 * CV_PI/180.0)); + double y = 0.25 + i/270.0 + sin(j * CV_PI/180.0) * 0.2 * sin(0.6 + j * 1.5 * CV_PI/180.0); + double z = 2 * sin(i * 3 * CV_PI/180.0) * (1.0 + 0.5 * cos(1.2 + i * CV_PI/180.0)); + result.push_back(viz::makeCameraPose(Vec3d(x, y, z), Vec3d::all(0.0), Vec3d(0.0, 1.0, 0.0))); } + return result; + } + + inline Mat make_gray(const Mat& image) + { + Mat chs[3]; split(image, chs); + return 0.114 * chs[0] + 0.58 * chs[1] + 0.3 * chs[2]; } } + +#endif diff --git a/modules/viz/test/test_tutorial2.cpp b/modules/viz/test/test_tutorial2.cpp new file mode 100644 index 000000000..a901adc2c --- /dev/null +++ b/modules/viz/test/test_tutorial2.cpp @@ -0,0 +1,54 @@ +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +void tutorial2() +{ + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Add line to represent (1,1,1) axis + viz::WLine axis(Point3f(-1.0, -1.0, -1.0), Point3d(1.0, 1.0, 1.0)); + axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Line Widget", axis); + + /// Construct a cube widget + viz::WCube cube_widget(Point3d(0.5, 0.5, 0.0), Point3d(0.0, 0.0, -0.5), true, viz::Color::blue()); + cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); + + /// Display widget (update if already displayed) + myWindow.showWidget("Cube Widget", cube_widget); + + /// Rodrigues vector + Vec3d rot_vec = Vec3d::all(0); + double translation_phase = 0.0, translation = 0.0; + while(!myWindow.wasStopped()) + { + /* Rotation using rodrigues */ + /// Rotate around (1,1,1) + rot_vec[0] += CV_PI * 0.01; + rot_vec[1] += CV_PI * 0.01; + rot_vec[2] += CV_PI * 0.01; + + /// Shift on (1,1,1) + translation_phase += CV_PI * 0.01; + translation = sin(translation_phase); + + /// Construct pose + Affine3d pose(rot_vec, Vec3d(translation, translation, translation)); + + myWindow.setWidgetPose("Cube Widget", pose); + + myWindow.spinOnce(1, true); + } +} + + +TEST(Viz, DISABLED_tutorial2_pose_of_widget) +{ + tutorial2(); +} diff --git a/modules/viz/test/test_tutorial3.cpp b/modules/viz/test/test_tutorial3.cpp new file mode 100644 index 000000000..b20e8d7a1 --- /dev/null +++ b/modules/viz/test/test_tutorial3.cpp @@ -0,0 +1,60 @@ +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +/** + * @function main + */ +void tutorial3(bool camera_pov) +{ + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Let's assume camera has the following properties + Point3d cam_origin(3.0, 3.0, 3.0), cam_focal_point(3.0, 3.0, 2.0), cam_y_dir(-1.0, 0.0, 0.0); + + /// We can get the pose of the cam using makeCameraPose + Affine3d camera_pose = viz::makeCameraPose(cam_origin, cam_focal_point, cam_y_dir); + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3d transform = viz::makeTransformToGlobal(Vec3d(0.0, -1.0, 0.0), Vec3d(-1.0, 0.0, 0.0), Vec3d(0.0, 0.0, -1.0), cam_origin); + + /// Create a cloud widget. + Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path()); + viz::WCloud cloud_widget(dragon_cloud, viz::Color::green()); + + /// Pose of the widget in camera frame + Affine3d cloud_pose = Affine3d().rotate(Vec3d(0.0, CV_PI/2, 0.0)).rotate(Vec3d(0.0, 0.0, CV_PI)).translate(Vec3d(0.0, 0.0, 3.0)); + /// Pose of the widget in global frame + Affine3d cloud_pose_global = transform * cloud_pose; + + /// Visualize camera frame + myWindow.showWidget("CPW_FRUSTUM", viz::WCameraPosition(Vec2f(0.889484f, 0.523599f)), camera_pose); + if (!camera_pov) + myWindow.showWidget("CPW", viz::WCameraPosition(0.5), camera_pose); + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(camera_pose); + + /// Start event loop. + myWindow.spin(); +} + +TEST(Viz, tutorial3_global_view) +{ + tutorial3(false); +} + +TEST(Viz, tutorial3_camera_view) +{ + tutorial3(true); +} diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp new file mode 100644 index 000000000..45128df2f --- /dev/null +++ b/modules/viz/test/test_viz3d.cpp @@ -0,0 +1,63 @@ +/*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) 2008-2013, 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" + +using namespace cv; + +TEST(Viz_viz3d, DISABLED_develop) +{ + cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); + + cv::viz::Viz3d viz("abc"); + viz.setBackgroundMeshLab(); + viz.showWidget("coo", cv::viz::WCoordinateSystem(1)); + viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud)); + + //---->>>>> + //std::vector gt, es; + //cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml"); + //cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml"); + //cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); + //---->>>>> + + viz.spin(); +} diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp new file mode 100644 index 000000000..f8f63c35b --- /dev/null +++ b/modules/viz/test/tests_simple.cpp @@ -0,0 +1,453 @@ +/*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) 2008-2013, 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" + +using namespace cv; +using namespace cv::viz; + +TEST(Viz, show_cloud_bluberry) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_cloud_bluberry"); + viz.setBackgroundColor(Color::black()); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud, Color::bluberry()), pose); + + viz.showWidget("text2d", WText("Bluberry cloud", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_cloud_random_color) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Mat colors(dragon_cloud.size(), CV_8UC3); + theRNG().fill(colors, RNG::UNIFORM, 0, 255); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_cloud_random_color"); + viz.setBackgroundMeshLab(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud, colors), pose); + viz.showWidget("text2d", WText("Random color cloud", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_cloud_masked) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Vec3f qnan = Vec3f::all(std::numeric_limits::quiet_NaN()); + for(int i = 0; i < (int)dragon_cloud.total(); ++i) + if (i % 15 != 0) + dragon_cloud.at(i) = qnan; + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_cloud_masked"); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud), pose); + viz.showWidget("text2d", WText("Nan masked cloud", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_cloud_collection) +{ + Mat cloud = readCloud(get_dragon_ply_file_path()); + + WCloudCollection ccol; + ccol.addCloud(cloud, Color::white(), Affine3d().translate(Vec3d(0, 0, 0)).rotate(Vec3d(CV_PI/2, 0, 0))); + ccol.addCloud(cloud, Color::blue(), Affine3d().translate(Vec3d(1, 0, 0))); + ccol.addCloud(cloud, Color::red(), Affine3d().translate(Vec3d(2, 0, 0))); + ccol.finalize(); + + Viz3d viz("show_cloud_collection"); + viz.setBackgroundColor(Color::mlab()); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("ccol", ccol); + viz.showWidget("text2d", WText("Cloud collection", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_painted_clouds) +{ + Mat cloud = readCloud(get_dragon_ply_file_path()); + + Viz3d viz("show_painted_clouds"); + viz.setBackgroundMeshLab(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("cloud1", WPaintedCloud(cloud), Affine3d(Vec3d(0.0, -CV_PI/2, 0.0), Vec3d(-1.5, 0.0, 0.0))); + viz.showWidget("cloud2", WPaintedCloud(cloud, Vec3d(0.0, -0.75, -1.0), Vec3d(0.0, 0.75, 0.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(1.5, 0.0, 0.0))); + viz.showWidget("cloud3", WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), Color::blue(), Color::red())); + viz.showWidget("arrow", WArrow(Vec3d(0.0, 1.0, -1.0), Vec3d(0.0, 1.0, 1.0), 0.009, Color::raspberry())); + viz.showWidget("text2d", WText("Painted clouds", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_mesh) +{ + Mesh mesh = Mesh::load(get_dragon_ply_file_path()); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_mesh"); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("mesh", WMesh(mesh), pose); + viz.showWidget("text2d", WText("Just mesh", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_mesh_random_colors) +{ + Mesh mesh = Mesh::load(get_dragon_ply_file_path()); + theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_mesh_random_color"); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("mesh", WMesh(mesh), pose); + viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG); + viz.showWidget("text2d", WText("Random color mesh", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_widget_merger) +{ + WWidgetMerger merger; + merger.addWidget(WCube(Vec3d::all(0.0), Vec3d::all(1.0), true, Color::gold())); + + RNG& rng = theRNG(); + for(int i = 0; i < 77; ++i) + { + Vec3b c; + rng.fill(c, RNG::NORMAL, Scalar::all(128), Scalar::all(48), true); + merger.addWidget(WSphere(Vec3d(c)*(1.0/255.0), 7.0/255.0, 10, Color(c[2], c[1], c[0]))); + } + merger.finalize(); + + Viz3d viz("show_mesh_random_color"); + viz.showWidget("coo", WCoordinateSystem()); + viz.showWidget("merger", merger); + viz.showWidget("text2d", WText("Widget merger", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_textured_mesh) +{ + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + + std::vector points; + std::vector tcoords; + std::vector polygons; + for(size_t i = 0; i < 64; ++i) + { + double angle = CV_PI/2 * i/64.0; + points.push_back(Vec3d(0.00, cos(angle), sin(angle))*0.75); + points.push_back(Vec3d(1.57, cos(angle), sin(angle))*0.75); + tcoords.push_back(Vec2d(0.0, i/64.0)); + tcoords.push_back(Vec2d(1.0, i/64.0)); + } + + for(int i = 0; i < (int)points.size()/2-1; ++i) + { + int polys[] = {3, 2*i, 2*i+1, 2*i+2, 3, 2*i+1, 2*i+2, 2*i+3}; + polygons.insert(polygons.end(), polys, polys + sizeof(polys)/sizeof(polys[0])); + } + + cv::viz::Mesh mesh; + mesh.cloud = Mat(points, true).reshape(3, 1); + mesh.tcoords = Mat(tcoords, true).reshape(2, 1); + mesh.polygons = Mat(polygons, true).reshape(1, 1); + mesh.texture = lena; + + Viz3d viz("show_textured_mesh"); + viz.setBackgroundMeshLab(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("mesh", WMesh(mesh)); + viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG); + viz.showWidget("text2d", WText("Textured mesh", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_polyline) +{ + const Color palette[] = { Color::red(), Color::green(), Color::blue(), Color::gold(), Color::raspberry(), Color::bluberry(), Color::lime() }; + size_t palette_size = sizeof(palette)/sizeof(palette[0]); + + Mat polyline(1, 32, CV_64FC3), colors(1, 32, CV_8UC3); + for(int i = 0; i < (int)polyline.total(); ++i) + { + polyline.at(i) = Vec3d(i/16.0, cos(i * CV_PI/6), sin(i * CV_PI/6)); + colors.at(i) = palette[i & palette_size]; + } + + Viz3d viz("show_polyline"); + viz.showWidget("polyline", WPolyLine(polyline, colors)); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("text2d", WText("Polyline", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_sampled_normals) +{ + Mesh mesh = Mesh::load(get_dragon_ply_file_path()); + computeNormals(mesh, mesh.normals); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + Viz3d viz("show_sampled_normals"); + viz.showWidget("mesh", WMesh(mesh), pose); + viz.showWidget("normals", WCloudNormals(mesh.cloud, mesh.normals, 30, 0.1f, Color::green()), pose); + viz.setRenderingProperty("normals", LINE_WIDTH, 2.0); + viz.showWidget("text2d", WText("Cloud or mesh normals", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_cloud_shaded_by_normals) +{ + Mesh mesh = Mesh::load(get_dragon_ply_file_path()); + computeNormals(mesh, mesh.normals); + + Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); + + WCloud cloud(mesh.cloud, Color::white(), mesh.normals); + cloud.setRenderingProperty(SHADING, SHADING_GOURAUD); + + Viz3d viz("show_cloud_shaded_by_normals"); + viz.showWidget("cloud", cloud, pose); + viz.showWidget("text2d", WText("Cloud shaded by normals", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_trajectories) +{ + std::vector path = generate_test_trajectory(), sub0, sub1, sub2, sub3, sub4, sub5; + int size =(int)path.size(); + + Mat(path).rowRange(0, size/10+1).copyTo(sub0); + Mat(path).rowRange(size/10, size/5+1).copyTo(sub1); + Mat(path).rowRange(size/5, 11*size/12).copyTo(sub2); + Mat(path).rowRange(11*size/12, size).copyTo(sub3); + Mat(path).rowRange(3*size/4, 33*size/40).copyTo(sub4); + Mat(path).rowRange(33*size/40, 9*size/10).copyTo(sub5); + Matx33d K(1024.0, 0.0, 320.0, 0.0, 1024.0, 240.0, 0.0, 0.0, 1.0); + + Viz3d viz("show_trajectories"); + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("sub0", WTrajectorySpheres(sub0, 0.25, 0.07)); + viz.showWidget("sub1", WTrajectory(sub1, WTrajectory::PATH, 0.2, Color::brown())); + viz.showWidget("sub2", WTrajectory(sub2, WTrajectory::FRAMES, 0.2)); + viz.showWidget("sub3", WTrajectory(sub3, WTrajectory::BOTH, 0.2, Color::green())); + viz.showWidget("sub4", WTrajectoryFrustums(sub4, K, 0.3, Color::yellow())); + viz.showWidget("sub5", WTrajectoryFrustums(sub5, Vec2d(0.78, 0.78), 0.15)); + viz.showWidget("text2d", WText("Different kinds of supported trajectories", Point(20, 20), 20, Color::green())); + + int i = 0; + while(!viz.wasStopped()) + { + double a = --i % 360; + Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180)); + viz.setViewerPose(makeCameraPose(pose * 7.5, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0))); + viz.spinOnce(20, true); + } + viz.resetCamera(); + viz.spin(); +} + +TEST(Viz, show_trajectory_reposition) +{ + std::vector path = generate_test_trajectory(); + + Viz3d viz("show_trajectory_reposition_to_origin"); + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("sub3", WTrajectory(Mat(path).rowRange(0, (int)path.size()/3), WTrajectory::BOTH, 0.2, Color::brown()), path.front().inv()); + viz.showWidget("text2d", WText("Trajectory resposition to origin", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_camera_positions) +{ + Matx33d K(1024.0, 0.0, 320.0, 0.0, 1024.0, 240.0, 0.0, 0.0, 1.0); + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + Mat gray = make_gray(lena); + + Affine3d poses[2]; + for(int i = 0; i < 2; ++i) + { + Vec3d pose = 5 * Vec3d(sin(3.14 + 2.7 + i*60 * CV_PI/180), 0.4 - i*0.3, cos(3.14 + 2.7 + i*60 * CV_PI/180)); + poses[i] = makeCameraPose(pose, Vec3d(0.0, 0.0, 0.0), Vec3d(0.0, -0.1, 0.0)); + } + + Viz3d viz("show_camera_positions"); + viz.showWidget("sphe", WSphere(Point3d(0,0,0), 1.0, 10, Color::orange_red())); + viz.showWidget("coos", WCoordinateSystem(1.5)); + viz.showWidget("pos1", WCameraPosition(0.75), poses[0]); + viz.showWidget("pos2", WCameraPosition(Vec2d(0.78, 0.78), lena, 2.2, Color::green()), poses[0]); + viz.showWidget("pos3", WCameraPosition(0.75), poses[1]); + viz.showWidget("pos4", WCameraPosition(K, gray, 3, Color::indigo()), poses[1]); + viz.showWidget("text2d", WText("Camera positions with images", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_overlay_image) +{ + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + Mat gray = make_gray(lena); + + Size2d half_lsize = Size2d(lena.cols, lena.rows) * 0.5; + + Viz3d viz("show_overlay_image"); + viz.setBackgroundMeshLab(); + Size vsz = viz.getWindowSize(); + + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("cube", WCube()); + viz.showWidget("img1", WImageOverlay(lena, Rect(Point(10, 10), half_lsize))); + viz.showWidget("img2", WImageOverlay(gray, Rect(Point(vsz.width-10-lena.cols/2, 10), half_lsize))); + viz.showWidget("img3", WImageOverlay(gray, Rect(Point(10, vsz.height-10-lena.rows/2), half_lsize))); + viz.showWidget("img5", WImageOverlay(lena, Rect(Point(vsz.width-10-lena.cols/2, vsz.height-10-lena.rows/2), half_lsize))); + viz.showWidget("text2d", WText("Overlay images", Point(20, 20), 20, Color::green())); + + int i = 0; + while(!viz.wasStopped()) + { + double a = ++i % 360; + Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180)); + viz.setViewerPose(makeCameraPose(pose * 3, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0))); + viz.getWidget("img1").cast().setImage(lena * pow(sin(i*10*CV_PI/180) * 0.5 + 0.5, 1.0)); + viz.spinOnce(1, true); + } + viz.showWidget("text2d", WText("Overlay images (stopped)", Point(20, 20), 20, Color::green())); + viz.spin(); +} + + +TEST(Viz, show_image_method) +{ + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + + Viz3d viz("show_image_method"); + viz.showImage(lena); + viz.spinOnce(1500, true); + viz.showImage(lena, lena.size()); + viz.spinOnce(1500, true); + + cv::viz::imshow("show_image_method", make_gray(lena)).spin(); +} + +TEST(Viz, show_image_3d) +{ + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + Mat gray = make_gray(lena); + + Viz3d viz("show_image_3d"); + viz.setBackgroundMeshLab(); + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("cube", WCube()); + viz.showWidget("arr0", WArrow(Vec3d(0.5, 0.0, 0.0), Vec3d(1.5, 0.0, 0.0), 0.009, Color::raspberry())); + viz.showWidget("img0", WImage3D(lena, Size2d(1.0, 1.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(.5, 0.0, 0.0))); + viz.showWidget("arr1", WArrow(Vec3d(-0.5, -0.5, 0.0), Vec3d(0.2, 0.2, 0.0), 0.009, Color::raspberry())); + viz.showWidget("img1", WImage3D(gray, Size2d(1.0, 1.0), Vec3d(-0.5, -0.5, 0.0), Vec3d(1.0, 1.0, 0.0), Vec3d(0.0, 1.0, 0.0))); + + viz.showWidget("arr3", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry())); + + viz.showWidget("text2d", WText("Images in 3D", Point(20, 20), 20, Color::green())); + + int i = 0; + while(!viz.wasStopped()) + { + viz.getWidget("img0").cast().setImage(lena * pow(sin(i++*7.5*CV_PI/180) * 0.5 + 0.5, 1.0)); + viz.spinOnce(1, true); + } + viz.showWidget("text2d", WText("Images in 3D (stopped)", Point(20, 20), 20, Color::green())); + viz.spin(); +} + +TEST(Viz, show_simple_widgets) +{ + Viz3d viz("show_simple_widgets"); + viz.setBackgroundMeshLab(); + + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("cube", WCube()); + viz.showWidget("cub0", WCube(Vec3d::all(-1.0), Vec3d::all(-0.5), false, Color::indigo())); + viz.showWidget("arro", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry())); + viz.showWidget("cir1", WCircle(0.5, 0.01, Color::bluberry())); + viz.showWidget("cir2", WCircle(0.5, Point3d(0.5, 0.0, 0.0), Vec3d(1.0, 0.0, 0.0), 0.01, Color::apricot())); + + viz.showWidget("cyl0", WCylinder(Vec3d(-0.5, 0.5, -0.5), Vec3d(0.5, 0.5, -0.5), 0.125, 30, Color::brown())); + viz.showWidget("con0", WCone(0.25, 0.125, 6, Color::azure())); + viz.showWidget("con1", WCone(0.125, Point3d(0.5, -0.5, 0.5), Point3d(0.5, -1.0, 0.5), 6, Color::turquoise())); + + viz.showWidget("text2d", WText("Different simple widgets", Point(20, 20), 20, Color::green())); + viz.showWidget("text3d", WText3D("Simple 3D text", Point3d( 0.5, 0.5, 0.5), 0.125, false, Color::green())); + + viz.showWidget("plane1", WPlane(Size2d(0.25, 0.75))); + viz.showWidget("plane2", WPlane(Vec3d(0.5, -0.5, -0.5), Vec3d(0.0, 1.0, 1.0), Vec3d(1.0, 1.0, 0.0), Size2d(1.0, 0.5), Color::gold())); + + viz.showWidget("grid1", WGrid(Vec2i(7,7), Vec2d::all(0.75), Color::gray()), Affine3d().translate(Vec3d(0.0, 0.0, -1.0))); + + viz.spin(); + viz.getWidget("text2d").cast().setText("Different simple widgets (updated)"); + viz.getWidget("text3d").cast().setText("Updated text 3D"); + viz.spin(); +} + +TEST(Viz, show_follower) +{ + Viz3d viz("show_follower"); + + viz.showWidget("coos", WCoordinateSystem()); + viz.showWidget("cube", WCube()); + viz.showWidget("t3d_2", WText3D("Simple 3D follower", Point3d(-0.5, -0.5, 0.5), 0.125, true, Color::green())); + viz.showWidget("text2d", WText("Follower: text always facing camera", Point(20, 20), 20, Color::green())); + viz.setBackgroundMeshLab(); + viz.spin(); + viz.getWidget("t3d_2").cast().setText("Updated follower 3D"); + viz.spin(); +} diff --git a/modules/world/CMakeLists.txt b/modules/world/CMakeLists.txt index f65447dc0..6a84c1b6a 100644 --- a/modules/world/CMakeLists.txt +++ b/modules/world/CMakeLists.txt @@ -103,6 +103,7 @@ macro(ios_include_3party_libs) list(APPEND objlist "\"${objpath3}\"") endforeach() # (srcname ${sources}) endforeach() + ocv_list_filterout(objlist jmemansi) # <<= dirty fix endmacro() if(IOS AND WITH_PNG) diff --git a/platforms/android/android.toolchain.cmake b/platforms/android/android.toolchain.cmake index 68b256fbd..457164a1e 100644 --- a/platforms/android/android.toolchain.cmake +++ b/platforms/android/android.toolchain.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2010-2011, Ethan Rublee -# Copyright (c) 2011-2013, Andrey Kamaev +# Copyright (c) 2011-2014, Andrey Kamaev # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -12,9 +12,9 @@ # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # -# 3. The name of the copyright holders may be used to endorse or promote -# products derived from this software without specific prior written -# permission. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may 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 @@ -29,12 +29,12 @@ # POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------ -# Android CMake toolchain file, for use with the Android NDK r5-r8 +# Android CMake toolchain file, for use with the Android NDK r5-r9 # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). # See home page: https://github.com/taka-no-me/android-cmake # # The file is mantained by the OpenCV project. The latest version can be get at -# https://github.com/Itseez/opencv/tree/master/platforms/android/android.toolchain.cmake +# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake # # Usage Linux: # $ export ANDROID_NDK=/absolute/path/to/the/android-ndk @@ -87,8 +87,7 @@ # "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP. # "x86" - matches to the NDK ABI with the same name. # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. -# "mips" - matches to the NDK ABI with the same name -# (It is not tested on real devices by the authos of this toolchain) +# "mips" - matches to the NDK ABI with the same name. # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. # # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. @@ -292,6 +291,16 @@ # - April 2013 # [+] support non-release NDK layouts (from Linaro git and Android git) # [~] automatically detect if explicit link to crtbegin_*.o is needed +# - June 2013 +# [~] fixed stl include path for standalone toolchain made by NDK >= r8c +# - July 2013 +# [+] updated for NDK r9 +# - November 2013 +# [+] updated for NDK r9b +# - December 2013 +# [+] updated for NDK r9c +# - January 2014 +# [~] fix copying of shared STL # ------------------------------------------------------------------------------ cmake_minimum_required( VERSION 2.6.3 ) @@ -318,7 +327,7 @@ set( CMAKE_SYSTEM_VERSION 1 ) # rpath makes low sence for Android set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) if( CMAKE_HOST_WIN32 ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) @@ -464,7 +473,7 @@ endif() # detect current host platform -if( NOT DEFINED ANDROID_NDK_HOST_X64 AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64") +if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) mark_as_advanced( ANDROID_NDK_HOST_X64 ) endif() @@ -484,9 +493,7 @@ else() message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) endif() -# CMAKE_HOST_SYSTEM_PROCESSOR on MacOS X always says i386 on Intel platform -# So we do not trust ANDROID_NDK_HOST_X64 on Apple hosts -if( NOT ANDROID_NDK_HOST_X64 AND NOT CMAKE_HOST_APPLE) +if( NOT ANDROID_NDK_HOST_X64 ) set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) endif() @@ -634,30 +641,27 @@ endif() macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) foreach( __toolchain ${${__availableToolchainsLst}} ) - # Skip renderscript folder. It's not C++ toolchain - if (NOT ${__toolchain} STREQUAL "renderscript") - if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) - string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) - else() - set( __gcc_toolchain "${__toolchain}" ) - endif() - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) - if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) - if( __machine MATCHES i686 ) - set( __arch "x86" ) - elseif( __machine MATCHES arm ) - set( __arch "arm" ) - elseif( __machine MATCHES mipsel ) - set( __arch "mipsel" ) - endif() - list( APPEND __availableToolchainMachines "${__machine}" ) - list( APPEND __availableToolchainArchs "${__arch}" ) - list( APPEND __availableToolchainCompilerVersions "${__version}" ) - list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) - endif() - unset( __gcc_toolchain ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + else() + set( __gcc_toolchain "${__toolchain}" ) endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) + if( __machine MATCHES i686 ) + set( __arch "x86" ) + elseif( __machine MATCHES arm ) + set( __arch "arm" ) + elseif( __machine MATCHES mipsel ) + set( __arch "mipsel" ) + endif() + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) + endif() + unset( __gcc_toolchain ) endforeach() endmacro() @@ -687,6 +691,7 @@ if( BUILD_WITH_ANDROID_NDK ) endif() __LIST_FILTER( __availableToolchainsLst "^[.]" ) __LIST_FILTER( __availableToolchainsLst "llvm" ) + __LIST_FILTER( __availableToolchainsLst "renderscript" ) __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) @@ -975,7 +980,11 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN ) set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) + # old location ( pre r8c ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + endif() if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) @@ -1130,15 +1139,7 @@ endif() # case of shared STL linkage if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) - if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) - get_filename_component( __libstlname "${__libstl}" NAME ) - execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) - if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") - message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) - endif() - unset( __fileCopyProcess ) - unset( __libstlname ) - endif() + # TODO: check if .so file exists before the renaming endif() @@ -1503,7 +1504,8 @@ endif() # global includes and link directories include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) -link_directories( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning +link_directories( "${__android_install_path}" ) # detect if need link crtbegin_so.o explicitly if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) @@ -1555,6 +1557,18 @@ if(NOT _CMAKE_IN_TRY_COMPILE) set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) endif() +# copy shaed stl library to build directory +if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) + get_filename_component( __libstlname "${__libstl}" NAME ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") + message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) + endif() + unset( __fileCopyProcess ) + unset( __libstlname ) +endif() + + # set these global flags for cmake client scripts to change behavior set( ANDROID True ) set( BUILD_ANDROID True ) @@ -1663,6 +1677,19 @@ if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) endif() +# force cmake to produce / instead of \ in build commands for Ninja generator +if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) + # it is a bad hack after all + # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW + set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW + set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion + enable_language( C ) + enable_language( CXX ) + # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it + unset( MINGW ) +endif() + + # set some obsolete variables for backward compatibility set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) @@ -1717,7 +1744,7 @@ endif() # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e; set only for NDK +# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e, r9, r9b, r9c; set only for NDK # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform diff --git a/platforms/android/libinfo/CMakeLists.txt b/platforms/android/libinfo/CMakeLists.txt index 028413ec6..55dd27859 100644 --- a/platforms/android/libinfo/CMakeLists.txt +++ b/platforms/android/libinfo/CMakeLists.txt @@ -36,4 +36,4 @@ set_target_properties(${the_module} PROPERTIES ) get_filename_component(lib_name "libopencv_info.so" NAME) -install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs) diff --git a/platforms/android/package/CMakeLists.txt b/platforms/android/package/CMakeLists.txt index 1382a078c..b48a55a6a 100644 --- a/platforms/android/package/CMakeLists.txt +++ b/platforms/android/package/CMakeLists.txt @@ -89,6 +89,6 @@ add_custom_command( DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers} opencv_java ) -install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT main) +install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT libs) add_custom_target(android_package ALL SOURCES "${APK_NAME}" ) add_dependencies(android_package opencv_java) diff --git a/platforms/android/service/CMakeLists.txt b/platforms/android/service/CMakeLists.txt index dde145513..c99b71392 100644 --- a/platforms/android/service/CMakeLists.txt +++ b/platforms/android/service/CMakeLists.txt @@ -3,4 +3,4 @@ if(BUILD_ANDROID_SERVICE) #add_subdirectory(engine_test) endif() -install(FILES "readme.txt" DESTINATION "apk/" COMPONENT main) +install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs) diff --git a/platforms/android/service/engine/AndroidManifest.xml b/platforms/android/service/engine/AndroidManifest.xml index 7cae6ce8a..3ada75d0a 100644 --- a/platforms/android/service/engine/AndroidManifest.xml +++ b/platforms/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="218@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.18" > diff --git a/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp b/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp index 359906406..2b113b4e2 100644 --- a/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp +++ b/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp @@ -15,7 +15,7 @@ using namespace android; const int OpenCVEngine::Platform = DetectKnownPlatforms(); const int OpenCVEngine::CpuID = GetCpuID(); -const int OpenCVEngine::KnownVersions[] = {2040000, 2040100, 2040200, 2040300, 2040301, 2040302, 2040400, 2040500, 2040600, 2040700, 2040701, 2040800}; +const int OpenCVEngine::KnownVersions[] = {2040000, 2040100, 2040200, 2040300, 2040301, 2040302, 2040400, 2040500, 2040600, 2040700, 2040701, 2040800, 2040900}; bool OpenCVEngine::ValidateVersion(int version) { diff --git a/platforms/android/service/engine/jni/Tests/HardwareDetectionTest.cpp b/platforms/android/service/engine/jni/Tests/HardwareDetectionTest.cpp index 83dd9c27e..8e7dfab00 100644 --- a/platforms/android/service/engine/jni/Tests/HardwareDetectionTest.cpp +++ b/platforms/android/service/engine/jni/Tests/HardwareDetectionTest.cpp @@ -55,7 +55,7 @@ TEST(Parse, ParseEmptyString) EXPECT_FALSE(ParseString(a, key, value)); } -TEST(Parse, ParseStringWithoutSeporator) +TEST(Parse, ParseStringWithoutSeparator) { string a = "qqqwww"; string key; diff --git a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java index 8e8389dcc..0cd2fd58e 100644 --- a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java +++ b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java @@ -117,7 +117,7 @@ public class ManagerActivity extends Activity } else { - HardwarePlatformView.setText("Tegra 5"); + HardwarePlatformView.setText("Tegra K1"); } } else @@ -214,12 +214,12 @@ public class ManagerActivity extends Activity } }); - mPackageChangeReciever = new BroadcastReceiver() { + mPackageChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - Log.d("OpenCVManager/Reciever", "Bradcast message " + intent.getAction() + " reciever"); - Log.d("OpenCVManager/Reciever", "Filling package list on broadcast message"); + Log.d("OpenCVManager/Receiver", "Broadcast message " + intent.getAction() + " receiver"); + Log.d("OpenCVManager/Receiver", "Filling package list on broadcast message"); if (!bindService(new Intent("org.opencv.engine.BIND"), new OpenCVEngineServiceConnection(), Context.BIND_AUTO_CREATE)) { TextView EngineVersionView = (TextView)findViewById(R.id.EngineVersionValue); @@ -235,14 +235,14 @@ public class ManagerActivity extends Activity filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); - registerReceiver(mPackageChangeReciever, filter); + registerReceiver(mPackageChangeReceiver, filter); } @Override protected void onDestroy() { super.onDestroy(); - if (mPackageChangeReciever != null) - unregisterReceiver(mPackageChangeReciever); + if (mPackageChangeReceiver != null) + unregisterReceiver(mPackageChangeReceiver); } @Override @@ -273,7 +273,7 @@ public class ManagerActivity extends Activity protected int ManagerApiLevel = 0; protected String ManagerVersion; - protected BroadcastReceiver mPackageChangeReciever = null; + protected BroadcastReceiver mPackageChangeReceiver = null; protected class OpenCVEngineServiceConnection implements ServiceConnection { diff --git a/platforms/android/service/readme.txt b/platforms/android/service/readme.txt index 65678093d..51853c24e 100644 --- a/platforms/android/service/readme.txt +++ b/platforms/android/service/readme.txt @@ -14,20 +14,20 @@ manually using adb tool: .. code-block:: sh - adb install OpenCV-2.4.8-android-sdk/apk/OpenCV_2.4.8_Manager_2.16_.apk + adb install OpenCV-2.4.9-android-sdk/apk/OpenCV_2.4.9_Manager_2.18_.apk Use the table below to determine proper OpenCV Manager package for your device: +------------------------------+--------------+----------------------------------------------------+ | Hardware Platform | Android ver. | Package name | +==============================+==============+====================================================+ -| armeabi-v7a (ARMv7-A + NEON) | >= 2.3 | OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk | +| armeabi-v7a (ARMv7-A + NEON) | >= 2.3 | OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk | +------------------------------+--------------+----------------------------------------------------+ -| armeabi-v7a (ARMv7-A + NEON) | = 2.2 | OpenCV_2.4.8_Manager_2.16_armv7a-neon-android8.apk | +| armeabi-v7a (ARMv7-A + NEON) | = 2.2 | OpenCV_2.4.9_Manager_2.18_armv7a-neon-android8.apk | +------------------------------+--------------+----------------------------------------------------+ -| armeabi (ARMv5, ARMv6) | >= 2.3 | OpenCV_2.4.8_Manager_2.16_armeabi.apk | +| armeabi (ARMv5, ARMv6) | >= 2.3 | OpenCV_2.4.9_Manager_2.18_armeabi.apk | +------------------------------+--------------+----------------------------------------------------+ -| Intel x86 | >= 2.3 | OpenCV_2.4.8_Manager_2.16_x86.apk | +| Intel x86 | >= 2.3 | OpenCV_2.4.9_Manager_2.18_x86.apk | +------------------------------+--------------+----------------------------------------------------+ -| MIPS | >= 2.3 | OpenCV_2.4.8_Manager_2.16_mips.apk | +| MIPS | >= 2.3 | OpenCV_2.4.9_Manager_2.18_mips.apk | +------------------------------+--------------+----------------------------------------------------+ diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index e9a68c32f..4d4f7e3d0 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -40,6 +40,7 @@ def build_opencv(srcroot, buildroot, target, arch): "-DCMAKE_BUILD_TYPE=Release " + "-DCMAKE_TOOLCHAIN_FILE=%s/platforms/ios/cmake/Toolchains/Toolchain-%s_Xcode.cmake " + "-DBUILD_opencv_world=ON " + + "-DCMAKE_C_FLAGS=\"-Wno-implicit-function-declaration\" " + "-DCMAKE_INSTALL_PREFIX=install") % (srcroot, target) # if cmake cache exists, just rerun cmake to update OpenCV.xproj if necessary if os.path.isfile(os.path.join(builddir, "CMakeCache.txt")): diff --git a/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java b/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java index 04da9a949..b9db22de1 100644 --- a/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java +++ b/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java @@ -21,6 +21,7 @@ public class CvNativeActivity extends Activity { System.loadLibrary("native_activity"); Intent intent = new Intent(CvNativeActivity.this, android.app.NativeActivity.class); CvNativeActivity.this.startActivity(intent); + CvNativeActivity.this.finish(); } break; default: { @@ -34,7 +35,7 @@ public class CvNativeActivity extends Activity { Log.i(TAG, "Instantiated new " + this.getClass()); } - @Override + @Override public void onResume() { super.onResume(); diff --git a/samples/android/tutorial-4-cuda/CMakeLists.txt b/samples/android/tutorial-4-cuda/CMakeLists.txt index a011b3349..da9fe9871 100644 --- a/samples/android/tutorial-4-cuda/CMakeLists.txt +++ b/samples/android/tutorial-4-cuda/CMakeLists.txt @@ -1,15 +1,16 @@ set(sample example-tutorial-4-cuda) -ocv_check_dependencies(opencv_core opencv_java opencv_gpu) +ocv_check_dependencies(opencv_core opencv_features2d opencv_java opencv_gpu) if (OCV_DEPENDENCIES_FOUND) if(BUILD_FAT_JAVA_LIB) set(native_deps opencv_java opencv_gpu) else() - set(native_deps opencv_gpu) + set(native_deps opencv_core opencv_features2d opencv_java opencv_gpu) endif() - add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps}) + add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps} EMBED_CUDA ON FORCE_EMBED_OPENCV ON) + if(TARGET ${sample}) add_dependencies(opencv_android_examples ${sample}) endif() diff --git a/samples/android/tutorial-4-cuda/jni/Android.mk b/samples/android/tutorial-4-cuda/jni/Android.mk index 3d709dff3..e14b1990f 100644 --- a/samples/android/tutorial-4-cuda/jni/Android.mk +++ b/samples/android/tutorial-4-cuda/jni/Android.mk @@ -2,6 +2,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) +INSTALL_CUDA_LIBRARIES:=on +OPENCV_INSTALL_MODULES:=on CUDA_TOOLKIT_DIR=$(CUDA_TOOLKIT_ROOT) include ../../sdk/native/jni/OpenCV.mk diff --git a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java index c1753b68c..6a8cb5ec0 100644 --- a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java +++ b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java @@ -49,29 +49,6 @@ public class Tutorial4Activity extends Activity implements CvCameraViewListener2 { Log.i(TAG, "OpenCV loaded successfully"); - // Check CUDA support - if (Gpu.getCudaEnabledDeviceCount() <= 0) - { - Log.e(TAG, "No CUDA capable device found!"); - AlertDialog InitFailedDialog = new AlertDialog.Builder(Tutorial4Activity.this).create(); - InitFailedDialog.setTitle("OpenCV CUDA error"); - InitFailedDialog.setMessage("CUDA compatible device was not found!"); - InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button - InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { - - public void onClick(DialogInterface dialog, int which) { - Tutorial4Activity.this.finish(); - } - }); - InitFailedDialog.show(); - } - else - { - // Load native library after(!) OpenCV initialization - Log.i(TAG, "Found CUDA capable device!"); - System.loadLibrary("cuda_sample"); - mOpenCvCameraView.enableView(); - } } break; default: { @@ -120,7 +97,32 @@ public class Tutorial4Activity extends Activity implements CvCameraViewListener2 public void onResume() { super.onResume(); - OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback); + if (OpenCVLoader.initDebug(true)) + { + // Check CUDA support + if (Gpu.getCudaEnabledDeviceCount() <= 0) + { + Log.e(TAG, "No CUDA capable device found!"); + AlertDialog InitFailedDialog = new AlertDialog.Builder(Tutorial4Activity.this).create(); + InitFailedDialog.setTitle("OpenCV CUDA error"); + InitFailedDialog.setMessage("CUDA compatible device was not found!"); + InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button + InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Tutorial4Activity.this.finish(); + } + }); + InitFailedDialog.show(); + } + else + { + // Load native library after(!) OpenCV initialization + Log.i(TAG, "Found CUDA capable device!"); + System.loadLibrary("cuda_sample"); + mOpenCvCameraView.enableView(); + } + + } } public void onDestroy() { diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index 77a42949d..6d374e744 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -39,7 +39,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/c" COMPONENT main) + RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/c" COMPONENT samples) endif() ENDMACRO() @@ -54,6 +54,6 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/c + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif () diff --git a/samples/c/adaptiveskindetector.cpp b/samples/c/adaptiveskindetector.cpp index 37856bd4e..3ae10017d 100644 --- a/samples/c/adaptiveskindetector.cpp +++ b/samples/c/adaptiveskindetector.cpp @@ -126,12 +126,12 @@ ASDFrameHolder::ASDFrameHolder( ) { image = NULL; timeStamp = 0; -}; +} ASDFrameHolder::~ASDFrameHolder( ) { cvReleaseImage(&image); -}; +} void ASDFrameHolder::assignFrame(IplImage *sourceImage, double frameTime) { @@ -143,22 +143,22 @@ void ASDFrameHolder::assignFrame(IplImage *sourceImage, double frameTime) image = cvCloneImage(sourceImage); timeStamp = frameTime; -}; +} IplImage *ASDFrameHolder::getImage() { return image; -}; +} double ASDFrameHolder::getTimeStamp() { return timeStamp; -}; +} void ASDFrameHolder::setImage(IplImage *sourceImage) { image = sourceImage; -}; +} //-------------------- ASDFrameSequencer -----------------------// @@ -166,26 +166,26 @@ void ASDFrameHolder::setImage(IplImage *sourceImage) ASDFrameSequencer::~ASDFrameSequencer() { close(); -}; +} IplImage *ASDFrameSequencer::getNextImage() { return NULL; -}; +} void ASDFrameSequencer::close() { -}; +} bool ASDFrameSequencer::isOpen() { return false; -}; +} void ASDFrameSequencer::getFrameCaption(char* /*caption*/) { return; -}; +} IplImage* ASDCVFrameSequencer::getNextImage() { @@ -201,7 +201,7 @@ IplImage* ASDCVFrameSequencer::getNextImage() { return NULL; } -}; +} void ASDCVFrameSequencer::close() { @@ -209,12 +209,12 @@ void ASDCVFrameSequencer::close() { cvReleaseCapture(&capture); } -}; +} bool ASDCVFrameSequencer::isOpen() { return (capture != NULL); -}; +} //-------------------- ASDFrameSequencerWebCam -----------------------// @@ -233,7 +233,7 @@ bool ASDFrameSequencerWebCam::open(int cameraIndex) { return true; } -}; +} //-------------------- ASDFrameSequencerVideoFile -----------------------// @@ -251,7 +251,7 @@ bool ASDFrameSequencerVideoFile::open(const char *fileName) { return true; } -}; +} //-------------------- ASDFrameSequencerImageFile -----------------------// @@ -263,11 +263,11 @@ void ASDFrameSequencerImageFile::open(const char *fileNameMask, int startIndex, nEndIndex = endIndex; std::sprintf(sFileNameMask, "%s", fileNameMask); -}; +} void ASDFrameSequencerImageFile::getFrameCaption(char *caption) { std::sprintf(caption, sFileNameMask, nCurrentIndex); -}; +} IplImage* ASDFrameSequencerImageFile::getNextImage() { @@ -283,23 +283,23 @@ IplImage* ASDFrameSequencerImageFile::getNextImage() IplImage* img = cvLoadImage(fileName); return img; -}; +} void ASDFrameSequencerImageFile::close() { nCurrentIndex = nEndIndex+1; -}; +} bool ASDFrameSequencerImageFile::isOpen() { return (nCurrentIndex <= nEndIndex); -}; +} static void putTextWithShadow(IplImage *img, const char *str, CvPoint point, CvFont *font, CvScalar color = CV_RGB(255, 255, 128)) { cvPutText(img, str, cvPoint(point.x-1,point.y-1), font, CV_RGB(0, 0, 0)); cvPutText(img, str, point, font, color); -}; +} #define ASD_RGB_SET_PIXEL(pointer, r, g, b) { (*pointer) = (unsigned char)b; (*(pointer+1)) = (unsigned char)g; (*(pointer+2)) = (unsigned char)r; } @@ -336,7 +336,7 @@ static void displayBuffer(IplImage *rgbDestImage, IplImage *buffer, int rValue, destY = 0; destX += dx; } -}; +} int main(int argc, char** argv ) { diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index ebee5bd0a..1f55ed90f 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -68,7 +68,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT main) + RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples) endif() ENDMACRO() @@ -82,6 +82,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ocv_list_filterout(cpp_samples "/gpu/") endif() + ocv_list_filterout(cpp_samples "viz") + foreach(sample_filename ${cpp_samples}) get_filename_component(sample ${sample_filename} NAME_WE) OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename}) @@ -91,6 +93,6 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/cpp/Qt_sample/CMakeLists.txt b/samples/cpp/Qt_sample/CMakeLists.txt index e831f752f..f465947db 100644 --- a/samples/cpp/Qt_sample/CMakeLists.txt +++ b/samples/cpp/Qt_sample/CMakeLists.txt @@ -7,6 +7,6 @@ FIND_PACKAGE( OpenCV REQUIRED ) find_package (OpenGL REQUIRED) -ADD_EXECUTABLE(OpenGL_Qt_Binding main.cpp) +ADD_EXECUTABLE(OpenGL_Qt_Binding qt_opengl.cpp) TARGET_LINK_LIBRARIES(OpenGL_Qt_Binding ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cube4.avi ${CMAKE_CURRENT_BINARY_DIR}/cube4.avi COPYONLY) diff --git a/samples/cpp/Qt_sample/main.cpp b/samples/cpp/Qt_sample/main.cpp deleted file mode 100644 index 6969544a0..000000000 --- a/samples/cpp/Qt_sample/main.cpp +++ /dev/null @@ -1,275 +0,0 @@ -//Yannick Verdie 2010 - -//--- Please read help() below: --- - -#include -#include - -#include -#include -#include -#include -#include - -#if defined WIN32 || defined _WIN32 || defined WINCE - #include - #undef small - #undef min - #undef max - #undef abs -#endif - -#ifdef __APPLE__ - #include -#else - #include -#endif - -using namespace std; -using namespace cv; - -static void help() -{ - cout << "\nThis demo demonstrates the use of the Qt enhanced version of the highgui GUI interface\n" - " and dang if it doesn't throw in the use of of the POSIT 3D tracking algorithm too\n" - "It works off of the video: cube4.avi\n" - "Using OpenCV version %s\n" << CV_VERSION << "\n\n" -" 1). This demo is mainly based on work from Javier Barandiaran Martirena\n" -" See this page http://code.opencv.org/projects/opencv/wiki/Posit.\n" -" 2). This is a demo to illustrate how to use **OpenGL Callback**.\n" -" 3). You need Qt binding to compile this sample with OpenGL support enabled.\n" -" 4). The features' detection is very basic and could highly be improved \n" -" (basic thresholding tuned for the specific video) but 2).\n" -" 5) THANKS TO Google Summer of Code 2010 for supporting this work!\n" << endl; -} - -#define FOCAL_LENGTH 600 -#define CUBE_SIZE 10 - -static void renderCube(float size) -{ - glBegin(GL_QUADS); - // Front Face - glNormal3f( 0.0f, 0.0f, 1.0f); - glVertex3f( 0.0f, 0.0f, 0.0f); - glVertex3f( size, 0.0f, 0.0f); - glVertex3f( size, size, 0.0f); - glVertex3f( 0.0f, size, 0.0f); - // Back Face - glNormal3f( 0.0f, 0.0f,-1.0f); - glVertex3f( 0.0f, 0.0f, size); - glVertex3f( 0.0f, size, size); - glVertex3f( size, size, size); - glVertex3f( size, 0.0f, size); - // Top Face - glNormal3f( 0.0f, 1.0f, 0.0f); - glVertex3f( 0.0f, size, 0.0f); - glVertex3f( size, size, 0.0f); - glVertex3f( size, size, size); - glVertex3f( 0.0f, size, size); - // Bottom Face - glNormal3f( 0.0f,-1.0f, 0.0f); - glVertex3f( 0.0f, 0.0f, 0.0f); - glVertex3f( 0.0f, 0.0f, size); - glVertex3f( size, 0.0f, size); - glVertex3f( size, 0.0f, 0.0f); - // Right face - glNormal3f( 1.0f, 0.0f, 0.0f); - glVertex3f( size, 0.0f, 0.0f); - glVertex3f( size, 0.0f, size); - glVertex3f( size, size, size); - glVertex3f( size, size, 0.0f); - // Left Face - glNormal3f(-1.0f, 0.0f, 0.0f); - glVertex3f( 0.0f, 0.0f, 0.0f); - glVertex3f( 0.0f, size, 0.0f); - glVertex3f( 0.0f, size, size); - glVertex3f( 0.0f, 0.0f, size); - glEnd(); -} - - -static void on_opengl(void* param) -{ - //Draw the object with the estimated pose - glLoadIdentity(); - glScalef( 1.0f, 1.0f, -1.0f); - glMultMatrixf( (float*)param ); - glEnable( GL_LIGHTING ); - glEnable( GL_LIGHT0 ); - glEnable( GL_BLEND ); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - renderCube( CUBE_SIZE ); - glDisable(GL_BLEND); - glDisable( GL_LIGHTING ); -} - -static void initPOSIT(std::vector *modelPoints) -{ - //Create the model pointss - modelPoints->push_back(cvPoint3D32f(0.0f, 0.0f, 0.0f)); //The first must be (0,0,0) - modelPoints->push_back(cvPoint3D32f(0.0f, 0.0f, CUBE_SIZE)); - modelPoints->push_back(cvPoint3D32f(CUBE_SIZE, 0.0f, 0.0f)); - modelPoints->push_back(cvPoint3D32f(0.0f, CUBE_SIZE, 0.0f)); -} - -static void foundCorners(vector *srcImagePoints, const Mat& source, Mat& grayImage) -{ - cvtColor(source, grayImage, COLOR_RGB2GRAY); - GaussianBlur(grayImage, grayImage, Size(11,11), 0, 0); - normalize(grayImage, grayImage, 0, 255, NORM_MINMAX); - threshold(grayImage, grayImage, 26, 255, THRESH_BINARY_INV); //25 - - Mat MgrayImage = grayImage; - //For debug - //MgrayImage = MgrayImage.clone();//deep copy - vector > contours; - vector hierarchy; - findContours(MgrayImage, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); - - Point p; - vector srcImagePoints_temp(4,cvPoint2D32f(0,0)); - - if (contours.size() == srcImagePoints_temp.size()) - { - - for(size_t i = 0 ; i y = 0 - //> x = 1 - //< x = 2 - //< y = 3 - - //get point 0; - size_t index = 0; - for(size_t i = 1 ; i srcImagePoints_temp.at(index).y) - index = i; - } - srcImagePoints->at(0) = srcImagePoints_temp.at(index); - - //get point 1; - index = 0; - for(size_t i = 1 ; i srcImagePoints_temp.at(index).x) - index = i; - } - srcImagePoints->at(1) = srcImagePoints_temp.at(index); - - //get point 2; - index = 0; - for(size_t i = 1 ; iat(2) = srcImagePoints_temp.at(index); - - //get point 3; - index = 0; - for(size_t i = 1 ; iat(3) = srcImagePoints_temp.at(index); - - Mat Msource = source; - stringstream ss; - for(size_t i = 0 ; iat(i),5,Scalar(0,0,255)); - putText(Msource,ss.str(),srcImagePoints->at(i),FONT_HERSHEY_SIMPLEX,1,Scalar(0,0,255)); - ss.str(""); - - //new coordinate system in the middle of the frame and reversed (camera coordinate system) - srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x-source.cols/2,source.rows/2-srcImagePoints_temp.at(i).y); - } - } - -} - -static void createOpenGLMatrixFrom(float *posePOSIT,const CvMatr32f &rotationMatrix, const CvVect32f &translationVector) -{ - - - //coordinate system returned is relative to the first 3D input point - for (int f=0; f<3; f++) - { - for (int c=0; c<3; c++) - { - posePOSIT[c*4+f] = rotationMatrix[f*3+c]; //transposed - } - } - posePOSIT[3] = 0.0; - posePOSIT[7] = 0.0; - posePOSIT[11] = 0.0; - posePOSIT[12] = translationVector[0]; - posePOSIT[13] = translationVector[1]; - posePOSIT[14] = translationVector[2]; - posePOSIT[15] = 1.0; -} - -int main(void) -{ - help(); - VideoCapture video("cube4.avi"); - CV_Assert(video.isOpened()); - - Mat source, grayImage; - - video >> source; - - namedWindow("original", WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO); - namedWindow("POSIT", WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO); - displayOverlay("POSIT", "We lost the 4 corners' detection quite often (the red circles disappear). This demo is only to illustrate how to use OpenGL callback.\n -- Press ESC to exit.", 10000); - - float OpenGLMatrix[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - setOpenGlDrawCallback("POSIT",on_opengl,OpenGLMatrix); - - vector modelPoints; - initPOSIT(&modelPoints); - - //Create the POSIT object with the model points - CvPOSITObject* positObject = cvCreatePOSITObject( &modelPoints[0], (int)modelPoints.size() ); - - CvMatr32f rotation_matrix = new float[9]; - CvVect32f translation_vector = new float[3]; - CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 100, 1.0e-4f); - - vector srcImagePoints(4,cvPoint2D32f(0,0)); - - - while(waitKey(33) != 27) - { - video >> source; - imshow("original",source); - - foundCorners(&srcImagePoints,source,grayImage); - cvPOSIT( positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector ); - createOpenGLMatrixFrom(OpenGLMatrix,rotation_matrix,translation_vector); - - imshow("POSIT",source); - - if (video.get(CV_CAP_PROP_POS_AVI_RATIO) > 0.99) - video.set(CV_CAP_PROP_POS_AVI_RATIO, 0); - } - - destroyAllWindows(); - cvReleasePOSITObject(&positObject); - - return 0; -} diff --git a/samples/cpp/Qt_sample/qt_opengl.cpp b/samples/cpp/Qt_sample/qt_opengl.cpp new file mode 100644 index 000000000..2878da4c0 --- /dev/null +++ b/samples/cpp/Qt_sample/qt_opengl.cpp @@ -0,0 +1,268 @@ +// Yannick Verdie 2010 +// --- Please read help() below: --- + +#include +#include + +#include +#include +#include +#include +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif + +using namespace std; +using namespace cv; + +static void help() +{ + cout << "This demo demonstrates the use of the Qt enhanced version of the highgui GUI interface\n" + "and dang if it doesn't throw in the use of of the POSIT 3D tracking algorithm too\n" + "It works off of the video: cube4.avi\n" + "Using OpenCV version " << CV_VERSION << "\n\n" + + " 1) This demo is mainly based on work from Javier Barandiaran Martirena\n" + " See this page http://code.opencv.org/projects/opencv/wiki/Posit.\n" + " 2) This is a demo to illustrate how to use **OpenGL Callback**.\n" + " 3) You need Qt binding to compile this sample with OpenGL support enabled.\n" + " 4) The features' detection is very basic and could highly be improved\n" + " (basic thresholding tuned for the specific video) but 2).\n" + " 5) Thanks to Google Summer of Code 2010 for supporting this work!\n" << endl; +} + +#define FOCAL_LENGTH 600 +#define CUBE_SIZE 0.5 + +static void renderCube(float size) +{ + glBegin(GL_QUADS); + // Front Face + glNormal3f( 0.0f, 0.0f, 1.0f); + glVertex3f( 0.0f, 0.0f, 0.0f); + glVertex3f( size, 0.0f, 0.0f); + glVertex3f( size, size, 0.0f); + glVertex3f( 0.0f, size, 0.0f); + // Back Face + glNormal3f( 0.0f, 0.0f,-1.0f); + glVertex3f( 0.0f, 0.0f, size); + glVertex3f( 0.0f, size, size); + glVertex3f( size, size, size); + glVertex3f( size, 0.0f, size); + // Top Face + glNormal3f( 0.0f, 1.0f, 0.0f); + glVertex3f( 0.0f, size, 0.0f); + glVertex3f( size, size, 0.0f); + glVertex3f( size, size, size); + glVertex3f( 0.0f, size, size); + // Bottom Face + glNormal3f( 0.0f,-1.0f, 0.0f); + glVertex3f( 0.0f, 0.0f, 0.0f); + glVertex3f( 0.0f, 0.0f, size); + glVertex3f( size, 0.0f, size); + glVertex3f( size, 0.0f, 0.0f); + // Right face + glNormal3f( 1.0f, 0.0f, 0.0f); + glVertex3f( size, 0.0f, 0.0f); + glVertex3f( size, 0.0f, size); + glVertex3f( size, size, size); + glVertex3f( size, size, 0.0f); + // Left Face + glNormal3f(-1.0f, 0.0f, 0.0f); + glVertex3f( 0.0f, 0.0f, 0.0f); + glVertex3f( 0.0f, size, 0.0f); + glVertex3f( 0.0f, size, size); + glVertex3f( 0.0f, 0.0f, size); + glEnd(); +} + +static void on_opengl(void* param) +{ + //Draw the object with the estimated pose + glLoadIdentity(); + glScalef( 1.0f, 1.0f, -1.0f); + glMultMatrixf( (float*)param ); + glEnable( GL_LIGHTING ); + glEnable( GL_LIGHT0 ); + glEnable( GL_BLEND ); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + renderCube( CUBE_SIZE ); + glDisable(GL_BLEND); + glDisable( GL_LIGHTING ); +} + +static void initPOSIT(std::vector * modelPoints) +{ + // Create the model pointss + modelPoints->push_back(cvPoint3D32f(0.0f, 0.0f, 0.0f)); // The first must be (0, 0, 0) + modelPoints->push_back(cvPoint3D32f(0.0f, 0.0f, CUBE_SIZE)); + modelPoints->push_back(cvPoint3D32f(CUBE_SIZE, 0.0f, 0.0f)); + modelPoints->push_back(cvPoint3D32f(0.0f, CUBE_SIZE, 0.0f)); +} + +static void foundCorners(vector * srcImagePoints, const Mat & source, Mat & grayImage) +{ + cvtColor(source, grayImage, COLOR_RGB2GRAY); + GaussianBlur(grayImage, grayImage, Size(11, 11), 0, 0); + normalize(grayImage, grayImage, 0, 255, NORM_MINMAX); + threshold(grayImage, grayImage, 26, 255, THRESH_BINARY_INV); //25 + + Mat MgrayImage = grayImage; + vector > contours; + vector hierarchy; + findContours(MgrayImage, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + + Point p; + vector srcImagePoints_temp(4, cvPoint2D32f(0, 0)); + + if (contours.size() == srcImagePoints_temp.size()) + { + for (size_t i = 0; i < contours.size(); i++ ) + { + p.x = p.y = 0; + + for (size_t j = 0 ; j < contours[i].size(); j++) + p += contours[i][j]; + + srcImagePoints_temp.at(i) = cvPoint2D32f(float(p.x) / contours[i].size(), float(p.y) / contours[i].size()); + } + + // Need to keep the same order + // > y = 0 + // > x = 1 + // < x = 2 + // < y = 3 + + // get point 0; + size_t index = 0; + for (size_t i = 1 ; i srcImagePoints_temp.at(index).y) + index = i; + srcImagePoints->at(0) = srcImagePoints_temp.at(index); + + // get point 1; + index = 0; + for (size_t i = 1 ; i srcImagePoints_temp.at(index).x) + index = i; + srcImagePoints->at(1) = srcImagePoints_temp.at(index); + + // get point 2; + index = 0; + for (size_t i = 1 ; iat(2) = srcImagePoints_temp.at(index); + + // get point 3; + index = 0; + for (size_t i = 1 ; iat(3) = srcImagePoints_temp.at(index); + + Mat Msource = source; + stringstream ss; + for (size_t i = 0; iat(i), 5, Scalar(0, 0, 255)); + putText(Msource, ss.str(), srcImagePoints->at(i), FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 0, 255)); + ss.str(""); + + // new coordinate system in the middle of the frame and reversed (camera coordinate system) + srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x - source.cols / 2, + source.rows / 2 - srcImagePoints_temp.at(i).y); + } + } +} + +static void createOpenGLMatrixFrom(float * posePOSIT, const CvMatr32f & rotationMatrix, + const CvVect32f & translationVector) +{ + // coordinate system returned is relative to the first 3D input point + for (int f = 0; f < 3; f++) + for (int c = 0; c < 3; c++) + posePOSIT[c * 4 + f] = rotationMatrix[f * 3 + c]; // transposed + + posePOSIT[3] = translationVector[0]; + posePOSIT[7] = translationVector[1]; + posePOSIT[11] = translationVector[2]; + posePOSIT[12] = 0.0f; + posePOSIT[13] = 0.0f; + posePOSIT[14] = 0.0f; + posePOSIT[15] = 1.0f; +} + +int main(void) +{ + help(); + + string fileName = "cube4.avi"; + VideoCapture video(fileName); + if (!video.isOpened()) + { + cerr << "Video file " << fileName << " could not be opened" << endl; + return EXIT_FAILURE; + } + + Mat source, grayImage; + video >> source; + + namedWindow("Original", WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO); + namedWindow("POSIT", WINDOW_OPENGL | CV_WINDOW_FREERATIO); + resizeWindow("POSIT", source.cols, source.rows); + + displayOverlay("POSIT", "We lost the 4 corners' detection quite often (the red circles disappear).\n" + "This demo is only to illustrate how to use OpenGL callback.\n" + " -- Press ESC to exit.", 10000); + + float OpenGLMatrix[] = { 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 }; + setOpenGlContext("POSIT"); + setOpenGlDrawCallback("POSIT", on_opengl, OpenGLMatrix); + + vector modelPoints; + initPOSIT(&modelPoints); + + // Create the POSIT object with the model points + CvPOSITObject* positObject = cvCreatePOSITObject( &modelPoints[0], (int)modelPoints.size()); + + CvMatr32f rotation_matrix = new float[9]; + CvVect32f translation_vector = new float[3]; + CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 100, 1e-4f); + vector srcImagePoints(4, cvPoint2D32f(0, 0)); + + while (waitKey(33) != 27) + { + video >> source; + if (source.empty()) + break; + + imshow("Original", source); + + foundCorners(&srcImagePoints, source, grayImage); + cvPOSIT(positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector); + createOpenGLMatrixFrom(OpenGLMatrix, rotation_matrix, translation_vector); + + updateWindow("POSIT"); + + if (video.get(CV_CAP_PROP_POS_AVI_RATIO) > 0.99) + video.set(CV_CAP_PROP_POS_AVI_RATIO, 0); + } + + setOpenGlDrawCallback("POSIT", NULL, NULL); + destroyAllWindows(); + cvReleasePOSITObject(&positObject); + + delete[]rotation_matrix; + delete[]translation_vector; + + return EXIT_SUCCESS; +} diff --git a/samples/cpp/calibration_artificial.cpp b/samples/cpp/calibration_artificial.cpp index c22cb528f..7d443c1db 100644 --- a/samples/cpp/calibration_artificial.cpp +++ b/samples/cpp/calibration_artificial.cpp @@ -46,7 +46,7 @@ private: Point3f generateChessBoardCenter(const Mat& camMat, const Size& imgSize) const; Mat rvec, tvec; }; -}; +} diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index 97de6a0a4..d475cf175 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -36,7 +36,7 @@ int main( int /*argc*/, char** /*argv*/ ) Mat points(sampleCount, 1, CV_32FC2), labels; clusterCount = MIN(clusterCount, sampleCount); - Mat centers(clusterCount, 1, points.type()); + Mat centers; /* generate random sample from multigaussian distribution */ for( k = 0; k < clusterCount; k++ ) diff --git a/samples/cpp/morphology2.cpp b/samples/cpp/morphology2.cpp index 330f4e064..a7793008a 100644 --- a/samples/cpp/morphology2.cpp +++ b/samples/cpp/morphology2.cpp @@ -12,7 +12,7 @@ static void help() printf("\nShow off image morphology: erosion, dialation, open and close\n" "Call:\n morphology2 [image]\n" - "This program also shows use of rect, elipse and cross kernels\n\n"); + "This program also shows use of rect, ellipse and cross kernels\n\n"); printf( "Hot keys: \n" "\tESC - quit the program\n" "\tr - use rectangle structuring element\n" diff --git a/samples/cpp/stitching_detailed.cpp b/samples/cpp/stitching_detailed.cpp index 7394a7282..4162addb3 100644 --- a/samples/cpp/stitching_detailed.cpp +++ b/samples/cpp/stitching_detailed.cpp @@ -355,7 +355,7 @@ int main(int argc, char* argv[]) Ptr finder; if (features_type == "surf") { -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) finder = new SurfFeaturesFinderGpu(); else @@ -543,7 +543,7 @@ int main(int argc, char* argv[]) // Warp images and their masks Ptr warper_creator; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) { if (warp_type == "plane") warper_creator = new cv::PlaneWarperGpu(); @@ -608,7 +608,7 @@ int main(int argc, char* argv[]) seam_finder = new detail::VoronoiSeamFinder(); else if (seam_find_type == "gc_color") { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR); else @@ -617,7 +617,7 @@ int main(int argc, char* argv[]) } else if (seam_find_type == "gc_colorgrad") { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR_GRAD); else diff --git a/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp index f4dd4e5e4..424a38e93 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp @@ -40,13 +40,13 @@ int main( int argc, char** argv ) hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) ); - /// Using 30 bins for hue and 32 for saturation + /// Using 50 bins for hue and 60 for saturation int h_bins = 50; int s_bins = 60; int histSize[] = { h_bins, s_bins }; - // hue varies from 0 to 256, saturation from 0 to 180 - float s_ranges[] = { 0, 256 }; + // hue varies from 0 to 179, saturation from 0 to 255 float h_ranges[] = { 0, 180 }; + float s_ranges[] = { 0, 256 }; const float* ranges[] = { h_ranges, s_ranges }; diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp index d98cc1182..96d5686a8 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp @@ -14,7 +14,7 @@ using namespace cv; /// Global variables int threshold_value = 0; -int threshold_type = 3;; +int threshold_type = 3; int const max_value = 255; int const max_type = 4; int const max_BINARY_value = 255; diff --git a/samples/cpp/tutorial_code/viz/bunny.ply b/samples/cpp/tutorial_code/viz/bunny.ply new file mode 100644 index 000000000..7d3423339 --- /dev/null +++ b/samples/cpp/tutorial_code/viz/bunny.ply @@ -0,0 +1,5752 @@ +ply +format ascii 1.0 +comment zipper output +element vertex 1889 +property float x +property float y +property float z +property float confidence +property float intensity +element face 3851 +property list uchar int vertex_indices +end_header +-0.0369122 0.127512 0.00276757 0.850855 0.5 +-0.0457707 0.130327 0.00306785 0.900159 0.5 +-0.0708847 0.149834 0.0388672 0.398443 0.5 +-0.00331557 0.130403 0.0212208 0.85268 0.5 +-0.0211979 0.1272 0.00915278 0.675938 0.5 +-0.0265255 0.12592 0.00874866 0.711533 0.5 +0.0339261 0.112038 0.0269672 0.652757 0.5 +0.0376485 0.110455 0.0145481 0.708171 0.5 +-0.0259368 0.111118 0.0379115 0.454541 0.437538 +0.027952 0.120939 0.0215377 0.533079 0.5 +-0.0628308 0.155987 -0.0150105 0.404517 0.5 +0.0390029 0.106711 0.0215202 0.535542 0.5 +0.0447976 0.0950477 0.00866471 0.579563 0.425995 +-0.0330636 0.173619 -0.0031267 0.365607 0.5 +-0.0808069 0.136243 0.0495014 0.499575 0.5 +-0.0705086 0.12445 0.0526685 0.564827 0.5 +0.00874873 0.131225 0.0145345 0.748371 0.5 +0.0401015 0.106711 0.00874166 0.680399 0.5 +0.0379483 0.100145 -0.00827134 0.600054 0.5 +-0.0906538 0.137201 0.0207305 0.824561 0.5 +-0.0841655 0.110667 0.0275273 0.690889 0.5 +-0.0705214 0.156214 0.0144536 0.807492 0.5 +-0.083872 0.15212 0.0282652 0.248168 0.41865 +0.00305028 0.12432 0.0332425 0.555044 0.354559 +0.00870828 0.124165 0.0330348 0.653433 0.5 +-0.0328896 0.12613 0.00300653 0.898771 0.5 +-0.0506302 0.143065 0.0150611 0.691477 0.5 +-0.0757863 0.13637 0.050172 0.566256 0.5 +-0.0027191 0.128962 0.0264678 0.271491 0.462815 +-0.0460961 0.125118 0.0263142 0.539149 0.5 +-0.0785104 0.0942728 -0.0109192 0.710999 0.5 +0.0216915 0.125373 0.0211452 0.530957 0.5 +-0.0888469 0.124305 0.00237041 0.635593 0.5 +0.040386 0.100825 -0.00303043 0.574857 0.5 +-0.0884145 0.117791 0.00268555 0.487167 0.430737 +-0.0319074 0.177421 -0.00491879 0.269231 0.447035 +-0.0765825 0.143224 0.0455148 0.414139 0.5 +-0.0209748 0.112544 0.0388613 0.482541 0.5 +-0.020836 0.179425 -0.0221622 0.341071 0.440034 +-0.0377039 0.167987 -0.0130391 0.396317 0.473039 +-0.0331765 0.12681 0.00839958 0.896274 0.5 +0.00893926 0.127114 0.0292916 0.350014 0.41288 +-0.044944 0.131083 0.0147963 0.599596 0.5 +-0.0266041 0.12515 0.00282384 0.73687 0.5 +0.0144285 0.12328 0.0319185 0.625269 0.5 +0.019244 0.122284 0.0308314 0.611204 0.34486 +-0.0390225 0.167317 0.00215527 0.413994 0.469929 +-0.08808 0.129976 0.00206377 0.625486 0.5 +-0.0537203 0.142608 0.0266058 0.696873 0.5 +0.043095 0.0980072 0.0191617 0.665192 0.5 +0.0432138 0.100117 0.00866473 0.691828 0.5 +0.0415448 0.0944954 0.0275695 0.671611 0.5 +-0.0578726 0.155337 0.0149245 0.394763 0.437313 +-0.0231577 0.157375 -0.0046304 0.136389 0.380194 +-0.0683123 0.145735 0.0420568 0.751812 0.5 +-0.0708351 0.142847 0.0451248 0.627973 0.5 +-0.070664 0.0642894 0.0209789 0.413051 0.5 +-0.0761519 0.130581 0.0525324 0.629117 0.5 +-0.0640036 0.161784 -0.0208118 0.449093 0.5 +-0.0706461 0.155711 0.00252406 0.855717 0.5 +-0.0924366 0.118434 0.0399838 0.673877 0.5 +-0.0635349 0.156052 0.0148814 0.798496 0.5 +0.0282675 0.118192 0.0274382 0.635485 0.5 +0.0392736 0.0938857 -0.00915453 0.585857 0.459742 +-0.0695973 0.164844 -0.0174846 0.548789 0.5 +-0.00892354 0.123904 0.0330319 0.602316 0.374044 +0.0269099 0.0942476 0.0444911 0.649753 0.5 +-0.0146258 0.162377 -0.0144398 0.338176 0.5 +-0.0450983 0.167072 0.00289327 0.449091 0.5 +-0.0761536 0.172742 -0.0384391 0.256591 0.4298 +-0.0858274 0.105458 0.00472318 0.523819 0.297125 +0.0370431 0.110443 0.0207229 0.52623 0.448558 +0.0321593 0.0994027 0.0380657 0.733041 0.5 +-0.075287 0.146433 0.0428582 0.424358 0.5 +-0.0395145 0.171107 0.000531747 0.452893 0.5 +-0.0839586 0.11215 0.00148754 0.436727 0.419097 +0.0446848 0.0883378 0.0216285 0.487783 0.481728 +0.0161783 0.127819 0.0220535 0.481793 0.5 +-0.00251635 0.0397232 0.0474087 0.280725 0.5 +0.00303163 0.0406968 0.0460422 0.331809 0.5 +-0.0143059 0.128197 0.00333856 0.693854 0.5 +-0.0526117 0.155596 0.0109972 0.561042 0.5 +-0.0332043 0.17776 -0.00906223 0.212789 0.5 +0.0394391 0.106654 0.00306577 0.522321 0.489889 +-0.0923799 0.1249 0.0327641 0.848517 0.5 +0.0454681 0.0882959 0.0146642 0.575503 0.5 +-0.0274495 0.179802 -0.00925837 0.258799 0.457369 +-0.072504 0.146297 0.0429682 0.549207 0.5 +-0.0579959 0.129793 0.0383118 0.658867 0.444043 +0.043117 0.0923689 0.0251649 0.622686 0.5 +-0.00865718 0.130323 0.0149721 0.633691 0.5 +-0.0141304 0.129188 0.0147431 0.547632 0.5 +-0.0707877 0.15583 0.00921954 0.739059 0.5 +-0.00952731 0.127041 0.0281475 0.375412 0.377874 +-0.0646289 0.153404 0.0329146 0.855321 0.5 +-0.0706939 0.15347 0.0328596 0.444959 0.455263 +0.0208126 0.118434 0.0336393 0.519282 0.5 +-0.0396566 0.173008 -0.00299705 0.274377 0.177706 +-0.0442176 0.170815 -0.00391429 0.245926 0.5 +-0.0582565 0.0395149 0.0457796 0.417977 0.459314 +-0.0523033 0.0401501 0.04623 0.454776 0.456044 +-0.0760211 0.161274 -0.0145891 0.267801 0.372187 +-0.0693983 0.163016 -0.0140293 0.403228 0.45768 +0.0399663 0.106491 0.014952 0.713602 0.5 +0.041536 0.0950084 -0.00475737 0.490139 0.464008 +-0.0470079 0.163779 0.00528295 0.432857 0.486946 +-0.0402546 0.161678 0.00298655 0.447592 0.5 +-0.0386569 0.0389805 0.0441153 0.509262 0.5 +-0.0704175 0.166991 -0.0216976 0.332592 0.447054 +-0.0254201 0.0886622 0.0503827 0.608282 0.5 +-0.0886334 0.137429 0.00876953 0.549009 0.5 +-0.014179 0.12627 0.0266417 0.420759 0.5 +-0.0360017 0.17408 -0.0118959 0.409753 0.289042 +-0.0886251 0.0937834 0.00823534 0.753697 0.5 +-0.0648672 0.155874 -0.00891497 0.595216 0.5 +-0.0704508 0.137752 -0.00774011 0.446131 0.5 +-0.0750154 0.166247 -0.0219558 0.263106 0.5 +0.0299465 0.114869 0.0300239 0.642356 0.5 +0.0398138 0.0998788 0.0273101 0.51725 0.5 +-0.015242 0.111698 0.0407424 0.605597 0.5 +-0.0700387 0.118219 0.0524379 0.585543 0.5 +0.0149973 0.112399 0.0386082 0.669811 0.5 +-0.036487 0.171225 0.000545037 0.438578 0.5 +-0.0641664 0.118551 -0.00968333 0.569796 0.5 +-0.071817 0.166979 -0.0463822 0.381568 0.451091 +-0.0913559 0.14534 0.0246937 0.648478 0.5 +0.00903703 0.112569 0.0396571 0.549283 0.408623 +0.0324674 0.0997396 -0.0141603 0.732658 0.5 +0.0417911 0.101845 0.00188609 0.547756 0.5 +0.00302992 0.112517 0.0415434 0.592572 0.5 +-0.0650368 0.148485 0.0382561 0.62562 0.5 +-0.0706519 0.13063 0.0502497 0.563116 0.5 +-0.0144471 0.128935 0.00903509 0.682121 0.5 +0.00292575 0.131541 0.00912318 0.795238 0.5 +-0.0625682 0.151125 0.035875 0.463512 0.5 +0.0349829 0.113328 0.0214487 0.620597 0.5 +0.021327 0.0385664 0.0392992 0.259499 0.426724 +0.0145125 0.093771 0.0501571 0.654705 0.5 +-0.00923752 0.112849 0.0413907 0.615633 0.5 +0.0415329 0.100906 0.0210277 0.662312 0.5 +0.0422859 0.101486 0.0146614 0.569693 0.490777 +-0.0773783 0.112839 -0.00448759 0.505277 0.5 +-0.078035 0.137641 -0.00517379 0.466714 0.5 +0.00873437 0.106347 -0.0202193 0.792948 0.5 +0.0090324 0.13035 0.0211569 0.465873 0.5 +0.00301322 0.130902 0.0206741 0.592486 0.5 +-0.00286342 0.13115 0.0147367 0.587804 0.5 +-0.0391578 0.12569 0.0207996 0.438744 0.464814 +-0.0205725 0.123523 0.0265579 0.445477 0.415699 +-0.0644194 0.155634 0.00928477 0.611624 0.331941 +-0.0463385 0.131411 0.0207671 0.674928 0.5 +-0.0532034 0.0439067 0.044658 0.417403 0.440199 +-0.00297651 0.131046 0.00884967 0.738924 0.5 +-0.089664 0.137755 0.0263925 0.80362 0.5 +-0.00888731 0.124273 -0.00880284 0.767738 0.284429 +-0.0460971 0.0385107 0.0446891 0.654962 0.5 +-0.0649255 0.178874 -0.0579325 0.245129 0.411885 +-0.0329347 0.124601 0.0211235 0.32811 0.5 +-0.0831301 0.149901 0.0334123 0.331963 0.314683 +-0.0895652 0.093948 0.0149303 0.603378 0.5 +-0.0328901 0.124518 -0.00282055 0.63839 0.5 +-0.0845271 0.106161 0.00204328 0.338681 0.43162 +-0.0469341 0.155816 0.00872921 0.470367 0.484595 +0.0206202 0.123943 0.0267275 0.477255 0.5 +-0.026256 0.117499 0.0321672 0.543293 0.5 +-0.021392 0.118632 0.0336445 0.468887 0.429556 +-0.0195069 0.116132 0.0368525 0.534732 0.411301 +-0.0761618 0.118382 0.0520923 0.490413 0.5 +0.00889281 0.0395765 0.0451727 0.476347 0.38769 +-0.0534736 0.159548 0.00753828 0.476667 0.5 +-0.0469464 0.161226 0.00680216 0.495992 0.483766 +-0.0574886 0.154862 0.0204748 0.677314 0.5 +0.0317199 0.117635 0.0202007 0.579556 0.5 +0.0378683 0.105514 -0.00259159 0.588286 0.5 +-0.0811847 0.137693 -0.00253994 0.641736 0.5 +-0.0764348 0.124515 0.0528345 0.65366 0.5 +0.0343816 0.106104 -0.00900254 0.534403 0.5 +0.0457922 0.088316 0.00867097 0.586292 0.439394 +-0.0703288 0.0944195 -0.0159143 0.511499 0.5 +-0.0756048 0.0937947 -0.0135536 0.429902 0.5 +-0.058657 0.156369 0.0093256 0.31374 0.5 +-0.0637335 0.153848 0.00222718 0.478676 0.5 +-0.0777278 0.0960024 0.0363437 0.678588 0.5 +-0.0868519 0.136556 0.00309926 0.517441 0.5 +-0.0455299 0.0432404 0.0432162 0.712662 0.5 +-0.0402011 0.045749 0.0408051 0.669165 0.320516 +-0.0654123 0.160403 -0.0149066 0.335302 0.5 +-0.0318898 0.0387174 0.0510004 0.553401 0.5 +-0.0267997 0.0453977 0.0509311 0.501112 0.5 +-0.0271043 0.0396972 0.0535379 0.487956 0.5 +-0.0215575 0.0460868 0.0517209 0.709553 0.5 +-0.0143078 0.0445295 0.0504368 0.575852 0.5 +-0.00981594 0.043264 0.0493162 0.448927 0.393067 +-0.00348436 0.044054 0.0472086 0.598081 0.5 +0.009577 0.0458139 0.0465877 0.519814 0.433928 +0.02048 0.111086 0.0379569 0.681163 0.5 +-0.0141831 0.128547 0.0200007 0.293349 0.5 +-0.0526702 0.144108 0.0210347 0.639643 0.5 +-0.0634838 0.17384 -0.0527131 0.549906 0.5 +-0.0366553 0.171999 -0.0125745 0.436075 0.5 +-0.0525548 0.131228 0.0328277 0.727547 0.5 +-0.0659567 0.132023 0.0442925 0.724494 0.5 +-0.0921726 0.11832 0.0267606 0.794672 0.5 +0.0452792 0.0882737 0.00268175 0.507794 0.5 +-0.00305651 0.112889 0.0417789 0.635396 0.5 +-0.0451955 0.161396 -0.00871567 0.424682 0.5 +-0.0402914 0.160933 -0.0115368 0.411895 0.405943 +-0.0521414 0.0701165 0.0389584 0.682177 0.456916 +-0.0383315 0.093604 -0.0232581 0.72469 0.5 +-0.0690556 0.137374 0.046352 0.61723 0.5 +-0.0695996 0.167401 -0.0516299 0.518552 0.5 +-0.00246047 0.124102 0.0337609 0.444043 0.5 +-0.0398624 0.128204 0.00299348 0.864483 0.5 +-0.0753331 0.149032 0.0395625 0.432149 0.5 +-0.0701432 0.160618 -0.00917801 0.464361 0.5 +-0.0589378 0.0440425 0.0434222 0.437887 0.447715 +-0.0207164 0.126445 0.00312493 0.710427 0.5 +-0.00850666 0.0467286 0.0481052 0.613173 0.5 +0.00300323 0.0450308 0.0469911 0.464978 0.5 +-0.0802174 0.148665 0.0379438 0.47939 0.5 +-0.0819961 0.130698 0.0513437 0.54405 0.5 +0.00273088 0.106333 -0.0209927 0.733954 0.5 +-0.0757273 0.0885687 -0.0138399 0.397424 0.5 +-0.0698477 0.0882875 -0.0167823 0.420617 0.5 +-0.0668508 0.159243 -0.0102161 0.42216 0.440727 +-0.0226988 0.0885773 0.0536309 0.546444 0.5 +-0.00281419 0.0990077 0.0505614 0.455087 0.5 +0.0452902 0.0696213 0.0253974 0.33948 0.5 +-0.0525629 0.0472823 0.040482 0.279548 0.5 +-0.046959 0.0466581 0.0408127 0.43714 0.5 +-0.0691348 0.156682 -0.00276369 0.629099 0.5 +-0.0897599 0.150073 0.0220744 0.276354 0.5 +-0.0702883 0.155637 0.0263654 0.47565 0.441038 +-0.0765031 0.154893 0.0266005 0.799832 0.5 +-0.00804843 0.0987379 0.0505998 0.327523 0.438474 +0.0300791 0.11567 -0.00430465 0.66246 0.5 +-0.0923054 0.117757 0.0334441 0.476916 0.5 +-0.0331192 0.0449511 0.0462474 0.432059 0.466683 +-0.0337794 0.113308 0.034612 0.683562 0.5 +-0.0521291 0.113769 0.0349566 0.515399 0.5 +0.0437636 0.0825382 -0.0027974 0.568535 0.5 +-0.0202819 0.126016 0.0210507 0.374818 0.437592 +0.0327872 0.043925 0.0295904 0.650152 0.5 +-0.0453372 0.155266 -0.0075525 0.386286 0.5 +-0.0284609 0.173987 -0.0175958 0.379432 0.418735 +0.0268448 0.0881755 -0.0223077 0.715629 0.5 +-0.0308231 0.0923023 -0.0246377 0.474586 0.431409 +-0.0899732 0.149975 0.0141115 0.257143 0.5 +0.0381804 0.105121 0.0266947 0.534482 0.490368 +0.00842001 0.12907 0.0258154 0.374593 0.448613 +-0.0266549 0.0942999 -0.0265555 0.294426 0.332222 +-0.0279896 0.0475815 0.0485532 0.381268 0.5 +-0.0150037 0.048073 0.0483203 0.576068 0.5 +-0.00298993 0.0473817 0.0491102 0.446744 0.431743 +0.00376754 0.0477551 0.0502037 0.495901 0.44823 +0.00748504 0.0473851 0.0493363 0.494952 0.5 +-0.0581651 0.149751 0.032858 0.470966 0.5 +-0.0720688 0.136456 0.0490662 0.625357 0.5 +-0.0810638 0.0939541 -0.0082617 0.685573 0.5 +0.0380863 0.0458646 0.0307423 0.807573 0.5 +-0.0253234 0.182998 -0.0108168 0.245054 0.5 +-0.0230508 0.183235 -0.0110157 0.246322 0.458572 +0.00323317 0.129146 0.0263855 0.347796 0.441746 +-0.0626125 0.149788 -0.00343342 0.691705 0.5 +-0.0591471 0.0466998 0.0395843 0.0883466 0.213805 +-0.0353862 0.0471292 0.0414241 0.656538 0.5 +-0.0194948 0.0486404 0.0485565 0.373069 0.5 +-0.00849455 0.0521633 0.0517688 0.61481 0.5 +-0.00296485 0.051429 0.0527827 0.53012 0.5 +0.00279019 0.0517664 0.0528352 0.560812 0.423049 +0.00904034 0.0517165 0.051222 0.558244 0.5 +0.0443839 0.0943042 0.00268377 0.582116 0.455816 +-0.0886145 0.111113 0.0148415 0.604102 0.5 +-0.0885219 0.144027 0.0329221 0.623335 0.5 +0.0440719 0.0937787 0.0206165 0.493368 0.454688 +0.0436531 0.0980341 0.0146596 0.668233 0.5 +-0.0650976 0.153799 -0.00285808 0.715743 0.5 +-0.0517297 0.0490759 0.0371355 0 0 +-0.0331222 0.0518259 0.0385377 0.676102 0.5 +-0.0377352 0.127448 0.0152358 0.612182 0.5 +-0.00906608 0.100701 0.0460122 0.338462 0.5 +-0.0410683 0.128416 0.0134054 0.417331 0.5 +-0.0712056 0.158724 -0.00521868 0.246338 0.5 +-0.0266313 0.0501544 0.044695 0.182016 0.5 +-0.0211065 0.0519946 0.0455753 0.195646 0.404388 +-0.0168667 0.0505241 0.0476889 0.520032 0.5 +-0.0147601 0.0527687 0.050103 0.451613 0.5 +-0.0626395 0.149972 -0.00897733 0.363787 0.461156 +-0.090861 0.124732 0.00627835 0.587249 0.5 +-0.0255786 0.0923499 -0.0315595 0.294527 0.5 +-0.0709738 0.172947 -0.052768 0.460427 0.5 +-0.0588974 0.143232 -0.00327646 0.48145 0.5 +-0.0943643 0.12436 0.0216467 0.570519 0.5 +0.0337044 0.112449 -0.00269877 0.532211 0.5 +-0.0515051 0.136557 0.0263185 0.72719 0.5 +-0.00886593 0.121199 0.0360577 0.614897 0.5 +-0.061729 0.155665 -0.0259512 0.690546 0.5 +-0.0862637 0.10567 0.0206042 0.519516 0.5 +-0.0895584 0.138606 0.032689 0.685876 0.5 +-0.0268168 0.123904 0.0208113 0.428255 0.5 +0.0341937 0.0515433 0.033081 0.609925 0.5 +0.0401268 0.0512743 0.0322702 0.669803 0.5 +0.0449306 0.0526595 0.0319582 0.655209 0.5 +-0.0405348 0.117168 0.0319438 0.657986 0.5 +-0.0636902 0.155546 -0.0390642 0.523327 0.5 +0.0278663 0.100401 0.0410064 0.689793 0.5 +-0.0275828 0.179275 -0.0157605 0.314049 0.5 +-0.0758871 0.0942302 0.0383961 0.647987 0.457049 +0.0138371 0.129201 0.0203961 0.412341 0.5 +-0.0152723 0.0998429 0.0451638 0.271215 0.427554 +-0.00916763 0.129718 0.0206646 0.438679 0.430152 +-0.0512444 0.0516901 0.0334801 0.192432 0.5 +-0.0461563 0.0523184 0.0379981 0.311543 0.5 +-0.0410001 0.05272 0.0393793 0.629588 0.477809 +-0.0270993 0.0526642 0.0393104 0.155274 0.5 +0.0434924 0.0931097 -0.00154028 0.576953 0.480183 +-0.0823819 0.112683 0.045427 0.438131 0.5 +-0.092066 0.118055 0.00909937 0.325678 0.5 +-0.00448884 0.121713 0.0362976 0.591545 0.5 +0.0147346 0.129423 0.0143146 0.840212 0.5 +-0.0158113 0.161888 -0.00973584 0.202865 0.5 +-0.0778838 0.149704 -0.00337488 0.403345 0.5 +-0.0865357 0.12477 -0.00166991 0.677311 0.5 +0.0153656 0.126058 0.0275381 0.479299 0.429147 +-0.0388913 0.123761 0.0249778 0.514489 0.5 +-0.0390351 0.121238 0.0283673 0.510424 0.470651 +-0.0324963 0.120237 0.0283344 0.568849 0.348087 +-0.0149052 0.12311 0.0316417 0.446842 0.5 +-0.0582873 0.117688 0.0386719 0.634635 0.5 +-0.0626536 0.161861 -0.0264031 0.685413 0.5 +-0.0818147 0.141639 0.0444825 0.392929 0.5 +0.0350734 0.100071 0.0345975 0.716199 0.5 +0.0311856 0.11215 0.0310216 0.689434 0.5 +-0.0335778 0.11743 0.031458 0.525408 0.5 +-0.059637 0.153475 0.031348 0.93076 0.5 +-0.0481256 0.0536625 0.0362191 0.58186 0.5 +-0.059026 0.156388 0.00269852 0.133166 0.5 +-0.0211187 0.0578754 0.0461125 0.660553 0.5 +-0.082738 0.124721 0.050554 0.665202 0.5 +-0.0466997 0.11363 0.0348133 0.568902 0.5 +-0.0107262 0.179662 -0.0277472 0.400699 0.458536 +0.0347725 0.0894441 -0.0170339 0.702331 0.5 +-0.0891825 0.100351 0.0148945 0.574286 0.477791 +0.0257275 0.122894 0.0207337 0.498278 0.5 +-0.0883949 0.100277 0.00841226 0.477822 0.5 +-0.0649858 0.155518 0.0263367 0.864791 0.5 +-0.0768402 0.154073 0.00257877 0.57436 0.5 +-0.0576877 0.154146 0.0262123 0.402162 0.5 +-0.0266966 0.125729 0.0145923 0.393422 0.5 +-0.076376 0.155782 0.0208875 0.505065 0.5 +-0.0763295 0.167188 -0.039594 0.405226 0.426366 +-0.0771877 0.100229 -0.0103313 0.528684 0.5 +-0.0153681 0.0590839 0.0519909 0.652683 0.5 +-0.010206 0.0576345 0.0535443 0.781548 0.413019 +-0.00350044 0.0578672 0.0543757 0.774384 0.5 +0.00300818 0.0568916 0.0538692 0.704357 0.5 +0.0088308 0.0580497 0.0529859 0.692645 0.5 +0.0410915 0.0820775 -0.00893411 0.500391 0.430286 +0.0395449 0.0576373 0.0318985 0.612032 0.4505 +-0.0762443 0.139336 0.0484763 0.588653 0.42756 +-0.0324306 0.120379 -0.00955344 0.656019 0.5 +-0.0194451 0.0881559 0.0557639 0.449983 0.473992 +-0.074787 0.159471 -0.00898201 0.281303 0.5 +-0.0639935 0.15611 0.0210031 0.687157 0.5 +-0.0762438 0.153101 0.0322442 0.323875 0.45561 +-0.00876679 0.128727 0.025102 0.735708 0.5 +0.0282216 0.112237 -0.00983067 0.567922 0.385391 +-0.0451341 0.0593225 0.0387559 0.511245 0.5 +-0.0405005 0.0579499 0.040202 0.540369 0.5 +-0.033993 0.0584028 0.038704 0.646744 0.5 +-0.0272756 0.0585468 0.0382285 0.571263 0.5 +-0.0248608 0.122913 0.0245429 0.379391 0.5 +-0.0825276 0.154355 0.0206132 0.385494 0.444119 +-0.00884271 0.129403 0.00305159 0.702319 0.5 +0.0207587 0.126654 0.0147646 0.624434 0.5 +-0.0394868 0.173351 -0.00839443 0.199648 0.251821 +-0.028421 0.114019 0.0347746 0.603313 0.5 +-0.0193575 0.122009 0.0306737 0.55532 0.5 +-0.0691626 0.161675 -0.0514614 0.38665 0.5 +-0.0516736 0.15006 0.0148119 0.716684 0.5 +-0.0156325 0.120151 0.0349054 0.470635 0.336572 +0.0467454 0.0582319 0.0314404 0.576429 0.5 +-0.0770165 0.0685425 0.0147863 0.703257 0.5 +-0.00967101 0.173225 -0.0264945 0.379771 0.5 +-0.0213141 0.184813 -0.0151112 0.186313 0.403961 +-0.0766524 0.0882188 0.0382876 0.650646 0.5 +-0.0540219 0.0521463 0.0110698 0.270787 0.5 +-0.0219451 0.126821 0.0155536 0.534695 0.5 +-0.0820391 0.153392 0.0264506 0.292051 0.4047 +-0.0213183 0.124468 -0.00290836 0.782181 0.5 +-0.0268364 0.123465 -0.00321538 0.727949 0.5 +-0.0312035 0.177796 -0.0133521 0.371348 0.5 +-0.00749945 0.0598042 0.0553302 0.778631 0.5 +-0.00108951 0.0601245 0.0554892 0.776353 0.5 +0.00280202 0.0599746 0.0555283 0.768603 0.5 +-0.051797 0.118119 0.033678 0.677092 0.438456 +0.00302464 0.131618 0.0149353 0.692956 0.5 +0.0446005 0.0942619 0.0151198 0.554026 0.5 +-0.0880636 0.111855 0.00852285 0.304511 0.3924 +-0.0704321 0.144096 -0.0148369 0.130446 0.5 +-0.0820967 0.0943634 0.0322765 0.629357 0.5 +-0.0269642 0.120812 0.0275676 0.345323 0.386314 +-0.0540164 0.149968 0.0253393 0.49489 0.5 +-0.0800337 0.0995053 -0.00770139 0.499264 0.5 +0.00922138 0.12038 0.0360924 0.562107 0.5 +0.00286056 0.117968 0.0387331 0.649494 0.5 +-0.0936229 0.118494 0.0206524 0.664933 0.5 +-0.0409923 0.113229 0.035109 0.667726 0.5 +-0.0822185 0.154488 0.0146661 0.500539 0.5 +-0.0625956 0.155202 -0.0329876 0.814083 0.5 +-0.0462511 0.124621 -0.00898124 0.590842 0.5 +-0.0220336 0.160676 -0.00426008 0.309766 0.47069 +-0.065621 0.172767 -0.0466049 0.613718 0.5 +-0.0762614 0.155884 0.0148687 0.717415 0.5 +-0.0644988 0.149044 -0.0265159 0.690046 0.5 +-0.0581979 0.0593456 0.0210895 0.079935 0 +-0.0335439 0.122618 0.0254024 0.514037 0.5 +-0.0826578 0.153434 0.00921403 0.601617 0.5 +-0.049999 0.132417 0.0286961 0.650903 0.5 +0.0088217 0.131096 0.00864908 0.834131 0.5 +-0.0154842 0.0644282 0.0533754 0.608033 0.445048 +-0.00871951 0.065015 0.0556827 0.650491 0.470895 +-0.00324815 0.0640003 0.0562816 0.762387 0.5 +0.00292601 0.0643094 0.0563956 0.748671 0.5 +0.00738462 0.0651614 0.0553402 0.488299 0.46872 +-0.0143174 0.116971 0.037836 0.441459 0.5 +-0.00299223 0.118083 0.0390751 0.65526 0.5 +-0.00864301 0.117816 0.0385662 0.681198 0.5 +-0.0532884 0.0571719 0.0206631 0.106703 0 +-0.0882588 0.100387 0.0210097 0.535268 0.5 +-0.0324377 0.099703 -0.0227313 0.620611 0.5 +0.0425072 0.0603725 0.0302275 0.744481 0.5 +0.0523383 0.0580401 0.0290457 0.405493 0.41666 +0.0413612 0.0877503 -0.00929235 0.635782 0.5 +-0.0581547 0.0620148 0.0270981 0.448705 0.5 +-0.0530328 0.0590503 0.0266933 0.136202 0.5 +-0.0477227 0.135526 0.0148654 0.740469 0.5 +0.00323512 0.0983053 0.0504424 0.395048 0.366076 +0.0150627 0.119642 0.034806 0.696033 0.374342 +-0.0453373 0.0643061 0.0391142 0.587502 0.5 +-0.0394097 0.0644278 0.0414133 0.715885 0.5 +-0.033068 0.0642666 0.0396407 0.650585 0.5 +-0.0270237 0.0644489 0.0395335 0.617817 0.5 +-0.0881604 0.149479 0.0268507 0.265855 0.5 +-0.0640727 0.143434 -0.00894036 0.668887 0.5 +0.00286033 0.121151 0.036139 0.623932 0.5 +-0.0827306 0.138152 0.0466993 0.412428 0.5 +-0.00261511 0.127006 0.030132 0.335862 0.5 +0.0355841 0.108498 -0.00452523 0.461807 0.466834 +0.0219203 0.114136 0.0356941 0.554683 0.5 +-0.0379555 0.161954 -0.0128021 0.499753 0.5 +-0.0526362 0.0643632 0.0340621 0.277414 0.5 +0.025874 0.123374 0.0143811 0.506732 0.5 +-0.0451406 0.131184 0.00901599 0.493237 0.5 +-0.075778 0.155361 -0.00310678 0.708579 0.5 +-0.0739145 0.156437 -0.0274945 0.645327 0.5 +-0.0833056 0.100778 -0.00354288 0.490806 0.397415 +-0.0767099 0.173942 -0.0452732 0.259897 0.5 +0.00846106 0.116985 0.038033 0.66824 0.5 +-0.0200899 0.184788 -0.020546 0.237973 0.106197 +-0.046571 0.120413 0.0285524 0.752764 0.5 +-0.0515313 0.123718 -0.0088569 0.538005 0.5 +0.0212116 0.105804 -0.0171101 0.576137 0.468722 +-0.0938613 0.124487 0.0151416 0.737559 0.5 +0.0414591 0.064577 0.0290352 0.617794 0.5 +0.0466725 0.0643471 0.0285539 0.486488 0.5 +0.0526423 0.0634018 0.0283831 0.501229 0.5 +-0.0468141 0.168322 -0.00285433 0.371444 0.5 +-0.0869152 0.0944156 0.00293118 0.494536 0.346642 +-0.0773713 0.161559 -0.0267238 0.476378 0.5 +-0.0396095 0.126677 -0.00334699 0.853498 0.5 +-0.0271315 0.0764239 0.0455715 0.693464 0.5 +-0.0587953 0.107012 -0.0177177 0.484023 0.5 +-0.0748314 0.11156 -0.00720996 0.44421 0.5 +-0.0642623 0.0888181 -0.018733 0.676741 0.5 +-0.0325172 0.0881157 -0.0255424 0.370176 0.330832 +0.00325654 0.0700086 0.0561047 0.731659 0.5 +0.0103151 0.0636713 0.0537558 0.477793 0.458716 +0.0432701 0.0979967 0.00267804 0.544182 0.465461 +-0.0708223 0.156244 0.021207 0.768676 0.5 +-0.0584176 0.0702277 0.0384322 0.673529 0.5 +-0.0703207 0.112305 -0.00963846 0.530989 0.5 +-0.0581653 0.0881983 -0.0208369 0.619673 0.5 +-0.0443038 0.0877156 -0.0218942 0.693083 0.5 +-0.0488091 0.0660127 0.0373959 0.829801 0.5 +0.00269411 0.126911 0.030114 0.419275 0.5 +0.0239692 0.12105 0.0288706 0.523768 0.5 +-0.0469203 0.117468 0.0314407 0.649888 0.5 +-0.091552 0.143361 0.0201623 0.515231 0.5 +-0.0907563 0.143859 0.0263089 0.504684 0.469425 +-0.0495713 0.144022 0.00976642 0.636632 0.45621 +-0.0770934 0.15583 -0.0147903 0.519503 0.5 +-0.0868322 0.105634 0.00887573 0.731519 0.5 +-0.082848 0.131648 -0.00299747 0.386393 0.5 +-0.0384249 0.106407 -0.0201393 0.79815 0.5 +-0.0823953 0.118841 -0.00336022 0.540306 0.5 +-0.0102333 0.0876697 -0.0375101 0.564234 0.5 +-0.00789361 0.089842 -0.0363492 0.755212 0.5 +-0.0579097 0.111769 -0.0161856 0.463258 0.5 +0.0140074 0.105793 -0.0193841 0.554632 0.5 +-0.00328561 0.105435 -0.0225198 0.740261 0.5 +-0.0409613 0.070972 0.0419904 0.795206 0.5 +-0.033501 0.0710512 0.0409793 0.706864 0.5 +-0.0272732 0.0701361 0.0410332 0.726443 0.5 +-0.0161963 0.127121 0.0228897 0.305628 0.5 +-0.0190644 0.127936 0.0133818 0.519435 0.5 +-0.0149926 0.0694778 0.0545159 0.595577 0.5 +-0.00932719 0.0707313 0.0562936 0.785998 0.5 +-0.002994 0.0710941 0.0575426 0.779773 0.5 +0.00838831 0.0714267 0.0556585 0.671976 0.5 +0.0102531 0.0693533 0.0547665 0.525573 0.5 +-0.0323939 0.153399 -0.00240332 0.209483 0.5 +0.0435981 0.0881514 0.0254203 0.603121 0.478265 +-0.0586529 0.124882 -0.00781093 0.700525 0.5 +-0.0204287 0.107045 -0.022046 0.723165 0.5 +-0.0382961 0.0879422 -0.0229335 0.629507 0.5 +-0.081573 0.113394 -0.00173083 0.508624 0.426711 +-0.0380811 0.154778 -0.00889149 0.748063 0.5 +-0.00212588 0.0889926 -0.0354677 0.782073 0.5 +0.00904065 0.100193 -0.0222794 0.54652 0.5 +-0.0467068 0.0700493 0.0405769 0.710023 0.5 +-0.0779974 0.151244 0.0352264 0.347296 0.5 +0.0149019 0.116126 0.0367849 0.635361 0.5 +-0.07603 0.106301 -0.0087688 0.520423 0.5 +-0.0885261 0.137839 0.0393964 0.651389 0.5 +-0.0703112 0.131278 -0.00857724 0.737784 0.5 +0.0419377 0.0703605 0.0288832 0.54196 0.5 +0.0514194 0.0684326 0.0256968 0.512602 0.5 +-0.0922548 0.124813 0.0393757 0.806636 0.5 +0.0135035 0.128105 0.0250558 0.487288 0.424656 +-0.0704618 0.125421 -0.00881334 0.801453 0.5 +-0.0703931 0.118731 -0.00840961 0.381625 0.5 +-0.0719685 0.106305 -0.0114493 0.499561 0.5 +-0.0646972 0.161498 -0.0573125 0.41682 0.5 +0.0463693 0.0715128 0.0216754 0.461473 0.448797 +-0.0538246 0.153497 0.0152346 0.602795 0.402362 +-0.0142869 0.0724666 0.0554243 0.617853 0.5 +-0.0394057 0.118512 -0.01336 0.602235 0.5 +-0.0280509 0.0880065 -0.0330858 0.33771 0.5 +-0.00957701 0.168254 -0.0212321 0.359593 0.5 +-0.0445856 0.167324 -0.00782662 0.413138 0.327414 +-0.0513101 0.161594 -0.00355965 0.292939 0.5 +-0.0702356 0.179304 -0.0569867 0.253404 0.5 +-0.0644695 0.168402 -0.0398946 0.676128 0.5 +-0.0089459 0.130139 0.00911776 0.703889 0.5 +0.00219503 0.0880369 -0.0342201 0.75972 0.5 +-0.0268891 0.16726 -0.0174204 0.847505 0.5 +-0.0525985 0.155054 -0.00368706 0.37123 0.419006 +-0.0761618 0.131736 -0.00696723 0.42394 0.44361 +-0.0759576 0.07099 0.0265672 0.757943 0.5 +-0.00875341 0.10588 -0.02285 0.71177 0.5 +-0.0519242 0.1493 -0.00277595 0.483301 0.5 +-0.016371 0.18465 -0.0214272 0.271878 0.5 +-0.020548 0.0705632 0.0520411 0.601639 0.5 +-0.0813371 0.120073 0.049533 0.662828 0.5 +-0.0625087 0.149934 -0.0150319 0.415531 0.480025 +-0.0831098 0.10651 0.0273461 0.515033 0.5 +-0.011119 0.163582 -0.018751 0.17813 0.5 +-0.00291057 0.101147 0.0456419 0.307462 0.5 +-0.0635467 0.0660523 0.0318653 0.49936 0.45677 +-0.0511979 0.0873878 -0.0217212 0.75515 0.5 +-0.0530335 0.0740367 0.0417219 0.727079 0.5 +-0.0465007 0.0756701 0.0421325 0.696934 0.5 +-0.022314 0.0760359 0.0530306 0.607912 0.5 +-0.0151351 0.0764056 0.0563566 0.616605 0.5 +-0.00900601 0.0766621 0.0575852 0.791265 0.5 +-0.00299732 0.0767339 0.0584651 0.678647 0.450838 +0.00347424 0.0769755 0.0565905 0.523043 0.5 +0.00860763 0.0767538 0.0557293 0.612782 0.5 +-0.0271239 0.156216 -0.00302734 0.139755 0.329034 +-0.0633091 0.16738 -0.0580906 0.358909 0.45373 +-0.0873943 0.144225 0.00902371 0.583528 0.5 +-0.0626891 0.162297 -0.0470925 0.70746 0.5 +0.0370111 0.110397 0.00265294 0.516602 0.481774 +-0.0744006 0.144062 -0.00864565 0.417075 0.5 +-0.0244124 0.183841 -0.0135068 0.166659 0.5 +-0.0803381 0.0715473 0.0150483 0.5669 0.5 +-0.0644528 0.0761561 0.040638 0.610448 0.476331 +-0.0588413 0.0753794 0.0421022 0.634349 0.5 +-0.0524294 0.077372 0.0433357 0.774603 0.5 +-0.0484981 0.0769334 0.043281 0.674446 0.5 +-0.0414954 0.0773856 0.0429005 0.752035 0.5 +-0.0395008 0.0754808 0.0425134 0.72256 0.5 +-0.033488 0.0764759 0.0414605 0.748994 0.5 +-0.0627838 0.162163 -0.0530538 0.691143 0.5 +0.0381456 0.0881056 -0.0138675 0.676152 0.5 +-0.0642837 0.0396418 0.039624 0.532543 0.5 +-0.0526672 0.121335 -0.010917 0.523608 0.5 +-0.0738104 0.162942 -0.037093 0.458525 0.324439 +-0.0490869 0.13938 0.00889895 0.657159 0.5 +-0.0495771 0.166027 -0.00171113 0.322064 0.5 +-0.0709736 0.161609 -0.0450808 0.365011 0.420984 +0.0251847 0.12195 0.0254854 0.524179 0.5 +-0.0193615 0.0781018 0.0558163 0.595703 0.4544 +-0.0265458 0.120645 -0.00911332 0.52669 0.5 +-0.061796 0.155741 -0.0207923 0.443336 0.5 +-0.082476 0.110295 0.0324103 0.745977 0.5 +-0.0691674 0.156314 -0.050857 0.360984 0.5 +-0.0622848 0.16236 -0.0396288 0.427869 0.464762 +-0.088248 0.113803 0.0264606 0.595923 0.5 +-0.0575392 0.0787026 0.0436363 0.801201 0.5 +-0.0298439 0.0782596 0.0421168 0.771067 0.5 +-0.0677617 0.0876701 0.0434928 0.59211 0.5 +-0.0921939 0.131884 0.015227 0.781723 0.5 +-0.0878987 0.111742 0.0209206 0.698028 0.5 +-0.049353 0.139298 0.0147955 0.761861 0.5 +-0.0327071 0.173321 -0.0149209 0.384317 0.5 +-0.0866298 0.152851 0.0149144 0.267781 0.5 +-0.0779646 0.100025 0.035185 0.697079 0.5 +-0.0935537 0.118404 0.0151524 0.667612 0.5 +-0.084908 0.10801 0.0228537 0.694681 0.5 +-0.0210677 0.0821213 0.0562096 0.557699 0.5 +-0.0149957 0.082187 0.0572635 0.665194 0.5 +-0.00899671 0.0822178 0.0576875 0.71377 0.5 +-0.00299966 0.0822055 0.0574653 0.668024 0.472979 +0.0034748 0.0817533 0.0567544 0.69456 0.5 +0.00824833 0.082992 0.0556315 0.615627 0.5 +0.0102414 0.0812949 0.0546523 0.424956 0.485927 +-0.0398496 0.123966 -0.00878898 0.60318 0.5 +-0.092257 0.124769 0.00902091 0.309094 0.468872 +-0.0436728 0.126191 0.0209533 0.472028 0.413108 +-0.0820425 0.105873 -0.00271871 0.341089 0.347157 +-0.0663016 0.0807623 0.0424437 0.632223 0.5 +-0.0639939 0.0836688 0.0439754 0.778832 0.5 +-0.058539 0.0825906 0.0439671 0.770991 0.5 +-0.0521209 0.0822523 0.0446262 0.782751 0.5 +-0.0467559 0.0828569 0.0439458 0.699516 0.399968 +-0.0424962 0.0810729 0.0423266 0.617938 0.5 +-0.0404903 0.0830123 0.0430984 0.712874 0.5 +-0.0365108 0.0825773 0.0434355 0.675696 0.5 +-0.032204 0.0824171 0.0421121 0.529763 0.5 +-0.0864005 0.152981 0.0204492 0.250247 0.416029 +-0.0235661 0.115415 0.0353667 0.518805 0.471584 +-0.0764871 0.111685 0.0461598 0.498936 0.5 +-0.0763895 0.14977 -0.00829972 0.604451 0.5 +-0.0754801 0.161855 -0.0327796 0.39691 0.5 +-0.0285733 0.0828247 0.0462702 0.636794 0.5 +-0.0862819 0.100797 0.0028483 0.65379 0.5 +0.021088 0.08242 0.0504086 0.491924 0.475524 +-0.0801892 0.143128 -0.00230055 0.641961 0.5 +0.00844098 0.124407 -0.00878569 0.555015 0.5 +0.0147552 0.0825883 0.0529115 0.480476 0.5 +-0.061995 0.161169 -0.032654 0.499509 0.5 +-0.0807571 0.1525 0.0307996 0.295115 0.454522 +-0.00295953 0.130272 0.00279699 0.742188 0.5 +-0.0153619 0.0884791 0.0565599 0.818561 0.5 +-0.00899729 0.0878977 0.0570287 0.818958 0.5 +-0.00299611 0.0880658 0.0568489 0.695384 0.5 +0.00301457 0.0885291 0.0562756 0.81087 0.5 +0.00834267 0.0873808 0.0555541 0.577038 0.479545 +-0.00897481 0.0941651 -0.0338408 0.678465 0.5 +0.0314278 0.11673 0.0250113 0.597807 0.5 +-0.0760602 0.155337 0.0093949 0.68566 0.5 +0.0257808 0.116776 -0.00728909 0.54747 0.36626 +-0.0646577 0.0882843 0.0447113 0.69894 0.5 +-0.058996 0.0882997 0.0449149 0.778337 0.5 +-0.0529958 0.0883132 0.0451395 0.696869 0.45083 +-0.0465421 0.0881579 0.0443187 0.605881 0.5 +-0.0404961 0.0876863 0.0430941 0.556958 0.5 +-0.0331792 0.0885648 0.04366 0.668172 0.5 +-0.0280482 0.0879652 0.046363 0.699915 0.5 +0.0150626 0.0881784 0.0517745 0.702815 0.5 +0.0205955 0.087113 0.0492325 0.678548 0.5 +-0.0702712 0.0823874 0.0409431 0.628092 0.5 +-0.0296926 0.0896882 -0.0286839 0.317989 0.390463 +-0.0236137 0.179242 -0.0115629 0.264741 0.5 +-0.0809391 0.100029 0.0323433 0.683272 0.5 +-0.0928336 0.130683 0.0207107 0.62518 0.472282 +-0.0761771 0.156201 -0.0204165 0.612769 0.5 +0.0146577 0.129396 0.00843576 0.595962 0.5 +0.0104845 0.089766 0.0542005 0.46622 0.5 +-0.072579 0.161253 -0.0389447 0.482103 0.5 +-0.0322741 0.110391 -0.0184574 0.809584 0.5 +-0.0550172 0.150108 0.027792 0.412797 0.5 +-0.071635 0.0883254 0.0414652 0.604622 0.463567 +-0.0424904 0.0895336 0.0426086 0.959715 0.5 +0.0207945 0.0897491 0.0484315 0.669841 0.5 +0.0273189 0.118845 -0.00265658 0.615055 0.5 +0.0285218 0.121112 0.0162366 0.593248 0.434231 +-0.00899735 0.0930598 0.0559298 0.639163 0.5 +-0.00291176 0.118727 -0.0144021 0.826286 0.5 +-0.0885191 0.113233 0.0327948 0.447552 0.461926 +-0.0713744 0.0938304 0.0415269 0.544171 0.444972 +-0.0641029 0.0935514 0.0439488 0.597795 0.395518 +-0.0584965 0.0944146 0.0446213 0.678752 0.5 +-0.0515853 0.0939836 0.0442383 0.634435 0.477778 +-0.0465591 0.0937901 0.0436103 0.714507 0.5 +-0.0414914 0.0942416 0.0425268 0.490492 0.46307 +-0.0377723 0.0933327 0.0434889 0.620752 0.5 +-0.0332864 0.0945766 0.0443868 0.723538 0.5 +-0.0263807 0.094318 0.0450568 0.620324 0.5 +-0.0141606 0.0929618 0.0553898 0.503825 0.5 +-0.00319641 0.0930898 0.0557853 0.624082 0.5 +0.00150357 0.0931879 0.0551544 0.492015 0.5 +0.00367616 0.0950752 0.0535295 0.508462 0.5 +0.00915739 0.0941794 0.0519212 0.597357 0.452723 +0.0216553 0.0937794 0.0473202 0.671835 0.5 +-0.0702968 0.174481 -0.045888 0.43732 0.455145 +-0.0305889 0.168899 -0.00702359 0.59106 0.5 +-0.0528191 0.162649 0.00296711 0.343566 0.5 +-0.0890968 0.0940104 0.0208024 0.539357 0.478012 +-0.0626249 0.173112 -0.0586131 0.353011 0.447085 +-0.0443835 0.105923 -0.0201903 0.683228 0.5 +-0.0664958 0.0951776 0.0424531 0.672396 0.5 +-0.0324384 0.126415 0.0146752 0.445893 0.463327 +-0.0152469 0.0961657 0.0518098 0.323594 0.5 +-0.0097537 0.0960506 0.0535818 0.446732 0.426556 +-0.00304601 0.0963367 0.0537791 0.579525 0.5 +0.01642 0.0957081 0.0480381 0.687032 0.5 +-0.0876548 0.105191 0.0148253 0.774556 0.5 +-0.0699417 0.0763232 0.0381496 0.596573 0.5 +0.0358078 0.0958594 -0.0120328 0.738943 0.5 +0.0374966 0.100154 0.031249 0.720944 0.5 +-0.0530195 0.150059 0.0207323 0.696139 0.5 +-0.0905911 0.131765 0.0328667 0.816274 0.5 +-0.0709717 0.147309 -0.0268389 0.224341 0.389051 +-0.0443321 0.0935075 -0.0222668 0.709831 0.5 +-0.0400911 0.128618 0.00909496 0.81345 0.5 +-0.0710054 0.100275 0.0398128 0.481571 0.5 +-0.0653063 0.100124 0.0417262 0.670525 0.470095 +-0.0589969 0.0980495 0.0430328 0.779482 0.5 +-0.0529938 0.0980631 0.0432952 0.836255 0.5 +-0.0469951 0.0980659 0.043235 0.637806 0.5 +-0.0408476 0.100401 0.0414668 0.648927 0.395789 +-0.0323344 0.0988071 0.0435216 0.652032 0.5 +-0.0259464 0.0998425 0.0438947 0.737424 0.5 +-0.0212066 0.0999849 0.0444194 0.576924 0.5 +0.00749586 0.09835 0.0488255 0.46146 0.5 +0.0090271 0.101109 0.0469975 0.470012 0.5 +0.0153076 0.100008 0.0472449 0.600016 0.5 +0.0208175 0.100067 0.0453866 0.595024 0.46889 +-0.0648326 0.131509 -0.00838673 0.790869 0.5 +-0.0740297 0.150832 -0.0323367 0.406089 0.5 +-0.0932444 0.124885 0.026841 0.802537 0.5 +-0.0633239 0.169093 -0.0610358 0.362406 0.5 +-0.0771158 0.162488 -0.0202679 0.465605 0.5 +-0.0585669 0.0647555 0.0323611 0.494963 0.328305 +0.0377689 0.110383 0.00969065 0.710008 0.5 +-0.0503559 0.0935892 -0.0218956 0.807094 0.5 +-0.0589961 0.101543 0.042437 0.529374 0.5 +-0.0516647 0.101981 0.0417488 0.647378 0.5 +-0.0469248 0.101325 0.0421166 0.608323 0.5 +-0.0352173 0.101965 0.0413638 0.751982 0.5 +0.00285015 0.100935 0.0464433 0.395489 0.5 +-0.075479 0.150312 -0.0143808 0.730394 0.5 +-0.078936 0.108126 -0.00525459 0.540251 0.381971 +-0.0251472 0.168981 -0.0187156 0.757996 0.5 +-0.071457 0.113692 0.0499983 0.429195 0.5 +-0.0747771 0.0997536 0.0377868 0.551123 0.5 +-0.0902919 0.137212 0.0146286 0.495279 0.5 +-0.0264568 0.105883 0.0411765 0.58994 0.471484 +-0.0209966 0.1044 0.0429589 0.797197 0.5 +-0.0145208 0.105597 0.0430511 0.780555 0.5 +-0.00899316 0.10622 0.0435541 0.510194 0.5 +-0.00289533 0.105882 0.0438861 0.384284 0.5 +0.00245231 0.105621 0.0429868 0.332307 0.5 +0.00945613 0.104903 0.0439002 0.435482 0.5 +0.0149913 0.104769 0.0443348 0.548532 0.5 +-0.0772186 0.106139 0.0350601 0.430274 0.367589 +-0.0708601 0.106945 0.0381598 0.402417 0.5 +-0.0652985 0.106577 0.0390805 0.558067 0.398761 +-0.0583896 0.105623 0.0405326 0.594554 0.5 +-0.0529341 0.106445 0.0398435 0.644542 0.398207 +-0.0461638 0.105797 0.0404843 0.759883 0.5 +-0.0400204 0.106789 0.0388993 0.653599 0.5 +-0.03311 0.106322 0.0394461 0.532024 0.5 +0.0193026 0.10477 0.0431964 0.486674 0.480281 +-0.0501412 0.13774 0.00286739 0.569746 0.5 +0.0266104 0.105911 0.0384052 0.650339 0.5 +0.0438719 0.088439 -0.0031027 0.506353 0.478726 +-0.0590381 0.113203 0.0362299 0.87726 0.5 +-0.021499 0.107851 0.0414162 0.584043 0.5 +-0.0164951 0.107881 0.0420289 0.633836 0.5 +0.00450524 0.107918 0.0419336 0.79888 0.5 +0.00856234 0.108229 0.0410531 0.820786 0.5 +0.0149994 0.10779 0.0412845 0.598409 0.5 +0.0213049 0.106041 0.0409433 0.561561 0.479574 +-0.0336665 0.167843 -0.00338268 0.478764 0.5 +-0.0587789 0.131705 -0.00671001 0.673026 0.5 +-0.0443517 0.100306 -0.0215281 0.825942 0.5 +-0.0147306 0.179604 -0.0266222 0.40888 0.5 +0.0159582 0.108177 -0.0177822 0.564672 0.468958 +-0.0638447 0.138119 -0.00733006 0.633194 0.5 +-0.0330953 0.167861 -0.0155539 0.527374 0.428366 +-0.0643684 0.125359 -0.00876153 0.813046 0.5 +-0.032583 0.161992 -0.0142418 0.852313 0.5 +-0.068568 0.110392 0.0392194 0.353622 0.364353 +-0.0643494 0.112195 0.0388907 0.34696 0.5 +-0.0593722 0.112082 0.0373875 0.588374 0.5 +-0.0529986 0.110472 0.0373551 0.513233 0.408461 +-0.0468613 0.11028 0.0378862 0.569336 0.5 +-0.040984 0.110496 0.0370883 0.553647 0.5 +-0.0320055 0.110468 0.0370438 0.565129 0.5 +-0.0074871 0.110717 0.042649 0.617568 0.5 +-0.00449218 0.110714 0.0426582 0.621679 0.5 +0.0250033 0.110611 0.0368459 0.631257 0.5 +0.025919 0.0995286 -0.0189206 0.684181 0.5 +-0.06973 0.112153 0.0457184 0.746569 0.5 +-0.045604 0.148834 -0.00329924 0.521986 0.5 +-0.0653006 0.0947889 -0.0177657 0.582853 0.5 +-0.0906677 0.13318 0.0277848 0.773217 0.5 +-0.0331508 0.094474 -0.0237799 0.742 0.5 +-0.0575764 0.0941613 -0.0208023 0.703326 0.5 +-0.0200586 0.0397198 0.0532237 0.447203 0.5 +-0.0203685 0.0352888 0.051184 0.291685 0.457265 +-0.0764163 0.125947 -0.00745144 0.524375 0.5 +-0.0205906 0.167551 -0.0139677 0.809186 0.5 +0.025858 0.116851 0.0315289 0.660225 0.5 +-0.0139279 0.167191 -0.021044 0.669958 0.5 +-0.0587481 0.149802 -0.00133886 0.562881 0.5 +0.0144191 0.0395247 0.0443396 0.266796 0.5 +0.0332953 0.105473 0.0329627 0.721815 0.5 +-0.0647461 0.114313 -0.0115219 0.592211 0.5 +-0.0520818 0.0353771 0.0449331 0.341981 0.5 +-0.015004 0.0392095 0.0513548 0.312679 0.5 +-0.0094925 0.0384962 0.049554 0.302651 0.5 +-0.0638496 0.117631 0.0454477 0.559641 0.5 +-0.0573025 0.136864 0.033162 0.554568 0.5 +0.0189101 0.0400942 0.0428502 0.270107 0.5 +-0.0508192 0.124393 0.0332635 0.581555 0.5 +-0.0182623 0.180885 -0.017743 0.594618 0.5 +-0.0651271 0.150343 -0.0325707 0.505808 0.5 +0.0332966 0.0936886 0.0400216 0.637373 0.5 +-0.0463011 0.149493 0.00833001 0.611316 0.5 +0.00260773 0.0354887 0.0450013 0.261253 0.345588 +-0.0780807 0.10971 0.0423535 0.916894 0.5 +-0.0542262 0.124756 0.0369858 0.64506 0.5 +-0.0402584 0.0361447 0.0436625 0.193197 0.5 +-0.00317483 0.0942874 -0.0331049 0.71511 0.325502 +-0.0151032 0.179716 -0.0207621 0.731902 0.5 +0.026141 0.0403246 0.0327265 0.294647 0.339561 +-0.0640247 0.111376 -0.0136272 0.608847 0.5 +0.027817 0.112309 0.0339118 0.692282 0.5 +-0.0586332 0.142774 0.0334953 0.761767 0.5 +-0.0146622 0.167501 -0.0154455 0.61604 0.5 +-0.0270893 0.167298 -0.00866399 0.642638 0.5 +0.0152056 0.045813 0.0442638 0.487785 0.5 +0.0190988 0.0442996 0.0429 0.362689 0.463942 +0.0215694 0.0456112 0.041209 0.479281 0.5 +0.0257452 0.0459137 0.0381185 0.444171 0.5 +0.0387365 0.0944447 0.0327088 0.718127 0.5 +0.0287308 0.0456722 0.0347466 0.335561 0.431941 +-0.0151805 0.173809 -0.0213305 0.730436 0.5 +-0.0658903 0.118253 0.0498126 0.307185 0.5 +-0.0628345 0.093206 -0.0188544 0.659442 0.5 +-0.0643065 0.142451 0.0394123 0.621016 0.5 +-0.040079 0.150283 0.00280951 0.491474 0.5 +-0.026851 0.173268 -0.00983852 0.620534 0.5 +-0.0207913 0.173767 -0.0147826 0.653794 0.5 +-0.0582334 0.124238 0.0403406 0.70004 0.5 +-0.0683337 0.131545 0.0479709 0.732904 0.5 +-0.0693547 0.10637 -0.012803 0.472443 0.5 +-0.0428668 0.157627 0.0050419 0.670804 0.5 +-0.0476449 0.130368 0.0258834 0.623828 0.5 +0.0379451 0.0817167 -0.0141547 0.644934 0.5 +0.0312298 0.0470286 0.0324465 0.426433 0.5 +-0.0662284 0.138149 0.042896 0.72515 0.5 +-0.0644094 0.105575 -0.0158634 0.566501 0.5 +0.0411271 0.0443713 0.0285474 0.466284 0.5 +-0.0830031 0.0762361 0.0150296 0.67606 0.5 +-0.0660167 0.123488 0.0501643 0.718404 0.5 +-0.0416352 0.155329 0.00636435 0.466436 0.5 +-0.0388456 0.155994 0.00477206 0.438555 0.402124 +-0.0551732 0.116538 0.0359195 0.457649 0.5 +-0.0600069 0.134082 0.0369434 0.682472 0.5 +0.0452816 0.0453284 0.0263124 0.471094 0.5 +0.0513161 0.0463154 0.0204963 0.342211 0.398387 +-0.0106687 0.172847 -0.0215627 0.69267 0.5 +-0.0147735 0.18419 -0.0259341 0.309641 0.5 +0.0301064 0.106776 0.0358091 0.72383 0.5 +-0.063709 0.125122 0.0457451 0.712215 0.420475 +0.0473431 0.0499217 0.0295077 0.554948 0.5 +0.0497106 0.0482066 0.0259506 0.48379 0.5 +0.0518484 0.0518415 0.0267161 0.416499 0.5 +-0.0162732 0.172938 -0.0174582 0.719256 0.5 +0.0355097 0.107304 0.0291151 0.718782 0.5 +-0.0552656 0.143077 0.0300537 0.622521 0.5 +-0.0637191 0.136482 0.0388176 0.603354 0.5 +-0.0199086 0.161072 -0.00863325 0.350317 0.5 +-0.0209172 0.179282 -0.0148523 0.455842 0.5 +0.014511 0.0513519 0.0474271 0.589102 0.5 +-0.0610259 0.126912 0.0416133 0.698375 0.5 +0.0539905 0.0494141 0.0219114 0.418448 0.5 +0.00925922 0.118865 -0.0148674 0.54369 0.457314 +-0.0268384 0.162091 -0.00836699 0.546076 0.486591 +-0.0367024 0.163198 -0.00107067 0.680811 0.5 +-0.0336432 0.155948 0.00188963 0.445666 0.44081 +-0.0280966 0.159587 0.000483069 0.431301 0.5 +-0.026491 0.16163 -0.00321758 0.537982 0.323001 +0.0206613 0.0528733 0.0451655 0.647628 0.324331 +0.0231576 0.0513069 0.0414753 0.507052 0.5 +0.0266044 0.0526516 0.039853 0.635463 0.446542 +0.0309772 0.0527823 0.0371348 0.671735 0.5 +0.0239371 0.103424 0.0418106 0.654526 0.5 +0.0568895 0.0527484 0.0209204 0.474964 0.5 +-0.0664209 0.11329 0.0441331 0.212624 0.5 +-0.0326789 0.162384 -0.00243762 0.543585 0.5 +0.0145199 0.0932586 -0.026363 0.546403 0.5 +-0.0543983 0.119186 0.0365781 0.502204 0.44785 +-0.0564272 0.132376 0.0357966 0.720059 0.5 +-0.0501636 0.142911 0.00230897 0.376445 0.5 +-0.043714 0.147707 0.0038501 0.245798 0.5 +-0.0291346 0.177171 -0.00534178 0.371295 0.5 +0.0357304 0.100363 -0.0111604 0.61591 0.5 +0.0133943 0.0541536 0.0499521 0.532724 0.5 +0.0551089 0.0545007 0.0253961 0.545646 0.5 +0.0291033 0.0572886 0.0407089 0.633826 0.5 +0.0585723 0.0583402 0.0214893 0.549998 0.477428 +-0.0740322 0.0656952 0.0144875 0.594594 0.5 +-0.0749844 0.179305 -0.0518221 0.216638 0.5 +0.0145778 0.0585769 0.0501691 0.387785 0.5 +0.0214876 0.058332 0.0470549 0.596242 0.5 +0.0259507 0.0590004 0.0437762 0.663038 0.5 +0.032833 0.0585633 0.0387158 0.630786 0.5 +0.0358218 0.0578374 0.0350365 0.591179 0.5 +0.0360585 0.0951301 0.0364902 0.726421 0.5 +-0.0886806 0.118283 0.0459142 0.444358 0.5 +0.0562736 0.0586365 0.0253398 0.57284 0.5 +0.0303311 0.0951295 0.0419589 0.717458 0.5 +-0.0222315 0.167389 -0.0110472 0.688671 0.5 +-0.0543257 0.136577 0.0307959 0.688078 0.5 +-0.0500074 0.150447 0.0117579 0.563476 0.5 +-0.0616289 0.137406 0.0354744 0.592141 0.5 +-0.0319367 0.159507 0.00191749 0.44862 0.5 +-0.0634458 0.132148 0.0406867 0.731705 0.5 +0.0368678 0.0921989 0.0367449 0.708135 0.5 +-0.0728433 0.156137 -0.0339112 0.713518 0.5 +0.0389872 0.0640689 0.0330299 0.521361 0.5 +-0.0636611 0.1488 -0.0205996 0.618447 0.5 +0.0153938 0.0648444 0.0513036 0.554385 0.463079 +0.0213958 0.0645506 0.0473078 0.414803 0.412252 +0.0265105 0.0649235 0.0439721 0.611901 0.5 +0.0302364 0.0650657 0.0415975 0.600683 0.487653 +0.0331295 0.0642221 0.0397381 0.500385 0.490901 +0.0367885 0.065027 0.0366867 0.593561 0.5 +0.0563131 0.0650782 0.0252208 0.639437 0.5 +0.0591364 0.0644742 0.0211357 0.550839 0.448044 +-0.0110683 0.167098 -0.0167807 0.360187 0.5 +-0.0605202 0.146205 0.0366666 0.591479 0.5 +0.0194528 0.0665736 0.0491642 0.603282 0.5 +-0.0286777 0.158132 0.000508817 0.402765 0.431383 +0.0253025 0.0989569 0.0434277 0.623394 0.5 +-0.0349979 0.152158 8.20736e-05 0.217633 0.5 +0.014665 0.070627 0.0528306 0.52613 0.5 +0.0202908 0.071041 0.0498828 0.634288 0.435356 +0.0230702 0.0702991 0.0473835 0.571849 0.5 +0.0263693 0.0706238 0.0441789 0.622852 0.474797 +0.0328306 0.0707606 0.0401362 0.612279 0.409693 +0.0368832 0.070672 0.0365953 0.662199 0.5 +0.0398878 0.0705632 0.0325808 0.656566 0.5 +0.0579544 0.0694794 0.0198345 0.6125 0.5 +-0.0641704 0.063724 0.0268682 0.425507 0.418571 +-0.0919499 0.114216 0.0149265 0.530043 0.5 +0.0351624 0.0819076 -0.0172502 0.760295 0.5 +-0.0862408 0.119271 -0.00117534 0.455279 0.5 +-0.0294401 0.174958 -0.00579982 0.562984 0.5 +-0.0175288 0.165418 -0.0114925 0.675539 0.5 +-0.0617869 0.117789 0.0409144 0.40334 0.5 +0.0301891 0.0723658 0.0418804 0.606777 0.5 +-0.0822099 0.149486 0.00288044 0.385889 0.468811 +-0.0760271 0.175704 -0.0506937 0.340571 0.5 +-0.0652343 0.0614738 0.0211346 0.414933 0.425841 +-0.0266574 0.110394 -0.019007 0.783101 0.5 +-0.0813538 0.0779161 0.0268055 0.756683 0.5 +0.021417 0.118723 -0.00893569 0.549 0.5 +0.0149346 0.0759297 0.0536191 0.48671 0.476705 +0.0209886 0.0761609 0.0506055 0.575091 0.5 +0.0268396 0.0762089 0.0459193 0.572664 0.5 +0.0336785 0.0760737 0.0405166 0.630563 0.5 +0.0373422 0.0760306 0.0366776 0.505468 0.5 +0.0400324 0.0763062 0.0328345 0.645662 0.5 +0.0419048 0.076876 0.0296092 0.673034 0.5 +0.0438094 0.0763805 0.0258638 0.624347 0.5 +-0.0452412 0.118472 -0.0142046 0.833781 0.5 +0.0456773 0.0768089 0.0208187 0.458504 0.467907 +-0.050165 0.137714 0.0207618 0.606401 0.481088 +-0.00327054 0.111563 -0.0203549 0.551699 0.482404 +-0.0483236 0.145111 0.00757835 0.59165 0.5 +0.0310833 0.0775315 0.0432282 0.624343 0.5 +-0.046855 0.145222 0.00288431 0.195425 0.432502 +-0.0141716 0.10541 -0.0225802 0.672132 0.5 +0.0470348 0.0753979 0.0148736 0.455861 0.5 +-0.0611433 0.140542 0.0356184 0.646306 0.5 +0.0272779 0.0823714 0.0459243 0.61663 0.478488 +0.0309212 0.08255 0.0430252 0.611382 0.5 +0.0343037 0.0825412 0.0402907 0.613309 0.465282 +0.0370354 0.0824663 0.0369099 0.642585 0.5 +-0.0799946 0.147989 -0.000835337 0.484293 0.5 +-0.0774435 0.0690153 0.00961977 0.704234 0.277826 +0.0404363 0.0826995 0.0326021 0.686672 0.5 +0.0417479 0.0827335 0.0302524 0.63553 0.5 +0.0436887 0.0825508 0.0263844 0.61829 0.5 +0.0454407 0.0825465 0.0207137 0.601475 0.480065 +-0.0822812 0.116295 0.0482855 0.66926 0.5 +-0.0844726 0.0947391 -0.00345192 0.592061 0.5 +-0.020271 0.168003 -0.0193935 0.821267 0.5 +-0.0742716 0.0668501 0.0190414 0.706894 0.5 +0.026747 0.0882417 0.0458314 0.539865 0.389736 +0.0308722 0.0882572 0.0430146 0.948814 0.5 +0.0344922 0.0883047 0.0403697 0.638338 0.5 +0.0372481 0.0881263 0.0366393 0.643327 0.5 +0.039927 0.088094 0.0326668 0.711283 0.5 +0.0419027 0.0877782 0.0290815 0.667656 0.5 +0.00264738 0.112302 -0.019871 0.766242 0.5 +-0.0703315 0.1455 -0.0205576 0.136819 0.239158 +-0.0749446 0.137879 -0.00653312 0.459033 0.397283 +-0.0266967 0.114299 -0.0159903 0.856895 0.5 +-0.0869924 0.113518 0.00410409 0.344807 0.5 +-0.0142186 0.174013 -0.0259807 0.439072 0.5 +-0.0221564 0.157852 -0.00861651 0.254248 0.5 +-0.011587 0.164129 -0.0163045 0.228563 0.367524 +-0.00997381 0.169338 -0.0247765 0.42189 0.5 +-0.082875 0.143405 0.00186692 0.494272 0.5 +0.0203757 0.0354405 -0.00287175 0 0 +0.0191274 0.0363337 -0.00917714 0.174536 0.5 +0.0184456 0.036388 -0.013479 0.173751 0.5 +0.0149535 0.0347732 -0.0154937 0.144529 0.253209 +0.0221204 0.0372026 0.0342324 0.156956 0.287305 +0.039271 0.0382866 0.00854708 0.245023 0.5 +0.0397549 0.0398545 0.002614 0.276002 0.5 +0.0221892 0.0380614 -0.00446361 0.173629 0.5 +0.0179901 0.0369066 -0.0161835 0.336518 0.5 +0.0154148 0.0392444 -0.0212861 0.367832 0.5 +0.0208023 0.100118 -0.0213392 0.648293 0.46589 +0.0446004 0.0409064 0.00927401 0.208963 0.5 +0.0435625 0.0411355 0.00427044 0.357471 0.452104 +0.0381381 0.0411139 -0.00147908 0.514406 0.5 +-0.0478807 0.135207 0.00885778 0.482359 0.5 +0.0217274 0.0404287 -0.00964433 0.311593 0.5 +0.0206744 0.0405956 -0.0144437 0.473825 0.5 +0.0192578 0.0411681 -0.0195074 0.414351 0.5 +-0.0885736 0.112913 0.0395856 0.488806 0.5 +-0.026793 0.106457 -0.0218501 0.617481 0.5 +0.0481487 0.0428585 0.0145594 0.265572 0.5 +0.0521212 0.0461655 0.0089655 0.199267 0.5 +0.0480438 0.0430647 0.00724585 0.412258 0.5 +0.0460936 0.0434131 0.00284357 0.566688 0.5 +0.0285003 0.100485 -0.0168103 0.728425 0.5 +0.0269462 0.0395833 -0.00334578 0.464947 0.5 +-0.0907856 0.117838 0.00647331 0.421552 0.5 +-0.062721 0.167567 -0.0470628 0.645866 0.5 +-0.0799532 0.106813 0.0316838 0.420249 0.5 +0.0527437 0.0462125 0.0139554 0.286197 0.5 +0.0504533 0.0466263 0.00264513 0.57721 0.5 +-0.0322581 0.117324 -0.0133273 0.811815 0.5 +0.0272475 0.0455966 -0.00927071 0.533119 0.5 +-0.0146455 0.0942084 -0.0337341 0.520871 0.5 +-0.0411545 0.16722 -0.010818 0.48116 0.5 +-0.0721385 0.156112 -0.0384102 0.511983 0.468875 +0.0456803 0.0474217 -0.00311192 0.412576 0.5 +0.0239407 0.0433254 -0.00969837 0.651864 0.5 +0.021084 0.0462585 -0.0205303 0.476548 0.5 +-0.0348527 0.0351549 -0.0307351 0.16856 0.5 +-0.0699867 0.0663066 0.0259153 0.590849 0.43032 +-0.0747071 0.149891 -0.0201453 0.5851 0.5 +-0.0845448 0.13725 0.000743181 0.580039 0.5 +0.0549514 0.0484178 0.0163982 0.295573 0.5 +0.0264565 0.0466261 -0.0141039 0.515417 0.5 +0.0225276 0.0444655 -0.0157683 0.505631 0.5 +0.0330538 0.0938135 -0.0160538 0.699679 0.5 +0.0526476 0.0694992 0.00297306 0.629664 0.372945 +0.0528544 0.0581339 -0.00277966 0.592036 0.5 +-0.0571464 0.0671799 0.0361705 0.503626 0.472266 +-0.0651544 0.157167 -0.0515491 0.708429 0.5 +-0.0493189 0.133682 0.00119868 0.355836 0.438333 +-0.032962 0.10595 -0.0206729 0.810434 0.5 +-0.0649538 0.155656 -0.045631 0.820472 0.5 +-0.0390456 0.150445 -0.00354536 0.204281 0.5 +0.0574365 0.051618 0.0145183 0.351624 0.5 +0.0574129 0.0522531 0.00903377 0.511629 0.5 +0.0536112 0.0500965 0.00204174 0.768402 0.5 +0.0512204 0.0520121 -0.00218354 0.534755 0.5 +0.0471226 0.0515811 -0.00481298 0.434179 0.5 +0.033443 0.047576 -0.0063817 0.557462 0.465257 +0.00280933 0.118297 -0.0158208 0.570337 0.473222 +-0.0147841 0.10125 -0.0238408 0.771507 0.5 +-0.0620037 0.167422 -0.0527165 0.538383 0.466596 +0.0559147 0.0528382 0.00339683 0.824166 0.5 +0.0334801 0.0518506 -0.00825293 0.591066 0.5 +0.0287814 0.0501171 -0.0157926 0.574224 0.5 +0.0256197 0.0485542 -0.0190548 0.421586 0.5 +-0.00863537 0.118406 -0.0146114 0.827086 0.5 +-0.0148322 0.117675 -0.014701 0.559736 0.5 +-0.0615138 0.145712 -0.00481276 0.466074 0.5 +0.0232531 0.12083 -0.00456186 0.617393 0.5 +-0.0401535 0.0342718 -0.0275149 0.0979878 0.5 +0.0302657 0.0496868 -0.0107289 0.647285 0.5 +0.0320066 0.111334 -0.00737407 0.536101 0.5 +-0.0211003 0.120417 -0.0102482 0.732965 0.5 +-0.0204991 0.117125 -0.0140803 0.767014 0.5 +-0.00910263 0.0383602 -0.025776 0.274297 0.5 +-0.0525144 0.11229 -0.0171034 0.442719 0.484227 +0.0202353 0.123713 -0.00247094 0.59012 0.5 +-0.0701749 0.0347541 -0.0017891 0.135623 0.5 +-0.00340266 0.114844 -0.0176928 0.826111 0.5 +0.0310248 0.053713 -0.0140522 0.572913 0.5 +0.0268191 0.0528482 -0.020339 0.412387 0.455219 +-0.0147458 0.120673 -0.0105853 0.653192 0.5 +0.0270905 0.106214 -0.0146756 0.603346 0.5 +0.0465541 0.0697991 0.00228503 0.590477 0.5 +-0.00300122 0.100676 -0.0235814 0.77298 0.5 +-0.0755874 0.076212 0.033468 0.651011 0.5 +0.059738 0.0572998 0.0151736 0.624329 0.5 +0.0595394 0.0578717 0.00861672 0.650231 0.5 +0.0572091 0.0580526 0.00253507 0.577167 0.5 +-0.0142907 0.123147 -0.00746744 0.689207 0.5 +0.0211831 0.112303 -0.0140834 0.636933 0.5 +0.0347455 0.0565046 -0.010714 0.517615 0.5 +0.0249138 0.0825163 -0.0245877 0.759593 0.5 +-0.0382227 0.114521 -0.016178 0.845616 0.5 +-0.0819485 0.0761672 0.0208322 0.76776 0.5 +-0.0269557 0.0392251 -0.0293943 0.537642 0.5 +0.0377037 0.0593401 -0.00852013 0.537798 0.5 +0.0330295 0.0586306 -0.014729 0.60439 0.5 +0.0218121 0.0515865 -0.0236492 0.56032 0.5 +-0.0204953 0.0935908 -0.0331675 0.485557 0.5 +-0.0872217 0.113521 0.0440666 0.448078 0.427651 +-0.0271537 0.0351608 0.0509267 0.96808 0.5 +-0.0503825 0.106302 -0.0194598 0.649024 0.5 +0.0266611 0.0585067 -0.0219134 0.622435 0.5 +0.00975018 0.0945932 -0.0280451 0.504262 0.457756 +-0.0205524 0.122391 -0.00754739 0.498583 0.5 +-0.0668021 0.0909191 -0.0174744 0.566525 0.5 +-0.0856155 0.0942099 -0.00109094 0.420789 0.436678 +-0.0915274 0.11444 0.0204492 0.759207 0.5 +-0.0909048 0.131701 0.00809159 0.558083 0.5 +0.0404851 0.0578886 -0.0051698 0.425865 0.437223 +0.0295964 0.0580473 -0.0178274 0.608291 0.460655 +0.0266986 0.0941359 -0.0205949 0.662934 0.5 +-0.0677104 0.172869 -0.0572602 0.695141 0.5 +0.0142001 0.118043 -0.013917 0.45799 0.403894 +-0.0698171 0.0699687 0.0326375 0.529959 0.5 +0.0607097 0.0648802 0.0151632 0.434757 0.451533 +0.0609346 0.0630505 0.0131585 0.526971 0.5 +0.0602205 0.0643718 0.00864139 0.443146 0.456896 +0.0574055 0.0638877 0.00271573 0.413274 0.5 +-0.0797793 0.103858 -0.00660016 0.553637 0.5 +-0.0563867 0.137359 -0.00421998 0.659682 0.5 +0.0344512 0.0638263 -0.0152012 0.581486 0.5 +0.0307139 0.0605317 -0.0184589 0.617611 0.449874 +0.0185684 0.121789 -0.00725624 0.61441 0.349043 +-0.0456617 0.112414 -0.0169658 0.70381 0.5 +0.0456177 0.0644845 -0.00162168 0.572144 0.5 +-0.0584268 0.0349015 0.0441202 0.767369 0.5 +-0.0747982 0.0723674 0.0308514 0.656357 0.5 +-0.0699373 0.0621854 0.0151778 0.587415 0.5 +-0.052889 0.136519 -0.00170821 0.593683 0.5 +0.0410205 0.0644886 -0.00476733 0.363401 0.5 +0.0388712 0.0646166 -0.00976797 0.384344 0.5 +0.0514871 0.0637279 -0.00174794 0.518067 0.5 +-0.0787297 0.0744551 0.0267421 0.809934 0.5 +-0.0850281 0.144269 0.00618082 0.578063 0.5 +0.0313094 0.064487 -0.0188936 0.672704 0.5 +0.0267274 0.0646171 -0.0220842 0.752591 0.5 +0.0318737 0.0877439 -0.0192705 0.740422 0.5 +-0.0772455 0.143995 -0.00470939 0.452269 0.5 +0.0132576 0.110443 -0.0183541 0.539267 0.5 +-0.00289343 0.124723 -0.00863032 0.516883 0.5 +-0.0342868 0.038582 0.0485461 0.546061 0.5 +0.0200397 0.0876233 -0.0261205 0.735721 0.5 +0.0585453 0.0705354 0.0146976 0.608535 0.5 +0.0581405 0.0699819 0.00856199 0.483528 0.5 +0.056099 0.069436 0.00424359 0.385578 0.5 +0.0370479 0.0665186 -0.0132637 0.645736 0.5 +-0.062561 0.172971 -0.0616721 0.43069 0.5 +-0.0702718 0.15494 -0.0455472 0.29179 0.457421 +-0.0916259 0.130499 0.00930481 0.432982 0.472725 +-0.070021 0.148229 -0.0328231 0.322588 0.195946 +-0.0721274 0.0680183 0.0267753 0.656727 0.5 +-0.0745337 0.15067 -0.0264303 0.331486 0.5 +0.0431087 0.0713461 -0.002764 0.390428 0.45538 +0.0421659 0.0692525 -0.00466106 0.55545 0.5 +0.0345404 0.0699378 -0.0160391 0.727409 0.5 +-0.0342368 0.122912 -0.00708584 0.432969 0.5 +0.0401518 0.070932 -0.00951127 0.706551 0.5 +0.0370706 0.0707408 -0.013301 0.722628 0.5 +0.0310856 0.0702175 -0.0192905 0.761897 0.5 +0.0283004 0.0705453 -0.0222447 0.701199 0.5 +-0.00859023 0.101699 -0.0237897 0.731824 0.5 +-0.0328234 0.0400139 -0.029875 0.413461 0.5 +-0.0830588 0.11047 0.0397334 0.931001 0.5 +0.0142724 0.123237 -0.00806485 0.479991 0.484444 +-0.0760443 0.108637 0.0389078 0.769887 0.5 +-0.0732762 0.154939 -0.0321392 0.640327 0.5 +0.0160324 0.0889232 -0.0282477 0.595959 0.5 +-0.0901677 0.131361 0.0394374 0.633972 0.457764 +0.0455828 0.0768365 0.00270178 0.323813 0.5 +-0.0516717 0.0553965 0.014906 0.168077 0.5 +-0.0376545 0.121002 -0.0109724 0.599451 0.451266 +0.0466318 0.0762885 0.00910629 0.334003 0.5 +0.0437303 0.0769241 -0.00295564 0.541016 0.5 +0.0405043 0.0766784 -0.0084913 0.540094 0.5 +0.0369463 0.0762836 -0.0128837 0.716695 0.5 +0.0349351 0.0766648 -0.0155944 0.687304 0.5 +0.0319237 0.0763904 -0.0194186 0.722365 0.5 +0.0285208 0.0758075 -0.0225233 0.729644 0.5 +-0.0646857 0.068809 0.0348219 0.518098 0.396839 +-0.00335573 0.0986136 -0.0269283 0.762285 0.5 +-0.0383606 0.100112 -0.0217661 0.633523 0.5 +-0.0705433 0.149897 -0.0387319 0.143598 0.5 +-0.0247871 0.179215 -0.0188356 0.466421 0.5 +0.00339058 0.0937023 -0.0318365 0.697748 0.5 +-0.09099 0.142689 0.0226645 0.743514 0.5 +-0.0851088 0.102115 0.000391121 0.420019 0.403283 +0.00299202 0.124707 -0.00864775 0.631346 0.5 +-0.0649459 0.167336 -0.0329944 0.692397 0.5 +0.045975 0.0827243 0.0146716 0.494123 0.463874 +0.0461931 0.0827376 0.00867911 0.540283 0.443947 +0.0453461 0.0826602 0.00269811 0.520808 0.5 +0.032594 0.082231 -0.0190597 0.700575 0.5 +-0.0707752 0.142011 -0.00901143 0.440829 0.5 +-0.0396694 0.045239 -0.0210351 0.371561 0.5 +-0.0736488 0.145787 -0.0131048 0.298566 0.5 +-0.0661855 0.1779 -0.0529018 0.456268 0.5 +-0.0698006 0.179227 -0.0517285 0.330383 0.5 +-0.0719677 0.177848 -0.0474604 0.498199 0.393806 +-0.0131817 0.0974247 0.0509808 0.29677 0.5 +-0.0760529 0.177651 -0.0471457 0.200482 0.341482 +-0.0875274 0.149451 0.00937476 0.260452 0.5 +-0.0847504 0.149536 0.00652369 0.220089 0.5 +-0.0853843 0.0980412 -0.000554198 0.453316 0.5 +-0.070162 0.172945 -0.0393132 0.377002 0.42015 +-0.0669053 0.17136 -0.0404187 0.587367 0.5 +-0.0915765 0.114644 0.0108349 0.335405 0.476851 +0.0311175 0.116345 -0.00142056 0.524001 0.485056 +-0.09039 0.144074 0.0142555 0.571623 0.5 +0.0533752 0.0724173 0.00805773 0.504643 0.5 +0.0348115 0.113636 0.00289967 0.517745 0.5 +0.0321047 0.117128 0.00373672 0.512637 0.481334 +-0.0558554 0.16013 0.00226313 0.176407 0.35978 +0.0284127 0.12005 0.00266093 0.800124 0.5 +-0.0693417 0.151526 -0.0443255 0.162625 0.220555 +0.0509143 0.0733396 0.0112131 0.81315 0.5 +0.0485286 0.0726358 0.00856732 0.779683 0.5 +0.0251471 0.122517 0.00254898 0.804299 0.5 +-0.0684168 0.170157 -0.0319531 0.535557 0.5 +-0.071028 0.171274 -0.0325886 0.712016 0.5 +-0.0765634 0.155757 -0.00874762 0.256295 0.5 +0.0525206 0.0734678 0.0148876 0.468908 0.45355 +0.035521 0.113454 0.00908801 0.654915 0.5 +0.0208324 0.125627 0.00327965 0.76886 0.5 +-0.0476722 0.134348 0.0194434 0.579216 0.488505 +-0.0746083 0.171229 -0.0326516 0.439107 0.422901 +0.0322027 0.117616 0.0093642 0.646061 0.5 +0.0162523 0.127588 0.00132734 0.679655 0.445027 +-0.0914669 0.142805 0.0167223 0.344959 0.5 +0.0290775 0.120474 0.00686894 0.798143 0.5 +0.0135909 0.12914 0.00336546 0.632038 0.474565 +-0.0861635 0.100458 0.025719 0.514874 0.431291 +-0.0653051 0.165945 -0.0269849 0.665887 0.5 +-0.0698492 0.16889 -0.0268648 0.536219 0.5 +-0.07827 0.167473 -0.032496 0.259817 0.452429 +0.0215557 0.0945234 -0.0226594 0.630702 0.48336 +0.0260612 0.123082 0.00873766 0.803075 0.5 +0.00920342 0.130081 0.00248247 0.641161 0.5 +-0.0709934 0.170517 -0.0295248 0.566905 0.409383 +-0.0760202 0.167938 -0.0272636 0.242234 0.5 +0.0525229 0.0716654 0.0211203 0.349876 0.431389 +0.0207167 0.126566 0.00922145 0.763786 0.5 +-0.0746025 0.0998033 -0.0126456 0.503102 0.5 +-0.0864333 0.0890874 0.0257055 0.752441 0.5 +0.0354941 0.113435 0.0150848 0.708057 0.5 +0.0320737 0.117698 0.0146262 0.694886 0.5 +0.00294754 0.130714 0.00292443 0.849802 0.5 +-0.0256391 0.0823957 0.0519489 0.764034 0.5 +-0.0666258 0.165416 -0.0221631 0.534987 0.5 +-0.0804177 0.153092 0.00488677 0.321879 0.39417 +-0.0645623 0.0350017 0.0151892 0.352362 0.5 +-0.0627936 0.0352479 0.02012 0.616295 0.5 +-0.0642932 0.0349381 0.0264604 0.161121 0.384305 +-0.0642421 0.0397497 0.0267659 0.206373 0.5 +-0.0652419 0.0352202 0.0324357 0.167045 0.5 +-0.06432 0.0352261 0.0387914 0.349097 0.5 +-0.0869014 0.0944088 0.0260869 0.722262 0.5 +-0.026376 0.100403 -0.0237519 0.527518 0.47737 +-0.0704394 0.0348288 0.00888692 0.228898 0.5 +-0.0696375 0.039673 0.0091864 0.30841 0.5 +-0.0678064 0.035728 0.013362 0.509091 0.5 +-0.0778433 0.0819732 0.0354617 0.774608 0.5 +-0.0809318 0.0827942 0.0325 0.767831 0.5 +-0.0712316 0.038974 0.00275642 0.155719 0.237906 +-0.0616101 0.0379618 0.0219344 0 0 +-0.0653778 0.0407054 0.0323415 0.379158 0.5 +-0.0612949 0.040108 0.0438783 0.388361 0.5 +-0.0748891 0.0826916 0.0381154 0.772848 0.5 +-0.0841641 0.133769 0.0486564 0.546232 0.467433 +-0.0849106 0.0945271 0.0290479 0.754258 0.5 +-0.082994 0.144712 0.0404065 0.382972 0.420138 +-0.0265479 0.117619 -0.0132781 0.755106 0.5 +-0.0679678 0.0383221 0.0123903 0.271535 0.306541 +-0.0639259 0.0401146 0.0151101 0.258252 0.450399 +-0.0588527 0.0407802 0.0202136 0.51937 0.5 +-0.0869621 0.135589 0.0440584 0.520567 0.5 +-0.038827 0.0398484 0.042564 0.570175 0.5 +-0.0253238 0.0773437 0.0501603 0.646885 0.5 +0.00864855 0.111878 -0.0192252 0.821439 0.5 +-0.0625014 0.04424 0.0388616 0.455153 0.47063 +-0.088493 0.125258 0.0461673 0.674925 0.5 +0.0150785 0.10107 -0.0220372 0.749486 0.5 +-0.0810533 0.0876325 0.0334622 0.750019 0.5 +-0.0636602 0.0439221 0.0322355 0.437404 0.5 +-0.0823757 0.12585 -0.00459555 0.376136 0.464207 +-0.0374554 0.042873 0.0429512 0.492581 0.5 +-0.031328 0.0432863 0.0501185 0.483275 0.5 +-0.0841802 0.0875016 0.0285815 0.671149 0.464325 +-0.0690099 0.0427216 0.00298087 0.372436 0.5 +-0.0690323 0.0427133 0.00739115 0.277083 0.5 +-0.0642007 0.0449178 0.00895163 0.562755 0.5 +-0.0630005 0.0427497 0.0133004 0.520064 0.348086 +-0.0580777 0.0444032 0.0143596 0.493924 0.5 +-0.087476 0.130712 0.0458544 0.531379 0.477045 +-0.0837712 0.0999337 0.029339 0.668895 0.5 +-0.083719 0.0822846 0.0270932 0.660348 0.5 +-0.0209183 0.0934772 0.0512134 0.479975 0.5 +-0.0868983 0.142651 0.0383505 0.486766 0.469754 +-0.0588984 0.0467651 0.00989959 0.460736 0.319245 +-0.0529144 0.0464475 0.0158024 0.381525 0.5 +-0.0881654 0.0882094 0.0209192 0.624947 0.5 +-0.0494075 0.165901 0.000731671 0.369742 0.391777 +-0.0586114 0.0473978 0.0337061 0.152377 0.410418 +-0.05614 0.0517476 0.00835186 0.396733 0.5 +-0.0865231 0.148073 0.0321271 0.367072 0.452379 +-0.0308497 0.0493297 0.0429654 0.330168 0.454747 +-0.0769102 0.114994 0.0501188 0.653806 0.5 +-0.0209065 0.0959579 0.0474195 0.622864 0.5 +-0.0509947 0.0509637 0.0150799 0.759028 0.5 +0.00842415 0.0889657 -0.0320537 0.627702 0.5 +-0.0240561 0.0544386 0.0416973 0.433194 0.5 +-0.0510392 0.0524223 0.0203213 0.262945 0.5 +-0.0526208 0.0518271 0.027021 0.695325 0.5 +-0.0504022 0.0591186 0.0326891 0.768296 0.5 +-0.0478821 0.0590694 0.0363134 0.800191 0.5 +-0.0239128 0.0586553 0.0421308 0.768223 0.5 +-0.0759314 0.119228 -0.00697007 0.568703 0.5 +-0.0183181 0.0604564 0.0506182 0.70539 0.5 +-0.0298441 0.0972531 -0.0235715 0.830462 0.5 +-0.0241926 0.0628773 0.0422936 0.709715 0.5 +-0.0223998 0.06467 0.045979 0.606456 0.5 +-0.0192899 0.0641483 0.0503928 0.754401 0.5 +-0.0260109 0.172925 -0.0191453 0.51739 0.5 +-0.0265331 0.161574 -0.0144318 0.84044 0.5 +-0.0558556 0.15572 -0.00121016 0.41523 0.5 +-0.0599028 0.136466 -0.0064456 0.660892 0.5 +-0.063538 0.071665 0.0379463 0.556494 0.5 +-0.0200417 0.0869862 -0.0378876 0.500126 0.449734 +-0.0557176 0.105745 -0.0186241 0.707273 0.5 +-0.0530691 0.143914 -0.00100898 0.728895 0.5 +-0.0256688 0.0704637 0.0438935 0.717372 0.393932 +-0.0235577 0.0693774 0.0470203 0.657726 0.5 +-0.0525759 0.127247 -0.00521525 0.567734 0.5 +-0.0787859 0.131858 -0.00545913 0.44224 0.460808 +-0.0580212 0.120088 -0.0102747 0.564344 0.455328 +-0.0396294 0.110441 -0.0186258 0.62346 0.5 +-0.0210282 0.173113 -0.0214922 0.42389 0.352327 +-0.0547593 0.0563289 0.0107147 0.179388 0.5 +-0.0435534 0.0345758 -0.024752 0.176398 0.205782 +-0.0449833 0.0346921 -0.0207483 0.159962 0.261208 +-0.0443576 0.0390403 -0.0217491 0.178142 0.5 +-0.0462855 0.0345037 -0.0153112 0.189574 0.5 +-0.046619 0.0396457 -0.0141457 0.194812 0.5 +-0.00904923 0.0343826 -0.0246429 0.15305 0.5 +0.00311748 0.100303 -0.0227929 0.684313 0.5 +-0.0690809 0.0392217 -0.00181724 0.169982 0.409113 +-0.0920289 0.131041 0.0262349 0.856795 0.5 +-0.043414 0.0372487 -0.0253064 0.219927 0.5 +0.0280974 0.0818294 -0.0220931 0.752623 0.5 +-0.067702 0.169446 -0.0560134 0.487347 0.455218 +-0.0915377 0.129674 0.0312365 0.601516 0.48259 +-0.0663086 0.0411162 -0.00443149 0.346306 0.5 +-0.0731255 0.151935 -0.0368879 0.40925 0.5 +-0.0390145 0.0394889 -0.027598 0.3765 0.5 +-0.0637372 0.0437827 -0.00264533 0.37233 0.5 +-0.0605427 0.0425565 0.0246975 0.23689 0.5 +-0.0857603 0.130763 -0.000714461 0.66754 0.5 +-0.0520472 0.0403573 -0.0107411 0.62257 0.5 +-0.0568522 0.0434504 0.0224413 0.404188 0.5 +-0.043239 0.0429342 -0.0193166 0.339314 0.38382 +-0.0438787 0.0441322 -0.0144222 0.427488 0.468839 +-0.0457505 0.046486 -0.0105694 0.340556 0.5 +-0.0645938 0.0456897 0.00313082 0.3549 0.5 +-0.0525978 0.0464843 0.0207116 0.3335 0.5 +-0.0572578 0.0459489 0.026887 0.439332 0.5 +-0.0618962 0.0443648 0.0286813 0.302557 0.45843 +-0.0331467 0.0453179 -0.0267282 0.481653 0.5 +-0.0377669 0.0443547 -0.0252099 0.392631 0.5 +-0.0320922 0.114425 -0.0162304 0.853943 0.5 +-0.0578027 0.0470669 -0.0032674 0.530144 0.5 +-0.0914954 0.147994 0.0205137 0.478387 0.480384 +-0.0400067 0.0471536 -0.0151042 0.224844 0.33752 +0.00454895 0.121869 -0.0124797 0.622385 0.5 +0.0151282 0.112708 -0.0165496 0.634759 0.463552 +-0.0525787 0.0463291 -0.00775444 0.598118 0.5 +-0.0599276 0.0475112 0.00267117 0.286734 0.429608 +-0.0726458 0.147126 -0.0218625 0.235551 0.5 +-0.0740924 0.168686 -0.0440312 0.451963 0.347747 +-0.057494 0.0515426 0.00319413 0.311918 0.5 +-0.0536918 0.0483048 0.0264945 0.447469 0.5 +-0.0147156 0.114453 -0.0172255 0.634887 0.5 +-0.0335191 0.0480424 -0.021246 0.299501 0.5 +0.019461 0.0924333 -0.0244344 0.636237 0.5 +0.0169402 0.0952065 -0.0238278 0.793707 0.5 +0.0201047 0.104156 -0.0188197 0.859301 0.5 +-0.0319642 0.0516657 -0.0152509 0.265727 0.5 +-0.0368448 0.0488256 -0.0131071 0.109826 0.5 +-0.0391265 0.0518909 -0.0109467 0.555432 0.5 +-0.00892221 0.111576 -0.0202733 0.785262 0.5 +-0.0515659 0.0515158 -0.00751393 0.527245 0.5 +-0.0557028 0.05294 -0.00268598 0.514955 0.5 +-0.0293421 0.0526398 -0.0213991 0.356317 0.5 +-0.0314453 0.0496351 -0.0193539 0.306544 0.5 +0.0322381 0.10409 -0.0128482 0.653044 0.5 +-0.0261025 0.0525801 -0.0264669 0.366688 0.5 +-0.0583031 0.116733 -0.0130038 0.568329 0.5 +-0.014851 0.111599 -0.0191484 0.630253 0.463696 +-0.0521348 0.118189 -0.0137451 0.464136 0.474515 +-0.0517493 0.0582798 -0.00896954 0.683087 0.5 +-0.0561982 0.0582462 -0.00310645 0.618759 0.5 +-0.0587989 0.0586119 0.00276734 0.328771 0.427166 +-0.0585564 0.0578416 0.00857596 0.293131 0.5 +0.019026 0.11614 -0.0131686 0.497701 0.5 +-0.0211893 0.111662 -0.0190883 0.650648 0.5 +-0.0239176 0.0561149 -0.030057 0.484351 0.5 +-0.0272603 0.058548 -0.027478 0.457773 0.5 +-0.0295766 0.0582799 -0.0217551 0.550969 0.5 +-0.0320928 0.0589382 -0.0147618 0.534177 0.453646 +0.0073938 0.121789 -0.0126555 0.654152 0.5 +-0.0251946 0.0595227 -0.0308632 0.509396 0.5 +-0.0307167 0.06013 -0.0194181 0.549851 0.422118 +-0.0650113 0.0632174 -0.00293095 0.168435 0.5 +-0.0696479 0.065751 -0.00198101 0.165663 0.5 +-0.0699926 0.0635013 0.00374106 0.275779 0.5 +-0.0799435 0.0724812 0.0191514 0.599916 0.5 +-0.0676844 0.160922 -0.0559942 0.35716 0.5 +-0.0215435 0.0636559 -0.0350431 0.45692 0.5 +-0.0258325 0.0648252 -0.0322087 0.452259 0.5 +-0.028982 0.0636438 -0.0274997 0.410415 0.5 +-0.0304226 0.0629368 -0.0224261 0.908229 0.5 +-0.0319042 0.0651819 -0.0201942 0.518875 0.434998 +-0.0332741 0.0636337 -0.0160032 0.40837 0.447765 +-0.0205547 0.034111 -0.026401 0.174612 0.215481 +-0.0743367 0.0658286 0.00833126 0.649876 0.5 +0.016103 0.120745 -0.0103843 0.509865 0.5 +-0.0770212 0.0700544 0.00316631 0.305775 0.384345 +-0.0748219 0.06693 0.00451345 0.433069 0.463791 +-0.0306317 0.0657524 -0.025453 0.517895 0.5 +-0.0711433 0.0687078 -0.00390291 0.256016 0.135401 +-0.0762625 0.0716316 -0.00295918 0.293636 0.296358 +-0.0802204 0.0713935 0.00991267 0.507181 0.5 +-0.0913413 0.148143 0.0161458 0.474933 0.5 +-0.0273736 0.0700052 -0.0335323 0.445714 0.5 +-0.0300274 0.0692073 -0.0289677 0.511122 0.5 +-0.0316277 0.0711218 -0.0266514 0.502235 0.5 +-0.0330629 0.0699765 -0.0212743 0.929225 0.5 +-0.0353642 0.0705896 -0.0177097 0.263666 0.5 +-0.0587004 0.0391044 -0.0090027 0.295521 0.5 +-0.0697696 0.0703857 -0.00808666 0.238472 0.5 +-0.0804832 0.0726462 0.00472466 0.630221 0.5 +0.0151616 0.126104 -0.00266395 0.542796 0.5 +-0.0745721 0.072883 -0.00757069 0.303203 0.5 +-0.0823908 0.076277 0.00270117 0.615888 0.5 +-0.0912831 0.133698 0.0142161 0.68945 0.5 +0.00371049 0.0968817 -0.0280931 0.670854 0.5 +-0.0761392 0.0766258 -0.00859487 0.260107 0.5 +-0.0784749 0.0748827 -0.00523624 0.238143 0.440892 +-0.0806781 0.0771902 -0.00290803 0.36458 0.43512 +-0.0834622 0.0765209 0.00927112 0.562933 0.5 +0.00983826 0.11402 -0.0178612 0.519736 0.475688 +0.00210649 0.0981565 -0.0261244 0.689185 0.5 +-0.0285085 0.0757575 -0.0348118 0.64535 0.304239 +-0.0330874 0.0761249 -0.0270661 0.564742 0.5 +-0.0346568 0.0757906 -0.0215029 0.930953 0.5 +0.0231104 0.0892807 -0.0240236 0.697809 0.45449 +-0.0312132 0.0771357 -0.0320416 0.687582 0.5 +-0.0700425 0.0763633 -0.0141464 0.485274 0.5 +-0.0861137 0.0814707 0.00908143 0.590509 0.5 +-0.086319 0.08152 0.0149936 0.698173 0.5 +-0.0208042 0.0963182 -0.0270563 0.75553 0.5 +-0.0211078 0.114391 -0.0171285 0.793027 0.5 +-0.0746162 0.0828529 -0.0139325 0.683447 0.5 +-0.077295 0.081216 -0.0100568 0.47673 0.5 +-0.0800127 0.0821605 -0.00722237 0.637376 0.5 +-0.0826334 0.0820868 -0.00324616 0.569954 0.5 +-0.0844667 0.0817669 0.00249573 0.601403 0.5 +-0.0860445 0.0832591 0.0203255 0.630527 0.5 +-0.084816 0.0816746 0.0219849 0.638209 0.5 +0.0545549 0.0661692 0.000765649 0.628404 0.43579 +-0.0331604 0.0828369 -0.0270493 0.417784 0.5 +-0.0358028 0.0829047 -0.0227723 0.112354 0 +-0.0861942 0.0842505 0.00298565 0.418742 0.5 +-0.0287072 0.0827267 -0.0349537 0.48086 0.471486 +-0.0311601 0.0822387 -0.0315627 0.627475 0.5 +-0.085403 0.141865 0.00516647 0.463398 0.5 +-0.0785169 0.0885628 -0.0107607 0.69884 0.5 +-0.0807046 0.0887676 -0.00826584 0.689404 0.5 +-0.0843972 0.0878743 -0.00349923 0.402052 0.5 +-0.0855708 0.0882073 -0.00109946 0.425364 0.422235 +-0.0876157 0.0881286 0.00369184 0.414972 0.435161 +-0.0885339 0.0876942 0.00897158 0.630733 0.5 +-0.0885791 0.0877213 0.0149616 0.665472 0.5 +-0.0643854 0.0348576 -0.00775085 0.279509 0.5 +-0.0512932 0.034227 -0.0129013 0.159841 0.5 +-0.0266839 0.0458556 -0.027274 0.610127 0.5 +-0.0146368 0.0981541 -0.0264318 0.44201 0.5 +-0.0213468 0.10077 -0.0239588 0.58675 0.5 +0.020932 0.0825954 -0.0267347 0.750174 0.5 +0.00759225 0.0928541 -0.0309237 0.580726 0.5 +-0.0144478 0.0879274 -0.0380297 0.689122 0.5 +-0.00859724 0.11451 -0.0173132 0.77831 0.5 +0.0264818 0.109935 -0.0126182 0.652634 0.5 +-0.0145855 0.0385179 -0.0267991 0.230538 0.5 +-0.0330054 0.0337044 -0.0272991 0.262513 0.5 +-0.0267872 0.0340475 -0.0271901 0.244173 0 +-0.00849157 0.0985859 -0.0270535 0.53889 0.411612 +-0.0110954 0.120824 -0.0120135 0.770076 0.5 +0.0367379 0.0925992 -0.0129888 0.684003 0.5 +-0.0571635 0.0435755 -0.00717607 0.581004 0.404197 +-0.0193328 0.0979251 -0.024792 0.661276 0.5 +-0.0203798 0.0385467 -0.0283088 0.392689 0.5 +-0.0587681 0.0337133 -0.00871891 0.1361 0.5 +-0.0517919 0.100655 -0.0213258 0.798237 0.5 +0.00702627 0.0978418 -0.0246055 0.732067 0.326346 +-0.0148892 0.126068 -0.00252126 0.467449 0.5 +0.0307578 0.092446 -0.0188519 0.704525 0.5 +0.0211049 0.0578126 -0.0266116 0.685576 0.5 +-0.0169237 0.0970481 -0.0278718 0.775366 0.5 +0.0460004 0.0581866 -0.00508589 0.612698 0.5 +-0.00944331 0.0822271 -0.0381067 0.670336 0.467319 +-0.0635881 0.0392124 -0.00717766 0.572252 0.5 +0.00864227 0.0386371 -0.0233053 0.540697 0.5 +0.0252935 0.0769557 -0.0248407 0.75695 0.5 +-0.0229653 0.0895159 -0.036199 0.454072 0.467569 +-0.0523791 0.0341193 -0.00994653 0.132813 0.5 +0.0211693 0.0643935 -0.0268578 0.690366 0.5 +-0.0515867 0.13164 -0.0028092 0.545448 0.5 +-0.0149669 0.0345529 -0.0254273 0.17846 0.5 +-0.0161167 0.127288 0.00169291 0.694465 0.5 +-0.0469232 0.128515 -0.00163965 0.389857 0.5 +-0.00961381 0.127158 -0.00378809 0.714685 0.5 +-0.0074566 0.128562 -0.00130751 0.72817 0.5 +-0.00304493 0.128909 -0.00174857 0.778769 0.5 +0.0028379 0.129022 -0.00194723 0.574275 0.5 +0.00903363 0.128674 -0.00165013 0.617309 0.5 +-0.0561607 0.131588 -0.00571429 0.687735 0.5 +-0.0457551 0.127167 -0.00484962 0.645893 0.5 +-0.00304746 0.127678 -0.00456004 0.562309 0.5 +0.00303811 0.12768 -0.00442 0.624596 0.5 +0.0101526 0.126812 -0.00466464 0.64326 0.5 +-0.0553259 0.126836 -0.00601308 0.517644 0.5 +0.00799473 0.034846 -0.0206913 0.278473 0.5 +0.0027179 0.0342191 -0.0204737 0.322372 0.5 +-0.00295804 0.0342418 -0.0216222 0.194059 0.5 +0.0134674 0.0353221 -0.0196961 0.466171 0.5 +0.00440963 0.0383063 -0.0240776 0.3469 0.5 +0.00140752 0.0383474 -0.0246147 0.361099 0.5 +-0.00309177 0.0383877 -0.0251866 0.314174 0.5 +-0.0575023 0.100661 -0.0195211 0.459895 0.452391 +-0.0485739 0.15316 -0.00547278 0.691758 0.5 +-0.0646573 0.0334831 -0.00296009 0.187639 0.5 +-0.0640796 0.100426 -0.0173936 0.44544 0.466101 +-0.0704415 0.100139 -0.0146037 0.499781 0.478548 +-0.0326376 0.155806 -0.00949884 0.828995 0.5 +0.0336094 0.0373624 0.00273412 0.290019 0.5 +0.0320943 0.0397885 -0.00195136 0.323719 0.5 +0.0158502 0.0449602 -0.0237212 0.910511 0.5 +0.00889467 0.0426449 -0.0242659 0.891863 0.5 +0.00312499 0.0452721 -0.026588 0.665265 0.460024 +-0.00298345 0.044686 -0.0272222 0.905955 0.5 +-0.00912346 0.0448524 -0.0280671 0.895801 0.5 +-0.0145351 0.0443266 -0.0277771 0.887903 0.5 +-0.0209223 0.0460913 -0.0281918 0.705844 0.5 +0.034052 0.0448434 -0.00540113 0.626363 0.5 +-0.0312646 0.158257 -0.01223 0.732334 0.5 +0.0401509 0.0448981 -0.00354586 0.446696 0.5 +0.0143253 0.0473484 -0.0251513 0.546545 0.456757 +0.00937888 0.0466526 -0.0261685 0.907397 0.5 +-0.0766531 0.0695423 0.0207982 0.774152 0.5 +0.0087246 0.0517916 -0.0291615 0.840924 0.5 +0.00299372 0.0506927 -0.0298557 0.901259 0.5 +-0.00164566 0.0489436 -0.0304144 0.872257 0.5 +-0.00321397 0.0522596 -0.0314075 0.634884 0.475184 +-0.00915341 0.0509217 -0.0318681 0.650022 0.5 +-0.0146018 0.0513752 -0.0319045 0.891033 0.5 +-0.0161558 0.0488543 -0.0303763 0.808351 0.5 +-0.0205843 0.0508011 -0.0296435 0.813106 0.5 +0.0405252 0.0518855 -0.00654453 0.65569 0.5 +0.0149309 0.0520772 -0.0273859 0.655547 0.5 +0.041884 0.0490868 -0.00604367 0.898378 0.5 +0.019962 0.0529908 -0.0261219 0.592286 0.5 +-0.0198501 0.0534234 -0.0312267 0.768335 0.5 +-0.0336273 0.0527187 -0.0106243 0.102172 0.5 +-0.0461112 0.0529158 -0.0101664 0.636429 0.372142 +-0.0204 0.161875 -0.014658 0.822907 0.5 +0.0449924 0.0530898 -0.00614891 0.575737 0.5 +0.00733679 0.0546532 -0.0305038 0.688621 0.5 +0.00283568 0.0546532 -0.0307468 0.611749 0.5 +-0.00302245 0.0577 -0.0331477 0.67582 0.5 +-0.00914668 0.0576676 -0.0341165 0.698389 0.5 +-0.01517 0.058199 -0.0349877 0.856637 0.5 +-0.0202707 0.0581031 -0.0333681 0.552506 0.5 +0.0140844 0.057965 -0.028983 0.564173 0.483714 +0.0103301 0.0588553 -0.0299472 0.602031 0.489059 +0.00732823 0.0588898 -0.0306117 0.710141 0.5 +0.0027369 0.0590151 -0.0321928 0.690932 0.5 +-0.0337187 0.0579742 -0.0115824 0.143826 0.5 +-0.0390711 0.0582467 -0.0115033 0.780735 0.5 +-0.0460474 0.0579124 -0.0115174 0.472305 0.5 +-0.00961439 0.0642168 -0.0358564 0.670518 0.457134 +-0.044157 0.0599825 -0.0123877 0.830365 0.5 +0.015251 0.0645803 -0.029567 0.626368 0.396114 +0.00839294 0.0649214 -0.0316957 0.79033 0.385997 +0.00325858 0.0643529 -0.0332439 0.728322 0.418376 +-0.00361257 0.0645861 -0.034907 0.670644 0.5 +-0.0144709 0.065006 -0.0371603 0.712311 0.5 +-0.0366623 0.060679 -0.0122791 0.525705 0.5 +-0.0526404 0.0636402 -0.0101297 0.452904 0.5 +-0.0381866 0.0648919 -0.0142073 0.543504 0.5 +-0.0452495 0.0647856 -0.0139819 0.883769 0.5 +-0.0599262 0.0622966 -0.00429285 0.195385 0.344922 +-0.0778641 0.117463 -0.00576778 0.523105 0.5 +-0.0187447 0.0664151 -0.0374779 0.820087 0.5 +-0.0577616 0.0644884 -0.00779097 0.472929 0.5 +-0.0625778 0.0655353 -0.00741131 0.379588 0.453283 +0.0251088 0.0710945 -0.0248604 0.704567 0.5 +0.021457 0.0702729 -0.0273415 0.740248 0.5 +0.0166747 0.0701586 -0.0297203 0.658948 0.5 +0.0132745 0.0702643 -0.0312074 0.651019 0.5 +0.00867525 0.0703509 -0.0324278 0.818076 0.5 +0.00229643 0.0708694 -0.0343123 0.73028 0.5 +-0.0030646 0.070381 -0.0353565 0.764349 0.5 +-0.00773679 0.0691749 -0.0362051 0.757441 0.5 +-0.0101988 0.0715122 -0.0373778 0.76291 0.5 +-0.0147454 0.0704429 -0.0382943 0.581028 0.470136 +-0.0203984 0.0706516 -0.038158 0.645161 0.5 +-0.0240967 0.0693418 -0.0362521 0.4533 0.5 +-0.0605175 0.0673597 -0.0108259 0.635082 0.5 +-0.0387293 0.0706355 -0.0168457 0.666323 0.5 +-0.0451347 0.0705064 -0.0164504 0.875899 0.5 +-0.0523435 0.0697862 -0.0145984 0.401473 0.5 +-0.0591515 0.0702891 -0.0147203 0.639534 0.5 +-0.0652515 0.0688492 -0.00993982 0.422384 0.422462 +-0.0247614 0.0719777 -0.0368317 0.497524 0.5 +-0.0637884 0.0712697 -0.0138535 0.437166 0.5 +0.0211454 0.0769268 -0.0268772 0.737516 0.5 +0.0162128 0.0765268 -0.0293784 0.712202 0.5 +0.0133247 0.0760196 -0.0306715 0.679361 0.5 +0.00907695 0.076038 -0.0330382 0.719764 0.5 +0.00245085 0.0760857 -0.0351615 0.721395 0.5 +-0.00176321 0.0762288 -0.0360688 0.799862 0.5 +-0.00476487 0.076286 -0.0369742 0.814155 0.377247 +-0.00962992 0.0765936 -0.0378651 0.627364 0.487104 +-0.0144481 0.0764118 -0.0385775 0.832444 0.5 +-0.021453 0.0763574 -0.038668 0.751656 0.5 +-0.024977 0.0762484 -0.0374518 0.39297 0.457854 +-0.0377453 0.0766164 -0.0189124 0.273711 0.5 +-0.0397395 0.0746623 -0.0180255 0.973337 0.5 +-0.0437423 0.0765905 -0.0187922 0.595439 0.440211 +-0.0466377 0.0744845 -0.0173668 0.538698 0.468502 +-0.0518623 0.0745812 -0.0175084 0.855826 0.5 +-0.0589866 0.0745368 -0.01766 0.879682 0.5 +-0.0644081 0.0756279 -0.0167529 0.562234 0.481782 +-0.0721295 0.0740256 -0.0105719 0.341576 0.432723 +-0.0615233 0.0354132 0.043881 0.499903 0.5 +-0.0524971 0.0769872 -0.0189536 0.873913 0.5 +-0.0587482 0.0767445 -0.0187462 0.882838 0.5 +0.013102 0.0809953 -0.0307917 0.69611 0.5 +0.00892296 0.0820652 -0.0325478 0.700162 0.5 +0.0022917 0.0820297 -0.0349279 0.829579 0.5 +-0.00177837 0.0804805 -0.0364471 0.647084 0.379833 +-0.00379684 0.0824193 -0.037328 0.824332 0.5 +-0.0142988 0.0820384 -0.0390211 0.832022 0.373406 +-0.0207708 0.0823862 -0.0387335 0.805306 0.5 +-0.0248089 0.0818968 -0.0377031 0.470046 0.439483 +-0.0735819 0.0777026 -0.0122023 0.445372 0.5 +0.015425 0.0831288 -0.0295207 0.735694 0.5 +-0.0383994 0.0817919 -0.0209596 0.290803 0.5 +-0.0451184 0.0815526 -0.020434 0.548777 0.45056 +-0.051814 0.0818472 -0.0211348 0.886135 0.5 +-0.0583689 0.0812724 -0.0202975 0.847354 0.5 +-0.063949 0.082768 -0.0188935 0.606874 0.5 +-0.0662709 0.080065 -0.0177832 0.593549 0.449354 +-0.0695594 0.0830593 -0.0170582 0.4495 0.5 +-0.00481814 0.086841 -0.0367951 0.827149 0.5 +-0.0248206 0.0867524 -0.0367639 0.487957 0.5 +0.0132046 0.0871602 -0.0305473 0.663835 0.5 +-0.0360837 0.0867076 -0.023791 0.366486 0.5 +-0.00877843 0.0340556 -0.0204927 0 0 +-0.0207128 0.0342382 -0.0208728 0.319674 0.5 +-0.0147915 0.0341096 -0.0207616 0.312592 0.5 +-0.0265767 0.0342963 -0.0210989 0.482378 0.5 +0.00282685 0.0351053 -0.0158136 0.508357 0.5 +0.00885967 0.034471 -0.0147487 0.490133 0.5 +-0.0390848 0.0337228 -0.0202617 0.628543 0.5 +-0.0326656 0.0345334 -0.0201874 0.788348 0.5 +-0.00224535 0.0351539 -0.0166234 0.756398 0.5 +-0.0149096 0.0357313 -0.0180956 0.933106 0.5 +-0.0114808 0.0353662 -0.0177045 0.933613 0.5 +-0.00921575 0.0380183 -0.0149732 0.909294 0.5 +-0.00282494 0.0382292 -0.0140636 0.920543 0.5 +0.00285919 0.0377324 -0.0134715 0.965028 0.5 +0.0159109 0.0347098 -0.00882204 0.420938 0.5 +-0.0306839 0.036693 -0.0184598 0.875112 0.5 +-0.0265216 0.0367471 -0.0188177 0.84266 0.5 +-0.0218341 0.0369718 -0.0184303 0.873319 0.5 +-0.0203027 0.0382765 -0.0152577 0.887215 0.5 +-0.0152596 0.0382328 -0.0156428 0.873575 0.5 +0.00738356 0.0366172 -0.0125003 0.962688 0.5 +0.00992361 0.0351979 -0.00924624 0.9642 0.5 +0.00702596 0.0378387 -0.00879015 0.927286 0.5 +-0.0396958 0.0342843 -0.014578 0.76643 0.5 +-0.0329517 0.0382154 -0.014678 0.654319 0.5 +-0.0263862 0.0385778 -0.0153644 0.924592 0.5 +0.00320835 0.0389424 -0.00953857 0.945732 0.5 +-0.0364387 0.0357946 -0.0155844 0.543249 0.5 +-0.00301526 0.0391061 -0.00886496 0.816802 0.5 +0.00831664 0.0348156 -0.00321961 0.671683 0.5 +0.0145039 0.0343685 -0.0028433 0.748562 0.5 +-0.0365752 0.0370276 -0.0136534 0.498247 0.5 +-0.0146234 0.0388055 -0.00887465 0.759701 0.5 +-0.00886749 0.0389394 -0.00890173 0.761944 0.5 +-0.0451032 0.0336721 -0.00848668 0.772585 0.5 +-0.040313 0.0350801 -0.00861758 0.462745 0.5 +-0.0206235 0.0386 -0.00878063 0.747754 0.5 +0.00267879 0.038424 -0.00319748 0.448355 0.5 +0.015044 0.0350517 0.00289039 0.579133 0.5 +0.0201479 0.0347806 0.00348327 0.403273 0.5 +0.027119 0.0353514 0.00366834 0.0909279 0.5 +0.0280785 0.0365531 0.000826759 0 0 +-0.0376066 0.0375692 -0.00942418 0.22755 0.5 +-0.0332748 0.0384549 -0.00855692 0.752109 0.5 +-0.0264541 0.0384497 -0.00886193 0.729343 0.5 +-0.00299262 0.0389582 -0.00292437 0.746846 0.5 +0.00451408 0.0356078 -0.00103635 0.413486 0.5 +0.00881079 0.0350428 0.00356828 0.588251 0.5 +0.0314184 0.0360255 0.00457907 0.187967 0.5 +-0.00888202 0.0387884 -0.00299409 0.73859 0.5 +0.00271787 0.0349091 0.00339755 0.645421 0.5 +-0.041199 0.0341471 -0.00327644 0 0 +-0.0205479 0.0384259 -0.00283766 0.741413 0.5 +-0.0146618 0.0385908 -0.00288739 0.718901 0.5 +0.00103528 0.0375917 0.000952222 0.441385 0.5 +0.0215747 0.0354906 0.0086194 0.395945 0.5 +0.0264794 0.0346514 0.00870654 0.414057 0.5 +0.0322391 0.0355412 0.00882378 0.515667 0.5 +-0.0521057 0.0334794 -0.00318207 0.614129 0.5 +-0.0455078 0.0336572 -0.00225818 0.757211 0.5 +-0.0334104 0.0383259 -0.00292317 0.611245 0.5 +-0.0265122 0.0383343 -0.00296504 0.763748 0.5 +-0.00224847 0.0383354 0.00320971 0.728422 0.5 +-0.0589386 0.0334143 -0.00291301 0.444064 0.5 +-0.00874044 0.0385976 0.00291227 0.735039 0.5 +0.00273457 0.0342734 0.0088248 0.796819 0.5 +0.00621941 0.0351341 0.00654928 0 0 +-0.080018 0.109279 0.0373655 0.503151 0.426569 +-0.0393178 0.0336443 0.00354096 0.266658 0.5 +-0.0213111 0.0382973 0.00334866 0.753895 0.5 +-0.0146196 0.0384265 0.00290922 0.762157 0.5 +-0.00353554 0.0379644 0.00874752 0.658939 0.5 +0.0276681 0.0349662 0.0149532 0.360666 0.5 +0.03282 0.0359255 0.0147037 0.719837 0.5 +0.0389763 0.0383079 0.0145025 0.635106 0.5 +-0.0523961 0.0335249 0.00326874 0.742717 0.5 +-0.0462346 0.0335696 0.00267776 0.743661 0.5 +-0.0277984 0.0382296 0.00286126 0.456211 0.5 +-0.000947006 0.0357374 0.0103469 0.779853 0.5 +0.0222276 0.0358262 0.0160256 0.180494 0.5 +0.0448051 0.0411192 0.0150961 0.294679 0.5 +-0.0581064 0.033504 0.00272997 0.775526 0.5 +-0.0352323 0.0337248 0.00491425 0.152905 0 +-0.0312985 0.0381858 0.00167702 0 0 +-0.0088641 0.03847 0.00876261 0.73345 0.5 +0.0028919 0.0342894 0.0147059 0.676527 0.5 +-0.0703332 0.0340583 0.00286723 0.639535 0.5 +-0.0648245 0.0334924 0.00301734 0.793089 0.5 +-0.0387963 0.034763 0.00935652 0.458758 0.5 +-0.0332327 0.0337932 0.00943608 0.151116 0.5 +-0.0203456 0.0382265 0.00836296 0.759992 0.5 +-0.0152156 0.0383161 0.00935801 0.755179 0.5 +-0.000385714 0.0351459 0.0134171 0.848157 0.5 +0.00663645 0.0342324 0.0159688 0 0 +0.0268074 0.0356469 0.0204126 0.619176 0.5 +0.0309391 0.0362152 0.0189937 0.762661 0.5 +0.0334119 0.0376179 0.0210082 0.70177 0.5 +-0.0515734 0.0338904 0.00817232 0.493124 0.5 +-0.0454999 0.0352808 0.00804865 0.53914 0.5 +-0.0263229 0.0380313 0.00871732 0.143858 0.5 +-0.0031858 0.0377098 0.014513 0.797449 0.5 +0.0211051 0.0351552 0.0207004 0.432057 0.5 +0.0391983 0.0395969 0.0205879 0.670001 0.5 +0.0441778 0.0418755 0.0204802 0.609797 0.5 +-0.0580282 0.0335624 0.00918162 0.776077 0.5 +-0.00922404 0.0383488 0.0150261 0.754001 0.5 +0.00313746 0.0352426 0.0204176 0.692001 0.5 +0.00877508 0.0346179 0.020856 0.290121 0.5 +0.0468489 0.0434226 0.0210936 0.239557 0.5 +-0.0648031 0.0337402 0.00884817 0.802283 0.5 +-0.0338156 0.0345063 0.0150293 0.572312 0.5 +-0.0149173 0.0382498 0.0147214 0.753708 0.5 +0.0146344 0.0345628 0.0222588 0.157065 0.5 +-0.0365655 0.0357926 0.0130139 0.391807 0.5 +-0.0262153 0.0376693 0.0148666 0.146481 0.5 +-0.0205165 0.0381248 0.0146779 0.715632 0.5 +-0.00229335 0.0382456 0.020565 0.923102 0.5 +0.014723 0.0347707 0.0263935 0.310145 0.5 +0.0210245 0.0353476 0.0265418 0.313898 0.5 +0.0250756 0.0364517 0.0246847 0.678097 0.5 +0.0273584 0.0381522 0.0267127 0.778478 0.5 +0.0321164 0.0401984 0.026762 0.778536 0.5 +-0.053829 0.0335431 0.0139547 0.458851 0.5 +0.00114114 0.037661 0.0223414 0.978558 0.5 +0.00915473 0.0353589 0.0262457 0.701449 0.5 +0.0380552 0.0412819 0.02589 0.374179 0.417844 +-0.0588034 0.0336951 0.0146283 0.798139 0.5 +-0.0339319 0.0346253 0.0202274 0.513983 0.5 +-0.0152545 0.0382629 0.0204704 0.75125 0.5 +-0.00888844 0.0384087 0.0207206 0.746481 0.5 +0.00307272 0.0384964 0.0264151 0.996029 0.5 +-0.0261643 0.0378491 0.0205422 0.603577 0.5 +-0.0205429 0.0381473 0.0213758 0.772551 0.5 +-0.0538188 0.0335608 0.0210581 0 0 +-0.00301594 0.03875 0.0263901 0.805634 0.5 +0.00756209 0.0380712 0.0285007 0.978659 0.5 +0.0143741 0.0348327 0.0331833 0.915728 0.5 +0.0198279 0.03555 0.0321213 0.749506 0.5 +0.0236875 0.0373106 0.0299772 0.517201 0.5 +-0.0588476 0.033906 0.020465 0.657735 0.5 +-0.00882687 0.0386047 0.0265705 0.756827 0.5 +0.00847025 0.0383344 0.0315598 0.739987 0.5 +0.0108958 0.035647 0.0330663 0.649316 0.5 +-0.0366651 0.0353042 0.023032 0.153172 0.5 +-0.0340084 0.0344659 0.0266224 0.263742 0.5 +-0.0270447 0.0379104 0.0270529 0.074682 0.5 +-0.0210471 0.0383013 0.026282 0.782021 0.5 +-0.0147317 0.0384888 0.0265233 0.791552 0.5 +-0.0712786 0.0733348 0.0355839 0.683322 0.427231 +-0.0388887 0.0346255 0.0265538 0.109729 0 +0.00290004 0.0393205 0.032168 0.626516 0.5 +0.0155389 0.0350901 0.0393977 0.759188 0.5 +0.0195159 0.0358111 0.0367948 0.405286 0.5 +-0.0589139 0.0341314 0.0264586 0.808252 0.5 +-0.052234 0.0340737 0.0268887 0.497915 0.5 +-0.0447866 0.0339274 0.0274346 0.154159 0.5 +-0.0310127 0.0369382 0.02848 0.240675 0.5 +-0.00908756 0.0390146 0.0330901 0.79352 0.5 +-0.00293287 0.039209 0.03365 0.804769 0.5 +0.00861952 0.0346654 0.0391536 0.125418 0.5 +-0.0149144 0.0388312 0.0324344 0.795183 0.5 +0.00392423 0.0347398 0.0399064 0.146347 0.5 +-0.0657827 0.0618455 0.00187562 0.442355 0.5 +-0.0640051 0.0606097 0.00361345 0.333039 0.5 +-0.0455164 0.0345095 0.0326748 0.510388 0.5 +-0.0385699 0.0344168 0.033204 0.485482 0.5 +-0.0342024 0.0351611 0.0325685 0.248514 0.5 +-0.0270303 0.0384799 0.0326469 0.783767 0.5 +-0.0209433 0.0387397 0.0332273 0.806699 0.5 +-0.0520994 0.0344582 0.0326775 0.466807 0.5 +-0.0313489 0.0377268 0.0321213 0.178238 0.5 +-0.00219023 0.0348305 0.0410082 0.139343 0 +0.00818206 0.0355366 0.0443043 0.642932 0.5 +0.014947 0.0361331 0.0431407 0.796588 0.5 +-0.0642564 0.0597236 0.0092932 0.716255 0.5 +-0.0584732 0.0343588 0.0331559 0.775713 0.5 +-0.0145859 0.0393004 0.0380317 0.483641 0.5 +-0.00937548 0.0394517 0.037871 0.328321 0.5 +-0.0588297 0.0579582 0.0145443 0 0 +-0.038732 0.0346956 0.0400227 0.628019 0.5 +-0.0331487 0.034492 0.0390527 0.154826 0.5 +-0.0201914 0.0391628 0.0381696 0.483919 0.5 +-0.00878985 0.0348233 0.0452949 0.139305 0.5 +-0.0031441 0.0351515 0.045825 0.295611 0.5 +-0.0701619 0.0622789 0.00863964 0.42197 0.408074 +-0.0451191 0.034688 0.0396457 0.766116 0.5 +-0.0256628 0.0389081 0.0373249 0 0 +-0.0146115 0.0348173 0.0458198 0.143796 0.5 +-0.0636462 0.0593677 0.014889 0.807508 0.5 +-0.0531671 0.0345191 0.0391729 0.74918 0.5 +-0.0595372 0.034497 0.0397515 0.783724 0.5 +-0.0329555 0.0349777 0.045552 0.474674 0.5 +-0.0262436 0.034809 0.0452831 0.162616 0.5 +-0.0215554 0.0348112 0.0459347 0.152356 0 +-0.0633407 0.0601272 0.0190813 0.939061 0.5 +-0.0471 0.0351015 0.0434178 0.627709 0.5 +-0.0120723 0.0353434 0.0494553 0.877126 0.5 +-0.016313 0.0351836 0.0504037 0.67915 0.5 +-0.0483699 0.146034 -0.00115148 0.583019 0.5 +-0.0264335 0.156562 -0.00835956 0.469485 0.437523 +-0.065003 0.144791 -0.0142909 0.400803 0.470167 +-0.066228 0.151547 -0.0394609 0.538048 0.5 +-0.0663323 0.145309 -0.018858 0.764025 0.5 +-0.0412403 0.152108 -0.00674014 0.633348 0.5 +3 4 132 80 +3 80 132 544 +3 373 80 544 +3 387 299 241 +3 859 1475 1474 +3 371 299 401 +3 401 326 333 +3 347 673 402 +3 1187 1354 386 +3 1221 457 69 +3 186 224 114 +3 1250 1256 116 +3 164 333 376 +3 19 488 1245 +3 749 19 1245 +3 667 19 749 +3 1040 412 543 +3 1359 1358 1500 +3 216 4 80 +3 152 544 146 +3 4 387 505 +3 543 1235 1205 +3 610 604 297 +3 250 801 1274 +3 504 148 111 +3 387 348 299 +3 401 333 164 +3 1484 1483 1110 +3 91 196 310 +3 90 91 310 +3 952 406 609 +3 1244 1247 1240 +3 93 327 65 +3 373 544 152 +3 373 152 644 +3 1321 158 22 +3 401 416 326 +3 644 152 1263 +3 276 59 181 +3 294 853 150 +3 308 249 529 +3 406 1124 604 +3 609 406 463 +3 146 3 145 +3 90 310 3 +3 58 186 10 +3 575 261 384 +3 25 40 43 +3 379 535 713 +3 348 704 157 +3 388 443 22 +3 396 146 145 +3 152 133 1263 +3 1830 1829 1812 +3 214 114 224 +3 157 147 324 +3 1335 430 1274 +3 282 230 214 +3 92 346 652 +3 1151 1012 1491 +3 571 1151 1491 +3 571 1491 183 +3 310 196 111 +3 91 4 505 +3 1250 116 108 +3 110 183 47 +3 1209 854 953 +3 132 4 91 +3 111 148 327 +3 93 111 327 +3 110 571 183 +3 713 171 402 +3 294 920 200 +3 81 180 52 +3 525 731 784 +3 347 256 673 +3 175 57 220 +3 338 175 220 +3 27 14 220 +3 57 27 220 +3 359 446 27 +3 359 36 446 +3 145 28 262 +3 133 16 419 +3 1447 576 1465 +3 1885 287 444 +3 133 396 16 +3 598 543 1205 +3 447 93 65 +3 73 213 36 +3 1236 1255 1250 +3 1235 1236 1250 +3 115 782 731 +3 28 93 447 +3 525 548 115 +3 299 416 401 +3 667 603 463 +3 292 667 463 +3 492 70 637 +3 133 146 396 +3 1166 1125 619 +3 1151 1219 959 +3 821 304 409 +3 1486 1487 1684 +3 15 175 167 +3 120 15 167 +3 15 131 57 +3 175 15 57 +3 57 131 27 +3 257 209 359 +3 27 257 359 +3 209 55 36 +3 359 209 36 +3 55 87 73 +3 36 55 73 +3 101 108 735 +3 108 101 64 +3 310 365 3 +3 576 859 1465 +3 262 28 447 +3 102 64 101 +3 544 91 90 +3 262 447 485 +3 485 447 211 +3 1443 1440 1442 +3 697 457 1221 +3 1008 383 1011 +3 451 435 1330 +3 129 405 426 +3 70 75 161 +3 648 693 692 +3 204 129 426 +3 812 481 123 +3 406 292 463 +3 878 1591 1009 +3 478 128 50 +3 900 979 977 +3 490 900 977 +3 241 299 371 +3 1164 701 734 +3 683 703 682 +3 719 718 682 +3 703 719 682 +3 760 759 718 +3 719 760 718 +3 137 729 728 +3 54 130 2 +3 302 358 301 +3 566 567 614 +3 1069 1103 1068 +3 1186 1190 1208 +3 4 348 387 +3 277 311 228 +3 707 226 706 +3 355 394 393 +3 773 129 755 +3 646 647 679 +3 356 355 269 +3 270 356 269 +3 424 394 356 +3 623 654 602 +3 654 683 602 +3 193 217 192 +3 1677 1676 1662 +3 1018 1019 1025 +3 597 1231 1165 +3 490 26 605 +3 299 157 416 +3 504 241 148 +3 84 528 714 +3 1247 669 1240 +3 683 719 703 +3 1886 1231 1066 +3 79 168 218 +3 211 318 426 +3 165 377 148 +3 91 505 387 +3 577 623 622 +3 692 693 707 +3 255 254 218 +3 194 270 255 +3 695 137 728 +3 1475 1498 1474 +3 67 808 1010 +3 1190 240 1208 +3 242 259 300 +3 476 509 567 +3 743 755 558 +3 1025 1024 1018 +3 194 255 218 +3 270 269 254 +3 203 271 12 +3 603 667 749 +3 1379 1395 1392 +3 783 546 1340 +3 578 600 577 +3 624 623 577 +3 600 624 577 +3 655 654 623 +3 684 683 654 +3 655 684 654 +3 720 719 683 +3 684 720 683 +3 720 739 719 +3 761 760 719 +3 739 761 719 +3 218 254 253 +3 694 695 437 +3 255 270 254 +3 1202 488 19 +3 412 1222 543 +3 60 528 84 +3 1352 494 702 +3 624 655 623 +3 1361 221 143 +3 755 129 204 +3 132 91 544 +3 543 1221 1235 +3 216 5 4 +3 1221 1236 1235 +3 754 755 204 +3 1169 732 715 +3 756 755 743 +3 1036 1035 1024 +3 728 756 743 +3 476 567 508 +3 4 5 348 +3 244 1339 546 +3 405 445 211 +3 254 269 268 +3 253 254 268 +3 381 358 302 +3 346 92 59 +3 517 450 1560 +3 1618 1333 141 +3 1498 1497 1474 +3 1231 597 1165 +3 228 264 215 +3 100 151 99 +3 151 215 99 +3 151 228 215 +3 1864 827 1870 +3 561 578 480 +3 207 561 480 +3 579 600 578 +3 561 579 578 +3 600 625 624 +3 656 655 624 +3 625 656 624 +3 685 684 655 +3 656 685 655 +3 685 721 720 +3 684 685 720 +3 721 740 739 +3 720 721 739 +3 739 740 761 +3 762 789 788 +3 761 762 788 +3 789 239 770 +3 788 789 770 +3 328 770 239 +3 423 424 476 +3 121 195 522 +3 423 476 422 +3 381 431 358 +3 148 371 401 +3 579 625 600 +3 465 464 431 +3 381 465 431 +3 464 465 227 +3 248 11 71 +3 548 142 1005 +3 740 762 761 +3 767 900 490 +3 728 743 437 +3 776 195 121 +3 1177 1176 1153 +3 1043 1034 1035 +3 137 708 729 +3 91 387 196 +3 1721 1729 1703 +3 728 729 756 +3 727 728 437 +3 196 387 241 +3 404 458 522 +3 355 354 268 +3 647 648 692 +3 979 846 901 +3 241 371 148 +3 142 1155 574 +3 269 355 268 +3 358 301 300 +3 301 358 300 +3 753 754 793 +3 184 229 228 +3 229 277 228 +3 312 311 277 +3 1845 1853 1831 +3 1523 1532 1153 +3 580 579 561 +3 1276 1280 1771 +3 580 626 625 +3 579 580 625 +3 626 657 656 +3 625 626 656 +3 656 657 685 +3 722 721 685 +3 741 740 721 +3 722 741 721 +3 740 763 762 +3 790 789 762 +3 763 790 762 +3 790 339 239 +3 789 790 239 +3 377 165 327 +3 476 508 422 +3 259 301 300 +3 162 170 169 +3 81 162 169 +3 580 561 562 +3 657 686 685 +3 229 312 277 +3 28 365 93 +3 1263 419 1254 +3 396 145 144 +3 685 686 722 +3 741 763 740 +3 133 152 146 +3 1263 133 419 +3 207 520 562 +3 520 562 580 +3 562 520 580 +3 562 626 580 +3 239 339 487 +3 597 1063 1066 +3 3 365 28 +3 649 648 615 +3 108 64 116 +3 571 1225 1218 +3 184 185 229 +3 313 312 229 +3 185 313 229 +3 439 501 520 +3 501 581 562 +3 520 501 562 +3 627 626 562 +3 581 627 562 +3 627 628 626 +3 658 657 626 +3 628 658 626 +3 658 675 657 +3 687 686 657 +3 675 687 657 +3 723 722 686 +3 687 723 686 +3 722 723 741 +3 741 723 763 +3 764 791 790 +3 763 764 790 +3 791 407 339 +3 790 791 339 +3 407 303 339 +3 303 487 339 +3 303 460 487 +3 303 325 460 +3 170 106 105 +3 105 106 68 +3 439 440 501 +3 723 764 763 +3 1 1027 453 +3 1067 511 942 +3 775 121 774 +3 1281 1270 1291 +3 368 440 439 +3 367 368 439 +3 582 581 501 +3 628 627 581 +3 658 688 687 +3 675 658 687 +3 1733 1562 1561 +3 757 775 756 +3 74 68 46 +3 398 1223 317 +3 631 607 231 +3 1465 859 1474 +3 1775 1784 1754 +3 204 138 793 +3 74 122 97 +3 584 533 570 +3 278 313 185 +3 265 278 185 +3 369 368 313 +3 278 369 313 +3 369 440 368 +3 502 501 440 +3 583 582 501 +3 502 583 501 +3 583 581 582 +3 629 628 581 +3 583 629 581 +3 629 659 658 +3 628 629 658 +3 658 659 688 +3 724 723 687 +3 688 724 687 +3 724 742 723 +3 742 765 764 +3 723 742 764 +3 764 238 791 +3 791 238 407 +3 407 238 303 +3 238 333 303 +3 333 325 303 +3 614 615 647 +3 46 122 74 +3 606 199 112 +3 441 440 369 +3 83 173 573 +3 775 776 121 +3 846 979 901 +3 441 502 440 +3 659 689 688 +3 84 714 1367 +3 535 52 171 +3 551 798 1883 +3 630 629 583 +3 629 630 659 +3 689 724 688 +3 792 238 764 +3 765 792 764 +3 1207 1208 177 +3 195 96 522 +3 122 13 97 +3 344 492 637 +3 1025 1036 1024 +3 775 774 756 +3 1012 1151 959 +3 1270 1372 1291 +3 145 3 28 +3 649 670 695 +3 517 1888 243 +3 444 399 1885 +3 370 369 278 +3 724 765 742 +3 376 333 238 +3 1372 1375 1291 +3 1060 1161 1162 +3 16 396 144 +3 369 442 441 +3 583 601 630 +3 690 689 659 +3 318 295 427 +3 138 204 427 +3 693 694 707 +3 310 111 365 +3 365 111 93 +3 636 660 659 +3 567 566 508 +3 426 405 211 +3 121 126 774 +3 471 601 583 +3 251 237 188 +3 1303 188 237 +3 278 314 370 +3 370 442 369 +3 442 503 502 +3 441 442 502 +3 503 471 583 +3 502 503 583 +3 858 302 259 +3 16 144 319 +3 660 690 659 +3 690 725 724 +3 689 690 724 +3 750 765 724 +3 725 750 724 +3 8 792 765 +3 750 8 765 +3 376 238 792 +3 8 376 792 +3 164 376 238 +3 376 164 238 +3 1381 1380 1375 +3 1135 1134 1103 +3 1104 1135 1103 +3 794 204 793 +3 447 65 211 +3 442 1347 503 +3 249 262 485 +3 1036 1043 1035 +3 522 96 438 +3 204 426 427 +3 188 283 251 +3 1235 1250 1205 +3 485 262 23 +3 597 1066 1165 +3 144 308 319 +3 1027 767 589 +3 648 649 694 +3 567 615 614 +3 821 409 304 +3 63 711 903 +3 8 164 376 +3 12 478 50 +3 171 347 402 +3 284 1327 314 +3 1447 1465 1459 +3 1456 1447 1459 +3 1329 1328 1380 +3 755 756 773 +3 756 774 773 +3 193 218 253 +3 648 694 693 +3 168 194 218 +3 190 188 189 +3 284 283 188 +3 190 284 188 +3 283 284 314 +3 262 485 23 +3 108 116 64 +3 751 750 725 +3 726 751 725 +3 751 771 750 +3 37 8 750 +3 771 37 750 +3 632 164 8 +3 569 53 411 +3 511 1560 1884 +3 386 1354 1320 +3 165 632 8 +3 37 165 8 +3 165 164 632 +3 662 661 638 +3 354 393 422 +3 401 165 148 +3 979 1883 798 +3 144 145 262 +3 413 408 349 +3 16 319 669 +3 318 211 295 +3 156 1213 198 +3 1153 1152 1119 +3 1225 1448 247 +3 190 266 284 +3 419 669 1247 +3 479 233 232 +3 166 165 37 +3 709 492 344 +3 567 568 615 +3 107 827 1864 +3 695 727 437 +3 485 211 23 +3 1254 419 1247 +3 419 16 669 +3 1884 1591 1009 +3 249 485 24 +3 41 249 24 +3 1103 1134 1133 +3 272 398 492 +3 754 204 794 +3 1498 159 113 +3 24 485 23 +3 1102 1103 1133 +3 308 144 249 +3 164 165 401 +3 692 707 706 +3 509 568 567 +3 191 252 190 +3 190 252 266 +3 252 285 284 +3 266 252 284 +3 285 286 284 +3 284 286 337 +3 144 262 249 +3 536 564 563 +3 563 564 593 +3 564 612 611 +3 593 564 611 +3 645 361 611 +3 612 645 611 +3 645 691 1313 +3 309 752 751 +3 726 309 751 +3 752 772 771 +3 751 752 771 +3 119 37 771 +3 772 119 771 +3 425 166 37 +3 119 425 37 +3 380 165 166 +3 425 380 166 +3 128 83 17 +3 50 128 17 +3 729 757 756 +3 394 423 422 +3 589 767 490 +3 424 509 476 +3 1374 1359 1531 +3 408 372 349 +3 679 692 706 +3 855 242 300 +3 766 757 730 +3 354 355 393 +3 79 218 193 +3 129 126 405 +3 126 458 405 +3 647 692 679 +3 757 766 775 +3 766 776 775 +3 1699 1014 1013 +3 393 394 422 +3 252 286 285 +3 752 119 772 +3 425 327 380 +3 696 730 729 +3 708 696 729 +3 649 695 694 +3 78 79 193 +3 1497 1498 113 +3 901 979 798 +3 404 24 445 +3 24 23 445 +3 776 795 195 +3 1340 1591 1884 +3 1035 1034 1024 +3 177 203 12 +3 380 327 425 +3 510 509 424 +3 477 510 424 +3 458 404 405 +3 192 217 252 +3 191 192 252 +3 217 267 286 +3 252 217 286 +3 286 267 352 +3 353 421 420 +3 352 353 420 +3 421 507 506 +3 506 507 536 +3 507 565 564 +3 536 507 564 +3 565 613 612 +3 564 565 612 +3 646 645 612 +3 613 646 612 +3 646 679 691 +3 645 646 691 +3 706 705 691 +3 679 706 691 +3 753 309 280 +3 138 119 752 +3 753 138 752 +3 427 425 119 +3 138 427 119 +3 295 380 425 +3 427 295 425 +3 65 327 380 +3 295 65 380 +3 769 104 315 +3 426 318 427 +3 568 616 615 +3 695 728 727 +3 404 445 405 +3 1635 1653 1453 +3 271 478 12 +3 839 136 830 +3 615 648 647 +3 311 277 228 +3 749 1245 1225 +3 353 392 421 +3 793 138 753 +3 315 104 33 +3 432 466 465 +3 381 432 465 +3 465 466 527 +3 1170 1190 1099 +3 754 794 793 +3 558 754 280 +3 193 253 217 +3 253 268 267 +3 217 253 267 +3 268 354 353 +3 267 268 353 +3 354 392 353 +3 422 421 392 +3 354 422 392 +3 422 508 507 +3 421 422 507 +3 508 566 565 +3 507 508 565 +3 614 613 565 +3 566 614 565 +3 614 647 646 +3 613 614 646 +3 168 810 194 +3 886 940 923 +3 946 945 930 +3 929 939 944 +3 940 569 887 +3 661 649 616 +3 320 919 878 +3 227 526 464 +3 882 873 866 +3 552 384 820 +3 464 927 358 +3 917 432 905 +3 879 829 820 +3 194 836 880 +3 935 466 432 +3 917 935 432 +3 1038 1725 1013 +3 1378 1391 1406 +3 173 448 293 +3 477 943 510 +3 616 568 617 +3 1405 550 980 +3 665 86 847 +3 891 906 912 +3 845 130 54 +3 999 925 822 +3 1885 928 555 +3 904 910 270 +3 315 33 478 +3 1033 1034 1042 +3 490 921 26 +3 850 257 131 +3 1070 1077 1034 +3 843 860 15 +3 120 843 15 +3 850 209 257 +3 914 913 300 +3 880 911 910 +3 641 661 616 +3 843 120 797 +3 860 870 15 +3 870 131 15 +3 870 850 131 +3 894 873 882 +3 811 248 875 +3 974 981 992 +3 850 201 131 +3 131 201 850 +3 850 201 209 +3 907 917 905 +3 694 437 226 +3 895 843 797 +3 870 860 843 +3 816 870 843 +3 870 201 850 +3 913 933 932 +3 968 969 986 +3 840 118 712 +3 816 843 895 +3 201 856 209 +3 856 845 55 +3 209 856 55 +3 931 930 911 +3 228 151 184 +3 1340 884 1884 +3 553 506 536 +3 539 867 842 +3 870 924 201 +3 977 823 490 +3 868 829 780 +3 999 1000 925 +3 198 701 156 +3 787 816 895 +3 924 877 856 +3 201 924 856 +3 877 845 856 +3 66 305 941 +3 769 203 1208 +3 848 847 919 +3 880 889 911 +3 1027 589 605 +3 957 816 787 +3 849 870 816 +3 957 849 816 +3 414 821 409 +3 1887 1004 928 +3 569 888 887 +3 459 384 552 +3 891 889 890 +3 839 892 891 +3 1080 1057 1051 +3 957 328 816 +3 328 957 816 +3 849 881 870 +3 881 849 870 +3 870 849 924 +3 481 531 123 +3 777 835 698 +3 891 892 906 +3 912 911 889 +3 891 912 889 +3 546 1339 746 +3 328 849 957 +3 849 88 924 +3 1043 1070 1034 +3 777 122 46 +3 477 929 943 +3 617 641 616 +3 822 915 72 +3 915 331 72 +3 834 806 956 +3 788 957 787 +3 770 788 787 +3 788 328 957 +3 864 877 924 +3 833 938 130 +3 845 833 130 +3 938 256 130 +3 1005 142 574 +3 661 676 137 +3 730 305 776 +3 1186 1208 1207 +3 1189 1186 1207 +3 798 1888 1067 +3 864 924 88 +3 864 922 877 +3 982 845 877 +3 922 982 877 +3 982 833 845 +3 894 905 873 +3 879 665 86 +3 879 665 847 +3 817 922 864 +3 833 982 922 +3 817 833 922 +3 894 907 905 +3 1562 1561 1038 +3 305 893 776 +3 899 864 88 +3 1071 1049 1072 +3 788 770 328 +3 776 768 795 +3 835 919 847 +3 817 864 899 +3 833 256 938 +3 1177 1195 1176 +3 1276 1771 1275 +3 155 100 813 +3 832 96 449 +3 879 384 665 +3 879 86 665 +3 834 956 320 +3 863 898 328 +3 826 849 328 +3 898 826 328 +3 849 826 88 +3 826 899 88 +3 1346 1883 900 +3 930 945 944 +3 939 930 944 +3 810 818 836 +3 838 836 837 +3 1077 1069 1034 +3 891 890 838 +3 1473 1680 1679 +3 44 24 438 +3 899 200 817 +3 1374 1391 1378 +3 466 935 527 +3 66 941 730 +3 913 906 912 +3 956 919 320 +3 662 676 661 +3 239 395 863 +3 395 898 863 +3 819 826 898 +3 826 200 899 +3 35 86 82 +3 880 270 194 +3 935 950 527 +3 670 661 695 +3 134 256 94 +3 818 837 836 +3 848 879 847 +3 395 819 898 +3 826 819 200 +3 200 920 817 +3 920 876 833 +3 817 920 833 +3 833 876 256 +3 1034 1069 1068 +3 932 933 947 +3 997 676 662 +3 836 889 880 +3 757 729 730 +3 956 806 919 +3 603 749 1460 +3 876 48 256 +3 827 107 155 +3 107 184 155 +3 830 855 841 +3 1042 1034 1068 +3 832 449 795 +3 997 662 638 +3 384 261 665 +3 997 696 676 +3 294 48 876 +3 920 294 876 +3 925 915 822 +3 1199 1231 1886 +3 941 305 730 +3 200 418 294 +3 569 940 886 +3 100 155 184 +3 840 712 331 +3 921 379 26 +3 1016 1014 1699 +3 776 766 730 +3 983 997 638 +3 676 696 137 +3 487 395 239 +3 487 819 395 +3 569 886 511 +3 940 887 923 +3 986 1000 985 +3 1125 110 47 +3 947 968 958 +3 842 874 834 +3 822 918 66 +3 985 999 998 +3 984 985 998 +3 999 822 998 +3 983 984 997 +3 984 998 997 +3 819 418 200 +3 177 85 1206 +3 12 275 397 +3 1231 1165 1066 +3 240 769 1208 +3 1000 999 985 +3 943 965 568 +3 906 913 932 +3 300 913 892 +3 997 998 66 +3 998 822 66 +3 478 33 128 +3 570 701 1076 +3 305 72 768 +3 72 811 768 +3 878 884 411 +3 878 835 884 +3 930 939 929 +3 968 978 967 +3 958 968 967 +3 946 958 967 +3 819 853 418 +3 510 943 509 +3 509 943 568 +3 151 100 184 +3 978 984 983 +3 967 978 983 +3 474 1122 799 +3 932 931 912 +3 487 460 819 +3 460 29 819 +3 819 29 853 +3 340 867 383 +3 1134 1135 1161 +3 947 946 931 +3 1411 1501 1408 +3 300 892 855 +3 356 910 929 +3 136 838 837 +3 1259 351 523 +3 887 896 923 +3 260 86 665 +3 774 129 773 +3 872 873 871 +3 906 932 912 +3 661 137 695 +3 511 886 942 +3 985 984 978 +3 968 985 978 +3 818 136 837 +3 1559 851 857 +3 872 871 865 +3 1222 1221 543 +3 548 1005 115 +3 430 1198 1065 +3 768 811 832 +3 945 967 944 +3 1132 1134 1160 +3 1019 1036 1025 +3 1134 1161 1160 +3 615 616 649 +3 1560 884 1884 +3 884 835 888 +3 214 230 114 +3 811 332 832 +3 878 411 53 +3 848 842 879 +3 842 829 879 +3 48 673 256 +3 869 811 768 +3 912 931 911 +3 935 936 950 +3 871 302 381 +3 972 991 971 +3 708 137 696 +3 1225 571 110 +3 847 955 13 +3 803 190 189 +3 865 871 858 +3 986 985 968 +3 929 944 943 +3 227 972 526 +3 888 835 896 +3 1001 1002 840 +3 1830 1841 1829 +3 50 140 275 +3 394 424 423 +3 411 884 888 +3 936 935 917 +3 907 936 917 +3 835 847 698 +3 811 6 332 +3 842 867 829 +3 1161 1060 1226 +3 1885 399 1887 +3 808 834 995 +3 1659 1658 1638 +3 65 295 211 +3 918 822 305 +3 302 871 381 +3 847 86 955 +3 1001 840 925 +3 1010 937 834 +3 1208 203 177 +3 1135 1162 1161 +3 921 81 379 +3 271 315 478 +3 948 969 947 +3 464 526 927 +3 834 848 806 +3 409 296 414 +3 302 873 432 +3 885 896 777 +3 841 892 839 +3 811 875 6 +3 1077 1104 1069 +3 1104 1103 1069 +3 68 106 46 +3 823 921 490 +3 162 81 921 +3 823 162 921 +3 989 1001 1000 +3 986 989 1000 +3 1000 1001 925 +3 888 896 887 +3 929 477 356 +3 974 972 534 +3 87 2 213 +3 915 840 331 +3 970 969 948 +3 965 641 568 +3 1207 177 1206 +3 1726 1725 1038 +3 1002 51 840 +3 814 191 803 +3 191 190 803 +3 855 892 841 +3 302 432 381 +3 173 293 573 +3 880 904 270 +3 871 873 302 +3 358 914 300 +3 239 863 328 +3 910 911 929 +3 331 712 811 +3 438 24 404 +3 892 913 906 +3 991 1002 990 +3 128 33 83 +3 810 836 194 +3 788 770 787 +3 814 803 804 +3 774 126 129 +3 242 855 830 +3 981 1189 1206 +3 927 934 914 +3 847 13 777 +3 301 358 300 +3 822 72 305 +3 641 617 568 +3 839 838 136 +3 904 880 910 +3 1850 1864 1870 +3 118 248 811 +3 949 970 948 +3 970 989 986 +3 1328 1325 1316 +3 358 927 914 +3 867 340 829 +3 943 944 966 +3 1100 221 1361 +3 530 805 525 +3 327 148 377 +3 1259 179 351 +3 1029 1028 1014 +3 969 968 947 +3 970 986 969 +3 832 795 768 +3 888 569 411 +3 342 344 113 +3 458 126 121 +3 943 966 965 +3 979 901 823 +3 823 861 162 +3 701 198 1076 +3 966 638 641 +3 769 315 271 +3 760 761 787 +3 965 966 641 +3 927 949 934 +3 949 948 934 +3 558 755 754 +3 919 835 878 +3 270 910 356 +3 852 162 861 +3 106 170 162 +3 852 106 162 +3 947 958 946 +3 815 192 191 +3 814 815 191 +3 820 384 879 +3 305 768 893 +3 698 847 777 +3 829 340 780 +3 534 972 227 +3 121 522 458 +3 1071 1077 1070 +3 846 823 901 +3 846 861 823 +3 918 305 66 +3 893 768 776 +3 1190 1186 1099 +3 67 1010 937 +3 925 840 915 +3 862 861 846 +3 862 852 861 +3 835 777 896 +3 946 945 944 +3 862 106 852 +3 1885 1887 928 +3 464 358 431 +3 526 949 927 +3 946 944 945 +3 890 889 838 +3 66 696 997 +3 1019 1561 1026 +3 1375 1380 1291 +3 1071 1061 1077 +3 712 118 811 +3 806 848 919 +3 971 990 970 +3 661 670 649 +3 971 970 949 +3 749 1225 110 +3 122 777 13 +3 35 13 955 +3 734 701 1164 +3 795 449 195 +3 874 842 848 +3 990 1002 989 +3 977 979 823 +3 526 971 949 +3 78 193 192 +3 815 78 192 +3 990 989 970 +3 834 539 842 +3 839 891 838 +3 1146 767 1064 +3 1002 1001 989 +3 840 51 118 +3 886 862 846 +3 280 754 753 +3 811 869 768 +3 906 913 912 +3 967 966 944 +3 931 946 930 +3 829 552 820 +3 886 106 862 +3 885 46 106 +3 1061 1104 1077 +3 320 67 834 +3 905 432 873 +3 874 848 834 +3 911 930 929 +3 1026 1572 1019 +3 972 974 992 +3 934 933 913 +3 914 934 913 +3 923 106 886 +3 777 46 885 +3 355 356 394 +3 449 96 195 +3 66 730 696 +3 807 96 832 +3 72 331 811 +3 896 106 923 +3 896 885 106 +3 1071 1070 1043 +3 932 947 931 +3 1049 1071 1043 +3 450 39 785 +3 946 967 945 +3 836 838 889 +3 787 761 788 +3 967 983 638 +3 966 967 638 +3 991 990 971 +3 597 1165 1231 +3 937 539 834 +3 934 948 947 +3 933 934 947 +3 886 846 942 +3 972 971 526 +3 1737 1762 1746 +3 1841 1851 1829 +3 417 1219 1218 +3 1166 110 1125 +3 159 342 113 +3 1065 1032 1274 +3 430 1065 1274 +3 1307 1320 1395 +3 767 1027 1 +3 846 798 1067 +3 735 1256 469 +3 1829 1850 1834 +3 398 317 1039 +3 288 32 34 +3 1051 1057 1058 +3 515 1684 1674 +3 1080 1079 1057 +3 1051 1058 1029 +3 1039 288 34 +3 1561 1726 1038 +3 1379 1307 1395 +3 304 642 409 +3 1396 1380 1381 +3 1030 1051 1029 +3 1219 1218 959 +3 598 1205 642 +3 1604 1615 1613 +3 1209 953 1193 +3 389 1521 1121 +3 398 75 70 +3 1314 273 524 +3 1022 1030 1021 +3 1022 1021 1016 +3 1030 1029 1021 +3 598 642 304 +3 528 1185 714 +3 1194 1209 1193 +3 177 12 397 +3 878 67 320 +3 1057 1045 1028 +3 1096 1095 1079 +3 1296 264 1319 +3 101 491 1237 +3 834 808 67 +3 1312 1484 1110 +3 963 1312 1110 +3 113 344 637 +3 1497 113 1496 +3 1119 1127 1113 +3 1312 1483 1484 +3 1799 1816 1812 +3 1079 1095 1057 +3 854 357 1191 +3 399 444 1210 +3 539 1011 383 +3 246 250 664 +3 1028 1038 1020 +3 1058 1057 1029 +3 311 1329 1396 +3 1260 1483 1312 +3 1187 1328 428 +3 1851 1864 1850 +3 317 609 619 +3 609 463 619 +3 1223 952 317 +3 603 1166 619 +3 1003 976 1094 +3 1248 556 297 +3 287 1885 555 +3 1138 1172 1163 +3 297 556 610 +3 1591 878 1009 +3 463 603 619 +3 749 110 1166 +3 1157 680 1081 +3 1886 304 409 +3 436 1027 605 +3 1015 1029 1014 +3 556 20 610 +3 20 604 610 +3 1099 1186 1189 +3 20 599 604 +3 1209 854 953 +3 1360 1550 1685 +3 492 398 70 +3 1172 1193 1192 +3 1175 1172 1192 +3 733 292 406 +3 202 733 406 +3 1010 834 67 +3 468 113 637 +3 154 1157 1081 +3 1172 1175 1163 +3 1193 854 1192 +3 953 854 1193 +3 1055 174 493 +3 1502 650 1046 +3 236 60 84 +3 1195 1194 1176 +3 85 177 397 +3 1163 1175 1148 +3 585 433 357 +3 1050 1045 1028 +3 1138 1148 1112 +3 1603 1402 1589 +3 1174 1192 1191 +3 1170 1174 1190 +3 1416 1417 1617 +3 398 1039 34 +3 75 398 1007 +3 1095 1107 1078 +3 1133 1134 1132 +3 1528 1022 1551 +3 1066 598 304 +3 292 733 667 +3 63 903 18 +3 619 1125 288 +3 1357 1355 1356 +3 733 1363 667 +3 470 1 212 +3 1017 830 136 +3 1119 1113 1095 +3 1387 231 247 +3 1107 1112 1078 +3 113 468 1496 +3 1028 1045 1050 +3 1014 1028 1013 +3 808 1011 539 +3 830 841 839 +3 12 50 275 +3 1344 1530 1115 +3 1363 153 19 +3 667 1363 19 +3 1103 1102 1068 +3 952 609 317 +3 1175 1174 1148 +3 1031 236 681 +3 595 10 555 +3 1119 1114 1587 +3 1114 1119 1096 +3 709 272 492 +3 451 736 434 +3 1174 1175 1192 +3 1380 1328 1316 +3 928 595 555 +3 153 489 1202 +3 572 598 1066 +3 19 153 1202 +3 1737 1746 1721 +3 1418 1417 1395 +3 1148 1147 1126 +3 488 1387 1448 +3 1245 488 1448 +3 1040 543 598 +3 572 1040 598 +3 1021 1029 1015 +3 1654 1653 1635 +3 329 58 595 +3 489 125 488 +3 1163 1148 1138 +3 1534 1687 1439 +3 342 709 344 +3 1112 1148 1126 +3 1202 489 488 +3 125 231 1387 +3 488 125 1387 +3 398 272 1223 +3 383 867 539 +3 414 296 928 +3 1176 1194 1172 +3 1028 1020 1013 +3 173 176 448 +3 1591 878 1009 +3 444 287 263 +3 1083 444 263 +3 272 952 1223 +3 1192 854 1191 +3 854 585 357 +3 1119 1152 1139 +3 1547 461 513 +3 296 329 595 +3 296 595 928 +3 603 749 1166 +3 1319 1329 1381 +3 1138 1152 1172 +3 63 18 33 +3 433 63 104 +3 769 433 104 +3 1174 1171 1147 +3 1372 1381 1375 +3 1613 1424 1603 +3 1113 1138 1107 +3 571 1218 1219 +3 1528 1551 1548 +3 1007 398 34 +3 1738 1737 1717 +3 1396 1329 1380 +3 1063 572 1066 +3 1153 1176 1152 +3 1139 1113 1127 +3 1119 1139 1127 +3 1191 357 1190 +3 357 240 1190 +3 1148 1174 1147 +3 29 460 325 +3 317 619 1039 +3 1754 1762 1737 +3 1329 311 1396 +3 1309 1380 1316 +3 1225 247 1218 +3 1448 1387 247 +3 1028 1045 1038 +3 1635 1453 1452 +3 116 1256 735 +3 514 1032 962 +3 1095 1078 1086 +3 1079 1095 1086 +3 357 433 240 +3 1174 1170 1171 +3 1218 1219 959 +3 1067 942 846 +3 1057 1095 1079 +3 10 114 287 +3 150 853 620 +3 555 10 287 +3 1152 1138 1139 +3 1052 1085 1370 +3 1704 1721 1703 +3 89 51 1002 +3 512 89 1002 +3 1152 1176 1172 +3 981 1206 992 +3 991 512 1002 +3 402 673 48 +3 1016 1551 1022 +3 1151 571 1219 +3 433 769 240 +3 1291 1380 1309 +3 1571 785 884 +3 589 490 605 +3 584 572 1063 +3 1057 1079 1045 +3 1138 1112 1107 +3 1045 1086 1078 +3 1095 1113 1107 +3 76 512 991 +3 1549 1552 1548 +3 203 769 271 +3 992 76 991 +3 274 89 512 +3 76 274 512 +3 274 51 89 +3 139 118 51 +3 274 139 51 +3 11 248 118 +3 139 11 118 +3 1056 1042 1068 +3 737 103 17 +3 871 302 858 +3 273 489 153 +3 1826 1835 1820 +3 197 48 294 +3 975 197 294 +3 197 713 402 +3 48 197 402 +3 584 1076 1040 +3 1079 1086 1045 +3 1029 1057 1028 +3 1139 1138 1113 +3 572 584 1040 +3 198 412 1040 +3 1076 198 1040 +3 298 273 153 +3 1500 1531 1359 +3 1096 1119 1095 +3 1194 1193 1172 +3 1560 785 1571 +3 882 866 894 +3 49 139 274 +3 1189 1207 1206 +3 1102 1133 1132 +3 1717 1721 1704 +3 1674 1487 1653 +3 584 570 1076 +3 894 1102 907 +3 821 1167 1199 +3 17 103 140 +3 50 17 140 +3 1042 1056 866 +3 1056 1068 894 +3 866 1056 894 +3 894 1068 1102 +3 1102 1132 936 +3 907 1102 936 +3 1160 950 936 +3 1132 1160 936 +3 1174 1191 1190 +3 1206 85 76 +3 992 1206 76 +3 397 274 76 +3 85 397 76 +3 275 49 274 +3 397 275 274 +3 140 139 49 +3 275 140 49 +3 103 11 139 +3 140 103 139 +3 409 642 329 +3 296 409 329 +3 436 975 1241 +3 436 605 975 +3 605 26 975 +3 26 197 975 +3 26 379 713 +3 197 26 713 +3 1010 539 937 +3 59 454 346 +3 652 408 413 +3 21 61 149 +3 171 345 347 +3 94 2 130 +3 130 256 134 +3 1004 1393 715 +3 313 368 367 +3 544 90 146 +3 81 535 379 +3 1257 527 950 +3 1257 950 1160 +3 302 301 259 +3 1004 414 928 +3 1160 1238 1257 +3 102 214 186 +3 1238 1160 1161 +3 1226 1238 1161 +3 1257 227 527 +3 95 233 364 +3 620 853 29 +3 1257 534 227 +3 282 454 230 +3 1453 1653 1452 +3 232 233 95 +3 821 1199 1886 +3 1232 1238 1226 +3 1238 981 1257 +3 1257 981 534 +3 417 408 652 +3 1233 1238 1232 +3 1027 436 42 +3 196 504 111 +3 169 180 81 +3 61 21 479 +3 631 231 388 +3 372 631 388 +3 1300 1382 1270 +3 1558 1559 857 +3 714 298 800 +3 298 153 800 +3 981 974 534 +3 704 348 5 +3 706 226 234 +3 388 231 443 +3 311 1330 1329 +3 1282 1300 1270 +3 1189 981 1238 +3 1233 1189 1238 +3 334 94 256 +3 1462 1672 1473 +3 895 786 787 +3 595 58 10 +3 1242 1251 1256 +3 489 231 125 +3 1236 1256 1250 +3 0 717 40 +3 470 212 0 +3 717 279 40 +3 276 230 59 +3 454 282 1237 +3 521 219 213 +3 417 652 346 +3 1266 417 346 +3 364 521 213 +3 171 363 345 +3 279 704 40 +3 470 0 160 +3 94 95 2 +3 42 281 717 +3 97 375 540 +3 61 479 363 +3 1216 705 706 +3 349 372 233 +3 453 42 717 +3 1241 975 150 +3 150 975 294 +3 214 362 282 +3 959 417 1266 +3 959 1219 417 +3 281 42 279 +3 408 607 372 +3 372 607 631 +3 0 40 25 +3 1221 69 1242 +3 287 114 263 +3 279 147 157 +3 704 279 157 +3 134 94 130 +3 81 52 535 +3 1265 58 329 +3 1249 1265 329 +3 82 97 13 +3 364 643 158 +3 82 375 97 +3 156 542 1214 +3 479 232 345 +3 35 82 13 +3 147 620 29 +3 102 186 58 +3 64 102 58 +3 363 479 345 +3 21 413 479 +3 652 413 21 +3 372 388 233 +3 216 43 5 +3 61 171 52 +3 413 349 479 +3 186 114 10 +3 619 288 1039 +3 697 1221 412 +3 171 61 363 +3 212 717 0 +3 1236 1242 1256 +3 607 408 417 +3 92 21 149 +3 279 42 147 +3 1221 1222 412 +3 697 1217 457 +3 156 1214 1213 +3 453 717 1 +3 552 829 868 +3 114 276 263 +3 570 734 701 +3 324 29 325 +3 1 717 212 +3 214 102 101 +3 2 364 213 +3 95 364 2 +3 74 97 68 +3 108 58 1265 +3 196 241 504 +3 416 325 326 +3 1346 900 767 +3 642 1205 1249 +3 71 135 6 +3 665 261 260 +3 389 43 216 +3 108 64 58 +3 1255 1236 1250 +3 7 1261 71 +3 1261 135 71 +3 83 737 17 +3 165 380 327 +3 147 29 324 +3 279 717 281 +3 417 1218 607 +3 1218 247 607 +3 83 573 737 +3 737 1239 7 +3 1239 1261 7 +3 42 620 147 +3 1215 697 1214 +3 1221 1242 1236 +3 1261 172 135 +3 651 62 6 +3 117 332 6 +3 62 117 6 +3 416 324 325 +3 157 324 416 +3 40 5 43 +3 1227 1239 737 +3 573 1227 737 +3 1261 1262 172 +3 172 651 6 +3 135 172 6 +3 62 807 117 +3 0 25 160 +3 364 388 643 +3 345 95 94 +3 1214 909 1215 +3 336 149 180 +3 233 388 364 +3 807 832 117 +3 1243 1262 1261 +3 1239 1243 1261 +3 42 150 620 +3 1215 1217 697 +3 1214 412 198 +3 1213 1214 198 +3 293 1227 573 +3 172 62 651 +3 878 1591 67 +3 1214 697 412 +3 1228 1243 1239 +3 1227 1228 1239 +3 96 45 438 +3 40 704 5 +3 59 92 181 +3 172 9 62 +3 643 22 158 +3 388 22 643 +3 92 149 181 +3 345 94 334 +3 652 21 92 +3 345 232 95 +3 214 101 362 +3 535 171 713 +3 1262 678 172 +3 678 9 172 +3 9 592 62 +3 479 349 233 +3 326 325 333 +3 117 832 332 +3 347 345 334 +3 234 1216 706 +3 486 62 592 +3 486 807 62 +3 884 1340 1884 +3 1270 1381 1372 +3 348 157 299 +3 1320 1418 1395 +3 1243 452 1262 +3 1262 452 678 +3 343 592 9 +3 149 61 52 +3 1224 1230 1228 +3 1246 1253 1243 +3 1243 1253 452 +3 163 486 592 +3 163 96 486 +3 2 87 54 +3 1474 1497 1496 +3 1488 1474 1496 +3 525 115 731 +3 1230 1246 1243 +3 1228 1230 1243 +3 452 343 9 +3 678 452 9 +3 31 592 343 +3 31 163 592 +3 743 226 437 +3 334 256 347 +3 149 52 180 +3 6 875 248 +3 1482 1474 1488 +3 1246 1230 1253 +3 452 31 343 +3 45 96 163 +3 364 158 521 +3 737 7 103 +3 213 73 87 +3 1063 533 584 +3 45 44 438 +3 42 436 150 +3 1244 1240 1092 +3 211 445 23 +3 1459 1465 1482 +3 1440 988 1442 +3 163 44 45 +3 1418 1354 1863 +3 436 1241 150 +3 453 1027 42 +3 108 1265 1249 +3 230 454 59 +3 1465 1474 1482 +3 311 1329 1319 +3 677 1234 1230 +3 1230 1234 1253 +3 452 374 31 +3 163 323 44 +3 282 214 230 +3 214 282 230 +3 1258 374 452 +3 1253 1258 452 +3 1215 909 1217 +3 1354 1418 1320 +3 1234 1240 1253 +3 294 418 853 +3 558 234 226 +3 11 103 71 +3 1240 1258 1253 +3 31 77 163 +3 77 323 163 +3 558 280 234 +3 214 224 186 +3 1205 1250 1249 +3 586 1296 1282 +3 1240 1234 677 +3 114 230 276 +3 1125 47 32 +3 308 77 31 +3 868 780 340 +3 1250 108 1249 +3 694 226 707 +3 288 1125 32 +3 319 31 374 +3 31 319 308 +3 529 323 77 +3 323 24 44 +3 280 309 234 +3 234 309 1216 +3 1491 1012 183 +3 77 308 529 +3 323 41 24 +3 225 361 1313 +3 6 248 71 +3 1258 669 374 +3 669 319 374 +3 249 41 323 +3 529 249 323 +3 115 444 782 +3 146 90 3 +3 309 705 1216 +3 669 1258 1240 +3 1264 109 636 +3 1302 185 1293 +3 1217 909 960 +3 237 265 1302 +3 337 1337 1336 +3 547 541 205 +3 1313 691 705 +3 286 352 337 +3 1327 1332 370 +3 798 846 901 +3 337 1338 1337 +3 361 225 611 +3 451 439 484 +3 677 1092 1240 +3 225 1313 109 +3 264 228 277 +3 352 1334 337 +3 785 783 1340 +3 309 1313 705 +3 674 683 682 +3 663 623 602 +3 622 663 710 +3 995 1591 806 +3 450 206 1047 +3 1283 99 215 +3 611 563 593 +3 475 246 664 +3 1294 1264 636 +3 442 1337 1347 +3 465 527 227 +3 659 630 636 +3 1454 1499 1527 +3 602 674 663 +3 107 1293 185 +3 1829 1851 1850 +3 109 690 660 +3 1313 690 109 +3 563 611 1264 +3 362 101 1237 +3 337 1334 1338 +3 206 450 517 +3 1347 471 503 +3 167 554 1323 +3 1468 1472 1489 +3 1091 1141 702 +3 471 563 1294 +3 715 1167 821 +3 1264 611 225 +3 1332 337 1336 +3 1004 1887 399 +3 586 1283 215 +3 1023 1252 1400 +3 1179 1370 1383 +3 1313 726 1324 +3 471 636 630 +3 352 420 1334 +3 1047 39 450 +3 99 1283 586 +3 237 1302 107 +3 14 446 330 +3 1313 361 645 +3 530 525 784 +3 1338 553 1348 +3 1337 1338 1348 +3 370 1332 442 +3 1332 1336 442 +3 715 821 414 +3 237 283 1322 +3 362 1237 282 +3 187 1303 237 +3 257 27 131 +3 801 430 1335 +3 1287 36 213 +3 554 167 338 +3 335 1331 1330 +3 311 335 1330 +3 1331 439 451 +3 506 420 421 +3 1330 1331 451 +3 663 674 1284 +3 674 385 1284 +3 184 107 185 +3 1322 283 314 +3 14 27 446 +3 439 520 484 +3 265 185 1302 +3 420 553 1338 +3 554 338 916 +3 1400 1298 1023 +3 553 563 471 +3 1324 726 1313 +3 1285 14 446 +3 434 435 451 +3 338 167 175 +3 277 311 1319 +3 546 783 244 +3 801 1335 1274 +3 338 1297 916 +3 1294 563 1264 +3 420 1338 1334 +3 783 606 244 +3 1337 1348 1347 +3 1313 1324 690 +3 311 312 335 +3 220 1285 1310 +3 1284 385 1278 +3 1128 1023 1252 +3 1285 220 14 +3 622 623 663 +3 109 660 636 +3 524 446 330 +3 1589 1402 1403 +3 338 220 1310 +3 674 682 385 +3 284 337 1332 +3 107 1302 1293 +3 663 1284 710 +3 1888 517 1067 +3 350 1251 69 +3 435 434 415 +3 435 415 428 +3 1297 338 1310 +3 682 307 385 +3 1306 1305 1280 +3 1276 1306 1280 +3 313 367 312 +3 1327 284 1332 +3 1336 1337 442 +3 1264 225 109 +3 180 169 1229 +3 475 801 246 +3 352 267 353 +3 1403 1404 1589 +3 1285 1292 1310 +3 307 682 748 +3 682 718 748 +3 1277 1276 1275 +3 1158 237 107 +3 1067 517 511 +3 1271 1282 1270 +3 489 125 443 +3 446 14 330 +3 586 1282 1271 +3 1292 1285 446 +3 446 330 1287 +3 443 125 489 +3 108 116 735 +3 813 100 99 +3 1276 1307 1306 +3 1483 1260 1317 +3 1272 586 1271 +3 1348 553 471 +3 1287 213 219 +3 330 446 1287 +3 443 231 489 +3 330 36 1287 +3 86 35 955 +3 450 785 1560 +3 1312 1304 1260 +3 1329 435 428 +3 1289 1276 1277 +3 1289 1290 1276 +3 1158 187 237 +3 1311 556 1248 +3 558 226 743 +3 1323 554 993 +3 1292 446 524 +3 273 443 489 +3 1290 1289 1277 +3 1290 1307 1276 +3 215 264 1296 +3 1304 1286 1273 +3 1260 1304 1273 +3 1311 1248 1273 +3 1286 1311 1273 +3 246 801 250 +3 1322 314 278 +3 1019 1572 1036 +3 307 748 608 +3 182 307 608 +3 1321 443 273 +3 471 1294 636 +3 215 1296 586 +3 1322 278 265 +3 542 701 1129 +3 1101 1284 1278 +3 39 783 785 +3 1304 400 1286 +3 400 1311 1286 +3 1339 244 1200 +3 1324 309 726 +3 674 602 683 +3 265 237 1322 +3 1653 1487 1470 +3 446 36 330 +3 1321 22 443 +3 1277 1267 1290 +3 1290 1308 1307 +3 1313 309 1324 +3 467 68 97 +3 1312 1279 1304 +3 367 1331 335 +3 524 330 1287 +3 1347 1348 471 +3 1308 1315 1307 +3 1365 1529 1108 +3 531 530 784 +3 123 531 784 +3 1041 556 1311 +3 666 1041 1311 +3 312 367 335 +3 1705 1707 1711 +3 690 1324 725 +3 1331 367 439 +3 710 1284 1101 +3 608 748 758 +3 170 699 169 +3 1308 1309 1315 +3 1368 1362 1371 +3 306 1200 244 +3 1279 1299 1304 +3 1304 1299 400 +3 666 1311 400 +3 251 283 237 +3 1853 1866 1871 +3 1312 963 1279 +3 1101 1279 963 +3 1314 1321 273 +3 699 1229 169 +3 1268 1290 1267 +3 1290 1309 1308 +3 386 1320 1315 +3 1320 386 1315 +3 314 1327 370 +3 542 156 701 +3 475 1486 1684 +3 1297 1185 528 +3 1031 916 60 +3 1297 1310 1185 +3 158 1321 1314 +3 1379 1305 1306 +3 553 420 506 +3 291 1342 782 +3 608 758 1041 +3 666 608 1041 +3 1635 1452 1453 +3 60 916 528 +3 916 1297 528 +3 1314 1287 158 +3 601 471 630 +3 1291 1290 1268 +3 1316 1315 1309 +3 1316 1320 1315 +3 400 608 666 +3 1292 524 1185 +3 187 189 188 +3 68 467 1318 +3 187 188 1303 +3 1281 1291 1268 +3 1290 1291 1309 +3 1320 1316 386 +3 1278 385 1299 +3 1279 1278 1299 +3 385 307 400 +3 1299 385 400 +3 307 182 400 +3 400 182 608 +3 801 208 430 +3 243 547 205 +3 1292 1185 1310 +3 1324 726 725 +3 699 170 105 +3 105 68 1318 +3 699 105 1318 +3 1316 1325 386 +3 1325 1187 386 +3 1096 1587 1114 +3 515 208 801 +3 1287 1314 524 +3 1287 219 158 +3 1541 1546 1545 +3 1540 1541 1545 +3 1361 519 1520 +3 570 1129 701 +3 785 1340 884 +3 176 903 127 +3 1232 1226 1233 +3 570 1366 1129 +3 1571 884 1560 +3 378 533 1432 +3 210 570 533 +3 378 210 533 +3 570 210 1366 +3 210 290 1129 +3 1366 210 1129 +3 1129 290 542 +3 290 909 542 +3 290 960 909 +3 124 697 290 +3 210 124 290 +3 697 457 290 +3 290 457 960 +3 960 457 1217 +3 378 124 210 +3 1477 1420 1006 +3 591 378 597 +3 1165 591 597 +3 378 591 124 +3 124 457 697 +3 124 1394 457 +3 1653 1470 1452 +3 1377 1378 1388 +3 1199 1048 1231 +3 124 350 1394 +3 1394 350 457 +3 1048 1165 1231 +3 1048 671 591 +3 1165 1048 591 +3 671 350 124 +3 591 671 124 +3 350 69 457 +3 98 467 97 +3 827 155 1880 +3 1544 1545 1157 +3 176 173 18 +3 1273 700 1260 +3 1369 1048 1199 +3 671 588 350 +3 1545 1546 1204 +3 1546 640 1204 +3 607 247 231 +3 1278 1279 1101 +3 154 1081 1513 +3 1777 1770 1785 +3 1295 499 143 +3 1850 1849 1834 +3 1199 732 1369 +3 732 1183 1369 +3 926 1048 1369 +3 1183 926 1369 +3 926 635 671 +3 1048 926 671 +3 671 635 588 +3 635 1251 350 +3 588 635 350 +3 1449 1472 1468 +3 1490 1489 1472 +3 1425 1074 1389 +3 1198 494 1065 +3 758 718 759 +3 1449 1468 1472 +3 1260 700 1317 +3 732 926 1183 +3 1449 1451 1468 +3 1468 1451 1472 +3 1490 538 1489 +3 272 406 952 +3 1183 926 732 +3 926 1183 635 +3 1426 1435 1434 +3 1449 1450 1451 +3 1421 1422 1426 +3 1426 1422 1435 +3 1469 1486 1490 +3 1472 1469 1490 +3 1183 455 635 +3 1435 1450 1449 +3 1434 1435 1449 +3 1451 1469 1472 +3 475 538 1490 +3 1486 475 1490 +3 475 664 538 +3 250 289 538 +3 664 250 538 +3 306 260 575 +3 455 1183 732 +3 1169 455 732 +3 455 469 635 +3 469 1256 1251 +3 635 469 1251 +3 1204 1389 1074 +3 1319 1381 1382 +3 1364 1370 1085 +3 1329 1396 1381 +3 1330 435 1329 +3 1444 1451 1450 +3 1435 1444 1450 +3 1520 519 1120 +3 1505 1120 1326 +3 640 883 1425 +3 1357 1364 1355 +3 1357 1370 1364 +3 1357 1211 1370 +3 1225 1245 1448 +3 1408 1423 1422 +3 1411 1408 1422 +3 1423 1436 1435 +3 1422 1423 1435 +3 1436 1437 1444 +3 1435 1436 1444 +3 1437 1452 1451 +3 1444 1437 1451 +3 1452 1470 1469 +3 1451 1452 1469 +3 1469 1470 1486 +3 1486 1674 1487 +3 1413 980 1420 +3 1470 1487 1486 +3 1537 154 1105 +3 1393 1054 1169 +3 668 455 1169 +3 1054 668 1169 +3 668 735 469 +3 455 668 469 +3 1455 1445 1446 +3 1185 524 298 +3 459 552 38 +3 1731 1739 1722 +3 1376 1211 1357 +3 1409 1408 1398 +3 1427 1437 1436 +3 1423 1427 1436 +3 1403 1388 1404 +3 84 1367 1363 +3 596 556 1041 +3 714 1185 298 +3 1004 1054 1393 +3 1210 574 399 +3 1320 1307 1315 +3 1635 1453 1438 +3 1359 1357 1356 +3 1358 1359 1356 +3 1377 1376 1357 +3 1359 1377 1357 +3 1388 1211 1376 +3 1377 1388 1376 +3 1402 1409 1398 +3 1388 1398 1211 +3 1402 1408 1409 +3 1402 1424 1423 +3 1408 1402 1423 +3 1423 1424 1427 +3 1424 1438 1437 +3 1427 1424 1437 +3 1438 1453 1452 +3 1437 1438 1452 +3 1197 828 650 +3 1111 1511 1510 +3 1300 1319 1382 +3 1010 808 539 +3 208 1198 430 +3 1200 459 38 +3 1539 1540 1544 +3 1507 1094 1405 +3 1094 976 1405 +3 475 515 801 +3 533 378 1432 +3 744 491 668 +3 1054 744 668 +3 491 101 735 +3 668 491 735 +3 384 459 1200 +3 306 384 1200 +3 1512 1197 650 +3 7 71 103 +3 1466 1295 1074 +3 1325 1328 1187 +3 1329 428 1328 +3 1507 1405 1397 +3 1120 897 1184 +3 1388 1403 1402 +3 1110 859 576 +3 1431 1110 576 +3 399 1212 744 +3 1363 800 153 +3 575 384 306 +3 1178 1100 1512 +3 1425 883 1074 +3 733 84 1363 +3 55 54 87 +3 1296 1300 1282 +3 1378 1377 1359 +3 1004 715 414 +3 1462 1479 1478 +3 1479 1492 222 +3 1478 1479 222 +3 1492 30 179 +3 222 1492 179 +3 30 351 179 +3 1544 1157 154 +3 429 297 709 +3 1110 1483 1475 +3 86 306 391 +3 700 159 1498 +3 1317 700 1498 +3 205 467 540 +3 828 518 650 +3 1672 1462 1473 +3 399 574 1212 +3 574 634 744 +3 1212 574 744 +3 634 1237 491 +3 744 634 491 +3 1367 714 1363 +3 375 606 112 +3 375 82 606 +3 82 86 391 +3 1457 1181 640 +3 1546 1457 640 +3 1479 1493 1492 +3 1493 258 30 +3 1492 1493 30 +3 429 1248 297 +3 39 375 199 +3 336 181 149 +3 1439 1511 1111 +3 1684 515 475 +3 1483 1317 1475 +3 1317 1498 1475 +3 429 342 159 +3 700 429 159 +3 1510 1052 1179 +3 1181 1130 883 +3 640 1181 883 +3 1405 980 1413 +3 1140 964 1181 +3 1509 1439 1517 +3 1479 1480 1493 +3 403 351 30 +3 258 403 30 +3 390 389 1121 +3 1400 897 1298 +3 604 272 709 +3 1460 749 603 +3 403 523 351 +3 1249 329 642 +3 1390 1466 883 +3 1382 1381 1270 +3 1363 714 800 +3 342 429 709 +3 540 375 1047 +3 297 604 709 +3 1467 1461 1201 +3 1130 1390 883 +3 1374 1454 1515 +3 1462 1480 1479 +3 1136 523 403 +3 964 1441 1181 +3 1059 1522 1128 +3 1003 221 500 +3 976 1003 500 +3 1100 1197 1512 +3 390 25 43 +3 1407 1416 1415 +3 1406 1407 1415 +3 1455 1446 1458 +3 1446 1463 1462 +3 1458 1446 1462 +3 1463 1464 1462 +3 1464 1481 1480 +3 1462 1464 1480 +3 1481 1494 1493 +3 1480 1481 1493 +3 1494 994 258 +3 1493 1494 258 +3 456 403 258 +3 994 456 258 +3 621 1136 403 +3 456 621 403 +3 621 523 1136 +3 621 745 523 +3 141 473 523 +3 745 141 523 +3 1516 1524 1476 +3 1128 245 1471 +3 1155 321 634 +3 574 1155 634 +3 599 681 202 +3 298 524 273 +3 681 236 202 +3 1368 1371 1527 +3 1263 1254 1540 +3 1502 1524 1476 +3 1476 1046 1115 +3 321 454 1237 +3 634 321 1237 +3 541 467 205 +3 467 97 540 +3 98 97 467 +3 236 84 733 +3 1446 1464 1463 +3 621 141 745 +3 1516 1476 1503 +3 1467 1201 828 +3 174 639 142 +3 202 236 733 +3 1686 1703 1702 +3 1494 1495 994 +3 1495 1123 994 +3 516 141 621 +3 1037 1059 1128 +3 590 467 541 +3 701 156 1164 +3 1398 1408 1383 +3 493 1301 322 +3 639 321 1155 +3 1429 1446 1445 +3 1481 1495 1494 +3 1220 456 994 +3 1123 1220 994 +3 954 322 495 +3 1373 493 322 +3 987 321 639 +3 260 306 86 +3 1370 1384 1383 +3 1280 1305 1362 +3 1305 1371 1362 +3 1305 1379 1371 +3 1392 1386 1371 +3 1392 1395 1386 +3 1395 1407 1386 +3 1395 1417 1416 +3 1407 1395 1416 +3 1703 1694 1704 +3 1428 1430 1429 +3 1430 1442 1446 +3 1429 1430 1446 +3 1442 1459 1464 +3 1446 1442 1464 +3 1459 1482 1481 +3 1464 1459 1481 +3 1482 1488 1481 +3 1488 1496 1495 +3 1481 1488 1495 +3 1496 468 1123 +3 1495 1496 1123 +3 637 1220 1123 +3 468 637 1123 +3 637 456 1220 +3 637 1203 456 +3 161 621 456 +3 1203 161 456 +3 75 516 621 +3 161 75 621 +3 1687 1694 1703 +3 75 34 495 +3 954 495 34 +3 34 32 322 +3 954 34 322 +3 32 47 322 +3 47 1373 322 +3 47 493 1373 +3 47 183 493 +3 183 1055 493 +3 1055 1012 174 +3 1012 639 174 +3 959 987 639 +3 1012 959 639 +3 959 321 987 +3 959 346 321 +3 346 454 321 +3 1341 1229 541 +3 1229 699 541 +3 699 1318 590 +3 541 699 590 +3 637 161 1203 +3 1615 1635 1438 +3 1300 1296 1319 +3 1379 1395 1392 +3 1615 1438 1424 +3 1613 1615 1424 +3 75 1007 34 +3 1229 1341 336 +3 700 1273 1248 +3 1392 1395 1379 +3 70 161 637 +3 183 1012 1055 +3 1673 1184 1504 +3 1159 1504 1184 +3 1266 346 959 +3 1604 1613 1603 +3 1459 1442 1456 +3 1075 1502 1503 +3 221 1100 500 +3 677 1084 1092 +3 1230 1224 677 +3 1537 1544 154 +3 1105 1097 1088 +3 1121 1105 1088 +3 1146 1346 767 +3 1087 293 176 +3 1100 1467 1197 +3 1154 585 1209 +3 962 1032 1065 +3 1765 1759 1024 +3 1408 1501 1383 +3 1516 1502 1524 +3 143 499 519 +3 1147 1142 1126 +3 1074 1094 680 +3 1399 897 1400 +3 1087 176 366 +3 235 1087 653 +3 897 1399 1184 +3 1149 1135 1061 +3 1685 1687 1360 +3 1379 1392 1371 +3 1810 259 242 +3 293 448 176 +3 1521 1537 1105 +3 235 653 677 +3 1100 1361 1467 +3 373 1538 1537 +3 1514 585 1059 +3 1059 585 341 +3 462 796 1023 +3 964 1106 1419 +3 1505 1326 1201 +3 711 63 1514 +3 964 1140 1092 +3 340 780 868 +3 796 1037 1128 +3 1037 127 796 +3 127 1037 796 +3 18 903 127 +3 1059 341 1522 +3 1508 366 1098 +3 1410 176 127 +3 293 1087 235 +3 1117 187 1876 +3 366 1508 1106 +3 1399 1159 1184 +3 1399 1400 1252 +3 1170 1099 1142 +3 1410 1037 1098 +3 903 18 127 +3 1383 1384 1211 +3 1522 341 1154 +3 1120 1505 1201 +3 1087 366 653 +3 1060 1135 1485 +3 964 1419 1130 +3 293 235 1224 +3 1244 1092 1457 +3 1545 1204 1157 +3 1252 1471 1399 +3 366 964 653 +3 1525 1126 1142 +3 160 360 1173 +3 366 176 1098 +3 499 1401 1298 +3 1539 1544 1537 +3 677 653 1084 +3 176 18 903 +3 199 375 112 +3 1520 1120 1461 +3 644 1539 1538 +3 80 1535 216 +3 176 1410 1098 +3 1140 1181 1457 +3 462 1098 796 +3 1541 1457 1546 +3 1361 1520 1467 +3 1467 1520 1461 +3 373 644 1538 +3 1106 462 781 +3 1591 834 67 +3 390 594 360 +3 160 390 360 +3 1254 1247 1541 +3 1075 1503 980 +3 903 711 127 +3 181 263 276 +3 444 1083 291 +3 1538 1539 1537 +3 1419 1106 1390 +3 519 1361 143 +3 216 1535 1521 +3 1094 976 680 +3 1441 1130 1181 +3 1006 672 1385 +3 1060 1485 1149 +3 43 389 390 +3 181 809 263 +3 1120 1201 1461 +3 1130 1419 1390 +3 1081 680 1507 +3 1231 1165 597 +3 809 1083 263 +3 964 366 1106 +3 809 181 336 +3 809 291 1083 +3 496 1506 1046 +3 650 496 1046 +3 390 1121 594 +3 1295 1003 1074 +3 1832 1845 1831 +3 1204 640 1389 +3 341 585 1154 +3 1081 1507 1082 +3 511 1884 569 +3 1197 1467 828 +3 1341 809 336 +3 1094 680 976 +3 1540 1545 1544 +3 1398 1388 1402 +3 594 1121 1088 +3 1233 1099 1189 +3 1502 1516 1503 +3 1506 1344 1115 +3 291 1137 1342 +3 1097 1513 1082 +3 1412 812 123 +3 498 831 812 +3 1412 498 812 +3 883 1466 1074 +3 1006 1420 962 +3 1399 1471 1159 +3 962 672 1006 +3 1118 1091 702 +3 1686 1687 1703 +3 653 964 1084 +3 1735 1756 1747 +3 1 470 1536 +3 127 1059 1037 +3 1046 1506 1115 +3 1288 1006 1385 +3 1044 1288 1385 +3 1147 1171 1170 +3 1170 1142 1147 +3 1137 291 1346 +3 808 1008 1011 +3 1159 245 1504 +3 672 962 1065 +3 1390 1106 781 +3 1390 1156 1466 +3 1466 1156 1295 +3 1015 1016 1021 +3 644 1540 1539 +3 1137 1533 1542 +3 1088 1089 1288 +3 594 1088 1288 +3 1721 1746 1729 +3 360 594 1044 +3 594 1288 1044 +3 245 1108 1504 +3 216 1521 389 +3 1370 1211 1384 +3 1089 1006 1288 +3 461 587 513 +3 513 587 1351 +3 1351 1414 1412 +3 1091 498 1412 +3 1414 1091 1412 +3 1115 1530 538 +3 1092 1140 1457 +3 1509 1090 1534 +3 1137 1146 1533 +3 1349 461 1547 +3 767 1 1064 +3 1529 1365 1195 +3 964 1130 1441 +3 1351 587 1414 +3 1115 538 289 +3 1405 1413 1397 +3 1513 1081 1082 +3 980 514 1420 +3 680 1094 1507 +3 461 1414 587 +3 1106 1508 462 +3 1052 1370 1179 +3 1457 1541 1247 +3 587 1414 461 +3 1420 514 962 +3 545 1201 1326 +3 63 585 1514 +3 1105 154 1097 +3 1064 1533 1146 +3 1414 587 461 +3 973 1414 587 +3 1414 973 587 +3 250 1476 289 +3 1157 1204 680 +3 1398 1383 1211 +3 1507 1397 1082 +3 1543 1349 1533 +3 1536 1543 1533 +3 1543 410 461 +3 1349 1543 461 +3 973 1141 1414 +3 1141 1091 1414 +3 1476 1115 289 +3 1084 964 1092 +3 373 1537 1521 +3 1521 1105 1121 +3 1476 250 1274 +3 1149 1525 1142 +3 1254 1541 1540 +3 1064 1 1533 +3 1082 1397 1089 +3 1088 1082 1089 +3 80 373 1521 +3 1535 80 1521 +3 1341 541 547 +3 39 199 783 +3 1536 1533 1 +3 973 1414 461 +3 410 973 461 +3 1397 1413 1420 +3 1089 1397 1420 +3 1111 1383 1501 +3 1503 1476 1274 +3 606 82 391 +3 780 38 868 +3 1135 1104 1061 +3 711 1514 1059 +3 1365 1194 1195 +3 1111 1510 1179 +3 1485 1135 1149 +3 796 1128 1252 +3 1228 293 1224 +3 644 1263 1540 +3 390 160 25 +3 63 33 104 +3 391 306 606 +3 306 244 606 +3 1097 154 1513 +3 494 672 1065 +3 1543 618 410 +3 537 973 410 +3 618 537 410 +3 1141 1352 702 +3 972 992 991 +3 1509 1534 1439 +3 1088 1097 1082 +3 1401 1023 1298 +3 53 569 1884 +3 1536 470 1543 +3 1410 127 1037 +3 1227 293 1228 +3 1128 1522 245 +3 1522 1154 245 +3 1850 1870 1849 +3 796 1252 1023 +3 173 83 33 +3 1543 470 618 +3 1242 69 1251 +3 1515 1527 1371 +3 1162 1135 1060 +3 1188 537 618 +3 1109 973 537 +3 1109 1141 973 +3 1109 1352 1141 +3 545 518 828 +3 1201 545 828 +3 1244 1457 1247 +3 1386 1515 1371 +3 1454 1518 1499 +3 1089 1477 1006 +3 462 1401 781 +3 1401 499 781 +3 63 433 585 +3 1886 1066 304 +3 1204 1074 680 +3 127 711 1059 +3 640 1425 1389 +3 1188 618 537 +3 499 1298 519 +3 1226 1060 1099 +3 1233 1226 1099 +3 1515 1454 1386 +3 1298 897 1120 +3 519 1298 1120 +3 1188 537 618 +3 1524 1502 1046 +3 1178 980 550 +3 1178 1512 1075 +3 1515 1386 1391 +3 1386 1454 1515 +3 1149 1142 1099 +3 1060 1149 1099 +3 1508 1098 462 +3 1401 462 1023 +3 1178 1075 980 +3 552 868 459 +3 1061 1525 1149 +3 1098 1037 796 +3 1524 1502 1476 +3 1476 1524 1046 +3 1828 1829 1834 +3 1089 1420 1477 +3 1352 672 494 +3 1502 1512 650 +3 1252 1128 1471 +3 1531 1518 1454 +3 1374 1531 1454 +3 1512 1502 1075 +3 1173 618 470 +3 160 1173 470 +3 1173 1188 618 +3 1173 360 1188 +3 1188 360 537 +3 360 1044 537 +3 537 1044 1109 +3 1044 1385 1109 +3 672 1352 1109 +3 1385 672 1109 +3 511 517 1560 +3 1390 781 1156 +3 223 222 178 +3 831 123 812 +3 141 1333 1618 +3 1812 1829 1828 +3 115 1005 1210 +3 1636 1637 1656 +3 1515 1454 1527 +3 1682 538 1530 +3 1637 1657 1656 +3 1072 1525 1061 +3 1071 1072 1061 +3 548 1350 142 +3 1072 1592 1525 +3 1487 1674 1684 +3 67 937 1010 +3 1754 1784 1762 +3 1462 1478 1473 +3 1137 1542 778 +3 1614 1637 1616 +3 1036 1572 1049 +3 1049 1584 1072 +3 1072 1584 1592 +3 1126 1525 1592 +3 1584 1126 1592 +3 199 606 783 +3 1499 1362 1368 +3 1680 1678 1679 +3 1049 1586 1584 +3 799 178 1558 +3 702 494 1198 +3 1499 1368 1527 +3 868 552 459 +3 1486 1487 1674 +3 1572 1584 1586 +3 1049 1572 1586 +3 779 702 1198 +3 1799 1812 1795 +3 1618 1333 141 +3 1662 1676 1675 +3 805 1350 548 +3 1026 1570 1572 +3 1572 1073 1584 +3 1073 1078 1584 +3 1112 1126 1584 +3 1078 1112 1584 +3 1617 1620 1416 +3 1676 560 483 +3 1675 1676 483 +3 1659 1678 1663 +3 1572 1570 1073 +3 1054 1004 399 +3 827 1880 1870 +3 1404 1590 1604 +3 1374 1515 1391 +3 1345 472 498 +3 802 1555 1519 +3 1655 1675 1674 +3 1416 1614 1415 +3 1407 1406 1386 +3 482 560 1676 +3 1678 1677 1663 +3 1146 1137 1346 +3 1026 1562 1570 +3 1562 1570 1572 +3 1570 1562 1572 +3 1677 482 1676 +3 547 1556 798 +3 701 734 570 +3 1589 1404 1603 +3 1641 1638 1634 +3 1639 1641 1634 +3 1657 1658 1662 +3 260 261 575 +3 156 701 1164 +3 1639 1634 1621 +3 1638 1658 1657 +3 1637 1638 1657 +3 1519 1118 702 +3 1415 1605 1590 +3 779 1519 702 +3 1406 1415 1590 +3 1663 1677 1662 +3 1641 1659 1638 +3 1658 1663 1662 +3 1635 1636 1654 +3 1562 1073 1570 +3 1687 1686 1439 +3 1047 375 39 +3 1621 1620 1617 +3 738 1519 779 +3 483 515 1674 +3 473 1333 531 +3 481 473 531 +3 1155 142 639 +3 1662 1675 1655 +3 1656 1662 1655 +3 1038 1045 1073 +3 1562 1038 1073 +3 222 179 178 +3 1428 1621 1617 +3 1675 483 1674 +3 1159 1471 245 +3 1365 245 1154 +3 1209 1365 1154 +3 245 1365 1108 +3 1637 1636 1616 +3 1416 1620 1614 +3 1638 1637 1614 +3 884 1340 1884 +3 1049 1043 1036 +3 1605 1616 1607 +3 1620 1638 1614 +3 1455 1428 1445 +3 1622 1529 1195 +3 1177 1622 1195 +3 550 976 500 +3 1587 1523 1119 +3 1428 1455 1639 +3 1096 1079 1080 +3 553 536 563 +3 1404 1604 1603 +3 1153 1622 1177 +3 641 638 661 +3 1013 1020 1038 +3 1051 1114 1096 +3 1080 1051 1096 +3 1114 1587 1096 +3 1556 243 798 +3 1532 1623 1622 +3 1153 1532 1622 +3 1642 1529 1622 +3 1623 1642 1622 +3 1642 1504 1108 +3 1529 1642 1108 +3 1378 1404 1388 +3 178 179 1559 +3 1455 1473 1641 +3 1653 1655 1674 +3 805 530 531 +3 33 18 173 +3 1605 1604 1590 +3 179 1259 1559 +3 1051 1587 1114 +3 1118 1345 1091 +3 851 523 532 +3 715 732 1167 +3 1636 1655 1654 +3 1621 1634 1620 +3 1093 1280 1362 +3 1051 1114 1587 +3 1604 1605 1607 +3 1022 1563 1051 +3 1030 1022 1051 +3 1563 1573 1114 +3 1051 1563 1114 +3 1573 1585 1587 +3 1114 1573 1587 +3 1585 1599 1523 +3 1587 1585 1523 +3 1599 1608 1532 +3 1523 1599 1532 +3 1608 1624 1623 +3 1532 1608 1623 +3 1643 1642 1623 +3 1624 1643 1623 +3 1643 1673 1504 +3 1642 1643 1504 +3 551 547 798 +3 1014 1016 1015 +3 1306 1307 1379 +3 805 548 525 +3 1656 1655 1636 +3 1333 805 531 +3 1683 1184 1673 +3 1608 1625 1624 +3 1644 1643 1624 +3 1625 1644 1624 +3 1664 1673 1643 +3 1644 1664 1643 +3 1023 1128 1252 +3 585 854 1209 +3 1351 1412 123 +3 322 1301 495 +3 799 844 474 +3 516 495 141 +3 1555 1345 1118 +3 495 1618 141 +3 1047 205 540 +3 141 1333 473 +3 1433 1426 1434 +3 597 378 1063 +3 1528 1564 1563 +3 1022 1528 1563 +3 1564 1574 1573 +3 1563 1564 1573 +3 1573 1574 1585 +3 1574 1576 1585 +3 1585 1576 1599 +3 1576 1600 1599 +3 1600 1609 1608 +3 1599 1600 1608 +3 1609 1626 1625 +3 1608 1609 1625 +3 1645 1644 1625 +3 1626 1645 1625 +3 1645 1665 1664 +3 1644 1645 1664 +3 1665 1673 1664 +3 1665 1326 1683 +3 1673 1665 1683 +3 1326 1184 1683 +3 1590 1404 1378 +3 1614 1616 1605 +3 1415 1614 1605 +3 495 1333 1618 +3 738 802 1519 +3 1473 1659 1641 +3 1301 805 1333 +3 205 206 517 +3 1405 976 550 +3 495 1301 1333 +3 1593 1601 1600 +3 1576 1593 1600 +3 1600 1601 1609 +3 716 208 515 +3 500 1178 550 +3 1259 523 851 +3 1559 1259 851 +3 831 481 812 +3 513 1349 1547 +3 1616 1636 1635 +3 222 223 1680 +3 1301 493 1350 +3 805 1301 1350 +3 1548 1552 1528 +3 1552 1565 1564 +3 1528 1552 1564 +3 1564 1565 1574 +3 1574 1565 1576 +3 1565 1577 1576 +3 1594 1593 1576 +3 1577 1594 1576 +3 1602 1601 1593 +3 1594 1602 1593 +3 1602 1610 1609 +3 1601 1602 1609 +3 1610 1627 1626 +3 1609 1610 1626 +3 1627 1646 1645 +3 1626 1627 1645 +3 1666 1665 1645 +3 1646 1666 1645 +3 1666 545 1326 +3 1665 1666 1326 +3 483 716 515 +3 547 243 1556 +3 221 1003 1295 +3 143 221 1295 +3 809 1341 547 +3 551 809 547 +3 782 1342 778 +3 731 782 778 +3 1458 1660 1455 +3 752 309 753 +3 1424 1402 1603 +3 1519 1555 1118 +3 1549 1553 1552 +3 1552 1553 1565 +3 1775 1799 1784 +3 1406 1590 1378 +3 493 174 142 +3 1350 493 142 +3 1656 1657 1662 +3 291 809 551 +3 731 778 513 +3 523 473 481 +3 1365 1209 1194 +3 1346 291 551 +3 784 731 513 +3 1550 1554 1553 +3 1549 1550 1553 +3 1566 1565 1553 +3 1554 1566 1553 +3 1566 1578 1577 +3 1565 1566 1577 +3 1578 1579 1577 +3 1577 1579 1594 +3 1579 1595 1602 +3 1594 1579 1602 +3 1595 1611 1610 +3 1602 1595 1610 +3 1628 1627 1610 +3 1611 1628 1610 +3 1628 1647 1646 +3 1627 1628 1646 +3 1647 1667 1666 +3 1646 1647 1666 +3 1667 1668 1666 +3 518 545 1666 +3 1668 518 1666 +3 1074 1003 1094 +3 1607 1616 1615 +3 123 784 513 +3 1499 1527 1454 +3 1604 1607 1615 +3 1566 1579 1578 +3 1628 1648 1647 +3 1648 1668 1667 +3 1647 1648 1667 +3 1681 518 1668 +3 778 1533 1349 +3 513 778 1349 +3 496 650 497 +3 1615 1616 1635 +3 1429 1445 1428 +3 718 758 748 +3 1678 1680 474 +3 1680 223 474 +3 778 1542 1533 +3 206 205 1047 +3 1478 222 1680 +3 1679 1678 1659 +3 857 831 498 +3 1386 1406 1391 +3 1360 1090 1554 +3 1550 1360 1554 +3 1567 1566 1554 +3 1090 1567 1554 +3 1567 1580 1579 +3 1566 1567 1579 +3 1580 1596 1595 +3 1579 1580 1595 +3 1596 1606 1611 +3 1595 1596 1611 +3 1606 1629 1628 +3 1611 1606 1628 +3 1629 1630 1628 +3 1630 1649 1648 +3 1628 1630 1648 +3 1649 1526 1668 +3 1648 1649 1668 +3 496 1681 1668 +3 1526 496 1668 +3 497 518 1681 +3 496 497 1681 +3 518 497 650 +3 1005 574 1210 +3 123 513 1351 +3 1877 1876 1865 +3 1558 1555 802 +3 799 1558 802 +3 472 857 498 +3 1455 1641 1639 +3 1634 1638 1620 +3 482 802 738 +3 1248 429 700 +3 1654 1655 1653 +3 1606 1630 1629 +3 1473 1478 1680 +3 1362 1499 1557 +3 1558 857 472 +3 1120 1184 1326 +3 857 851 831 +3 844 802 482 +3 474 844 482 +3 1555 1558 472 +3 844 799 802 +3 1342 1137 778 +3 1649 1669 1526 +3 1669 1506 496 +3 1526 1669 496 +3 1421 1411 1422 +3 851 532 481 +3 780 340 383 +3 1008 780 383 +3 1568 1567 1090 +3 1509 1568 1090 +3 1568 1581 1580 +3 1567 1568 1580 +3 1597 1596 1580 +3 1581 1597 1580 +3 1596 1597 1606 +3 1597 1612 1606 +3 1612 1631 1630 +3 1606 1612 1630 +3 1631 1650 1649 +3 1630 1631 1649 +3 1649 1650 1669 +3 1678 482 1677 +3 560 738 716 +3 1345 498 1091 +3 500 1100 1178 +3 1678 474 482 +3 1009 878 53 +3 1841 1855 1851 +3 1454 1527 1499 +3 827 107 1864 +3 495 516 75 +3 208 716 1198 +3 1428 1639 1621 +3 1771 1280 1093 +3 842 1008 808 +3 378 533 1063 +3 1582 1581 1568 +3 1659 1663 1658 +3 1865 1864 1851 +3 1503 514 980 +3 1583 1582 1568 +3 1588 1581 1582 +3 1583 1588 1582 +3 1598 1597 1581 +3 1588 1598 1581 +3 1433 1612 1597 +3 1433 1619 1612 +3 1632 1631 1612 +3 1619 1632 1612 +3 1651 1650 1631 +3 1632 1651 1631 +3 1651 1670 1669 +3 1650 1651 1669 +3 1670 1344 1506 +3 1669 1670 1506 +3 1660 1473 1455 +3 1353 842 808 +3 995 1353 808 +3 1353 1008 842 +3 1353 842 1008 +3 38 780 1008 +3 842 38 1008 +3 1517 1569 1568 +3 1509 1517 1568 +3 1569 1583 1568 +3 716 779 1198 +3 716 738 779 +3 560 482 738 +3 1360 1687 1534 +3 1353 38 842 +3 1111 1179 1383 +3 1598 1433 1597 +3 868 38 552 +3 1045 1078 1073 +3 1124 406 272 +3 1433 1632 1619 +3 474 223 1122 +3 1033 1765 1024 +3 1378 1359 1374 +3 1269 1270 1281 +3 291 782 444 +3 483 560 716 +3 1462 1473 1660 +3 499 1156 781 +3 1214 542 909 +3 1555 472 1345 +3 178 1559 1558 +3 851 481 831 +3 1269 1281 1268 +3 824 1856 1846 +3 53 1884 1009 +3 1439 1111 1517 +3 1111 1501 1569 +3 1517 1111 1569 +3 1411 1583 1569 +3 1411 1588 1583 +3 1411 1421 1588 +3 1421 1598 1588 +3 1421 1426 1598 +3 1426 1433 1598 +3 1434 1433 1598 +3 1433 1434 1598 +3 1633 1632 1433 +3 1434 1633 1433 +3 1633 1640 1632 +3 1652 1651 1632 +3 1640 1652 1632 +3 1671 1670 1651 +3 1652 1671 1651 +3 1671 1682 1344 +3 1670 1671 1344 +3 1274 1032 514 +3 1503 1274 514 +3 532 523 481 +3 1319 264 277 +3 546 806 1591 +3 546 995 806 +3 546 746 995 +3 1339 1353 995 +3 746 1339 995 +3 1339 1200 38 +3 1353 1339 38 +3 223 178 799 +3 1530 1344 1682 +3 1449 1633 1434 +3 399 744 1054 +3 831 812 123 +3 1122 223 799 +3 243 205 517 +3 1473 1679 1659 +3 1024 1034 1033 +3 1591 1340 546 +3 1501 1411 1569 +3 1156 499 1295 +3 1449 1640 1633 +3 1209 953 854 +3 1458 1462 1660 +3 1224 235 677 +3 1523 1153 1119 +3 1085 1355 1364 +3 1468 1652 1640 +3 1449 1468 1640 +3 1489 1671 1652 +3 1468 1489 1652 +3 1671 1489 1682 +3 1489 538 1682 +3 1836 1857 1844 +3 803 189 1117 +3 1685 1696 1695 +3 1785 1791 1801 +3 1808 1801 1791 +3 1791 1792 1815 +3 1751 1750 1735 +3 1843 1862 1842 +3 1210 444 115 +3 1800 1816 1799 +3 1803 1821 1802 +3 995 834 1591 +3 758 759 1182 +3 1836 1858 1857 +3 810 168 1857 +3 1858 810 1857 +3 1740 1757 1764 +3 873 872 865 +3 1808 1815 1801 +3 1815 1819 1801 +3 804 803 1117 +3 1741 1757 1740 +3 1793 865 1788 +3 1812 1816 1830 +3 804 1117 1878 +3 1561 1725 1726 +3 1857 168 824 +3 1757 1779 1764 +3 1764 1779 1786 +3 78 815 1868 +3 1822 1821 1803 +3 1717 1737 1721 +3 1844 1857 1846 +3 1725 1724 1013 +3 824 168 79 +3 1713 1718 1696 +3 1715 1714 1699 +3 1722 1730 1711 +3 1843 1842 1825 +3 1819 1843 1825 +3 1857 824 1846 +3 1821 1827 1826 +3 1809 1821 1826 +3 1815 1843 1819 +3 1821 1809 1802 +3 1548 1689 1549 +3 1733 1561 1562 +3 1733 1725 1561 +3 604 599 406 +3 406 599 202 +3 1822 1836 1821 +3 815 1881 1867 +3 1852 1855 1830 +3 1699 1706 1016 +3 54 55 845 +3 158 219 521 +3 1742 1741 1725 +3 1733 1742 1725 +3 1763 1777 1785 +3 1033 1788 1765 +3 1769 1776 1749 +3 1749 1755 1734 +3 1756 1769 1747 +3 1732 1751 1735 +3 1707 1714 1722 +3 1738 1754 1737 +3 1876 1864 1865 +3 1722 1714 1731 +3 865 1810 1787 +3 1788 865 1787 +3 1715 1732 1714 +3 1742 1757 1741 +3 1804 1803 1786 +3 1779 1804 1786 +3 1770 1791 1785 +3 1806 1810 242 +3 1722 1747 1730 +3 1705 1706 1707 +3 1804 1805 1803 +3 1835 1843 1815 +3 1346 551 1883 +3 1802 1809 1792 +3 1837 1836 1822 +3 1017 1837 1822 +3 1878 1117 1877 +3 1711 1730 1713 +3 1690 1706 1705 +3 1837 136 1836 +3 1830 1855 1841 +3 1868 1867 1856 +3 599 20 681 +3 136 1858 1836 +3 1791 1815 1808 +3 1024 1759 1018 +3 1730 1734 1713 +3 1785 1790 1756 +3 20 596 681 +3 1831 1830 1817 +3 1797 1802 1792 +3 1864 1876 827 +3 1881 815 814 +3 1787 1806 1781 +3 1116 916 1031 +3 814 1882 1872 +3 1711 1713 1697 +3 1110 1475 859 +3 1690 1705 1698 +3 1785 1801 1790 +3 1765 1787 1759 +3 596 20 556 +3 596 1180 681 +3 681 1180 1031 +3 1882 804 1872 +3 1698 1711 1697 +3 1759 1781 1758 +3 900 1883 979 +3 1696 1717 1704 +3 1026 1561 1562 +3 1769 1796 1776 +3 1013 1723 1715 +3 1734 1717 1718 +3 1832 1831 1813 +3 1180 316 1116 +3 1031 1180 1116 +3 1561 1742 1733 +3 1882 814 804 +3 1820 1835 1815 +3 1442 988 1447 +3 710 577 622 +3 1810 1806 1787 +3 596 1752 1180 +3 1180 316 1116 +3 316 1180 1116 +3 316 993 916 +3 1116 316 916 +3 1759 1787 1781 +3 1776 1800 1775 +3 1732 1735 1714 +3 1886 409 821 +3 1703 1729 1710 +3 1693 1685 1550 +3 1016 1706 1690 +3 1693 1689 1697 +3 1842 1862 1861 +3 1694 1695 1704 +3 1687 1685 1694 +3 988 382 1447 +3 1447 382 576 +3 747 797 120 +3 1776 1775 1755 +3 1199 1167 732 +3 1041 758 596 +3 596 758 1752 +3 1876 1158 107 +3 1685 1695 1694 +3 1858 818 810 +3 382 1431 576 +3 1693 1697 1696 +3 243 1888 798 +3 1117 189 187 +3 1823 1822 1803 +3 1805 1823 1803 +3 1442 1430 1443 +3 818 1858 136 +3 356 477 424 +3 382 1575 1431 +3 916 993 554 +3 467 590 1318 +3 1685 1693 1696 +3 1845 1866 1853 +3 1431 1575 1110 +3 1182 1752 758 +3 1182 1180 1752 +3 1182 825 1180 +3 1180 825 316 +3 1017 136 1837 +3 1430 1440 1443 +3 1440 908 988 +3 988 908 382 +3 1575 549 1110 +3 549 1150 963 +3 1110 549 963 +3 1825 1813 1814 +3 1796 1817 1800 +3 825 633 316 +3 1699 1714 1706 +3 633 993 316 +3 633 1323 993 +3 1430 1869 1440 +3 908 1575 382 +3 1101 963 1150 +3 1734 1738 1717 +3 1819 1825 1814 +3 1801 1819 1814 +3 633 825 1182 +3 1440 1869 908 +3 908 996 1575 +3 759 787 786 +3 1809 1826 1820 +3 1869 1145 908 +3 549 1101 1150 +3 1723 1732 1715 +3 1428 1847 1430 +3 1145 56 908 +3 908 56 996 +3 1144 1101 549 +3 1809 1820 1815 +3 1793 1788 1033 +3 797 633 1182 +3 759 797 1182 +3 1735 1750 1756 +3 996 56 1575 +3 56 549 1575 +3 1750 1763 1756 +3 1847 1848 1430 +3 1848 1859 1430 +3 1430 1859 1869 +3 56 1168 549 +3 1690 1689 1548 +3 1758 1779 1757 +3 786 797 759 +3 747 633 797 +3 633 747 1323 +3 1323 747 167 +3 865 866 873 +3 1778 1791 1770 +3 78 1868 824 +3 1805 1804 1779 +3 1428 1848 1847 +3 56 1053 1168 +3 1168 1131 1144 +3 549 1168 1144 +3 1877 1117 1876 +3 1707 1722 1711 +3 1731 1735 1739 +3 830 1823 1805 +3 830 1822 1823 +3 1859 1873 1145 +3 1869 1859 1145 +3 1131 1101 1144 +3 1814 1813 1790 +3 830 1017 1822 +3 207 562 561 +3 1772 1771 1093 +3 1557 1772 1093 +3 866 1033 1042 +3 1617 1417 1428 +3 1428 1417 1848 +3 1734 1755 1738 +3 1821 1836 1844 +3 1801 1814 1790 +3 895 797 786 +3 787 759 760 +3 1873 961 1145 +3 1145 961 56 +3 1053 1131 1168 +3 1833 1101 1131 +3 1833 710 1101 +3 1853 1871 1852 +3 1689 1690 1698 +3 1772 1275 1771 +3 1848 1417 1859 +3 242 830 1806 +3 1713 1734 1718 +3 1800 1799 1775 +3 1695 1696 1704 +3 1518 1557 1499 +3 1794 1275 1772 +3 1809 1815 1792 +3 1417 1418 1859 +3 961 951 56 +3 56 951 1053 +3 1833 1131 710 +3 1019 1742 1561 +3 1758 1757 1742 +3 1780 1779 1758 +3 1748 1557 1518 +3 1794 1277 1275 +3 1873 1879 961 +3 951 559 1053 +3 1053 559 1131 +3 1876 107 827 +3 1747 1769 1749 +3 1267 1277 1794 +3 1418 1863 1859 +3 1859 1863 1873 +3 1868 815 1867 +3 1766 1772 1557 +3 1748 1766 1557 +3 866 1793 1033 +3 559 1196 1131 +3 1196 1343 1131 +3 1131 1343 710 +3 1766 1794 1772 +3 180 1229 336 +3 415 1879 1873 +3 415 961 1879 +3 1343 577 710 +3 866 865 1793 +3 1362 1557 1093 +3 1789 1794 1766 +3 1873 1863 415 +3 1456 1442 1447 +3 1018 1742 1019 +3 1743 1748 1518 +3 1531 1743 1518 +3 1789 1267 1794 +3 434 961 415 +3 434 951 961 +3 1781 1779 1780 +3 1811 1267 1789 +3 1781 1805 1779 +3 404 522 438 +3 434 736 951 +3 736 559 951 +3 1743 1766 1748 +3 559 736 1196 +3 1722 1739 1747 +3 715 1393 1169 +3 1534 1090 1360 +3 1269 1271 1270 +3 604 1124 272 +3 1358 1531 1500 +3 1824 1268 1267 +3 1811 1824 1267 +3 155 813 1880 +3 736 480 1196 +3 1196 480 1343 +3 1343 480 577 +3 1790 1813 1796 +3 1782 1789 1766 +3 1760 1782 1766 +3 1803 1802 1797 +3 1777 1770 1785 +3 1719 1743 1531 +3 1760 1766 1743 +3 1838 1269 1268 +3 1824 1838 1268 +3 1750 1770 1777 +3 480 578 577 +3 1689 1693 1550 +3 1763 1750 1777 +3 1770 1777 1785 +3 1691 1358 1356 +3 1719 1531 1358 +3 736 1062 480 +3 1813 1831 1817 +3 1549 1689 1550 +3 1756 1763 1785 +3 1691 1356 1355 +3 1085 1691 1355 +3 1761 1760 1743 +3 1744 1761 1743 +3 1807 1811 1789 +3 1838 1271 1269 +3 78 824 79 +3 1876 187 1158 +3 1821 1844 1827 +3 1708 1719 1358 +3 1744 1743 1719 +3 1782 1807 1789 +3 1807 1824 1811 +3 1860 1271 1838 +3 736 451 1062 +3 1756 1790 1769 +3 1725 1740 1724 +3 1698 1705 1711 +3 1510 1691 1085 +3 1708 1358 1691 +3 1761 1782 1760 +3 1818 1824 1807 +3 1860 1272 1271 +3 1718 1717 1696 +3 451 207 480 +3 1062 451 480 +3 1817 1830 1816 +3 1796 1800 1776 +3 1510 1085 1052 +3 1818 1838 1824 +3 1875 1272 1860 +3 1813 1817 1796 +3 1720 1719 1708 +3 1736 1744 1719 +3 1839 1838 1818 +3 96 807 486 +3 1018 1758 1742 +3 1842 1861 1845 +3 1881 814 1872 +3 1781 1780 1758 +3 1867 1881 1872 +3 1692 1691 1510 +3 1720 1736 1719 +3 1783 1782 1761 +3 1839 1860 1838 +3 1875 1661 586 +3 1272 1875 586 +3 1806 1805 1781 +3 1712 1716 1708 +3 1727 1720 1708 +3 1716 1727 1708 +3 1854 1860 1839 +3 1143 1661 1875 +3 1661 99 586 +3 1143 99 1661 +3 1031 60 236 +3 1709 1708 1691 +3 1692 1709 1691 +3 1709 1712 1708 +3 1709 1716 1712 +3 1709 1727 1716 +3 1727 1728 1720 +3 1786 1803 1797 +3 747 120 167 +3 484 207 451 +3 1736 1753 1744 +3 1753 1761 1744 +3 1753 1783 1761 +3 1874 1860 1854 +3 1874 1875 1860 +3 1792 1791 1778 +3 824 1868 1856 +3 1817 1816 1800 +3 520 207 484 +3 1692 1700 1709 +3 1728 1727 1709 +3 1728 1745 1727 +3 1511 1688 1510 +3 1688 1692 1510 +3 1874 1143 1875 +3 1013 1715 1699 +3 1749 1776 1755 +3 1759 1758 1018 +3 1688 1701 1700 +3 1692 1688 1700 +3 1773 1783 1753 +3 1849 1854 1839 +3 813 1143 1874 +3 813 99 1143 +3 1842 1845 1832 +3 1710 1709 1700 +3 1701 1710 1700 +3 1872 804 1878 +3 1825 1842 1832 +3 1853 1852 1830 +3 1730 1749 1734 +3 1689 1698 1697 +3 1805 1806 830 +3 1710 1728 1709 +3 1840 1849 1839 +3 1831 1853 1830 +3 1724 1723 1013 +3 1729 1728 1710 +3 1849 1874 1854 +3 1849 1870 1874 +3 1741 1740 1725 +3 1755 1775 1754 +3 1731 1714 1735 +3 1747 1749 1730 +3 1706 1714 1707 +3 1729 1745 1728 +3 1767 1773 1753 +3 1880 813 1874 +3 1870 1880 1874 +3 865 858 1810 +3 1810 858 259 +3 1861 1866 1845 +3 1790 1796 1769 +3 1755 1754 1738 +3 1739 1735 1747 +3 1686 1688 1511 +3 1439 1686 1511 +3 1746 1745 1729 +3 1774 1773 1767 +3 1834 1849 1840 +3 1016 1690 1548 +3 1788 1787 1765 +3 1551 1016 1548 +3 1686 1702 1701 +3 1688 1686 1701 +3 1703 1710 1701 +3 1702 1703 1701 +3 1795 1798 1773 +3 1825 1832 1813 +3 1697 1713 1696 +3 1762 1745 1746 +3 1762 1768 1745 +3 1795 1773 1774 diff --git a/samples/cpp/tutorial_code/viz/creating_widgets.cpp b/samples/cpp/tutorial_code/viz/creating_widgets.cpp new file mode 100644 index 000000000..9ee6c5436 --- /dev/null +++ b/samples/cpp/tutorial_code/viz/creating_widgets.cpp @@ -0,0 +1,113 @@ +/** + * @file creating_widgets.cpp + * @brief Creating custom widgets using VTK + * @author Ozan Cagri Tonkal + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace cv; +using namespace std; + +/** + * @function help + * @brief Display instructions to use this tutorial program + */ +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to create a custom widget. You can create your own " + << "widgets by extending Widget2D/Widget3D, and with the help of WidgetAccessor." << endl + << "Usage:" << endl + << "./creating_widgets" << endl + << endl; +} + +/** + * @class TriangleWidget + * @brief Defining our own 3D Triangle widget + */ +class WTriangle : public viz::Widget3D +{ + public: + WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); +}; + +/** + * @function TriangleWidget::TriangleWidget + * @brief Constructor + */ +WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color) +{ + // Create a triangle + vtkSmartPointer points = vtkSmartPointer::New(); + points->InsertNextPoint(pt1.x, pt1.y, pt1.z); + points->InsertNextPoint(pt2.x, pt2.y, pt2.z); + points->InsertNextPoint(pt3.x, pt3.y, pt3.z); + + vtkSmartPointer triangle = vtkSmartPointer::New(); + triangle->GetPointIds()->SetId(0,0); + triangle->GetPointIds()->SetId(1,1); + triangle->GetPointIds()->SetId(2,2); + + vtkSmartPointer cells = vtkSmartPointer::New(); + cells->InsertNextCell(triangle); + + // Create a polydata object + vtkSmartPointer polyData = vtkSmartPointer::New(); + + // Add the geometry and topology to the polydata + polyData->SetPoints(points); + polyData->SetPolys(cells); + + // Create mapper and actor + vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 + mapper->SetInput(polyData); +#else + mapper->SetInputData(polyData); +#endif + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + // Store this actor in the widget in order that visualizer can access it + viz::WidgetAccessor::setProp(*this, actor); + + // Set the color of the widget. This has to be called after WidgetAccessor. + setColor(color); +} + +/** + * @function main + */ +int main() +{ + help(); + + /// Create a window + viz::Viz3d myWindow("Creating Widgets"); + + /// Create a triangle widget + WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); + + /// Show widget in the visualizer window + myWindow.showWidget("TRIANGLE", tw); + + /// Start event loop + myWindow.spin(); + + return 0; +} diff --git a/samples/cpp/tutorial_code/viz/launching_viz.cpp b/samples/cpp/tutorial_code/viz/launching_viz.cpp new file mode 100644 index 000000000..55a3ddee2 --- /dev/null +++ b/samples/cpp/tutorial_code/viz/launching_viz.cpp @@ -0,0 +1,66 @@ +/** + * @file launching_viz.cpp + * @brief Launching visualization window + * @author Ozan Cagri Tonkal + */ + +#include +#include + +using namespace cv; +using namespace std; + +/** + * @function help + * @brief Display instructions to use this tutorial program + */ +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. " + << "You can access the same window via its name. You can run event loop for a given period of time. " << endl + << "Usage:" << endl + << "./launching_viz" << endl + << endl; +} + +/** + * @function main + */ +int main() +{ + help(); + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + + /// Start event loop + myWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "First event loop is over" << endl; + + /// Access window via its name + viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo"); + + /// Start event loop + sameWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "Second event loop is over" << endl; + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + + /// Once more event loop is stopped + cout << "Last event loop is over" << endl; + return 0; +} diff --git a/samples/cpp/tutorial_code/viz/transformations.cpp b/samples/cpp/tutorial_code/viz/transformations.cpp new file mode 100644 index 000000000..d8713fddc --- /dev/null +++ b/samples/cpp/tutorial_code/viz/transformations.cpp @@ -0,0 +1,112 @@ +/** + * @file transformations.cpp + * @brief Visualizing cloud in different positions, coordinate frames, camera frustums + * @author Ozan Cagri Tonkal + */ + +#include +#include +#include + +using namespace cv; +using namespace std; + +/** + * @function help + * @brief Display instructions to use this tutorial program + */ +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to use makeTransformToGlobal() to compute required pose," + << "how to use makeCameraPose and Viz3d::setViewerPose. You can observe the scene " + << "from camera point of view (C) or global point of view (G)" << endl + << "Usage:" << endl + << "./transformations [ G | C ]" << endl + << endl; +} + +/** + * @function cvcloud_load + * @brief load bunny.ply + */ +Mat cvcloud_load() +{ + Mat cloud(1, 1889, CV_32FC3); + ifstream ifs("bunny.ply"); + + string str; + for(size_t i = 0; i < 12; ++i) + getline(ifs, str); + + Point3f* data = cloud.ptr(); + float dummy1, dummy2; + for(size_t i = 0; i < 1889; ++i) + ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2; + + cloud *= 5.0f; + return cloud; +} + +/** + * @function main + */ +int main(int argn, char **argv) +{ + help(); + + if (argn < 2) + { + cout << "Missing arguments." << endl; + return 1; + } + + bool camera_pov = (argv[1][0] == 'C'); + + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Let's assume camera has the following properties + Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + + /// We can get the pose of the cam using makeCameraPose + Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + + /// Create a cloud widget. + Mat bunny_cloud = cvcloud_load(); + viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + + /// Pose of the widget in camera frame + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + /// Pose of the widget in global frame + Affine3f cloud_pose_global = transform * cloud_pose; + + /// Visualize camera frame + if (!camera_pov) + { + viz::WCameraPosition cpw(0.5); // Coordinate axes + viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + myWindow.showWidget("CPW", cpw, cam_pose); + myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); + } + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(cam_pose); + + /// Start event loop. + myWindow.spin(); + + return 0; +} diff --git a/samples/cpp/tutorial_code/viz/widget_pose.cpp b/samples/cpp/tutorial_code/viz/widget_pose.cpp new file mode 100644 index 000000000..3ecead8d9 --- /dev/null +++ b/samples/cpp/tutorial_code/viz/widget_pose.cpp @@ -0,0 +1,79 @@ +/** + * @file widget_pose.cpp + * @brief Setting pose of a widget + * @author Ozan Cagri Tonkal + */ + +#include +#include +#include + +using namespace cv; +using namespace std; + +/** + * @function help + * @brief Display instructions to use this tutorial program + */ +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to visualize a cube rotated around (1,1,1) and shifted " + << "using Rodrigues vector." << endl + << "Usage:" << endl + << "./widget_pose" << endl + << endl; +} + +/** + * @function main + */ +int main() +{ + help(); + + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Add line to represent (1,1,1) axis + viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); + axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Line Widget", axis); + + /// Construct a cube widget + viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); + cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); + myWindow.showWidget("Cube Widget", cube_widget); + + /// Rodrigues vector + Mat rot_vec = Mat::zeros(1,3,CV_32F); + float translation_phase = 0.0, translation = 0.0; + while(!myWindow.wasStopped()) + { + /* Rotation using rodrigues */ + /// Rotate around (1,1,1) + rot_vec.at(0,0) += CV_PI * 0.01f; + rot_vec.at(0,1) += CV_PI * 0.01f; + rot_vec.at(0,2) += CV_PI * 0.01f; + + /// Shift on (1,1,1) + translation_phase += CV_PI * 0.01f; + translation = sin(translation_phase); + + Mat rot_mat; + Rodrigues(rot_vec, rot_mat); + + /// Construct pose + Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); + + myWindow.setWidgetPose("Cube Widget", pose); + + myWindow.spinOnce(1, true); + } + + return 0; +} diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 732a9172a..d25c3a6b5 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -41,7 +41,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_GPU_SAMPLES_REQUIRED_DEPS}) - if(HAVE_CUDA) + if(HAVE_CUDA AND NOT ANDROID) target_link_libraries(${the_target} ${CUDA_CUDA_LIBRARY}) endif() @@ -65,7 +65,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) if(MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) endif() ENDMACRO() @@ -83,6 +83,6 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${install_list} - DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/gpu/brox_optical_flow.cpp b/samples/gpu/brox_optical_flow.cpp index 722e19f02..7cd5089b4 100644 --- a/samples/gpu/brox_optical_flow.cpp +++ b/samples/gpu/brox_optical_flow.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "cvconfig.h" #include "opencv2/core/core.hpp" diff --git a/samples/gpu/morphology.cpp b/samples/gpu/morphology.cpp index 36f518b70..2596b2d0f 100644 --- a/samples/gpu/morphology.cpp +++ b/samples/gpu/morphology.cpp @@ -13,7 +13,7 @@ static void help() printf("\nShow off image morphology: erosion, dialation, open and close\n" "Call:\n morphology2 [image]\n" - "This program also shows use of rect, elipse and cross kernels\n\n"); + "This program also shows use of rect, ellipse and cross kernels\n\n"); printf( "Hot keys: \n" "\tESC - quit the program\n" "\tr - use rectangle structuring element\n" diff --git a/samples/gpu/opticalflow_nvidia_api.cpp b/samples/gpu/opticalflow_nvidia_api.cpp index 05a37ef69..31ee56978 100644 --- a/samples/gpu/opticalflow_nvidia_api.cpp +++ b/samples/gpu/opticalflow_nvidia_api.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "cvconfig.h" #include diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 8f3caac5b..de0feadd2 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -23,12 +23,13 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/gpu" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/gpu" COMPONENT samples) endif() if(INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB GPU_FILES performance/*.cpp performance/*.h) install(FILES ${GPU_FILES} - DESTINATION share/OpenCV/samples/gpu/performance - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu/performance + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + COMPONENT samples) endif() diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 6efd24144..85cb6cff1 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -1,6 +1,8 @@ #include #include #include +#include + #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" diff --git a/samples/ocl/CMakeLists.txt b/samples/ocl/CMakeLists.txt index 8db77d52c..7fc20fd35 100644 --- a/samples/ocl/CMakeLists.txt +++ b/samples/ocl/CMakeLists.txt @@ -38,7 +38,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) if(MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) endif() ENDMACRO() @@ -54,6 +54,6 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${install_list} - DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/ocl + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/python2/asift.py b/samples/python2/asift.py index 00d54c9e3..104cc5c11 100755 --- a/samples/python2/asift.py +++ b/samples/python2/asift.py @@ -16,7 +16,7 @@ USAGE --feature - Feature to use. Can be sift, surf of orb. Append '-flann' to feature name to use Flann-based matcher instead bruteforce. - Press left mouse button on a feature point to see its mathcing point. + Press left mouse button on a feature point to see its matching point. ''' import numpy as np diff --git a/samples/python2/find_obj.py b/samples/python2/find_obj.py index 66c971dd2..7c5e4b9f0 100755 --- a/samples/python2/find_obj.py +++ b/samples/python2/find_obj.py @@ -9,7 +9,7 @@ USAGE --feature - Feature to use. Can be sift, surf of orb. Append '-flann' to feature name to use Flann-based matcher instead bruteforce. - Press left mouse button on a feature point to see its mathcing point. + Press left mouse button on a feature point to see its matching point. ''' import numpy as np diff --git a/samples/winrt/ImageManipulations/common/LayoutAwarePage.cpp b/samples/winrt/ImageManipulations/common/LayoutAwarePage.cpp index 07092bb74..f3f4be234 100644 --- a/samples/winrt/ImageManipulations/common/LayoutAwarePage.cpp +++ b/samples/winrt/ImageManipulations/common/LayoutAwarePage.cpp @@ -235,7 +235,7 @@ void LayoutAwarePage::CoreWindow_PointerPressed(CoreWindow^ sender, PointerEvent if (properties->IsLeftButtonPressed || properties->IsRightButtonPressed || properties->IsMiddleButtonPressed) return; - // If back or foward are pressed (but not both) navigate appropriately + // If back or forward are pressed (but not both) navigate appropriately bool backPressed = properties->IsXButton1Pressed; bool forwardPressed = properties->IsXButton2Pressed; if (backPressed ^ forwardPressed)