【发布时间】:2019-03-01 03:58:49
【问题描述】:
【问题讨论】:
标签: algorithm opencv computer-vision heatmap counting
【问题讨论】:
标签: algorithm opencv computer-vision heatmap counting
来源 => 检测
我的方法是:Gray => Threshold => FindContours(必要时按区域过滤)
#!/usr/bin/python3
# 2019/03/01
import cv2
img = cv2.imread("featmap.png")
# Gray => Threshold => FindContours (filter by area if necessary)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blured = cv2.medianBlur(gray, 3)
th, threshed = cv2.threshold(blured, 100, 255, cv2.THRESH_OTSU|cv2.THRESH_BINARY)
cnts = cv2.findContours(threshed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2]
print("nums: {}".format(len(cnts)))
# draw on the original
cv2.drawContours(img, cnts, -1, (0, 255, 0), 1, cv2.LINE_AA)
cv2.imwrite("dst.png", img)
谨慎使用findContours:How to use `cv2.findContours` in different OpenCV versions?
【讨论】:
您可以应用cvThreshold操作来制作黑白图像。
然后用opening morhological operation过滤小缺陷
现在找到connected components 并获取它们的数量。
【讨论】: