refined QRCodeDetector API for OpenCV 4.0 (#13086)

* refined QRCodeDetector API for OpenCV 4.0

* expanded and tested QRCodeDetector::detectAndDecode()
This commit is contained in:
Vadim Pisarevsky
2018-11-09 12:57:27 +03:00
committed by GitHub
parent 6fb780eae6
commit 8cdf7bb84b
5 changed files with 127 additions and 58 deletions
+56 -16
View File
@@ -778,7 +778,15 @@ bool QRCodeDetector::detect(InputArray in, OutputArray points) const
{
Mat inarr = in.getMat();
CV_Assert(!inarr.empty());
CV_Assert(inarr.type() == CV_8UC1);
CV_Assert(inarr.depth() == CV_8U);
int incn = inarr.channels();
if( incn == 3 || incn == 4 )
{
Mat gray;
cvtColor(inarr, gray, COLOR_BGR2GRAY);
inarr = gray;
}
QRDetect qrdet;
qrdet.init(inarr, p->epsX, p->epsY);
if (!qrdet.localization()) { return false; }
@@ -788,15 +796,6 @@ bool QRCodeDetector::detect(InputArray in, OutputArray points) const
return true;
}
CV_EXPORTS bool detectQRCode(InputArray in, vector<Point> &points, double eps_x, double eps_y)
{
QRCodeDetector qrdetector;
qrdetector.setEpsX(eps_x);
qrdetector.setEpsY(eps_y);
return qrdetector.detect(in, points);
}
class QRDecode
{
public:
@@ -1060,11 +1059,20 @@ bool QRDecode::fullDecodingProcess()
#endif
}
CV_EXPORTS bool decodeQRCode(InputArray in, InputArray points, std::string &decoded_info, OutputArray straight_qrcode)
CV_EXPORTS std::string QRCodeDetector::decode(InputArray in, InputArray points,
OutputArray straight_qrcode)
{
Mat inarr = in.getMat();
CV_Assert(!inarr.empty());
inarr.convertTo(inarr, CV_8UC1);
CV_Assert(inarr.depth() == CV_8U);
int incn = inarr.channels();
if( incn == 3 || incn == 4 )
{
Mat gray;
cvtColor(inarr, gray, COLOR_BGR2GRAY);
inarr = gray;
}
CV_Assert(points.isVector());
vector<Point2f> src_points;
@@ -1074,18 +1082,50 @@ CV_EXPORTS bool decodeQRCode(InputArray in, InputArray points, std::string &deco
QRDecode qrdec;
qrdec.init(inarr, src_points);
bool exit_flag = qrdec.fullDecodingProcess();
bool ok = qrdec.fullDecodingProcess();
decoded_info = qrdec.getDecodeInformation();
std::string decoded_info = qrdec.getDecodeInformation();
if (exit_flag && straight_qrcode.needed())
if (ok && straight_qrcode.needed())
{
qrdec.getStraightBarcode().convertTo(straight_qrcode,
straight_qrcode.fixedType() ?
straight_qrcode.type() : CV_32FC2);
}
return exit_flag;
return ok ? decoded_info : std::string();
}
CV_EXPORTS std::string QRCodeDetector::detectAndDecode(InputArray in,
OutputArray points_,
OutputArray straight_qrcode)
{
Mat inarr = in.getMat();
CV_Assert(!inarr.empty());
CV_Assert(inarr.depth() == CV_8U);
int incn = inarr.channels();
if( incn == 3 || incn == 4 )
{
Mat gray;
cvtColor(inarr, gray, COLOR_BGR2GRAY);
inarr = gray;
}
vector<Point2f> points;
bool ok = detect(inarr, points);
if( points_.needed() )
{
if( ok )
Mat(points).copyTo(points_);
else
points_.release();
}
std::string decoded_info;
if( ok )
decoded_info = decode(inarr, points, straight_qrcode);
return decoded_info;
}
}