Identikit-Robot/get_head.py

38 lines
1.1 KiB
Python

import cv2
import time
cap = cv2.VideoCapture(0)
def get_image():
# Set the window name
window_name = 'Camera Capture'
# Get the default frames per second (fps) of the camera
fps = int(cap.get(cv2.CAP_PROP_FPS))
# Set the countdown duration in seconds
countdown_duration = 10
# Start the countdown
for countdown in range(countdown_duration, 10, -1):
ret, frame = cap.read()
# Display the camera feed
cv2.imshow(window_name, frame)
# Display the countdown on the image
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(frame, str(countdown)[0], (10, 30), font, 1, (0, 255, 0), 2, cv2.LINE_AA)
cv2.imshow(window_name, frame)
# Wait for 1 second and check for key press
if cv2.waitKey(100) & 0xFF == 27: # 27 is the ASCII code for the 'ESC' key
break
# Take a picture at the end of the countdown
ret, frame = cap.read()
#cv2.imwrite("image.png", frame)
# Release the camera and close the OpenCV window
cap.release()
cv2
return frame