@@ -235,9 +235,11 @@ vector<Vec3d> QRDetect::searchHorizontalLines()
235
235
vector<Point2f> QRDetect::separateVerticalLines (const vector<Vec3d> &list_lines)
236
236
{
237
237
CV_TRACE_FUNCTION ();
238
-
239
- for (int coeff_epsilon = 1 ; coeff_epsilon < 10 ; coeff_epsilon++)
238
+ const double min_dist_between_points = 10.0 ;
239
+ const double max_ratio = 1.0 ;
240
+ for (int coeff_epsilon_i = 1 ; coeff_epsilon_i < 101 ; ++coeff_epsilon_i)
240
241
{
242
+ const float coeff_epsilon = coeff_epsilon_i * 0 .1f ;
241
243
vector<Point2f> point2f_result = extractVerticalLines (list_lines, eps_horizontal * coeff_epsilon);
242
244
if (!point2f_result.empty ())
243
245
{
@@ -247,9 +249,23 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
247
249
point2f_result, 3 , labels,
248
250
TermCriteria (TermCriteria::EPS + TermCriteria::COUNT, 10 , 0.1 ),
249
251
3 , KMEANS_PP_CENTERS, centers);
250
- if (compactness == 0 )
252
+ double min_dist = std::numeric_limits<double >::max ();
253
+ for (size_t i = 0 ; i < centers.size (); i++)
254
+ {
255
+ double dist = norm (centers[i] - centers[(i+1 ) % centers.size ()]);
256
+ if (dist < min_dist)
257
+ {
258
+ min_dist = dist;
259
+ }
260
+ }
261
+ if (min_dist < min_dist_between_points)
262
+ {
251
263
continue ;
252
- if (compactness > 0 )
264
+ }
265
+ double mean_compactness = compactness / point2f_result.size ();
266
+ double ratio = mean_compactness / min_dist;
267
+
268
+ if (ratio < max_ratio)
253
269
{
254
270
return point2f_result;
255
271
}
@@ -456,15 +472,14 @@ bool QRDetect::localization()
456
472
vector<Point2f> list_lines_y = separateVerticalLines (list_lines_x);
457
473
if ( list_lines_y.empty () ) { return false ; }
458
474
459
- vector<Point2f> centers;
460
475
Mat labels;
461
476
kmeans (list_lines_y, 3 , labels,
462
477
TermCriteria ( TermCriteria::EPS + TermCriteria::COUNT, 10 , 0.1 ),
463
478
3 , KMEANS_PP_CENTERS, localization_points);
464
479
465
480
fixationPoints (localization_points);
466
481
467
- bool suare_flag = false , local_points_flag = false ;
482
+ bool square_flag = false , local_points_flag = false ;
468
483
double triangle_sides[3 ];
469
484
double triangle_perim, square_area, img_square_area;
470
485
if (localization_points.size () == 3 )
@@ -482,14 +497,14 @@ bool QRDetect::localization()
482
497
483
498
if (square_area > (img_square_area * 0.2 ))
484
499
{
485
- suare_flag = true ;
500
+ square_flag = true ;
486
501
}
487
502
}
488
503
else
489
504
{
490
505
local_points_flag = true ;
491
506
}
492
- if ((suare_flag || local_points_flag) && purpose == SHRINKING)
507
+ if ((square_flag || local_points_flag) && purpose == SHRINKING)
493
508
{
494
509
localization_points.clear ();
495
510
bin_barcode = resized_bin_barcode.clone ();
@@ -1970,6 +1985,13 @@ bool QRDecode::createSpline(vector<vector<Point2f> > &spline_lines)
1970
1985
}
1971
1986
}
1972
1987
}
1988
+ for (int i = 0 ; i < NUM_SIDES; i++)
1989
+ {
1990
+ if (spline_lines[i].size () == 0 )
1991
+ {
1992
+ return false ;
1993
+ }
1994
+ }
1973
1995
return true ;
1974
1996
}
1975
1997
0 commit comments