执行opencv时刻函数

时间:2017-03-07 10:07:15

标签: python opencv

我正在开发一个python应用程序,它可以查找特定图像中的轮廓和时刻。该片段如下。

self.blob = cv2.imread('output-17-03-07-13-28.bmp')
gray = cv2.cvtColor(self.blob,cv2.COLOR_BGR2GRAY) 
contours, hierarchy = cv2.findContours(gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
count = str(len(contours))

以下块计算完美的轮廓

self.areaArray = []
for i, c in enumerate(contours):
    r = (randint(0,255))
    g = (randint(0,255))
    b = (randint(0,255))
    area = cv2.contourArea(c)
    self.areaArray.append(area)
    #print i,self.areaArray[i]
    cnt = contours[i]
    cv2.drawContours(self.blob, [cnt], 0, (b, g, r), -1)

以下块计算时刻

moments = [cv2.moments(cnt) for cnt in contours]
centroids = [(int(M['m10'] / M['m00']), int(M['m01'] / M['m00'])) for M in moments]
for c in centroids:
    cv2.circle(self.blob, c, 5, (0, 0, 0))
    cv2.imshow('img', self.blob)

一旦我运行脚本,我就会收到错误

ZeroDivisionError: float division by zero

0 个答案:

没有答案