【问题标题】:How could I count the number of the light small clusters in a feature map我如何计算特征图中轻小簇的数量
【发布时间】:2019-03-01 03:58:49
【问题描述】:

假设我有这样的热图:

热图上的像素值范围为 0-1。值越接近 0,像素越暗。上面有六个写簇,如图。有什么方法可以让我知道热图中有多少个光团?

【问题讨论】:

    标签: algorithm opencv computer-vision heatmap counting


    【解决方案1】:

    来源 => 检测


    我的方法是: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?

    【讨论】:

      【解决方案2】:

      您可以应用cvThreshold操作来制作黑白图像。

      然后用opening morhological operation过滤小缺陷

      现在找到connected components 并获取它们的数量。

      【讨论】:

        猜你喜欢
        • 2020-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多