index:.../Matching/Deformable/creat_local_deformable_model_xld.hdev
建立一个可变形的模板并进行匹配
这个例程中一个子函数对MVTec做处理,这里面很有意思,代码如下。
建立一个可变形的模板并进行匹配
这个例程中一个子函数对MVTec做处理,这里面很有意思,代码如下。
Blue := [0,48,117]
Orange := [255,181,41]
*
* Read the image containing the logo
read_image (Image, 'pen/pen-01')
get_image_size (Image, Width, Height)
*
* Segment the logo
auto_threshold (Image, Regions, 10)
connection (Regions, Regions)
select_shape (Regions, SelectedRegions, ['row1','holes_num'], 'and', [80,0], [100,0])
用row1左上角的点和holes_num连接部件和孔的数量,给零就是互不连接的部分来选择 ,大概没验证代码。
用row1左上角的点和holes_num连接部件和孔的数量,给零就是互不连接的部分来选择 ,大概没验证代码。
sort_region (SelectedRegions, SelectedRegions, 'character', 'true', 'row')
排序
排序
closing_rectangle1 (SelectedRegions, Characters, 3, 3)
opening_rectangle1 (Characters, Characters, 5, 5)
*
* Extract the contour
dilation_rectangle1 (Characters, RegionDilation, 5, 5)
erosion_rectangle1 (Characters, RegionErosion, 5, 5)
difference (RegionDilation, RegionErosion, RegionDifference)
膨胀收缩做差
膨胀收缩做差
count_obj (RegionDifference, Number)
gen_empty_obj (LogoContoursTemp)
for Index := 1 to Number by 1
select_obj (RegionDifference, ObjectSelected, Index)
reduce_domain (Image, ObjectSelected, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 1.5, 10, 20)
提取轮廓,提取出来结果是分离的edges
提取轮廓,提取出来结果是分离的edges
union_adjacent_contours_xld (Edges, UnionContours, 5, 1, 'attr_keep')
这里做了连接
这里做了连接
close_contours_xld (UnionContours, ClosedContours)
闭操作,这前后几句都是惯例
闭操作,这前后几句都是惯例
concat_obj (LogoContoursTemp, ClosedContours, LogoContoursTemp)
endfor
*
* Create the colored image of the logo
smallest_rectangle1_xld (LogoContoursTemp, Row1, Column1, Row2, Column2)
用上面结合出来的五个部件画了个包含他们的矩形
用上面结合出来的五个部件画了个包含他们的矩形
Row1 := min(Row1)
Column1 := min(Column1)
Row2 := max(Row2)
Column2 := max(Column2)
WidthLogoOrig := Column2 - Column1 + 1
ScaleFactor := real(WidthLogo) / WidthLogoOrig
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, -0.5 * (Row1 + Row2), -0.5 * (Column1 + Column2), HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, ScaleFactor, ScaleFactor, 0, 0, HomMat2DScale)
hom_mat2d_translate (HomMat2DScale, 0.5 * HeightImage, 0.5 * WidthImage, HomMat2DComplete)
affine_trans_contour_xld (LogoContoursTemp, LogoContours, HomMat2DComplete)
gen_image_const (ImageRed, 'byte', WidthImage, HeightImage)
gen_image_const (ImageGreen, 'byte', WidthImage, HeightImage)
gen_image_const (ImageBlue, 'byte', WidthImage, HeightImage)
compose3 (ImageRed, ImageGreen, ImageBlue, LogoImageTempl)
paint_xld (LogoContours, LogoImageTempl, LogoImage, [Blue,Orange,Blue,Blue,Blue,Blue])
*
* Dilate the original logo
if (Broadening > 0)
gray_dilation_shape (LogoImage, LogoImage, 2 * Broadening + 1, 2 * Broadening + 1, 'octagon')
elseif (Broadening < 0)
gray_erosion_shape (LogoImage, LogoImage, -2 * Broadening + 1, -2 * Broadening + 1, 'octagon')
endif
return ()
学习了这个例程,程序很复杂了,就是建立一个可以变形的模板来做后期查找,但模板不好做
总之每次得分都很高,我个人感觉因为是商量MVTec都是源于一张图片,实际的话不知效果如何。
学习了这个例程,程序很复杂了,就是建立一个可以变形的模板来做后期查找,但模板不好做
create_local_deformable_model_xld (LogoContours, 'auto', 0.0, 0.0, 'auto', 1, 1, 'auto', 1, 1, 'auto', 'auto', 'ignore_local_polarity', 5, [], [], ModelID)
find_local_deformable_model (GrayImage, ImageRectified, VectorField, DeformedContours, ModelID, 0, 0, 1, 1, 1, 1, 0.5, 1, 1, 4, 0.9, ['image_rectified','vector_field','deformed_contours'], ['deformation_smoothness','expand_border','subpixel'], [21,0,1], Score, Row, Column)
这两个函数是这个例程的核心,后面这个函数还做出来一个向量场 VectorField,grayimage是每次产生出来做对比的模板。
总之每次得分都很高,我个人感觉因为是商量MVTec都是源于一张图片,实际的话不知效果如何。