[Blog Machine Vision] The extraction, recognition and generation of one-dimensional two-dimensional code

Source: Internet
Author: User

extraction, recognition and generation of one-dimensional two-dimensional code
0, related instructions:the "jsxyhelu.cnblogs.com/Machine Vision" section focuses on a complete set of solutions, ideas and software sets related to image processing and machine vision. We hope to provide some help to solve specific problems in practical work. First, background information:now one-dimensional code, two-dimensional code widely used in all aspects of industry. Many of the requirements related to image processing are also involved. Here also read some papers, there are some methods or art-of-air, but also some have a certain reference value. Here is just a talk about the extraction and identification of the general situation. For special cases, it must be treated in a special way, which is actually an enhanced treatment. In the processing and production of bar code, mainly with the help of Zxing      then the problem can be divided into three1.1 How to get the barcode area from the picture and extract the barcode (due to the lack of the QR code picture all here only analysis one-dimensional code, later with the two-dimensional code of the actual shot of the picture again to fill up);1.2 How to identify the barcode;1.3 How to parameter barcodesecond, the main content:2.1 How Toget the barcode area from the picture and extract the barcodebarcodes (i.e., one-dimensional code) are designed to be vertically redundant when designed. This feature is available for extraction. For example, this kind of image, after Canny->dilate->erode can get such a result
    Mat cannyClone= Mat::zeros(Size(gray.cols,gray.rows),gray.type());
    Canny(gray,canny,100,255);
    Mat element = getStructuringElement(MORPH_ELLIPSE,Size(7,3));
    morphologyEx(canny,canny,CV_MOP_DILATE,element);
    morphologyEx(canny,canny,CV_MOP_ERODE ,element);
    imwrite("canny.jpg",canny);
features have been more obvious, and then select the largest of all the contours, and the largest outline of the outer rectangle of the entire deduction, the general situation will be able to get the correct results:
Findcontours (Canny,contours,cv_retr_tree,cv_chain_approx_none);
for(intI=0;i<contours.size (); i++)
{
intItmp = Contourarea (Contours[i]);
if(Imaxcontour < Itmp)
{
IMAX = i;
Imaxcontour = itmp;
}
}
Find the processing of the contour
Rect boundrect;//Minimum bounding rectangle
Drawcontours (Cannyclone,contours,imax,scalar (255),-1);
Boundrect = Boundingrect (Mat (Contours[imax]));
Mat Srcroi = src (boundrect);
Imwrite ("Barcode.jpg", Srcroi);

2.2 How to identify the barcode;with the help of the Zxing method, the solution is one-dimensional/two-dimensional universal  String Opfilepath = System.Environment.CurrentDirectory + "\\result.jpg";
Multiformatreader Mutireader =NewCom.google.zxing.MultiFormatReader ();
Bitmap img = (Bitmap) bitmap.fromfile (Opfilepath);
if(img = = null)
return;
Luminancesource ls =NewRgbluminancesource (IMG, IMG. Width, IMG. Height);
Binarybitmap BB =NewBinarybitmap (NewCom.google.zxing.common.HybridBinarizer (LS));
Result r = Mutireader.decode (BB);
Tb. Text = R.text;
2.2 how to generate barcode;This is also the case with the help of zxing, a specific look at the code and related Materials.        Iii. Legacy Issues:since zxing is not absorbed from the source code, it cannot guarantee the robustness and portability of the algorithm, and many times the choice of the final platform should take into account the problems of zxing itself .at the same time, for some of the more complex situations, there may be more simple access to the problem, but also the specific problem of specific treatment.




From for notes (Wiz)

[Blog Machine Vision] The extraction, recognition and generation of one-dimensional two-dimensional code

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.