import cv2
import numpy as np
key = cv2. waitKey(1)
webcam = cv2.VideoCapture(0)
while True:
try:
check, frame = webcam.read()
print(check) #
print(frame) #
cv2.imshow("Cámara de Seguridad", frame)
key = cv2.waitKey(1)
if key == ord('s'):
cv2.imwrite(filename='saved_img.jpg', img=frame)
webcam.release()
img_new = cv2.imread('saved_img.jpg', cv2.IMREAD_GRAYSCALE)
img_new = cv2.imshow("Imagen Capturada", img_new)
cv2.waitKey(2650)
cv2.destroyAllWindows()
print("Procesando la Imagen...")
img_ = cv2.imread('saved_img.jpg', cv2.IMREAD_ANYCOLOR)
print("Converting RGB imagen a escala de grises...")
gray = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY)
print("Converted RGB image to grayscale...")
print("redimencionado imagen a 25x35 scale...")
img_ = cv2.resize(gray,(28,28))
print("Redimencionado")
img_resized = cv2.imwrite(filename='saved_img-final.jpg', img=img_)
print("Imagen guardada")
break
elif key == ord('q'):
print("Apagando Camara")
webcam.release()
print("Camera apagada")
print("programa finalizado.")
cv2.destroyAllWindows()
break
except(KeyboardInterrupt):
print("Apagando Camara")
webcam.release()
print("Camera apagada")
print("Programa finalizado.")
cv2.destroyAllWindows()
break
añade un comentario
|
1 respuesta
En el if
te sobran tres líneas:
webcam.release()
: si liberas la cámara, en la siguiente iteración el frame seráNone
y provocará una excepción enimshow
.cv2.destroyAllWindows()
obviamente.break
: esto rompe el ciclowhile
cunado caes en elif
(captura) que es lo que no quieres. Esto no ocasiona que la ventana se cierre, pero quedará congelada al no actualizarse con nuevos frames.
Con esto la ventana no se cerrará cuando generes una captura.