gpt4 book ai didi

opencv - 如何在OpenCV中删除内部轮廓

转载 作者:行者123 更新时间:2023-12-02 17:31:12 27 4
gpt4 key购买 nike

我要设置轮廓ROI,并将其连同其中的区域一起删除。一世
我正在使用下面的代码来检测和删除轮廓,但是如何也可以删除内部区域?

def get_skin_area(self):

# Get pointer to video frames from primary device
sourceImage = cv2.imread(self.img)

# Constants for finding range of skin color in YCrCb
min_YCrCb = np.array([0, 133, 77], np.uint8)
max_YCrCb = np.array([255, 173, 127], np.uint8)

# Convert image to YCrCb
imageYCrCb = cv2.cvtColor(sourceImage, cv2.COLOR_BGR2YCR_CB)

# Find region with skin tone in YCrCb image
skinRegion = cv2.inRange(imageYCrCb, min_YCrCb, max_YCrCb)

# Do contour detection on skin region
_, contours, hierarchy = cv2.findContours(skinRegion, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

mask = np.ones(sourceImage.shape[:2], dtype="uint8") * 255

# Draw the contour on the source image
for i, c in enumerate(contours):
area = cv2.contourArea(c)
if area > 1000:
# cv2.drawContours(sourceImage, contours, i, (0, 255, 0), 3)
cv2.drawContours(mask, contours, i, (0, 255, 0), 3)

image = cv2.bitwise_and(sourceImage, sourceImage, mask=mask)

cv2.imshow("Mask", mask)
cv2.imshow("After", image)

最佳答案

您可以使用cv.fillPoly用颜色填充轮廓。 docs.opencv.org/3.0-beta/modules/imgproc/doc/

关于opencv - 如何在OpenCV中删除内部轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55582722/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com