From ef7185ce43d3ace32443c6ea903320d3a333576d Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Viel Date: Wed, 1 Jul 2020 00:43:42 +0200 Subject: [PATCH 01/16] Fix genericity of computeNodeStatistics that couldn't compute stats properly on sub-nodes --- modules/flann/include/opencv2/flann/kmeans_index.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index f743d75224..695ef6e8b1 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -663,7 +663,7 @@ private: memset(mean,0,veclen_*sizeof(DistanceType)); - for (size_t i=0; i<(size_t)indices_length; ++i) { + for (int i=0; i(), veclen_); } for (size_t j=0; j(), veclen_); DistanceType tmp = 0; From 93a6be836cba1dff3ebd3c7f1b3d3afbbafe1a47 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Viel Date: Wed, 1 Jul 2020 18:15:01 +0200 Subject: [PATCH 02/16] Remove duplicate line --- .../flann/include/opencv2/flann/hierarchical_clustering_index.h | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index 20304ede73..d830bc6a00 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -386,7 +386,6 @@ public: throw FLANNException("Unknown algorithm for choosing initial centers."); } - trees_ = get_param(params,"trees",4); root = new NodePtr[trees_]; indices = new int*[trees_]; From 482cacd420ada7c0bd0fe46a500b62cb76439955 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Viel Date: Wed, 1 Jul 2020 18:27:07 +0200 Subject: [PATCH 03/16] Mix of 32 and 64bits vector types prevents vectorisation for distance computation. Argument "a" is of type ElementType* that is either int* or float*, while b was double*. Mixing types prevents the possibility to use SSE or AVX instructions. On implementation without SIMD instructions, this doesn't show any impact on performance. --- .../include/opencv2/flann/kmeans_index.h | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index f743d75224..b556b4ad8a 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -726,15 +726,6 @@ private: } - cv::AutoBuffer dcenters_buf(branching*veclen_); - Matrix dcenters(dcenters_buf.data(), branching, veclen_); - for (int i=0; i radiuses(branching); cv::AutoBuffer count_buf(branching); int* count = count_buf.data(); @@ -748,10 +739,10 @@ private: int* belongs_to = belongs_to_buf.data(); for (int i=0; inew_sq_dist) { belongs_to[i] = j; sq_dist = new_sq_dist; @@ -763,6 +754,15 @@ private: count[belongs_to[i]]++; } + cv::AutoBuffer dcenters_buf(branching*veclen_); + Matrix dcenters(dcenters_buf.data(), branching, veclen_); + for (int i=0; i Date: Wed, 1 Jul 2020 18:52:05 +0200 Subject: [PATCH 04/16] Precompute the divisor to ensure that no kind of compiler would process it on the fly at each call. --- modules/flann/include/opencv2/flann/dist.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index b092b531a1..4cf32d5987 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -506,7 +506,7 @@ struct Hamming2 const uint64_t* pa = reinterpret_cast(a); const uint64_t* pb = reinterpret_cast(b); ResultType result = 0; - size /= (sizeof(uint64_t)/sizeof(unsigned char)); + size /= long_word_size_; for(size_t i = 0; i < size; ++i ) { result += popcnt64(*pa ^ *pb); ++pa; @@ -516,7 +516,7 @@ struct Hamming2 const uint32_t* pa = reinterpret_cast(a); const uint32_t* pb = reinterpret_cast(b); ResultType result = 0; - size /= (sizeof(uint32_t)/sizeof(unsigned char)); + size /= long_word_size_; for(size_t i = 0; i < size; ++i ) { result += popcnt32(*pa ^ *pb); ++pa; @@ -525,6 +525,13 @@ struct Hamming2 #endif return result; } + +private: +#ifdef FLANN_PLATFORM_64_BIT + static const size_t long_word_size_ = sizeof(uint64_t)/sizeof(unsigned char); +#else + static const size_t long_word_size_ = sizeof(uint32_t)/sizeof(unsigned char); +#endif }; From 6a045fd67870af15d127cc4e78df0bc7f148318f Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Viel Date: Wed, 1 Jul 2020 18:20:02 +0200 Subject: [PATCH 05/16] Fix arguments list in loadindex for histogram intersection --- modules/flann/src/miniflann.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp index 98baaa6a9a..1f698e7871 100644 --- a/modules/flann/src/miniflann.cpp +++ b/modules/flann/src/miniflann.cpp @@ -801,7 +801,7 @@ bool Index::load(InputArray _data, const String& filename) loadIndex< ::cvflann::MaxDistance >(this, index, data, fin); break; case FLANN_DIST_HIST_INTERSECT: - loadIndex< ::cvflann::HistIntersectionDistance >(index, data, fin); + loadIndex< ::cvflann::HistIntersectionDistance >(this, index, data, fin); break; case FLANN_DIST_HELLINGER: loadIndex< ::cvflann::HellingerDistance >(this, index, data, fin); From cb3a098b251882a8d42fe5849cd7cfb0a909ed46 Mon Sep 17 00:00:00 2001 From: Heritier Kinke Date: Thu, 2 Jul 2020 03:27:34 +0200 Subject: [PATCH 06/16] forget to look in sub folder of include/openblas --- cmake/OpenCVFindOpenBLAS.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVFindOpenBLAS.cmake b/cmake/OpenCVFindOpenBLAS.cmake index ae2daaa194..6cb486d95d 100644 --- a/cmake/OpenCVFindOpenBLAS.cmake +++ b/cmake/OpenCVFindOpenBLAS.cmake @@ -46,6 +46,7 @@ SET(Open_BLAS_INCLUDE_SEARCH_PATHS $ENV{OpenBLAS_HOME} $ENV{OpenBLAS_HOME}/include + $ENV{OpenBLAS_HOME}/include/openblas /opt/OpenBLAS/include /usr/local/include/openblas /usr/include/openblas @@ -103,4 +104,4 @@ MARK_AS_ADVANCED( OpenBLAS_INCLUDE_DIR OpenBLAS_LIB OpenBLAS -) \ No newline at end of file +) From 00e1bc49c8c38c8d57deae4eb0841dea2d05558b Mon Sep 17 00:00:00 2001 From: Ken Shirriff Date: Thu, 2 Jul 2020 03:58:53 -0700 Subject: [PATCH 07/16] Merge pull request #17708 from shirriff:patch-1 Clarify component statistics documentation * Change ConnectedComponentsTypes documentation Change from "algorithm output formats" to "statistics" because it specifies types of statistics, not formats. * Documentation: clarify component statistics Explain that ConnectedComponentTypes selects a statistic. --- modules/imgproc/include/opencv2/imgproc.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index f6b5339194..91c1ec52fc 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -387,7 +387,7 @@ enum FloodFillFlags { //! @addtogroup imgproc_shape //! @{ -//! connected components algorithm output formats +//! connected components statistics enum ConnectedComponentsTypes { CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding //!< box in the horizontal direction. @@ -3881,9 +3881,9 @@ parallel framework is enabled and if the rows of the image are at least twice th @param image the 8-bit single-channel image to be labeled @param labels destination labeled image -@param stats statistics output for each label, including the background label, see below for -available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of -#ConnectedComponentsTypes. The data type is CV_32S. +@param stats statistics output for each label, including the background label. +Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S. @param centroids centroid output for each label, including the background label. Centroids are accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively @@ -3897,9 +3897,9 @@ CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponents /** @overload @param image the 8-bit single-channel image to be labeled @param labels destination labeled image -@param stats statistics output for each label, including the background label, see below for -available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of -#ConnectedComponentsTypes. The data type is CV_32S. +@param stats statistics output for each label, including the background label. +Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S. @param centroids centroid output for each label, including the background label. Centroids are accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively From 65dbbf712dbde71d9a7e77f0049e0162a0d99bd0 Mon Sep 17 00:00:00 2001 From: Liubov Batanina Date: Fri, 3 Jul 2020 21:07:08 +0300 Subject: [PATCH 08/16] Merge pull request #17733 from l-bat:tiny_yolov4 * Supported yolov4-tiny * Added comments --- modules/dnn/src/darknet/darknet_io.cpp | 50 ++++++++++++++++++++-- modules/dnn/test/test_darknet_importer.cpp | 6 +++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/modules/dnn/src/darknet/darknet_io.cpp b/modules/dnn/src/darknet/darknet_io.cpp index 664a1d617b..f6504b96c7 100644 --- a/modules/dnn/src/darknet/darknet_io.cpp +++ b/modules/dnn/src/darknet/darknet_io.cpp @@ -363,6 +363,28 @@ namespace cv { fused_layer_names.push_back(last_layer); } + void setSlice(int input_index, int split_size, int group_id) + { + int begin[] = {0, split_size * group_id, 0, 0}; + cv::dnn::DictValue paramBegin = cv::dnn::DictValue::arrayInt(begin, 4); + + int end[] = {-1, begin[1] + split_size, -1, -1}; + cv::dnn::DictValue paramEnd = cv::dnn::DictValue::arrayInt(end, 4); + + darknet::LayerParameter lp; + lp.layer_name = cv::format("slice_%d", layer_id); + lp.layer_type = "Slice"; + lp.layerParams.set("begin", paramBegin); + lp.layerParams.set("end", paramEnd); + + lp.bottom_indexes.push_back(fused_layer_names.at(input_index)); + net->layers.push_back(lp); + + layer_id++; + last_layer = lp.layer_name; + fused_layer_names.push_back(last_layer); + } + void setReorg(int stride) { cv::dnn::LayerParams reorg_params; @@ -717,6 +739,7 @@ namespace cv { { std::string bottom_layers = getParam(layer_params, "layers", ""); CV_Assert(!bottom_layers.empty()); + int groups = getParam(layer_params, "groups", 1); std::vector layers_vec = getNumbers(bottom_layers); tensor_shape[0] = 0; @@ -725,10 +748,31 @@ namespace cv { tensor_shape[0] += net->out_channels_vec[layers_vec[k]]; } - if (layers_vec.size() == 1) - setParams.setIdentity(layers_vec.at(0)); + if (groups > 1) + { + int group_id = getParam(layer_params, "group_id", 0); + tensor_shape[0] /= groups; + int split_size = tensor_shape[0] / layers_vec.size(); + for (size_t k = 0; k < layers_vec.size(); ++k) + setParams.setSlice(layers_vec[k], split_size, group_id); + + if (layers_vec.size() > 1) + { + // layer ids in layers_vec - inputs of Slice layers + // after adding offset to layers_vec: layer ids - ouputs of Slice layers + for (size_t k = 0; k < layers_vec.size(); ++k) + layers_vec[k] += layers_vec.size(); + + setParams.setConcat(layers_vec.size(), layers_vec.data()); + } + } else - setParams.setConcat(layers_vec.size(), layers_vec.data()); + { + if (layers_vec.size() == 1) + setParams.setIdentity(layers_vec.at(0)); + else + setParams.setConcat(layers_vec.size(), layers_vec.data()); + } } else if (layer_type == "dropout" || layer_type == "cost") { diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 607761ed2f..fcc9088b00 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -627,6 +627,12 @@ TEST_P(Test_Darknet_layers, reorg) testDarknetLayer("reorg"); } +TEST_P(Test_Darknet_layers, route) +{ + testDarknetLayer("route"); + testDarknetLayer("route_multi"); +} + TEST_P(Test_Darknet_layers, maxpool) { #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000) From 56b5a7d9772c75795d0b2d644c9ddcbcc42ef03d Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 3 Jul 2020 19:31:41 +0000 Subject: [PATCH 09/16] cmake: fix ENABLE_PROFILING --- cmake/OpenCVCompilerOptions.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 476156f256..9ac671dd34 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -189,7 +189,6 @@ if(CV_GCC OR CV_CLANG) # Profiling? if(ENABLE_PROFILING) - add_extra_compiler_option("-pg -g") # turn off incompatible options foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS) @@ -197,6 +196,9 @@ if(CV_GCC OR CV_CLANG) string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}") string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}") endforeach() + # -pg should be placed both in the linker and in the compiler settings + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") + add_extra_compiler_option("-pg -g") else() if(MSVC) # TODO: Clang/C2 is not supported From 65f87b114b545b73a43232c15e0bd345406c4896 Mon Sep 17 00:00:00 2001 From: pemmanuelviel Date: Sat, 4 Jul 2020 19:15:44 +0200 Subject: [PATCH 10/16] Merge pull request #17722 from pemmanuelviel:pev--replace-asserts * Clean: replace C style asserts by CV_Assert and CV_DbgAssert * Try fixing warning on Windows compilation * Another way trying to fix warnings on Win * Fixing warnings with some compilers: Some compilers warn on systematic exit preventing to execute the code that follows. This is why assert(0) that exits only in debug was working, but not CV_Assert or CV_Error that exit both in release and debug, even if with different behavior. In addition, other compilers complain when return 0 is removed from getKey(), even if before we have a statement leading to systematic exit. * Disable "unreachable code" warnings for Win compilers so we can use proper CV_Error --- .../include/opencv2/flann/autotuned_index.h | 2 +- .../include/opencv2/flann/flann_base.hpp | 1 - .../flann/hierarchical_clustering_index.h | 9 ++++----- .../include/opencv2/flann/index_testing.h | 1 - .../include/opencv2/flann/kdtree_index.h | 5 ++--- .../opencv2/flann/kdtree_single_index.h | 11 +++++----- .../include/opencv2/flann/kmeans_index.h | 9 ++++----- .../flann/include/opencv2/flann/lsh_index.h | 20 +++++++++++++------ .../flann/include/opencv2/flann/lsh_table.h | 16 +++++++++++---- .../flann/include/opencv2/flann/nn_index.h | 10 +++++----- .../include/opencv2/flann/simplex_downhill.h | 2 +- 11 files changed, 48 insertions(+), 38 deletions(-) diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index eb4554f077..54a60a73d6 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -497,7 +497,7 @@ private: const int nn = 1; const size_t SAMPLE_COUNT = 1000; - assert(bestIndex_ != NULL); // must have a valid index + CV_Assert(bestIndex_ != NULL && "Requires a valid index"); // must have a valid index float speedup = 0; diff --git a/modules/flann/include/opencv2/flann/flann_base.hpp b/modules/flann/include/opencv2/flann/flann_base.hpp index 83606d232f..641fdb01e2 100644 --- a/modules/flann/include/opencv2/flann/flann_base.hpp +++ b/modules/flann/include/opencv2/flann/flann_base.hpp @@ -34,7 +34,6 @@ //! @cond IGNORED #include -#include #include #include "general.h" diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index d830bc6a00..a52166d3c4 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -153,7 +152,7 @@ private: int n = indices_length; int rnd = rand_int(n); - assert(rnd >=0 && rnd < n); + CV_DbgAssert(rnd >=0 && rnd < n); centers[0] = dsindices[rnd]; @@ -208,7 +207,7 @@ private: // Choose one random center and set the closestDistSq values int index = rand_int(n); - assert(index >=0 && index < n); + CV_DbgAssert(index >=0 && index < n); centers[0] = dsindices[index]; // Computing distance^2 will have the advantage of even higher probability further to pick new centers @@ -295,7 +294,7 @@ private: // Choose one random center and set the closestDistSq values int index = rand_int(n); - assert(index >=0 && index < n); + CV_DbgAssert(index >=0 && index < n); centers[0] = dsindices[index]; for (int i = 0; i < n; i++) { @@ -564,10 +563,10 @@ public: NodePtr node = branch.node; findNN(node, result, vec, checks, maxChecks, heap, checked); } - assert(result.full()); delete heap; + CV_Assert(result.full()); } IndexParams getParameters() const CV_OVERRIDE diff --git a/modules/flann/include/opencv2/flann/index_testing.h b/modules/flann/include/opencv2/flann/index_testing.h index 47b6f0b86f..f3d147588d 100644 --- a/modules/flann/include/opencv2/flann/index_testing.h +++ b/modules/flann/include/opencv2/flann/index_testing.h @@ -34,7 +34,6 @@ //! @cond IGNORED #include -#include #include #include "matrix.h" diff --git a/modules/flann/include/opencv2/flann/kdtree_index.h b/modules/flann/include/opencv2/flann/kdtree_index.h index 472350516f..acc87a3198 100644 --- a/modules/flann/include/opencv2/flann/kdtree_index.h +++ b/modules/flann/include/opencv2/flann/kdtree_index.h @@ -35,7 +35,6 @@ #include #include -#include #include #include "general.h" @@ -433,7 +432,7 @@ private: if (trees_>0) { searchLevelExact(result, vec, tree_roots_[0], 0.0, epsError); } - assert(result.full()); + CV_Assert(result.full()); } /** @@ -462,7 +461,7 @@ private: delete heap; - assert(result.full()); + CV_Assert(result.full()); } diff --git a/modules/flann/include/opencv2/flann/kdtree_single_index.h b/modules/flann/include/opencv2/flann/kdtree_single_index.h index ce4c1c5b7e..e571403b10 100644 --- a/modules/flann/include/opencv2/flann/kdtree_single_index.h +++ b/modules/flann/include/opencv2/flann/kdtree_single_index.h @@ -35,7 +35,6 @@ #include #include -#include #include #include "general.h" @@ -214,11 +213,11 @@ public: */ void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) CV_OVERRIDE { - assert(queries.cols == veclen()); - assert(indices.rows >= queries.rows); - assert(dists.rows >= queries.rows); - assert(int(indices.cols) >= knn); - assert(int(dists.cols) >= knn); + CV_Assert(queries.cols == veclen()); + CV_Assert(indices.rows >= queries.rows); + CV_Assert(dists.rows >= queries.rows); + CV_Assert(int(indices.cols) >= knn); + CV_Assert(int(dists.cols) >= knn); KNNSimpleResultSet resultSet(knn); for (size_t i = 0; i < queries.rows; i++) { diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index 695ef6e8b1..475f79b66a 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -152,7 +151,7 @@ public: int n = indices_length; int rnd = rand_int(n); - assert(rnd >=0 && rnd < n); + CV_DbgAssert(rnd >=0 && rnd < n); centers[0] = indices[rnd]; @@ -207,7 +206,7 @@ public: // Choose one random center and set the closestDistSq values int index = rand_int(n); - assert(index >=0 && index < n); + CV_DbgAssert(index >=0 && index < n); centers[0] = indices[index]; for (int i = 0; i < n; i++) { @@ -502,9 +501,9 @@ public: KMeansNodePtr node = branch.node; findNN(node, result, vec, checks, maxChecks, heap); } - assert(result.full()); - delete heap; + + CV_Assert(result.full()); } } diff --git a/modules/flann/include/opencv2/flann/lsh_index.h b/modules/flann/include/opencv2/flann/lsh_index.h index 86c0654051..9ac30136ff 100644 --- a/modules/flann/include/opencv2/flann/lsh_index.h +++ b/modules/flann/include/opencv2/flann/lsh_index.h @@ -38,7 +38,6 @@ //! @cond IGNORED #include -#include #include #include #include @@ -53,6 +52,11 @@ #include "random.h" #include "saving.h" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4702) //disable unreachable code +#endif + namespace cvflann { @@ -191,11 +195,11 @@ public: */ virtual void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) CV_OVERRIDE { - assert(queries.cols == veclen()); - assert(indices.rows >= queries.rows); - assert(dists.rows >= queries.rows); - assert(int(indices.cols) >= knn); - assert(int(dists.cols) >= knn); + CV_Assert(queries.cols == veclen()); + CV_Assert(indices.rows >= queries.rows); + CV_Assert(dists.rows >= queries.rows); + CV_Assert(int(indices.cols) >= knn); + CV_Assert(int(dists.cols) >= knn); KNNUniqueResultSet resultSet(knn); @@ -391,6 +395,10 @@ private: }; } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + //! @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 8f5250171b..a189562d3a 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -58,6 +58,12 @@ #include "dynamic_bitset.h" #include "matrix.h" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4702) //disable unreachable code +#endif + + namespace cvflann { @@ -162,8 +168,7 @@ public: { feature_size_ = feature_size; CV_UNUSED(key_size); - std::cerr << "LSH is not implemented for that type" << std::endl; - assert(0); + CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" ); } /** Add a feature to the table @@ -243,8 +248,7 @@ public: */ size_t getKey(const ElementType* /*feature*/) const { - std::cerr << "LSH is not implemented for that type" << std::endl; - assert(0); + CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" ); return 0; } @@ -510,6 +514,10 @@ inline LshStats LshTable::getStats() const } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //! @endcond diff --git a/modules/flann/include/opencv2/flann/nn_index.h b/modules/flann/include/opencv2/flann/nn_index.h index 00fe6ec5ae..fbb4c7924c 100644 --- a/modules/flann/include/opencv2/flann/nn_index.h +++ b/modules/flann/include/opencv2/flann/nn_index.h @@ -69,11 +69,11 @@ public: */ virtual void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) { - assert(queries.cols == veclen()); - assert(indices.rows >= queries.rows); - assert(dists.rows >= queries.rows); - assert(int(indices.cols) >= knn); - assert(int(dists.cols) >= knn); + CV_Assert(queries.cols == veclen()); + CV_Assert(indices.rows >= queries.rows); + CV_Assert(dists.rows >= queries.rows); + CV_Assert(int(indices.cols) >= knn); + CV_Assert(int(dists.cols) >= knn); #if 0 KNNResultSet resultSet(knn); diff --git a/modules/flann/include/opencv2/flann/simplex_downhill.h b/modules/flann/include/opencv2/flann/simplex_downhill.h index 20b7e03c92..02970148b2 100644 --- a/modules/flann/include/opencv2/flann/simplex_downhill.h +++ b/modules/flann/include/opencv2/flann/simplex_downhill.h @@ -72,7 +72,7 @@ float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) { const int MAX_ITERATIONS = 10; - assert(n>0); + CV_DbgAssert(n>0); T* p_o = new T[n]; T* p_r = new T[n]; From 2566d131005091446a206436332791e350ec85a5 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Wed, 1 Jul 2020 23:50:09 +0300 Subject: [PATCH 11/16] Update documentation of imwrite() --- modules/imgcodecs/include/opencv2/imgcodecs.hpp | 7 ++++--- .../snippets/imgcodecs_imwrite.cpp | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/imgcodecs/include/opencv2/imgcodecs.hpp b/modules/imgcodecs/include/opencv2/imgcodecs.hpp index 319f6cbd97..e1f8208e0b 100644 --- a/modules/imgcodecs/include/opencv2/imgcodecs.hpp +++ b/modules/imgcodecs/include/opencv2/imgcodecs.hpp @@ -204,16 +204,17 @@ can be saved using this function, with these exceptions: - PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). +- Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below). If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format. -The sample below shows how to create a BGRA image and save it to a PNG file. It also demonstrates how to set custom -compression parameters: +The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. +It also demonstrates how to save multiple images in a TIFF file: @include snippets/imgcodecs_imwrite.cpp @param filename Name of the file. -@param img Image to be saved. +@param img (Mat or vector of Mat) Image or Images to be saved. @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags */ CV_EXPORTS_W bool imwrite( const String& filename, InputArray img, diff --git a/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp b/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp index 10f4151694..ad9ee6d6b2 100644 --- a/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp +++ b/samples/cpp/tutorial_code/snippets/imgcodecs_imwrite.cpp @@ -3,7 +3,7 @@ using namespace cv; using namespace std; -static void createAlphaMat(Mat &mat) +static void paintAlphaMat(Mat &mat) { CV_Assert(mat.channels() == 4); for (int i = 0; i < mat.rows; ++i) @@ -21,9 +21,9 @@ static void createAlphaMat(Mat &mat) int main() { - // Create mat with alpha channel - Mat mat(480, 640, CV_8UC4); - createAlphaMat(mat); + Mat mat(480, 640, CV_8UC4); // Create a matrix with alpha channel + paintAlphaMat(mat); + vector compression_params; compression_params.push_back(IMWRITE_PNG_COMPRESSION); compression_params.push_back(9); @@ -37,9 +37,18 @@ int main() { fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what()); } + if (result) printf("Saved PNG file with alpha data.\n"); else printf("ERROR: Can't save PNG file.\n"); + + vector imgs; + imgs.push_back(mat); + imgs.push_back(~mat); + imgs.push_back(mat(Rect(0, 0, mat.cols / 2, mat.rows / 2))); + imwrite("test.tiff", imgs); + printf("Multiple files saved in test.tiff\n"); + return result ? 0 : 1; } From e8129429e96f3742b698318f5462f5d36e2ed64e Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Mon, 6 Jul 2020 14:52:52 +0300 Subject: [PATCH 12/16] imgcodecs: fix test build with disabled JPEG and PNG libs --- modules/imgcodecs/test/test_read_write.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/imgcodecs/test/test_read_write.cpp b/modules/imgcodecs/test/test_read_write.cpp index c53cc5a46b..985d5c110a 100644 --- a/modules/imgcodecs/test/test_read_write.cpp +++ b/modules/imgcodecs/test/test_read_write.cpp @@ -31,6 +31,7 @@ const tuple images[] = #ifdef HAVE_PNG make_tuple("../cv/shared/pic1.png", Size(400, 300)), #endif + make_tuple("../highgui/readwrite/ordinary.bmp", Size(480, 272)), }; TEST_P(Imgcodecs_Resize, imread_reduce_flags) From d69a7a3bbf4260e0135bd79167dab0314a1a9dc3 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Mon, 6 Jul 2020 11:11:59 +0300 Subject: [PATCH 13/16] Fixed header paths for some nGraph ops * Added dependency on IE version backport of commit: 992c908b566d264b824680d0cf7d668cdf918254 --- modules/dnn/src/layers/detection_output_layer.cpp | 5 +++++ modules/dnn/src/layers/pooling_layer.cpp | 5 +++++ modules/dnn/src/layers/prior_box_layer.cpp | 5 +++++ modules/dnn/src/layers/proposal_layer.cpp | 4 ++++ modules/dnn/src/layers/reorg_layer.cpp | 6 +++++- modules/dnn/src/layers/resize_layer.cpp | 4 ++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index d32357b04e..76142181ae 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -54,9 +54,14 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#else #include #endif +#endif + namespace cv { namespace dnn diff --git a/modules/dnn/src/layers/pooling_layer.cpp b/modules/dnn/src/layers/pooling_layer.cpp index cd16ec7f3b..3f2a0f7d03 100644 --- a/modules/dnn/src/layers/pooling_layer.cpp +++ b/modules/dnn/src/layers/pooling_layer.cpp @@ -48,9 +48,14 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#include +#else #include #include #endif +#endif #include #include diff --git a/modules/dnn/src/layers/prior_box_layer.cpp b/modules/dnn/src/layers/prior_box_layer.cpp index dbd5b0426f..7385afd3b0 100644 --- a/modules/dnn/src/layers/prior_box_layer.cpp +++ b/modules/dnn/src/layers/prior_box_layer.cpp @@ -46,9 +46,14 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#include +#else #include #include #endif +#endif #include #include diff --git a/modules/dnn/src/layers/proposal_layer.cpp b/modules/dnn/src/layers/proposal_layer.cpp index 2420dbf579..990cfeda30 100644 --- a/modules/dnn/src/layers/proposal_layer.cpp +++ b/modules/dnn/src/layers/proposal_layer.cpp @@ -10,8 +10,12 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#else #include #endif +#endif namespace cv { namespace dnn { diff --git a/modules/dnn/src/layers/reorg_layer.cpp b/modules/dnn/src/layers/reorg_layer.cpp index d6fafa664f..6961243865 100644 --- a/modules/dnn/src/layers/reorg_layer.cpp +++ b/modules/dnn/src/layers/reorg_layer.cpp @@ -41,7 +41,6 @@ //M*/ #include "../precomp.hpp" -#include "../op_inf_engine.hpp" #include #include @@ -50,10 +49,15 @@ #include "opencl_kernels_dnn.hpp" #endif +#include "../op_inf_engine.hpp" #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#else #include #endif +#endif namespace cv { diff --git a/modules/dnn/src/layers/resize_layer.cpp b/modules/dnn/src/layers/resize_layer.cpp index 3679c9e51b..7fc21154cf 100644 --- a/modules/dnn/src/layers/resize_layer.cpp +++ b/modules/dnn/src/layers/resize_layer.cpp @@ -11,8 +11,12 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" +#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) +#include +#else #include #endif +#endif namespace cv { namespace dnn { From 99c4b76a6d4df9159e3e75bfcb3ad989bc40222c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 3 Jul 2020 19:14:05 +0000 Subject: [PATCH 14/16] dnn(test): add YOLOv4-tiny tests --- modules/dnn/perf/perf_net.cpp | 13 +++++ modules/dnn/test/test_common.impl.hpp | 8 ++- modules/dnn/test/test_darknet_importer.cpp | 66 +++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/modules/dnn/perf/perf_net.cpp b/modules/dnn/perf/perf_net.cpp index f4d008f161..3bee2313c0 100644 --- a/modules/dnn/perf/perf_net.cpp +++ b/modules/dnn/perf/perf_net.cpp @@ -216,6 +216,19 @@ PERF_TEST_P_(DNNTestNetwork, YOLOv4) processNet("dnn/yolov4.weights", "dnn/yolov4.cfg", "", inp); } +PERF_TEST_P_(DNNTestNetwork, YOLOv4_tiny) +{ + if (backend == DNN_BACKEND_HALIDE) + throw SkipTestException(""); + if (target == DNN_TARGET_MYRIAD) + throw SkipTestException(""); + Mat sample = imread(findDataFile("dnn/dog416.png")); + cvtColor(sample, sample, COLOR_BGR2RGB); + Mat inp; + sample.convertTo(inp, CV_32FC3, 1.0f / 255, 0); + processNet("dnn/yolov4-tiny.weights", "dnn/yolov4-tiny.cfg", "", inp); +} + PERF_TEST_P_(DNNTestNetwork, EAST_text_detection) { if (backend == DNN_BACKEND_HALIDE) diff --git a/modules/dnn/test/test_common.impl.hpp b/modules/dnn/test/test_common.impl.hpp index fdd1fe20cb..559b74f126 100644 --- a/modules/dnn/test/test_common.impl.hpp +++ b/modules/dnn/test/test_common.impl.hpp @@ -96,9 +96,12 @@ void normAssertDetections( const char *comment /*= ""*/, double confThreshold /*= 0.0*/, double scores_diff /*= 1e-5*/, double boxes_iou_diff /*= 1e-4*/) { + ASSERT_FALSE(testClassIds.empty()) << "No detections"; std::vector matchedRefBoxes(refBoxes.size(), false); + std::vector refBoxesIoUDiff(refBoxes.size(), 1.0); for (int i = 0; i < testBoxes.size(); ++i) { + //cout << "Test[i=" << i << "]: score=" << testScores[i] << " id=" << testClassIds[i] << " box " << testBoxes[i] << endl; double testScore = testScores[i]; if (testScore < confThreshold) continue; @@ -115,6 +118,7 @@ void normAssertDetections( double interArea = (testBox & refBoxes[j]).area(); double iou = interArea / (testBox.area() + refBoxes[j].area() - interArea); topIoU = std::max(topIoU, iou); + refBoxesIoUDiff[j] = std::min(refBoxesIoUDiff[j], 1.0f - iou); if (1.0 - iou < boxes_iou_diff) { matched = true; @@ -137,7 +141,9 @@ void normAssertDetections( if (!matchedRefBoxes[i] && refScores[i] > confThreshold) { std::cout << cv::format("Unmatched reference: class %d score %f box ", - refClassIds[i], refScores[i]) << refBoxes[i] << std::endl; + refClassIds[i], refScores[i]) << refBoxes[i] + << " IoU diff: " << refBoxesIoUDiff[i] + << std::endl; EXPECT_LE(refScores[i], confThreshold) << comment; } } diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index fcc9088b00..f328b29b20 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -254,6 +254,13 @@ public: } + if (cvIsNaN(iouDiff)) + { + if (b == 0) + std::cout << "Skip accuracy checks" << std::endl; + continue; + } + normAssertDetections(refClassIds[b], refConfidences[b], refBoxes[b], nms_classIds, nms_confidences, nms_boxes, format("batch size %d, sample %d\n", batch_size, b).c_str(), confThreshold, scoreDiff, iouDiff); } @@ -449,7 +456,7 @@ TEST_P(Test_Darknet_nets_async, Accuracy) } INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_nets_async, Combine( - Values("yolo-voc", "tiny-yolo-voc", "yolov3", "yolov4"), + Values("yolo-voc", "tiny-yolo-voc", "yolov3", "yolov4", "yolov4-tiny"), dnnBackendsAndTargets() )); @@ -587,6 +594,63 @@ TEST_P(Test_Darknet_nets, YOLOv4) } } +TEST_P(Test_Darknet_nets, YOLOv4_tiny) +{ + applyTestTag( + target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB + ); + + const double confThreshold = 0.5; + // batchId, classId, confidence, left, top, right, bottom + const int N0 = 2; + const int N1 = 3; + static const float ref_[/* (N0 + N1) * 7 */] = { +0, 7, 0.85935f, 0.593484f, 0.141211f, 0.920356f, 0.291593f, +0, 16, 0.795188f, 0.169207f, 0.386886f, 0.423753f, 0.933004f, + +1, 2, 0.996832f, 0.653802f, 0.464573f, 0.815193f, 0.653292f, +1, 2, 0.963325f, 0.451151f, 0.458915f, 0.496255f, 0.52241f, +1, 0, 0.926244f, 0.194851f, 0.361743f, 0.260277f, 0.632364f, + }; + Mat ref(N0 + N1, 7, CV_32FC1, (void*)ref_); + + double scoreDiff = 0.01f; + double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.15 : 0.01f; + + std::string config_file = "yolov4-tiny.cfg"; + std::string weights_file = "yolov4-tiny.weights"; + +#if defined(INF_ENGINE_RELEASE) + if (target == DNN_TARGET_MYRIAD) // bad accuracy + iouDiff = std::numeric_limits::quiet_NaN(); + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL) + iouDiff = std::numeric_limits::quiet_NaN(); + if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || + backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && DNN_TARGET_OPENCL_FP16) + iouDiff = std::numeric_limits::quiet_NaN(); +#endif + + { + SCOPED_TRACE("batch size 1"); + testDarknetModel(config_file, weights_file, ref.rowRange(0, N0), scoreDiff, iouDiff, confThreshold); + } + + { + SCOPED_TRACE("batch size 2"); + testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff, confThreshold); + } + +#if defined(INF_ENGINE_RELEASE) + if (target == DNN_TARGET_MYRIAD) // bad accuracy + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || + backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && DNN_TARGET_OPENCL_FP16) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif +} + INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_nets, dnnBackendsAndTargets()); From d5713c657bc135c533439a1bb8df4f0894c39c90 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 6 Jul 2020 14:13:38 +0000 Subject: [PATCH 15/16] dnn(slice): disable buggy OCV/OCL implementation --- modules/dnn/src/layers/slice_layer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/layers/slice_layer.cpp b/modules/dnn/src/layers/slice_layer.cpp index 00bebbcd2d..a16384cbd4 100644 --- a/modules/dnn/src/layers/slice_layer.cpp +++ b/modules/dnn/src/layers/slice_layer.cpp @@ -202,6 +202,10 @@ public: #ifdef HAVE_OPENCL bool forward_ocl(InputArrayOfArrays inputs_, OutputArrayOfArrays outputs_, OutputArrayOfArrays internals_) { +#if 1 + // TODO fix that (brokes YOLOv4-tiny) + return false; +#else std::vector inputs; std::vector outputs; @@ -244,7 +248,8 @@ public: } return true; - } +#endif + } #endif void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE From eb6678ebef9b4b01a89e0666c55dd198cf594f6a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 7 Jul 2020 01:58:17 +0300 Subject: [PATCH 16/16] Merge pull request #17699 from alalek:build_core_cuda * core(cuda): fix build - MSVS 19.25.28612.0 - CUDA release 11.0, V11.0.167 * cmake(cuda): backport workaround for CUDA 11 * cmake(cuda): call CUDA_BUILD_CLEAN_TARGET() on finalize * cmake(cuda): use CMAKE_SUPPRESS_REGENERATION with MSVS --- CMakeLists.txt | 4 ++++ cmake/OpenCVDetectCUDA.cmake | 12 ++++++++++++ modules/core/include/opencv2/core/cuda_types.hpp | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 614baa2107..2620bbe808 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1652,6 +1652,10 @@ if(ENABLE_CONFIG_VERIFICATION) ocv_verify_config() endif() +if(HAVE_CUDA AND COMMAND CUDA_BUILD_CLEAN_TARGET) + CUDA_BUILD_CLEAN_TARGET() +endif() + ocv_cmake_hook(POST_FINALIZE) # ---------------------------------------------------------------------------- diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index a32977e260..2586a53f80 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -28,6 +28,11 @@ endif() if(CUDA_FOUND) set(HAVE_CUDA 1) + if(NOT CUDA_VERSION VERSION_LESS 11.0) + # CUDA 11.0 removes nppicom + ocv_list_filterout(CUDA_nppi_LIBRARY "nppicom") + ocv_list_filterout(CUDA_npp_LIBRARY "nppicom") + endif() if(WITH_CUFFT) set(HAVE_CUFFT 1) @@ -370,4 +375,11 @@ if(HAVE_CUDA) set(CUDA_cufft_LIBRARY_ABS ${CUDA_cufft_LIBRARY}) ocv_convert_to_lib_name(CUDA_cufft_LIBRARY ${CUDA_cufft_LIBRARY}) endif() + + if(CMAKE_GENERATOR MATCHES "Visual Studio" + AND NOT OPENCV_SKIP_CUDA_CMAKE_SUPPRESS_REGENERATION + ) + message(WARNING "CUDA with MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.") + set(CMAKE_SUPPRESS_REGENERATION ON) + endif() endif() diff --git a/modules/core/include/opencv2/core/cuda_types.hpp b/modules/core/include/opencv2/core/cuda_types.hpp index 45dc2cad1c..b33f06179d 100644 --- a/modules/core/include/opencv2/core/cuda_types.hpp +++ b/modules/core/include/opencv2/core/cuda_types.hpp @@ -106,8 +106,8 @@ namespace cv size_t step; - __CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr::data + y * step); } - __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr::data + y * step); } + __CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)(((DevPtr*)this)->data) + y * step); } + __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)(((DevPtr*)this)->data) + y * step); } __CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } __CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }