栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

cv2.matchShape()

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cv2.matchShape()

        函数cv2.matchShape()可以比较两个形状或轮廓的相似度。如果返回值越小,匹配越好。它是根据Hu矩来计算的,Hu矩是归一化中心矩的线性组合,之所以这么做是为了能够获取代表图像的某个特征的矩函数,这些矩函数对某些变换如缩放,旋转,镜像映射(除了h1)具有不变性。

double cv::matchShapes	(	InputArray 	contour1,
InputArray 	contour2,
int 	method,
double 	parameter 
)		
Python:
cv.matchShapes(	contour1, contour2, method, parameter	) ->	retval

 比较一下上面这三张图:

In [4]: img1 = cv2.imread(r'E:comprehensive_libraryIntelligent_material_onlinelibretrievaldatabaseornament_1.png
   ...: ',0)

In [9]: img2 = cv2.imread(r'E:comprehensive_libraryIntelligent_material_onlinelibretrievaldatabasejd2.jpg',0)

In [10]: img3 = cv2.imread(r'E:comprehensive_libraryIntelligent_material_onlinelibretrievaldatabasemizhi1.png',0
    ...: )

In [17]: ret,thresh1=cv2.threshold(img1,240,255,0)

In [18]: cv2.namedWindow('thresh1')
    ...: cv2.imshow('thresh1',thresh1)
    ...: cv2.waitKey(0)
    ...: cv2.destroyWindow('thresh1')
    ...:

In [19]: ret,thresh2=cv2.threshold(img2,240,255,0)

In [20]: cv2.namedWindow('thresh2')
    ...: cv2.imshow('thresh2',thresh2)
    ...: cv2.waitKey(0)
    ...: cv2.destroyWindow('thresh2')
    ...:

In [21]: ret,thresh3=cv2.threshold(img3,240,255,0)

In [22]: cv2.namedWindow('thresh3')
    ...: cv2.imshow('thresh3',thresh1)
    ...: cv2.waitKey(0)
    ...: cv2.destroyWindow('thresh3')
    ...:

In [24]: contours,hierarchy = cv2.findContours(thresh1,2,1)

In [25]: cnt1 = contours[0]

In [26]: cnt1
Out[26]: array([[[ 64, 137]]], dtype=int32)

In [27]: contours1,hierarchy = cv2.findContours(thresh2,2,1)

In [28]: contours3,hierarchy = cv2.findContours(thresh3,2,1)

In [29]: cnt2=contours1[0]

In [30]: cnt2
Out[30]: array([[[291, 303]]], dtype=int32)

In [31]: cnt3=contours3[0]

In [33]: ret = cv2.matchShapes(cnt1,cnt2,1,0.0)

In [34]: ret
Out[34]: 0.0

In [35]: ret = cv2.matchShapes(cnt1,cnt3,1,0.0)

In [36]: ret
Out[36]: 1.7976931348623157e+308

In [37]: ret = cv2.matchShapes(cnt1,cnt1,1,0.0)

In [38]: ret
Out[38]: 0.0

In [39]: ret = cv2.matchShapes(cnt3,cnt3,1,0.0)

In [40]: ret
Out[40]: 0.0

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/849463.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号