diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake index b36fa78ccd..a796ae9faa 100644 --- a/cmake/OpenCVPCHSupport.cmake +++ b/cmake/OpenCVPCHSupport.cmake @@ -305,10 +305,13 @@ fi ${_command} '-D$,' '-D>' ") GET_FILENAME_COMPONENT(_outdir ${_output} PATH) + if(NOT CMAKE_HOST_WIN32) # chmod may be not available on Win32/MinGW (and it is not required) + set(_pch_prepare_command COMMAND chmod +x "${_pch_generate_file_cmd}") + endif() ADD_CUSTOM_COMMAND( OUTPUT "${_output}" COMMAND ${CMAKE_COMMAND} -E make_directory "${_outdir}" - COMMAND chmod +x "${_pch_generate_file_cmd}" + ${_pch_prepare_command} COMMAND "${_pch_generate_file_cmd}" DEPENDS "${_input}" "${_pch_generate_file_cmd}" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_name}" diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 637bf51b4b..99bed33153 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -147,7 +147,7 @@ if(DOXYGEN_FOUND) # set export variables string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_INPUT_LIST "${rootfile} ; ${faqfile} ; ${paths_include} ; ${paths_hal_interface} ; ${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${tutorial_js_path} ; ${paths_tutorial} ; ${tutorial_contrib_root}") - string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_IMAGE_PATH "${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${tutorial_js_path} ; ${paths_tutorial}") + string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_IMAGE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/images ; ${paths_doc} ; ${tutorial_path} ; ${tutorial_py_path} ; ${tutorial_js_path} ; ${paths_tutorial}") string(REPLACE ";" " \\\n" CMAKE_DOXYGEN_EXCLUDE_LIST "${CMAKE_DOXYGEN_EXCLUDE_LIST}") string(REPLACE ";" " " CMAKE_DOXYGEN_ENABLED_SECTIONS "${CMAKE_DOXYGEN_ENABLED_SECTIONS}") # TODO: remove paths_doc from EXAMPLE_PATH after face module tutorials/samples moved to separate folders diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 85f8fe161f..d6d3120b32 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -266,9 +266,7 @@ GENERATE_TAGFILE = @CMAKE_DOXYGEN_OUTPUT_PATH@/html/opencv.tag ALLEXTERNALS = NO EXTERNAL_GROUPS = YES EXTERNAL_PAGES = YES -PERL_PATH = /usr/bin/perl CLASS_DIAGRAMS = YES -MSCGEN_PATH = DIA_PATH = HIDE_UNDOC_RELATIONS = NO HAVE_DOT = NO diff --git a/doc/js_tutorials/js_video/js_meanshift/images/camshift_face.gif b/doc/images/camshift_face.gif similarity index 100% rename from doc/js_tutorials/js_video/js_meanshift/images/camshift_face.gif rename to doc/images/camshift_face.gif diff --git a/doc/tutorials/video/meanshift/images/camshift_result.jpg b/doc/images/camshift_result.jpg similarity index 100% rename from doc/tutorials/video/meanshift/images/camshift_result.jpg rename to doc/images/camshift_result.jpg diff --git a/doc/js_tutorials/js_video/js_meanshift/images/meanshift_basics.jpg b/doc/images/meanshift_basics.jpg similarity index 100% rename from doc/js_tutorials/js_video/js_meanshift/images/meanshift_basics.jpg rename to doc/images/meanshift_basics.jpg diff --git a/doc/js_tutorials/js_video/js_meanshift/images/meanshift_face.gif b/doc/images/meanshift_face.gif similarity index 100% rename from doc/js_tutorials/js_video/js_meanshift/images/meanshift_face.gif rename to doc/images/meanshift_face.gif diff --git a/doc/tutorials/video/meanshift/images/meanshift_result.jpg b/doc/images/meanshift_result.jpg similarity index 100% rename from doc/tutorials/video/meanshift/images/meanshift_result.jpg rename to doc/images/meanshift_result.jpg diff --git a/doc/js_tutorials/js_video/js_lucas_kanade/images/optical_flow_basic1.jpg b/doc/images/optical_flow_basic1.jpg similarity index 100% rename from doc/js_tutorials/js_video/js_lucas_kanade/images/optical_flow_basic1.jpg rename to doc/images/optical_flow_basic1.jpg diff --git a/doc/tutorials/video/optical_flow/images/opticalfb.jpg b/doc/images/opticalfb.jpg similarity index 100% rename from doc/tutorials/video/optical_flow/images/opticalfb.jpg rename to doc/images/opticalfb.jpg diff --git a/doc/tutorials/video/optical_flow/images/opticalflow_lk.jpg b/doc/images/opticalflow_lk.jpg similarity index 100% rename from doc/tutorials/video/optical_flow/images/opticalflow_lk.jpg rename to doc/images/opticalflow_lk.jpg diff --git a/doc/tutorials/introduction/desktop_java/images/lena.png b/doc/tutorials/introduction/desktop_java/images/lena.png deleted file mode 100644 index 68342fae53..0000000000 Binary files a/doc/tutorials/introduction/desktop_java/images/lena.png and /dev/null differ diff --git a/doc/tutorials/introduction/display_image/images/Display_Image_Tutorial_Result.jpg b/doc/tutorials/introduction/display_image/images/Display_Image_Tutorial_Result.jpg deleted file mode 100644 index 16400698f0..0000000000 Binary files a/doc/tutorials/introduction/display_image/images/Display_Image_Tutorial_Result.jpg and /dev/null differ diff --git a/doc/tutorials/introduction/images/Display_Image_Tutorial_Result.jpg b/doc/tutorials/introduction/images/Display_Image_Tutorial_Result.jpg index 9c646e21ae..16400698f0 100644 Binary files a/doc/tutorials/introduction/images/Display_Image_Tutorial_Result.jpg and b/doc/tutorials/introduction/images/Display_Image_Tutorial_Result.jpg differ diff --git a/doc/tutorials/introduction/images/Load_Save_Image_Result_1.jpg b/doc/tutorials/introduction/images/Load_Save_Image_Result_1.jpg index 5b8fc982ce..fcc7afa4e3 100644 Binary files a/doc/tutorials/introduction/images/Load_Save_Image_Result_1.jpg and b/doc/tutorials/introduction/images/Load_Save_Image_Result_1.jpg differ diff --git a/doc/tutorials/introduction/load_save_image/images/Load_Save_Image_Result_2.jpg b/doc/tutorials/introduction/images/Load_Save_Image_Result_2.jpg similarity index 100% rename from doc/tutorials/introduction/load_save_image/images/Load_Save_Image_Result_2.jpg rename to doc/tutorials/introduction/images/Load_Save_Image_Result_2.jpg diff --git a/doc/tutorials/introduction/clojure_dev_intro/images/lena.png b/doc/tutorials/introduction/images/lena.png similarity index 100% rename from doc/tutorials/introduction/clojure_dev_intro/images/lena.png rename to doc/tutorials/introduction/images/lena.png diff --git a/doc/tutorials/introduction/load_save_image/images/Load_Save_Image_Result_1.jpg b/doc/tutorials/introduction/load_save_image/images/Load_Save_Image_Result_1.jpg deleted file mode 100644 index fcc7afa4e3..0000000000 Binary files a/doc/tutorials/introduction/load_save_image/images/Load_Save_Image_Result_1.jpg and /dev/null differ diff --git a/doc/tutorials/ios/hello/hello.markdown b/doc/tutorials/ios/hello/hello.markdown index 5a499c3091..44f14adb12 100644 --- a/doc/tutorials/ios/hello/hello.markdown +++ b/doc/tutorials/ios/hello/hello.markdown @@ -50,7 +50,7 @@ Now we will learn how to write a simple Hello World Application in Xcode using O Output ------ -![](images/output.png) +![](images/ios_hello_output.png) Changes for XCode5+ and iOS8+ ----------------------------- diff --git a/doc/tutorials/ios/hello/images/output.png b/doc/tutorials/ios/hello/images/ios_hello_output.png similarity index 100% rename from doc/tutorials/ios/hello/images/output.png rename to doc/tutorials/ios/hello/images/ios_hello_output.png diff --git a/doc/tutorials/ml/introduction_to_pca/images/output.png b/doc/tutorials/ml/introduction_to_pca/images/pca_output.png similarity index 100% rename from doc/tutorials/ml/introduction_to_pca/images/output.png rename to doc/tutorials/ml/introduction_to_pca/images/pca_output.png diff --git a/doc/tutorials/ml/introduction_to_pca/introduction_to_pca.markdown b/doc/tutorials/ml/introduction_to_pca/introduction_to_pca.markdown index 63ab1eeb1a..02f2d16ea9 100644 --- a/doc/tutorials/ml/introduction_to_pca/introduction_to_pca.markdown +++ b/doc/tutorials/ml/introduction_to_pca/introduction_to_pca.markdown @@ -205,4 +205,4 @@ The code opens an image, finds the orientation of the detected objects of intere ![](images/pca_test1.jpg) -![](images/output.png) +![](images/pca_output.png) diff --git a/doc/tutorials/video/meanshift/images/camshift_face.gif b/doc/tutorials/video/meanshift/images/camshift_face.gif deleted file mode 100644 index d46e1c7915..0000000000 Binary files a/doc/tutorials/video/meanshift/images/camshift_face.gif and /dev/null differ diff --git a/doc/tutorials/video/meanshift/images/meanshift_basics.jpg b/doc/tutorials/video/meanshift/images/meanshift_basics.jpg deleted file mode 100644 index 73e513fb14..0000000000 Binary files a/doc/tutorials/video/meanshift/images/meanshift_basics.jpg and /dev/null differ diff --git a/doc/tutorials/video/meanshift/images/meanshift_face.gif b/doc/tutorials/video/meanshift/images/meanshift_face.gif deleted file mode 100644 index 6f9733146e..0000000000 Binary files a/doc/tutorials/video/meanshift/images/meanshift_face.gif and /dev/null differ diff --git a/doc/tutorials/video/optical_flow/images/optical_flow_basic1.jpg b/doc/tutorials/video/optical_flow/images/optical_flow_basic1.jpg deleted file mode 100644 index 718d83c10b..0000000000 Binary files a/doc/tutorials/video/optical_flow/images/optical_flow_basic1.jpg and /dev/null differ diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 1e25089ce8..ff9fa36232 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -73,8 +73,10 @@ @defgroup core_cluster Clustering @defgroup core_utils Utility and system functions and macros @{ + @defgroup core_logging Logging facilities @defgroup core_utils_sse SSE utilities @defgroup core_utils_neon NEON utilities + @defgroup core_utils_vsx VSX utilities @defgroup core_utils_softfloat Softfloat support @defgroup core_utils_samples Utility functions for OpenCV samples @} diff --git a/modules/core/include/opencv2/core/hal/intrin_vsx.hpp b/modules/core/include/opencv2/core/hal/intrin_vsx.hpp index b770e95d3f..5e417a00bf 100644 --- a/modules/core/include/opencv2/core/hal/intrin_vsx.hpp +++ b/modules/core/include/opencv2/core/hal/intrin_vsx.hpp @@ -1039,6 +1039,15 @@ inline v_float64x2 v_cvt_f64(const v_float32x4& a) inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) { return v_float64x2(vec_cvfo(vec_mergel(a.val, a.val))); } +// The altivec intrinsic is missing for this 2.06 insn +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ +vec_double2 out; + +__asm__ ("xvcvsxddp %x0,%x1" : "=wa"(out) : "wa"(a.val)); +return v_float64x2(out); +} + ////////////// Lookup table access //////////////////// inline v_int8x16 v_lut(const schar* tab, const int* idx) diff --git a/modules/core/include/opencv2/core/softfloat.hpp b/modules/core/include/opencv2/core/softfloat.hpp index 547098038d..485e15c473 100644 --- a/modules/core/include/opencv2/core/softfloat.hpp +++ b/modules/core/include/opencv2/core/softfloat.hpp @@ -507,8 +507,8 @@ Special cases: */ CV_EXPORTS softdouble cos( const softdouble& a ); -} +//! @} core_utils_softfloat -//! @} +} // cv:: #endif diff --git a/modules/core/include/opencv2/core/utils/logger.hpp b/modules/core/include/opencv2/core/utils/logger.hpp index b00a552bfb..bf73d9ac51 100644 --- a/modules/core/include/opencv2/core/utils/logger.hpp +++ b/modules/core/include/opencv2/core/utils/logger.hpp @@ -12,15 +12,13 @@ #include "logger.defines.hpp" #include "logtag.hpp" -//! @addtogroup core_logging -// This section describes OpenCV logging utilities. -// -//! @{ - namespace cv { namespace utils { namespace logging { +//! @addtogroup core_logging +//! @{ + /** Set global logging level @return previous logging level */ @@ -148,8 +146,8 @@ struct LogTagAuto # define CV_LOG_VERBOSE(tag, v, ...) #endif -}}} // namespace - //! @} +}}} // namespace + #endif // OPENCV_LOGGER_HPP diff --git a/modules/core/include/opencv2/core/utils/trace.hpp b/modules/core/include/opencv2/core/utils/trace.hpp index 858e973a83..ef5d35b4f2 100644 --- a/modules/core/include/opencv2/core/utils/trace.hpp +++ b/modules/core/include/opencv2/core/utils/trace.hpp @@ -7,15 +7,13 @@ #include -//! @addtogroup core_logging -// This section describes OpenCV tracing utilities. -// -//! @{ - namespace cv { namespace utils { namespace trace { +//! @addtogroup core_logging +//! @{ + //! Macro to trace function #define CV_TRACE_FUNCTION() @@ -247,8 +245,8 @@ CV_EXPORTS void traceArg(const TraceArg& arg, double value); //! @endcond -}}} // namespace - //! @} +}}} // namespace + #endif // OPENCV_TRACE_HPP diff --git a/modules/core/src/matmul.simd.hpp b/modules/core/src/matmul.simd.hpp index bb6b6c55d5..fcc88a120d 100644 --- a/modules/core/src/matmul.simd.hpp +++ b/modules/core/src/matmul.simd.hpp @@ -2493,7 +2493,36 @@ double dotProd_16s(const short* src1, const short* src2, int len) double dotProd_32s(const int* src1, const int* src2, int len) { +#if CV_SIMD128_64F + double r = 0.0; + int i = 0; + int lenAligned = len & -v_int32x4::nlanes; + v_float64x2 a(0.0, 0.0); + v_float64x2 b(0.0, 0.0); + + for( i = 0; i < lenAligned; i += v_int32x4::nlanes ) + { + v_int32x4 s1 = v_load(src1); + v_int32x4 s2 = v_load(src2); + +#if CV_VSX + // Do 32x32->64 multiplies, convert/round to double, accumulate + // Potentially less precise than FMA, but 1.5x faster than fma below. + a += v_cvt_f64(v_int64(vec_mule(s1.val, s2.val))); + b += v_cvt_f64(v_int64(vec_mulo(s1.val, s2.val))); +#else + a = v_fma(v_cvt_f64(s1), v_cvt_f64(s2), a); + b = v_fma(v_cvt_f64_high(s1), v_cvt_f64_high(s2), b); +#endif + src1 += v_int32x4::nlanes; + src2 += v_int32x4::nlanes; + } + a += b; + r = v_reduce_sum(a); + return r + dotProd_(src1, src2, len - i); +#else return dotProd_(src1, src2, len); +#endif } double dotProd_32f(const float* src1, const float* src2, int len) diff --git a/modules/core/src/norm.cpp b/modules/core/src/norm.cpp index d3eec98e38..0e06bff4d1 100644 --- a/modules/core/src/norm.cpp +++ b/modules/core/src/norm.cpp @@ -63,7 +63,31 @@ int normHamming(const uchar* a, int n, int cellSize) return -1; int i = 0; int result = 0; -#if CV_ENABLE_UNROLLED +#if CV_SIMD + v_uint64 t = vx_setzero_u64(); + if ( cellSize == 2) + { + v_uint16 mask = v_reinterpret_as_u16(vx_setall_u8(0x55)); + for(; i <= n - v_uint8::nlanes; i += v_uint8::nlanes) + { + v_uint16 a0 = v_reinterpret_as_u16(vx_load(a + i)); + t += v_popcount(v_reinterpret_as_u64((a0 | (a0 >> 1)) & mask)); + } + } + else // cellSize == 4 + { + v_uint16 mask = v_reinterpret_as_u16(vx_setall_u8(0x11)); + for(; i <= n - v_uint8::nlanes; i += v_uint8::nlanes) + { + v_uint16 a0 = v_reinterpret_as_u16(vx_load(a + i)); + v_uint16 a1 = a0 | (a0 >> 2); + t += v_popcount(v_reinterpret_as_u64((a1 | (a1 >> 1)) & mask)); + + } + } + result += (int)v_reduce_sum(t); + vx_cleanup(); +#elif CV_ENABLE_UNROLLED for( ; i <= n - 4; i += 4 ) result += tab[a[i]] + tab[a[i+1]] + tab[a[i+2]] + tab[a[i+3]]; #endif @@ -85,7 +109,30 @@ int normHamming(const uchar* a, const uchar* b, int n, int cellSize) return -1; int i = 0; int result = 0; -#if CV_ENABLE_UNROLLED +#if CV_SIMD + v_uint64 t = vx_setzero_u64(); + if ( cellSize == 2) + { + v_uint16 mask = v_reinterpret_as_u16(vx_setall_u8(0x55)); + for(; i <= n - v_uint8::nlanes; i += v_uint8::nlanes) + { + v_uint16 ab0 = v_reinterpret_as_u16(vx_load(a + i) ^ vx_load(b + i)); + t += v_popcount(v_reinterpret_as_u64((ab0 | (ab0 >> 1)) & mask)); + } + } + else // cellSize == 4 + { + v_uint16 mask = v_reinterpret_as_u16(vx_setall_u8(0x11)); + for(; i <= n - v_uint8::nlanes; i += v_uint8::nlanes) + { + v_uint16 ab0 = v_reinterpret_as_u16(vx_load(a + i) ^ vx_load(b + i)); + v_uint16 ab1 = ab0 | (ab0 >> 2); + t += v_popcount(v_reinterpret_as_u64((ab1 | (ab1 >> 1)) & mask)); + } + } + result += (int)v_reduce_sum(t); + vx_cleanup(); +#elif CV_ENABLE_UNROLLED for( ; i <= n - 4; i += 4 ) result += tab[a[i] ^ b[i]] + tab[a[i+1] ^ b[i+1]] + tab[a[i+2] ^ b[i+2]] + tab[a[i+3] ^ b[i+3]]; @@ -99,13 +146,20 @@ float normL2Sqr_(const float* a, const float* b, int n) { int j = 0; float d = 0.f; #if CV_SIMD - v_float32 v_d = vx_setzero_f32(); - for (; j <= n - v_float32::nlanes; j += v_float32::nlanes) + v_float32 v_d0 = vx_setzero_f32(), v_d1 = vx_setzero_f32(); + v_float32 v_d2 = vx_setzero_f32(), v_d3 = vx_setzero_f32(); + for (; j <= n - 4 * v_float32::nlanes; j += 4 * v_float32::nlanes) { - v_float32 t = vx_load(a + j) - vx_load(b + j); - v_d = v_muladd(t, t, v_d); + v_float32 t0 = vx_load(a + j) - vx_load(b + j); + v_float32 t1 = vx_load(a + j + v_float32::nlanes) - vx_load(b + j + v_float32::nlanes); + v_float32 t2 = vx_load(a + j + 2 * v_float32::nlanes) - vx_load(b + j + 2 * v_float32::nlanes); + v_float32 t3 = vx_load(a + j + 3 * v_float32::nlanes) - vx_load(b + j + 3 * v_float32::nlanes); + v_d0 = v_muladd(t0, t0, v_d0); + v_d1 = v_muladd(t1, t1, v_d1); + v_d2 = v_muladd(t2, t2, v_d2); + v_d3 = v_muladd(t3, t3, v_d3); } - d = v_reduce_sum(v_d); + d = v_reduce_sum(v_d0 + v_d1 + v_d2 + v_d3); #endif for( ; j < n; j++ ) { @@ -120,10 +174,16 @@ float normL1_(const float* a, const float* b, int n) { int j = 0; float d = 0.f; #if CV_SIMD - v_float32 v_d = vx_setzero_f32(); - for (; j <= n - v_float32::nlanes; j += v_float32::nlanes) - v_d += v_absdiff(vx_load(a + j), vx_load(b + j)); - d = v_reduce_sum(v_d); + v_float32 v_d0 = vx_setzero_f32(), v_d1 = vx_setzero_f32(); + v_float32 v_d2 = vx_setzero_f32(), v_d3 = vx_setzero_f32(); + for (; j <= n - 4 * v_float32::nlanes; j += 4 * v_float32::nlanes) + { + v_d0 += v_absdiff(vx_load(a + j), vx_load(b + j)); + v_d1 += v_absdiff(vx_load(a + j + v_float32::nlanes), vx_load(b + j + v_float32::nlanes)); + v_d2 += v_absdiff(vx_load(a + j + 2 * v_float32::nlanes), vx_load(b + j + 2 * v_float32::nlanes)); + v_d3 += v_absdiff(vx_load(a + j + 3 * v_float32::nlanes), vx_load(b + j + 3 * v_float32::nlanes)); + } + d = v_reduce_sum(v_d0 + v_d1 + v_d2 + v_d3); #endif for( ; j < n; j++ ) d += std::abs(a[j] - b[j]); @@ -134,8 +194,11 @@ int normL1_(const uchar* a, const uchar* b, int n) { int j = 0, d = 0; #if CV_SIMD - for (; j <= n - v_uint8::nlanes; j += v_uint8::nlanes) - d += v_reduce_sad(vx_load(a + j), vx_load(b + j)); + for (; j <= n - 4 * v_uint8::nlanes; j += 4 * v_uint8::nlanes) + d += v_reduce_sad(vx_load(a + j), vx_load(b + j)) + + v_reduce_sad(vx_load(a + j + v_uint8::nlanes), vx_load(b + j + v_uint8::nlanes)) + + v_reduce_sad(vx_load(a + j + 2 * v_uint8::nlanes), vx_load(b + j + 2 * v_uint8::nlanes)) + + v_reduce_sad(vx_load(a + j + 3 * v_uint8::nlanes), vx_load(b + j + 3 * v_uint8::nlanes)); #endif for( ; j < n; j++ ) d += std::abs(a[j] - b[j]); diff --git a/modules/core/src/opencl/fft.cl b/modules/core/src/opencl/fft.cl index d9dfbb7c6a..08f844acbd 100644 --- a/modules/core/src/opencl/fft.cl +++ b/modules/core/src/opencl/fft.cl @@ -536,9 +536,9 @@ __kernel void fft_multi_radix_rows(__global const uchar* src_ptr, int src_step, const int x = get_global_id(0); const int y = get_group_id(1); const int block_size = LOCAL_SIZE/kercn; + __local CT smem[LOCAL_SIZE]; // used in (y < nz) code branch only, but should be declared in the outermost scope of a kernel function if (y < nz) { - __local CT smem[LOCAL_SIZE]; __global const CT* twiddles = (__global const CT*)(twiddles_ptr + twiddles_offset); const int ind = x; #ifdef IS_1D @@ -615,9 +615,9 @@ __kernel void fft_multi_radix_cols(__global const uchar* src_ptr, int src_step, const int x = get_group_id(0); const int y = get_global_id(1); + __local CT smem[LOCAL_SIZE]; // used in (x < nz) code branch only, but should be declared in the outermost scope of a kernel function if (x < nz) { - __local CT smem[LOCAL_SIZE]; __global const uchar* src = src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(CT)), src_offset)); __global const CT* twiddles = (__global const CT*)(twiddles_ptr + twiddles_offset); const int ind = y; @@ -682,9 +682,9 @@ __kernel void ifft_multi_radix_rows(__global const uchar* src_ptr, int src_step, const FT scale = (FT) 1/(dst_cols*dst_rows); #endif + __local CT smem[LOCAL_SIZE]; // used in (y < nz) code branch only, but should be declared in the outermost scope of a kernel function if (y < nz) { - __local CT smem[LOCAL_SIZE]; __global const CT* twiddles = (__global const CT*)(twiddles_ptr + twiddles_offset); const int ind = x; @@ -782,10 +782,10 @@ __kernel void ifft_multi_radix_cols(__global const uchar* src_ptr, int src_step, const int x = get_group_id(0); const int y = get_global_id(1); -#ifdef COMPLEX_INPUT + __local CT smem[LOCAL_SIZE]; // used in (x < nz) code branch only, but should be declared in the outermost scope of a kernel function if (x < nz) { - __local CT smem[LOCAL_SIZE]; +#ifdef COMPLEX_INPUT __global const uchar* src = src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(CT)), src_offset)); __global uchar* dst = dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(CT)), dst_offset)); __global const CT* twiddles = (__global const CT*)(twiddles_ptr + twiddles_offset); @@ -812,15 +812,11 @@ __kernel void ifft_multi_radix_cols(__global const uchar* src_ptr, int src_step, res[0].x = smem[y + i*block_size].x; res[0].y = -smem[y + i*block_size].y; } - } #else - if (x < nz) - { __global const CT* twiddles = (__global const CT*)(twiddles_ptr + twiddles_offset); const int ind = y; const int block_size = LOCAL_SIZE/kercn; - __local CT smem[LOCAL_SIZE]; #ifdef EVEN if (x!=0 && (x!=(nz-1))) #else @@ -877,6 +873,6 @@ __kernel void ifft_multi_radix_cols(__global const uchar* src_ptr, int src_step, res[0].x = smem[y + i*block_size].x; res[0].y = -smem[y + i*block_size].y; } - } #endif -} \ No newline at end of file + } +} diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index 9885e4d647..db2385a258 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -155,7 +155,7 @@ static void* WinGetProcAddress(const char* name) #define CV_CL_GET_PROC_ADDRESS(name) WinGetProcAddress(name) #endif // _WIN32 -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include #include diff --git a/modules/core/src/stat.simd.hpp b/modules/core/src/stat.simd.hpp index b8ae15dc91..0592f84794 100644 --- a/modules/core/src/stat.simd.hpp +++ b/modules/core/src/stat.simd.hpp @@ -39,6 +39,7 @@ int normHamming(const uchar* a, int n) for (; i <= n - v_uint8::nlanes; i += v_uint8::nlanes) t += v_popcount(v_reinterpret_as_u64(vx_load(a + i))); result = (int)v_reduce_sum(t); + vx_cleanup(); } #endif diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index f2a3a7bf08..bad1e59b0d 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -1619,11 +1619,37 @@ struct Net::Impl Ptr layer = ld.layerInstance; if (!fused && !layer->supportBackend(preferableBackend)) { - addInfEngineNetOutputs(ld); - net = Ptr(); - netBlobsWrappers.clear(); // Is not used for R5 release but we don't wrap it to #ifdef. - layer->preferableTarget = DNN_TARGET_CPU; - continue; + bool customizable = ld.id != 0 && ld.outputBlobs.size() == 1; + // TODO: there is a bug in Myriad plugin with custom layers shape infer. + if (preferableTarget == DNN_TARGET_MYRIAD) + { + for (int i = 0; customizable && i < ld.inputBlobs.size(); ++i) + { + customizable = ld.inputBlobs[i]->size[0] == 1; + } + } + + // TODO: fix these workarounds + if (preferableTarget == DNN_TARGET_MYRIAD || + preferableTarget == DNN_TARGET_OPENCL || + preferableTarget == DNN_TARGET_OPENCL_FP16) + customizable &= ld.type != "Concat"; + + if (preferableTarget == DNN_TARGET_OPENCL || + preferableTarget == DNN_TARGET_OPENCL_FP16) + customizable &= ld.type != "Power"; + + if (preferableTarget == DNN_TARGET_OPENCL) + customizable &= ld.type != "Eltwise"; + + if (!customizable) + { + addInfEngineNetOutputs(ld); + net = Ptr(); + netBlobsWrappers.clear(); // Is not used for R5 release but we don't wrap it to #ifdef. + layer->preferableTarget = DNN_TARGET_CPU; + continue; + } } ld.skip = true; // Initially skip all Inference Engine supported layers. @@ -1662,7 +1688,13 @@ struct Net::Impl if (!fused) { - node = layer->initInfEngine(ld.inputBlobsWrappers); + if (layer->supportBackend(preferableBackend)) + node = layer->initInfEngine(ld.inputBlobsWrappers); + else + { + node = Ptr(new InfEngineBackendNode( + ld.layerInstance, ld.inputBlobs, ld.outputBlobs, ld.internals)); + } } else if (node.empty()) continue; diff --git a/modules/dnn/src/layers/const_layer.cpp b/modules/dnn/src/layers/const_layer.cpp index 339f2ec255..7a33d6ec84 100644 --- a/modules/dnn/src/layers/const_layer.cpp +++ b/modules/dnn/src/layers/const_layer.cpp @@ -6,6 +6,7 @@ // Third party copyrights are property of their respective owners. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" #include "layers_common.hpp" #ifdef HAVE_OPENCL @@ -23,6 +24,11 @@ public: CV_Assert(blobs.size() == 1); } + virtual bool supportBackend(int backendId) CV_OVERRIDE + { + return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_INFERENCE_ENGINE; + } + virtual bool getMemoryShapes(const std::vector &inputs, const int requiredOutputs, std::vector &outputs, @@ -58,6 +64,15 @@ public: outputs_arr.getMatVector(outputs); blobs[0].copyTo(outputs[0]); } + +#ifdef HAVE_INF_ENGINE + virtual Ptr initInfEngine(const std::vector >&) CV_OVERRIDE + { + InferenceEngine::Builder::ConstLayer ieLayer(name); + ieLayer.setData(wrapToInfEngineBlob(blobs[0])); + return Ptr(new InfEngineBackendNode(ieLayer)); + } +#endif // HAVE_INF_ENGINE }; Ptr ConstLayer::create(const LayerParams& params) diff --git a/modules/dnn/src/layers/crop_and_resize_layer.cpp b/modules/dnn/src/layers/crop_and_resize_layer.cpp index 4596b4721f..de87107d43 100644 --- a/modules/dnn/src/layers/crop_and_resize_layer.cpp +++ b/modules/dnn/src/layers/crop_and_resize_layer.cpp @@ -14,6 +14,7 @@ class CropAndResizeLayerImpl CV_FINAL : public CropAndResizeLayer public: CropAndResizeLayerImpl(const LayerParams& params) { + setParamsFrom(params); CV_Assert_N(params.has("width"), params.has("height")); outWidth = params.get("width"); outHeight = params.get("height"); diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index a0496d2303..6734243b3b 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -927,7 +927,7 @@ public: ieLayer.setShareLocation(_shareLocation); ieLayer.setBackgroudLabelId(_backgroundLabelId); ieLayer.setNMSThreshold(_nmsThreshold); - ieLayer.setTopK(_topK); + ieLayer.setTopK(_topK > 0 ? _topK : _keepTopK); ieLayer.setKeepTopK(_keepTopK); ieLayer.setConfidenceThreshold(_confidenceThreshold); ieLayer.setVariantEncodedInTarget(_varianceEncodedInTarget); diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index 9c7b7566fe..6b4225b9d3 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -25,10 +25,186 @@ namespace cv { namespace dnn { // OpenCV lets users use an empty input name and to prevent unexpected naming, // we can use some predefined name. static std::string kDefaultInpLayerName = "empty_inp_layer_name"; +static std::string kOpenCVLayersType = "OpenCVLayer"; + +static std::string shapesToStr(const std::vector& mats) +{ + std::ostringstream shapes; + shapes << mats.size() << " "; + for (const Mat& m : mats) + { + shapes << m.dims << " "; + for (int i = 0; i < m.dims; ++i) + shapes << m.size[i] << " "; + } + return shapes.str(); +} + +static void strToShapes(const std::string& str, std::vector >& shapes) +{ + std::istringstream ss(str); + int num, dims; + ss >> num; + shapes.resize(num); + for (int i = 0; i < num; ++i) + { + ss >> dims; + shapes[i].resize(dims); + for (int j = 0; j < dims; ++j) + ss >> shapes[i][j]; + } +} + +class InfEngineCustomLayer : public InferenceEngine::ILayerExecImpl +{ +public: + explicit InfEngineCustomLayer(const InferenceEngine::CNNLayer& layer) : cnnLayer(layer) + { + std::istringstream iss(layer.GetParamAsString("impl")); + size_t ptr; + iss >> ptr; + cvLayer = (Layer*)ptr; + + std::vector > shapes; + strToShapes(layer.GetParamAsString("internals"), shapes); + internals.resize(shapes.size()); + for (int i = 0; i < shapes.size(); ++i) + internals[i].create(std::vector(shapes[i].begin(), shapes[i].end()), CV_32F); + } + + virtual InferenceEngine::StatusCode execute(std::vector& inputs, + std::vector& outputs, + InferenceEngine::ResponseDesc *resp) noexcept + { + std::vector inpMats, outMats; + infEngineBlobsToMats(inputs, inpMats); + infEngineBlobsToMats(outputs, outMats); + + try + { + cvLayer->forward(inpMats, outMats, internals); + return InferenceEngine::StatusCode::OK; + } + catch (...) + { + return InferenceEngine::StatusCode::GENERAL_ERROR; + } + } + + virtual InferenceEngine::StatusCode + getSupportedConfigurations(std::vector& conf, + InferenceEngine::ResponseDesc* resp) noexcept + { + std::vector inDataConfig; + std::vector outDataConfig; + for (auto& it : cnnLayer.insData) + { + InferenceEngine::DataConfig conf; + conf.desc = it.lock()->getTensorDesc(); + inDataConfig.push_back(conf); + } + + for (auto& it : cnnLayer.outData) + { + InferenceEngine::DataConfig conf; + conf.desc = it->getTensorDesc(); + outDataConfig.push_back(conf); + } + + InferenceEngine::LayerConfig layerConfig; + layerConfig.inConfs = inDataConfig; + layerConfig.outConfs = outDataConfig; + + conf.push_back(layerConfig); + return InferenceEngine::StatusCode::OK; + } + + InferenceEngine::StatusCode init(InferenceEngine::LayerConfig& config, + InferenceEngine::ResponseDesc *resp) noexcept + { + return InferenceEngine::StatusCode::OK; + } + +private: + InferenceEngine::CNNLayer cnnLayer; + dnn::Layer* cvLayer; + std::vector internals; +}; + +class InfEngineCustomLayerShapeInfer : public InferenceEngine::IShapeInferImpl +{ +public: + InferenceEngine::StatusCode + inferShapes(const std::vector& inBlobs, + const std::map& params, + const std::map& blobs, + std::vector& outShapes, + InferenceEngine::ResponseDesc* desc) noexcept override + { + strToShapes(params.at("outputs"), outShapes); + return InferenceEngine::StatusCode::OK; + } +}; + +class InfEngineCustomLayerFactory : public InferenceEngine::ILayerImplFactory { +public: + explicit InfEngineCustomLayerFactory(const InferenceEngine::CNNLayer* layer) : cnnLayer(*layer) {} + + InferenceEngine::StatusCode + getImplementations(std::vector& impls, + InferenceEngine::ResponseDesc* resp) noexcept override { + impls.push_back(std::make_shared(cnnLayer)); + return InferenceEngine::StatusCode::OK; + } + +private: + InferenceEngine::CNNLayer cnnLayer; +}; + +class InfEngineExtension : public InferenceEngine::IExtension +{ +public: + virtual void SetLogCallback(InferenceEngine::IErrorListener&) noexcept {} + virtual void Unload() noexcept {} + virtual void Release() noexcept {} + virtual void GetVersion(const InferenceEngine::Version*&) const noexcept {} + + virtual InferenceEngine::StatusCode getPrimitiveTypes(char**&, unsigned int&, + InferenceEngine::ResponseDesc*) noexcept + { + return InferenceEngine::StatusCode::OK; + } + + InferenceEngine::StatusCode getFactoryFor(InferenceEngine::ILayerImplFactory*& factory, + const InferenceEngine::CNNLayer* cnnLayer, + InferenceEngine::ResponseDesc* resp) noexcept + { + if (cnnLayer->type != kOpenCVLayersType) + return InferenceEngine::StatusCode::NOT_IMPLEMENTED; + factory = new InfEngineCustomLayerFactory(cnnLayer); + return InferenceEngine::StatusCode::OK; + } +}; InfEngineBackendNode::InfEngineBackendNode(const InferenceEngine::Builder::Layer& _layer) : BackendNode(DNN_BACKEND_INFERENCE_ENGINE), layer(_layer) {} + InfEngineBackendNode::InfEngineBackendNode(Ptr& cvLayer_, std::vector& inputs, + std::vector& outputs, + std::vector& internals) + : BackendNode(DNN_BACKEND_INFERENCE_ENGINE), layer(cvLayer_->name), + cvLayer(cvLayer_) +{ + CV_Assert(!cvLayer->name.empty()); + layer.setName(cvLayer->name); + layer.setType(kOpenCVLayersType); + layer.getParameters()["impl"] = (size_t)cvLayer.get(); + layer.getParameters()["outputs"] = shapesToStr(outputs); + layer.getParameters()["internals"] = shapesToStr(internals); + layer.setInputPorts(std::vector(inputs.size())); + layer.setOutputPorts(std::vector(outputs.size())); +} + static std::vector > infEngineWrappers(const std::vector >& ptrs) { @@ -111,6 +287,8 @@ void InfEngineBackendNet::init(int targetId) #endif netBuilder.addLayer({InferenceEngine::PortInfo(id)}, outLayer); } + netBuilder.getContext().addShapeInferImpl(kOpenCVLayersType, + std::make_shared()); cnn = InferenceEngine::CNNNetwork(InferenceEngine::Builder::convertToICNNNetwork(netBuilder.build())); } @@ -404,6 +582,7 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net) try { AutoLock lock(getInitializationMutex()); + InferenceEngine::Core& ie = getCore(); #if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1) auto& sharedPlugins = getSharedPlugins(); auto pluginIt = sharedPlugins.find(device_name); @@ -465,7 +644,9 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net) #if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1) enginePtr->AddExtension(extension, 0); #else - getCore().AddExtension(extension, "CPU"); + ie.AddExtension(extension, "CPU"); + // OpenCV fallbacks as extensions. + ie.AddExtension(std::make_shared(), "CPU"); #endif CV_LOG_INFO(NULL, "DNN-IE: Loaded extension plugin: " << libName); found = true; @@ -486,7 +667,7 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net) }}, 0); #else if (device_name == "CPU") - getCore().SetConfig({{ + ie.SetConfig({{ InferenceEngine::PluginConfigParams::KEY_CPU_THREADS_NUM, format("%d", getNumThreads()), }}, device_name); #endif @@ -496,7 +677,25 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net) plugin = InferenceEngine::InferencePlugin(enginePtr); netExec = plugin.LoadNetwork(net, {}); #else - netExec = getCore().LoadNetwork(net, device_name); + bool isHetero = false; + if (device_name != "CPU") + { + isHetero = device_name == "FPGA"; + for (auto& layer : net) + { + if (layer->type == kOpenCVLayersType) + { + layer->affinity = "CPU"; + isHetero = true; + } + else + layer->affinity = device_name; + } + } + if (isHetero) + netExec = ie.LoadNetwork(net, "HETERO:" + device_name + ",CPU"); + else + netExec = ie.LoadNetwork(net, device_name); #endif } catch (const std::exception& ex) @@ -673,6 +872,14 @@ Mat infEngineBlobToMat(const InferenceEngine::Blob::Ptr& blob) return Mat(size, type, (void*)blob->buffer()); } +void infEngineBlobsToMats(const std::vector& blobs, + std::vector& mats) +{ + mats.resize(blobs.size()); + for (int i = 0; i < blobs.size(); ++i) + mats[i] = infEngineBlobToMat(blobs[i]); +} + bool InfEngineBackendLayer::getMemoryShapes(const std::vector &inputs, const int requiredOutputs, std::vector &outputs, @@ -770,7 +977,8 @@ void resetMyriadDevice() #if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1) getSharedPlugins().erase("MYRIAD"); #else - getCore().UnregisterPlugin("MYRIAD"); + // To unregister both "MYRIAD" and "HETERO:MYRIAD,CPU" plugins + getCore() = InferenceEngine::Core(); #endif #endif // HAVE_INF_ENGINE } diff --git a/modules/dnn/src/op_inf_engine.hpp b/modules/dnn/src/op_inf_engine.hpp index 39613bd126..4f195fdd37 100644 --- a/modules/dnn/src/op_inf_engine.hpp +++ b/modules/dnn/src/op_inf_engine.hpp @@ -137,12 +137,17 @@ class InfEngineBackendNode : public BackendNode public: InfEngineBackendNode(const InferenceEngine::Builder::Layer& layer); + InfEngineBackendNode(Ptr& layer, std::vector& inputs, + std::vector& outputs, std::vector& internals); + void connect(std::vector >& inputs, std::vector >& outputs); // Inference Engine network object that allows to obtain the outputs of this layer. InferenceEngine::Builder::Layer layer; Ptr net; + // CPU fallback in case of unsupported Inference Engine layer. + Ptr cvLayer; }; class InfEngineBackendWrapper : public BackendWrapper @@ -173,6 +178,9 @@ InferenceEngine::DataPtr infEngineDataNode(const Ptr& ptr); Mat infEngineBlobToMat(const InferenceEngine::Blob::Ptr& blob); +void infEngineBlobsToMats(const std::vector& blobs, + std::vector& mats); + // Convert Inference Engine blob with FP32 precision to FP16 precision. // Allocates memory for a new blob. InferenceEngine::Blob::Ptr convertFp16(const InferenceEngine::Blob::Ptr& blob); diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 9a575723cd..10fb8fdb2e 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -53,17 +53,6 @@ static std::string _tf(TString filename) return (getOpenCVExtraDir() + "/dnn/") + filename; } -static std::vector getOutputsNames(const Net& net) -{ - std::vector names; - std::vector outLayers = net.getUnconnectedOutLayers(); - std::vector layersNames = net.getLayerNames(); - names.resize(outLayers.size()); - for (size_t i = 0; i < outLayers.size(); ++i) - names[i] = layersNames[outLayers[i] - 1]; - return names; -} - TEST(Test_Darknet, read_tiny_yolo_voc) { Net net = readNetFromDarknet(_tf("tiny-yolo-voc.cfg")); @@ -159,7 +148,7 @@ public: net.setPreferableTarget(target); net.setInput(inp); std::vector outs; - net.forward(outs, getOutputsNames(net)); + net.forward(outs, net.getUnconnectedOutLayersNames()); for (int b = 0; b < batch_size; ++b) { @@ -339,6 +328,62 @@ TEST_P(Test_Darknet_nets, TinyYoloVoc) } } +#ifdef HAVE_INF_ENGINE +static const std::chrono::milliseconds async_timeout(500); + +typedef testing::TestWithParam > Test_Darknet_nets_async; +TEST_P(Test_Darknet_nets_async, Accuracy) +{ + applyTestTag(CV_TEST_TAG_MEMORY_512MB); + + std::string prefix = get<0>(GetParam()); + int target = get<1>(GetParam()); + + const int numInputs = 2; + std::vector inputs(numInputs); + int blobSize[] = {1, 3, 416, 416}; + for (int i = 0; i < numInputs; ++i) + { + inputs[i].create(4, &blobSize[0], CV_32F); + randu(inputs[i], 0, 1); + } + + Net netSync = readNet(findDataFile("dnn/" + prefix + ".cfg"), + findDataFile("dnn/" + prefix + ".weights", false)); + netSync.setPreferableTarget(target); + + // Run synchronously. + std::vector refs(numInputs); + for (int i = 0; i < numInputs; ++i) + { + netSync.setInput(inputs[i]); + refs[i] = netSync.forward().clone(); + } + + Net netAsync = readNet(findDataFile("dnn/" + prefix + ".cfg"), + findDataFile("dnn/" + prefix + ".weights", false)); + netAsync.setPreferableTarget(target); + + // Run asynchronously. To make test more robust, process inputs in the reversed order. + for (int i = numInputs - 1; i >= 0; --i) + { + netAsync.setInput(inputs[i]); + + AsyncArray out = netAsync.forwardAsync(); + ASSERT_TRUE(out.valid()); + Mat result; + EXPECT_TRUE(out.get(result, async_timeout)); + normAssert(refs[i], result, format("Index: %d", i).c_str(), 0, 0); + } +} + +INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_nets_async, Combine( + Values("yolo-voc", "tiny-yolo-voc", "yolov3"), + ValuesIn(getAvailableTargets(DNN_BACKEND_INFERENCE_ENGINE)) +)); + +#endif + TEST_P(Test_Darknet_nets, YOLOv3) { applyTestTag(CV_TEST_TAG_LONG, (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB)); @@ -376,6 +421,16 @@ TEST_P(Test_Darknet_nets, YOLOv3) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL) // Test with 'batch size 2' is disabled for DLIE/OpenCL target #endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE) + { + if (target == DNN_TARGET_OPENCL) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_2019R2); + if (target == DNN_TARGET_OPENCL_FP16) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_2019R2); + } +#endif + { SCOPED_TRACE("batch size 2"); testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff); diff --git a/modules/dnn/test/test_halide_layers.cpp b/modules/dnn/test/test_halide_layers.cpp index a85b3fa897..6b66722936 100644 --- a/modules/dnn/test/test_halide_layers.cpp +++ b/modules/dnn/test/test_halide_layers.cpp @@ -554,6 +554,11 @@ TEST_P(ReLU, Accuracy) Backend backendId = get<0>(get<1>(GetParam())); Target targetId = get<1>(get<1>(GetParam())); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) + if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD && negativeSlope < 0) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2); +#endif + LayerParams lp; lp.set("negative_slope", negativeSlope); lp.type = "ReLU"; diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 847095262d..6b71b9b80b 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -1112,7 +1112,7 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_DLDT_two_inputs, Combine( class UnsupportedLayer : public Layer { public: - UnsupportedLayer(const LayerParams ¶ms) {} + UnsupportedLayer(const LayerParams ¶ms) : Layer(params) {} static Ptr create(const LayerParams& params) { diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index dd10a4d68b..2a8fd88efe 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -145,8 +145,17 @@ TEST_P(Test_TensorFlow_layers, padding) { runTensorFlowNet("padding_valid"); runTensorFlowNet("spatial_padding"); - runTensorFlowNet("keras_pad_concat"); runTensorFlowNet("mirror_pad"); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE) + { + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_2019R2); + if (target == DNN_TARGET_OPENCL_FP16) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_2019R2); + } +#endif + runTensorFlowNet("keras_pad_concat"); } TEST_P(Test_TensorFlow_layers, padding_same) @@ -472,7 +481,7 @@ TEST_P(Test_TensorFlow_nets, Faster_RCNN) "faster_rcnn_resnet50_coco_2018_01_28"}; checkBackend(); - if (backend == DNN_BACKEND_INFERENCE_ENGINE) + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE); if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); @@ -573,6 +582,10 @@ TEST_P(Test_TensorFlow_nets, EAST_text_detection) #if defined(INF_ENGINE_RELEASE) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD); + + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16 && + INF_ENGINE_VER_MAJOR_EQ(2019020000)) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_2019R2); #endif checkBackend(); @@ -673,7 +686,8 @@ TEST_P(Test_TensorFlow_layers, lstm) TEST_P(Test_TensorFlow_layers, split) { - if (backend == DNN_BACKEND_INFERENCE_ENGINE) + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD && + getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2); runTensorFlowNet("split"); if (backend == DNN_BACKEND_INFERENCE_ENGINE) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index c18f80fea8..7b9f3a6dd9 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -80,6 +80,10 @@ This section describes approaches based on local 2D features and used to categor - (Python) An example using the features2D framework to perform object categorization can be found at opencv_source_code/samples/python/find_obj.py + @defgroup feature2d_hal Hardware Acceleration Layer + @{ + @defgroup features2d_hal_interface Interface + @} @} */ diff --git a/modules/features2d/include/opencv2/features2d/hal/interface.h b/modules/features2d/include/opencv2/features2d/hal/interface.h index bcc6577c19..bc3b084264 100644 --- a/modules/features2d/include/opencv2/features2d/hal/interface.h +++ b/modules/features2d/include/opencv2/features2d/hal/interface.h @@ -2,7 +2,7 @@ #define OPENCV_FEATURE2D_HAL_INTERFACE_H #include "opencv2/core/cvdef.h" -//! @addtogroup featrure2d_hal_interface +//! @addtogroup features2d_hal_interface //! @{ //! @name Fast feature detector types diff --git a/modules/flann/include/opencv2/flann.hpp b/modules/flann/include/opencv2/flann.hpp index 050b5f7f58..887759e643 100644 --- a/modules/flann/include/opencv2/flann.hpp +++ b/modules/flann/include/opencv2/flann.hpp @@ -107,38 +107,38 @@ the index is built. `Distance` functor specifies the metric to be used to calculate the distance between two points. There are several `Distance` functors that are readily available: -@link cvflann::L2_Simple cv::flann::L2_Simple @endlink- Squared Euclidean distance functor. +cv::cvflann::L2_Simple - Squared Euclidean distance functor. This is the simpler, unrolled version. This is preferable for very low dimensionality data (eg 3D points) -@link cvflann::L2 cv::flann::L2 @endlink- Squared Euclidean distance functor, optimized version. +cv::flann::L2 - Squared Euclidean distance functor, optimized version. -@link cvflann::L1 cv::flann::L1 @endlink - Manhattan distance functor, optimized version. +cv::flann::L1 - Manhattan distance functor, optimized version. -@link cvflann::MinkowskiDistance cv::flann::MinkowskiDistance @endlink - The Minkowsky distance functor. +cv::flann::MinkowskiDistance - The Minkowsky distance functor. This is highly optimised with loop unrolling. The computation of squared root at the end is omitted for efficiency. -@link cvflann::MaxDistance cv::flann::MaxDistance @endlink - The max distance functor. It computes the +cv::flann::MaxDistance - The max distance functor. It computes the maximum distance between two vectors. This distance is not a valid kdtree distance, it's not dimensionwise additive. -@link cvflann::HammingLUT cv::flann::HammingLUT @endlink - %Hamming distance functor. It counts the bit +cv::flann::HammingLUT - %Hamming distance functor. It counts the bit differences between two strings using a lookup table implementation. -@link cvflann::Hamming cv::flann::Hamming @endlink - %Hamming distance functor. Population count is +cv::flann::Hamming - %Hamming distance functor. Population count is performed using library calls, if available. Lookup table implementation is used as a fallback. -@link cvflann::Hamming2 cv::flann::Hamming2 @endlink- %Hamming distance functor. Population count is +cv::flann::Hamming2 - %Hamming distance functor. Population count is implemented in 12 arithmetic operations (one of which is multiplication). -@link cvflann::HistIntersectionDistance cv::flann::HistIntersectionDistance @endlink - The histogram +cv::flann::HistIntersectionDistance - The histogram intersection distance functor. -@link cvflann::HellingerDistance cv::flann::HellingerDistance @endlink - The Hellinger distance functor. +cv::flann::HellingerDistance - The Hellinger distance functor. -@link cvflann::ChiSquareDistance cv::flann::ChiSquareDistance @endlink - The chi-square distance functor. +cv::flann::ChiSquareDistance - The chi-square distance functor. -@link cvflann::KL_Divergence cv::flann::KL_Divergence @endlink - The Kullback-Leibler divergence functor. +cv::flann::KL_Divergence - The Kullback-Leibler divergence functor. Although the provided implementations cover a vast range of cases, it is also possible to use a custom implementation. The distance functor is a class whose `operator()` computes the distance @@ -397,8 +397,6 @@ int GenericIndex::radiusSearch(const Mat& query, Mat& indices, Mat& di return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); } -//! @endcond - /** * @deprecated Use GenericIndex class instead */ @@ -531,6 +529,7 @@ private: ::cvflann::Index< L1 >* nnIndex_L1; }; +//! @endcond /** @brief Clusters features using hierarchical k-means algorithm. @@ -567,8 +566,8 @@ int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::K return ::cvflann::hierarchicalClustering(m_features, m_centers, params, d); } -/** @deprecated -*/ +//! @cond IGNORED + template CV_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params) { @@ -589,6 +588,8 @@ CV_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, cons } } +//! @endcond + //! @} flann } } // namespace cv::flann diff --git a/modules/flann/include/opencv2/flann/all_indices.h b/modules/flann/include/opencv2/flann/all_indices.h index ff53fd84c2..ba5a2f2dde 100644 --- a/modules/flann/include/opencv2/flann/all_indices.h +++ b/modules/flann/include/opencv2/flann/all_indices.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_ALL_INDICES_H_ #define OPENCV_FLANN_ALL_INDICES_H_ +//! @cond IGNORED + #include "general.h" #include "nn_index.h" @@ -152,4 +154,6 @@ NNIndex* create_index_by_type(const Matrix #include @@ -189,4 +191,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_ALLOCATOR_H_ diff --git a/modules/flann/include/opencv2/flann/any.h b/modules/flann/include/opencv2/flann/any.h index 5b57aa3df3..f5684e9962 100644 --- a/modules/flann/include/opencv2/flann/any.h +++ b/modules/flann/include/opencv2/flann/any.h @@ -12,6 +12,8 @@ * Adapted for FLANN by Marius Muja */ +//! @cond IGNORED + #include "defines.h" #include #include @@ -327,4 +329,6 @@ inline std::ostream& operator <<(std::ostream& out, const any& any_val) } +//! @endcond + #endif // OPENCV_FLANN_ANY_H_ diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index 2fbc6c9afb..eb4554f077 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_AUTOTUNED_INDEX_H_ #define OPENCV_FLANN_AUTOTUNED_INDEX_H_ +//! @cond IGNORED + #include #include "general.h" @@ -588,4 +590,6 @@ private: }; } +//! @endcond + #endif /* OPENCV_FLANN_AUTOTUNED_INDEX_H_ */ diff --git a/modules/flann/include/opencv2/flann/composite_index.h b/modules/flann/include/opencv2/flann/composite_index.h index 5e12a177bf..bcf0827c9f 100644 --- a/modules/flann/include/opencv2/flann/composite_index.h +++ b/modules/flann/include/opencv2/flann/composite_index.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_COMPOSITE_INDEX_H_ #define OPENCV_FLANN_COMPOSITE_INDEX_H_ +//! @cond IGNORED + #include "general.h" #include "nn_index.h" #include "kdtree_index.h" @@ -191,4 +193,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_COMPOSITE_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/config.h b/modules/flann/include/opencv2/flann/config.h index 56832fd37f..c9342c00c3 100644 --- a/modules/flann/include/opencv2/flann/config.h +++ b/modules/flann/include/opencv2/flann/config.h @@ -30,9 +30,13 @@ #ifndef OPENCV_FLANN_CONFIG_H_ #define OPENCV_FLANN_CONFIG_H_ +//! @cond IGNORED + #ifdef FLANN_VERSION_ #undef FLANN_VERSION_ #endif #define FLANN_VERSION_ "1.6.10" +//! @endcond + #endif /* OPENCV_FLANN_CONFIG_H_ */ diff --git a/modules/flann/include/opencv2/flann/defines.h b/modules/flann/include/opencv2/flann/defines.h index 6fd53c2f78..884c6004d4 100644 --- a/modules/flann/include/opencv2/flann/defines.h +++ b/modules/flann/include/opencv2/flann/defines.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_DEFINES_H_ #define OPENCV_FLANN_DEFINES_H_ +//! @cond IGNORED + #include "config.h" #ifdef FLANN_EXPORT @@ -161,4 +163,6 @@ enum } +//! @endcond + #endif /* OPENCV_FLANN_DEFINES_H_ */ diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 4246a3dffc..fe19bb0392 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_DIST_H_ #define OPENCV_FLANN_DIST_H_ +//! @cond IGNORED + #include #include #include @@ -901,4 +903,6 @@ typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultTyp } +//! @endcond + #endif //OPENCV_FLANN_DIST_H_ diff --git a/modules/flann/include/opencv2/flann/dummy.h b/modules/flann/include/opencv2/flann/dummy.h index d6837e53c8..c176f2e4ef 100644 --- a/modules/flann/include/opencv2/flann/dummy.h +++ b/modules/flann/include/opencv2/flann/dummy.h @@ -2,6 +2,8 @@ #ifndef OPENCV_FLANN_DUMMY_H_ #define OPENCV_FLANN_DUMMY_H_ +//! @cond IGNORED + namespace cvflann { @@ -9,5 +11,6 @@ CV_DEPRECATED inline void dummyfunc() {} } +//! @endcond #endif /* OPENCV_FLANN_DUMMY_H_ */ diff --git a/modules/flann/include/opencv2/flann/dynamic_bitset.h b/modules/flann/include/opencv2/flann/dynamic_bitset.h index 923b658321..a00ce1bb7e 100644 --- a/modules/flann/include/opencv2/flann/dynamic_bitset.h +++ b/modules/flann/include/opencv2/flann/dynamic_bitset.h @@ -35,6 +35,8 @@ #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_ #define OPENCV_FLANN_DYNAMIC_BITSET_H_ +//! @cond IGNORED + #ifndef FLANN_USE_BOOST # define FLANN_USE_BOOST 0 #endif @@ -156,4 +158,6 @@ private: #endif +//! @endcond + #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_ diff --git a/modules/flann/include/opencv2/flann/flann_base.hpp b/modules/flann/include/opencv2/flann/flann_base.hpp index 0ffb857cc6..83606d232f 100644 --- a/modules/flann/include/opencv2/flann/flann_base.hpp +++ b/modules/flann/include/opencv2/flann/flann_base.hpp @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_BASE_HPP_ #define OPENCV_FLANN_BASE_HPP_ +//! @cond IGNORED + #include #include #include @@ -292,4 +294,7 @@ int hierarchicalClustering(const Matrix& points, } } + +//! @endcond + #endif /* OPENCV_FLANN_BASE_HPP_ */ diff --git a/modules/flann/include/opencv2/flann/general.h b/modules/flann/include/opencv2/flann/general.h index 9d5402a6f2..ac848d6230 100644 --- a/modules/flann/include/opencv2/flann/general.h +++ b/modules/flann/include/opencv2/flann/general.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_GENERAL_H_ #define OPENCV_FLANN_GENERAL_H_ +//! @cond IGNORED + #include "opencv2/core.hpp" namespace cvflann @@ -46,5 +48,6 @@ public: } +//! @endcond #endif /* OPENCV_FLANN_GENERAL_H_ */ diff --git a/modules/flann/include/opencv2/flann/ground_truth.h b/modules/flann/include/opencv2/flann/ground_truth.h index fd8f3ae7f0..17f2a8e848 100644 --- a/modules/flann/include/opencv2/flann/ground_truth.h +++ b/modules/flann/include/opencv2/flann/ground_truth.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_GROUND_TRUTH_H_ #define OPENCV_FLANN_GROUND_TRUTH_H_ +//! @cond IGNORED + #include "dist.h" #include "matrix.h" @@ -91,4 +93,6 @@ void compute_ground_truth(const Matrix& dataset, } +//! @endcond + #endif //OPENCV_FLANN_GROUND_TRUTH_H_ diff --git a/modules/flann/include/opencv2/flann/hdf5.h b/modules/flann/include/opencv2/flann/hdf5.h new file mode 100644 index 0000000000..75543840d6 --- /dev/null +++ b/modules/flann/include/opencv2/flann/hdf5.h @@ -0,0 +1,235 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_HDF5_H_ +#define OPENCV_FLANN_HDF5_H_ + +//! @cond IGNORED + +#include + +#include "matrix.h" + + +namespace cvflann +{ + +namespace +{ + +template +hid_t get_hdf5_type() +{ + throw FLANNException("Unsupported type for IO operations"); +} + +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_CHAR; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_UCHAR; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_SHORT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_USHORT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_INT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_UINT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_LONG; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_ULONG; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_FLOAT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_DOUBLE; } +} + + +#define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y)); + +template +void save_to_file(const cvflann::Matrix& dataset, const String& filename, const String& name) +{ + +#if H5Eset_auto_vers == 2 + H5Eset_auto( H5E_DEFAULT, NULL, NULL ); +#else + H5Eset_auto( NULL, NULL ); +#endif + + herr_t status; + hid_t file_id; + file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + if (file_id < 0) { + file_id = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); + } + CHECK_ERROR(file_id,"Error creating hdf5 file."); + + hsize_t dimsf[2]; // dataset dimensions + dimsf[0] = dataset.rows; + dimsf[1] = dataset.cols; + + hid_t space_id = H5Screate_simple(2, dimsf, NULL); + hid_t memspace_id = H5Screate_simple(2, dimsf, NULL); + + hid_t dataset_id; +#if H5Dcreate_vers == 2 + dataset_id = H5Dcreate2(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); +#else + dataset_id = H5Dcreate(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT); +#endif + + if (dataset_id<0) { +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + } + CHECK_ERROR(dataset_id,"Error creating or opening dataset in file."); + + status = H5Dwrite(dataset_id, get_hdf5_type(), memspace_id, space_id, H5P_DEFAULT, dataset.data ); + CHECK_ERROR(status, "Error writing to dataset"); + + H5Sclose(memspace_id); + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); + +} + + +template +void load_from_file(cvflann::Matrix& dataset, const String& filename, const String& name) +{ + herr_t status; + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + + hsize_t dims_out[2]; + H5Sget_simple_extent_dims(space_id, dims_out, NULL); + + dataset = cvflann::Matrix(new T[dims_out[0]*dims_out[1]], dims_out[0], dims_out[1]); + + status = H5Dread(dataset_id, get_hdf5_type(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]); + CHECK_ERROR(status, "Error reading dataset"); + + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} + + +#ifdef HAVE_MPI + +namespace mpi +{ +/** + * Loads a the hyperslice corresponding to this processor from a hdf5 file. + * @param flann_dataset Dataset where the data is loaded + * @param filename HDF5 file name + * @param name Name of dataset inside file + */ +template +void load_from_file(cvflann::Matrix& dataset, const String& filename, const String& name) +{ + MPI_Comm comm = MPI_COMM_WORLD; + MPI_Info info = MPI_INFO_NULL; + + int mpi_size, mpi_rank; + MPI_Comm_size(comm, &mpi_size); + MPI_Comm_rank(comm, &mpi_rank); + + herr_t status; + + hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(plist_id, comm, info); + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, plist_id); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + H5Pclose(plist_id); + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + hsize_t dims[2]; + H5Sget_simple_extent_dims(space_id, dims, NULL); + + hsize_t count[2]; + hsize_t offset[2]; + + hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1); + hsize_t cnt = (mpi_rank(), memspace_id, space_id, plist_id, dataset.data); + CHECK_ERROR(status, "Error reading dataset"); + + H5Pclose(plist_id); + H5Sclose(space_id); + H5Sclose(memspace_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} +} +#endif // HAVE_MPI +} // namespace cvflann::mpi + +//! @endcond + +#endif /* OPENCV_FLANN_HDF5_H_ */ diff --git a/modules/flann/include/opencv2/flann/heap.h b/modules/flann/include/opencv2/flann/heap.h index 92a6ea614b..ee1c682cfe 100644 --- a/modules/flann/include/opencv2/flann/heap.h +++ b/modules/flann/include/opencv2/flann/heap.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_HEAP_H_ #define OPENCV_FLANN_HEAP_H_ +//! @cond IGNORED + #include #include @@ -162,4 +164,6 @@ public: } +//! @endcond + #endif //OPENCV_FLANN_HEAP_H_ diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index e2fce857a9..20304ede73 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ #define OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ +//! @cond IGNORED + #include #include #include @@ -845,4 +847,6 @@ private: } +//! @endcond + #endif /* OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ */ diff --git a/modules/flann/include/opencv2/flann/index_testing.h b/modules/flann/include/opencv2/flann/index_testing.h index d76400409a..47b6f0b86f 100644 --- a/modules/flann/include/opencv2/flann/index_testing.h +++ b/modules/flann/include/opencv2/flann/index_testing.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_INDEX_TESTING_H_ #define OPENCV_FLANN_INDEX_TESTING_H_ +//! @cond IGNORED + #include #include #include @@ -315,4 +317,6 @@ void test_index_precisions(NNIndex& index, const Matrix #include #include @@ -623,4 +625,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_KDTREE_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/kdtree_single_index.h b/modules/flann/include/opencv2/flann/kdtree_single_index.h index 22a28d0c1a..fa38f9f1a2 100644 --- a/modules/flann/include/opencv2/flann/kdtree_single_index.h +++ b/modules/flann/include/opencv2/flann/kdtree_single_index.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ #define OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ +//! @cond IGNORED + #include #include #include @@ -632,4 +634,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index 500745121f..7574e7faf8 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_KMEANS_INDEX_H_ #define OPENCV_FLANN_KMEANS_INDEX_H_ +//! @cond IGNORED + #include #include #include @@ -1169,4 +1171,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_KMEANS_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/linear_index.h b/modules/flann/include/opencv2/flann/linear_index.h index ca3f44d0cb..8a0f10fd86 100644 --- a/modules/flann/include/opencv2/flann/linear_index.h +++ b/modules/flann/include/opencv2/flann/linear_index.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_LINEAR_INDEX_H_ #define OPENCV_FLANN_LINEAR_INDEX_H_ +//! @cond IGNORED + #include "general.h" #include "nn_index.h" @@ -129,4 +131,6 @@ private: } +//! @endcond + #endif // OPENCV_FLANN_LINEAR_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/logger.h b/modules/flann/include/opencv2/flann/logger.h index 32618dbbb7..8911812a77 100644 --- a/modules/flann/include/opencv2/flann/logger.h +++ b/modules/flann/include/opencv2/flann/logger.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_LOGGER_H #define OPENCV_FLANN_LOGGER_H +//! @cond IGNORED + #include #include @@ -132,4 +134,6 @@ private: } +//! @endcond + #endif //OPENCV_FLANN_LOGGER_H diff --git a/modules/flann/include/opencv2/flann/lsh_index.h b/modules/flann/include/opencv2/flann/lsh_index.h index 42afe892ac..ee620dae3e 100644 --- a/modules/flann/include/opencv2/flann/lsh_index.h +++ b/modules/flann/include/opencv2/flann/lsh_index.h @@ -35,6 +35,8 @@ #ifndef OPENCV_FLANN_LSH_INDEX_H_ #define OPENCV_FLANN_LSH_INDEX_H_ +//! @cond IGNORED + #include #include #include @@ -389,4 +391,6 @@ private: }; } +//! @endcond + #endif //OPENCV_FLANN_LSH_INDEX_H_ diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h index b07a9d5284..db8b5af946 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -35,6 +35,8 @@ #ifndef OPENCV_FLANN_LSH_TABLE_H_ #define OPENCV_FLANN_LSH_TABLE_H_ +//! @cond IGNORED + #include #include #include @@ -510,4 +512,6 @@ inline LshStats LshTable::getStats() const //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//! @endcond + #endif /* OPENCV_FLANN_LSH_TABLE_H_ */ diff --git a/modules/flann/include/opencv2/flann/matrix.h b/modules/flann/include/opencv2/flann/matrix.h index f6092d134e..34893b72c3 100644 --- a/modules/flann/include/opencv2/flann/matrix.h +++ b/modules/flann/include/opencv2/flann/matrix.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_DATASET_H_ #define OPENCV_FLANN_DATASET_H_ +//! @cond IGNORED + #include #include "general.h" @@ -113,4 +115,6 @@ public: } +//! @endcond + #endif //OPENCV_FLANN_DATASET_H_ diff --git a/modules/flann/include/opencv2/flann/miniflann.hpp b/modules/flann/include/opencv2/flann/miniflann.hpp index 2590ad76fb..253290790e 100644 --- a/modules/flann/include/opencv2/flann/miniflann.hpp +++ b/modules/flann/include/opencv2/flann/miniflann.hpp @@ -43,6 +43,8 @@ #ifndef OPENCV_MINIFLANN_HPP #define OPENCV_MINIFLANN_HPP +//! @cond IGNORED + #include "opencv2/core.hpp" #include "opencv2/flann/defines.h" @@ -174,4 +176,6 @@ protected: } } // namespace cv::flann +//! @endcond + #endif diff --git a/modules/flann/include/opencv2/flann/nn_index.h b/modules/flann/include/opencv2/flann/nn_index.h index 381d4bc3cb..00fe6ec5ae 100644 --- a/modules/flann/include/opencv2/flann/nn_index.h +++ b/modules/flann/include/opencv2/flann/nn_index.h @@ -36,6 +36,8 @@ #include "result_set.h" #include "params.h" +//! @cond IGNORED + namespace cvflann { @@ -174,4 +176,6 @@ public: } +//! @endcond + #endif //OPENCV_FLANN_NNINDEX_H diff --git a/modules/flann/include/opencv2/flann/object_factory.h b/modules/flann/include/opencv2/flann/object_factory.h index 7f971c5a31..5cc45ad1b3 100644 --- a/modules/flann/include/opencv2/flann/object_factory.h +++ b/modules/flann/include/opencv2/flann/object_factory.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_OBJECT_FACTORY_H_ #define OPENCV_FLANN_OBJECT_FACTORY_H_ +//! @cond IGNORED + #include namespace cvflann @@ -88,4 +90,6 @@ private: } +//! @endcond + #endif /* OPENCV_FLANN_OBJECT_FACTORY_H_ */ diff --git a/modules/flann/include/opencv2/flann/params.h b/modules/flann/include/opencv2/flann/params.h index 95ef4cd23b..b8f7331905 100644 --- a/modules/flann/include/opencv2/flann/params.h +++ b/modules/flann/include/opencv2/flann/params.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_PARAMS_H_ #define OPENCV_FLANN_PARAMS_H_ +//! @cond IGNORED + #include "any.h" #include "general.h" #include @@ -95,5 +97,6 @@ inline void print_params(const IndexParams& params) } +//! @endcond #endif /* OPENCV_FLANN_PARAMS_H_ */ diff --git a/modules/flann/include/opencv2/flann/random.h b/modules/flann/include/opencv2/flann/random.h index d6784747c0..3bb48b687b 100644 --- a/modules/flann/include/opencv2/flann/random.h +++ b/modules/flann/include/opencv2/flann/random.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_RANDOM_H #define OPENCV_FLANN_RANDOM_H +//! @cond IGNORED + #include #include #include @@ -152,4 +154,6 @@ public: } +//! @endcond + #endif //OPENCV_FLANN_RANDOM_H diff --git a/modules/flann/include/opencv2/flann/result_set.h b/modules/flann/include/opencv2/flann/result_set.h index e5b6fb24e2..735028fb45 100644 --- a/modules/flann/include/opencv2/flann/result_set.h +++ b/modules/flann/include/opencv2/flann/result_set.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_RESULTSET_H #define OPENCV_FLANN_RESULTSET_H +//! @cond IGNORED + #include #include #include @@ -540,4 +542,6 @@ private: }; } +//! @endcond + #endif //OPENCV_FLANN_RESULTSET_H diff --git a/modules/flann/include/opencv2/flann/sampling.h b/modules/flann/include/opencv2/flann/sampling.h index 396f177ae3..4e452b9bba 100644 --- a/modules/flann/include/opencv2/flann/sampling.h +++ b/modules/flann/include/opencv2/flann/sampling.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_SAMPLING_H_ #define OPENCV_FLANN_SAMPLING_H_ +//! @cond IGNORED + #include "matrix.h" #include "random.h" @@ -77,5 +79,6 @@ Matrix random_sample(const Matrix& srcMatrix, size_t size) } // namespace +//! @endcond #endif /* OPENCV_FLANN_SAMPLING_H_ */ diff --git a/modules/flann/include/opencv2/flann/saving.h b/modules/flann/include/opencv2/flann/saving.h index 7e3bea564b..53359b4b7b 100644 --- a/modules/flann/include/opencv2/flann/saving.h +++ b/modules/flann/include/opencv2/flann/saving.h @@ -29,6 +29,8 @@ #ifndef OPENCV_FLANN_SAVING_H_ #define OPENCV_FLANN_SAVING_H_ +//! @cond IGNORED + #include #include @@ -184,4 +186,6 @@ void load_value(FILE* stream, std::vector& value) } +//! @endcond + #endif /* OPENCV_FLANN_SAVING_H_ */ diff --git a/modules/flann/include/opencv2/flann/simplex_downhill.h b/modules/flann/include/opencv2/flann/simplex_downhill.h index 145901ab0d..9fd84f488c 100644 --- a/modules/flann/include/opencv2/flann/simplex_downhill.h +++ b/modules/flann/include/opencv2/flann/simplex_downhill.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ #define OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ +//! @cond IGNORED + namespace cvflann { @@ -183,4 +185,6 @@ float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) } +//! @endcond + #endif //OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ diff --git a/modules/flann/include/opencv2/flann/timer.h b/modules/flann/include/opencv2/flann/timer.h index f771a34179..73795aa35b 100644 --- a/modules/flann/include/opencv2/flann/timer.h +++ b/modules/flann/include/opencv2/flann/timer.h @@ -31,6 +31,8 @@ #ifndef OPENCV_FLANN_TIMER_H #define OPENCV_FLANN_TIMER_H +//! @cond IGNORED + #include #include "opencv2/core.hpp" #include "opencv2/core/utility.hpp" @@ -91,4 +93,6 @@ public: } +//! @endcond + #endif // FLANN_TIMER_H diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index dfd946c429..f109640414 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -197,7 +197,8 @@ enum WindowPropertyFlags { WND_PROP_AUTOSIZE = 1, //!< autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). WND_PROP_OPENGL = 3, //!< opengl support. - WND_PROP_VISIBLE = 4 //!< checks whether the window exists and is visible + WND_PROP_VISIBLE = 4, //!< checks whether the window exists and is visible + WND_PROP_TOPMOST = 5 //!< property to toggle normal window being topmost or not }; //! Mouse Events see cv::MouseCallback diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 53ac43587d..1123fc2a99 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -109,6 +109,12 @@ double cvGetOpenGlProp_GTK(const char* name); double cvGetPropVisible_W32(const char* name); +double cvGetPropTopmost_W32(const char* name); +double cvGetPropTopmost_COCOA(const char* name); + +void cvSetPropTopmost_W32(const char* name, const bool topmost); +void cvSetPropTopmost_COCOA(const char* name, const bool topmost); + //for QT #if defined (HAVE_QT) CvRect cvGetWindowRect_QT(const char* name); diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index faba842986..5ce22a7ec1 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -42,6 +42,7 @@ #include "precomp.hpp" #include #include "opencv2/core/opengl.hpp" +#include "opencv2/core/utils/logger.hpp" // in later times, use this file as a dispatcher to implementations like cvcap.cpp @@ -81,6 +82,16 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu #endif break; + case cv::WND_PROP_TOPMOST: + #if defined(HAVE_WIN32UI) + cvSetPropTopmost_W32(name, (prop_value != 0 ? true : false)); + #elif defined(HAVE_COCOA) + cvSetPropTopmost_COCOA(name, (prop_value != 0 ? true : false)); + #else + CV_LOG_WARNING(NULL, "Property WND_PROP_TOPMOST is not supported on current GUI backend"); + #endif + break; + default:; } } @@ -158,6 +169,18 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return -1; #endif break; + + case cv::WND_PROP_TOPMOST: + #if defined(HAVE_WIN32UI) + return cvGetPropTopmost_W32(name); + #elif defined(HAVE_COCOA) + return cvGetPropTopmost_COCOA(name); + #else + CV_LOG_WARNING(NULL, "Property WND_PROP_TOPMOST is not supported on current GUI backend"); + return -1; + #endif + break; + default: return -1; } diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 2a59d1a07b..08b11ae89a 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -713,6 +713,68 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) __END__; } +double cvGetPropTopmost_COCOA(const char* name) +{ + double result = -1; + CVWindow* window = nil; + + CV_FUNCNAME("cvGetPropTopmost_COCOA"); + + __BEGIN__; + if (name == NULL) + { + CV_ERROR(CV_StsNullPtr, "NULL name string"); + } + + window = cvGetWindow(name); + if (window == NULL) + { + CV_ERROR(CV_StsNullPtr, "NULL window"); + } + + result = (window.level == NSStatusWindowLevel) ? 1 : 0; + + __END__; + return result; +} + +void cvSetPropTopmost_COCOA( const char* name, const bool topmost ) +{ + CVWindow *window = nil; + NSAutoreleasePool* localpool = nil; + CV_FUNCNAME( "cvSetPropTopmost_COCOA" ); + + __BEGIN__; + if( name == NULL ) + { + CV_ERROR( CV_StsNullPtr, "NULL name string" ); + } + + window = cvGetWindow(name); + if ( window == NULL ) + { + CV_ERROR( CV_StsNullPtr, "NULL window" ); + } + + if ([[window contentView] isInFullScreenMode]) + { + EXIT; + } + + localpool = [[NSAutoreleasePool alloc] init]; + if (topmost) + { + [window makeKeyAndOrderFront:window.self]; + [window setLevel:CGWindowLevelForKey(kCGMaximumWindowLevelKey)]; + } + else + { + [window makeKeyAndOrderFront:nil]; + } + [localpool drain]; + __END__; +} + void cv::setWindowTitle(const String& winname, const String& title) { CVWindow *window = cvGetWindow(winname.c_str()); diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index bd0df341a2..b30861d26d 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -40,6 +40,9 @@ //M*/ #include "precomp.hpp" + +using namespace cv; + #include // required for GET_X_LPARAM() and GET_Y_LPARAM() macros #if defined _WIN32 @@ -551,6 +554,48 @@ void cvSetModeWindow_W32( const char* name, double prop_value)//Yannick Verdie __END__; } +double cvGetPropTopmost_W32(const char* name) +{ + double result = -1; + + CV_Assert(name); + + CvWindow* window = icvFindWindowByName(name); + if (!window) + CV_Error(Error::StsNullPtr, "NULL window"); + + LONG style = GetWindowLongA(window->frame, GWL_EXSTYLE); // -20 + if (!style) + { + std::ostringstream errorMsg; + errorMsg << "window(" << name << "): failed to retrieve extended window style using GetWindowLongA(); error code: " << GetLastError(); + CV_Error(Error::StsError, errorMsg.str().c_str()); + } + + result = (style & WS_EX_TOPMOST) == WS_EX_TOPMOST; + + return result; +} + +void cvSetPropTopmost_W32(const char* name, const bool topmost) +{ + CV_Assert(name); + + CvWindow* window = icvFindWindowByName(name); + if (!window) + CV_Error(Error::StsNullPtr, "NULL window"); + + HWND flag = topmost ? HWND_TOPMOST : HWND_TOP; + BOOL success = SetWindowPos(window->frame, flag, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + + if (!success) + { + std::ostringstream errorMsg; + errorMsg << "window(" << name << "): error reported by SetWindowPos(" << (topmost ? "HWND_TOPMOST" : "HWND_TOP") << "), error code: " << GetLastError(); + CV_Error(Error::StsError, errorMsg.str().c_str()); + } +} + void cv::setWindowTitle(const String& winname, const String& title) { CvWindow* window = icvFindWindowByName(winname.c_str()); diff --git a/modules/imgproc/perf/perf_integral.cpp b/modules/imgproc/perf/perf_integral.cpp index 85a426efc9..59a5060937 100644 --- a/modules/imgproc/perf/perf_integral.cpp +++ b/modules/imgproc/perf/perf_integral.cpp @@ -5,9 +5,24 @@ namespace opencv_test { +enum PerfSqMatDepth{ + DEPTH_32S_32S = 0, + DEPTH_32S_32F, + DEPTH_32S_64F, + DEPTH_32F_32F, + DEPTH_32F_64F, + DEPTH_64F_64F}; + +CV_ENUM(IntegralOutputDepths, DEPTH_32S_32S, DEPTH_32S_32F, DEPTH_32S_64F, DEPTH_32F_32F, DEPTH_32F_64F, DEPTH_64F_64F); + +static int extraOutputDepths[6][2] = {{CV_32S, CV_32S}, {CV_32S, CV_32F}, {CV_32S, CV_64F}, {CV_32F, CV_32F}, {CV_32F, CV_64F}, {CV_64F, CV_64F}}; + typedef tuple Size_MatType_OutMatDepth_t; typedef perf::TestBaseWithParam Size_MatType_OutMatDepth; +typedef tuple Size_MatType_OutMatDepthArray_t; +typedef perf::TestBaseWithParam Size_MatType_OutMatDepthArray; + PERF_TEST_P(Size_MatType_OutMatDepth, integral, testing::Combine( testing::Values(TYPICAL_MAT_SIZES), @@ -55,6 +70,32 @@ PERF_TEST_P(Size_MatType_OutMatDepth, integral_sqsum, SANITY_CHECK(sqsum, 1e-6); } +PERF_TEST_P(Size_MatType_OutMatDepthArray, DISABLED_integral_sqsum_full, + testing::Combine( + testing::Values(TYPICAL_MAT_SIZES), + testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4), + testing::Values(DEPTH_32S_32S, DEPTH_32S_32F, DEPTH_32S_64F, DEPTH_32F_32F, DEPTH_32F_64F, DEPTH_64F_64F) + ) + ) +{ + Size sz = get<0>(GetParam()); + int matType = get<1>(GetParam()); + int *outputDepths = (int *)extraOutputDepths[get<2>(GetParam())]; + int sdepth = outputDepths[0]; + int sqdepth = outputDepths[1]; + + Mat src(sz, matType); + Mat sum(sz, sdepth); + Mat sqsum(sz, sqdepth); + + declare.in(src, WARMUP_RNG).out(sum, sqsum); + declare.time(100); + + TEST_CYCLE() integral(src, sum, sqsum, sdepth, sqdepth); + + SANITY_CHECK_NOTHING(); +} + PERF_TEST_P( Size_MatType_OutMatDepth, integral_sqsum_tilted, testing::Combine( testing::Values(TYPICAL_MAT_SIZES), diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index c7ae005da8..36bbb11563 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -2686,6 +2686,258 @@ void cv::warpAffine( InputArray _src, OutputArray _dst, namespace cv { +#if CV_SIMD128_64F +void WarpPerspectiveLine_ProcessNN_CV_SIMD(const double *M, short* xy, double X0, double Y0, double W0, int bw) +{ + const v_float64x2 v_M0 = v_setall_f64(M[0]); + const v_float64x2 v_M3 = v_setall_f64(M[3]); + const v_float64x2 v_M6 = v_setall_f64(M[6]); + const v_float64x2 v_intmax = v_setall_f64((double)INT_MAX); + const v_float64x2 v_intmin = v_setall_f64((double)INT_MIN); + const v_float64x2 v_2 = v_setall_f64(2.0); + const v_float64x2 v_zero = v_setzero_f64(); + const v_float64x2 v_1 = v_setall_f64(1.0); + + int x1 = 0; + v_float64x2 v_X0d = v_setall_f64(X0); + v_float64x2 v_Y0d = v_setall_f64(Y0); + v_float64x2 v_W0 = v_setall_f64(W0); + v_float64x2 v_x1(0.0, 1.0); + + for (; x1 <= bw - 16; x1 += 16) + { + // 0-3 + v_int32x4 v_X0, v_Y0; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X0 = v_round(v_fX0, v_fX1); + v_Y0 = v_round(v_fY0, v_fY1); + } + + // 4-7 + v_int32x4 v_X1, v_Y1; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X1 = v_round(v_fX0, v_fX1); + v_Y1 = v_round(v_fY0, v_fY1); + } + + // 8-11 + v_int32x4 v_X2, v_Y2; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X2 = v_round(v_fX0, v_fX1); + v_Y2 = v_round(v_fY0, v_fY1); + } + + // 12-15 + v_int32x4 v_X3, v_Y3; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_1 / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X3 = v_round(v_fX0, v_fX1); + v_Y3 = v_round(v_fY0, v_fY1); + } + + // convert to 16s + v_X0 = v_reinterpret_as_s32(v_pack(v_X0, v_X1)); + v_X1 = v_reinterpret_as_s32(v_pack(v_X2, v_X3)); + v_Y0 = v_reinterpret_as_s32(v_pack(v_Y0, v_Y1)); + v_Y1 = v_reinterpret_as_s32(v_pack(v_Y2, v_Y3)); + + v_store_interleave(xy + x1 * 2, (v_reinterpret_as_s16)(v_X0), (v_reinterpret_as_s16)(v_Y0)); + v_store_interleave(xy + x1 * 2 + 16, (v_reinterpret_as_s16)(v_X1), (v_reinterpret_as_s16)(v_Y1)); + } + + for( ; x1 < bw; x1++ ) + { + double W = W0 + M[6]*x1; + W = W ? 1./W : 0; + double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); + double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); + int X = saturate_cast(fX); + int Y = saturate_cast(fY); + + xy[x1*2] = saturate_cast(X); + xy[x1*2+1] = saturate_cast(Y); + } +} + +void WarpPerspectiveLine_Process_CV_SIMD(const double *M, short* xy, short* alpha, double X0, double Y0, double W0, int bw) +{ + const v_float64x2 v_M0 = v_setall_f64(M[0]); + const v_float64x2 v_M3 = v_setall_f64(M[3]); + const v_float64x2 v_M6 = v_setall_f64(M[6]); + const v_float64x2 v_intmax = v_setall_f64((double)INT_MAX); + const v_float64x2 v_intmin = v_setall_f64((double)INT_MIN); + const v_float64x2 v_2 = v_setall_f64(2.0); + const v_float64x2 v_zero = v_setzero_f64(); + const v_float64x2 v_its = v_setall_f64((double)INTER_TAB_SIZE); + const v_int32x4 v_itsi1 = v_setall_s32(INTER_TAB_SIZE - 1); + + int x1 = 0; + + v_float64x2 v_X0d = v_setall_f64(X0); + v_float64x2 v_Y0d = v_setall_f64(Y0); + v_float64x2 v_W0 = v_setall_f64(W0); + v_float64x2 v_x1(0.0, 1.0); + + for (; x1 <= bw - 16; x1 += 16) + { + // 0-3 + v_int32x4 v_X0, v_Y0; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X0 = v_round(v_fX0, v_fX1); + v_Y0 = v_round(v_fY0, v_fY1); + } + + // 4-7 + v_int32x4 v_X1, v_Y1; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X1 = v_round(v_fX0, v_fX1); + v_Y1 = v_round(v_fY0, v_fY1); + } + + // 8-11 + v_int32x4 v_X2, v_Y2; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X2 = v_round(v_fX0, v_fX1); + v_Y2 = v_round(v_fY0, v_fY1); + } + + // 12-15 + v_int32x4 v_X3, v_Y3; + { + v_float64x2 v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY0 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_W = v_muladd(v_M6, v_x1, v_W0); + v_W = v_select(v_W != v_zero, v_its / v_W, v_zero); + v_float64x2 v_fX1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M0, v_x1, v_X0d) * v_W)); + v_float64x2 v_fY1 = v_max(v_intmin, v_min(v_intmax, v_muladd(v_M3, v_x1, v_Y0d) * v_W)); + v_x1 += v_2; + + v_X3 = v_round(v_fX0, v_fX1); + v_Y3 = v_round(v_fY0, v_fY1); + } + + // store alpha + v_int32x4 v_alpha0 = ((v_Y0 & v_itsi1) << INTER_BITS) + (v_X0 & v_itsi1); + v_int32x4 v_alpha1 = ((v_Y1 & v_itsi1) << INTER_BITS) + (v_X1 & v_itsi1); + v_store((alpha + x1), v_pack(v_alpha0, v_alpha1)); + + v_alpha0 = ((v_Y2 & v_itsi1) << INTER_BITS) + (v_X2 & v_itsi1); + v_alpha1 = ((v_Y3 & v_itsi1) << INTER_BITS) + (v_X3 & v_itsi1); + v_store((alpha + x1 + 8), v_pack(v_alpha0, v_alpha1)); + + // convert to 16s + v_X0 = v_reinterpret_as_s32(v_pack(v_X0 >> INTER_BITS, v_X1 >> INTER_BITS)); + v_X1 = v_reinterpret_as_s32(v_pack(v_X2 >> INTER_BITS, v_X3 >> INTER_BITS)); + v_Y0 = v_reinterpret_as_s32(v_pack(v_Y0 >> INTER_BITS, v_Y1 >> INTER_BITS)); + v_Y1 = v_reinterpret_as_s32(v_pack(v_Y2 >> INTER_BITS, v_Y3 >> INTER_BITS)); + + v_store_interleave(xy + x1 * 2, (v_reinterpret_as_s16)(v_X0), (v_reinterpret_as_s16)(v_Y0)); + v_store_interleave(xy + x1 * 2 + 16, (v_reinterpret_as_s16)(v_X1), (v_reinterpret_as_s16)(v_Y1)); + } + + for( ; x1 < bw; x1++ ) + { + double W = W0 + M[6]*x1; + W = W ? INTER_TAB_SIZE/W : 0; + double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); + double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); + int X = saturate_cast(fX); + int Y = saturate_cast(fY); + + xy[x1*2] = saturate_cast(X >> INTER_BITS); + xy[x1*2+1] = saturate_cast(Y >> INTER_BITS); + alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + + (X & (INTER_TAB_SIZE-1))); + } +} +#endif class WarpPerspectiveInvoker : public ParallelLoopBody @@ -2707,7 +2959,7 @@ public: { const int BLOCK_SZ = 32; short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ]; - int x, y, x1, y1, width = dst.cols, height = dst.rows; + int x, y, y1, width = dst.cols, height = dst.rows; int bh0 = std::min(BLOCK_SZ/2, height); int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, width); @@ -2738,14 +2990,15 @@ public: if( interpolation == INTER_NEAREST ) { - x1 = 0; - #if CV_TRY_SSE4_1 if (pwarp_impl_sse4) pwarp_impl_sse4->processNN(M, xy, X0, Y0, W0, bw); else #endif - for( ; x1 < bw; x1++ ) + #if CV_SIMD128_64F + WarpPerspectiveLine_ProcessNN_CV_SIMD(M, xy, X0, Y0, W0, bw); + #else + for( int x1 = 0; x1 < bw; x1++ ) { double W = W0 + M[6]*x1; W = W ? 1./W : 0; @@ -2757,18 +3010,21 @@ public: xy[x1*2] = saturate_cast(X); xy[x1*2+1] = saturate_cast(Y); } + #endif } else { short* alpha = A + y1*bw; - x1 = 0; #if CV_TRY_SSE4_1 if (pwarp_impl_sse4) pwarp_impl_sse4->process(M, xy, alpha, X0, Y0, W0, bw); else #endif - for( ; x1 < bw; x1++ ) + #if CV_SIMD128_64F + WarpPerspectiveLine_Process_CV_SIMD(M, xy, alpha, X0, Y0, W0, bw); + #else + for( int x1 = 0; x1 < bw; x1++ ) { double W = W0 + M[6]*x1; W = W ? INTER_TAB_SIZE/W : 0; @@ -2782,6 +3038,7 @@ public: alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (X & (INTER_TAB_SIZE-1))); } + #endif } } diff --git a/modules/imgproc/src/imgwarp.hpp b/modules/imgproc/src/imgwarp.hpp index ef1f6646a2..1f8f1c5d17 100644 --- a/modules/imgproc/src/imgwarp.hpp +++ b/modules/imgproc/src/imgwarp.hpp @@ -50,6 +50,7 @@ #ifndef OPENCV_IMGPROC_IMGWARP_HPP #define OPENCV_IMGPROC_IMGWARP_HPP #include "precomp.hpp" +#include "opencv2/core/hal/intrin.hpp" namespace cv { @@ -78,6 +79,12 @@ public: }; #endif } + +#if CV_SIMD128_64F +void WarpPerspectiveLine_ProcessNN_CV_SIMD(const double *M, short* xy, double X0, double Y0, double W0, int bw); +void WarpPerspectiveLine_Process_CV_SIMD(const double *M, short* xy, short* alpha, double X0, double Y0, double W0, int bw); +#endif + } #endif /* End of file. */ diff --git a/modules/photo/include/opencv2/photo.hpp b/modules/photo/include/opencv2/photo.hpp index 9ef1c0fe9b..c2e89a3858 100644 --- a/modules/photo/include/opencv2/photo.hpp +++ b/modules/photo/include/opencv2/photo.hpp @@ -77,6 +77,8 @@ Useful links: http://www.inf.ufrgs.br/~eslgastal/DomainTransform https://www.learnopencv.com/non-photorealistic-rendering-using-opencv-python-c/ + + @defgroup photo_c C API @} */ diff --git a/samples/cpp/application_trace.cpp b/samples/cpp/application_trace.cpp index 4c03e48c0c..3ad06a4ccd 100644 --- a/samples/cpp/application_trace.cpp +++ b/samples/cpp/application_trace.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include using namespace cv; diff --git a/samples/cpp/demhist.cpp b/samples/cpp/demhist.cpp index 3e416b32ad..4a564af402 100644 --- a/samples/cpp/demhist.cpp +++ b/samples/cpp/demhist.cpp @@ -56,11 +56,6 @@ static void updateBrightnessContrast( int /*arg*/, void* ) Scalar::all(0), -1, 8, 0 ); imshow("histogram", histImage); } -static void help() -{ - std::cout << "\nThis program demonstrates the use of calcHist() -- histogram creation.\n" - << "Usage: \n" << "demhist [image_name -- Defaults to baboon.jpg]" << std::endl; -} const char* keys = { @@ -70,9 +65,10 @@ const char* keys = int main( int argc, const char** argv ) { CommandLineParser parser(argc, argv, keys); + parser.about("\nThis program demonstrates the use of calcHist() -- histogram creation.\n"); if (parser.has("help")) { - help(); + parser.printMessage(); return 0; } string inputImage = parser.get(0); diff --git a/samples/cpp/dft.cpp b/samples/cpp/dft.cpp index 652ffb3dca..f57ae3f8ae 100644 --- a/samples/cpp/dft.cpp +++ b/samples/cpp/dft.cpp @@ -9,12 +9,11 @@ using namespace cv; using namespace std; -static void help() +static void help(const char ** argv) { printf("\nThis program demonstrated the use of the discrete Fourier transform (dft)\n" "The dft of an image is taken and it's power spectrum is displayed.\n" - "Usage:\n" - "./dft [image_name -- default lena.jpg]\n"); + "Usage:\n %s [image_name -- default lena.jpg]\n",argv[0]); } const char* keys = @@ -24,18 +23,18 @@ const char* keys = int main(int argc, const char ** argv) { - help(); + help(argv); CommandLineParser parser(argc, argv, keys); if (parser.has("help")) { - help(); + help(argv); return 0; } string filename = parser.get(0); Mat img = imread(samples::findFile(filename), IMREAD_GRAYSCALE); if( img.empty() ) { - help(); + help(argv); printf("Cannot read image file: %s\n", filename.c_str()); return -1; } diff --git a/samples/cpp/facedetect.cpp b/samples/cpp/facedetect.cpp index 88d632b408..cf3a2a3e2f 100644 --- a/samples/cpp/facedetect.cpp +++ b/samples/cpp/facedetect.cpp @@ -1,6 +1,7 @@ #include "opencv2/objdetect.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" +#include "opencv2/videoio.hpp" #include using namespace std; diff --git a/samples/cpp/falsecolor.cpp b/samples/cpp/falsecolor.cpp index cb074bdcf0..ed422b39c1 100644 --- a/samples/cpp/falsecolor.cpp +++ b/samples/cpp/falsecolor.cpp @@ -14,15 +14,16 @@ struct ParamColorMap { }; String winName="False color"; -static const String ColorMaps[] = { "Autumn", "Bone", "Jet", "Winter", "Rainbow", "Ocean", "Summer", - "Spring", "Cool", "HSV", "Pink", "Hot", "Parula", "User defined (random)"}; +static const String ColorMaps[] = { "Autumn", "Bone", "Jet", "Winter", "Rainbow", "Ocean", "Summer", "Spring", + "Cool", "HSV", "Pink", "Hot", "Parula", "Magma", "Inferno", "Plasma", "Viridis", + "Cividis", "Twilight", "Twilight Shifted", "Turbo", "User defined (random)" }; static void TrackColorMap(int x, void *r) { ParamColorMap *p = (ParamColorMap*)r; Mat dst; p->iColormap= x; - if (x == COLORMAP_PARULA + 1) + if (x == COLORMAP_TURBO + 1) { Mat lutRND(256, 1, CV_8UC3); randu(lutRND, Scalar(0, 0, 0), Scalar(255, 255, 255)); @@ -98,7 +99,7 @@ int main(int argc, char** argv) namedWindow(winName); createTrackbar("colormap", winName,&p.iColormap,1,TrackColorMap,(void*)&p); setTrackbarMin("colormap", winName, COLORMAP_AUTUMN); - setTrackbarMax("colormap", winName, COLORMAP_PARULA+1); + setTrackbarMax("colormap", winName, COLORMAP_TURBO+1); setTrackbarPos("colormap", winName, -1); TrackColorMap(0, (void*)&p); diff --git a/samples/cpp/inpaint.cpp b/samples/cpp/inpaint.cpp index 175bff828c..cabf5528b4 100644 --- a/samples/cpp/inpaint.cpp +++ b/samples/cpp/inpaint.cpp @@ -8,13 +8,12 @@ using namespace cv; using namespace std; -static void help() +static void help( char** argv ) { cout << "\nCool inpainging demo. Inpainting repairs damage to images by floodfilling the damage \n" << "with surrounding image areas.\n" "Using OpenCV version %s\n" << CV_VERSION << "\n" - "Usage:\n" - "./inpaint [image_name -- Default fruits.jpg]\n" << endl; + "Usage:\n" << argv[0] <<" [image_name -- Default fruits.jpg]\n" << endl; cout << "Hot keys: \n" "\tESC - quit the program\n" @@ -48,7 +47,7 @@ static void onMouse( int event, int x, int y, int flags, void* ) int main( int argc, char** argv ) { cv::CommandLineParser parser(argc, argv, "{@image|fruits.jpg|}"); - help(); + help(argv); string filename = samples::findFile(parser.get("@image")); Mat img0 = imread(filename, IMREAD_COLOR); diff --git a/samples/cpp/peopledetect.cpp b/samples/cpp/peopledetect.cpp index c7640db0b7..9671f3b78c 100644 --- a/samples/cpp/peopledetect.cpp +++ b/samples/cpp/peopledetect.cpp @@ -31,9 +31,9 @@ public: // groupThreshold (set groupThreshold to 0 to turn off the grouping completely). vector found; if (m == Default) - hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2, false); + hog.detectMultiScale(img, found, 0, Size(8,8), Size(), 1.05, 2, false); else if (m == Daimler) - hog_d.detectMultiScale(img, found, 0.5, Size(8,8), Size(32,32), 1.05, 2, true); + hog_d.detectMultiScale(img, found, 0, Size(8,8), Size(), 1.05, 2, true); return found; } void adjustRect(Rect & r) const @@ -54,7 +54,7 @@ static const string keys = "{ help h | | print help message }" int main(int argc, char** argv) { CommandLineParser parser(argc, argv, keys); - parser.about("This sample demonstrates the use ot the HoG descriptor."); + parser.about("This sample demonstrates the use of the HoG descriptor."); if (parser.has("help")) { parser.printMessage(); @@ -114,7 +114,7 @@ int main(int argc, char** argv) imshow("People detector", frame); // interact with user - const char key = (char)waitKey(30); + const char key = (char)waitKey(1); if (key == 27 || key == 'q') // ESC { cout << "Exit requested" << endl; diff --git a/samples/cpp/polar_transforms.cpp b/samples/cpp/polar_transforms.cpp index b9b73c64cf..cdd653a29e 100644 --- a/samples/cpp/polar_transforms.cpp +++ b/samples/cpp/polar_transforms.cpp @@ -1,24 +1,18 @@ #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" +#include "opencv2/videoio.hpp" #include using namespace cv; -static void help( void ) -{ - printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n" - "Usage :\n" - "./polar_transforms [[camera number -- Default 0],[path_to_filename]]\n\n"); -} - int main( int argc, char** argv ) { VideoCapture capture; Mat log_polar_img, lin_polar_img, recovered_log_polar, recovered_lin_polar_img; - help(); - - CommandLineParser parser(argc, argv, "{@input|0|}"); + CommandLineParser parser(argc, argv, "{@input|0| camera device number or video file path}"); + parser.about("\nThis program illustrates usage of Linear-Polar and Log-Polar image transforms\n"); + parser.printMessage(); std::string arg = parser.get("@input"); if( arg.size() == 1 && isdigit(arg[0]) ) @@ -28,9 +22,7 @@ int main( int argc, char** argv ) if( !capture.isOpened() ) { - const char* name = argv[0]; fprintf(stderr,"Could not initialize capturing...\n"); - fprintf(stderr,"Usage: %s , or \n %s \n", name, name); return -1; } @@ -102,15 +94,6 @@ int main( int argc, char** argv ) drawMarker(src, Point(x, y), Scalar(0, 255, 0)); drawMarker(dst, Point(rho, phi), Scalar(0, 255, 0)); - -#if 0 //C version - CvMat src = frame; - CvMat dst = lin_polar_img; - CvMat inverse = recovered_lin_polar_img; - cvLinearPolar(&src, &dst, center, maxRadius, flags); - cvLinearPolar(&dst, &inverse, center, maxRadius,flags + WARP_INVERSE_MAP); -#endif - imshow("Src frame", src); imshow("Log-Polar", log_polar_img); imshow("Linear-Polar", lin_polar_img); diff --git a/samples/cpp/qrcode.cpp b/samples/cpp/qrcode.cpp index 41c19f1e5d..1e938f66f1 100644 --- a/samples/cpp/qrcode.cpp +++ b/samples/cpp/qrcode.cpp @@ -1,6 +1,7 @@ #include "opencv2/objdetect.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" +#include "opencv2/videoio.hpp" #include #include diff --git a/samples/cpp/smiledetect.cpp b/samples/cpp/smiledetect.cpp index ceac5e9686..4da0ce87e9 100644 --- a/samples/cpp/smiledetect.cpp +++ b/samples/cpp/smiledetect.cpp @@ -1,22 +1,23 @@ #include "opencv2/objdetect.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" +#include "opencv2/videoio.hpp" #include using namespace std; using namespace cv; -static void help() +static void help(const char** argv) { cout << "\nThis program demonstrates the smile detector.\n" - "Usage:\n" - "./smiledetect [--cascade= this is the frontal face classifier]\n" + "Usage:\n" << + argv[0] << " [--cascade= this is the frontal face classifier]\n" " [--smile-cascade=[]]\n" " [--scale=]\n" " [--try-flip]\n" " [video_filename|camera_index]\n\n" - "Example:\n" - "./smiledetect --cascade=\"data/haarcascades/haarcascade_frontalface_alt.xml\" --smile-cascade=\"data/haarcascades/haarcascade_smile.xml\" --scale=2.0\n\n" + "Example:\n" << + argv[0] << " --cascade=\"data/haarcascades/haarcascade_frontalface_alt.xml\" --smile-cascade=\"data/haarcascades/haarcascade_smile.xml\" --scale=2.0\n\n" "During execution:\n\tHit any key to quit.\n" "\tUsing OpenCV version " << CV_VERSION << "\n" << endl; } @@ -35,7 +36,7 @@ int main( int argc, const char** argv ) string inputName; bool tryflip; - help(); + help(argv); CascadeClassifier cascade, nestedCascade; double scale; @@ -46,7 +47,7 @@ int main( int argc, const char** argv ) "{try-flip||}{@input||}"); if (parser.has("help")) { - help(); + help(argv); return 0; } cascadeName = samples::findFile(parser.get("cascade")); @@ -56,7 +57,7 @@ int main( int argc, const char** argv ) scale = parser.get("scale"); if (!parser.check()) { - help(); + help(argv); return 1; } if (scale < 1) @@ -64,13 +65,13 @@ int main( int argc, const char** argv ) if( !cascade.load( cascadeName ) ) { cerr << "ERROR: Could not load face cascade" << endl; - help(); + help(argv); return -1; } if( !nestedCascade.load( nestedCascadeName ) ) { cerr << "ERROR: Could not load smile cascade" << endl; - help(); + help(argv); return -1; } if( inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1) ) @@ -108,7 +109,7 @@ int main( int argc, const char** argv ) else { cerr << "ERROR: Could not initiate capture" << endl; - help(); + help(argv); return -1; } diff --git a/samples/cpp/squares.cpp b/samples/cpp/squares.cpp index b466e32e97..36535d1ee0 100644 --- a/samples/cpp/squares.cpp +++ b/samples/cpp/squares.cpp @@ -138,8 +138,8 @@ static void drawSquares( Mat& image, const vector >& squares ) int main(int argc, char** argv) { - static const char* names[] = { "data/pic1.png", "data/pic2.png", "data/pic3.png", - "data/pic4.png", "data/pic5.png", "data/pic6.png", 0 }; + static const char* names[] = { "pic1.png", "pic2.png", "pic3.png", + "pic4.png", "pic5.png", "pic6.png", 0 }; help(argv[0]); if( argc > 1) diff --git a/samples/cpp/train_HOG.cpp b/samples/cpp/train_HOG.cpp index 3a1527d8f4..356ff0ec3f 100644 --- a/samples/cpp/train_HOG.cpp +++ b/samples/cpp/train_HOG.cpp @@ -2,7 +2,7 @@ #include "opencv2/highgui.hpp" #include "opencv2/ml.hpp" #include "opencv2/objdetect.hpp" - +#include "opencv2/videoio.hpp" #include #include diff --git a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp index dce34e7eb4..eeeba0002d 100644 --- a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp @@ -1,5 +1,5 @@ /** - * @file LinearBlend.cpp + * @file AddingImagesTrackbar.cpp * @brief Simple linear blender ( dst = alpha*src1 + beta*src2 ) * @author OpenCV team */ @@ -44,8 +44,8 @@ int main( void ) { //![load] /// Read images ( both have to be of the same size and type ) - src1 = imread("../data/LinuxLogo.jpg"); - src2 = imread("../data/WindowsLogo.jpg"); + src1 = imread( samples::findFile("LinuxLogo.jpg") ); + src2 = imread( samples::findFile("WindowsLogo.jpg") ); //![load] if( src1.empty() ) { cout << "Error loading src1 \n"; return -1; } diff --git a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp index 12cdebf00f..cdd33fb57b 100644 --- a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp @@ -1,5 +1,5 @@ /** - * @file LinearTransforms.cpp + * @file BasicLinearTransformsTrackbar.cpp * @brief Simple program to change contrast and brightness * @date Mon, June 6, 2011 * @author OpenCV team @@ -44,12 +44,12 @@ static void on_trackbar( int, void* ) int main( int argc, char** argv ) { /// Read image given by user - String imageName("../data/lena.jpg"); // by default + String imageName("lena.jpg"); // by default if (argc > 1) { imageName = argv[1]; } - image = imread( imageName ); + image = imread( samples::findFile( imageName ) ); /// Initialize values alpha = 1; diff --git a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp index 8f5492b4d4..7f1c55b868 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp @@ -18,8 +18,8 @@ using namespace std; int main( int argc, char** argv ) { //! [Load image] - CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ), IMREAD_COLOR ); + CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp index f2f0ec03c5..5bcc878965 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp @@ -34,7 +34,7 @@ int main( int argc, char** argv ) if (argc < 3) { cout << "Not enough parameters" << endl; - cout << "Usage:\n./MatchTemplate_Demo []" << endl; + cout << "Usage:\n" << argv[0] << " []" << endl; return -1; } @@ -51,7 +51,7 @@ int main( int argc, char** argv ) if(img.empty() || templ.empty() || (use_mask && mask.empty())) { cout << "Can't read one of the images" << endl; - return -1; + return EXIT_FAILURE; } //! [load_image] @@ -71,7 +71,7 @@ int main( int argc, char** argv ) //! [wait_key] waitKey(0); - return 0; + return EXIT_SUCCESS; //! [wait_key] } diff --git a/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp index fc45fc24dc..86167e519a 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp @@ -18,11 +18,11 @@ using namespace cv; int main(int argc, char** argv) { //! [Load image] - CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ), IMREAD_COLOR ); + CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); if( src.empty() ) { - return -1; + return EXIT_FAILURE; } //! [Load image] @@ -85,5 +85,5 @@ int main(int argc, char** argv) waitKey(); //! [Display] - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp index 0e6cb0a6ad..dc7b849f42 100644 --- a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp +++ b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp @@ -22,8 +22,8 @@ int main( int argc, char** argv ) { /// Read image given by user //! [basic-linear-transform-load] - CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" ); - Mat image = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" ); + Mat image = imread( samples::findFile( parser.get( "@input" ) ) ); if( image.empty() ) { cout << "Could not open or find the image!\n" << endl; @@ -67,7 +67,7 @@ int main( int argc, char** argv ) imshow("Original Image", image); imshow("New Image", new_image); - /// Wait until user press some key + /// Wait until the user press a key waitKey(); //! [basic-linear-transform-display] return 0; diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp index 4f5ab98a93..48b0c2e6e3 100644 --- a/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp @@ -31,8 +31,8 @@ void Dilation( int, void* ); int main( int argc, char** argv ) { /// Load an image - CommandLineParser parser( argc, argv, "{@input | ../data/LinuxLogo.jpg | input image}" ); - src = imread( parser.get( "@input" ), IMREAD_COLOR ); + CommandLineParser parser( argc, argv, "{@input | LinuxLogo.jpg | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp index ce71a3b118..3bc40d3b0d 100644 --- a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp @@ -33,13 +33,13 @@ void Morphology_Operations( int, void* ); int main( int argc, char** argv ) { //![load] - CommandLineParser parser( argc, argv, "{@input | ../data/baboon.jpg | input image}" ); - src = imread( parser.get( "@input" ), IMREAD_COLOR ); + CommandLineParser parser( argc, argv, "{@input | baboon.jpg | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); if (src.empty()) { std::cout << "Could not open or find the image!\n" << std::endl; std::cout << "Usage: " << argv[0] << " " << std::endl; - return -1; + return EXIT_FAILURE; } //![load] diff --git a/samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp b/samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp index 1cc7bf2edc..22192b5a4c 100644 --- a/samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp @@ -27,16 +27,16 @@ int main( int argc, char** argv ) " * [ESC] -> Close program \n" << endl; //![load] - const char* filename = argc >=2 ? argv[1] : "../data/chicky_512.png"; + const char* filename = argc >=2 ? argv[1] : "chicky_512.png"; // Loads an image - Mat src = imread( filename ); + Mat src = imread( samples::findFile( filename ) ); // Check if image is loaded fine if(src.empty()){ printf(" Error opening image\n"); - printf(" Program Arguments: [image_name -- default ../data/chicky_512.png] \n"); - return -1; + printf(" Program Arguments: [image_name -- default chicky_512.png] \n"); + return EXIT_FAILURE; } //![load] @@ -65,5 +65,5 @@ int main( int argc, char** argv ) } //![loop] - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp b/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp index 34d5733f75..f561c543fb 100644 --- a/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp @@ -33,14 +33,14 @@ int main( int argc, char ** argv ) namedWindow( window_name, WINDOW_AUTOSIZE ); /// Load the source image - const char* filename = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* filename = argc >=2 ? argv[1] : "lena.jpg"; - src = imread( filename, IMREAD_COLOR ); - if(src.empty()) + src = imread( samples::findFile( filename ), IMREAD_COLOR ); + if (src.empty()) { printf(" Error opening image\n"); - printf(" Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n"); - return -1; + printf(" Usage:\n %s [image_name-- default lena.jpg] \n", argv[0]); + return EXIT_FAILURE; } if( display_caption( "Original Image" ) != 0 ) diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp index a0f4b8894e..e44291c3a4 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp @@ -49,16 +49,16 @@ static void Threshold_Demo( int, void* ) int main( int argc, char** argv ) { //! [load] - String imageName("../data/stuff.jpg"); // by default + String imageName("stuff.jpg"); // by default if (argc > 1) { imageName = argv[1]; } - src = imread( imageName, IMREAD_COLOR ); // Load an image + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image if (src.empty()) { - cout << "Cannot read image: " << imageName << std::endl; + cout << "Cannot read the image: " << imageName << std::endl; return -1; } @@ -72,16 +72,16 @@ int main( int argc, char** argv ) //! [trackbar] createTrackbar( trackbar_type, window_name, &threshold_type, - max_type, Threshold_Demo ); // Create Trackbar to choose type of Threshold + max_type, Threshold_Demo ); // Create a Trackbar to choose type of Threshold createTrackbar( trackbar_value, window_name, &threshold_value, - max_value, Threshold_Demo ); // Create Trackbar to choose Threshold value + max_value, Threshold_Demo ); // Create a Trackbar to choose Threshold value //! [trackbar] Threshold_Demo( 0, 0 ); // Call the function to initialize - /// Wait until user finishes program + /// Wait until the user finishes the program waitKey(); return 0; } diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp index 0320e5a743..d2ced1fcfd 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold_inRange.cpp @@ -1,5 +1,6 @@ #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" +#include "opencv2/videoio.hpp" #include using namespace cv; diff --git a/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp b/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp index 7c977a37b9..51936c4b5e 100644 --- a/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp +++ b/samples/cpp/tutorial_code/ImgProc/changing_contrast_brightness_image/changing_contrast_brightness_image.cpp @@ -64,8 +64,8 @@ void on_gamma_correction_trackbar(int, void *) int main( int argc, char** argv ) { - CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" ); - img_original = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" ); + img_original = imread( samples::findFile( parser.get( "@input" ) ) ); if( img_original.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp b/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp index ac10f9cff1..9a909de966 100644 --- a/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp +++ b/samples/cpp/tutorial_code/ImgProc/morph_lines_detection/Morphology_3.cpp @@ -17,8 +17,8 @@ using namespace cv; int main(int argc, char** argv) { //! [load_image] - CommandLineParser parser(argc, argv, "{@input | ../data/notes.png | input image}"); - Mat src = imread(parser.get("@input"), IMREAD_COLOR); + CommandLineParser parser(argc, argv, "{@input | notes.png | input image}"); + Mat src = imread( samples::findFile( parser.get("@input") ), IMREAD_COLOR); if (src.empty()) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp index cd65f154ab..0ac1a969bd 100644 --- a/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp @@ -58,8 +58,8 @@ static void CannyThreshold(int, void*) int main( int argc, char** argv ) { //![load] - CommandLineParser parser( argc, argv, "{@input | ../data/fruits.jpg | input image}" ); - src = imread( parser.get( "@input" ), IMREAD_COLOR ); // Load an image + CommandLineParser parser( argc, argv, "{@input | fruits.jpg | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); // Load an image if( src.empty() ) { diff --git a/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp index 2e91467f25..65ca184749 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp @@ -18,8 +18,8 @@ using namespace std; int main( int argc, char** argv ) { //! [Load the image] - CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp index a1c3b1eac2..ea081f496a 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp @@ -18,7 +18,6 @@ namespace const std::string windowName = "Hough Circle Detection Demo"; const std::string cannyThresholdTrackbarName = "Canny threshold"; const std::string accumulatorThresholdTrackbarName = "Accumulator Threshold"; - const std::string usage = "Usage : tutorial_HoughCircle_Demo \n"; // initial and max values of the parameters of interests. const int cannyThresholdInitialValue = 100; @@ -56,17 +55,17 @@ int main(int argc, char** argv) Mat src, src_gray; // Read the image - String imageName("../data/stuff.jpg"); // by default + String imageName("stuff.jpg"); // by default if (argc > 1) { imageName = argv[1]; } - src = imread( imageName, IMREAD_COLOR ); + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); if( src.empty() ) { - std::cerr<<"Invalid input image\n"; - std::cout<\n";; return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp index 213d07cbc3..12fa051ba3 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp @@ -38,12 +38,12 @@ void Probabilistic_Hough( int, void* ); int main( int argc, char** argv ) { // Read the image - String imageName("../data/building.jpg"); // by default + String imageName("building.jpg"); // by default if (argc > 1) { imageName = argv[1]; } - src = imread( imageName, IMREAD_COLOR ); + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); if( src.empty() ) { help(); diff --git a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp index 80b6e84344..0c8b1f1674 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp @@ -26,14 +26,14 @@ int main( int argc, char** argv ) //![variables] //![load] - const char* imageName = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* imageName = argc >=2 ? argv[1] : "lena.jpg"; - src = imread( imageName, IMREAD_COLOR ); // Load an image + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image // Check if image is loaded fine if(src.empty()){ printf(" Error opening image\n"); - printf(" Program Arguments: [image_name -- default ../data/lena.jpg] \n"); + printf(" Program Arguments: [image_name -- default lena.jpg] \n"); return -1; } //![load] diff --git a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp index 9a9147899c..d4ff193c3f 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp @@ -19,11 +19,11 @@ void update_map( int &ind, Mat &map_x, Mat &map_y ); */ int main(int argc, const char** argv) { - CommandLineParser parser(argc, argv, "{@image |../data/chicky_512.png|input image name}"); + CommandLineParser parser(argc, argv, "{@image |chicky_512.png|input image name}"); std::string filename = parser.get(0); //! [Load] /// Load the image - Mat src = imread( filename, IMREAD_COLOR ); + Mat src = imread( samples::findFile( filename ), IMREAD_COLOR ); if (src.empty()) { std::cout << "Cannot read image: " << filename << std::endl; diff --git a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp index 16661d8d31..9b48f6aa77 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp @@ -19,10 +19,10 @@ using namespace std; int main( int argc, char** argv ) { cv::CommandLineParser parser(argc, argv, - "{@input |../data/lena.jpg|input image}" - "{ksize k|1|ksize (hit 'K' to increase its value)}" - "{scale s|1|scale (hit 'S' to increase its value)}" - "{delta d|0|delta (hit 'D' to increase its value)}" + "{@input |lena.jpg|input image}" + "{ksize k|1|ksize (hit 'K' to increase its value at run time)}" + "{scale s|1|scale (hit 'S' to increase its value at run time)}" + "{delta d|0|delta (hit 'D' to increase its value at run time)}" "{help h|false|show help message}"); cout << "The sample uses Sobel or Scharr OpenCV functions for edge detection\n\n"; @@ -43,13 +43,13 @@ int main( int argc, char** argv ) //![load] String imageName = parser.get("@input"); // As usual we load our source image (src) - image = imread( imageName, IMREAD_COLOR ); // Load an image + image = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image // Check if image is loaded fine if( image.empty() ) { printf("Error opening image: %s\n", imageName.c_str()); - return 1; + return EXIT_FAILURE; } //![load] @@ -95,7 +95,7 @@ int main( int argc, char** argv ) if(key == 27) { - return 0; + return EXIT_SUCCESS; } if (key == 'k' || key == 'K') @@ -120,5 +120,5 @@ int main( int argc, char** argv ) delta = 0; } } - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp index 52c7610389..2eeff1cf0d 100644 --- a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp @@ -25,15 +25,15 @@ RNG rng(12345); int main( int argc, char** argv ) { //![load] - const char* imageName = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* imageName = argc >=2 ? argv[1] : "lena.jpg"; // Loads an image - src = imread( imageName, IMREAD_COLOR ); // Load an image + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image // Check if image is loaded fine if( src.empty()) { printf(" Error opening image\n"); - printf(" Program Arguments: [image_name -- default ../data/lena.jpg] \n"); + printf(" Program Arguments: [image_name -- default lena.jpg] \n"); return -1; } //![load] diff --git a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp index 3b7f3a96b5..37fb6f6efa 100644 --- a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp @@ -26,16 +26,16 @@ int main ( int argc, char** argv ) const char* window_name = "filter2D Demo"; //![load] - const char* imageName = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* imageName = argc >=2 ? argv[1] : "lena.jpg"; // Loads an image - src = imread( imageName, IMREAD_COLOR ); // Load an image + src = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image if( src.empty() ) { printf(" Error opening image\n"); - printf(" Program Arguments: [image_name -- default ../data/lena.jpg] \n"); - return -1; + printf(" Program Arguments: [image_name -- default lena.jpg] \n"); + return EXIT_FAILURE; } //![load] @@ -70,5 +70,5 @@ int main ( int argc, char** argv ) ind++; } - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp b/samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp index 2a869413b3..0cec4456a5 100644 --- a/samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp @@ -12,16 +12,16 @@ using namespace std; int main(int argc, char** argv) { //![load] - const char* filename = argc >=2 ? argv[1] : "../data/smarties.png"; + const char* filename = argc >=2 ? argv[1] : "smarties.png"; // Loads an image - Mat src = imread( filename, IMREAD_COLOR ); + Mat src = imread( samples::findFile( filename ), IMREAD_COLOR ); // Check if image is loaded fine if(src.empty()){ printf(" Error opening image\n"); printf(" Program Arguments: [image_name -- default %s] \n", filename); - return -1; + return EXIT_FAILURE; } //![load] @@ -61,5 +61,5 @@ int main(int argc, char** argv) waitKey(); //![display] - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/ImgTrans/houghlines.cpp b/samples/cpp/tutorial_code/ImgTrans/houghlines.cpp index 0211d6cde2..0052c185bc 100644 --- a/samples/cpp/tutorial_code/ImgTrans/houghlines.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/houghlines.cpp @@ -1,5 +1,5 @@ /** - * @file houghclines.cpp + * @file houghlines.cpp * @brief This program demonstrates line finding with the Hough transform */ @@ -16,11 +16,11 @@ int main(int argc, char** argv) Mat dst, cdst, cdstP; //![load] - const char* default_file = "../data/sudoku.png"; + const char* default_file = "sudoku.png"; const char* filename = argc >=2 ? argv[1] : default_file; // Loads an image - Mat src = imread( filename, IMREAD_GRAYSCALE ); + Mat src = imread( samples::findFile( filename ), IMREAD_GRAYSCALE ); // Check if image is loaded fine if(src.empty()){ diff --git a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp index d038cbd874..201466e99b 100644 --- a/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/imageSegmentation.cpp @@ -15,8 +15,8 @@ int main(int argc, char *argv[]) { //! [load_image] // Load the image - CommandLineParser parser( argc, argv, "{@input | ../data/cards.png | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | cards.png | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp index 1083657ead..15990b515e 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp @@ -25,8 +25,8 @@ void thresh_callback(int, void* ); int main( int argc, char** argv ) { /// Load source image - CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | HappyFish.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp index f8eb194378..68fa2b97c5 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp @@ -26,8 +26,8 @@ int main( int argc, char** argv ) { //! [setup] /// Load source image - CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | stuff.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp index 2018b64bb2..81e5fd7588 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp @@ -25,8 +25,8 @@ void thresh_callback(int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | stuff.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp index 6640286feb..3b46f9e9b0 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp @@ -25,8 +25,8 @@ void thresh_callback(int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | stuff.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp index eaccd14e83..9b243ca53c 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp @@ -26,8 +26,8 @@ void thresh_callback(int, void* ); int main( int argc, char** argv ) { /// Load source image - CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | stuff.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp index 894b01ce56..a43024e557 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp @@ -38,8 +38,8 @@ void myHarris_function( int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/building.jpg | input image}" ); - src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | building.jpg | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ) ); if ( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp index 35672706bc..298f9523d3 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp @@ -28,8 +28,8 @@ void cornerHarris_demo( int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/building.jpg | input image}" ); - src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | building.jpg | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ) ); if ( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp index 853078bada..5004496a82 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp @@ -29,8 +29,8 @@ void goodFeaturesToTrack_Demo( int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" ); - src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | pic3.png | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp index 022cd456d1..f306f30414 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp @@ -30,8 +30,8 @@ void goodFeaturesToTrack_Demo( int, void* ); int main( int argc, char** argv ) { /// Load source image and convert it to gray - CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" ); - src = imread( parser.get( "@input" ) ); + CommandLineParser parser( argc, argv, "{@input | pic3.png | input image}" ); + src = imread( samples::findFile( parser.get( "@input" ) ) ); if( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp b/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp index 1181894482..83644b62bc 100644 --- a/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp +++ b/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp @@ -36,12 +36,12 @@ int main( void ) //![load] /// Read images ( both have to be of the same size and type ) - src1 = imread( "../data/LinuxLogo.jpg" ); - src2 = imread( "../data/WindowsLogo.jpg" ); + src1 = imread( samples::findFile("LinuxLogo.jpg") ); + src2 = imread( samples::findFile("WindowsLogo.jpg") ); //![load] - if( src1.empty() ) { cout << "Error loading src1" << endl; return -1; } - if( src2.empty() ) { cout << "Error loading src2" << endl; return -1; } + if( src1.empty() ) { cout << "Error loading src1" << endl; return EXIT_FAILURE; } + if( src2.empty() ) { cout << "Error loading src2" << endl; return EXIT_FAILURE; } //![blend_images] beta = ( 1.0 - alpha ); diff --git a/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp b/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp index 7121b16b35..e9e8096b31 100644 --- a/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp +++ b/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp @@ -8,25 +8,25 @@ using namespace cv; using namespace std; -static void help(void) +static void help(char ** argv) { cout << endl << "This program demonstrated the use of the discrete Fourier transform (DFT). " << endl - << "The dft of an image is taken and it's power spectrum is displayed." << endl + << "The dft of an image is taken and it's power spectrum is displayed." << endl << endl << "Usage:" << endl - << "./discrete_fourier_transform [image_name -- default ../data/lena.jpg]" << endl; + << argv[0] << " [image_name -- default lena.jpg]" << endl << endl; } int main(int argc, char ** argv) { - help(); + help(argv); - const char* filename = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* filename = argc >=2 ? argv[1] : "lena.jpg"; - Mat I = imread(filename, IMREAD_GRAYSCALE); + Mat I = imread( samples::findFile( filename ), IMREAD_GRAYSCALE); if( I.empty()){ cout << "Error opening image" << endl; - return -1; + return EXIT_FAILURE; } //! [expand] @@ -91,5 +91,5 @@ int main(int argc, char ** argv) imshow("spectrum magnitude", magI); waitKey(); - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp b/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp index 53a0cc40b5..0fece804b2 100644 --- a/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp +++ b/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp @@ -12,7 +12,7 @@ static void help(char* progName) << "This program shows how to filter images with mask: the write it yourself and the" << "filter2d way. " << endl << "Usage:" << endl - << progName << " [image_path -- default ../data/lena.jpg] [G -- grayscale] " << endl << endl; + << progName << " [image_path -- default lena.jpg] [G -- grayscale] " << endl << endl; } @@ -21,19 +21,19 @@ void Sharpen(const Mat& myImage,Mat& Result); int main( int argc, char* argv[]) { help(argv[0]); - const char* filename = argc >=2 ? argv[1] : "../data/lena.jpg"; + const char* filename = argc >=2 ? argv[1] : "lena.jpg"; Mat src, dst0, dst1; if (argc >= 3 && !strcmp("G", argv[2])) - src = imread( filename, IMREAD_GRAYSCALE); + src = imread( samples::findFile( filename ), IMREAD_GRAYSCALE); else - src = imread( filename, IMREAD_COLOR); + src = imread( samples::findFile( filename ), IMREAD_COLOR); if (src.empty()) { cerr << "Can't open image [" << filename << "]" << endl; - return -1; + return EXIT_FAILURE; } namedWindow("Input", WINDOW_AUTOSIZE); @@ -67,7 +67,7 @@ int main( int argc, char* argv[]) imshow( "Output", dst1 ); waitKey(); - return 0; + return EXIT_SUCCESS; } //! [basic_method] void Sharpen(const Mat& myImage,Mat& Result) diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp index b5b1b9229e..c5978e97fd 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp @@ -13,14 +13,14 @@ int main(int argc, char* argv[]) { //! [load] CommandLineParser parser(argc, argv, - "{@img1 | ../data/graf1.png | input image 1}" - "{@img2 | ../data/graf3.png | input image 2}" - "{@homography | ../data/H1to3p.xml | homography matrix}"); - Mat img1 = imread(parser.get("@img1"), IMREAD_GRAYSCALE); - Mat img2 = imread(parser.get("@img2"), IMREAD_GRAYSCALE); + "{@img1 | graf1.png | input image 1}" + "{@img2 | graf3.png | input image 2}" + "{@homography | H1to3p.xml | homography matrix}"); + Mat img1 = imread( samples::findFile( parser.get("@img1") ), IMREAD_GRAYSCALE); + Mat img2 = imread( samples::findFile( parser.get("@img2") ), IMREAD_GRAYSCALE); Mat homography; - FileStorage fs(parser.get("@homography"), FileStorage::READ); + FileStorage fs( samples::findFile( parser.get("@homography") ), FileStorage::READ); fs.getFirstTopLevelNode() >> homography; //! [load] diff --git a/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp b/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp index 5f671bbc13..acc2faa88b 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp @@ -52,8 +52,8 @@ void computeC2MC1(const Mat &R1, const Mat &tvec1, const Mat &R2, const Mat &tve void decomposeHomography(const string &img1Path, const string &img2Path, const Size &patternSize, const float squareSize, const string &intrinsicsPath) { - Mat img1 = imread(img1Path); - Mat img2 = imread(img2Path); + Mat img1 = imread( samples::findFile( img1Path) ); + Mat img2 = imread( samples::findFile( img2Path) ); vector corners1, corners2; bool found1 = findChessboardCorners(img1, patternSize, corners1); @@ -69,7 +69,7 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S vector objectPoints; calcChessboardCorners(patternSize, squareSize, objectPoints); - FileStorage fs(intrinsicsPath, FileStorage::READ); + FileStorage fs( samples::findFile( intrinsicsPath ), FileStorage::READ); Mat cameraMatrix, distCoeffs; fs["camera_matrix"] >> cameraMatrix; fs["distortion_coefficients"] >> distCoeffs; @@ -154,9 +154,9 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S const char* params = "{ help h | | print usage }" - "{ image1 | ../data/left02.jpg | path to the source chessboard image }" - "{ image2 | ../data/left01.jpg | path to the desired chessboard image }" - "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }" + "{ image1 | left02.jpg | path to the source chessboard image }" + "{ image2 | left01.jpg | path to the desired chessboard image }" + "{ intrinsics | left_intrinsics.yml | path to camera intrinsics }" "{ width bw | 9 | chessboard width }" "{ height bh | 6 | chessboard height }" "{ square_size | 0.025 | chessboard square size }"; diff --git a/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp b/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp index b0bb4da1cc..5bcb6dbb7b 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp @@ -65,8 +65,8 @@ void computeC2MC1(const Mat &R1, const Mat &tvec1, const Mat &R2, const Mat &tve void homographyFromCameraDisplacement(const string &img1Path, const string &img2Path, const Size &patternSize, const float squareSize, const string &intrinsicsPath) { - Mat img1 = imread(img1Path); - Mat img2 = imread(img2Path); + Mat img1 = imread( samples::findFile( img1Path ) ); + Mat img2 = imread( samples::findFile( img2Path ) ); //! [compute-poses] vector corners1, corners2; @@ -82,7 +82,7 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2 vector objectPoints; calcChessboardCorners(patternSize, squareSize, objectPoints); - FileStorage fs(intrinsicsPath, FileStorage::READ); + FileStorage fs( samples::findFile( intrinsicsPath ), FileStorage::READ); Mat cameraMatrix, distCoeffs; fs["camera_matrix"] >> cameraMatrix; fs["distortion_coefficients"] >> distCoeffs; @@ -170,9 +170,9 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2 const char* params = "{ help h | | print usage }" - "{ image1 | ../data/left02.jpg | path to the source chessboard image }" - "{ image2 | ../data/left01.jpg | path to the desired chessboard image }" - "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }" + "{ image1 | left02.jpg | path to the source chessboard image }" + "{ image2 | left01.jpg | path to the desired chessboard image }" + "{ intrinsics | left_intrinsics.yml | path to camera intrinsics }" "{ width bw | 9 | chessboard width }" "{ height bh | 6 | chessboard height }" "{ square_size | 0.025 | chessboard square size }"; diff --git a/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp b/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp index 1dadb4c354..3ab29280ae 100755 --- a/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.cpp @@ -10,8 +10,8 @@ namespace { void basicPanoramaStitching(const string &img1Path, const string &img2Path) { - Mat img1 = imread(img1Path); - Mat img2 = imread(img2Path); + Mat img1 = imread( samples::findFile( img1Path ) ); + Mat img2 = imread( samples::findFile( img2Path ) ); //! [camera-pose-from-Blender-at-location-1] Mat c1Mo = (Mat_(4,4) << 0.9659258723258972, 0.2588190734386444, 0.0, 1.5529145002365112, @@ -67,9 +67,9 @@ void basicPanoramaStitching(const string &img1Path, const string &img2Path) } const char* params - = "{ help h | | print usage }" - "{ image1 | ../data/Blender_Suzanne1.jpg | path to the first Blender image }" - "{ image2 | ../data/Blender_Suzanne2.jpg | path to the second Blender image }"; + = "{ help h | | print usage }" + "{ image1 | Blender_Suzanne1.jpg | path to the first Blender image }" + "{ image2 | Blender_Suzanne2.jpg | path to the second Blender image }"; } int main(int argc, char *argv[]) diff --git a/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp b/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp index 91abddffea..9d5bc2442e 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/perspective_correction.cpp @@ -19,8 +19,8 @@ Scalar randomColor( RNG& rng ) void perspectiveCorrection(const string &img1Path, const string &img2Path, const Size &patternSize, RNG &rng) { - Mat img1 = imread(img1Path); - Mat img2 = imread(img2Path); + Mat img1 = imread( samples::findFile(img1Path) ); + Mat img2 = imread( samples::findFile(img2Path) ); //! [find-corners] vector corners1, corners2; @@ -68,8 +68,8 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const const char* params = "{ help h | | print usage }" - "{ image1 | ../data/left02.jpg | path to the source chessboard image }" - "{ image2 | ../data/left01.jpg | path to the desired chessboard image }" + "{ image1 | left02.jpg | path to the source chessboard image }" + "{ image2 | left01.jpg | path to the desired chessboard image }" "{ width bw | 9 | chessboard width }" "{ height bh | 6 | chessboard height }"; } diff --git a/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp b/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp index 9be865eaab..37ebcac7be 100644 --- a/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp +++ b/samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp @@ -42,7 +42,7 @@ void calcChessboardCorners(Size boardSize, float squareSize, vector& co void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intrinsicsPath, const Size &patternSize, const float squareSize) { - Mat img = imread(imgPath); + Mat img = imread( samples::findFile( imgPath) ); Mat img_corners = img.clone(), img_pose = img.clone(); //! [find-chessboard-corners] @@ -69,7 +69,7 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri //! [compute-object-points] //! [load-intrinsics] - FileStorage fs(intrinsicsPath, FileStorage::READ); + FileStorage fs( samples::findFile( intrinsicsPath ), FileStorage::READ); Mat cameraMatrix, distCoeffs; fs["camera_matrix"] >> cameraMatrix; fs["distortion_coefficients"] >> distCoeffs; @@ -126,8 +126,8 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri const char* params = "{ help h | | print usage }" - "{ image | ../data/left04.jpg | path to a chessboard image }" - "{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }" + "{ image | left04.jpg | path to a chessboard image }" + "{ intrinsics | left_intrinsics.yml | path to camera intrinsics }" "{ width bw | 9 | chessboard width }" "{ height bh | 6 | chessboard height }" "{ square_size | 0.025 | chessboard square size }"; diff --git a/samples/cpp/tutorial_code/features2D/feature_description/SURF_matching_Demo.cpp b/samples/cpp/tutorial_code/features2D/feature_description/SURF_matching_Demo.cpp index 3fb34e9f1b..5c307bb1e2 100755 --- a/samples/cpp/tutorial_code/features2D/feature_description/SURF_matching_Demo.cpp +++ b/samples/cpp/tutorial_code/features2D/feature_description/SURF_matching_Demo.cpp @@ -11,15 +11,15 @@ using std::cout; using std::endl; const char* keys = - "{ help h | | Print help message. }" - "{ input1 | ../data/box.png | Path to input image 1. }" - "{ input2 | ../data/box_in_scene.png | Path to input image 2. }"; + "{ help h | | Print help message. }" + "{ input1 | box.png | Path to input image 1. }" + "{ input2 | box_in_scene.png | Path to input image 2. }"; int main( int argc, char* argv[] ) { CommandLineParser parser( argc, argv, keys ); - Mat img1 = imread( parser.get("input1"), IMREAD_GRAYSCALE ); - Mat img2 = imread( parser.get("input2"), IMREAD_GRAYSCALE ); + Mat img1 = imread( samples::findFile( parser.get("input1") ), IMREAD_GRAYSCALE ); + Mat img2 = imread( samples::findFile( parser.get("input2") ), IMREAD_GRAYSCALE ); if ( img1.empty() || img2.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/features2D/feature_detection/SURF_detection_Demo.cpp b/samples/cpp/tutorial_code/features2D/feature_detection/SURF_detection_Demo.cpp index ba9494ed2c..f1256e65e2 100755 --- a/samples/cpp/tutorial_code/features2D/feature_detection/SURF_detection_Demo.cpp +++ b/samples/cpp/tutorial_code/features2D/feature_detection/SURF_detection_Demo.cpp @@ -12,8 +12,8 @@ using std::endl; int main( int argc, char* argv[] ) { - CommandLineParser parser( argc, argv, "{@input | ../data/box.png | input image}" ); - Mat src = imread( parser.get( "@input" ), IMREAD_GRAYSCALE ); + CommandLineParser parser( argc, argv, "{@input | box.png | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_GRAYSCALE ); if ( src.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.cpp b/samples/cpp/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.cpp index 1724709828..e968ab2a0f 100755 --- a/samples/cpp/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.cpp +++ b/samples/cpp/tutorial_code/features2D/feature_flann_matcher/SURF_FLANN_matching_Demo.cpp @@ -11,15 +11,15 @@ using std::cout; using std::endl; const char* keys = - "{ help h | | Print help message. }" - "{ input1 | ../data/box.png | Path to input image 1. }" - "{ input2 | ../data/box_in_scene.png | Path to input image 2. }"; + "{ help h | | Print help message. }" + "{ input1 | box.png | Path to input image 1. }" + "{ input2 | box_in_scene.png | Path to input image 2. }"; int main( int argc, char* argv[] ) { CommandLineParser parser( argc, argv, keys ); - Mat img1 = imread( parser.get("input1"), IMREAD_GRAYSCALE ); - Mat img2 = imread( parser.get("input2"), IMREAD_GRAYSCALE ); + Mat img1 = imread( samples::findFile( parser.get("input1") ), IMREAD_GRAYSCALE ); + Mat img2 = imread( samples::findFile( parser.get("input2") ), IMREAD_GRAYSCALE ); if ( img1.empty() || img2.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.cpp b/samples/cpp/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.cpp index 231cda887d..2aa0bcd9cb 100755 --- a/samples/cpp/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.cpp +++ b/samples/cpp/tutorial_code/features2D/feature_homography/SURF_FLANN_matching_homography_Demo.cpp @@ -13,15 +13,15 @@ using std::cout; using std::endl; const char* keys = - "{ help h | | Print help message. }" - "{ input1 | ../data/box.png | Path to input image 1. }" - "{ input2 | ../data/box_in_scene.png | Path to input image 2. }"; + "{ help h | | Print help message. }" + "{ input1 | box.png | Path to input image 1. }" + "{ input2 | box_in_scene.png | Path to input image 2. }"; int main( int argc, char* argv[] ) { CommandLineParser parser( argc, argv, keys ); - Mat img_object = imread( parser.get("input1"), IMREAD_GRAYSCALE ); - Mat img_scene = imread( parser.get("input2"), IMREAD_GRAYSCALE ); + Mat img_object = imread( samples::findFile( parser.get("input1") ), IMREAD_GRAYSCALE ); + Mat img_scene = imread( samples::findFile( parser.get("input2") ), IMREAD_GRAYSCALE ); if ( img_object.empty() || img_scene.empty() ) { cout << "Could not open or find the image!\n" << endl; diff --git a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp index 456286741e..80151ec8a9 100644 --- a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp +++ b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp @@ -4,19 +4,18 @@ #include #include -#include //! [includes] //! [namespace] using namespace cv; +using namespace std; //! [namespace] -using namespace std; int main( int argc, char** argv ) { //! [load] - String imageName( "../data/HappyFish.jpg" ); // by default + String imageName( "HappyFish.jpg" ); // by default if( argc > 1) { imageName = argv[1]; @@ -28,7 +27,7 @@ int main( int argc, char** argv ) //! [mat] //! [imread] - image = imread( imageName, IMREAD_COLOR ); // Read the file + image = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Read the file //! [imread] if( image.empty() ) // Check for invalid input diff --git a/samples/cpp/tutorial_code/introduction/windows_visual_studio_opencv/introduction_windows_vs.cpp b/samples/cpp/tutorial_code/introduction/windows_visual_studio_opencv/introduction_windows_vs.cpp index 41fe2b1e9c..0080e2c74d 100644 --- a/samples/cpp/tutorial_code/introduction/windows_visual_studio_opencv/introduction_windows_vs.cpp +++ b/samples/cpp/tutorial_code/introduction/windows_visual_studio_opencv/introduction_windows_vs.cpp @@ -10,7 +10,7 @@ int main( int argc, char** argv ) { if( argc != 2) { - cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; + cout <<" Usage: " << argv[0] << " ImageToLoadAndDisplay" << endl; return -1; } @@ -28,4 +28,4 @@ int main( int argc, char** argv ) waitKey(0); // Wait for a keystroke in the window return 0; -} \ No newline at end of file +} diff --git a/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp b/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp index aa6107c120..c0ca672436 100644 --- a/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp +++ b/samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp @@ -96,11 +96,11 @@ int main(int argc, char** argv) { //! [pre-process] // Load image - CommandLineParser parser(argc, argv, "{@input | ../data/pca_test1.jpg | input image}"); + CommandLineParser parser(argc, argv, "{@input | pca_test1.jpg | input image}"); parser.about( "This program demonstrates how to use OpenCV PCA to extract the orientation of an object.\n" ); parser.printMessage(); - Mat src = imread(parser.get("@input")); + Mat src = imread( samples::findFile( parser.get("@input") ) ); // Check if image is loaded successfully if(src.empty()) @@ -142,5 +142,5 @@ int main(int argc, char** argv) imshow("output", src); waitKey(); - return 0; + return EXIT_SUCCESS; } diff --git a/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp b/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp index 2115549e30..063aeb26c6 100644 --- a/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp +++ b/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp @@ -1,7 +1,7 @@ #include "opencv2/objdetect.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" - +#include "opencv2/videoio.hpp" #include using namespace std; @@ -19,16 +19,16 @@ int main( int argc, const char** argv ) { CommandLineParser parser(argc, argv, "{help h||}" - "{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|Path to face cascade.}" - "{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|Path to eyes cascade.}" + "{face_cascade|data/haarcascades/haarcascade_frontalface_alt.xml|Path to face cascade.}" + "{eyes_cascade|data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|Path to eyes cascade.}" "{camera|0|Camera device number.}"); parser.about( "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n" "You can use Haar or LBP features.\n\n" ); parser.printMessage(); - String face_cascade_name = parser.get("face_cascade"); - String eyes_cascade_name = parser.get("eyes_cascade"); + String face_cascade_name = samples::findFile( parser.get("face_cascade") ); + String eyes_cascade_name = samples::findFile( parser.get("eyes_cascade") ); //-- 1. Load the cascades if( !face_cascade.load( face_cascade_name ) ) diff --git a/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp b/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp index c566dc7125..3ad42820c4 100644 --- a/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp +++ b/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp @@ -26,18 +26,18 @@ using namespace cv; int main( int argc, char *argv[] ) { - CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" ); - Mat src = imread( parser.get( "@input" ), IMREAD_COLOR ); + CommandLineParser parser( argc, argv, "{@input | HappyFish.jpg | input image}" ); + Mat src = imread( samples::findFile( parser.get( "@input" ) ), IMREAD_COLOR ); if ( src.empty() ) { cout << "Could not open or find the image!\n" << endl; cout << "Usage: " << argv[0] << " " << endl; - return -1; + return EXIT_FAILURE; } - Mat gray = Mat( src.size(), CV_8UC1 ); - Mat color_boost = Mat( src.size(), CV_8UC3 ); + Mat gray, color_boost; decolor( src, gray, color_boost ); + imshow( "Source Image", src ); imshow( "grayscale", gray ); imshow( "color_boost", color_boost ); waitKey(0); diff --git a/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp b/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp index 244e31ad58..c2d8864009 100644 --- a/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp +++ b/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp @@ -25,8 +25,8 @@ using namespace cv; int main(int argc, char* argv[]) { int num,type; - CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}"); - Mat src = imread(parser.get("@input"), IMREAD_COLOR); + CommandLineParser parser(argc, argv, "{@input | lena.jpg | input image}"); + Mat src = imread( samples::findFile( parser.get("@input") ), IMREAD_COLOR); if(src.empty()) { diff --git a/samples/cpp/tutorial_code/video/bg_sub.cpp b/samples/cpp/tutorial_code/video/bg_sub.cpp index 3180abbb8a..5a5d9eaace 100644 --- a/samples/cpp/tutorial_code/video/bg_sub.cpp +++ b/samples/cpp/tutorial_code/video/bg_sub.cpp @@ -16,9 +16,9 @@ using namespace cv; using namespace std; const char* params - = "{ help h | | Print usage }" - "{ input | ../data/vtest.avi | Path to a video or a sequence of image }" - "{ algo | MOG2 | Background subtraction method (KNN, MOG2) }"; + = "{ help h | | Print usage }" + "{ input | vtest.avi | Path to a video or a sequence of image }" + "{ algo | MOG2 | Background subtraction method (KNN, MOG2) }"; int main(int argc, char* argv[]) { @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) //! [create] //! [capture] - VideoCapture capture(parser.get("input")); + VideoCapture capture( samples::findFile( parser.get("input") ) ); if (!capture.isOpened()){ //error in opening the video input cerr << "Unable to open: " << parser.get("input") << endl; diff --git a/samples/cpp/tutorial_code/video/optical_flow/optical_flow.cpp b/samples/cpp/tutorial_code/video/optical_flow/optical_flow.cpp index 9b03d331a9..0394c6abd4 100644 --- a/samples/cpp/tutorial_code/video/optical_flow/optical_flow.cpp +++ b/samples/cpp/tutorial_code/video/optical_flow/optical_flow.cpp @@ -16,7 +16,7 @@ int main(int argc, char **argv) " https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4"; const string keys = "{ h help | | print this help message }" - "{ @image || path to image file }"; + "{ @image | vtest.avi | path to image file }"; CommandLineParser parser(argc, argv, keys); parser.about(about); if (parser.has("help")) @@ -24,7 +24,7 @@ int main(int argc, char **argv) parser.printMessage(); return 0; } - string filename = parser.get("@image"); + string filename = samples::findFile(parser.get("@image")); if (!parser.check()) { parser.printErrors(); diff --git a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp index 2d1282d89d..e7889f08ea 100644 --- a/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp +++ b/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp @@ -24,14 +24,14 @@ const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio int main(int argc, char* argv[]) { CommandLineParser parser(argc, argv, - "{@img1 | ../data/graf1.png | input image 1}" - "{@img2 | ../data/graf3.png | input image 2}" - "{@homography | ../data/H1to3p.xml | homography matrix}"); - Mat img1 = imread(parser.get("@img1"), IMREAD_GRAYSCALE); - Mat img2 = imread(parser.get("@img2"), IMREAD_GRAYSCALE); + "{@img1 | graf1.png | input image 1}" + "{@img2 | graf3.png | input image 2}" + "{@homography | H1to3p.xml | homography matrix}"); + Mat img1 = imread( samples::findFile( parser.get("@img1") ), IMREAD_GRAYSCALE); + Mat img2 = imread( samples::findFile( parser.get("@img2") ), IMREAD_GRAYSCALE); Mat homography; - FileStorage fs(parser.get("@homography"), FileStorage::READ); + FileStorage fs( samples::findFile( parser.get("@homography") ), FileStorage::READ); fs.getFirstTopLevelNode() >> homography; vector kpts1, kpts2; diff --git a/samples/cpp/warpPerspective_demo.cpp b/samples/cpp/warpPerspective_demo.cpp index 04e1e95d74..4a9069f5d2 100644 --- a/samples/cpp/warpPerspective_demo.cpp +++ b/samples/cpp/warpPerspective_demo.cpp @@ -20,7 +20,7 @@ static void help(char** argv) cout << "\nThis is a demo program shows how perspective transformation applied on an image, \n" "Using OpenCV version " << CV_VERSION << endl; - cout << "\nUsage:\n" << argv[0] << " [image_name -- Default data/right.jpg]\n" << endl; + cout << "\nUsage:\n" << argv[0] << " [image_name -- Default right.jpg]\n" << endl; cout << "\nHot keys: \n" "\tESC, q - quit the program\n" @@ -45,7 +45,7 @@ bool validation_needed = true; int main(int argc, char** argv) { help(argv); - CommandLineParser parser(argc, argv, "{@input| data/right.jpg |}"); + CommandLineParser parser(argc, argv, "{@input| right.jpg |}"); string filename = samples::findFile(parser.get("@input")); Mat original_image = imread( filename ); @@ -81,7 +81,7 @@ int main(int argc, char** argv) { line(image, roi_corners[i-1], roi_corners[(i)], Scalar(0, 0, 255), 2); circle(image, roi_corners[i], 5, Scalar(0, 255, 0), 3); - putText(image, labels[i].c_str(), roi_corners[i], QT_FONT_NORMAL, 0.8, Scalar(255, 0, 0), 2); + putText(image, labels[i].c_str(), roi_corners[i], FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255, 0, 0), 2); } } imshow( windowTitle, image ); @@ -94,7 +94,7 @@ int main(int argc, char** argv) { line(image, roi_corners[i], roi_corners[(i + 1) % 4], Scalar(0, 0, 255), 2); circle(image, roi_corners[i], 5, Scalar(0, 255, 0), 3); - putText(image, labels[i].c_str(), roi_corners[i], QT_FONT_NORMAL, 0.8, Scalar(255, 0, 0), 2); + putText(image, labels[i].c_str(), roi_corners[i], FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255, 0, 0), 2); } imshow( windowTitle, image ); diff --git a/samples/cpp/watershed.cpp b/samples/cpp/watershed.cpp index f3fefa7d4e..9c48ae0ee3 100644 --- a/samples/cpp/watershed.cpp +++ b/samples/cpp/watershed.cpp @@ -9,11 +9,10 @@ using namespace cv; using namespace std; -static void help() +static void help(char** argv) { cout << "\nThis program demonstrates the famous watershed segmentation algorithm in OpenCV: watershed()\n" - "Usage:\n" - "./watershed [image_name -- default is fruits.jpg]\n" << endl; + "Usage:\n" << argv[0] <<" [image_name -- default is fruits.jpg]\n" << endl; cout << "Hot keys: \n" @@ -51,7 +50,7 @@ int main( int argc, char** argv ) cv::CommandLineParser parser(argc, argv, "{help h | | }{ @input | fruits.jpg | }"); if (parser.has("help")) { - help(); + help(argv); return 0; } string filename = samples::findFile(parser.get("@input")); @@ -59,10 +58,11 @@ int main( int argc, char** argv ) if( img0.empty() ) { - cout << "Couldn't open image " << filename << ". Usage: watershed \n"; + cout << "Couldn't open image "; + help(argv); return 0; } - help(); + help(argv); namedWindow( "image", 1 ); img0.copyTo(img); diff --git a/samples/tapi/hog.cpp b/samples/tapi/hog.cpp index 9ed93cb238..3425fe69ba 100644 --- a/samples/tapi/hog.cpp +++ b/samples/tapi/hog.cpp @@ -7,7 +7,6 @@ #include #include #include "opencv2/imgcodecs.hpp" -#include #include #include #include