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:
@@ -86,6 +86,7 @@ int liveQRCodeDetect()
|
||||
return -4;
|
||||
}
|
||||
|
||||
QRCodeDetector qrcode;
|
||||
TickMeter total;
|
||||
for(;;)
|
||||
{
|
||||
@@ -97,11 +98,11 @@ int liveQRCodeDetect()
|
||||
cvtColor(frame, src, COLOR_BGR2GRAY);
|
||||
|
||||
total.start();
|
||||
bool result_detection = detectQRCode(src, transform);
|
||||
bool result_detection = qrcode.detect(src, transform);
|
||||
if (result_detection)
|
||||
{
|
||||
bool result_decode = decodeQRCode(src, transform, decode_info, straight_barcode);
|
||||
if (result_decode) { cout << decode_info << '\n'; }
|
||||
decode_info = qrcode.decode(src, transform, straight_barcode);
|
||||
if (!decode_info.empty()) { cout << decode_info << '\n'; }
|
||||
}
|
||||
total.stop();
|
||||
double fps = 1 / total.getTimeSec();
|
||||
@@ -110,7 +111,7 @@ int liveQRCodeDetect()
|
||||
if (result_detection) { getMatWithQRCodeContour(frame, transform); }
|
||||
getMatWithFPS(frame, fps);
|
||||
|
||||
imshow("Live detect QR code", frame);
|
||||
imshow("Live QR code detector", frame);
|
||||
if( waitKey(30) > 0 ) { break; }
|
||||
}
|
||||
return 0;
|
||||
@@ -119,33 +120,34 @@ int liveQRCodeDetect()
|
||||
int showImageQRCodeDetect(string in, string out)
|
||||
{
|
||||
Mat src = imread(in, IMREAD_GRAYSCALE), straight_barcode;
|
||||
string decode_info;
|
||||
string decoded_info;
|
||||
vector<Point> transform;
|
||||
const int count_experiments = 10;
|
||||
double transform_time = 0.0;
|
||||
bool result_detection = false, result_decode = false;
|
||||
bool result_detection = false;
|
||||
TickMeter total;
|
||||
QRCodeDetector qrcode;
|
||||
for (size_t i = 0; i < count_experiments; i++)
|
||||
{
|
||||
total.start();
|
||||
transform.clear();
|
||||
result_detection = detectQRCode(src, transform);
|
||||
result_detection = qrcode.detect(src, transform);
|
||||
total.stop();
|
||||
transform_time += total.getTimeSec();
|
||||
total.reset();
|
||||
if (!result_detection) { break; }
|
||||
|
||||
total.start();
|
||||
result_decode = decodeQRCode(src, transform, decode_info, straight_barcode);
|
||||
decoded_info = qrcode.decode(src, transform, straight_barcode);
|
||||
total.stop();
|
||||
transform_time += total.getTimeSec();
|
||||
total.reset();
|
||||
if (!result_decode) { break; }
|
||||
if (decoded_info.empty()) { break; }
|
||||
|
||||
}
|
||||
double fps = count_experiments / transform_time;
|
||||
if (!result_detection) { cout << "Not find QR-code." << '\n'; return -2; }
|
||||
if (!result_decode) { cout << "Not decode QR-code." << '\n'; return -3; }
|
||||
if (!result_detection) { cout << "QR code not found\n"; return -2; }
|
||||
if (decoded_info.empty()) { cout << "QR code cannot be decoded\n"; return -3; }
|
||||
|
||||
Mat color_src = imread(in);
|
||||
getMatWithQRCodeContour(color_src, transform);
|
||||
@@ -166,7 +168,7 @@ int showImageQRCodeDetect(string in, string out)
|
||||
cout << "Output image file path: " << out << '\n';
|
||||
cout << "Size: " << color_src.size() << '\n';
|
||||
cout << "FPS: " << fps << '\n';
|
||||
cout << "Decode info: " << decode_info << '\n';
|
||||
cout << "Decoded info: " << decoded_info << '\n';
|
||||
|
||||
vector<int> compression_params;
|
||||
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
|
||||
|
||||
Reference in New Issue
Block a user