From a22dd28e0272ec0f1cfee8811d3f5f0392827c65 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 20 Dec 2021 15:03:21 +0000 Subject: [PATCH 1/6] videoio: fix ffmpeg standalone build --- modules/videoio/src/cap_ffmpeg_impl.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index d5be759f43..a724d7f724 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -67,6 +67,10 @@ #ifndef CV_UNUSED // Required for standalone compilation mode (OpenCV defines this in base.hpp) #define CV_UNUSED(name) (void)name #endif +#ifndef CV_Assert // Required for standalone compilation mode (OpenCV defines this in base.hpp) +#include +#define CV_Assert(expr) assert(expr) +#endif #ifdef __cplusplus extern "C" { From 8fa86d4d34939dff48a6c12dfe8440a80e160367 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 20 Dec 2021 15:32:05 +0000 Subject: [PATCH 2/6] ffmpeg/3.4: update FFmpeg wrapper 2021.12 - FFmpeg 3.4.9 --- 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 336bf0d227..ad10940335 100644 --- a/3rdparty/ffmpeg/ffmpeg.cmake +++ b/3rdparty/ffmpeg/ffmpeg.cmake @@ -1,8 +1,8 @@ -# Binaries branch name: ffmpeg/3.4_20211005 -# Binaries were created for OpenCV: 95c1d2a8872b222f32bd88db9f1efcbd9f70a9cf -ocv_update(FFMPEG_BINARIES_COMMIT "0bf6c0753d435d2c82c03c48db0c6e18ac79976c") -ocv_update(FFMPEG_FILE_HASH_BIN32 "55c25bbc13e4a12d4339b70d3b76987f") -ocv_update(FFMPEG_FILE_HASH_BIN64 "67caee9231c6843483b4de9815d6526e") +# Binaries branch name: ffmpeg/3.4_20211220 +# Binaries were created for OpenCV: a22dd28e0272ec0f1cfee8811d3f5f0392827c65 +ocv_update(FFMPEG_BINARIES_COMMIT "5a7644ec3940c6eed41c6ebb5a0602a5615fdb3f") +ocv_update(FFMPEG_FILE_HASH_BIN32 "8ad9de6f1f2ca77786748d1f3a4e83ea") +ocv_update(FFMPEG_FILE_HASH_BIN64 "2c670f068252e7cd28d3883993dc1d6e") ocv_update(FFMPEG_FILE_HASH_CMAKE "3b90f67f4b429e77d3da36698cef700c") function(download_win_ffmpeg script_var) From 0a178a687a747fa9ad89fed3a66a368d53327028 Mon Sep 17 00:00:00 2001 From: rogday Date: Mon, 20 Dec 2021 19:53:37 +0300 Subject: [PATCH 3/6] fix const/x in Div --- modules/dnn/src/onnx/onnx_importer.cpp | 11 ++++++++++- modules/dnn/test/test_onnx_importer.cpp | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 5d88844e61..7bedf9543f 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1472,7 +1472,16 @@ void ONNXImporter::parseMul(LayerParams& layerParams, const opencv_onnx::NodePro blob = blob.reshape(1, 1); if (blob.total() == 1) { float blob_value = blob.ptr()[0]; - float coeff = isDiv ? 1.0 / blob_value : blob_value; + float coeff = blob_value; + if (isDiv) + { + coeff = 1.f / blob_value; + if (constId == 0) + { + // Power layer calculates (x*scale + shift)^power, so const/x -> (x * (1/const) + 0)^(-1) + layerParams.set("power", -1.f); + } + } layerParams.set("scale", coeff); layerParams.type = "Power"; } diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index a432f2251e..d5a5a86091 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -1056,6 +1056,11 @@ TEST_P(Test_ONNX_layers, SubFromConst) testONNXModels("sub_from_const_broadcast"); } +TEST_P(Test_ONNX_layers, DivConst) +{ + testONNXModels("div_const"); +} + INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets()); class Test_ONNX_nets : public Test_ONNX_layers From 3e01a387bad0b9fe7f639eacd724403dec7971b2 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 21 Dec 2021 15:44:59 +0000 Subject: [PATCH 4/6] highgui: fix Win32 with OPENGL=ON --- modules/highgui/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 8339a1d7d2..416fb5a315 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -163,6 +163,10 @@ if(APPLE) add_apple_compiler_options(${the_module}) endif() +if(HAVE_WIN32UI AND HAVE_OPENGL AND OPENGL_LIBRARIES) + ocv_target_link_libraries(${the_module} PRIVATE "${OPENGL_LIBRARIES}") +endif() + if(MSVC AND NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") endif() From 54c180092d2ca02e0460eac7176cab23890fc11e Mon Sep 17 00:00:00 2001 From: dwardor <50771662+dwardor@users.noreply.github.com> Date: Wed, 22 Dec 2021 13:00:00 +0100 Subject: [PATCH 5/6] Merge pull request #21114 from dwardor:patch-1 * Fix compile against lapack-3.10.0 Fix compilation against lapack >= 3.9.1 and 3.10.0 while not breaking older versions OpenCVFindLAPACK.cmake & CMakeLists.txt: determine OPENCV_USE_LAPACK_PREFIX from LAPACK_VERSION hal_internal.cpp : Only apply LAPACK_FUNC to functions whose number of inputs depends on LAPACK_FORTRAN_STR_LEN in lapack >= 3.9.1 lapack_check.cpp : remove LAPACK_FUNC which is not OK as function are not used with input parameters (so lapack.h preprocessing of "LAPACK_xxxx(...)" is not applicable with lapack >= 3.9.1 If not removed lapack_check fails so LAPACK is deactivated in build (not want we want) use OCV_ prefix and don't use Global, instead generate OCV_LAPACK_FUNC depending on CMake Conditions Remove CONFIG from find_package(LAPACK) and use LAPACK_GLOBAL and LAPACK_NAME to figure out if using netlib's reference LAPACK implementation and how to #define OCV_LAPACK_FUNC(f) * Fix typos and grammar in comments --- cmake/OpenCVFindLAPACK.cmake | 17 +++++++++++++++ modules/core/src/hal_internal.cpp | 36 +++++++++++++++---------------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/cmake/OpenCVFindLAPACK.cmake b/cmake/OpenCVFindLAPACK.cmake index 342bebc723..3f17b7b289 100644 --- a/cmake/OpenCVFindLAPACK.cmake +++ b/cmake/OpenCVFindLAPACK.cmake @@ -51,6 +51,23 @@ macro(ocv_lapack_check) if(NOT "${OPENCV_CBLAS_H_PATH_${_lapack_impl}}" STREQUAL "${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}") list(APPEND _lapack_content "#include \"${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}\"") endif() + list(APPEND _lapack_content " +#if defined(LAPACK_GLOBAL) || defined(LAPACK_NAME) +/* + * Using netlib's reference LAPACK implementation version >= 3.4.0 (first with C interface). + * Use LAPACK_xxxx to transparently (via predefined lapack macros) deal with pre and post 3.9.1 versions. + * LAPACK 3.9.1 introduces LAPACK_FORTRAN_STRLEN_END and modifies (through preprocessing) the declarations of the following functions used in opencv + * sposv_, dposv_, spotrf_, dpotrf_, sgesdd_, dgesdd_, sgels_, dgels_ + * which end up with an extra parameter. + * So we also need to preprocess the function calls in opencv coding by prefixing them with LAPACK_. + * The good news is the preprocessing works fine whatever netlib's LAPACK version. + */ +#define OCV_LAPACK_FUNC(f) LAPACK_##f +#else +/* Using other LAPACK implementations so fall back to opencv's assumption until now */ +#define OCV_LAPACK_FUNC(f) f##_ +#endif +") if(${_lapack_add_extern_c}) list(APPEND _lapack_content "}") endif() diff --git a/modules/core/src/hal_internal.cpp b/modules/core/src/hal_internal.cpp index 483281d1f7..cbe02780d2 100644 --- a/modules/core/src/hal_internal.cpp +++ b/modules/core/src/hal_internal.cpp @@ -163,9 +163,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n if(n == 1 && b_step == sizeof(fptype)) { if(typeid(fptype) == typeid(float)) - sposv_(L, &m, &n, (float*)a, &lda, (float*)b, &m, &lapackStatus); + OCV_LAPACK_FUNC(sposv)(L, &m, &n, (float*)a, &lda, (float*)b, &m, &lapackStatus); else if(typeid(fptype) == typeid(double)) - dposv_(L, &m, &n, (double*)a, &lda, (double*)b, &m, &lapackStatus); + OCV_LAPACK_FUNC(dposv)(L, &m, &n, (double*)a, &lda, (double*)b, &m, &lapackStatus); } else { @@ -174,9 +174,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n transpose(b, ldb, tmpB, m, m, n); if(typeid(fptype) == typeid(float)) - sposv_(L, &m, &n, (float*)a, &lda, (float*)tmpB, &m, &lapackStatus); + OCV_LAPACK_FUNC(sposv)(L, &m, &n, (float*)a, &lda, (float*)tmpB, &m, &lapackStatus); else if(typeid(fptype) == typeid(double)) - dposv_(L, &m, &n, (double*)a, &lda, (double*)tmpB, &m, &lapackStatus); + OCV_LAPACK_FUNC(dposv)(L, &m, &n, (double*)a, &lda, (double*)tmpB, &m, &lapackStatus); transpose(tmpB, m, b, ldb, n, m); delete[] tmpB; @@ -185,9 +185,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n else { if(typeid(fptype) == typeid(float)) - spotrf_(L, &m, (float*)a, &lda, &lapackStatus); + OCV_LAPACK_FUNC(spotrf)(L, &m, (float*)a, &lda, &lapackStatus); else if(typeid(fptype) == typeid(double)) - dpotrf_(L, &m, (double*)a, &lda, &lapackStatus); + OCV_LAPACK_FUNC(dpotrf)(L, &m, (double*)a, &lda, &lapackStatus); } if(lapackStatus == 0) *info = true; @@ -227,17 +227,17 @@ lapack_SVD(fptype* a, size_t a_step, fptype *w, fptype* u, size_t u_step, fptype } if(typeid(fptype) == typeid(float)) - sgesdd_(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)&work1, &lwork, iworkBuf, info); + OCV_LAPACK_FUNC(sgesdd)(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)&work1, &lwork, iworkBuf, info); else if(typeid(fptype) == typeid(double)) - dgesdd_(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)&work1, &lwork, iworkBuf, info); + OCV_LAPACK_FUNC(dgesdd)(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)&work1, &lwork, iworkBuf, info); lwork = (int)round(work1); //optimal buffer size fptype* buffer = new fptype[lwork + 1]; if(typeid(fptype) == typeid(float)) - sgesdd_(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)buffer, &lwork, iworkBuf, info); + OCV_LAPACK_FUNC(sgesdd)(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)buffer, &lwork, iworkBuf, info); else if(typeid(fptype) == typeid(double)) - dgesdd_(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)buffer, &lwork, iworkBuf, info); + OCV_LAPACK_FUNC(dgesdd)(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)buffer, &lwork, iworkBuf, info); if(!(flags & CV_HAL_SVD_NO_UV)) transpose_square_inplace(vt, ldv, n); @@ -288,18 +288,18 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste if (k == 1 && b_step == sizeof(fptype)) { if (typeid(fptype) == typeid(float)) - sgels_(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)&work1, &lwork, info); + OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)&work1, &lwork, info); else if (typeid(fptype) == typeid(double)) - dgels_(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)&work1, &lwork, info); + OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)&work1, &lwork, info); lwork = cvRound(work1); //optimal buffer size std::vector workBufMemHolder(lwork + 1); fptype* buffer = &workBufMemHolder.front(); if (typeid(fptype) == typeid(float)) - sgels_(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)buffer, &lwork, info); + OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)buffer, &lwork, info); else if (typeid(fptype) == typeid(double)) - dgels_(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)buffer, &lwork, info); + OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)buffer, &lwork, info); } else { @@ -309,18 +309,18 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste transpose(b, ldb, tmpB, m, m, k); if (typeid(fptype) == typeid(float)) - sgels_(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)&work1, &lwork, info); + OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)&work1, &lwork, info); else if (typeid(fptype) == typeid(double)) - dgels_(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)&work1, &lwork, info); + OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)&work1, &lwork, info); lwork = cvRound(work1); //optimal buffer size std::vector workBufMemHolder(lwork + 1); fptype* buffer = &workBufMemHolder.front(); if (typeid(fptype) == typeid(float)) - sgels_(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)buffer, &lwork, info); + OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)buffer, &lwork, info); else if (typeid(fptype) == typeid(double)) - dgels_(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)buffer, &lwork, info); + OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)buffer, &lwork, info); transpose(tmpB, m, b, ldb, k, m); } From b1a57c4cb29d2c6541d367085ff0631203bc386b Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 22 Dec 2021 12:38:21 +0000 Subject: [PATCH 6/6] fix 3.4 links --- .../js_assets/js_image_classification.html | 2 +- .../js_assets/js_image_classification_model_info.json | 10 +++++----- .../js_assets/js_image_classification_with_camera.html | 2 +- doc/js_tutorials/js_assets/js_object_detection.html | 2 +- .../js_assets/js_object_detection_model_info.json | 6 +++--- .../js_assets/js_object_detection_with_camera.html | 2 +- doc/js_tutorials/js_setup/js_nodejs/js_nodejs.markdown | 2 +- doc/js_tutorials/js_setup/js_usage/js_usage.markdown | 4 +++- .../interactive_calibration.markdown | 2 +- doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown | 2 +- .../dnn_halide_scheduling.markdown | 2 +- .../erosion_dilatation/erosion_dilatation.markdown | 2 +- .../random_generator_and_text.markdown | 2 +- modules/dnn/misc/quantize_face_detector.py | 2 +- modules/dnn/test/imagenet_cls_test_inception.py | 2 +- modules/python/test/tests_common.py | 2 +- platforms/readme.txt | 2 +- samples/dnn/README.md | 6 +++--- samples/dnn/openpose.cpp | 4 ++-- 19 files changed, 30 insertions(+), 28 deletions(-) diff --git a/doc/js_tutorials/js_assets/js_image_classification.html b/doc/js_tutorials/js_assets/js_image_classification.html index 656f2720b6..343f486cd6 100644 --- a/doc/js_tutorials/js_assets/js_image_classification.html +++ b/doc/js_tutorials/js_assets/js_image_classification.html @@ -116,7 +116,7 @@ swapRB = false; needSoftmax = false; // url for label file, can from local or Internet -labelsUrl = "https://raw.githubusercontent.com/opencv/opencv/master/samples/data/dnn/classification_classes_ILSVRC2012.txt"; +labelsUrl = "https://raw.githubusercontent.com/opencv/opencv/3.4/samples/data/dnn/classification_classes_ILSVRC2012.txt";