2
votes

I run the following code, according this page - http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html

cap = cv2.VideoCapture(0)
print cap.read()
print cap.open()
cap.release()

the results I get are:

(False, None)

TypeError: Required argument 'device' (pos 1) not found

I use jupyter notebook, python 2.7, openCV 2.4.

How can I get the openCV to work with the cam?

2
try instead of 0 1 - thesonyman101
You are using opencv 2.4 but reading the 3.0 documentation? - mr nick

2 Answers

3
votes

For OpenCV 2.4, use the following code:

import cv2
cap = cv2.VideoCapture(0)
    
while True: 
    
    ret,img=cap.read()
    
    cv2.imshow('Video', img)
    
    if(cv2.waitKey(10) & 0xFF == ord('b')):
        break

If you still can't get the camera input, replace VideoCapture(0) with VideoCapture(1). The issue could be because of a 3rd party camera driver installed on your machine.

If that doesn't work either, try VideoCapture("path/to/saved_video"). If you have entered the file path correctly, and your OpenCV configuration has no issues, you should get saved video frames. This would imply that you need to check the camera drivers

0
votes

use the following command to figure which device is your webcam on:

$ls /dev/video*

and use the number for VideoCapture(num)