Hello same issue with my raspberry
python --version
Python 3.5.3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.0'
cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Python source code :
import numpy as np
import cv2
device = 0
cap = cv2.VideoCapture(device)
# if capture failed to open, try again
if not cap.isOpened():
cap.open(device)
# only attempt to read if it is opened
if cap.isOpened:
while True:
re, img = cap.read()
# Only display the image if it is not empty
if re:
cv2.imshow("video output", img)
# if it is empty abort
else:
print( "Error reading capture device")
break
k = cv2.waitKey(10) & 0xFF
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
else:
print("Failed to open capture device")
But works whith this source :
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
how many webcams do you have ? the 1st would be id
0
, the 2nd id1
, etc. probably it's just the wrong id ...I have the one from the notebook self, and would like to use the one I plugged in. So I thought id = 1 but it also does not work