halcon-实例:根据颜色提取想要的对象

 

 实例目的:提取最上面黄色的线

在HDevelop中

复制代码
dev_close_window ()
read_image (Image, 'D:/bb/tu/8.png')
get_image_size (Image, Width, Height)
decompose3 (Image, Red, Green, Blue)
    
    *将RGB三通道数据转化为HSV色彩空间的三通道图像数据
    *HSV:看https://blog.csdn.net/xiaoyafang123/article/details/113029596
    trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv')
    
    对HSV图像中的饱和度通道进行阈值操作
    threshold (Saturation, HighSaturation, 200, 255)
    
    *获取上述阈值操作后区域中的色调通道图像数据
    reduce_domain (Hue, HighSaturation, HueHighSaturation)
    
    *对上述色调通道图像数据进行阈值处理
    threshold (HueHighSaturation, Yellow, 20, 30)
    
    *寻找连通域
    connection (Yellow, ConnectedRegions)
    
    *保留ConnectedRegions里的最大的区域
    select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 0)
    
    *对SelectedRegions进行闭运算操作
    closing_circle (SelectedRegions, Yellow, 3.5)
    
    *将Yellow区域里的图像剪切出来
    reduce_domain (Image, Yellow, ImageReduced)
    
    
    dev_open_window(10,10,Width, Height,'black',WindowHandle)
    dev_display(ImageReduced)
    

    
复制代码

 

 


在Qt Creator中

  HObject  ho_Image, ho_Red, ho_Green, ho_Blue;
  HObject  ho_Hue, ho_Saturation, ho_Intensity, ho_HighSaturation;
  HObject  ho_HueHighSaturation, ho_Yellow, ho_ConnectedRegions;
  HObject  ho_SelectedRegions, ho_ImageReduced;
  HTuple  hv_Width, hv_Height, hv_WindowHandle;

 

复制代码
  ReadImage(&ho_Image, "D:/bb/tu/8.png");
  GetImageSize(ho_Image, &hv_Width, &hv_Height);
  Decompose3(ho_Image, &ho_Red, &ho_Green, &ho_Blue);

  //将RGB三通道数据转化为HSV色彩空间的三通道图像数据
  //HSV:看https://blog.csdn.net/xiaoyafang123/article/details/113029596
  TransFromRgb(ho_Red, ho_Green, ho_Blue, &ho_Hue, &ho_Saturation, &ho_Intensity, 
      "hsv");

  //对HSV图像中的饱和度通道进行阈值操作
  Threshold(ho_Saturation, &ho_HighSaturation, 200, 255);

  //获取上述阈值操作后区域中的色调通道图像数据
  ReduceDomain(ho_Hue, ho_HighSaturation, &ho_HueHighSaturation);

  //对上述色调通道图像数据进行阈值处理
  Threshold(ho_HueHighSaturation, &ho_Yellow, 20, 30);

  //寻找连通域
  Connection(ho_Yellow, &ho_ConnectedRegions);

  //保留ConnectedRegions里的最大的区域
  SelectShapeStd(ho_ConnectedRegions, &ho_SelectedRegions, "max_area", 0);

  //对SelectedRegions进行闭运算操作
  ClosingCircle(ho_SelectedRegions, &ho_Yellow, 3.5);

  //将Yellow区域里的图像剪切出来
  ReduceDomain(ho_Image, ho_Yellow, &ho_ImageReduced);


  SetWindowAttr("background_color","black");
  OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
  HDevWindowStack::Push(hv_WindowHandle);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_ImageReduced, HDevWindowStack::GetActive());
复制代码

 

 

posted @   天子骄龙  阅读(1351)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
历史上的今天:
2019-05-02 python-类对象的遍历操作
点击右上角即可分享
微信分享提示

目录导航