-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera_transform.py
More file actions
65 lines (53 loc) · 2.24 KB
/
Copy pathcamera_transform.py
File metadata and controls
65 lines (53 loc) · 2.24 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
"""Scale, rotate, mirror, and crop the camera onto the panel via the PPA.
``capture_scaled`` hands the frame to the Pixel Processing Accelerator:
rotate and mirror are free in the same pass as the scale. The destination is
described as a whole picture plus the rectangle to write inside it -- exactly
a panel framebuffer.
mpremote run camera_transform.py
Cycles through a few orientations so the effect is obvious on the glass.
"""
import time
import board_config
from board_config import display_drv as display
ORIENTATIONS = (
(0, False, "normal"),
(90, False, "rotate 90"),
(180, False, "rotate 180"),
(270, False, "rotate 270"),
(0, True, "mirrored"),
(180, True, "rotate 180 + mirror"),
)
def main(hold_s=2):
cam = board_config.camera
fb = display.framebuffers()[0]
print("sensor %s %dx%d -> panel %dx%d"
% ((cam.sensor()[0],) + cam.size()[:2] + (display.width, display.height)))
try:
for rotate, mirror, label in ORIENTATIONS:
print(label)
end = time.ticks_add(time.ticks_ms(), int(hold_s * 1000))
while time.ticks_diff(end, time.ticks_ms()) > 0:
# Full panel; crop example: pass x,y,w,h to write into a
# quadrant instead -- same call, smaller rectangle.
if cam.capture_scaled(fb, display.width, display.height,
rotate=rotate, mirror=mirror,
timeout=500) is None:
continue
display.show()
# And a cropped inset: centre quarter of the panel.
w, h = display.width // 2, display.height // 2
x, y = (display.width - w) // 2, (display.height - h) // 2
print(" + cropped inset %dx%d at (%d,%d)" % (w, h, x, y))
display.fill(0)
if cam.capture_scaled(fb, display.width, display.height,
x=x, y=y, w=w, h=h,
rotate=rotate, mirror=mirror,
timeout=500) is not None:
display.show()
time.sleep_ms(800)
except KeyboardInterrupt:
print("stopped")
finally:
cam.deinit()
if __name__ == "__main__":
main()