【Halcon-example】angio.hdev

 

dev_update_off ()
read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
dev_display (Angio)
disp_message (WindowID, 'Original image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
calculate_lines_gauss_parameters (8, [12,0], Sigma, Low, High)
lines_gauss (Angio, Lines, Sigma, Low, High, 'dark', 'true', 'parabolic', 'true')
select_contours_xld (Lines, RelLines, 'length', 5.0, 999, 0, 0)
dev_set_colored (12)
dev_display (Angio)
dev_display (RelLines)
disp_message (WindowID, 'Extracted lines', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
count_obj (RelLines, Number)
sort_contours_xld (RelLines, RelLines, 'lower_left', 'true', 'row')
gen_empty_obj (PrintedLines)
for I := 1 to Number by 1
    dev_display (Angio)
    dev_set_color ('white')
    dev_display (PrintedLines)
    select_obj (RelLines, Line, I)
    dev_set_color ('green')
    dev_display (Line)
    concat_obj (PrintedLines, Line, PrintedLines)
    get_contour_xld (Line, Row, Col)
    meanRow := sum(Row) / |Row|
    meanCol := sum(Col) / |Col|
    get_contour_attrib_xld (Line, 'width_left', WidthL)
    get_contour_attrib_xld (Line, 'width_right', WidthR)
    get_contour_attrib_xld (Line, 'contrast', Contrast)
    meanContrast := sum(Contrast) / |Contrast|
    * To display the lines widths, the point at which the gray value drops
    * to 25% of the contrast between the line and the background will be
    * displayed.  This point is given by sqrt(3/4) for the parabolic line
    * model.
    Diameter := (WidthL + WidthR) * sqrt(0.75)
    Diam := sum(Diameter) / |Diameter|
    if (meanRow > Height - 50)
        disp_message (WindowID, 'diam: ' + Diam, 'image', Height - 70, meanCol, 'yellow', 'false')
    else
        disp_message (WindowID, 'diam: ' + Diam, 'image', meanRow, meanCol, 'yellow', 'false')
    endif
    disp_message (WindowID, 'Diameters of line segments', 'window', 135, 60, 'black', 'true')
    if (I < 5)
        disp_continue_message (WindowID, 'black', 'true')
        stop ()
    else
        wait_seconds (0.2)
    endif
endfor
dev_update_on ()

猜你喜欢

转载自blog.csdn.net/qingzhuyuxian/article/details/93057292