我有一个有很多类似模式的图像,我想创建模板使用图像中的模式并使用模板匹配其他模式。我已经完成使用Halcon并且我想使用OpenCV来实现。图像如下。 Halcon成就:
Halcon Src
*shape model
read_image (Image, 'C:/Users/Jason/Documents/ShareWM/image/21.jpg')
rgb1_to_gray (Image, GrayImage1)
gen_rectangle1 (Rectangle, 1428.04, 3185.44, 1811.68, 3967.26)
reduce_domain (Image, Rectangle, ImageReduced)
rgb1_to_gray (ImageReduced, GrayImage)
derivate_gauss (GrayImage, DerivGauss, 2, 'eigenvalue1')
threshold (DerivGauss, Regions, -1.556, 0.266)
connection (Regions, Connection)
select_shape (Connection, SelectedRegions, ['area','circularity'], 'and', [13000,0.3], [9999900,0.4])
union1 (SelectedRegions, RegionUnion)
fill_up (RegionUnion, RegionFillUp)
closing_circle (RegionFillUp, RegionClosing, 5.5)
fill_up (RegionClosing, RegionFillUp1)
boundary (RegionFillUp1, RegionBorder, 'inner')
gen_contour_region_xld (RegionBorder, Contours, 'border')
gen_polygons_xld (Contours, Polygons, 'ramer', 2)
*shape match
create_shape_model_xld (Contours, 2, 0, rad(200), rad(2), 'point_reduction_low', 'ignore_local_polarity', 5, ModelID)
find_shape_model (GrayImage1, ModelID, 0, rad(200), 0.4, 0, 0.5, 'least_squares', 2, 0.9, Row1, Column1, Angle1, Score1)
Num := |Row1|
for Index := 0 to Num-1 by 1
get_shape_model_contours (ModelContours, ModelID, 1)
vector_angle_to_rigid (0, 0, 0, Row1[Index], Column1[Index], Angle1[Index], HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)
endfor
clear_shape_model (ModelID)
结束src
感谢您的时间!