Skip to content

Commit cceeabf

Browse files
committed
べき長方形分解のテスト追加、不具合修正
1 parent 7f040f6 commit cceeabf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

modules/ximgproc/src/sparse_table_morphology.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
8787
&& row < rowLim && ptr[kernel.cols] == 1) continue;
8888

8989
// ignore if neighboring block is white; will be alive in deeper table
90-
if (col + colOfst <= colLim && ptr[colOfst] == 1) continue;
90+
if (col + colOfst < colLim && ptr[colOfst] == 1) continue;
9191
if (col - colOfst >= 0 && ptr[-colOfst] == 1) continue;
92-
if (row + rowOfst <= rowLim && ptr[x] == 1) continue;
92+
if (row + rowOfst < rowLim && ptr[x] == 1) continue;
9393
if (row - rowOfst >= 0 && ptr[-x] == 1) continue;
9494

9595
p2Rects.emplace_back(col, row, colDepth, rowDepth);

modules/ximgproc/test/test_sparse_table_morphology.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Mat knBig() { return getStructuringElement(cv::MorphShapes::MORPH_RECT, Size(201
4545
Mat knAsymm (){
4646
return (Mat_<uchar>(5, 5) << 0,0,0,0,0, 0,0,1,0,0, 0,1,0,0,0, 0,0,0,0,0, 0,0,1,0,0);
4747
}
48+
Mat knRnd(int size)
49+
{
50+
Mat rndMat(size, size, CV_8UC1);
51+
randu(rndMat, 0, 2);
52+
return rndMat;
53+
}
4854

4955
#pragma endregion
5056

@@ -191,6 +197,24 @@ TEST(ximgproc_StMorph_ex, regression_hitmiss) { ex_rgr(im(CV_8UC1), MORPH_HITMIS
191197

192198
#pragma endregion
193199

200+
#pragma region power2RectCovering
201+
202+
void p2RCov(InputArray kernel)
203+
{
204+
std::vector<Rect> p2Rects = stMorph::genPow2RectsToCoverKernel(kernel);
205+
Mat expected = kernel.getMat();
206+
Mat actual = Mat::zeros(kernel.size(), kernel.type());
207+
for (Rect p2Rect: p2Rects)
208+
{
209+
Rect rect(p2Rect.x, p2Rect.y, 1 << p2Rect.width, 1 << p2Rect.height);
210+
actual(rect).setTo(1);
211+
}
212+
assertArraysIdentical(expected, actual);
213+
}
214+
TEST(ximgproc_StMorph_private, feature_P2RCov_rnd) { p2RCov(knRnd(100)); }
215+
216+
#pragma endregion
217+
194218
#pragma region morph_dev
195219

196220
TEST(ximgproc_StMorph_dev, compare_with_original_erode)

0 commit comments

Comments
 (0)