- *尝试一下,是要这个效果吗
- read_image (Image, 'D:/针曹.png')
- decompose4 (Image, ImageR, ImageG, ImageB, ImageA)
- *二值化
- gray_opening_shape (ImageG, ImageOpening, 5, 5, 'octagon')
- binary_threshold (ImageOpening, Region, 'max_separability', 'dark', UsedThreshold)
- fill_up(Region, RegionFillUp)
- closing_circle (RegionFillUp, RegionClosing, 3.5)
- *筛选针槽区域
- connection (RegionClosing, ConnectedRegions)
- select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 100, 600)
- *可根据中间长条进行水平纠偏
- select_shape_std (ConnectedRegions, MiddleBar, 'max_area', 70)
- *灰度投影用于位置区分
- gray_projections (ImageG, ImageG, 'simple', HorProjection, VertProjection)
- create_funct_1d_array (HorProjection, Function)
- funct_1d_to_pairs (Function, XValues, YValues)
- *间隔灰度在254左右, 找灰度值比230小的Y方向值
- Mask := YValues [<=] 230
- Selected := select_mask([0:|Mask|-1], Mask)
- RowValues := subset(XValues, Selected)
- ColValues := gen_tuple_const (|Selected|, 0)
- *根据点数组绘制投影结果区域
- gen_region_points (Projection, RowValues, ColValues)
- connection (Projection, ProjectionRegions)
- *上边一排针
- region_features (ProjectionRegions, 'row2', Value)
- select_shape (SelectedRegions, SelectedRegionsUP, 'row', 'and', 0, min(Value))
- *下边一排针
- region_features (ProjectionRegions, 'row1', Value)
- select_shape (SelectedRegions, SelectedRegionsDW, 'row', 'and', max(Value), 999999)
- dev_display (Image)
- dev_display (SelectedRegionsUP)
- dev_display (SelectedRegionsDW)
复制代码
|