如何在不影响图像其余部分的情况下删除图像中的外圆?

问题描述 投票:0回答:1

我的图像类似于下面显示的图像。enter image description here

我想删除图像的黑色和红色圆圈而不影响图像内部的红色方块(因为红色圆圈和红色方块的像素值相同)

我已经尝试使用cv2.HoughCircles来检测红色圆圈,并尝试将其转换为黑色,但是红色圆圈的某些部分保持不变,如图所示。enter image description here

这是我用于此的代码。

import numpy as np
import cv2


image = cv2.imread("13-14.png")
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.3, 145)


if circles is not None:
    circles = np.round(circles[0, :]).astype("int")

    for (x, y, r) in circles:
        cv2.circle(output, (x, y), r, (0, 0 , 0), 4)


cv2.imshow("output", np.hstack([image, output]))
cv2.waitKey(0)

有什么建议吗?预先感谢。

python python-3.x image-processing cv2
1个回答
0
投票

从左上角开始填充,先填充黑色,然后填充白色,再填充红色:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.