Last active
April 19, 2017 13:55
-
-
Save tmkasun/f041a531cb6f99ffd46dd8b15d46c3de to your computer and use it in GitHub Desktop.
Capture frames from Lepton camera using PyLepton and serialize the data and transmit it over web socket protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThermalDataHandler(WebSocketHandler): | |
clients = [] | |
DEBUG = False | |
def __init__(self, application, request, **kwargs): | |
super(ThermalDataHandler, self).__init__(application, request, **kwargs) | |
if not ThermalDataHandler.DEBUG: | |
self.lepton = Lepton("/dev/spidev0.0") | |
self.lepton.__enter__() | |
self.mock_samples = MockData() | |
def check_origin(self, origin): | |
return True | |
def open(self): | |
if self not in ThermalDataHandler.clients: | |
self.write_message("ACK") | |
ThermalDataHandler.clients.append(self) | |
def on_close(self): | |
if self in ThermalDataHandler.clients: | |
ThermalDataHandler.clients.remove(self) | |
def on_message(self, message): | |
self.write_message(self._get_data()) | |
def _get_data(self): | |
if ThermalDataHandler.DEBUG: | |
raw_frame = self.mock_samples.get_next_sample() | |
else: | |
raw_frame, _ = self.lepton.capture() | |
raw_frame.astype(np.uint16) | |
return json.dumps(raw_frame.tolist()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment