【发布时间】:2013-02-28 11:45:24
【问题描述】:
有没有办法在opencv中计算粗糙度轮廓?
图片样本:https://docs.google.com/file/d/0ByS6Z5WRz-h2NDgySmJ6NnpId0U/edit?usp=sharing
更新
我的粗糙度计算代码:
周长轮廓/凸包周长
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]
#ROUGHNESS
perimeter = cv2.arcLength(unicocnt,True)
hull = cv2.convexHull(unicocnt,returnPoints = False)
hullperimeter = cv2.arcLength(hull,True)
print("perimeter")
print(perimeter)
print("hullperimeter")
print(hullperimeter)
roughness = perimeter/hullperimeter
print("roughness")
print(roughness)
错误:
Traceback (most recent call last):
File "C:\Python27\nuovefeature.py", line 417, in <module>
hullperimeter = cv2.arcLength(hull,True)
error: ..\..\..\src\opencv\modules\imgproc\src\contours.cpp:1886: error: (-215) curve.checkVector(2) >= 0 && (curve.depth() == CV_32F || curve.depth() == CV_32S)
【问题讨论】:
-
请附上您尝试过的内容,以及到目前为止所做的研究。
-
或添加图像并解释您期望的输出?
-
我没有尝试anithink,教授问我有没有像matlab一样测量粗糙度轮廓的函数。
-
试试convexityDefects和isContourConvex。
-
我试过但后来我看到计算粗糙度是周长轮廓/周长凸包,但 hullperimeter = cv2.arcLength(hull,True) 我收到此错误:Traceback(最近一次通话最后):文件“C:\Python27\nuovefeature.py”,第 417 行,在
hullperimeter = cv2.arcLength(hull,True) 错误:..\..\..\src\opencv\modules\imgproc\src\contours .cpp:1886: 错误: (-215) curve.checkVector(2) >= 0 && (curve.depth() == CV_32F || curve.depth() == CV_32S)
标签: python opencv contour feature-extraction