-2

Assertion failed -215 opencv

!_src.empty() in function 'cv::cvtColor

error                                     Traceback (most recent call last)
<ipython-input-4-22f9613d8d9c> in <module>
     13 while 1:
     14     ret, img = cap.read()
---> 15     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
     16     faces = face_cascade.detectMultiScale(gray, 1.3, 5)
     17 

error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
Gautamrk
  • 1,144
  • 9
  • 12
  • What led to this error? – Seyi Daniel Aug 25 '20 at 12:20
  • it can means that it had problem to read file - CV doesn't raise error when it can't read file but it returns `None` in `img` and then you have empty data when you try to covnert color. if it has problem to read file then you should check if code runs in corect folder - `os.getcwd()` - or what you have in active folder - `os.listdir()`. OR you should use full path to image. If you get empty frame from camera then you may have to skip few frames because camera may need to warm up. `if img is not None: your_code` – furas Aug 25 '20 at 17:04

1 Answers1

-1

Try terminating the camera before running your code again. Because in the background your camera will be running. So make sure you end that and run again.

If you are using any XML files for feature extraction make sure you provide the exact path of the XML file.