天天看点

HALCON示例程序color_fuses_lut_trans.hdev通过颜色对保险丝进行分类HALCON示例程序color_fuses_lut_trans.hdev通过颜色对保险丝进行分类

HALCON示例程序color_fuses_lut_trans.hdev通过颜色对保险丝进行分类

示例程序源码(加注释)

  • 关于显示类函数解释

    dev_update_off ()

  • 定义变量并初始化,这些变量都是下边识别要用到的

    FuseColors := [‘Orange’,‘Red’,‘Blue’,‘Yellow’,‘Green’]

    DisplayColors := [‘coral’,‘red’,‘blue’,‘goldenrod’,‘forest green’]

    FuseTypes := [5,10,15,20,30]

  • 在hsv的H分量重Orange阈值为 10-30, Red阈值为 0-10以此类推

    HueRanges := [10,30,0,10,125,162,30,64,96,128]

    dev_close_window ()

    read_image (Image, ‘color/color_fuses_00’)

    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)

    set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)

  • create_color_trans_lut - 创建查找表,用于将图像从RGB颜色空间转换为任意颜色空间。
  • create_color_trans_lut(:: 转化后的颜色空间,从什么颜色空间转化,图片位数:颜色转化句柄)

    create_color_trans_lut (‘hsv’, ‘from_rgb’, 8, ColorTransLUTHandle)

    for Count := 0 to 4 by 1

    read_image (Image, ‘color/color_fuses_0’ + Count)

    dev_display (Image)

    disp_message (WindowHandle, ‘color/color_fuses0’ + Count + ‘.png’, ‘window’, 12, 512, ‘black’, ‘true’)

    • 下边两句话是将rgb图像转化到HSV空间。与上一篇转化不一样。

      decompose3 (Image, Red, Green, Blue)

    • apply_color_trans_lut - 使用预生成的查找表进行颜色空间转换。
    • apply_color_trans_lut(图1,图2,图3:图像结果1,图像结果2,图像结果3:颜色转化句柄 ?

      apply_color_trans_lut (Red, Green, Blue, Hue, Saturation, Intensity, ColorTransLUTHandle)

    • 下边的这些算子与上一篇写的就是一样的了。

      threshold (Saturation, Saturated, 60, 255)

      reduce_domain (Hue, Saturated, HueSaturated)

      Output := []

      for Fuse := 0 to |FuseTypes| - 1 by 1

      threshold (HueSaturated, CurrentFuse, HueRanges[Fuse * 2], HueRanges[Fuse * 2 + 1])

      connection (CurrentFuse, CurrentFuseConn)

      fill_up (CurrentFuseConn, CurrentFuseFill)

      select_shape (CurrentFuseFill, CurrentFuseSel, ‘area’, ‘and’, 6000, 20000)

      area_center (CurrentFuseSel, FuseArea, Row1, Column1)

      dev_set_color (‘magenta’)

      for i := 0 to |FuseArea| - 1 by 1

      disp_message (WindowHandle, FuseColors[Fuse] + ’ ’ + FuseTypes[Fuse] + ’ Ampere’, ‘image’, Row1[i] + 40, Column1[i] - 100, DisplayColors[Fuse], ‘true’)

      endfor

      Output := [Output,FuseColors[Fuse] + ’ Fuses: ’ + |FuseArea|]

      endfor

      disp_message (WindowHandle, Output, ‘window’, -1, -1, DisplayColors, ‘true’)

      disp_continue_message (WindowHandle, ‘black’, ‘true’)

      stop ()

      endfor

      dev_update_on ()

      dev_close_window ()

处理思路

这个例子是将三通道的RGB图像转化到HSV空间进行分割的例子,使用 create_color_trans_lut、decompose3 、apply_color_trans_lut三个算子实现RGB图像转化到HSV空间作用,使用HSV空间内区域特征更加明显的特点进行分割。与上一篇不一样的地方就在这个空间转换是利用转换查找表的形式进行的。

后记

大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。

继续阅读