From 50ff40d684d46969de45ee52fa743281f171dc96 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 6 Sep 2020 22:26:32 +0000 Subject: [PATCH 01/15] pre: OpenCV 3.4.12 (version++) --- doc/tutorials/dnn/dnn_android/dnn_android.markdown | 2 +- .../cross_referencing/tutorial_cross_referencing.markdown | 4 ++-- modules/core/include/opencv2/core/version.hpp | 4 ++-- modules/dnn/include/opencv2/dnn/dnn.hpp | 4 ++-- modules/python/package/setup.py | 2 +- platforms/android/build_sdk.py | 2 +- platforms/android/service/readme.txt | 2 +- platforms/maven/opencv-it/pom.xml | 2 +- platforms/maven/opencv/pom.xml | 2 +- platforms/maven/pom.xml | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/tutorials/dnn/dnn_android/dnn_android.markdown b/doc/tutorials/dnn/dnn_android/dnn_android.markdown index 4cd5b9f9e5..b0f7655a92 100644 --- a/doc/tutorials/dnn/dnn_android/dnn_android.markdown +++ b/doc/tutorials/dnn/dnn_android/dnn_android.markdown @@ -15,7 +15,7 @@ Tutorial was written for the following versions of corresponding software: - Download and install Android Studio from https://developer.android.com/studio. -- Get the latest pre-built OpenCV for Android release from https://github.com/opencv/opencv/releases and unpack it (for example, `opencv-3.4.11-android-sdk.zip`). +- Get the latest pre-built OpenCV for Android release from https://github.com/opencv/opencv/releases and unpack it (for example, `opencv-3.X.Y-android-sdk.zip`). - Download MobileNet object detection model from https://github.com/chuanqi305/MobileNet-SSD. We need a configuration file `MobileNetSSD_deploy.prototxt` and weights `MobileNetSSD_deploy.caffemodel`. diff --git a/doc/tutorials/introduction/cross_referencing/tutorial_cross_referencing.markdown b/doc/tutorials/introduction/cross_referencing/tutorial_cross_referencing.markdown index 26ed952202..bf5f62a013 100644 --- a/doc/tutorials/introduction/cross_referencing/tutorial_cross_referencing.markdown +++ b/doc/tutorials/introduction/cross_referencing/tutorial_cross_referencing.markdown @@ -39,14 +39,14 @@ Open your Doxyfile using your favorite text editor and search for the key `TAGFILES`. Change it as follows: @code -TAGFILES = ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/3.4.11 +TAGFILES = ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/3.4.12 @endcode If you had other definitions already, you can append the line using a `\`: @code TAGFILES = ./docs/doxygen-tags/libstdc++.tag=https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen \ - ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/3.4.11 + ./docs/doxygen-tags/opencv.tag=http://docs.opencv.org/3.4.12 @endcode Doxygen can now use the information from the tag file to link to the OpenCV diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index c5272e81ef..00172f809e 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -7,8 +7,8 @@ #define CV_VERSION_MAJOR 3 #define CV_VERSION_MINOR 4 -#define CV_VERSION_REVISION 11 -#define CV_VERSION_STATUS "-dev" +#define CV_VERSION_REVISION 12 +#define CV_VERSION_STATUS "-pre" #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp index 50aacad75c..98a825940d 100644 --- a/modules/dnn/include/opencv2/dnn/dnn.hpp +++ b/modules/dnn/include/opencv2/dnn/dnn.hpp @@ -47,9 +47,9 @@ #include "opencv2/core/async.hpp" #if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS -#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v18 { +#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v19 { #define CV__DNN_EXPERIMENTAL_NS_END } -namespace cv { namespace dnn { namespace experimental_dnn_34_v18 { } using namespace experimental_dnn_34_v18; }} +namespace cv { namespace dnn { namespace experimental_dnn_34_v19 { } using namespace experimental_dnn_34_v19; }} #else #define CV__DNN_EXPERIMENTAL_NS_BEGIN #define CV__DNN_EXPERIMENTAL_NS_END diff --git a/modules/python/package/setup.py b/modules/python/package/setup.py index d419161d90..d6d74d5e3e 100644 --- a/modules/python/package/setup.py +++ b/modules/python/package/setup.py @@ -9,7 +9,7 @@ def main(): os.chdir(SCRIPT_DIR) package_name = 'opencv' - package_version = os.environ.get('OPENCV_VERSION', '3.4.11') # TODO + package_version = os.environ.get('OPENCV_VERSION', '3.4.12') # TODO long_description = 'Open Source Computer Vision Library Python bindings' # TODO diff --git a/platforms/android/build_sdk.py b/platforms/android/build_sdk.py index 14fd8f664f..86c534d732 100755 --- a/platforms/android/build_sdk.py +++ b/platforms/android/build_sdk.py @@ -269,7 +269,7 @@ class Builder: # Add extra data apkxmldest = check_dir(os.path.join(apkdest, "res", "xml"), create=True) apklibdest = check_dir(os.path.join(apkdest, "libs", abi.name), create=True) - for ver, d in self.extra_packs + [("3.4.11", os.path.join(self.libdest, "lib"))]: + for ver, d in self.extra_packs + [("3.4.12", os.path.join(self.libdest, "lib"))]: r = ET.Element("library", attrib={"version": ver}) log.info("Adding libraries from %s", d) diff --git a/platforms/android/service/readme.txt b/platforms/android/service/readme.txt index d0771ebbfb..42df960bbd 100644 --- a/platforms/android/service/readme.txt +++ b/platforms/android/service/readme.txt @@ -12,7 +12,7 @@ manually using adb tool: adb install /apk/OpenCV__Manager__.apk -Example: OpenCV_3.4.11-dev_Manager_3.49_armeabi-v7a.apk +Example: OpenCV_3.4.12-dev_Manager_3.49_armeabi-v7a.apk Use the list of platforms below to determine proper OpenCV Manager package for your device: diff --git a/platforms/maven/opencv-it/pom.xml b/platforms/maven/opencv-it/pom.xml index 9dcf06ea0d..4feab3e367 100644 --- a/platforms/maven/opencv-it/pom.xml +++ b/platforms/maven/opencv-it/pom.xml @@ -4,7 +4,7 @@ org.opencv opencv-parent - 3.4.11 + 3.4.12 org.opencv opencv-it diff --git a/platforms/maven/opencv/pom.xml b/platforms/maven/opencv/pom.xml index bef3d5f87e..29856097f2 100644 --- a/platforms/maven/opencv/pom.xml +++ b/platforms/maven/opencv/pom.xml @@ -4,7 +4,7 @@ org.opencv opencv-parent - 3.4.11 + 3.4.12 org.opencv opencv diff --git a/platforms/maven/pom.xml b/platforms/maven/pom.xml index 5e81609042..b8f00d4f49 100644 --- a/platforms/maven/pom.xml +++ b/platforms/maven/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.opencv opencv-parent - 3.4.11 + 3.4.12 pom OpenCV Parent POM From f56445d7caf49100de50143db2c9aeb3566f1ed4 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 7 Sep 2020 17:21:55 +0000 Subject: [PATCH 02/15] ffmpeg/3.4: update FFmpeg wrapper - FFmpeg 3.4.8 --- 3rdparty/ffmpeg/ffmpeg.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/3rdparty/ffmpeg/ffmpeg.cmake b/3rdparty/ffmpeg/ffmpeg.cmake index 134547cbdd..531d301fa8 100644 --- a/3rdparty/ffmpeg/ffmpeg.cmake +++ b/3rdparty/ffmpeg/ffmpeg.cmake @@ -1,8 +1,8 @@ -# Binaries branch name: ffmpeg/3.4_20200608 -# Binaries were created for OpenCV: 458f1d5ebe31e22789d9d781d0ca2ca936758fde -ocv_update(FFMPEG_BINARIES_COMMIT "57064cd66d98994503b34aade3c8d8ff25007b46") -ocv_update(FFMPEG_FILE_HASH_BIN32 "6fff20f5617bd1b7362058790db52caa") -ocv_update(FFMPEG_FILE_HASH_BIN64 "15df55131471191b575668a424dff385") +# Binaries branch name: ffmpeg/3.4_20200907 +# Binaries were created for OpenCV: 03bee14372f5537daa56c62e771ec16181ca1f98 +ocv_update(FFMPEG_BINARIES_COMMIT "2a96257b743695a47f8012aab1ffb995a1dee8b4") +ocv_update(FFMPEG_FILE_HASH_BIN32 "5e68a3ff82f43ac6524e50e448a34c9c") +ocv_update(FFMPEG_FILE_HASH_BIN64 "205db629d893e7d4865fd1459807ff47") ocv_update(FFMPEG_FILE_HASH_CMAKE "3b90f67f4b429e77d3da36698cef700c") function(download_win_ffmpeg script_var) From 2dff2f36bfdf6b5c0c85e3096d0c1ab05e6146d7 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 8 Sep 2020 20:22:26 +0300 Subject: [PATCH 03/15] Install: added prebuilt samples installation --- CMakeLists.txt | 1 + cmake/OpenCVModule.cmake | 4 ++-- samples/samples_utils.cmake | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2620bbe808..d143a7aeaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -463,6 +463,7 @@ OCV_OPTION(BUILD_JAVA "Enable Java support" # OpenCV installation options # =================================================== OCV_OPTION(INSTALL_CREATE_DISTRIB "Change install rules to build the distribution package" OFF ) +OCV_OPTION(INSTALL_BIN_EXAMPLES "Install prebuilt examples" WIN32 IF BUILD_EXAMPLES) OCV_OPTION(INSTALL_C_EXAMPLES "Install C examples" OFF ) OCV_OPTION(INSTALL_PYTHON_EXAMPLES "Install Python examples" OFF ) OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples" OFF IF ANDROID ) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 634b5b264c..10ee406032 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -1337,8 +1337,8 @@ function(ocv_add_samples) endif() add_dependencies(${parent_target} ${the_target}) - if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples) + if(INSTALL_BIN_EXAMPLES) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${module_id}" COMPONENT samples) endif() endforeach() endif() diff --git a/samples/samples_utils.cmake b/samples/samples_utils.cmake index 845b4585ea..9459099200 100644 --- a/samples/samples_utils.cmake +++ b/samples/samples_utils.cmake @@ -15,8 +15,12 @@ function(ocv_define_sample out_target source sub) if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() - if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples) + # Should be usable in stand-alone build scenario + if((NOT DEFINED INSTALL_BIN_EXAMPLES AND WIN32) OR INSTALL_BIN_EXAMPLES) + if(NOT DEFINED OPENCV_SAMPLES_BIN_INSTALL_PATH) + set(OPENCV_SAMPLES_BIN_INSTALL_PATH "samples") + endif() + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sub}" COMPONENT samples) endif() # Add single target to build all samples in the group: 'make opencv_samples_cpp' set(parent_target opencv_samples_${sub}) From b542a1804c2dd47442104b42c30fc9a67e94f5b5 Mon Sep 17 00:00:00 2001 From: Liubov Batanina Date: Wed, 9 Sep 2020 10:40:02 +0300 Subject: [PATCH 04/15] Support global reduce ops --- modules/dnn/src/onnx/onnx_importer.cpp | 49 ++++++++++++++++++++----- modules/dnn/test/test_onnx_importer.cpp | 5 +++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 153d026e4b..01feeeb7c7 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -392,24 +392,21 @@ void ONNXImporter::populateNet(Net dstNet) layerParams.set("ave_pool_padded_area", framework_name == "pytorch"); } else if (layer_type == "GlobalAveragePool" || layer_type == "GlobalMaxPool" || - layer_type == "ReduceMean" || layer_type == "ReduceSum") + layer_type == "ReduceMean" || layer_type == "ReduceSum" || layer_type == "ReduceMax") { CV_Assert(node_proto.input_size() == 1); layerParams.type = "Pooling"; String pool; - if (layer_type == "GlobalMaxPool") + if (layer_type == "GlobalMaxPool" || layer_type == "ReduceMax") pool = "MAX"; else if (layer_type == "ReduceSum") pool = "SUM"; else pool = "AVE"; layerParams.set("pool", pool); - layerParams.set("global_pooling", layer_type == "GlobalAveragePool" || layer_type == "GlobalMaxPool"); - if (layer_type == "ReduceMean" || layer_type == "ReduceSum") + layerParams.set("global_pooling", !layerParams.has("axes")); + if (layerParams.has("axes") && (layer_type == "ReduceMean" || layer_type == "ReduceSum" || layer_type == "ReduceMax")) { - if (!layerParams.has("axes")) - CV_Error(Error::StsNotImplemented, "Unsupported mode of " + layer_type + " operation."); - MatShape inpShape = outShapes[node_proto.input(0)]; DictValue axes = layerParams.get("axes"); bool keepdims = layerParams.get("keepdims"); @@ -487,6 +484,36 @@ void ONNXImporter::populateNet(Net dstNet) layerParams.type = "Reshape"; layerParams.set("dim", DictValue::arrayInt(&targetShape[0], targetShape.size())); + node_proto.set_input(0, node_proto.output(0)); + node_proto.set_output(0, layerParams.name); + } + else if (!layerParams.has("axes") && (layer_type == "ReduceMean" || layer_type == "ReduceSum" || layer_type == "ReduceMax")) + { + CV_CheckEQ(layerParams.get("keepdims"), 0, (layer_type + " layer only supports keepdims = false").c_str()); + LayerParams reshapeLp; + reshapeLp.name = layerParams.name + "/reshape"; + reshapeLp.type = "Reshape"; + CV_Assert(layer_id.find(reshapeLp.name) == layer_id.end()); + int newShape[] = {1, 1, 1, -1}; + reshapeLp.set("dim", DictValue::arrayInt(&newShape[0], 4)); + + opencv_onnx::NodeProto proto; + proto.add_input(node_proto.input(0)); + proto.add_output(reshapeLp.name); + addLayer(dstNet, reshapeLp, proto, layer_id, outShapes); + + LayerParams poolLp = layerParams; + poolLp.name = layerParams.name + "/pool"; + CV_Assert(layer_id.find(poolLp.name) == layer_id.end()); + + node_proto.set_input(0, reshapeLp.name); + node_proto.set_output(0, poolLp.name); + addLayer(dstNet, poolLp, node_proto, layer_id, outShapes); + + layerParams.type = "Reshape"; + int targetShape[] = {1}; + layerParams.set("dim", DictValue::arrayInt(&targetShape[0], 1)); + node_proto.set_input(0, node_proto.output(0)); node_proto.set_output(0, layerParams.name); } @@ -1427,8 +1454,10 @@ void ONNXImporter::populateNet(Net dstNet) case opencv_onnx::TensorProto_DataType_INT64: type = CV_32S; break; default: type = blob.type(); } - blob.convertTo(blob, type); - addConstant(layerParams.name, blob, constBlobs, outShapes); + Mat dst; + blob.convertTo(dst, type); + dst.dims = blob.dims; + addConstant(layerParams.name, dst, constBlobs, outShapes); continue; } else @@ -1477,6 +1506,8 @@ void ONNXImporter::populateNet(Net dstNet) { outShape.erase(outShape.begin() + axis); out.reshape(0, outShape); + } else { + out.dims = 1; } addConstant(layerParams.name, out, constBlobs, outShapes); continue; diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 1eb848897c..2a4555619f 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -262,6 +262,11 @@ TEST_P(Test_ONNX_layers, ReduceSum) testONNXModels("reduce_sum"); } +TEST_P(Test_ONNX_layers, ReduceMaxGlobal) +{ + testONNXModels("reduce_max"); +} + TEST_P(Test_ONNX_layers, ReduceMean3D) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) From 23e71d1aa20ae2105cba9f7346d339036f45f3ce Mon Sep 17 00:00:00 2001 From: Shubham Singh <55784408+shubhamcodez@users.noreply.github.com> Date: Tue, 23 Jun 2020 14:36:32 +0530 Subject: [PATCH 05/15] fixes #17187 probably Added Eltwise Layer Support --- modules/dnn/src/onnx/onnx_importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 153d026e4b..586aa52a17 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -653,7 +653,7 @@ void ONNXImporter::populateNet(Net dstNet) LayerParams constParams; constParams.name = layerParams.name + "/const"; constParams.type = "Const"; - constParams.blobs.push_back(blob); + constParams.blobs.push_back((isSub ? -1 : 1) * blob); int id = dstNet.addLayer(constParams.name, constParams.type, constParams); layer_id.insert(std::make_pair(constParams.name, LayerInfo(id, 0))); outShapes[constParams.name] = shape(blob); From 7dfe68cac6e3ed26deb842d70f641264fd604071 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 13 Sep 2020 11:14:56 +0000 Subject: [PATCH 06/15] imgcodecs: lazy on-demand codecs initialization --- modules/imgcodecs/src/loadsave.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index ddd5fcf6fa..4e626cd216 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -189,7 +189,19 @@ struct ImageCodecInitializer std::vector encoders; }; -static ImageCodecInitializer codecs; +static +ImageCodecInitializer& getCodecs() +{ +#ifdef CV_CXX11 + static ImageCodecInitializer g_codecs; + return g_codecs; +#else + // C++98 doesn't guarantee correctness of multi-threaded initialization of static global variables + // (memory leak here is not critical, use C++11 to avoid that) + static ImageCodecInitializer* g_codecs = new ImageCodecInitializer(); + return *g_codecs; +#endif +} /** * Find the decoders @@ -203,6 +215,7 @@ static ImageDecoder findDecoder( const String& filename ) { size_t i, maxlen = 0; /// iterate through list of registered codecs + ImageCodecInitializer& codecs = getCodecs(); for( i = 0; i < codecs.decoders.size(); i++ ) { size_t len = codecs.decoders[i]->signatureLength(); @@ -240,6 +253,7 @@ static ImageDecoder findDecoder( const Mat& buf ) if( buf.rows*buf.cols < 1 || !buf.isContinuous() ) return ImageDecoder(); + ImageCodecInitializer& codecs = getCodecs(); for( i = 0; i < codecs.decoders.size(); i++ ) { size_t len = codecs.decoders[i]->signatureLength(); @@ -272,6 +286,7 @@ static ImageEncoder findEncoder( const String& _ext ) for( ext++; len < 128 && isalnum(ext[len]); len++ ) ; + ImageCodecInitializer& codecs = getCodecs(); for( size_t i = 0; i < codecs.encoders.size(); i++ ) { String description = codecs.encoders[i]->getDescription(); From 1612db5f91bebb759aa731a88bc1b742c94c96a9 Mon Sep 17 00:00:00 2001 From: Gil Shotan Date: Fri, 11 Sep 2020 02:47:53 +0300 Subject: [PATCH 07/15] Fix signed integer overflow in connected components --- modules/imgproc/src/connectedcomponents.cpp | 21 ++++++++++++------- .../imgproc/test/test_connectedcomponents.cpp | 14 +++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/imgproc/src/connectedcomponents.cpp b/modules/imgproc/src/connectedcomponents.cpp index 2e06be4f98..c3a3f6f75b 100644 --- a/modules/imgproc/src/connectedcomponents.cpp +++ b/modules/imgproc/src/connectedcomponents.cpp @@ -145,14 +145,21 @@ namespace cv{ void finish(){ for (int l = 0; l < statsv.rows; ++l){ int *row =& statsv.at(l, 0); - row[CC_STAT_WIDTH] = row[CC_STAT_WIDTH] - row[CC_STAT_LEFT] + 1; - row[CC_STAT_HEIGHT] = row[CC_STAT_HEIGHT] - row[CC_STAT_TOP] + 1; - - Point2ui64& integral = integrals[l]; - double *centroid = ¢roidsv.at(l, 0); double area = ((unsigned*)row)[CC_STAT_AREA]; - centroid[0] = double(integral.x) / area; - centroid[1] = double(integral.y) / area; + double *centroid = ¢roidsv.at(l, 0); + if (area > 0){ + row[CC_STAT_WIDTH] = row[CC_STAT_WIDTH] - row[CC_STAT_LEFT] + 1; + row[CC_STAT_HEIGHT] = row[CC_STAT_HEIGHT] - row[CC_STAT_TOP] + 1; + Point2ui64& integral = integrals[l]; + centroid[0] = double(integral.x) / area; + centroid[1] = double(integral.y) / area; + } else { + row[CC_STAT_WIDTH] = 0; + row[CC_STAT_HEIGHT] = 0; + row[CC_STAT_LEFT] = -1; + centroid[0] = std::numeric_limits::quiet_NaN(); + centroid[1] = std::numeric_limits::quiet_NaN(); + } } } diff --git a/modules/imgproc/test/test_connectedcomponents.cpp b/modules/imgproc/test/test_connectedcomponents.cpp index 5952577691..bc5c9f0a23 100644 --- a/modules/imgproc/test/test_connectedcomponents.cpp +++ b/modules/imgproc/test/test_connectedcomponents.cpp @@ -225,5 +225,19 @@ TEST(Imgproc_ConnectedComponents, parallel_wu_labels) EXPECT_EQ(nbPixels, area); } +TEST(Imgproc_ConnectedComponents, missing_background_pixels) +{ + cv::Mat m = Mat::ones(10, 10, CV_8U); + cv::Mat labels; + cv::Mat stats; + cv::Mat centroids; + EXPECT_NO_THROW(cv::connectedComponentsWithStats(m, labels, stats, centroids, 8, CV_32S, cv::CCL_WU) ); + EXPECT_EQ(stats.at(0, cv::CC_STAT_WIDTH), 0); + EXPECT_EQ(stats.at(0, cv::CC_STAT_HEIGHT), 0); + EXPECT_EQ(stats.at(0, cv::CC_STAT_LEFT), -1); + EXPECT_TRUE(std::isnan(centroids.at(0, 0))); + EXPECT_TRUE(std::isnan(centroids.at(0, 1))); +} + }} // namespace From 49ba74413039b83faa74f474322b51af0014b0a5 Mon Sep 17 00:00:00 2001 From: or-toledano <49984106+or-toledano@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:23:38 +0300 Subject: [PATCH 08/15] Fix np row,column to cv y,x This explanation was created to avoid confusion, but it seems like the author was confused :D --- .../py_contour_properties/py_contour_properties.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contour_properties/py_contour_properties.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contour_properties/py_contour_properties.markdown index a07b5e87b3..461c870343 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contour_properties/py_contour_properties.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contour_properties/py_contour_properties.markdown @@ -78,7 +78,7 @@ pixelpoints = np.transpose(np.nonzero(mask)) Here, two methods, one using Numpy functions, next one using OpenCV function (last commented line) are given to do the same. Results are also same, but with a slight difference. Numpy gives coordinates in **(row, column)** format, while OpenCV gives coordinates in **(x,y)** format. So -basically the answers will be interchanged. Note that, **row = x** and **column = y**. +basically the answers will be interchanged. Note that, **row = y** and **column = x**. 7. Maximum Value, Minimum Value and their locations --------------------------------------------------- From a61546680b082bf6da1ff2648836d288c5e3a772 Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Wed, 16 Sep 2020 15:45:03 +0900 Subject: [PATCH 09/15] use only even number for inplace flip --- modules/cudaarithm/src/core.cpp | 4 +++- modules/cudaarithm/test/test_core.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/cudaarithm/src/core.cpp b/modules/cudaarithm/src/core.cpp index ac01afc7f0..aefcfc5af2 100644 --- a/modules/cudaarithm/src/core.cpp +++ b/modules/cudaarithm/src/core.cpp @@ -163,8 +163,10 @@ void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& str _dst.create(src.size(), src.type()); GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream); + if (src.data == dst.data && ((src.cols & 1) == 1 || (src.rows & 1) == 1)) + CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height"); - if (src.refcount != dst.refcount) + if (src.data != dst.data) funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream)); else // in-place ifuncs[src.depth()][src.channels() - 1](src, flipCode, StreamAccessor::getStream(stream)); diff --git a/modules/cudaarithm/test/test_core.cpp b/modules/cudaarithm/test/test_core.cpp index bc8f3737e5..04b144ff37 100644 --- a/modules/cudaarithm/test/test_core.cpp +++ b/modules/cudaarithm/test/test_core.cpp @@ -281,6 +281,8 @@ CUDA_TEST_P(Flip, Accuracy) CUDA_TEST_P(Flip, AccuracyInplace) { + size.width = (size.width >> 1) << 1; // in-place version only accepts even number + size.height = (size.height >> 1) << 1; // in-place version only accepts even number cv::Mat src = randomMat(size, type); cv::cuda::GpuMat srcDst = loadMat(src, useRoi); From fa953e4205327224a1124be10b90d497d7cfa32f Mon Sep 17 00:00:00 2001 From: Sergei Slashchinin <62052793+sl-sergei@users.noreply.github.com> Date: Thu, 17 Sep 2020 14:05:22 +0300 Subject: [PATCH 10/15] Merge pull request #18316 from sl-sergei:fix_18253 Fix loading of ONNX models with Resize operation with Opset 11 for newer versions of Pytorch * Add reproducer for Resize operation from newer versions of Pytorch * Fix loading of scales parameter for Resize layer * Change check type for better diagnostic messages --- modules/dnn/src/onnx/onnx_importer.cpp | 4 +++- modules/dnn/test/test_onnx_importer.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 995800310f..318c2cc290 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1588,7 +1588,9 @@ void ONNXImporter::populateNet(Net dstNet) Mat shapes = getBlob(node_proto, constBlobs, node_proto.input_size() - 1); CV_CheckEQ(shapes.size[0], 4, ""); CV_CheckEQ(shapes.size[1], 1, ""); - CV_CheckTypeEQ(shapes.depth(), CV_32S, ""); + CV_CheckDepth(shapes.depth(), shapes.depth() == CV_32S || shapes.depth() == CV_32F, ""); + if (shapes.depth() == CV_32F) + shapes.convertTo(shapes, CV_32S); int height = shapes.at(2); int width = shapes.at(3); if (node_proto.input_size() == 3) diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 2a4555619f..4234fa8d8b 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -636,6 +636,11 @@ TEST_P(Test_ONNX_layers, MatmulWithTwoInputs) testONNXModels("matmul_with_two_inputs"); } +TEST_P(Test_ONNX_layers, ResizeOpset11_Torch1_6) +{ + testONNXModels("resize_opset11_torch1.6"); +} + INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets()); class Test_ONNX_nets : public Test_ONNX_layers From 8c44b8306befb45cbe2af4139262a6cecd300554 Mon Sep 17 00:00:00 2001 From: Takehiro Kajihara Date: Thu, 17 Sep 2020 21:51:50 +0900 Subject: [PATCH 11/15] Fix typo in videoio doc --- modules/videoio/doc/videoio_overview.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/videoio/doc/videoio_overview.markdown b/modules/videoio/doc/videoio_overview.markdown index b2db4b3956..13602fade0 100644 --- a/modules/videoio/doc/videoio_overview.markdown +++ b/modules/videoio/doc/videoio_overview.markdown @@ -77,7 +77,7 @@ for the operating system. Thus you can't use VideoCapture or VideoWriter with t To get access to their devices, manufactures provide their own C++ API and library that you have to include and link with your OpenCV application. -Is common case that this libraries read/write images from/to a memory buffer. If it so, it is +It is a common case that these libraries read/write images from/to a memory buffer. If it so, it is possible to make a `Mat` header for memory buffer (user-allocated data) and process it in-place using OpenCV functions. See cv::Mat::Mat() for more details. @@ -85,9 +85,9 @@ The FFmpeg library ------------------ OpenCV can use the FFmpeg library (http://ffmpeg.org/) as backend to record, convert and stream audio and video. -FFMpeg is a complete, cross-reference solution. If you enable FFmpeg while configuring OpenCV than +FFmpeg is a complete, cross-reference solution. If you enable FFmpeg while configuring OpenCV than CMake will download and install the binaries in `OPENCV_SOURCE_CODE/3rdparty/ffmpeg/`. To use -FFMpeg at runtime, you must deploy the FFMepg binaries with your application. +FFmpeg at runtime, you must deploy the FFMepg binaries with your application. @note FFmpeg is licensed under the GNU Lesser General Public License (LGPL) version 2.1 or later. See `OPENCV_SOURCE_CODE/3rdparty/ffmpeg/readme.txt` and http://ffmpeg.org/legal.html for details and From f77c2d700f52d091e63617aa54be3983538115d7 Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Fri, 18 Sep 2020 21:04:24 +0900 Subject: [PATCH 12/15] add explicit cast for half --- modules/dnn/src/opencl/prior_box.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dnn/src/opencl/prior_box.cl b/modules/dnn/src/opencl/prior_box.cl index a3f1161f30..021840773f 100644 --- a/modules/dnn/src/opencl/prior_box.cl +++ b/modules/dnn/src/opencl/prior_box.cl @@ -114,6 +114,6 @@ __kernel void clip(const int nthreads, for (int index = get_global_id(0); index < nthreads; index += get_global_size(0)) { Dtype4 vec = vload4(index, dst); - vstore4(clamp(vec, 0.0f, 1.0f), index, dst); + vstore4(clamp(vec, (Dtype)0.0f, (Dtype)1.0f), index, dst); } } From ebb528976f6e7e4572a8fadf1004ffcebc9ca584 Mon Sep 17 00:00:00 2001 From: Liubov Batanina Date: Fri, 18 Sep 2020 16:01:14 +0300 Subject: [PATCH 13/15] Merge pull request #18353 from l-bat:issue_18350 * Fixed bug in ONNX Mul op * Replaced node --- modules/dnn/src/onnx/onnx_importer.cpp | 10 ++++++++++ modules/dnn/test/test_onnx_importer.cpp | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 318c2cc290..58e5cf75f5 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1051,6 +1051,16 @@ void ONNXImporter::populateNet(Net dstNet) } else { + // Scale layer allocate output with the first input shape + if (total(outShapes[node_proto.input(0)]) < total(outShapes[node_proto.input(1)])) + { + opencv_onnx::NodeProto proto; + proto.add_input(node_proto.input(1)); + proto.add_input(node_proto.input(0)); + proto.add_output(layerParams.name); + node_proto = proto; + } + if (isDiv) { LayerParams powerParams; diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 4234fa8d8b..993ba56be4 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -267,6 +267,13 @@ TEST_P(Test_ONNX_layers, ReduceMaxGlobal) testONNXModels("reduce_max"); } +TEST_P(Test_ONNX_layers, Scale) +{ + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); + testONNXModels("scale"); +} + TEST_P(Test_ONNX_layers, ReduceMean3D) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) From 4fa82809dfc66b01242ff86f18b85588899f19cf Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 18 Sep 2020 06:45:27 +0300 Subject: [PATCH 14/15] ocl: avoid rescheduling of async kernels --- modules/core/src/ocl.cpp | 37 ++++++++++++++++++- .../dnn/src/ocl4dnn/src/math_functions.cpp | 13 +++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 467a62b8c1..24b18dc7f8 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2755,7 +2755,7 @@ KernelArg KernelArg::Constant(const Mat& m) struct Kernel::Impl { Impl(const char* kname, const Program& prog) : - refcount(1), handle(NULL), isInProgress(false), nu(0) + refcount(1), handle(NULL), isInProgress(false), isAsyncRun(false), nu(0) { cl_program ph = (cl_program)prog.ptr(); cl_int retval = 0; @@ -2832,6 +2832,7 @@ struct Kernel::Impl enum { MAX_ARRS = 16 }; UMatData* u[MAX_ARRS]; bool isInProgress; + bool isAsyncRun; // true if kernel was scheduled in async mode int nu; std::list images; bool haveTempDstUMats; @@ -3111,13 +3112,45 @@ bool Kernel::run(int dims, size_t _globalsize[], size_t _localsize[], } +static bool isRaiseErrorOnReuseAsyncKernel() +{ + static bool initialized = false; + static bool value = false; + if (!initialized) + { + value = cv::utils::getConfigurationParameterBool("OPENCV_OPENCL_RAISE_ERROR_REUSE_ASYNC_KERNEL", false); + initialized = true; + } + return value; +} + bool Kernel::Impl::run(int dims, size_t globalsize[], size_t localsize[], bool sync, int64* timeNS, const Queue& q) { CV_INSTRUMENT_REGION_OPENCL_RUN(name.c_str()); - if (!handle || isInProgress) + if (!handle) + { + CV_LOG_ERROR(NULL, "OpenCL kernel has zero handle: " << name); return false; + } + + if (isAsyncRun) + { + CV_LOG_ERROR(NULL, "OpenCL kernel can't be reused in async mode: " << name); + if (isRaiseErrorOnReuseAsyncKernel()) + CV_Assert(0); + return false; // OpenCV 5.0: raise error + } + isAsyncRun = !sync; + + if (isInProgress) + { + CV_LOG_ERROR(NULL, "Previous OpenCL kernel launch is not finished: " << name); + if (isRaiseErrorOnReuseAsyncKernel()) + CV_Assert(0); + return false; // OpenCV 5.0: raise error + } cl_command_queue qq = getQueue(q); if (haveTempDstUMats) diff --git a/modules/dnn/src/ocl4dnn/src/math_functions.cpp b/modules/dnn/src/ocl4dnn/src/math_functions.cpp index ea5c2c8938..47224c3be6 100644 --- a/modules/dnn/src/ocl4dnn/src/math_functions.cpp +++ b/modules/dnn/src/ocl4dnn/src/math_functions.cpp @@ -46,6 +46,8 @@ #include #include "opencl_kernels_dnn.hpp" +#include "opencv2/core/utils/logger.hpp" + namespace cv { namespace dnn { namespace ocl4dnn { enum gemm_data_type_t @@ -238,10 +240,6 @@ static bool ocl4dnnFastImageGEMM(const CBLAS_TRANSPOSE TransA, kernel_name += "_float"; } - ocl::Kernel oclk_gemm_float(kernel_name.c_str(), ocl::dnn::gemm_image_oclsrc, opts); - if (oclk_gemm_float.empty()) - return false; - while (C_start_y < M) { blockC_width = std::min(static_cast(N) - C_start_x, blocksize); @@ -348,6 +346,10 @@ static bool ocl4dnnFastImageGEMM(const CBLAS_TRANSPOSE TransA, } local[1] = 1; + ocl::Kernel oclk_gemm_float(kernel_name.c_str(), ocl::dnn::gemm_image_oclsrc, opts); + if (oclk_gemm_float.empty()) + return false; + cl_uint arg_idx = 0; if (is_image_a) oclk_gemm_float.set(arg_idx++, ocl::KernelArg::PtrReadOnly(A)); @@ -378,7 +380,10 @@ static bool ocl4dnnFastImageGEMM(const CBLAS_TRANSPOSE TransA, oclk_gemm_float.set(arg_idx++, isFirstColBlock); if (!oclk_gemm_float.run(2, global, local, false)) + { + CV_LOG_WARNING(NULL, "OpenCL kernel enqueue failed: " << kernel_name); return false; + } if (TransA == CblasNoTrans) A_start_x += blockA_width; From 261ad781224813c0138d01220b6109d5c3940657 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 18 Sep 2020 15:20:45 +0000 Subject: [PATCH 15/15] core: emit more clear messages in OutputArray::create() --- modules/core/src/matrix_wrap.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/core/src/matrix_wrap.cpp b/modules/core/src/matrix_wrap.cpp index d410ab7719..8d9e984bc8 100644 --- a/modules/core/src/matrix_wrap.cpp +++ b/modules/core/src/matrix_wrap.cpp @@ -1247,6 +1247,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, { CV_Assert( i < 0 ); Mat& m = *(Mat*)obj; + CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty Mat with locked layout (probably due to misused 'const' modifier)"); if (allowTransposed && !m.empty() && d == 2 && m.dims == 2 && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && @@ -1260,13 +1261,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) mtype = m.type(); else - CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); + CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate Mat with locked type (probably due to misused 'const' modifier)"); } if(fixedSize()) { - CV_CheckEQ(m.dims, d, ""); + CV_CheckEQ(m.dims, d, "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)"); for(int j = 0; j < d; ++j) - CV_CheckEQ(m.size[j], sizes[j], ""); + CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)"); } m.create(d, sizes, mtype); return; @@ -1276,6 +1277,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, { CV_Assert( i < 0 ); UMat& m = *(UMat*)obj; + CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty UMat with locked layout (probably due to misused 'const' modifier)"); if (allowTransposed && !m.empty() && d == 2 && m.dims == 2 && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && @@ -1289,13 +1291,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) mtype = m.type(); else - CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); + CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate UMat with locked type (probably due to misused 'const' modifier)"); } if(fixedSize()) { - CV_CheckEQ(m.dims, d, ""); + CV_CheckEQ(m.dims, d, "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)"); for(int j = 0; j < d; ++j) - CV_CheckEQ(m.size[j], sizes[j], ""); + CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)"); } m.create(d, sizes, mtype); return;