Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/imgproc/src/contours_approx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ static void pass_cleanup(vector<ApproxItem>& ares, size_t start_idx)

if (s1 > s2 || (s1 == s2 && ares[prev].k <= ares[i].k))
/* remove second */
clear_until(ares, prev, get_next_idx(ares, i));
ares[i].removed = true;
else
/* remove first */
clear_until(ares, get_next_idx(ares, first), i);
ares[prev].removed = true;
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions modules/imgproc/src/contours_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void LinkRunner::establishLinks(int& prev_point,
lower_run = rns[rns[lower_run].next].next;
continue;
}
rns[rns[lower_run].next] = rns[rns[lower_run].next];
rns[lower_run].link = rns[lower_run].next;

// First point of contour
Expand All @@ -269,7 +268,6 @@ void LinkRunner::establishLinks(int& prev_point,
upper_run = rns[rns[upper_run].next].next;
continue;
}
rns[rns[upper_run].next] = rns[rns[upper_run].next];
rns[rns[upper_run].next].link = upper_run;
upper_run = rns[rns[upper_run].next].next;
}
Expand Down
22 changes: 3 additions & 19 deletions modules/imgproc/test/test_contours_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ TEST_P(Imgproc_FindContours_Modes2, approx)
findContours(img, contours, hierarchy, mode, method);

#if CHECK_OLD
// NOTE: old and new function results might not match when approximation mode is TC89.
// Currently this test passes, but might fail for other random data.
// See https://github.com/opencv/opencv/issues/25663 for details.
vector<vector<Point>> contours_o;
vector<Vec4i> hierarchy_o;
findContours_legacy(img, contours_o, hierarchy_o, mode, method);
Expand Down Expand Up @@ -602,23 +605,4 @@ TEST(Imgproc_FindContours, link_runs)
#endif
}

TEST(Imgproc_F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1,1,1,1,1,1,1,1,1,1,1};
Mat1b img(32,32,data);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_TC89_L1);
#if CHECK_OLD
vector<vector<Point>> contours_o;
findContours_legacy(img, contours_o, RETR_EXTERNAL, CHAIN_APPROX_TC89_L1);
ASSERT_EQ(contours_o.size(), contours.size());
for (size_t i = 0; i < contours_o.size(); ++i)
{
SCOPED_TRACE(format("contour = %zu", i));
EXPECT_MAT_NEAR(Mat(contours_o[i]), Mat(contours[i]), 0);
}
#endif
}

}} // namespace opencv_test