【issue-halcon例程学习】measure_pin.hdev

例程功能

检测IC引脚。代码更多地关注测量函数的可视化情况。

代码如下

cpp 复制代码
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 ()
* draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_update_pc ('off')
dev_update_var ('off')
n := 100
count_seconds (Seconds1)
for i := 1 to n by 1
    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')
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)
avgPinWidth := sum(PinWidth) / |PinWidth|
avgPinDistance := sum(PinDistance) / |PinDistance|
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 ()
* draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
Row1 := 0
Column1 := 600
Row2 := 100
Column2 := 700
dev_set_color ('blue')
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 ()
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
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
stop ()
measure_pos (Image, MeasureHandle, 1.5, 30, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
PinHeight1 := RowEdge[1] - RowEdge[0]
PinHeight2 := RowEdge[3] - RowEdge[2]
dev_set_color ('red')
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')
dev_set_draw ('fill')
dev_set_line_width (1)

要点

  1. disp_continue_message------在WindowHandle对应区域右下角显示Press Run (F5) to continue;
    WindowHandle:入参,文本显示的窗口句柄;
    Color :入参,文本显示的颜色;
    Box :入参,置true文本在白框内,反之无白框;
  2. disp_line------显示线段;
    WindowHandle:入参,窗口句柄;
    Row1 :入参,起始点行值(纵坐标);
    Column1 :入参,起始点列值(横坐标);
    Row2 :入参,终止点行值(纵坐标);
    Column2 :入参,终止点列值(横坐标);
  3. disp_rectangle1------显示不带旋转角度的矩形;
    WindowHandle:入参,窗口句柄;
    Row1 :入参,左上角点行值(纵坐标);
    Column1 :入参,左上角点列值(横坐标);
    Row2 :入参,右下角点行值(纵坐标);
    Column2 :入参,右下角点列值(横坐标);
    4.measure_pairs ------提取垂直于矩形或环形弧的直边对;
    measure_pos ------提取垂直于矩形或环形弧的直边;
相关推荐
IT技术员21 分钟前
【Java学习】动态代理有哪些形式?
java·python·学习
一只码代码的章鱼1 小时前
学习笔记(算法学习+Maven)
笔记·学习·算法
冰茶_2 小时前
WPF TextBlock控件性能优化指南
学习·性能优化·wpf·控件
keep intensify2 小时前
数据结构---单链表的增删查改
c语言·数据结构·c++·经验分享·学习·算法·分享
2501_915373882 小时前
怎样学习Electron
javascript·学习·electron
怀念无所不能的你3 小时前
acwing背包问题求方案数
学习·算法·动态规划·dp
LVerrrr4 小时前
Missashe考研日记-day29
学习·考研
灏瀚星空4 小时前
从基础到实战的量化交易全流程学习:1.3 数学与统计学基础——线性代数与矩阵运算 | 矩阵基础
笔记·python·学习·线性代数·数学建模·金融·矩阵
qq_162911594 小时前
tigase源码学习杂记-IO处理的线程模型
java·学习·源码·xmpp·tigase·多线程io模型
viperrrrrrrrrr74 小时前
大数据学习(115)-hive与impala
大数据·hive·学习·impala