ocr_wafer_semi_font.hdev圓晶上semi字符提取 相關例程學習

Index:.../Applications/OCR/ocr_wafer_semi_font.hdev



* This example describes one step from the semiconductor product chain.
* In the front-end-of-line step, the ICs are printed on the wafer. To
* tag a single wafer from the production life line, each wafer receives
* an ID number, printed with the SEMI font. This ID number is read here.

dev_update_off ()
dev_close_window ()
read_image (Image, 'ocr/wafer_semi_font_01')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_draw ('margin')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (2)
dev_set_colored (12)

設置的顏色挺多的

read_ocr_class_mlp ('SEMI', OCRHandle)

用的是semi訓練模板
NumImages := 10
for Index := 1 to NumImages by 1
    * 
    * Segment characters
    read_image (Image, 'ocr/wafer_semi_font_' + Index$'02')
    * Characters must be black-on-white, i.e., dark characters on a light background
    invert_image (Image, ImageInvert)
    mean_image (Image, ImageMean, 31, 31)
    dyn_threshold (Image, ImageMean, RegionDynThresh, 7, 'light')

dynthreshold提取字符
    * Characters are often dotted. Therefore, we first merge close dots
    * that belong to the same character just before calling the operator connection
    closing_circle (RegionDynThresh, RegionClosing, 2.0)

但字符各種點,做了closing閉操作,很常用要熟悉
    connection (RegionClosing, ConnectedRegions)
    * Filter out characters based on two facts:
    * 1. Characters are printed in SEMI-12. Therefore we can make strong assumptions
    *    on the dimensions of the characters
    * 2. Characters are printed along a straight line
    select_shape (ConnectedRegions, SelectedRegions1, ['height','width'], 'and', [29,15], [60,40])

提取方法比較固定,想必因爲這一系列圖的字符所佔像素點差不多大小
    area_center (SelectedRegions1, Area, RowCh, ColumnCh)
    MedianRow := median(RowCh)

中位數,這裏很有意義,我們都學過統計,當出現這種一串穩定數據,裏面有幾個不穩定值時,該用哪種統計方法解決問題?

雖然大家都會,但解決問題時能不能想出來,則是關鍵了
    select_shape (SelectedRegions1, Chars, 'row', 'and', MedianRow - 30, MedianRow + 30)

用中位數(座標)來提取字符就很穩定了

    * 

    * Read out segmented characters
    sort_region (Chars, CharsSorted, 'character', 'true', 'column')
    shape_trans (CharsSorted, Characters, 'rectangle1')

排序後把字符外接矩陣做出來,shape-trans
    do_ocr_multi_class_mlp (Characters, ImageInvert, OCRHandle, Class, Confidence)

做匹配,關鍵還是halcon匹配算法太牛了,雖然實際用慢多了,但例程都快狠準
    * 

下面全是顯示代碼
    dev_display (ImageInvert)
    dilation_rectangle1 (Characters, RegionDilation, 7, 7)
    dev_display (RegionDilation)
    area_center (CharsSorted, Area1, Row, Column)
    MeanRow := mean(Row)
    for IndexL := 0 to |Class| - 1 by 1
        disp_message (WindowHandle, Class[IndexL], 'image', MeanRow + 40, Column[IndexL] - 20, 'black', 'true')
    endfor
    if (Index != NumImages)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
clear_ocr_class_mlp (OCRHandle)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章