Skip to content

Commit 88fdb86

Browse files
authored
Update thinning.cpp
1 parent 4d657c7 commit 88fdb86

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

modules/ximgproc/src/thinning.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,19 @@ static void thinningIteration(Mat &img, Mat &marker, const uint8_t* const lut) {
106106
if (i == 0 || j == 0 || i == rows - 1 || j == cols - 1) { return; }
107107

108108
auto ptr = img.ptr(i, j); // p1
109-
uchar p2 = ptr[-cols];
110-
uchar p3 = ptr[-cols + 1];
111-
uchar p4 = ptr[1];
112-
uchar p5 = ptr[cols + 1];
113-
uchar p6 = ptr[cols];
114-
uchar p7 = ptr[cols - 1];
115-
uchar p8 = ptr[-1];
116-
uchar p9 = ptr[-cols - 1];
109+
if (ptr[0]) {
110+
uchar p2 = ptr[-cols];
111+
uchar p3 = ptr[-cols + 1];
112+
uchar p4 = ptr[1];
113+
uchar p5 = ptr[cols + 1];
114+
uchar p6 = ptr[cols];
115+
uchar p7 = ptr[cols - 1];
116+
uchar p8 = ptr[-1];
117+
uchar p9 = ptr[-cols - 1];
117118

118-
int neighbors = p9 | (p2 << 1) | (p3 << 2) | (p4 << 3) | (p5 << 4) | (p6 << 5) | (p7 << 6) | (p8 << 7);
119-
value = lut[neighbors];
119+
int neighbors = p9 | (p2 << 1) | (p3 << 2) | (p4 << 3) | (p5 << 4) | (p6 << 5) | (p7 << 6) | (p8 << 7);
120+
value = lut[neighbors];
121+
}
120122
});
121123

122124
img &= marker;

0 commit comments

Comments
 (0)