2

Totally newbie here, I'm trying to do a project with the FLIR sensor and a Raspberry Pi. They provided me with some code that turns on both the Raspberry Pi Camera and the FLIR sensor and overlays the images. However, I don't care about the Raspberry Pi camera and just want the FLIR sensor display. I've never worked with a Raspberry Pi and never programmed in python so can someone help my by telling me what needs to be removed from the following code:

#!/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.fullscreen = True
    # 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)
0

Minimum change would be to remove the line:

camera.start_preview()

You could go much further than that, but sounds like you're not too familiar with code?

  • No I got it from the GitHub repo that the manufacturer linked to. Also, that line does disable a camera but it disables the wrong one. – Angel Lockhart Jul 13 '16 at 18:10
  • start_preview simply starts the live preview from the Pi's camera module. Looking at that demo code, it's using picamera's overlay system to render the Lepton FLIR camera's output; the overlay should work fine without the preview though, so with that line removed it should just be displaying the FLIR output – Dave Jones Jul 13 '16 at 20:19
  • Did you manage to get this working? I tried Andy's suggestion and got back this errors. ("Camera not enabled") even though the camera has been enabled via raspi-config. – Cullen McGough Dec 2 '16 at 15:03
0

You're doing a lot with picamera which is only useful if you actually want to use the visible light camera. If you are just trying to capture an image without any overlay, you could try this much more concise code I found from another stack exchange.

import numpy
import cv2
import threading
import Lepton

with Lepton() as l:

    def capture_video():
        threading.Timer(0.2, capture_video).start()
        a,_ = l.capture() #capturing raw sensor data
        cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX) #contrast-extending it
        numpy.right_shift(a, 8, a) #fitting to 8 bits
        cv2.imshow('image', numpy.uint8(a)) #just overwriting the saved file repeatedly
        cv2.waitKey()

capture_video()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.