目的:在多张图片中找到圆
效果:
代码
list_image_files ('D:/定位圆形', 'default', [], ImageFiles)
read_image (ImageModel, ImageFiles[0])
dev_set_draw ('margin')
gen_rectangle1 (ROI_0, 81,201, 633,817)
reduce_domain (ImageModel, ROI_0, ImageReduced)
dev_display (ImageReduced)
dev_set_line_width(3)
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 40, 70)
*创建模板
create_shape_model_xld (Edges, 'auto', rad(-180), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
*找模板图片的轮廓位置
* get_shape_model_contours (ModelContours, ModelID, 1)
* *查找
find_shape_model (ImageModel, ModelID, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, RowModel, ColumnModel, AngleModel, Score)
for Index := 0 to |ImageFiles|-1 by 1
read_image (Image, ImageFiles[Index])
find_shape_model (Image, ModelID, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, RowCur, ColumnCur, AngleCur, Score)
*得到现在图片与模板图 矩阵变化
vector_angle_to_rigid (RowModel, ColumnModel, AngleModel, RowCur, ColumnCur, AngleCur, HomMat2D)
* hom_mat2d_identity (HomMat2DIdentity)
* hom_mat2d_rotate (HomMat2DIdentity, AngleCur, 0, 0, HomMat2DRotate)
* hom_mat2d_translate (HomMat2DRotate, RowCur, ColumnCur, HomMat2DTranslate)
affine_trans_contour_xld (Edges, ContoursAffineTrans, HomMat2D)
create_metrology_model (MetrologyHandle)
disp_message(200001, ['x:'+RowCur,'y:'+ColumnCur], 'window', 30, 30, 'black', 'true')
stop()
endfor
发现模板匹配这类型的,基本操作都差不多喔。
第一步都是搞一个模板,然后去别的图片里面找。显示一下就OK啦~