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