0

Below is the code I'm trying to execute. I have followed this tutorial.

import cv2

CLASSIFIER_FILE = 'haarcascade_frontalface_default.xml'

face_cascade = cv2.CascadeClassifier(CLASSIFIER_FILE)

img = cv2.imread('abba.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


faces = face_cascade.detectMultiScale(gray, 1.3, 5)
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('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

When I try to run this code I'm getting this error:

ERROR: Required OpenCL device not found, check configuration: 
    Platform: any
    Device types: GPU 
    Device name: any
OpenCV Error: Unknown error code -33 (Requested OpenCL device is not found) in cv::ocl::selectOpenCLDevice, file ..\..\..\..\opencv\modules\core\src\ocl.cpp, line 2344
OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp, line 1578
Traceback (most recent call last):
  File "somepath\FaceDetect\face_detect.py", line 12, in <module>
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp:1578: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

From what I see there are some drivers missing but I'm not sure, where to search for them? I'm using AMD Radeon Graphics card. Can you help me understand the error I'm getting and how to fix it. Thank you!

5
  • i don't think, the error is related to your code. can you try any other tutorial there ?
    – berak
    Dec 23, 2014 at 16:20
  • @berak all tutorials I came through were using this CascadeClassifier and I'm always getting this error in the detectMultiScale function Dec 23, 2014 at 16:23
  • true. but that means, your cv2.pyd was compiled with opencl support, and your box does not have it [or does not find it]. (i only wanted you to do a cross-check)
    – berak
    Dec 23, 2014 at 16:30
  • @berak updating my GPU drivers fixed that, but know I'm getting (-215) !empty() in function cv::CascadeClassifier::detectMultiScale error. Do you have any ideas how to solve that? I have added gray = np.array(gray, dtype='uint8') faces = face_cascade.detectMultiScale(gray, 1.3, 5) But it's still not working. Dec 23, 2014 at 18:42
  • 1
    oh, progress, good ;). error means, that the img you load is empty(not found). or maybe the cascade. check the file path for both again. keep your original code, don't make a new numpy array.
    – berak
    Dec 23, 2014 at 18:48

1 Answer 1

0

This might resolve your problem, Give it a shot !

from cv2 import *
import os

class Camera:

# initialize the camera
def capture_pic():
    cam = VideoCapture(0)   # 0 -> index of camera
    s, img = cam.read()
    if s:    # frame captured without any errors
        namedWindow("cam-test", flags = WINDOW_AUTOSIZE)
        imshow("cam-test",img)
        waitKey(0)
        destroyWindow("cam-test")
        imwrite('test_pic.jpg', img) 
        cv2.imshow('test_pic.jpg', img)


Camera.capture_pic()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.