cv.cvtColor(img, cv.COLOR_BGR2GRAY) doesn't work
<p>This is my first attempt to detect faces and eyes in OpenCV 3.1. Here is my code:</p>

<pre><code>import cv2 as cv
import numpy as np

face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml')

cam = cv.VideoCapture(0)

while True:
    tf, img = cam.read()
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:
        img = cv.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]
        eyes = eye_cascade.detectMultiScalenter code heree(roi_gray)

        for (ex, ey, ew, eh) in eyes:
            cv.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)

        print(tf)
        cv.imshow('my cam', img)
        key = cv.waitKey(1)
        if key  == 27:
            break
cam.release()
cv.destroyAllWindows()
</code></pre>

<p>And I got this error:</p>

<pre><code>OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file D:\Build\OpenCV\opencv-3.1.0\modules\objdetect\src\cascadedetect.cpp, line 1639
Traceback (most recent call last):
  File "C:/Users/hedon/PycharmProjects/deneme_1.1/ilk.py", line 13, in &lt;module&gt;
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\objdetect\src\cascadedetect.cpp:1639: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
</code></pre>

<p>Can anybody told where is my mistake? I've also tried:</p>

<p><code>gray = cv.cvtColor(img, cv.COLOR_BAYER_GR2GRAY)</code> as PyCharm suggested. Same error:</p>

<pre><code>OpenCV Error: Assertion failed (scn == 1 &amp;&amp; dcn == 1) in cv::demosaicing, file D:\Build\OpenCV\opencv-3.1.0\modules\imgproc\src\demosaicing.cpp, line 1630
Traceback (most recent call last):
  File "C:/Users/hedon/PycharmProjects/deneme_1.1/ilk.py", line 11, in &lt;module&gt;
    gray = cv.cvtColor(img, cv.COLOR_BAYER_BG2GRAY)
cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\imgproc\src\demosaicing.cpp:1630: error: (-215) scn == 1 &amp;&amp; dcn == 1 in function cv::demosaicing
</code></pre>

<blockquote>
  <p>OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale</p>
</blockquote>

<p>is telling you that the classifier is <em>empty</em>, because you didn't load the xml files correctly. </p>

<p>Use the full path to the xml files to be sure to load them properly.</p>

python opencv numpy python-3.5 opencv3.1