Halcon Digital Recognition instance annotation on bottle

Source: Internet
Author: User
* Key mastery of digital segmentation technology
* Bottle2.hdev:Segmenting and reading of numbers on a beer bottle
* Program without visualization: "Bottle.hdev"
*
* Step 0:preparations
* Specify the name of the the font to the reading the date on the bottle.
* It's easiest to use the pre-trained font industrial_0-9. If you have run the
* Program Bottlet.hdev in this directory, you can activate the second line
* To use the font trained.
FontName: = ' industrial_0-9 '
* FontName: = ' bottle '
*
* Step 1:segmentation
Dev_update_window (' off ')
Read_image (Bottle, ' bottle2 ')
Get_image_size (Bottle, Width, Height)
Dev_close_window ()
Dev_open_window (0, 0, 2*width, 2*height, ' black ', windowid)
Set_display_font (Windowid, ' mono ', ' true ', ' false ')
Dev_display (Bottle)
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
* Binary, select the darker part
Threshold (Bottle, rawsegmentation, 0, 95)
* Fill up some small holes in the middle
Fill_up_shape (rawsegmentation, removednoise, ' area ', 1, 5)
* Open operation, remove the small impurity image

Opening_circle (Removednoise, thickstructures, 2.5)


Dev_display (Bottle)
Dev_set_color (' green ')
Dev_display (Thickstructures)
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
Dev_set_draw (' margin ')
Dev_set_line_width (3)
Dev_display (Bottle)
Dev_display (Thickstructures)
Disp_continue_message (Windowid, ' black ', ' true ')
Stop ()
* Fill area, inside hole sealed up, handle edge
Fill_up (Thickstructures, Solid)
Dev_display (Bottle)
Dev_clear_window ()
Dev_display (Solid)
Disp_continue_message (Windowid, ' black ', ' true ')

Stop ()


* Rectangular open operation, separate the connected small area
Opening_rectangle1 (Solid, Cut, 1, 7)
Dev_display (Bottle)
Dev_display (Cut)
Disp_continue_message (Windowid, ' black ', ' true ')

Stop ()


* Calculate connected areas
Connection (Cut, Connectedpatterns)
* Intersection
Dev_clear_window ()
Dev_display (Connectedpatterns)
Dev_clear_window ()
Dev_display (Thickstructures)
Intersection (Connectedpatterns, Thickstructures, Numbercandidates)
Dev_clear_window ()
Dev_display (Numbercandidates)


Dev_set_colored (12)
Dev_display (Bottle)
Dev_display (Numbercandidates)
Disp_continue_message (Windowid, ' black ', ' true ')

Stop ()

* Select Area

Select_shape (Numbercandidates, Numbers, ' area ', ' and ', 300, 9999)

* Queued Sort_region (Numbers, finalnumbers, ' First_point ', ' true ', ' column ')
Dev_set_color (' Red ')
Dev_display (Bottle)
Dev_display (Numbers)
Dev_set_shape (' Rectangle1 ')
Dev_set_color (' green ')
Dev_display (Finalnumbers)
Dev_set_shape (' original ')
Dev_set_line_width (1)
Dev_set_draw (' Fill ')
*
* step2:reading
* Read the well-trained classifier. This is supposed to be a neural network and stuff like that.
READ_OCR_CLASS_MLP (FontName, Ocrhandle)
* Identification
DO_OCR_MULTI_CLASS_MLP (Finalnumbers, Bottle, Ocrhandle, Recnum, Confidence)
* Computing Center Point
Area_center (finalnumbers, area, Row, Colnum)
Set_display_font (Windowid, +, ' mono ', ' true ', ' false ')
For I: = 0 to | Recnum|-1 by 1
Disp_message (Windowid, recnum[i], ' image ', A, colnum[i]-3, ' green ', ' false ')
ENDfor

* Display effect


CLEAR_OCR_CLASS_MLP (Ocrhandle)
Dev_update_window (' on ')

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.