基于halcon的目标定位与方向确定实例
程序员文章站
2022-04-03 11:12:14
基于halcon的目标定位与方向确定实例原图代码结果原图代码dev_close_window ()*读取图像read_image (Image, 'E:/Halcon_Learn/定位方向_画箭头/clip.png')*获得图像尺寸get_image_size (Image, Width, Height)*打开图像大小的窗口dev_open_window (0, 0, Width, Height, 'black', WindowHandle)*灰度化rgb1_to_gray (Ima...
原图
代码
dev_close_window ()
*读取图像
read_image (Image, 'E:/Halcon_Learn/定位方向_画箭头/clip.png')
*获得图像尺寸
get_image_size (Image, Width, Height)
*打开图像大小的窗口
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*灰度化
rgb1_to_gray (Image, GrayImage)
*阈值化
threshold (GrayImage, Regions, 0, 67)
*区域化分块
connection (Regions, ConnectedRegions)
*特征筛选(面积)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4380.1, 10000)
*统计符合区域个数
count_obj (SelectedRegions, Number)
*最小外接矩形
smallest_rectangle2 (SelectedRegions, Row, Column, Phi, Length1, Length2)
*设置画笔颜色
dev_set_color ('green')
*设置填充形式
dev_set_draw ('margin')
*设置线宽
dev_set_line_width (3)
*设置字体大小
set_display_font (WindowHandle, 24, 'mono', 'true', 'false')
*显示原图
dev_display (Image)
*通过最小外接矩形参数生成矩形
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*求目标各区域的旋转角度
orientation_region (SelectedRegions, Phi1)
*求目标各区域的中心
area_center (SelectedRegions, Area, Row1, Column1)
*设置画笔颜色
dev_set_color ('red')
*画区域目标方向箭头
disp_arrow (WindowHandle, Row1, Column1, Row1+Length1*cos(Phi1+1.5708), Column1+Length1*sin(Phi1+1.5708), 1)
*设置画笔颜色
dev_set_color ('blue')
*循环显示目标提示语
set_tposition (WindowHandle,10,10)
write_string (WindowHandle, '目标定位结果如下:')
*设置字体大小
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
for i := 0 to Number-1 by 1
set_tposition (WindowHandle, Row1[i], Column1[i])
write_string (WindowHandle, '第'+(i+1)+'个')
endfor
*保存窗口显示结果
dump_window (WindowHandle, 'png', '定位方向')
结果
本文地址:https://blog.csdn.net/qq_39467811/article/details/109002751
推荐阅读