Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 20, 2018 23:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3f0b8483632308555f8a46cbec132ba8 to your computer and use it in GitHub Desktop.
Save parzibyte/3f0b8483632308555f8a46cbec132ba8 to your computer and use it in GitHub Desktop.
"""
Tomar foto con Python y opencv
@date 20-03-2018
@author parzibyte
@see https://www.parzibyte.me/blog
"""
import cv2
import uuid
"""
En este caso, 0 quiere decir que queremos acceder
a la cámara 0. Si hay más cámaras, puedes ir probando
con 1, 2, 3...
"""
cap = cv2.VideoCapture(0)
leido, frame = cap.read()
if leido == True:
nombre_foto = str(uuid.uuid4()) + ".png" # uuid4 regresa un objeto, no una cadena. Por eso lo convertimos
cv2.imwrite(nombre_foto, frame)
print("Foto tomada correctamente con el nombre {}".format(nombre_foto))
else:
print("Error al acceder a la cámara")
"""
Finalmente liberamos o soltamos la cámara
"""
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment