Ask Your Question
0

Why does faceCascade.detectMultiScale abort on call?

asked 2017-06-10 20:05:33 -0500

Bazmundi gravatar image

updated 2017-06-10 20:07:23 -0500

The code is:

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(1)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

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

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

Code was from https://realpython.com/blog/python/fa...

The original code did not work because of deprication of cv2.cv.CV_HAAR_SCALE_IMAGE which is replaced with cv2.CASCADE_SCALE_IMAGE from guidance at https://stackoverflow.com/questions/4...

However, cv::CascadeClassifier::detectMultiScale causes exception with assertion (!empty()) at cascadedetect.cpp line 1681

I am using windoze 10, OpenCV 3.2, Python 2.7.9 64bit (stackless)

Any ideas please? It is a fresh install of OpenCV binaries.

Cheers, B

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-06-10 20:22:14 -0500

Bazmundi gravatar image

DOH. Answer is make sure you set the path to the xml haarcascade descriptor. The error is not very descriptive but it turns out it means there was no xml file at file path provided when running code.

edit flag offensive delete link more
0

answered 2017-10-30 20:41:39 -0500

supra56 gravatar image

video_capture = cv2.VideoCapture(0)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-10 20:05:33 -0500

Seen: 483 times

Last updated: Oct 30 '17