HALCON示例程序color_fuses_lut_trans.hdev通過顏色對保險絲進行分類
示例程序源碼(加注釋)
- 關于顯示類函數解釋
dev_update_off () - 定義變量并初始化,這些變量都是下邊識別要用到的
FuseColors := [‘Orange’,‘Red’,‘Blue’,‘Yellow’,‘Green’]
DisplayColors := [‘coral’,‘red’,‘blue’,‘goldenrod’,‘forest green’]
FuseTypes := [5,10,15,20,30] - 在hsv的H分量重Orange閾值為 10-30, Red閾值為 0-10以此類推
HueRanges := [10,30,0,10,125,162,30,64,96,128]
dev_close_window ()
read_image (Image, ‘color/color_fuses_00’)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’) - create_color_trans_lut - 創建查找表,用于將圖像從RGB顏色空間轉換為任意顏色空間。
- create_color_trans_lut(:: 轉化后的顏色空間,從什么顏色空間轉化,圖片位數:顏色轉化句柄)
create_color_trans_lut (‘hsv’, ‘from_rgb’, 8, ColorTransLUTHandle)
for Count := 0 to 4 by 1
read_image (Image, ‘color/color_fuses_0’ + Count)
dev_display (Image)
disp_message (WindowHandle, ‘color/color_fuses0’ + Count + ‘.png’, ‘window’, 12, 512, ‘black’, ‘true’)- 下邊兩句話是將rgb圖像轉化到HSV空間。與上一篇轉化不一樣。
decompose3 (Image, Red, Green, Blue) - apply_color_trans_lut - 使用預生成的查找表進行顏色空間轉換。
- apply_color_trans_lut(圖1,圖2,圖3:圖像結果1,圖像結果2,圖像結果3:顏色轉化句柄 ?
apply_color_trans_lut (Red, Green, Blue, Hue, Saturation, Intensity, ColorTransLUTHandle) - 下邊的這些算子與上一篇寫的就是一樣的了。
threshold (Saturation, Saturated, 60, 255)
reduce_domain (Hue, Saturated, HueSaturated)
Output := []
for Fuse := 0 to |FuseTypes| - 1 by 1
threshold (HueSaturated, CurrentFuse, HueRanges[Fuse * 2], HueRanges[Fuse * 2 + 1])
connection (CurrentFuse, CurrentFuseConn)
fill_up (CurrentFuseConn, CurrentFuseFill)
select_shape (CurrentFuseFill, CurrentFuseSel, ‘area’, ‘and’, 6000, 20000)
area_center (CurrentFuseSel, FuseArea, Row1, Column1)
dev_set_color (‘magenta’)
for i := 0 to |FuseArea| - 1 by 1
disp_message (WindowHandle, FuseColors[Fuse] + ’ ’ + FuseTypes[Fuse] + ’ Ampere’, ‘image’, Row1[i] + 40, Column1[i] - 100, DisplayColors[Fuse], ‘true’)
endfor
Output := [Output,FuseColors[Fuse] + ’ Fuses: ’ + |FuseArea|]
endfor
disp_message (WindowHandle, Output, ‘window’, -1, -1, DisplayColors, ‘true’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endfor
dev_update_on ()
dev_close_window ()
- 下邊兩句話是將rgb圖像轉化到HSV空間。與上一篇轉化不一樣。
處理思路
這個例子是將三通道的RGB圖像轉化到HSV空間進行分割的例子,使用 create_color_trans_lut、decompose3 、apply_color_trans_lut三個算子實現RGB圖像轉化到HSV空間作用,使用HSV空間內區域特征更加明顯的特點進行分割。與上一篇不一樣的地方就在這個空間轉換是利用轉換查找表的形式進行的。
后記
大家有什么問題可以向我提問哈,我看到了第一時間回復,希望在學習的路上多多結交良師益友。