探究算子find_shape_model中参数MaxOverlap的准确意思

基于形状的模板查找算子:

find_shape_model(Image : : ModelID, AngleStart, AngleExtent, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels, Greediness : Row, Column, Angle, Score)

 

MaxOverlap:意思是允许的最大重叠区域。

 

那么我们想问,这个重叠区域指的是哪个区域呢?

如果下图是创建形状模型的图像:

那么对于下图来说,其中的2个形状有重叠吗?

 

按照一般的理解,很显然没有重叠,只是一个刚好插到另一个的缝隙中去了,但是两个形状貌似并没有实质上的重叠。

 

后来看了一些资料,说这里的重叠指的是每个形状的最小外接矩形重叠的部分。即下图中红色的色块:

事实是否如此,我来验证一下:

复制代码

 1 *建立模型 01.png是本文第1张图,02.png是本文第2张图
 2 read_image (Image_mode, 'C:/Users/happy xia/Desktop/01.png')
 3 create_shape_model (Image_mode, 'auto', -3.0, 6.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID2)
 4 
 5 *验证
 6 read_image (Image, 'C:/Users/happy xia/Desktop/02.png')
 7 dev_set_draw ('margin')
 8 binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
 9 connection (Region, ConnectedRegions)
10 smallest_rectangle2 (ConnectedRegions, Row, Column, Phi, Length1, Length2)
11 gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
12 select_obj (Rectangle, ObjectSelected, 1)
13 select_obj (Rectangle, ObjectSelected1, 2)
14 area_center (ObjectSelected1, Area1, Row11, Column11)
15 
16 intersection (ObjectSelected, ObjectSelected1, RegionIntersection)
17 area_center (RegionIntersection, Area, Row1, Column1)
18 
19 *(Area1 + 0.1)是想让商为小数,不然的话ratio会等于0
20 ratio := Area/(Area1 + 0.1)
21 disp_message (3600, ratio, 'image', 160, 205, 'red', 'true')
22 
23 dev_display (Image)
24 
25 *注意:第6个参数NumMatchs = 0,意思是不限制匹配的个数,可以匹配出多个
26 find_shape_model (Image, ModelID2,-3.0, 6.79 ,0.5, 0, ratio + 0.01 , 'least_squares', 0, 0.9, Row2, Column2, Angle2, Score2)
27 
28 * get_shape_model_contours (ModelContours, ModelID2, 1)
29 * vector_angle_to_rigid (0, 0, 0, Row2[0], Column2[0], Angle2[0], HomMat2D0)
30 * affine_trans_contour_xld (ModelContours, ContoursAffinTrans0, HomMat2D0)
31 
32 * vector_angle_to_rigid (0, 0, 0, Row2[1], Column2[1], Angle2[1], HomMat2D1)
33 * affine_trans_contour_xld (ModelContours, ContoursAffinTrans1, HomMat2D1)

复制代码

这里,重叠部分和单个形状最小外接矩形的面积比值为0.426317。

当find_shape_model中参数MaxOverlap取值为ratio + 0.01(或者ratio)时,Score2 = [0.999136, 0.998544]

当find_shape_model中参数MaxOverlap取值为ratio - 0.01时,Score2 = 0.999136,即只找到了一个。

 

由此可以说明:ratio(值为0.426317)确实是本例中的允许的最大重叠比例的分界值,进而可以确定find_shape_model中的MaxOverlap指的是每个形状的最小外接矩形重叠的部分所占单个最小矩形的比例

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The `find_shape_model` function in OpenCV is used for finding a shape model from a set of training images. It is part of the Shape Matching module in OpenCV, which provides tools for matching shapes based on their contour and other features. The `find_shape_model` function takes as input a set of training images, which are typically binary images with the object of interest represented as a white shape on a black background. The function then computes a shape model based on the contours of the objects in the training images. The shape model can be used for shape matching, which involves finding the best match between a given image and the shape model. This can be useful for object recognition and tracking. To use the `find_shape_model` function, you first need to create a ShapeContextDistanceExtractor object, which defines the distance metric used for shape matching. You then call the `find_shape_model` function, passing in the training images and the ShapeContextDistanceExtractor object. Here's an example of how to use the `find_shape_model` function: ``` import cv2 # Load training images img1 = cv2.imread("train1.png", cv2.IMREAD_GRAYSCALE) img2 = cv2.imread("train2.png", cv2.IMREAD_GRAYSCALE) img3 = cv2.imread("train3.png", cv2.IMREAD_GRAYSCALE) # Create ShapeContextDistanceExtractor object sc_extractor = cv2.createShapeContextDistanceExtractor() # Find shape model from training images shape_model = cv2.findShapeModel([img1, img2, img3], sc_extractor) ``` In this example, we load three training images and create a ShapeContextDistanceExtractor object. We then call the `findShapeModel` function, passing in the three training images and the ShapeContextDistanceExtractor object. The function returns a shape model, which can be used for shape matching.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值