mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
Merge pull request #25680 from mshabunin:fix-approx-2
Reverted contour approximation behavior #25680 Related issue #25663 - revert new function behavior despite it returning different result than the old one (reverts PR #25672). Also added Coverity issue fix.
This commit is contained in:
parent
08107957d8
commit
29f91a08d5
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
@ -602,23 +605,4 @@ TEST(Imgproc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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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
|
||||
|
Loading…
Reference in New Issue
Block a user