Halcon 一维测量/1D-Measuring
1.核心算子
measure_pos — Extract straight edges perpendicular to a rectangle or annular arc. 提取垂直于矩形或环形圆弧的直边
measure_pairs — Extract straight edge pairs perpendicular to a rectangle or annular arc 提取垂直于矩形或环形圆弧的直边对;将返回具有明-暗-亮过渡的边缘对或具有深-明-暗过渡的边缘对
measure_pairs的提取算法与measure_pos相同
2.测试
measure_pairs (Fuse, MeasureHandle, 1, 10, 'positive', 'first', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
对应效果:
measure_pairs (Fuse, MeasureHandle, 1, 10, 'negative', 'first', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
对应效果如下:
measure_pairs (Fuse, MeasureHandle, 1, 10, 'negative', 'first', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
对应效果如下:
dev_update_window ('off') dev_close_window () * **** * step: acquire image * **** read_image (Image, 'test.bmp') get_image_size (Image, Width, Height) dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowID) set_display_font (WindowID, 12, 'mono', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (3) dev_display (Image) set_display_font (WindowID, 12, 'mono', 'true', 'false') disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: create measure object * **** * -> specify ROI dev_get_window(WindowHandle) draw_rectangle2(WindowHandle, Row, Column, Angle, Length1, Length2) gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2) * -> create measure object gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bilinear', MeasureHandle) dev_display (ROI) disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: measure * **** dev_display (Image) dev_display (ROI) set_display_font(WindowHandle, 36, 'mono', 'true', 'false') measure_pairs (Image, MeasureHandle, 1, 10, 'negative', 'first', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance) disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: visualize results * **** for i := 0 to |RowEdgeFirst| - 1 by 1 *创建查找到第一条边缘 * gen_contour_polygon_xld (EdgeFirst, [-sin(Angle + rad(90)) * Length2 + RowEdgeFirst[i],-sin(Angle - rad(90)) * Length2 + RowEdgeFirst[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeFirst[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeFirst[i]]) *创建查找到第二条边缘 * gen_contour_polygon_xld (EdgeSecond, [-sin(Angle + rad(90)) * Length2 + RowEdgeSecond[i],-sin(Angle - rad(90)) * Length2 + RowEdgeSecond[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeSecond[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeSecond[i]]) gen_contour_polygon_xld (EdgeFirst, [-sin(Angle + rad(90)) * Length2 + RowEdgeFirst[i],-sin(Angle - rad(90)) * Length2 + RowEdgeFirst[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeFirst[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeFirst[i]]) *创建查找到第二条边缘 gen_contour_polygon_xld (EdgeSecond, [-sin(Angle + rad(90)) * Length2 + RowEdgeSecond[i],-sin(Angle - rad(90)) * Length2 + RowEdgeSecond[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeSecond[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeSecond[i]]) dev_set_color ('cyan') dev_display (EdgeFirst) dev_set_color ('magenta') dev_display (EdgeSecond) dev_set_color ('blue') if (i == 0) set_tposition (WindowID, RowEdgeFirst[i] + 5, ColumnEdgeFirst[i] + 20) else set_tposition (WindowID, RowEdgeFirst[i] - 40, ColumnEdgeFirst[i] + 20) endif write_string (WindowID, 'width: ' + IntraDistance[i] + ' pix') endfor disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: destroy measure object * **** close_measure (MeasureHandle) * dev_update_window ('on') * dev_clear_window ()
------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!