-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam.py
More file actions
73 lines (49 loc) · 1.76 KB
/
Copy pathcam.py
File metadata and controls
73 lines (49 loc) · 1.76 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
61
62
63
64
65
66
67
68
69
70
71
72
73
import camera
import machine
import time
def main():
import binascii
led = machine.Pin(4, machine.Pin.OUT)
led.on()
# Deinitialize the camera if it is initialize first
camera.deinit()
# Initialize the camera
camera.init(0) # 0 = default configuration
# Set camera parameters (optional)
camera.framesize(camera.FRAME_VGA) # 640x480 resolution
camera.quality(10) # Lower value = better quality
# Capture an image
img = camera.capture()
img_b64 = binascii.b2a_base64(img).decode("utf-8")
# print("Captured Image (Base64)")
# print(img_b64)
with open("/base64_img.txt", "wb") as file:
file.write(img_b64)
# # Save the image to a file
# with open("/sdcard/captured.jpg", "wb") as f:
# f.write(img)
print("Succesfuly Image captured and saved as 'base64_img.txt'")
# print("Image captured and saved as 'captured.jpg'")
led.off()
if __name__ == '__main__':
main()
# ============================= Extra function ================================= #
# Initializing camera
def init_camera(quality = 10):
# Deinitialize the camera if it is initialize first
camera.deinit()
# Initialize the camera
camera.init(0)
camera.framesize(camera.FRAME_QVGA) # Small size for fast streaming
camera.quality(quality) # Lower quality for better speed
# Generating stream
def generate_stream(delay_in_ms = 0.1):
while True:
frame = camera.capture()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
time.sleep(delay_in_ms) # Stream delay
# Capturing image
def capture_image():
img = camera.capture()
return img