Giter Site home page Giter Site logo

pylepton's Introduction

pylepton

Quick and dirty pure python library for capturing images from the Lepton over SPI (for example, on a Raspberry PI).

Requires cv2 and numpy modules, if you don't have them already. On a Debian-based system you can probably do this:

$ sudo apt-get install python-opencv python-numpy

You can run the examples in the working directory, but a distutils setup is included to install into site-packages for distribution:

$ sudo python setup.py install

Example usage

import numpy as np
import cv2
from pylepton import Lepton

with Lepton() as l:
  a,_ = l.capture()
cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX) # extend contrast
np.right_shift(a, 8, a) # fit data into 8 bits
cv2.imwrite("output.jpg", np.uint8(a)) # write it!

Image data from capture() is 12-bit, non-normalized (raw sensor data). Here we contrast extend it since the bandwidth tends to be narrow.

capture() returns a tuple that includes a unique frame ID, as lepton frames can update at ~27 Hz, but only unique ones are returned at ~9 Hz. Currently, this is just a simple sum, but ideally this will turn into a real frame ID from telemetry once this feature is implemented.

Note also that the Lepton contructor can take as an optional argument the SPI device on which to find the Lepton. If in your system that device is /dev/spidev0.1, you can instantiate lepton as such:

...
with Lepton("/dev/spidev0.1") as l:
  ...

Example programs

pylepton_overlay

Requires python-picamera, a Raspberry PI, and compatible camera such as http://www.adafruit.com/products/1367

$ sudo apt-get install python-picamera

$ pylepton_overlay --help
Usage: pylepton_overlay [options]

Options:
  -h, --help            show this help message and exit
  -f, --flip-vertical   flip the output images vertically
  -a ALPHA, --alpha=ALPHA
                        set lepton overlay opacity

To get a 100% lepton overlay (note camera installation still required):

$ pylepton_overlay -a 255

pylepton_capture

Note that this program will output any image format that opencv knows about, just specify the output file format extension (e.g. output.jpg or output.png)

$ pylepton_capture --help
Usage: pylepton_capture [options] output_file[.format]

Options:
  -h, --help           show this help message and exit
  -f, --flip-vertical  flip the output image vertically

To capture a png file named output.png:

$ pylepton_capture output.png

pylepton's People

Contributors

kekiefer avatar brandoncurtis avatar

Watchers

Coby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.