Access Webcam using Python?

0 votes
I would like to access my webcam from Python.

I tried using the VideoCapture extension, but that didn't work very well for me. But the problem is that it's a bit slow with resolutions >320x230, and sometimes it returns None for no apparent reason.

Can you help me with a better way to access my webcam from Python?
Oct 17, 2018 in Python by SDeb
• 12,280 points
243 views

1 answer to this question.

0 votes
OpenCV has support for getting data from a webcam, and it comes with Python wrappers by default, you also need to install numpy for the OpenCV Python extension (called cv2) to work

An example copied from Displaying webcam feed using opencv and python:

import cv2

cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False

while rval:
    cv2.imshow("preview", frame)
    rval, frame = vc.read()
    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
        break
cv2.destroyWindow("preview")
answered Oct 17, 2018 by ana1504.k
• 7,430 points

Related Questions In Python

+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,092 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,304 views
+2 votes
2 answers

How can I plot a k-dsitance graph using python?

Hi there, instead of sklearn you could ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,710 points
972 views
0 votes
2 answers

how to print the current time using python?

print(datetime.datetime.today()) READ MORE

answered Feb 14 in Python by Shashank
• 1,350 points
33 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 125 views
0 votes
1 answer

Power Math in Python

When you use "^" operator, it is ...READ MORE

answered Nov 12, 2018 in Python by ana1504.k
• 7,430 points
28 views
0 votes
1 answer

% operator in Python

When you use '(%g,%g)', it is the ...READ MORE

answered Nov 12, 2018 in Python by ana1504.k
• 7,430 points
18 views