Halcon中的2D Metrology模块提供了亚像素级别的卡尺测量功能。主要针对圆/圆弧、椭圆/椭圆弧、直线、rectangle2矩形创建测量对象。
一般首次使用2D Metrology测量工具有如下步骤:
如图,计算图中元件的中心与缺口角度问题:
read_image (Image, 'uranium_targeting_256.bmp')
try
get_image_size (Image, Width, Height)
auto_threshold (Image, Regions, 5)
fill_up (Regions, RegionFillUp)
select_shape_std (RegionFillUp, SelectedRegions1, 'max_area', 70)
reduce_domain (Image, SelectedRegions1, ImageReduced1)
threshold (ImageReduced1, Region2, 0, 150)
connection (Region2, ConnectedRegions5)
fill_up (ConnectedRegions5, RegionFillUp2)
select_shape_std (RegionFillUp2, SelectedRegions4, 'max_area', 70)
opening_circle (SelectedRegions4, RegionOpening, 10)
gen_contour_region_xld (RegionOpening, Contours, 'border')
fit_circle_contour_xld (Contours, 'atukey', -1, 0, 0, 3, 2, CircleCenterRow, CircleCenterColumn, CircleCenterRadius, StartPhi1, EndPhi1, PointOrder1)
gen_circle_contour_xld (ContCircle1, CircleCenterRow, CircleCenterColumn, CircleCenterRadius, 0, 6.28318, 'positive', 1)
gen_region_contour_xld (Contours, Region3, 'margin')
gen_region_contour_xld (ContCircle1, Region, 'margin')
shape_trans (RegionOpening, RegionTrans, 'rectangle2')
erosion_circle (RegionTrans, RegionErosion, 30)
difference (Region3, RegionErosion, RegionDifference)
connection (RegionDifference, ConnectedRegions4)
select_shape_std (ConnectedRegions4, SelectedRegions3, 'max_area', 70)
dilation_circle (SelectedRegions3, RegionDilation, 5)
skeleton (RegionDilation, Skeleton1)
gen_contours_skeleton_xld (Skeleton1, Contours2, 10, 'filter')
fit_line_contour_xld (Contours2, 'tukey', -1, 0, 5, 2.0, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_region_line (RegionLines, RowBegin, ColBegin, RowEnd, ColEnd)
intersection (RegionLines, Region, RegionIntersection2)
connection (RegionIntersection2, ConnectedRegions1)
* 直线检测的起始点与终止点
area_center (ConnectedRegions1, Area4, LineRegionRow, LineRegionColumn)
**卡尺精定位部分
create_metrology_model (MetrologyHandle)
set_metrology_model_image_size (MetrologyHandle, Width, Height)
add_metrology_object_circle_measure (MetrologyHandle, CircleCenterRow, CircleCenterColumn, CircleCenterRadius, 10, 5, 1.5, 20, ['measure_transition','min_score'], ['positive',0.5], MetrologyCircleIndex)
apply_metrology_model (Image, MetrologyHandle)
get_metrology_object_result (MetrologyHandle, MetrologyCircleIndex, 'all', 'result_type', 'all_param', CircleParameter)
add_metrology_object_line_measure (MetrologyHandle, LineRegionRow[0], LineRegionColumn[0], LineRegionRow[1], LineRegionColumn[1], 10, 5, 1, 20, ['measure_transition','min_score'], ['uniform',0.5], MetrologyLineIndex)
apply_metrology_model (Image, MetrologyHandle)
get_metrology_object_result (MetrologyHandle, MetrologyLineIndex, 'all', 'result_type', 'all_param', LineParameter)
** 显示信息
get_metrology_object_result_contour (MetrologyCircleContour, MetrologyHandle, MetrologyCircleIndex, 'all', 1.5)
get_metrology_object_result_contour (MetrologyLineContour, MetrologyHandle, MetrologyLineIndex, 'all', 1.5)
gen_region_line (RegionLinesH, LineParameter[0], LineParameter[1], LineParameter[2], LineParameter[3])
* *** Output ****
if (LineParameter[1]CircleParameter[0])
ReturnDeg := Deg - 180
elseif(RowCircleParameter[1])
ReturnDeg := 0
elseif (Row==CircleParameter[0] and Column
输出结果: