|
17 | 17 | #include <cmath>
|
18 | 18 | #include <iostream>
|
19 | 19 | #include <queue>
|
| 20 | +#include <limits> |
20 | 21 |
|
21 | 22 | namespace cv
|
22 | 23 | {
|
@@ -1293,7 +1294,7 @@ class QRDetectMulti : public QRDetect
|
1293 | 1294 | void deleteUsedPoints(vector<vector<Point2f> >& true_points_group, vector<vector<Point2f> >& loc,
|
1294 | 1295 | vector<Point2f>& tmp_localization_points);
|
1295 | 1296 | void fixationPoints(vector<Point2f> &local_point);
|
1296 |
| - bool checkPoints(const vector<Point2f>& quadrangle_points); |
| 1297 | + bool checkPoints(vector<Point2f> quadrangle_points); |
1297 | 1298 | bool checkPointsInsideQuadrangle(const vector<Point2f>& quadrangle_points);
|
1298 | 1299 | bool checkPointsInsideTriangle(const vector<Point2f>& triangle_points);
|
1299 | 1300 |
|
@@ -1571,59 +1572,39 @@ void QRDetectMulti::fixationPoints(vector<Point2f> &local_point)
|
1571 | 1572 | }
|
1572 | 1573 | }
|
1573 | 1574 |
|
1574 |
| -bool QRDetectMulti::checkPoints(const vector<Point2f>& quadrangle_points) |
| 1575 | +class BWCounter |
1575 | 1576 | {
|
1576 |
| - if (quadrangle_points.size() != 4) |
1577 |
| - return false; |
1578 |
| - vector<Point2f> quadrangle = quadrangle_points; |
1579 |
| - std::sort(quadrangle.begin(), quadrangle.end(), compareDistanse_y()); |
1580 |
| - LineIterator it1(bin_barcode_fullsize, quadrangle[1], quadrangle[0]); |
1581 |
| - LineIterator it2(bin_barcode_fullsize, quadrangle[2], quadrangle[0]); |
1582 |
| - LineIterator it3(bin_barcode_fullsize, quadrangle[1], quadrangle[3]); |
1583 |
| - LineIterator it4(bin_barcode_fullsize, quadrangle[2], quadrangle[3]); |
1584 |
| - vector<LineIterator> list_line_iter; |
1585 |
| - list_line_iter.push_back(it1); |
1586 |
| - list_line_iter.push_back(it2); |
1587 |
| - list_line_iter.push_back(it3); |
1588 |
| - list_line_iter.push_back(it4); |
1589 |
| - int count_w = 0; |
1590 |
| - int count_b = 0; |
1591 |
| - for (int j = 0; j < 3; j +=2) |
1592 |
| - { |
1593 |
| - LineIterator& li = list_line_iter[j]; |
1594 |
| - LineIterator& li2 = list_line_iter[j + 1]; |
1595 |
| - for (int i = 0; i < li.count; i++) |
| 1577 | + size_t white; |
| 1578 | + size_t black; |
| 1579 | +public: |
| 1580 | + BWCounter(size_t b = 0, size_t w = 0) : white(w), black(b) {} |
| 1581 | + BWCounter& operator+=(const BWCounter& other) { black += other.black; white += other.white; return *this; } |
| 1582 | + void count1(uchar pixel) { if (pixel == 255) white++; else if (pixel == 0) black++; } |
| 1583 | + double getBWFraction() const { return white == 0 ? std::numeric_limits<double>::infinity() : double(black) / double(white); } |
| 1584 | + static BWCounter checkOnePair(const Point2f& tl, const Point2f& tr, const Point2f& bl, const Point2f& br, const Mat& img) |
| 1585 | + { |
| 1586 | + BWCounter res; |
| 1587 | + LineIterator li1(img, tl, tr), li2(img, bl, br); |
| 1588 | + for (int i = 0; i < li1.count && i < li2.count; i++, li1++, li2++) |
1596 | 1589 | {
|
1597 |
| - |
1598 |
| - Point pt1 = li.pos(); |
1599 |
| - Point pt2 = li2.pos(); |
1600 |
| - LineIterator it0(bin_barcode_fullsize, pt1, pt2); |
1601 |
| - for (int r = 0; r < it0.count; r++) |
1602 |
| - { |
1603 |
| - int pixel = bin_barcode.at<uchar>(it0.pos().y , it0.pos().x); |
1604 |
| - if (pixel == 255) |
1605 |
| - { |
1606 |
| - count_w++; |
1607 |
| - } |
1608 |
| - if (pixel == 0) |
1609 |
| - { |
1610 |
| - count_b++; |
1611 |
| - } |
1612 |
| - it0++; |
1613 |
| - } |
1614 |
| - li++; |
1615 |
| - li2++; |
| 1590 | + LineIterator it(img, li1.pos(), li2.pos()); |
| 1591 | + for (int r = 0; r < it.count; r++, it++) |
| 1592 | + res.count1(img.at<uchar>(it.pos())); |
1616 | 1593 | }
|
| 1594 | + return res; |
1617 | 1595 | }
|
1618 |
| - if (count_w == 0) |
1619 |
| - return false; |
| 1596 | +}; |
1620 | 1597 |
|
1621 |
| - double frac = double(count_b) / double(count_w); |
1622 |
| - double bottom_bound = 0.76; |
1623 |
| - double upper_bound = 1.24; |
1624 |
| - if ((frac <= bottom_bound) || (frac >= upper_bound)) |
| 1598 | +bool QRDetectMulti::checkPoints(vector<Point2f> quadrangle) |
| 1599 | +{ |
| 1600 | + if (quadrangle.size() != 4) |
1625 | 1601 | return false;
|
1626 |
| - return true; |
| 1602 | + std::sort(quadrangle.begin(), quadrangle.end(), compareDistanse_y()); |
| 1603 | + BWCounter s; |
| 1604 | + s += BWCounter::checkOnePair(quadrangle[1], quadrangle[0], quadrangle[2], quadrangle[0], bin_barcode); |
| 1605 | + s += BWCounter::checkOnePair(quadrangle[1], quadrangle[3], quadrangle[2], quadrangle[3], bin_barcode); |
| 1606 | + const double frac = s.getBWFraction(); |
| 1607 | + return frac > 0.76 && frac < 1.24; |
1627 | 1608 | }
|
1628 | 1609 |
|
1629 | 1610 | bool QRDetectMulti::checkPointsInsideQuadrangle(const vector<Point2f>& quadrangle_points)
|
|
0 commit comments