error: (-215: Assertion failed)! empty () in function 'detectMultiScale'

0

I'm totally lazy in linux and I'm trying to use opencv version 3.4.2 with python 3.5.2 in 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, here below, the error:

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'
    
asked by anonymous 29.07.2018 / 03:43

1 answer

3

The error was in this line:

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

The correct bar to be used:

classificador = cv2.CascadeClassifier('/home/linux/Documentos/deteccao/haarcascade_frontalface_default.xml') 
    
29.07.2018 / 04:06