Skip to content

Commit

Permalink
fixed duplicate corners and style
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrPanov committed Sep 19, 2022
1 parent 5d90679 commit 14157b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions modules/wechat_qrcode/src/decodermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ int DecoderMgr::decodeImage(cv::Mat src, bool use_nn_detector, vector<string>& r
}
int ret = TryDecode(source, zx_results);
if (!ret) {
for(unsigned int k=0; k<zx_results.size(); k++){
for(size_t k = 0; k < zx_results.size(); k++) {
results.emplace_back(zx_results[k]->getText()->getText());
vector<Point2f> tmp_qr_points;
auto tmp_zx_points = zx_results[k]->getResultPoints();
for(int i = 0; i < tmp_zx_points->size() / 4; i++) {
for (int i = 0; i < tmp_zx_points->size() / 4; i++) {
const int ind = i * 4;
for (int j = 1; j < 4; j++){
tmp_qr_points.emplace_back(tmp_zx_points[ind+j]->getX(), tmp_zx_points[ind+j]->getY());
tmp_qr_points.emplace_back(tmp_zx_points[ind + j]->getX(), tmp_zx_points[ind + j]->getY());
}
tmp_qr_points.emplace_back(tmp_zx_points[ind]->getX(), tmp_zx_points[ind]->getY());
}
Expand Down
27 changes: 24 additions & 3 deletions modules/wechat_qrcode/src/wechat_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ 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;
vector<vector<Point2f>> zxing_points;
vector<vector<Point2f>> zxing_points, check_points;
auto ret = decodemgr.decodeImage(scaled_img, use_nn_detector_, decode_results, zxing_points);
if (ret == 0) {
for(unsigned int i=0; i<zxing_points.size(); ++i){
for(size_t i = 0; i <zxing_points.size(); i++){
vector<Point2f> points_qr = zxing_points[i];
for (auto&& pt: points_qr) {
pt /= cur_scale;
Expand All @@ -159,7 +159,28 @@ vector<string> WeChatQRCode::Impl::decode(const Mat& img, vector<Mat>& candidate
point.at<float>(j, 0) = points_qr[j].x;
point.at<float>(j, 1) = points_qr[j].y;
}
points.push_back(point);
// try to find duplicate qr corners
bool isDuplicate = false;
for (const auto &tmp_points: check_points) {
const float eps = 10.f;
for (size_t j = 0; j < tmp_points.size(); j++) {
if (abs(tmp_points[j].x - points_qr[j].x) < eps &&
abs(tmp_points[j].y - points_qr[j].y) < eps) {
isDuplicate = true;
}
else {
isDuplicate = false;
break;
}
}
}
if (isDuplicate == false) {
points.push_back(point);
check_points.push_back(points_qr);
}
else {
decode_results.erase(decode_results.begin() + i, decode_results.begin() + i + 1);
}
}
break;
}
Expand Down

0 comments on commit 14157b1

Please sign in to comment.