-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3351 from bit1002lst:decode_multi_qrcodes
fix the bug that cannot detect multi qrcode when use_nn_detector is false
- Loading branch information
Showing
10 changed files
with
255 additions
and
55 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
modules/wechat_qrcode/samples/qrcode_example_without_nn.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <iostream> | ||
#include <opencv2/core.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
#include <opencv2/wechat_qrcode.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
cout << endl << argv[0] << endl << endl; | ||
cout << "A demo program of WeChat QRCode Detector: " << endl; | ||
|
||
Mat img; | ||
int camIdx = -1; | ||
if (argc > 1) { | ||
bool live = strcmp(argv[1], "-camera") == 0; | ||
if (live) { | ||
camIdx = argc > 2 ? atoi(argv[2]) : 0; | ||
} else { | ||
img = imread(argv[1]); | ||
} | ||
} else { | ||
cout << " Usage: " << argv[0] << " <input_image>" << endl; | ||
return 0; | ||
} | ||
// The model is downloaded to ${CMAKE_BINARY_DIR}/downloads/wechat_qrcode if cmake runs without warnings, | ||
// otherwise you can download them from https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode. | ||
Ptr<wechat_qrcode::WeChatQRCode> detector; | ||
|
||
try { | ||
detector = makePtr<wechat_qrcode::WeChatQRCode>("", "", "", ""); | ||
} catch (const std::exception& e) { | ||
cout << | ||
"\n---------------------------------------------------------------\n" | ||
"Failed to initialize WeChatQRCode.\n" | ||
"---------------------------------------------------------------\n"; | ||
cout << e.what() << endl; | ||
return 0; | ||
} | ||
string prevstr = ""; | ||
vector<Mat> points; | ||
|
||
if (camIdx < 0) { | ||
auto res = detector->detectAndDecode(img, points); | ||
for (const auto& t : res) cout << t << endl; | ||
} else { | ||
VideoCapture cap(camIdx); | ||
for(;;) { | ||
cap >> img; | ||
if (img.empty()) | ||
break; | ||
auto res = detector->detectAndDecode(img, points); | ||
for (const auto& t : res) { | ||
if (t != prevstr) | ||
cout << t << endl; | ||
} | ||
if (!res.empty()) | ||
prevstr = res.back(); | ||
imshow("image", img); | ||
if (waitKey(30) >= 0) | ||
break; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import cv2 | ||
import sys | ||
|
||
print(sys.argv[0]) | ||
print('A demo program of WeChat QRCode Detector:') | ||
camIdx = -1 | ||
if len(sys.argv) > 1: | ||
if sys.argv[1] == "-camera": | ||
camIdx = int(sys.argv[2]) if len(sys.argv)>2 else 0 | ||
img = cv2.imread(sys.argv[1]) | ||
else: | ||
print(" Usage: " + sys.argv[0] + " <input_image>") | ||
exit(0) | ||
|
||
# For python API generator, it follows the template: {module_name}_{class_name}, | ||
# so it is a little weird. | ||
# The model is downloaded to ${CMAKE_BINARY_DIR}/downloads/wechat_qrcode if cmake runs without warnings, | ||
# otherwise you can download them from https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode. | ||
try: | ||
detector = cv2.wechat_qrcode_WeChatQRCode( | ||
"", "", "", "") | ||
except: | ||
print("---------------------------------------------------------------") | ||
print("Failed to initialize WeChatQRCode.") | ||
print("---------------------------------------------------------------") | ||
exit(0) | ||
|
||
prevstr = "" | ||
|
||
if camIdx < 0: | ||
res, points = detector.detectAndDecode(img) | ||
print(res,points) | ||
else: | ||
cap = cv2.VideoCapture(camIdx) | ||
while True: | ||
res, img = cap.read() | ||
if img is None: | ||
break | ||
res, points = detector.detectAndDecode(img) | ||
for t in res: | ||
if t != prevstr: | ||
print(t) | ||
if res: | ||
prevstr = res[-1] | ||
cv2.imshow("image", img) | ||
if cv2.waitKey(30) >= 0: | ||
break | ||
# When everything done, release the capture | ||
cap.release() | ||
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.