使用opencvpython进行人脸移除

2024-06-07 16:07:41 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我想检测和跟踪的手使用皮肤颜色为基础,但我不需要看到脸或任何皮肤颜色(我的意思是我只需要左手跟踪)在输出视频。 谢谢

import cv2
import numpy as np

# Range for finding skin color in YCrCb
Low_YCrCb = np.array([0,125,80],np.uint8)
High_YCrCb = np.array([255,169,133],np.uint8)


while True 

    # grab frames from Video
    _, img = videoFrame.read()

    # Convert to YCrCb --
    img_YCrCb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)

    # Find ROI in YCrCb 
    skin_ROI = cv2.inRange(img_YCrCb, Low_YCrCb, High_YCrCb)

    # Find contour in skin region
    _, contours, _= cv2.findContours(skinROI, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # Draw the contour --
    for i, cnt in enumerate(contours):
        area = cv2.contourArea(cnt)
        if area > 500:
            cv2.drawContours(img, contours, i, (255, 0, 0), 2)

    # Results
    cv2.imshow('Result',img)

cv2.waitKey(0)
cv2.destroyWindow('Result')
videoFrame.release()

Tags: inimportimgfor颜色nparraycv2

热门问题