From 405e820fe13cb50c042996e7cfc8903a6d64a900 Mon Sep 17 00:00:00 2001 From: berak Date: Tue, 20 Apr 2021 12:59:36 +0200 Subject: [PATCH 01/15] Update contrast_preserve.hpp fix a build warning: ``` C:\Slave\workspace\precommit\windows10\opencv\modules\photo\src\contrast_preserve.hpp(289): warning C4244: '=': conversion from 'double' to '_Tp', possible loss of data with [ _Tp=float ] C:\Slave\workspace\precommit\windows10\opencv\modules\photo\src\contrast_preserve.hpp(361): warning C4244: '=': conversion from 'double' to '_Tp', possible loss of data with [ _Tp=float ] ``` (from https://build.opencv.org.cn/job/precommit/job/windows10/1633/console) --- modules/photo/src/contrast_preserve.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/photo/src/contrast_preserve.hpp b/modules/photo/src/contrast_preserve.hpp index 1afd4bc3e3..5681779fc9 100644 --- a/modules/photo/src/contrast_preserve.hpp +++ b/modules/photo/src/contrast_preserve.hpp @@ -285,9 +285,9 @@ void Decolor::grad_system(const Mat &im, vector < vector < double > > &polyGrad, add_vector(comb,idx,r,g,b); for(int i = 0;i(i,j)= + curIm.at(i,j)=static_cast( pow(rgb_channel[2].at(i,j),r)*pow(rgb_channel[1].at(i,j),g)* - pow(rgb_channel[0].at(i,j),b); + pow(rgb_channel[0].at(i,j),b)); vector curGrad; gradvector(curIm,curGrad); add_to_vector_poly(polyGrad,curGrad,idx1); From 3930c9a49201677e9e6b3e17b0a4cc932f9c4fc7 Mon Sep 17 00:00:00 2001 From: danielenricocahall Date: Tue, 20 Apr 2021 22:08:01 -0400 Subject: [PATCH 02/15] fix loop boundary condition --- modules/stitching/src/matchers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index 4c6cce8038..b3f1c7a1bf 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -826,7 +826,7 @@ void BestOf2NearestRangeMatcher::operator ()(const std::vector &f std::vector > near_pairs; for (int i = 0; i < num_images - 1; ++i) - for (int j = i + 1; j < std::min(num_images, i + range_width_); ++j) + for (int j = i + 1; j < std::min(num_images, i + 1 + range_width_); ++j) if (features[i].keypoints.size() > 0 && features[j].keypoints.size() > 0 && mask_(i, j)) near_pairs.push_back(std::make_pair(i, j)); From 2e143b87995e370bf79abd4a4cbbdfc84f294e77 Mon Sep 17 00:00:00 2001 From: Aleksandr Voron Date: Wed, 21 Apr 2021 21:29:19 +0300 Subject: [PATCH 03/15] Merge pull request #19961 from alvoron:dnn_ngraph_int64_fix Explicit usage of int64_t in CropAndResizeLayer (IE backend) * Update crop_and_resize_layer.cpp --- modules/dnn/src/layers/crop_and_resize_layer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/layers/crop_and_resize_layer.cpp b/modules/dnn/src/layers/crop_and_resize_layer.cpp index ba11c33508..261706a78e 100644 --- a/modules/dnn/src/layers/crop_and_resize_layer.cpp +++ b/modules/dnn/src/layers/crop_and_resize_layer.cpp @@ -125,7 +125,8 @@ public: auto input = nodes[0].dynamicCast()->node; auto rois = nodes[1].dynamicCast()->node; - std::vector dims = rois->get_shape(), offsets(4, 0); + auto rois_shape = rois->get_shape(); + std::vector dims(rois_shape.begin(), rois_shape.end()), offsets(4, 0); offsets[3] = 2; dims[3] = 7; @@ -139,7 +140,7 @@ public: lower_bounds, upper_bounds, strides, std::vector{}, std::vector{}); // Reshape rois from 4D to 2D - std::vector shapeData = {dims[2], 5}; + std::vector shapeData = {dims[2], 5}; auto shape = std::make_shared(ngraph::element::i64, ngraph::Shape{2}, shapeData.data()); auto reshape = std::make_shared(slice, shape, true); From 1b64851fa88700281f58812e22eff56607eb1dd1 Mon Sep 17 00:00:00 2001 From: Stefano Allegretti Date: Thu, 22 Apr 2021 20:20:12 +0200 Subject: [PATCH 04/15] Merge pull request #19951 from stal12:3.4 * Fix #4363 - wrong hierarchy (CV_RETR_TREE) in findContours * Add regression test for findContours * use C++11 => C++98 on 3.4 branch --- modules/imgproc/src/contours.cpp | 32 +++++++++++++++-- modules/imgproc/test/test_contours.cpp | 49 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index e433cdb514..241f1443f5 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -625,7 +625,8 @@ icvFetchContour( schar *ptr, /* trace contour until certain point is met. - returns 1 if met, 0 else. + returns 1 if met and this is the last contour + encountered by a raster scan reaching the point, 0 else. */ static int icvTraceContour( schar *ptr, int step, schar *stop_ptr, int is_hole ) @@ -668,14 +669,39 @@ icvTraceContour( schar *ptr, int step, schar *stop_ptr, int is_hole ) break; } - if( i3 == stop_ptr || (i4 == i0 && i3 == i1) ) + if (i3 == stop_ptr) { + if (!(*i3 & 0x80)) { + /* it's the only contour */ + return 1; + } + + /* check if this is the last contour */ + /* encountered during a raster scan */ + schar *i5; + int t = s; + while (true) + { + t = (t - 1) & 7; + i5 = i3 + deltas[t]; + if (*i5 != 0) + break; + if (t == 0) + return 1; + } + } + + if( (i4 == i0 && i3 == i1) ) break; i3 = i4; s = (s + 4) & 7; } /* end of border following loop */ } - return i3 == stop_ptr; + else { + return i3 == stop_ptr; + } + + return 0; } diff --git a/modules/imgproc/test/test_contours.cpp b/modules/imgproc/test/test_contours.cpp index a5c924829d..c07d19098b 100644 --- a/modules/imgproc/test/test_contours.cpp +++ b/modules/imgproc/test/test_contours.cpp @@ -485,6 +485,55 @@ TEST(Imgproc_FindContours, border) ASSERT_EQ(0, cvtest::norm(img, img_draw_contours, NORM_INF)); } +TEST(Imgproc_FindContours, regression_4363_shared_nbd) +{ + // Create specific test image + Mat1b img(12, 69, (const uchar&)0); + + img(1, 1) = 1; + + // Vertical rectangle with hole sharing the same NBD + for (int r = 1; r <= 10; ++r) { + for (int c = 3; c <= 5; ++c) { + img(r, c) = 1; + } + } + img(9, 4) = 0; + + // 124 small CCs + for (int r = 1; r <= 7; r += 2) { + for (int c = 7; c <= 67; c += 2) { + img(r, c) = 1; + } + } + + // Last CC + img(9, 7) = 1; + + vector< vector > contours; + vector hierarchy; + findContours(img, contours, hierarchy, RETR_TREE, CHAIN_APPROX_NONE); + + bool found = false; + size_t index = 0; + for (vector< vector >::const_iterator i = contours.begin(); i != contours.end(); ++i) + { + const vector& c = *i; + if (!c.empty() && c[0] == Point(7, 9)) + { + found = true; + index = (size_t)(i - contours.begin()); + break; + } + } + EXPECT_TRUE(found) << "Desired result: point (7,9) is a contour - Actual result: point (7,9) is not a contour"; + + if (found) + { + EXPECT_LT(hierarchy[index][3], 0) << "Desired result: (7,9) has no parent - Actual result: parent of (7,9) is another contour. index = " << index; + } +} + TEST(Imgproc_PointPolygonTest, regression_10222) { vector contour; From 886835088836d90460f33ebd002a0af23d87824c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 23 Apr 2021 22:30:06 +0000 Subject: [PATCH 05/15] doxygen: fix quotes in add_toggle macro --- doc/Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 02dd372660..808315efcf 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -31,7 +31,7 @@ MULTILINE_CPP_IS_BRIEF = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 4 -ALIASES += add_toggle{1}="@htmlonly[block]
\1
@endhtmlonly" +ALIASES += add_toggle{1}="@htmlonly[block]
\1
@endhtmlonly" ALIASES += add_toggle_cpp="@htmlonly[block]