halcon_line_color

在这里插入图片描述

* This example program shows how to use lines_color and the differences
* between the output of lines_color and lines_gauss using an image in which
* some lines can only be extracted from a color image.
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
dev_set_part (0, 0, 479, 639)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
NumImages := 2
for J := 1 to NumImages by 1
    read_image (Image, 'cable' + J)
    dev_display (Image)
    disp_message (WindowHandle, 'Color image', 'window', 12, 12, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * Extract color lines from the image.  Note that since the color line extractor
    * cannot discern between bright or dark lines (in fact, this criterion does not
    * even make sense for color lines), the lines corresponding to the colored
    * cables are simply selected based on their length.
    lines_color (Image, Lines, 3.5, 0, 12, 'true', 'false')
    select_contours_xld (Lines, LongLines, 'contour_length', 450, 100000, 0, 0)
    dev_display (Image)
    dev_set_line_width (2)
    dev_set_color ('yellow')
    dev_display (LongLines)
    disp_message (WindowHandle, 'Color lines', 'window', 12, 12, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * Now construct XLD contours that are used to visualize the line width.  One
    * contour for the left and right edge of the line is constructed based on the
    * line position, angle, and width_* attributes.
    * Note that when the width is visualized you will see several abruptly changing
    * line widths.  This happens because the edges of the line merge with the
    * edges of adjacent lines because of the scale-space effects induced by the
    * smoothing that is used in lines_color to extract the lines.
    count_obj (LongLines, Number)
    gen_empty_obj (EdgesL)
    gen_empty_obj (EdgesR)
    for K := 1 to Number by 1
        select_obj (LongLines, Line, K)
        get_contour_xld (Line, Row, Col)
        get_contour_attrib_xld (Line, 'angle', Angle)
        get_contour_attrib_xld (Line, 'width_right', WidthR)
        get_contour_attrib_xld (Line, 'width_left', WidthL)
        EdgeRR := Row + cos(Angle) * WidthR
        EdgeRC := Col + sin(Angle) * WidthR
        EdgeLR := Row - cos(Angle) * WidthL
        EdgeLC := Col - sin(Angle) * WidthL
        gen_contour_polygon_xld (EdgeR, EdgeRR, EdgeRC)
        gen_contour_polygon_xld (EdgeL, EdgeLR, EdgeLC)
        concat_obj (EdgesL, EdgeL, EdgesL)
        concat_obj (EdgesR, EdgeR, EdgesR)
    endfor
    dev_display (Image)
    dev_set_line_width (2)
    dev_set_color ('yellow')
    dev_display (LongLines)
    dev_set_color ('slate blue')
    dev_display (EdgesR)
    dev_display (EdgesL)
    disp_message (WindowHandle, 'Color lines and their width', 'window', 12, 12, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * Now convert the image into a gray value image.
    rgb1_to_gray (Image, GrayImage)
    dev_display (GrayImage)
    disp_message (WindowHandle, 'Gray value image', 'window', 12, 12, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * Extract dark lines corresponding to the cables from the gray value image.
    * Note that the conversion to a gray value image causes several adjacent
    * lines to have almost identical contrasts.  Therefore, it is impossible to
    * extract the lines corresponding to the cables completely.
    lines_gauss (GrayImage, LinesGray, 3.5, 0.0, 0.7, 'dark', 'true', 'bar-shaped', 'false')
    select_contours_xld (LinesGray, LongGrayLines, 'contour_length', 50, 100000, 0, 0)
    dev_display (GrayImage)
    dev_set_line_width (2)
    dev_set_color ('yellow')
    dev_display (LongGrayLines)
    disp_message (WindowHandle, 'Gray value lines', 'window', 12, 12, 'black', 'true')
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * Now construct XLD contours that are used to visualize the line width.  One
    * contour for the left and right edge of the line is constructed based on the
    * line position, angle, and width_* attributes.
    * Note that because of the very low contrast in the gray value image many of
    * the line edges are very poorly defined, leading to wrongly extracted widths
    * in several places.
    count_obj (LongGrayLines, Number)
    gen_empty_obj (EdgesGrayL)
    gen_empty_obj (EdgesGrayR)
    for K := 1 to Number by 1
        select_obj (LongGrayLines, Line, K)
        get_contour_xld (Line, Row, Col)
        get_contour_attrib_xld (Line, 'angle', Angle)
        get_contour_attrib_xld (Line, 'width_right', WidthR)
        get_contour_attrib_xld (Line, 'width_left', WidthL)
        EdgeRR := Row + cos(Angle) * WidthR
        EdgeRC := Col + sin(Angle) * WidthR
        EdgeLR := Row - cos(Angle) * WidthL
        EdgeLC := Col - sin(Angle) * WidthL
        gen_contour_polygon_xld (EdgeR, EdgeRR, EdgeRC)
        gen_contour_polygon_xld (EdgeL, EdgeLR, EdgeLC)
        concat_obj (EdgesGrayL, EdgeL, EdgesGrayL)
        concat_obj (EdgesGrayR, EdgeR, EdgesGrayR)
    endfor
    dev_display (GrayImage)
    dev_set_line_width (2)
    dev_set_color ('yellow')
    dev_display (LongGrayLines)
    dev_set_color ('slate blue')
    dev_display (EdgesGrayL)
    dev_display (EdgesGrayR)
    disp_message (WindowHandle, 'Gray value lines and their width', 'window', 12, 12, 'black', 'true')
    if (J < NumImages)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值