Ask Your Question
0

What am I doing wrong?

asked 2017-11-13 11:25:17 -0600

Sasha gravatar image

updated 2017-11-13 11:35:11 -0600

berak gravatar image

Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread('D:/14801853607540.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: D:\Build\OpenCV\opencv-3.3.0\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
edit retag flag offensive close merge delete

Comments

I just pointed to the full path to 'haarcascade_frontalface_default.xml', and it worked. I am stupid. Thank you kind man

Sasha gravatar imageSasha ( 2017-11-13 12:26:38 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-13 11:35:53 -0600

berak gravatar image

updated 2017-11-13 12:18:36 -0600

it simply never found your 'haarcascade_frontalface_default.xml'

i know, noobs NEVER follow advice, but take my one on this -- whenever you're loading something from somewhere, CHECK, if it worked, or not.

in this case:

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
if face_cascade.empty(): # you got the path wrong

# also:
img = cv2.imread('D:/14801853607540.jpg')
if img.empty(): #same sillynes. every 4th SO question is about failing to do so.

stop being a noob, and check your resources, please !

edit flag offensive delete link more

Comments

@Sasha Don't forget to up-vote and mark as answer if it helped resolve your issue

eshirima gravatar imageeshirima ( 2017-11-13 13:08:24 -0600 )edit

How do I get more medals? I need some more to be able to up-vote answers to my own questions.

sjhalayka gravatar imagesjhalayka ( 2017-11-13 14:00:54 -0600 )edit
1

@sjhalaykaThis should be helpful. Search the forum for open questions and see if you can answer them. I would recommend you also review, how to write a good answer

eshirima gravatar imageeshirima ( 2017-11-13 14:53:50 -0600 )edit

Thank you!

sjhalayka gravatar imagesjhalayka ( 2017-11-13 15:24:54 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-13 11:18:17 -0600

Seen: 77 times

Last updated: Nov 13