圆形卡尺测量后创建模板
作者:互联网
read_image (Image, 'QQ图片20201113111404.jpg')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
rgb1_to_gray (Image,Image)
****创建模板阶段
*大致找内圆
fast_threshold (Image, Region, 128, 255, 20)
connection (Region, ConnectedRegions)
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
fill_up_shape (SelectedRegions, RegionFillUp, 'area', 100000, 1000000000)
difference (RegionFillUp, SelectedRegions, RegionDifference)
smallest_circle (RegionDifference, Row, Column, Radius)
*对内圆进行精确测量
create_metrology_model (MetrologyHandle)
add_metrology_object_circle_measure (MetrologyHandle, Row, Column, Radius, Radius/10, Radius/60, 1, 60, ['measure_distance','min_score'], [Radius/30,0.2], Index1)
apply_metrology_model (Image, MetrologyHandle)
gen_empty_obj (Contours)
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row1, Column1)
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5)
*创建模板
create_shape_model_xld (Contour, 'auto', 0, 0, 'auto', 'auto', 'ignore_local_polarity', 60, ModelID)
*清除精确测量句柄
clear_metrology_model (MetrologyHandle)
*显示创建内容
dev_display (Image)
dev_display (Contour)
*********进行查找
*查找模板
count_seconds (Seconds1)
find_shape_model (Image, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares', 5, 0.9, Row2, Column2, Angle, Score)
count_seconds (Seconds2)
get_shape_model_contours (ShapeModel, ModelID, 1)
vector_angle_to_rigid (0, 0, 0, Row2, Column2, Angle, MovementOfObject)
affine_trans_contour_xld (ShapeModel, ModelAtNewPosition, MovementOfObject)
*显示结果
dev_display (Image)
dev_display (ModelAtNewPosition)
disp_message (WindowHandle, '查找耗时'+(Seconds2-Seconds1)*1000+'ms', 'window', 50, 50, 'black', 'true')
标签:MetrologyHandle,metrology,Image,shape,dev,圆形,model,卡尺,模板 来源: https://blog.csdn.net/cashmood/article/details/111637358