"Turn" Delphi+halcon combat one: Two lines of code identification QR codes

Source: Internet
Author: User

Delphi+halcon Real Combat One: two lines of code identification QR codes

Thanks to netizens: Peerless double pepper (qq:51536348) support

This article is peerless double pepper works, because recently in the busy ZW quantitative training, and ziwang.com website upgrade, Halcon no time to operate.

However, with the upgrading of domestic industry, the development of the robotics industry, the future of Delphi+halcon, is unlimited.

Other netizens, have halcon this aspect works, has the need, may also give the ZW forwards.

In addition, ZW is seeking to cooperate with training institutions to start Delphi+halcon training projects, interested institutions can contact qq:357811718 (King of Letters)

Environment:
Delphi XE8 Update1, Halcon 12, a QR code image. The picture is generated by the report tool, then printed and then photographed with the phone. In order to test the interference identification, the picture is doodle-painted.
Results:
The core code only 2 lines, accurate identification, recognition time is only about 25ms!!!!!!!!!!

1 UnitUnit1;2 3 Interface4 5 uses6 winapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes,7 vcl.graphics, Vcl.controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls, Vcl.oleserver ,8 halconxlib_tlb, Vcl.olectrls, System.Diagnostics;9 Ten type OneTForm1 =class(Tform) A Hwindowxctrl1:thwindowxctrl; - Memo1:tmemo; - Button2:tbutton; the     procedureButton2click (sender:tobject); -   Private -     {Private Declarations} -    Public +     {Public Declarations} -   End; +  A var at Form1:tform1; -  - Implementation -  - {$R *.DFM} -  in procedureTform1.button2click (sender:tobject); - var to Op:hoperatorsetx; + srcimgage, Symbolxlds:huntypedobjectx; - hv_width, hv_height:olevariant; the DATACODEHANDLEQR, ResultHandles1, decodeddatastrings:olevariant; * savefilename:olevariant; $ Stopwatch:tstopwatch;Panax Notoginseng begin -  the Memo1.Lines.Clear; +OP: = Cohoperatorsetx.Create; A   //Clear Image the op. Genemptyobj (srcimgage); +   //reading Images -Op. Readimage (Srcimgage, Extractfilepath (Paramstr (0)) +'img\2dqr.jpg'); $   //to get the size, display the picture according to the actual size of HWINDOWXCTRL1 $ op. GetImageSize (Srcimgage, Hv_width, hv_height); -HWindowXCtrl1.HalconWindow.SetPart (0,0, Hv_height-1, Hv_width-1); -   //Display Image the op. Dispobj (Srcimgage, HWindowXCtrl1.HalconWindow.HalconID); -   //The following two core code, only two lines, you can identify the QR codeWuyi   //For specific parameter descriptions, please see Halcon's help manual theStopwatch: =tstopwatch.startnew; -Op. Createdatacode2dmodel ('QR Code','default_parameters','maximum_recognition', DATACODEHANDLEQR); WuOp. Finddatacode2d (Srcimgage, Symbolxlds, DATACODEHANDLEQR,'Train',' All', ResultHandles1, decodeddatastrings); -   //write the QR code that is identified on the image AboutHWindowXCtrl1.HalconWindow.SetColor ('Red'); $HWindowXCtrl1.HalconWindow.SetTposition ( -, -); -HWindowXCtrl1.HalconWindow.WriteString ('qr code found:'+decodeddatastrings); -   //and show the QR code to memo. -MEMO1.LINES.ADD ('QR Code:'+ Decodeddatastrings +'time consuming:'+ Stopwatch.ElapsedMilliseconds.ToString +'Ms'); A   //re-save a picture with a QR code content +   //Note: read out the QR code followed by a newline character, to be removed, or not save theSavefilename: = Extractfilepath (Paramstr (0)) +'img\'+Trim (decodeddatastrings); -   //saves the current picture, but only saves the current window size $   //I only think of this method, how to display the original image, please ZW rewrite the op. Dumpwindowimage (Srcimgage, HWindowXCtrl1.HalconWindow.HalconID); theOp. Writeimage (Srcimgage,'jpg',0, savefilename); the End; the  - End.

"Go" delphi+halcon combat one: Two lines of code identification QR codes

Related Article

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.