天天看點

歡迎使用CSDN-markdown編輯器Halcon學習之旅

Halcon學習之旅

從零基礎開始學習halcon,希望能一直堅持下去。。。

1.安裝

首次是安裝halcon-10.0-windows.exe和halcon-10.0-images-windows.exe,然後各種替換檔案破解,之後打開一個例程,F5能正常。

2.安裝是否成功

開始以例程中

歡迎使用CSDN-markdown編輯器Halcon學習之旅

對現實場景中的瓶蓋打标進行識别提取。

3.例程學習

例程中的代碼量很少,但是萬事開頭難,想很好的了解并不容易:

dev_update_window ('off')
dev_update_var ('off')
dev_update_pc ('off')
dev_close_window ()
dev_open_window (, , , , 'black', WindowHandle)
set_display_font (WindowHandle, , 'mono', 'true', 'false')
dev_set_colored ()
dev_set_draw ('margin')
for J :=  to  by 
    read_image (Image, 'dot_print_rotated/dot_print_rotated_'+J$'02d')
    text_line_orientation (Image, Image, , rad(-), rad(), OrientationAngle)
    rotate_image (Image, ImageRotate, -OrientationAngle/rad()*, 'constant')
    dots_image (ImageRotate, ImageDots, , 'dark', )
    scale_image_max (ImageDots, ImageScaleMax)
    intensity (ImageRotate, ImageRotate, Mean, Deviation)
    threshold (ImageScaleMax, RegionThresh, Mean-, )
    connection (RegionThresh, ConnectedDots)
    select_shape (ConnectedDots, SelectedDots, 'area', 'and', , )
    closing_circle (RegionThresh, RegionClosing, )
    connection (RegionClosing, ConnectedRegions)
    * Connect splitted parts
    smallest_rectangle1 (ConnectedRegions, Row11, Column11, Row21, Column21)
    gen_rectangle1 (Rectangle1, Row11, Column11, Row21, Column21)
    union1 (Rectangle1, RegionUnion3)
    connection (RegionUnion3, ConnectedRegions2)
    select_shape (ConnectedRegions2, SelectedRegions, ['area','height','width'], 'and', [,,], [,,])
    * Get rectangular shape
    smallest_rectangle1 (SelectedRegions, Row1, Column1, Row2, Column2)
    gen_rectangle1 (RectangularShape, Row1, Column1, Row2, Column2)
    * Build lines
    union1 (SelectedRegions, RegionUnion)
    dilation_rectangle1 (RegionUnion, RegionDilation, , )
    connection (RegionDilation, ConnectedLines)
    select_shape (ConnectedLines, SelectedLines, 'area', 'and', , )
*     dev_display (ImageRotate)
*     dev_display (ConnectedLines)
    * Element of lines
    intersection (SelectedLines, RectangularShape, ElementOfLines)
    intersection (ElementOfLines, SelectedDots, RegionDots)
    dev_clear_window ()
    dev_display (ImageRotate)
    dev_display (ElementOfLines)
    dev_display (RegionDots)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
endfor
dev_clear_window ()
           

首先前面幾行無非是設定顯示窗體的顔色、類型之類的,從readImage開始;

a. “$”及for語句

讀圖使用for循環,J$’02d’可以了解為,圖檔名稱字尾,其中變量J(兩位十進制數),省略了字尾.png。其支援的格式有“ima, .tif, .tiff, .gif, .bmp, .jpg, .jpeg, .jp2, .png, .pcx, .ras, .xwd, .pbm, .pnm, .pgm, .ppm”;

b.函數簽名

通過多看幾次函數調用,基本發現規律:比如-

text_line_orientation (Operator)
           

其簽名為:

其中有3個“:”,抽象Fun(A:B:C:D),四個參數A、B、C、D參數集合,分别為:

1. A-圖像輸入

2. B-圖像輸出

3. C-參數輸入

4. D-參數輸出

各個集合中多個參數采用“,”隔開,沒有則為空。

c.使用方式

由于英文很久沒用,而且也不會如此多的專業術語,有道詞典是必備的,通過翻譯,其功用是确定文本行或段落的方向。通過圖像的傳入,該算子能傳回圖像應該偏移的角度值OrientationAngle,供後續的算子作圖形校正之用,值此,對HDevelop文法的套路有初步的了解。

5.牛刀小試

歡迎使用CSDN-markdown編輯器Halcon學習之旅

這裡使用PS黑圖層旋轉-30度,白色字型旋轉8.5度(獨立圖層哦),使用

text_line_orientation (Image, Image, 50, rad(-30), rad(30), OrientationAngle) rotate_image (Image, ImageRotate, -OrientationAngle/rad(180)*180, 'constant')

原套路校正效果:

歡迎使用CSDN-markdown編輯器Halcon學習之旅

這裡要注意text_line_orientation算子的限制條件,即能接收旋轉角度複原的最大承受角度為(-45度至45度)。

感覺學習一天就能看到小小效果,滿懷激動,希望能堅持學習,加油!