简介:
通过Halcon对目标区域特征检测。常用检测面积、长宽等。
介绍:
Regions (input_object) | Regions to be examined. | 区域 |
Features (input_control) | Shape features to be calculated. Default value: 'area' List of values: 'anisometry', 'area', 'area_holes', 'bulkiness', 'circularity', 'column', 'column1', 'column2', 'compactness', 'connect_num', 'contlength', 'convexity', 'dist_deviation', 'dist_mean', 'euler_number', 'height', 'holes_num', 'inner_height', 'inner_radius', 'inner_width', 'max_diameter', 'moments_i1', 'moments_i2', 'moments_i3', 'moments_i4', 'moments_ia', 'moments_ib', 'moments_m02', 'moments_m02_invar', 'moments_m03', 'moments_m03_invar', 'moments_m11', 'moments_m11_invar', 'moments_m12', 'moments_m12_invar', 'moments_m20', 'moments_m20_invar', 'moments_m21', 'moments_m21_invar', 'moments_m30', 'moments_m30_invar', 'moments_phi1', 'moments_phi2', 'moments_psi1', 'moments_psi2', 'moments_psi3', 'moments_psi4', 'num_sides', 'orientation', 'outer_radius', 'phi', 'ra', 'rb', 'rect2_len1', 'rect2_len2', 'rect2_phi', 'rectangularity', 'roundness', 'row', 'row1', 'row2', 'struct_factor', 'width' | 特征选择 |
Value (output_control) | The calculated features. | 输出的特征值 |
area | Area of the object | 对象的面积 | |
row | Row index of the center | 中心点的行坐标 | |
column | Column index of the center | 中心点的列坐标 | |
width | Width of the region | 区域的宽度 | |
height | Height of the region | 区域的高度 | |
row1 | Row index of upper left corner | 左上角行坐标 | |
column1 | Column index of upper left corner | 左上角列坐标 | |
row2 | Row index of lower right corner | 右下角行坐标 | |
column2 | Column index of lower right corner | 右下角列坐标 | |
circularity | Circularity | 圆度 | 0~1(circularity) |
compactness | Compactness | 紧密度 | 0~1(compactness) |
contlength | Total length of contour | 轮廓线总长 | (contlength) |
convexity | Convexity | 凸性 | (convexity) |
rectangularity | Rectangularity | 矩形度 | 0~1(rectangularity) |
ra | Main radius of the equivalent ellipse | 等效椭圆长轴半径长度 | (elliptic_axis) |
rb | Secondary radius of the equivalent ellipse | 等效椭圆短轴半径长度 | (elliptic_axis) |
phi | Orientation of the equivalent ellipse | 等效椭圆方向 | (elliptic_axis) |
anisometry | Anisometry | 椭圆参数,Ra/Rb长轴与短轴的比值 | (eccentricity) |
bulkiness | Bulkiness | 椭圆参数,蓬松度π*Ra*Rb/A | (eccentricity) |
struct_factor | Structur Factor | 椭圆参数,Anisometry*Bulkiness-1 | (eccentricity) |
outer_radius | Radius of smallest surrounding circle | 最小外接圆半径 | (smallest_circle) |
inner_radius | Radius of largest inner circle | 最大内接圆半径 | (inner_circle) |
inner_width | Width of the largest axis-parallel rectangle that fits into the region | 最大内接矩形宽度 | (inner_rectangle1) |
inner_height | Height of the largest axis-parallel rectangle that fits into the region | 最大内接矩形高度 | ( inner_rectangle1) |
dist_mean | Mean distance from the region border to the center | 区域边界到中心的平均距离 | (roundness) |
dist_deviation | Deviation of the distance from the region border from the center | 区域边界到中心距离的偏差 | (roundness) |
roundness | Roundness | 圆度,与circularity计算方法不同 | (roundness) |
num_sides | Number of polygon sides | 多边形边数 | (roundness) |
connect_num | Number of connection components | 连通数 | (connect_and_holes) |
holes_num | Number of holes | 区域内洞数 | (connect_and_holes) |
area_holes | Area of the holes of the object | 所有洞的面积 | (area_holes) |
max_diameter | Maximum diameter of the region | 最大直径 | (diameter_region) |
orientation | Orientation of the region | 区域方向 | (orientation_region) |
euler_number | Euler number | 欧拉数,即连通数和洞数的差 | (euler_number) |
rect2_phi | Orientation of the smallest surrounding rectangle | 最小外接矩形的方向 | (smallest_rectangle2) |
rect2_len1 | Half the length of the smallest surrounding rectangle | 最小外接矩形长度的一半 | (smallest_rectangle2) |
rect2_len2 | Half the width of the smallest surrounding rectangle | 最小外接矩形宽度的一半 | (smallest_rectangle2) |
moments_m11 | Geometric moments of the region | 几何矩 | |
moments_m20 | Geometric moments of the region | 几何矩 | |
moments_m02 | Geometric moments of the region | 几何矩 | |
moments_ia | Geometric moments of the region | 几何矩 | |
moments_ib | Geometric moments of the region | 几何矩 | |
moments_m11_invar | Geometric moments of the region | 几何矩 | |
moments_m20_invar | Geometric moments of the region | 几何矩 | |
moments_m02_invar | Geometric moments of the region | 几何矩 | |
moments_phi1 | Geometric moments of the region | 几何矩 | |
moments_phi2 | Geometric moments of the region | 几何矩 | |
moments_m21 | Geometric moments of the region | 几何矩 | |
moments_m12 | Geometric moments of the region | 几何矩 | |
moments_m03 | Geometric moments of the region | 几何矩 | |
moments_m30 | Geometric moments of the region | 几何矩 | |
moments_m21_invar | Geometric moments of the region | 几何矩 | |
moments_m12_invar | Geometric moments of the region | 几何矩 | |
moments_m03_invar | Geometric moments of the region | 几何矩 | |
moments_m30_invar | Geometric moments of the region | 几何矩 | |
moments_i1 | Geometric moments of the region | 几何矩 | |
moments_i2 | Geometric moments of the region | 几何矩 | |
moments_i3 | Geometric moments of the region | 几何矩 | |
moments_i4 | Geometric moments of the region | 几何矩 | |
moments_psi1 | Geometric moments of the region | 几何矩 | |
moments_psi2 | Geometric moments of the region | 几何矩 | |
moments_psi3 | Geometric moments of the region | 几何矩 | |
moments_psi4 | Geometric moments of the region | 几何矩 |
使用:
- 彩色图像要转成灰色图像。
- 腐蚀和膨胀,去除影响的区域。
- 特征检测,根据特征参数选择所需要的。
read_image (Image, 'E:/照片/RGB.jpg')
decompose3 (Image, Image1, Image2, Image3)
trans_from_rgb (Image1, Image2, Image3, ImageResult1, ImageResult2, ImageResult3, 'hsv')
threshold (ImageResult3, Region, 180, 255)
*腐蚀
erosion_rectangle1 (Region, RegionErosion, 2, 2)
*膨胀
dilation_rectangle1 (RegionErosion, RegionDilation, 2, 2)
connection (RegionDilation, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
*特征
region_features (SelectedRegions, ['area','row1','column1', 'width', 'height'], Value)
for i := 0 to (|Value|/5) - 1 by 1
area := Value[i*5]
row1 := Value[i*5 + 1]
column1 := Value[i*5 + 2]
width := Value[i*5 + 3]
height := Value[i*5 + 4]
*height
disp_arrow (3600, row1, column1, row1 + height, column1, 1)
disp_message (3600, height, 'image', row1 + height/3, column1 - 10, 'cyan', 'false')
*width
disp_arrow (3600, row1, column1, row1, column1 + width, 1)
disp_message (3600, height, 'image', row1 - 10 , column1 + width/3, 'cyan', 'false')
*area
disp_message (3600, area, 'image', row1 + height/3 , column1 + width/3, 'black', 'true')
endfor
