排序学习总结

取每个对象的内接矩形框,然后再排序,根据排序的结果确定原对象顺序。

inner_rectangle1(RegionAffineTrans1, Row1, Column1, Row2, Column2)
gen_rectangle1(Rect,Row1, Column1, Row2, Column2)
sort_region(Rect,RectSort,'character','true', 'row')

count_obj (RegionAffineTrans1, Number)
gen_empty_obj(RegionAffineTransSort)
dev_update_off ()
for i:=1 to Number by 1    
    select_obj (RectSort, ObjectSelected1, i)    
    for j:=1 to Number by 1    
        select_obj (RegionAffineTrans1, ObjectSelected2, j)    
        intersection(ObjectSelected1,ObjectSelected2,ObjectSelected)
        area_center (ObjectSelected, Area, Row1, Column1)
        if (Area>1)
            concat_obj(RegionAffineTransSort,ObjectSelected2,RegionAffineTransSort)
            break
        endif
    endfor

endfor

排序学习总结_第1张图片

排序学习总结_第2张图片

dev_update_off ()
dev_close_window ()
read_image (Image, 'E:/Users/laihuaxun/Desktop/14_51340_b19208273509701.jpg')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/4, Height/4, 'black', WindowHandle)
dev_display (Image)


draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
dev_display (Image)
dev_display (Rectangle)
*扣图
reduce_domain (Image, Rectangle, ImageReduced)
*分割
threshold (ImageReduced, Regions, 150, 255)
connection (Regions, ConnectedRegions)
*筛选
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1475, 99999)
*求区域中心
area_center (SelectedRegions, Area1, Row, Column)
*在区域中心生成小圆
tuple_gen_const (|Row|, 20.5, Radius)
gen_circle (Circle, Row, Column, Radius)
*对小圆排序
sort_region (Circle, SortedRegions, 'character', 'true', 'row')
*得到排序后的中心坐标
area_center (SortedRegions, Area, Row1, Column1)


*显示结果
dev_display (ImageReduced)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
count_obj (SortedRegions, Number)
for i:=1 to Number by 1    
    *根扰排序后坐标得到筛选区域索引
    get_region_index (SelectedRegions, Row1[i-1], Column1[i-1], Index)
    *根据索引选择区域,这个区域就是按顺序进行选中
    select_obj (SelectedRegions, ObjectSelected1, Index)
    *显示
    dev_display (ObjectSelected1)
    dev_disp_text (i, 'image', Row1[i-1]-10, Column1[i-1]-10, 'yellow', 'box', 'false')
endfor
threshold (Image, Regions, 118, 255)
closing_circle (Regions, RegionClosing, 55)
connection (RegionClosing, ConnectedRegions)
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
intersection (Regions, SelectedRegions, RegionIntersection)
closing_circle (RegionIntersection, RegionClosing1, 5)
connection (RegionClosing1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 880.22, 10000)
shape_trans (SelectedRegions1, RegionTrans, 'convex')
area_center (RegionTrans, Area, Row, Column)
tuple_round (Row/10, Round)
Round:=Round*10
Round:=Round-Round[0]
Round:=round(Round/70.0)
Round:=Round*70.0+Row[0]/10*10
gen_region_points (Region, Round, Column)
connection (Region, ConnectedRegions2)
sort_region (ConnectedRegions2, SortedRegions, 'upper_left', 'true', 'row')

 

 

你可能感兴趣的:(笔记,开发语言)