用OpenCV實現二維條形碼識別/辨識

用OpenCV實現二維條形碼識別/辨識

用OpenCV實現二維條碼識別/辨識


資料來源: https://mp.weixin.qq.com/s/odrdAlfAOmNfYitRJ-k6uQ


code:

python

import cv2

bardet = cv2.barcode_BarcodeDetector()
img = cv2.imread("your file path")
ok, decoded_info, decoded_type, corners = bardet.detectAndDecode(img)

C/C++

#include "opencv2/barcode.hpp"
#include "opencv2/imgproc.hpp"

using namespace cv;
void main()
{
Ptr<barcode::BarcodeDetector> bardet = makePtr<barcode::BarcodeDetector>("sr.prototxt", "sr.caffemodel"); //如果不使用超分辨率则可以不指定模型路径
Mat input = imread("your file path");
Mat corners; //返回的检测框的四个角点坐标,如果检测到N个条码,那么维度应该是[N][4][2]
std::vector<std::string> decoded_info; //返回的解码结果,如果解码失败,则为空string
std::vector<barcode::BarcodeType> decoded_format; //返回的条码类型,如果解码失败,则为BarcodeType::NONE
bool ok = bardet->detectAndDecode(input, decoded_info, decoded_format, corners);	
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *