当前位置:网站首页>Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine

Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine

2022-07-05 07:56:00 BoomBiuBiu

This routine measures the number of chip pins 、 Average width and pin height

1、 Read the picture

dev_close_window ()
read_image (Image, 'ic_pin')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

 2、 Draw a measuring rectangle

Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
*Length1 Length2 Half width and half height 
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
* Form a measuring rectangle 
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

3、 Start measurement ---- Show results  

* to update PC by off state 
dev_update_pc ('off')
* Update variable is off state 
dev_update_var ('off')
n := 100
* Calculate start time 
count_seconds (Seconds1)
* This cycle is to measure each pin 
for i := 1 to n by 1
    * Get the measurement results 
    measure_pairs (Image, MeasureHandle, 1.5, 30, 'negative', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, PinWidth, PinDistance)
endfor
count_seconds (Seconds2)
Time := Seconds2 - Seconds1
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_color ('red')

* In order to draw the edge pairs of the detected pins with straight lines 
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)

* Find the average pin width 
avgPinWidth := sum(PinWidth) / |PinWidth|
* Find the average distance between the edge pairs of pins 
avgPinDistance := sum(PinDistance) / |PinDistance|
* Find the number of pin edge pairs 
numPins := |PinWidth|
dev_set_color ('yellow')
disp_message (WindowHandle, 'Number of pins: ' + numPins, 'image', 200, 100, 'yellow', 'false')
disp_message (WindowHandle, 'Average Pin Width:  ' + avgPinWidth, 'image', 260, 100, 'yellow', 'false')
disp_message (WindowHandle, 'Average Pin Distance:  ' + avgPinDistance, 'image', 320, 100, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\pins_result')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

 4、 Zoom in on some areas

* Drawing this rectangle is to enlarge this part of the pin image 
disp_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
stop ()

dev_set_part (Row1, Column1, Row2, Column2)
dev_display (Image)
dev_set_color ('green')
dev_display (Rectangle)
dev_set_color ('red')
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
close_measure (MeasureHandle)

5、 Measure the height of the pins

dev_set_part (0, 0, Height - 1, Width - 1)
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_set_color ('green')
* draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
Row := 508
Column := 200
Phi := -1.5708
Length1 := 482
Length2 := 35
* Form a rectangular area    Measure the pin height 
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
* Form a measuring rectangle 
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
stop ()

* Measure the distance between the edges 
measure_pos (Image, MeasureHandle, 1.5, 30, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
* The height of the upper pin 
PinHeight1 := RowEdge[1] - RowEdge[0]
* The height of the following pins 
PinHeight2 := RowEdge[3] - RowEdge[2]
dev_set_color ('red')
* Draw a straight line 
disp_line (WindowHandle, RowEdge, ColumnEdge - Length2, RowEdge, ColumnEdge + Length2)
disp_message (WindowHandle, 'Pin Height:  ' + PinHeight1, 'image', RowEdge[1] + 40, ColumnEdge[1] + 100, 'yellow', 'false')
disp_message (WindowHandle, 'Pin Height:  ' + PinHeight2, 'image', RowEdge[3] - 120, ColumnEdge[3] + 100, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\pins_height_result')
close_measure (MeasureHandle)
dev_set_draw ('fill')
dev_set_line_width (1)


Generate a measurement rectangle
gen_measure_rectangle2( : : Row, Column, Phi, Length1, Length2, Width, Height, Interpolation : MeasureHandle)

Row, Column,Phi: Measure the row and column coordinates and angles of the center of the rectangle ;
Length1, Length2: Measure the width and half height of the rectangular plate ;
Width, Height: Measure the width and height of the image where the rectangle is located ;
Interpolation: Interpolation algorithm
MeasureHandle: Handle of measuring rectangle

Find without edge pairs
measure_pos(Image : : MeasureHandle, Sigma, Threshold, Transition, Select : RowEdge, ColumnEdge, Amplitude, Distance)

MeasureHandle: Handle of measuring rectangle ;
Sigma: Gaussian smoothing coefficient ;
Threshold: Minimum margin amplitude ;
Transition: excessive , Light to dark ’negative’, Dark to bright ’positive’, Both ’all’
Select : If set to ’all’, All edge points are returned . If you set it to ’ first’, Then only the first of the extracted edge points is returned , Set it to ’last’ when , Return only the last .
RowEdge, ColumnEdge: Row and column coordinates of edge points
Amplitude: Returns the edge amplitude
Distance: Returns the distance between consecutive edges

原网站

版权声明
本文为[BoomBiuBiu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140548302306.html