Blurring only a part of a video

asked 2018-05-02 05:03:17 -0500

KaanCidar gravatar image

updated 2018-12-10 09:28:49 -0500

Hello im trying to blur my face in a video i have detected the face and blurred it but it it shows roi as seperate video and does the blurring there. my intention is to blur my face completely when i show video in canny edge detect mode.

Here's my code:

import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('/home/kaan/opencv-3.1.0/data/haarcascades/haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture(0)

while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = img[y:y + h, x:x + w]
        average = np.float32(roi_color)
        cv2.accumulateWeighted(roi_color, average, 0.05)

        # Scales, calculates absolute values, and converts the result to 8-bit
        blur = cv2.blur(roi_color, (15, 15))
        canny_face_blur = cv2.Canny(blur, 100, 200)
        cv2.imshow('Blurred Canny Face', canny_face_blur)
        blur2 = cv2.blur(img, (15, 15))

    cv2.imshow('img', img)
    canny_full_image = cv2.Canny(img, 100, 200)
    cv2.imshow('Canny Full Image', canny_full_image)

    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

and the problem is ? (and why the canny ?)

berak gravatar imageberak ( 2018-05-02 05:57:01 -0500 )edit
1

@berak Im getting seperate window that consist of the roi but i want to add that blurred roi to the original video. I need canny of the background for the real application. This just practice for me im trying to learn how to apply these to a video.

KaanCidar gravatar imageKaanCidar ( 2018-05-02 06:04:39 -0500 )edit