我怎么知道在opencv中轮廓是打开还是关闭? [英] How can i know if a contour is open or closed in opencv?
本文介绍了我怎么知道在opencv中轮廓是打开还是关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么知道在opencv中从查找轮廓功能获取的轮廓是打开还是关闭?
How can i know if a contour taken from 'find contour' function is open or closed in opencv?
更新
我尝试将isContourConvex应用于此图像: https://docs.google.com/file/d/0ByS6Z5WRz-h2RXdzVGtXUTlPSGc/edit?usp=sharing
I tried to apply isContourConvex to this image: https://docs.google.com/file/d/0ByS6Z5WRz-h2RXdzVGtXUTlPSGc/edit?usp=sharing
i提取轮廓具有最大面积
并返回false。
我可以更改轮廓提取,扩展吗?
i extractes contour with greatest area and return false. I change, maybe, contour extraction, dilating?
nomeimg = 'Riscalate2/JPEG/e (5).jpg'
img = cv2.imread(nomeimg)
gray = cv2.imread(nomeimg,0)#convert grayscale adn binarize
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(6,6))
graydilate = cv2.erode(gray, element) #imgbnbin
cv2.imshow('image',graydilate)
cv2.waitKey(0)
ret,thresh = cv2.threshold(graydilate,127,255,cv2.THRESH_BINARY_INV) # binarize
imgbnbin = thresh
cv2.imshow('bn',thresh)
cv2.waitKey()
#element = cv2.getStructuringElement(cv2.MORPH_CROSS,(2,2))
#element = np.ones((11,11),'uint8')
contours, hierarchy = cv2.findContours(imgbnbin, cv2.RETR_TREE ,cv2.CHAIN_APPROX_SIMPLE)
print(len(contours))
# Take only biggest contour basing on area
Areacontours = list()
calcarea = 0.0
unicocnt = 0.0
for i in range (0, len(contours)):
area = cv2.contourArea(contours[i])
#print("area")
#print(area)
if (area > 90 ): #con 90 trova i segni e togli puntini
if (calcarea<area):
calcarea = area
unicocnt = contours[i]
convex = cv2.isContourConvex(unicocnt)
print("convex")
print(convex)
推荐答案
You're looking for the terms concave (like a C) vs convex (like an O) contours.
猜猜是什么,有一种方法可以检查凸度:
And guess what, there is a method to check for convexity:
这篇关于我怎么知道在opencv中轮廓是打开还是关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文