2D code recognition library based on OpenCV+ZXing and FPS300 +

2D code recognition library based on OpenCV+ZXing and FPS300 +

Original: gloomyfish OpenCV school yesterday

Click the blue word above to follow us

WeChat official account: OpenCV school

Focus on acquiring more knowledge of computer vision and in-depth learning

Software version information

Windows10 system OpenCV4.5.1VS2017

OpenCV official support function

OpenCV supports wechat open source QR code recognition in 4.5.1. Detection and preprocessing are realized through detection model and super-pixel model respectively, and then decoding is realized based on ZXing. At present, it is still in the expansion module, and DNN model support is also required. Although the model is small, it also consumes electricity! The advantage is three lines of code, which is simple to call:

import cv2detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr.caffemodel")image = cv2.imread("weixin.png")res, points = detector.detectAndDecode(image)

The speed of video detection + recognition is about FPS 70 +, which has been tested by some people! My first feeling after seeing this is that I have a more environmentally friendly + fast scheme.

Stones from other mountains can attack jade

Based on the traditional two-dimensional code detection, I reorganized and optimized the process, used the binary analysis method to realize the detection and positioning of two-dimensional code, and then realized the detection and recognition of two-dimensional code based on ZXing decoding. The size of the input image is:


3508x2480 My image! testing+The average recognition speed is about 25 milliseconds!

Camera based QR code real-time recognition, 640x480 resolution, detection + recognition speed over 350+FPS, 5 times faster than directly calling OpenCV official support functions! It also supports preprocessing such as rotation, low pixel reconstruction, edge interference repair and so on. If you don't believe it, please see the picture:

The code will not be released. A long time ago, when there was no QR code detection function in opencv, I wrote an article to teach you how to manually write code based on OpenCV to achieve high-precision QR code detection. Link here:

OpenCV QR code detection and location

Dry goods | 2D code detection and recognition based on OpenCV Python

The current code is based on the modification of the article code at that time, and then added ZXing library support to realize detection + recognition. It can be said that the speed is completely suspended. OpenCV officially provides three lines of code! In fact, I have encapsulated the function, and the call is very simple. The test code is as follows:

cv::Mat codeROI;
std::vector<cv::Point> pts;
ResultInfo rsinfo;
QRCodeDetector qrdetector;
cv::VideoCapture cap(0);
while (true) {
    int64 start = cv::getTickCount();
    qrdetector.detectQR(image, pts, codeROI);
    if (!codeROI.empty()) {
        qrdetector.decode(codeROI, rsinfo);
        if (rsinfo.status == 0) {
            //printf("QR Code Detected! \n");
            //printf("QR Code recognized! \n");
            //std::cout << rsinfo.code << std::endl;
            cv::putText(image, rsinfo.code, pts[0], cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(255, 0, 0), 2, 8);
    double ct = (cv::getTickCount() - start) / cv::getTickFrequency();
    // printf("execution time : %.5f ms\n", ct * 1000);
    cv::putText(image, cv::format("FPS: %.2f", 1.0/ct), cv::Point(50, 50), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 0, 255), 2, 8);
    cv::imshow("Recognition results", image);


Stop saying anything, praise, forward, and continue to tell stories in the follow-up

OpenCV school
Focus on the sharing of computer vision development technology and the use of technical framework, including OpenCV, Tensorflow, python tutorials and cases, detailed explanation of relevant algorithms, latest CV direction papers, detailed explanation of hard core code dry goods and code cases! The author has worked deeply in CV engineering for 15 years. Thank you for your attention! We look forward to your continued support!
338 original content
official account


Posted by rdoylelmt on Sun, 17 Apr 2022 12:46:22 +0930