@@ -96,6 +96,10 @@ static void thinningIteration(Mat img, int iter, int thinningType){
96
96
Mat marker = Mat::zeros (img.size (), CV_8UC1);
97
97
int rows = img.rows ;
98
98
int cols = img.cols ;
99
+ marker.col (0 ).setTo (1 );
100
+ marker.col (cols - 1 ).setTo (1 );
101
+ marker.row (0 ).setTo (1 );
102
+ marker.row (rows - 1 ).setTo (1 );
99
103
100
104
if (thinningType == THINNING_ZHANGSUEN){
101
105
marker.forEach <uchar>([=](uchar& value, const int postion[]) {
@@ -133,6 +137,7 @@ static void thinningIteration(Mat img, int iter, int thinningType){
133
137
// int m1 = iter == 0 ? (p2 * p4 * p6) : (p2 * p4 * p8);
134
138
// int m2 = iter == 0 ? (p4 * p6 * p8) : (p2 * p6 * p8);
135
139
// if (A == 1 && (B >= 2 && B <= 6) && m1 == 0 && m2 == 0) value = 0;
140
+ // else value = 1;
136
141
});
137
142
}
138
143
if (thinningType == THINNING_GUOHALL){
@@ -170,6 +175,7 @@ static void thinningIteration(Mat img, int iter, int thinningType){
170
175
// int N = N1 < N2 ? N1 : N2;
171
176
// int m = iter == 0 ? ((p6 | p7 | (!p9)) & p8) : ((p2 | p3 | (!p5)) & p4);
172
177
// if ((C == 1) && ((N >= 2) && ((N <= 3)) & (m == 0))) value = 0;
178
+ // else value = 1;
173
179
});
174
180
}
175
181
@@ -183,16 +189,15 @@ void thinning(InputArray input, OutputArray output, int thinningType){
183
189
// Enforce the range of the input image to be in between 0 - 255
184
190
processed /= 255 ;
185
191
186
- Mat prev = Mat::zeros (processed.size (), CV_8UC1);
187
- Mat diff;
192
+ Mat prev = processed.clone ();
188
193
189
194
do {
190
195
thinningIteration (processed, 0 , thinningType);
191
196
thinningIteration (processed, 1 , thinningType);
192
- absdiff ( processed, prev, diff) ;
197
+ if (! hasNonZero ( processed - prev)) break ;
193
198
processed.copyTo (prev);
194
199
}
195
- while (countNonZero (diff) > 0 );
200
+ while (true );
196
201
197
202
processed *= 255 ;
198
203
0 commit comments