K
K
kuzdman2018-08-26 17:43:51
Python
kuzdman, 2018-08-26 17:43:51

Where can I find full XML file paths for Haar Cascade (OpenCV Python)?

Hello! I execute the following code :

import numpy as np
import cv2


faceCascade = cv2.CascadeClassifier('Cascades/haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture(0)
cap.set(3, 640)  # set Width
cap.set(4, 480)  # set Height

while True:
    ret, img = cap.read()
    img = cv2.flip(img, -1)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.2,
        minNeighbors=5,
        minSize=(20, 20)
    )

    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]

    cv2.imshow('video', img)

    k = cv2.waitKey(30) & 0xff
    if k == 27:  # press 'ESC' to quit
        break

cap.release()
cv2.destroyAllWindows()

Gives an error like:
Traceback (most recent call last):
  File "mycodedirectory", line 19, in <module>
    minSize=(20, 20)
cv2.error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'

Googled, I realized that you need to write in line 5 the full path to the XML files for Haar Cascade.
The question is where are they. I can't find it at all. Tell me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2018-12-15
@kuzdman

...\Anaconda3\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml
Or download the file separately from the OpenCV sources on GitHub.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question