B
B
Bogdan Karpov2018-05-14 14:24:08
Python
Bogdan Karpov, 2018-05-14 14:24:08

How to get webcam images in Python 3?

How to get images from a webcam in Python 3, which module can be used for this purpose?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2018-05-14
@phpkoder

You can use the opencv module

import cv2

# Включаем первую камеру
cap = cv2.VideoCapture(0)

# "Прогреваем" камеру, чтобы снимок не был тёмным
for i in range(30):
    cap.read()

# Делаем снимок    
ret, frame = cap.read()

# Записываем в файл
cv2.imwrite('cam.png', frame)   

# Отключаем камеру
cap.release()

Q
QWERTYUIOPas, 2020-11-13
@QWERTYUIOPas

no module named 'cv2'
How to fix?

N
N00b228, 2021-06-30
@N00b228

@@QWERTYUIOPas
run pip install opencv-python on the command line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question