-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathpicture.py
More file actions
60 lines (44 loc) · 1.6 KB
/
picture.py
File metadata and controls
60 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# try:
# from picamera2 import Picamera2
# except:
# pass
# from time import sleep
# def take_picture(filepath: str):
# """Take a picture using the Picamera2 library and save it to the provided file path."""
# print("Taking picture...")
# picam2 = Picamera2()
# # Create a camera configuration for preview
# camera_config = picam2.create_preview_configuration()
# # Configure the camera with the preview configuration
# picam2.configure(camera_config)
# # Start the camera preview using DRM for non-GUI
# picam2.start_preview(Preview.QTGL)
# # Start the camera
# picam2.start()
# # Wait for 2 seconds to allow the camera sensor to adjust
# sleep(2)
# # Capture an image and save it as filepath"
# picam2.capture_file(filepath)
# # Stop the camera
# picam2.stop()
# print(f"Picture taken and saved as {filepath}")
# return f"Picture taken and saved as {filepath}"
import cv2
from time import sleep
from text_to_speech import speak
def take_picture(filepath: str):
"""Take a picture using the specified camera and save it to the provided file path."""
speak("Alright, I'm taking a picture now.")
print("Taking picture...")
cap = cv2.VideoCapture(0)
sleep(2)
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
cap.release()
return None
cv2.imwrite(filepath, frame)
print(f"Picture taken and saved as {filepath}")
cap.release()
speak("Got it! I've taken picture and saved it.")
return f"Picture taken and saved as {filepath}"