Skip to content
Advertisement

opencv cascade.detectMultiScale creates error: (-215) !empty()

I am following this tutorial to understand haar features. While writing following code:

import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('Sachin.jpeg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

getting following error:

File "<ipython-input-6-0b479e459b0f>", line 1, in <module>
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    error: /home/travis/miniconda/conda-bld/conda_1486587069159/work/opencv-3.1.0/modules/objdetect/src/cascadedetect.cpp:1639: error: (-215) !empty() in function detectMultiScale

(Sachin is the image i downloaded from google, of size (237,237,3) and after converting gray it is (237,237) with min=23, max=210. I am using opencv 3.1.0 with python 3.6, installed using command conda install -c menpo opencv3. i am trying for this solution but unable to find xml file in my desktop. How to solve problem.

Advertisement

Answer

You need to specify the full paths to the XML files for Haar Cascade.

On Ubuntu 16.04, these files can be found in /usr/share/opencv/haarcascades.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement