Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/wechat_qrcode/src/decodermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using zxing::Result;
using zxing::UnicomBlock;
namespace cv {
namespace wechat_qrcode {
int DecoderMgr::decodeImage(cv::Mat src, bool use_nn_detector, string& result) {
int DecoderMgr::decodeImage(cv::Mat src, bool use_nn_detector, string& result, vector<Point2f>& points){
int width = src.cols;
int height = src.rows;
if (width <= 20 || height <= 20)
Expand Down Expand Up @@ -46,6 +46,10 @@ int DecoderMgr::decodeImage(cv::Mat src, bool use_nn_detector, string& result) {
int ret = TryDecode(source, zx_result);
if (!ret) {
result = zx_result->getText()->getText();
auto result_points = zx_result->getResultPoints();
for(int i=0; i < result_points->size(); i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corners should be order as Top Left -> Top Right -> Bottom Right -> Bottom Left
result_points are returned in Bottom Left -> Top Left -> Top Right -> Bottom Right

points.emplace_back(result_points[i]->getX(), result_points[i]->getY());
}
return ret;
}
// try different binarizers
Expand Down
2 changes: 1 addition & 1 deletion modules/wechat_qrcode/src/decodermgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DecoderMgr {
DecoderMgr() { reader_ = new zxing::qrcode::QRCodeReader(); };
~DecoderMgr(){};

int decodeImage(cv::Mat src, bool use_nn_detector, string& result);
int decodeImage(cv::Mat src, bool use_nn_detector, string& result, vector<Point2f>& points);

private:
zxing::Ref<zxing::UnicomBlock> qbarUicomBlock_;
Expand Down
22 changes: 18 additions & 4 deletions modules/wechat_qrcode/src/wechat_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ vector<string> WeChatQRCode::Impl::decode(const Mat& img, vector<Mat>& candidate
vector<string> decode_results;
for (auto& point : candidate_points) {
Mat cropped_img;
Align *aligner = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simple Align aligner without any extra heap allocations

if (use_nn_detector_) {
Align aligner;
cropped_img = cropObj(img, point, aligner);
aligner = new Align();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using operator new(). You should use cv::Ptr or std::shared_ptr:

auto aligner = makePtr<Align>();

cropped_img = cropObj(img, point, *aligner);
} else {
cropped_img = img;
}
Expand All @@ -132,9 +133,22 @@ vector<string> WeChatQRCode::Impl::decode(const Mat& img, vector<Mat>& candidate
super_resolution_model_->processImageScale(cropped_img, cur_scale, use_nn_sr_);
string result;
DecoderMgr decodemgr;
auto ret = decodemgr.decodeImage(scaled_img, use_nn_detector_, result);

vector<Point2f> points_qr;
auto ret = decodemgr.decodeImage(scaled_img, use_nn_detector_, result, points_qr);
if (ret == 0) {
for (int i = 0; i < 4; i++) {
points_qr[i].x = points_qr[i].x / cur_scale;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (auto&& pt: points_qr) {
    pt /= cur_scale;
}

points_qr[i].y = points_qr[i].y / cur_scale;
}
if (use_nn_detector_) {
points_qr = aligner->warpBack(points_qr);
delete aligner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using operator delete(). You should use cv::Ptr or std::shared_ptr

}

for(int i = 0; i < 4; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (int i = 0; i < 4; ++i) {
    point.at<Point2f>(i) = points_qr[static_cast<size_t>(i)];
}

point.at<float>(i, 0) = points_qr[i].x;
point.at<float>(i, 1) = points_qr[i].y;
}
decode_results.push_back(result);
points.push_back(point);
break;
Expand Down