复杂情况下,目标区域定位

复杂情况下,基于halcon的目标区域定位

  • 原始图
  • 源代码
  • 处理结果

原始图

源代码

dev_close_window ()
read_image (Image, 'E:/Halcon_Learn/黑块提取_网络/1.bmp')
get_image_size (Image, Width, Height)
dev_open_window_fit_size (0, 0, Width, Height, -1, -1, WindowHandle)
dev_set_line_width (3)
dev_set_draw ('fill')
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 4, 10)
*求区域补集
complement (Regions, RegionComplement)
*图像中截取对应区域
reduce_domain (Image, RegionComplement, ImageReduced)
*均值滤波
mean_image (ImageReduced, ImageMean, 301, 301)
*动态阈值分割
dyn_threshold (ImageReduced, ImageMean, RegionDynThresh, 35, 'dark')
*开操作
opening_circle (RegionDynThresh, RegionOpening, 9)
*闭操作
closing_circle (RegionOpening, RegionClosing, 11)
*连通区域分块
connection (RegionClosing, ConnectedRegions)
*设置画笔颜色
dev_set_color ('green')
*显示原图
dev_display (Image)
*设置填充格式
dev_set_draw ('margin')
*设置字体
set_display_font (WindowHandle, 22, 'mono', 'true', 'false')
*结果提示语
set_tposition (WindowHandle, 10, 10)
write_string (WindowHandle, '黑块污渍提取结果如下:')
*显示目标区域
dev_display (ConnectedRegions)
*设置字体
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*最小外接矩形
smallest_rectangle2 (ConnectedRegions, Row, Column, Phi, Length1, Length2)
*目标区域旁显示提示语
set_tposition (WindowHandle, Row, Column+2*Length2)
write_string (WindowHandle, '目标区域')
*保存显示框
dump_window (WindowHandle, 'png', '目标区域')

处理结果

复杂情况下,目标区域定位_第1张图片

说明:本文原始图片来自网络。
代码若对你有所帮助,请多多点赞支持。

你可能感兴趣的:(HALCON,计算机视觉,经验分享,程序人生,定位)