HALCON示例程序measure_circuit_width_lines_gauss.hdev电路板线宽检测
生活随笔
收集整理的這篇文章主要介紹了
HALCON示例程序measure_circuit_width_lines_gauss.hdev电路板线宽检测
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
HALCON示例程序measure_circuit_width_lines_gauss.hdev電路板線寬檢測
示例程序源碼(加注釋)
- 關于顯示類函數解釋
dev_update_off ()
dev_close_window ()
read_image (Image, ‘pcb_color’)
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
dev_display (Image)
dev_set_draw (‘margin’)
dev_set_color (‘yellow’) - Define the minimum and maximum width of the pcb tracks
MaxTrackWidth := 6.0
MinTrackWidth := 4.0 - Select a sub-region of the image
Rectangle := [271,285,528,718]
gen_rectangle1 (PcbPart, Rectangle[0], Rectangle[1], Rectangle[2], Rectangle[3])
dev_display (Image)
dev_display (PcbPart)
disp_message (WindowHandle, ‘Measure the width of tracks using lines_gauss’, ‘window’, 12, 12, ‘black’, ‘true’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
dev_set_part (Rectangle[0] - 15, Rectangle[1] - 15, Rectangle[2] + 15, Rectangle[3] + 15)
dev_display (Image)
dev_display (PcbPart)
disp_message (WindowHandle, ‘Exemplarily shown here for a part of the circuit board’, ‘window’, 12, 12, ‘black’, ‘true’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop () - Extract the tracks
decompose3 (Image, ImageR, ImageG, ImageB)
reduce_domain (ImageG, PcbPart, ImageReduced)
threshold (ImageReduced, Region, 90, 255)
dilation_circle (Region, RegionDilation, 3.5)
opening_rectangle1 (Region, RegionOpening, 8, 8)
dilation_circle (RegionOpening, RegionDilation1, 3.5)
difference (Region, RegionDilation1, RegionDifference)
difference (RegionDilation, RegionDilation1, RegionDifference)
connection (RegionDifference, ConnectedRegions)
select_shape (ConnectedRegions, RegionSelected, ‘area’, ‘and’, 260, 4595)
union1 (RegionSelected, RegionTracks)
reduce_domain (ImageReduced, RegionTracks, ImageReducedTracks) - lines_gauss - 檢測線條及其寬度。
- lines_gauss(圖片:輸出線:高斯平滑值,滯后閾值低值,滯后閾值高值,線條是暗是亮,線條屬性,找線條模式,在無法提取線條處添加交叉點:)
lines_gauss (ImageReducedTracks, Lines, 1.5, 1, 8, ‘light’, ‘true’, ‘bar-shaped’, ‘true’) - 通過連續長度篩選線條
select_shape_xld (Lines, SelectedXLD, ‘contlength’, ‘and’, 20, 99999)
dev_display (Image)
dev_set_color (‘yellow’)
dev_display (PcbPart)
dev_set_color (‘green’)
dev_set_line_width (2)
dev_display (Lines)
disp_message (WindowHandle, ‘Extracted tracks’, ‘window’, 12, 12, ‘black’, ‘true’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
count_obj (SelectedXLD, NumberL)
RowLine := []
ColLine := []
LineWidth := []
tuple_find (min2(LineWidth,MaxTrackWidth), MaxTrackWidth, IndicesTooBroad)
tuple_find (max2(LineWidth,MinTrackWidth), MinTrackWidth, IndicesTooNarrow)
- 將各個點組成一個區域
gen_region_points (RegionTooBroad, subset(RowLine,IndicesTooBroad), subset(ColLine,IndicesTooBroad))
gen_region_points (RegionTooNarrow, subset(RowLine,IndicesTooNarrow), subset(ColLine,IndicesTooNarrow))
connection (RegionTooBroad, RegionTooBroad) - 將骨架轉換為XLD輪廓。
gen_contours_skeleton_xld (RegionTooBroad, TracksTooBroad, 1, ‘filter’)
smallest_circle (RegionTooBroad, RowTooBroad, ColumnTooBroad, RadiusTooBroad)
gen_circle_contour_xld (CircleTooBroad, RowTooBroad, ColumnTooBroad, min2(RadiusTooBroad + 10,20), 0, 6.28318, ‘positive’, 1)
connection (RegionTooNarrow, RegionTooNarrow)
gen_contours_skeleton_xld (RegionTooNarrow, TracksTooNarrow, 1, ‘filter’)
smallest_circle (RegionTooNarrow, RowTooNarrow, ColumnTooNarrow, RadiusTooNarrow)
gen_circle_contour_xld (CircleTooNarrow, RowTooNarrow, ColumnTooNarrow, min2(RadiusTooNarrow + 10,20), 0, 6.28318, ‘positive’, 1)
dev_clear_window ()
dev_display (Image)
dev_display (ImageReduced)
dev_set_line_width (1)
dev_set_color (‘green’)
dev_display (Lines)
dev_set_line_width (2)
dev_set_color (‘red’)
dev_display (TracksTooBroad)
dev_display (CircleTooBroad)
dev_set_color (‘magenta’)
dev_display (CircleTooNarrow)
dev_display (TracksTooNarrow)
disp_message (WindowHandle, [‘Extracted tracks’,’ - Too broad’,’ - Too narrow’], ‘window’, 12, 12, [‘black’,‘red’,‘magenta’], ‘true’)
處理思路
這個例子是主要講解了lines_gauss算子的應用。一個能夠提取線段的算子。
后記
大家有什么問題可以向我提問哈,我看到了第一時間回復,希望在學習的路上多多結交良師益友。
總結
以上是生活随笔為你收集整理的HALCON示例程序measure_circuit_width_lines_gauss.hdev电路板线宽检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IMX8 Audio声卡
- 下一篇: POJ 1742 Coins ( 经典多