Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
I might want to get to my webcam from Python.

I attempted utilizing the VideoCapture extension, yet that didn't function admirably for me, I needed to work around certain issues, for example, it's somewhat delayed with the resolutions >320x230, and once in a while, it returns None for no clear explanation.

I just want to know, Is there any better way to access the webcam through python.

1 Answer

0 votes
by (26.4k points)

OpenCV has a support for getting information from the webcam, and it accompanies Python wrappers as a matter of course, you additionally need to install the NumPy for the OpenCV Python segmentation (called cv2) to work. Starting in 2019, you can also install both of these libraries with pip: 

pip install numpy 

pip install opencv-python

Click on this link, For more information on using the OpenCV with Python

Look at the below code:

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")

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 20, 2019 in DevOps and Agile by chandra (29.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...