Skip to content
Open
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
2 changes: 2 additions & 0 deletions modules/wechat_qrcode/include/opencv2/wechat_qrcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CV_EXPORTS_W WeChatQRCode {
*/
CV_WRAP WeChatQRCode(const std::string& detector_model_path = "",
const std::string& super_resolution_model_path = "");
WeChatQRCode(const char* detector_model_buffer, size_t detector_model_len,
const char* super_resolution_model_buffer, size_t super_resolution_model_len);
~WeChatQRCode(){};

/**
Expand Down
5 changes: 5 additions & 0 deletions modules/wechat_qrcode/src/detector/ssd_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ int SSDDetector::init(const string& onnx_path) {
return 0;
}

int SSDDetector::init(const char* model_buffer, size_t model_len) {
net_ = dnn::readNetFromONNX(model_buffer, model_len);
return 0;
}

vector<Mat> SSDDetector::forward(Mat img, const int target_width, const int target_height) {
int img_w = img.cols;
int img_h = img.rows;
Expand Down
1 change: 1 addition & 0 deletions modules/wechat_qrcode/src/detector/ssd_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SSDDetector {
SSDDetector(){};
~SSDDetector(){};
int init(const std::string& onnx_path);
int init(const char* model_buffer, size_t model_len);
std::vector<Mat> forward(Mat img, const int target_width, const int target_height);

private:
Expand Down
6 changes: 6 additions & 0 deletions modules/wechat_qrcode/src/scale/super_scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ int SuperScale::init(const std::string &onnx_path) {
return 0;
}

int SuperScale::init(const char* model_buffer, size_t model_len) {
srnet_ = dnn::readNetFromONNX(model_buffer, model_len);
net_loaded_ = true;
return 0;
}

Mat SuperScale::processImageScale(const Mat &src, float scale, const bool &use_sr,
int sr_max_size) {
Mat dst = src;
Expand Down
1 change: 1 addition & 0 deletions modules/wechat_qrcode/src/scale/super_scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SuperScale {
SuperScale(){};
~SuperScale(){};
int init(const std::string &onnx_path);
int init(const char* model_buffer, size_t model_len);
Mat processImageScale(const Mat &src, float scale, const bool &use_sr, int sr_max_size = 160);

private:
Expand Down
22 changes: 22 additions & 0 deletions modules/wechat_qrcode/src/wechat_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ WeChatQRCode::WeChatQRCode(const String& detector_model_path,
}
}

WeChatQRCode::WeChatQRCode(const char* detector_model_buffer, size_t detector_model_len,
const char* super_resolution_model_buffer, size_t super_resolution_model_len) {
CV_Assert(detector_model_buffer != nullptr && detector_model_len > 0);
CV_Assert(super_resolution_model_buffer != nullptr && super_resolution_model_len > 0);

p = makePtr<WeChatQRCode::Impl>();
// initialize detector model
p->use_nn_detector_ = true;
p->detector_ = make_shared<SSDDetector>();
auto ret = p->detector_->init(detector_model_buffer, detector_model_len);
CV_Assert(ret == 0);

// initialize super_resolution_model
// it could also support non model weights by cubic resizing
// so, we initialize it first.
p->use_nn_sr_ = true;
p->super_resolution_model_ = make_shared<SuperScale>();
ret = p->super_resolution_model_->init(
super_resolution_model_buffer, super_resolution_model_len);
CV_Assert(ret == 0);
}

vector<string> WeChatQRCode::detectAndDecode(InputArray img, OutputArrayOfArrays points) {
CV_Assert(!img.empty());
CV_CheckDepthEQ(img.depth(), CV_8U, "");
Expand Down
Loading