工控编程吧
标题:
1.9 halcon 测量圆形金属弧长
[打印本页]
作者:
qq263946146
时间:
2019-3-19 15:58
标题:
1.9 halcon 测量圆形金属弧长
前面帖子介绍的为矩形范围内测量边缘对的距离。
其实很多情况会有测量弧长的需要。
当前这个帖子通过 使用函数gen_measure_arc来计算弧长。
(, 下载次数: 1)
上传
点击文件名下载附件
实现代码与注释如下:
*从磁盘读取图片保存到变量Zeiss1
read_image (Zeiss1, 'zeiss1')
*获取图片长宽
get_image_size (Zeiss1, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Zeiss1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* draw_circle (WindowHandle, Row, Column, Radius)
Row := 275
Column := 335
Radius := 107
AngleStart := -rad(55)
AngleExtent := rad(170)
dev_set_draw ('fill')
dev_set_color ('green')
dev_set_line_width (1)
*函数用于计算椭圆上特定角度 上的一个点,为实现绘制出测量区域,与绘制矩形区域 类似 。
*AngleStart + AngleExtent,为圆弧起始角度与拓展角度之和,
*Row, Column, 为椭圆中心行列坐标
*0为椭圆主轴旋转角度, Radius, Radius,为椭圆长短半轴长度,
*RowPoint, ColPoint为椭圆上点的行列坐标,为数组形式,由AngleStart + AngleExtent范围决定
get_points_ellipse (AngleStart + AngleExtent, Row, Column, 0, Radius, Radius, RowPoint, ColPoint)
*显示弧度,Row, Column为椭圆中心行列坐标,AngleExtent为起点终点的的角度范围
*RowPoint, ColPoint为圆弧起点。
disp_arc (WindowHandle, Row, Column, AngleExtent, RowPoint, ColPoint)
dev_set_line_width (3)
*生成测量圆弧,和前面帖子生成的测量矩形类似。用于非直线他的同学的边缘距离 提取。
*Row, Column, 为圆弧中心行列坐标,Radius, AngleStart, AngleExtent,为圆弧半径,起始角度,
*10, Width, Height, 为圆弧宽度一半,图像宽,度。
*'nearest_neighbor',在投影时采用近邻插值方法, MeasureHandle为前面 生成的测量圆弧句柄。
gen_measure_arc (Row, Column, Radius, AngleStart, AngleExtent, 10, Width, Height, 'nearest_neighbor', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
count_seconds (Seconds1)
n := 10
for i := 1 to n by 1
*measure_pos前面帖子已介绍过,为一测量函数,用于测量边缘音距离 ,Image为输入图像, MeasureHandle为输入窗口句柄 ,
*1.5为高斯平滑系数, 30为最小边缘幅度值, 'all'检测所有正负边缘, 'all'表示选中所有边缘,
*RowEdge, ColumnEdge边缘中心行列坐标, Amplitude边缘幅度大小, Distance边缘间距
measure_pos (Zeiss1, MeasureHandle, 1, 10, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
endfor
count_seconds (Seconds2)
Time := (Seconds2 - Seconds1) / n
disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
distance_pp (RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2], IntermedDist)
* dev_display (Zeiss1)
dev_set_color ('red')
* disp_circle (WindowHandle, RowEdge, ColumnEdge, RowEdge - RowEdge + 1)
disp_line (WindowHandle, RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2])
dev_set_color ('yellow')
disp_message (WindowHandle, 'Distance: ' + IntermedDist, 'image', 250, 80, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\zeiss_result')
close_measure (MeasureHandle)
dev_set_line_width (1)
* disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()
复制代码
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4