forked from groupgets/pylepton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylepton_overlay
executable file
·66 lines (56 loc) · 2.32 KB
/
pylepton_overlay
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
#!/usr/bin/env python
import time
import picamera
import numpy as np
import cv2
import traceback
from pylepton import Lepton
def main(flip_v = False, alpha = 128, device = "/dev/spidev0.0"):
# Create an array representing a 1280x720 image of
# a cross through the center of the display. The shape of
# the array must be of the form (height, width, color)
a = np.zeros((240, 320, 3), dtype=np.uint8)
lepton_buf = np.zeros((60, 80, 1), dtype=np.uint16)
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.framerate = 24
camera.vflip = flip_v
camera.start_preview()
camera.zoom = (0.0, 0.0, 1.0, 1.0)
# Add the overlay directly into layer 3 with transparency;
# we can omit the size parameter of add_overlay as the
# size is the same as the camera's resolution
o = camera.add_overlay(np.getbuffer(a), size=(320,240), layer=3, alpha=int(alpha), crop=(0,0,80,60), vflip=flip_v)
try:
time.sleep(0.2) # give the overlay buffers a chance to initialize
with Lepton(device) as l:
last_nr = 0
while True:
_,nr = l.capture(lepton_buf)
if nr == last_nr:
# no need to redo this frame
continue
last_nr = nr
cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)
np.right_shift(lepton_buf, 8, lepton_buf)
a[:lepton_buf.shape[0], :lepton_buf.shape[1], :] = lepton_buf
o.update(np.getbuffer(a))
except Exception:
traceback.print_exc()
finally:
camera.remove_overlay(o)
if __name__ == '__main__':
from optparse import OptionParser
usage = "usage: %prog [options] output_file[.format]"
parser = OptionParser(usage=usage)
parser.add_option("-f", "--flip-vertical",
action="store_true", dest="flip_v", default=False,
help="flip the output images vertically")
parser.add_option("-a", "--alpha",
dest="alpha", default=128,
help="set lepton overlay opacity")
parser.add_option("-d", "--device",
dest="device", default="/dev/spidev0.0",
help="specify the spi device node (might be /dev/spidev0.1 on a newer device)")
(options, args) = parser.parse_args()
main(flip_v = options.flip_v, alpha = options.alpha, device = options.device)