error: (-215:Assertion failed) ! Empty() in Function 'detectMultiScale'

Asked

Viewed 1,733 times

0

I’m totally layy on linux and I’m trying to use opencv version 3.4.2 with python 3.5.2 on linux Mint to run an example facial detection code. Below the code:

import numpy as np
import cv2

classificador = cv2.CascadeClassifier('\home\linux\Documentos\deteccao\haarcascade_frontalface_default.xml')

imagem = cv2.imread('pessoas.jpg')
imagemCinza = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)

facesDetectadas = classificador.detectMultiScale(imagemCinza, scaleFactor=1.1, minNeighbors=20, minSize=(30,30))
print(len(facesDetectadas))
print(facesDetectadas)

for (x, y, l, a) in facesDetectadas:
print(x, y, l, a)
cv2.rectangle(imagem, (x, y), (x + l, y + a), (255, 0, 255), 2)

cv2.imshow("Faces encontradas", imagem)
cv2.waitKey()

And down here, the mistake:

Traceback (most recent call last):
 File "exemplo1.py", line 11, in <module>
  facesDetectadas = classificador.detectMultiScale(imagemCinza, scaleFactor=1.1, minNeighbors=20, minSize=(30,30))
cv2.error: OpenCV(3.4.2) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

1 answer

4

The mistake was on that line:

classificador = cv2.CascadeClassifier('\home\linux\Documentos\deteccao\haarcascade_frontalface_default.xml')

The correct bar to use:

classificador = cv2.CascadeClassifier('/home/linux/Documentos/deteccao/haarcascade_frontalface_default.xml') 

Browser other questions tagged

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