Blur in a specific area with Opencv

Asked

Viewed 177 times

0

I am trying to blur a face found in a video using Opencv but am having the following error:

cv2.error: Opencv(4.1.0) /io/opencv/modules/imgproc/src/filter.simd.hpp:220: error: (-215:Assertion failed) src && dst && Count > 0 in Function 'Filterengine__proceed

I ran another code with the same logic changing the input to a static image and works perfectly.

Line in which the error occurs:

frame[x:x+w, y:y+h] = cv2.Blur(frame[x:x+w, y:y+h], (23, 23))

Complete code:

import cv2
import sys
import numpy

#argumento para entrada de arquivos de video
video = sys.argv[1]
#argumento para entrada de classificadores
cascPath = sys.argv[2]

#carrega o arquivo de classificacao treinado
faceCascades = cv2.CascadeClassifier(cascPath)

#capturando o video
cap = cv2.VideoCapture(video)

while(1):
    #lendo a imagem
    ret, frame = cap.read()
    #passando a imagem para cinza
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    #localizando faces
    faces = faceCascades.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30,30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        frame[x:x+w, y:y+h] = cv2.blur(frame[x:x+w, y:y+h], (23, 23))

        #exibindo o frame processado
        cv2.imshow('frame', frame)


    #aguardando tecla para finalizar o programa
    if cv2.waitKey(1) == ord('q'):
        break

#destroi todas janelas abertas 
cv2.destroyAllWindows()

I couldn’t find any more detailed content on Opencv besides the documentation, so if anyone has a good reference of studies on the subject, it will be very welcome.

  • I changed the given line but the error persists.

  • I took the test with the classifier /data/haarcascade_frontalface_alt.xml and with the webcam cap = cv2.VideoCapture(0). The code ran error-free, it’s just not working properly. The problem may be in the way your video is captured by Opencv.

  • I’m using a video. mp4 very short, I tried to change the video and the error continues, but now it arrives to initialize (thing that did not happen before). I noticed that the error occurs just when some face appears in the video. The problem started to happen when I added the Blur part. Locate faces and draw some geometric shape on it works normally.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.