Halcon——矩形拟合

* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('E:/      ', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|\
                                  pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
**************************************参数设置*********************************
select_area_min:=300000
selece_area_max:=999999
select_rectangularity_min:=0.98
pixel_number:=10
**************************************算法执行*********************************
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    **********************************区域分割*********************************
    get_image_size (Image, Width, Height)
    threshold (Image, Regions, 80, 255)
    connection (Regions, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'rectangularity', 'and', \
                  select_rectangularity_min, 1)
    select_shape (SelectedRegions, SelectedRegions_rec, 'area', 'and', \
                  select_area_min, selece_area_max)
    count_obj (SelectedRegions_rec, Number)
    if (Number==0)
        continue
    else
        ******************************判断region是否完整***********************
        get_region_points (SelectedRegions_rec, Rows, Columns)
        tuple_find (Rows, 0, Indices_up)
        tuple_find (Rows, Height-1, Indices_down)
        tuple_max (Indices_up, Max_up)
        tuple_max (Indices_down, Max_down)
        if (Max_up>pixel_number or Max_down>pixel_number)
            continue
        else
            fill_up (SelectedRegions_rec, RegionFillUp)
            erosion_rectangle1 (RegionFillUp, RegionErosion, 5, 5)
            dilation_rectangle1 (RegionErosion, RegionDilation, 5, 5)
            gen_contour_region_xld (RegionDilation, Contours, 'border')
            fit_rectangle2_contour_xld (Contours, 'regression', -1, 0, 0, 3, 2, Row,\
                                        Column, Phi, Length1, Length2, PointOrder)
            gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
            area_center (Rectangle, Area, Row_rec, Column_rec)
            gen_cross_contour_xld (Cross, Row_rec, Column_rec, 30, Phi)
            dev_display (Image)
            dev_set_draw ('margin')
            dev_set_color ('red')
            dev_display (Rectangle)
            dev_set_color ('green')
            dev_display (Cross)
        endif
    endif
    stop ()
endfor

你可能感兴趣的:(Halcon)