Skip to content

Commit a8c1cdf

Browse files
committed
Merge pull request opencv#17511 from mshabunin:fix-kw-issues-34
2 parents 781fbde + 7a187e9 commit a8c1cdf

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

modules/dnn/src/dnn.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,7 @@ struct Net::Impl : public detail::NetImplBase
20232023
Ptr<BackendNode> inpNode = inpLd.backendNodes[preferableBackend];
20242024
if (!inpNode.empty()) {
20252025
Ptr<InfEngineNgraphNode> ieNode = inpNode.dynamicCast<InfEngineNgraphNode>();
2026+
CV_Assert(!ieNode.empty());
20262027
ieNode->net->setUnconnectedNodes(ieNode);
20272028
}
20282029
}
@@ -2067,6 +2068,7 @@ struct Net::Impl : public detail::NetImplBase
20672068
int cons_inp = cons->oid;
20682069
Ptr<NgraphBackendWrapper> inpWrapper = inpLd.outputBlobsWrappers[cons_inp].
20692070
dynamicCast<NgraphBackendWrapper>();
2071+
CV_Assert(!inpWrapper.empty());
20702072
auto iter = std::find(inputNames.begin(), inputNames.end(),
20712073
inpWrapper->dataPtr->getName());
20722074
if (iter == inputNames.end()) {

modules/objdetect/src/qrcode.cpp

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cmath>
1818
#include <iostream>
1919
#include <queue>
20+
#include <limits>
2021

2122
namespace cv
2223
{
@@ -1293,7 +1294,7 @@ class QRDetectMulti : public QRDetect
12931294
void deleteUsedPoints(vector<vector<Point2f> >& true_points_group, vector<vector<Point2f> >& loc,
12941295
vector<Point2f>& tmp_localization_points);
12951296
void fixationPoints(vector<Point2f> &local_point);
1296-
bool checkPoints(const vector<Point2f>& quadrangle_points);
1297+
bool checkPoints(vector<Point2f> quadrangle_points);
12971298
bool checkPointsInsideQuadrangle(const vector<Point2f>& quadrangle_points);
12981299
bool checkPointsInsideTriangle(const vector<Point2f>& triangle_points);
12991300

@@ -1571,59 +1572,39 @@ void QRDetectMulti::fixationPoints(vector<Point2f> &local_point)
15711572
}
15721573
}
15731574

1574-
bool QRDetectMulti::checkPoints(const vector<Point2f>& quadrangle_points)
1575+
class BWCounter
15751576
{
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++)
15961589
{
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()));
16161593
}
1594+
return res;
16171595
}
1618-
if (count_w == 0)
1619-
return false;
1596+
};
16201597

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)
16251601
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;
16271608
}
16281609

16291610
bool QRDetectMulti::checkPointsInsideQuadrangle(const vector<Point2f>& quadrangle_points)

0 commit comments

Comments
 (0)