Как убрать внутренний контур в OpenCV - PullRequest
0 голосов
/ 09 апреля 2019

Я хочу установить 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)

1 Ответ

1 голос
/ 10 апреля 2019

Вы можете использовать cv.fillPoly, чтобы заполнить контур цветом. docs.opencv.org/3.0-beta/modules/imgproc/doc/

...