read_image (Image, '不规则区域抠取.png')
get_image_size (Image, Width, Height)
********************************************************************************
dual_threshold (Image, Region, 500, 128, 100)
union1 (Region, RegionUnion)
opening_rectangle1 (RegionUnion, RegionOpening, 7, 1)
closing_rectangle1 (RegionOpening, RegionClosing, 200, 1)
opening_rectangle1 (RegionClosing, RegionOpening, 200, 3)
opening_circle (RegionOpening, RegionOpening1, 11)
connection (RegionOpening1, ConnectedRegions)
select_shape_std (ConnectedRegions, LightRegion, 'max_area', 70)
smallest_rectangle2 (LightRegion, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle1, Row, Column, Phi, Length1 + Width, Length2)
reduce_domain (Image, Rectangle1, ImageReduced)
*分割出手指区域
binary_threshold (ImageReduced, Region, 'max_separability', 'light', UsedThreshold)
opening_circle (Region, RegionOpening, 3.5)
fill_up (RegionOpening, RegionFillUp)
connection (RegionFillUp, ConnectedRegions)
region_features (ConnectedRegions, 'width', Value)
tuple_median (Value, FinWidth)
********************************************************************************
*水平区域
select_shape (ConnectedRegions, HorRegions, 'ratio', 'and', 0, 1)
*竖直区域
select_shape (ConnectedRegions, SelectedRegions, 'ratio', 'and', 1, 99999)
find_neighbors (HorRegions, SelectedRegions, FinWidth, RegionIndex1, RegionIndex2)
select_obj (SelectedRegions, VerRegions, RegionIndex1)
*创建水平区域和竖直区域
smallest_rectangle1 (HorRegions, Row1H, Column1H, Row2H, Column2H)
smallest_rectangle1 (VerRegions, Row1V, Column1V, Row2V, Column2V)
gen_rectangle1 (RectangleH, Row1H, Column1H, Row2H, Column2V)
gen_rectangle1 (RectangleV, Row1V, Column1V, Row2V, Column2V)
*合并生成标志手指区域
union2 (RectangleH, RectangleV, MarkRegion)
*把垂直区域转换为矩形
shape_trans (SelectedRegions, RegionTrans, 'rectangle1')
union2 (MarkRegion, RegionTrans, RegionUnion)
connection (RegionUnion, ConnectedRegions)
sort_region (ConnectedRegions, SortedRegions, 'first_point', 'true', 'column')
********************************************************************************
*使用第一根普通手指作为模板与ROI区域
select_obj (SortedRegions, ModelObject, 2)
reduce_domain (Image, ModelObject, ImageReduced1)
area_center (ModelObject, Area, Row1, Column1)
create_shape_model (ImageReduced1, 'auto', rad(-10), rad(20), 'auto', 'auto', 'use_polarity', 50, 30, ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
vector_angle_to_rigid (0, 0, 0, Row1, Column1, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)
smallest_rectangle1 (ModelObject, Row11, Column11, Row21, Column21)
gen_rectangle1 (ROI, Row11-10, Column11-10, Row21+10, Column21+10)
********************************************************************************
*读取测试图像
read_image (Image1, '不规则区域抠取1.png')
*截取ROI进行匹配
reduce_domain (Image1, ROI, ImageReduced2)
find_shape_model (ImageReduced2, ModelID, rad(-10), rad(20), 0.75, 1, 0.5, 'least_squares', 0, 0.9, Row2, Column2, Angle2, Score)
*根据匹配结果计算跟随区域
gen_empty_obj (FllowRegions)
if (|Score| > 0)
*跟随区域仿射变换矩阵的计算
vector_angle_to_rigid (Row1, Column1, 0, Row2, Column2, -Angle2, HomMat2D1)
count_obj (SortedRegions, Number)
for Idx := 1 to Number by 1
select_obj (SortedRegions, ObjectSelected, Idx)
affine_trans_region (ObjectSelected, RegionAffineTrans, HomMat2D1, 'nearest_neighbor')
concat_obj (FllowRegions, RegionAffineTrans, FllowRegions)
endfor
endif
dev_display (Image1)
dev_display (FllowRegions) |