Ask Your Question

Revision history [back]

cv2.VideoCapture(0).read() return always 'none' value

import cv2
camera = cv2.VideoCapture(-1)
facealg=cv2.CascadeClassifier("/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanima/haarcascade_frontalface_default.xml")
while True:
     ret, frame=camera.read()
     gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
     faces=  facealg.detectMultiScale(gray,1.3,5)
     for (x,y,w,h) in faces:
            cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2 )
    cv2.imshow("deneme",gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
cap.release()
cv2.destroyAllWindows()

This my codes.

I get the following error when I run the code:

Exception has occurred: cv2.error OpenCV(3.4.4) ../modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' File "/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanıma/KameradanYuzTanima.py", line 6, in <module> gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)

And i cant access the camera.

click to hide/show revision 2
retagged

updated 2019-02-13 12:51:54 -0600

berak gravatar image

cv2.VideoCapture(0).read() return always 'none' value

import cv2
camera = cv2.VideoCapture(-1)
facealg=cv2.CascadeClassifier("/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanima/haarcascade_frontalface_default.xml")
while True:
     ret, frame=camera.read()
     gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
     faces=  facealg.detectMultiScale(gray,1.3,5)
     for (x,y,w,h) in faces:
            cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2 )
    cv2.imshow("deneme",gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
cap.release()
cv2.destroyAllWindows()

This my codes.

I get the following error when I run the code:

Exception has occurred: cv2.error OpenCV(3.4.4) ../modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' File "/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanıma/KameradanYuzTanima.py", line 6, in <module> gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)

And i cant access the camera.

cv2.VideoCapture(0).read() return always 'none' value

import cv2
camera = cv2.VideoCapture(-1)
facealg=cv2.CascadeClassifier("/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanima/haarcascade_frontalface_default.xml")
while True:
     ret, frame=camera.read()
     gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
     faces=  facealg.detectMultiScale(gray,1.3,5)
     for (x,y,w,h) in faces:
            cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2 )
    cv2.imshow("deneme",gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
cap.release()
cv2.destroyAllWindows()

This my codes.

I get the following error when I run the code:

Exception has occurred: cv2.error OpenCV(3.4.4) ../modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' File "/home/resistablee/Documents/Projects/Python/Kameradan Yüz Tanıma/KameradanYuzTanima.py", line 6, in <module> gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/home/resistablee/Documents/Anaconda3/envs/Resistablee/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)

And i cant access the camera.