跟踪图像中的白色区域

时间:2020-04-29 23:36:48

标签: python-3.x opencv

我有一个带有黑色边框勾勒出的白色圆圈的图像。我想使用某种形式的软件来测量白色圆圈的大小。我一直在尝试,但是没有运气。这是我当前的代码,没有添加尝试的批注:

import cv2
from scipy import ndimage
import os
import matplotlib.pyplot as plt

def load_images_from_folder(folder):
    images = []
    for filename in os.listdir(folder):
        img = cv2.imread(os.path.join(folder,filename),0)
        if img is not None:
            images.append(img)
    return images

rawframes=load_images_from_folder('BubbleSize/90FoamQuality/DryFoams')

blur = cv2.bilateralFilter(rawframes[0],1,200,200)
blur = cv2.Canny(blur,60,60)

blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_dilation(blur)
blur = ndimage.binary_erosion(blur)
blur = ndimage.binary_erosion(blur)
blur = ndimage.binary_erosion(blur)
blur = ndimage.binary_erosion(blur)

plt.imshow(final,'binary')

之前:

Before


之后:

After

1 个答案:

答案 0 :(得分:0)

使用connectedComponentsWithStats函数,此函数返回连接的组件和该区域。