Two-dimensional code open Source Library Zbar, zxing use experience

Source: Internet
Author: User

First of all, my test scenario is "identify the two-dimensional code printed on paper", look for the QR code in the scan results and identify it, instead of just letting the camera scan the QR code.

Zbar and zxing are using their own DLL compiled from GitHub's clone C + + source/interface, which is the default parameter

Again conclusion: measured about thousands of pictures, two of the accuracy of the library is almost (due to the diversity of the picture scene, the exact accuracy of the number is meaningless), but the Zbar speed is much faster, probably zxing 4-5 times. In fact, the accuracy of the two library is not very satisfactory, a little blurred can not be recognized, and even some of the image can not be blurred. In contrast, the recognition effect on the inverse of the day, how to toss can be identified, let me very curious.

Later, I try to improve the recognition effect, first look at the two-dimensional code recognition principle, too complex, can not start. So try to improve the image preprocessing, the result is only a binary add-open operation let the recognition effect has been greatly improved, let me very strange so simple preprocessing why developers did not do it? And then continue to optimize, found that two value of the threshold value of the identification of the two-dimensional code is very critical, badcase is usually due to the threshold is not suitable for the cause, so sacrifice performance, in the identification program to try different thresholds, the final recognition effect reached a more satisfactory result, the accuracy rate from 90% Up to about 99.8%, the majority of printing is not clear caused by the badcase have been resolved, the code is as follows:

#include <iostream>#include<include\zbar.h>#include"opencv/cv.h"#include"opencv/highgui.h"using namespacestd;using namespaceCV;using namespaceZbar;//Zbar Interfacestringzbardecoder (Mat img) {stringresult;    Imagescanner scanner; Const void*raw = (&img)data; //Configure the readerScanner.set_config (Zbar_qrcode, Zbar_cfg_enable,1); //Wrap image DataImage Image (Img.cols, img.rows,"Y800", Raw, Img.cols *img.rows); //Scan the image for barcodes    intn =Scanner.scan (image); //Extract Resultsresult = Image.symbol_begin ()Get_data (); Image.set_data (NULL,0); returnresult;}//recognition of two-valued images and two-time identification of open operations if they failstringgetqrinbinimg (Mat binimg) {stringresult =Zbardecoder (BINIMG); if(Result.empty ()) {Mat openimg; Mat element= Getstructuringelement (Morph_rect, Size (3,3));        Morphologyex (binimg, openimg, morph_open, Element); Result=Zbardecoder (OPENIMG); }    returnresult;}//Main functionstringGETQR (Mat img) {mat binimg; //based on the results of the Otsu two value, the threshold value is continuously increased to identify the blurred image .    intthre = Threshold (IMG, binimg,0,255, Cv::thresh_otsu); stringresult;  while(Result.empty () && thre<255) {Threshold (IMG, binimg, thre,255, cv::thresh_binary); Result=getqrinbinimg (BINIMG); Thre+= -;//The threshold step is set to 20, the greater the step, the lower the recognition rate, the faster    }    returnresult;}

Two-dimensional code open Source Library Zbar, zxing use experience

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.