You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenCV处理气泡阴影图:紧邻气泡被识别为单轮廓的解决方案求助

气泡阴影图的OpenCV轮廓提取问题

我用OpenCV做气泡阴影图的边缘检测和轮廓提取,整体效果还行,但遇到两个紧邻的气泡时,系统会把它们识别成一个轮廓,可实际是两个独立的气泡。

用圆形度条件过滤后,右侧的气泡簇圆形度更高,但我想要的是把中间那两个紧邻气泡识别成独立个体,同时忽略右侧的气泡簇。

以下是我目前的代码:

import cv2 as cv
import numpy as np

img = cv.imread(path)
gi = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
edges = cv.Canny(gi, 30, 200)
contours, hierarchy = cv.findContours(edges, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)
            
circular_contours = []

for a in range(len(contours)):
    peri = cv.arcLength(contours[a], True)
    area = cv.contourArea(contours[a])
    if peri == 0:
        continue
    circularity = 4 * np.pi * (area / peri**2)
    print('Circularity: ' + str(circularity))
    if 0.69 < circularity < 1.15:
        circular_contours.append(contours[a])
        
cv.drawContours(img, circular_contours, -1, (0,255,0), 1)

相关图像:

  • 轮廓化阴影图:显示初始轮廓提取结果的图像
  • 应用圆形度条件后的轮廓化阴影图:经过圆形度过滤后的轮廓展示图像
  • 源图像:原始气泡阴影图

内容的提问来源于stack exchange,提问作者Alfred Bednall

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 17:47:44