Created
March 20, 2018 23:33
-
-
Save parzibyte/3f0b8483632308555f8a46cbec132ba8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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