def prepThermalCameraValues(flip_v=False, device="/dev/spidev0.0"):
    #gives min and max temperature from array
    with Lepton3(device) as l:
        a, _ = l.capture()
        min_t = ((a.min() - 27315) / 100.0)
        max_t = ((a.max() - 27315) / 100.00)
        return min_t, max_t
Exemplo n.º 2
0
def capture(device="/dev/spidev0.0"):
    with Lepton3(device) as l:
        #    time.sleep(0.2)
        a, _ = l.capture()
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    np.right_shift(a, 8, a)
    return np.uint8(a)
Exemplo n.º 3
0
def capture(flip_v=False, device="/dev/spidev0.1"):
    with Lepton3(device) as l:
        a, _ = l.capture()
    if flip_v:
        cv2.flip(a, 0, a)
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    np.right_shift(a, 8, a)
    return np.uint8(a)
Exemplo n.º 4
0
    def _thread(cls):
        if cls.device_type == raspberrypi():
            with picamera.PiCamera() as camera:
                # camera setup
                camera.resolution = (cls.width, cls.height)
                camera.hflip = True
                camera.vflip = True

                # let camera warm up
                camera.start_preview()
                sleep(2)

                stream = io.BytesIO()
                for _ in camera.capture_continuous(stream,
                                                   'jpeg',
                                                   use_video_port=True):
                    stream.seek(0)
                    cls.frame = stream.read()
                    stream.seek(0)
                    stream.truncate()

                    if cls.should_stop():
                        break
        elif cls.device_type == thermal():
            while True:
                with Lepton3("/dev/spidev0.0") as l:
                    a, _ = l.capture()

                vflip = True
                if vflip:
                    cv2.flip(a, 0, a)

                cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
                np.right_shift(a, 8, a)
                cls.frame = cv2.imencode('.jpg', np.uint8(a))[1].tobytes()

                if cls.should_stop():
                    break
        else:  # Default to default system camera device
            capture = cv2.VideoCapture(0)
            success, frame = capture.read()

            if success:
                cls.height, cls.width = frame.shape[:2]
                cls.size = cls.height * cls.width

                while success:
                    success, frame = capture.read()
                    cls.frame = cv2.imencode('.jpg', frame)[1].tobytes()

                    if cls.should_stop():
                        break
            else:
                print("Default camera device not found [{}]".format(
                    cls.device_type))

        print("Setting thread to none")
        cls.thread = None
 def lepton_sensor_init(self, device = "/dev/spidev0.0"):
     self.sensor = Lepton3(device)
     self.image_id = 0
     self.file_extention = ".png"
     self.path_file_name = "/home/pi/flir_lepton_sensor/scripts/path.txt"
     self.image_file_name = "/home/pi/flir_lepton_sensor/scripts/image.txt"
     self.path = self.get_path()
     self.create_image_directory()
     self.create_image_file()
def captureT(flip_v=False, device="/dev/spidev0.0"):
    #prep for thermal capture
    with Lepton3(device) as l:
        a, _ = l.capture()
    if flip_v:
        cv2.flip(a, 0, a)
    minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(a)
    a[0][0] = min_c
    a[-1][-1] = max_c
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    np.right_shift(a, 8, a)
    image_gray = np.uint8(a)
    img = cv2.applyColorMap(image_gray, cv2.COLORMAP_JET)
    return img
Exemplo n.º 7
0
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((120, 160, 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, 160, 120),
                               vflip=flip_v)
        try:
            time.sleep(0.2)  # give the overlay buffers a chance to initialize
            with Lepton3(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)
Exemplo n.º 8
0
def main():
    args = parse_args()

    device = "/dev/spidev0.0"

    width = args.width
    height = args.height

    pixel_width = args.pixel
    pixel_height = args.pixel

    screen_width = width * pixel_width
    screen_height = height * pixel_height

    pixels = np.zeros((height, width, 1), dtype=np.uint16)

    print(screen_width, screen_height)
    print(args.min, args.max)
    print('Press "Esc", "q" or "Q" to exit.')

    # pygame
    pygame.init()

    clock = pygame.time.Clock()

    screen = pygame.display.set_mode((screen_width, screen_height))

    screen.fill((0, 0, 0))
    pygame.display.update()

    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                break

        keys = pygame.key.get_pressed()
        if keys[pygame.K_ESCAPE] or keys[pygame.K_q]:
            run = False

        if run == False:
            break

        nr = 0
        max_temp = float("-inf")
        min_temp = float("inf")

        try:
            with Lepton3(device) as l:
                _, nr = l.capture(pixels, args.debug)

                for ix, row in enumerate(pixels):
                    max_temp = max(max_temp, max(row))
                    min_temp = min(min_temp, min(row))

                # pixels[0][0] = args.max
                # pixels[0][1] = args.min

                cv2.normalize(pixels, pixels, 0, 65535, cv2.NORM_MINMAX)
                np.right_shift(pixels, 8, pixels)

        except Exception:
            traceback.print_exc()

        # draw everything
        for ix, row in enumerate(pixels):  # 120
            for jx, pixel in enumerate(row):  # 160
                color = get_color(pixel)
                pygame.draw.rect(
                    screen,
                    color,
                    (
                        # left, top, width, height
                        pixel_width * jx,
                        pixel_height * ix,
                        pixel_width,
                        pixel_height,
                    ),
                )

        print(nr, args.min, min_temp, max_temp, args.max)

        if max_temp > args.max:
            filename = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S-%f")
            data = {
                "filename": filename,
                "temperature": max_temp,
                "uploaded": False
            }
            save_json(args.json_path, data)

        pygame.display.update()
        clock.tick(FRAME_RATE)

    pygame.quit()
Exemplo n.º 9
0
import sys
import numpy as np
import cv2
from pylepton.Lepton3 import Lepton3

with Lepton3("/dev/spidev0.0") as l:
    rawArray, _ = l.capture()
a = rawArray / 100 - 273.15
for i in range(0, 120):
    print(a[i])
Exemplo n.º 10
0
import numpy as np
import cv2
from pylepton.Lepton3 import Lepton3

while True:
    with Lepton3() 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.imshow("output", np.uint8(a))  # write it!
    if cv2.waitKey(20) & 0xFF == ord('d'):
        break

cv2.destroyAllWindows()
Exemplo n.º 11
0
def main(device = "/dev/spidev0.0"):
    a = np.zeros((120, 160, 3), dtype=np.uint8)
    lepton_buf = np.zeros((120, 160, 1), dtype=np.uint16)
    fgbg = cv2.createBackgroundSubtractorMOG2()
    debut = time.time()

    # Window creation to expand them
    cv2.namedWindow('Background Subtraction',cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Background Subtraction',160*3,120*3)
    cv2.namedWindow('Original Stream',cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Original Stream',160*3,120*3)
    cv2.namedWindow('Threshold Processed', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Threshold Processed', 160*3,120*3)
    rectangleFound = False
    contoursFound = False
    try:
        with Lepton3(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

                # Background Removing by appliying the BackgroundSubtractorMOG2
                gmask = fgbg.apply(a)

                # Image processing in binary format then refining it by erosion then dilatation
                thresh = cv2.threshold(gmask, 15, 255, cv2.THRESH_BINARY)[1]
                kernel = np.ones((2,2), np.uint8)
                thresh = cv2.erode(thresh, kernel, iterations=1)
                thresh = cv2.dilate(thresh, kernel, iterations=1)
                
                #Finding all the contours with an area bigger than 70 pixels
                _, contours, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                
                for c in contours:
		    
                    # if the contour is too small, ignore it
                    if cv2.contourArea(c) < 70:
                        continue
                    
                    contoursFound = True
 
                    # compute the bounding box for the contour, draw it on the frame,
                    # and update the text
                    (x, y, w, h) = cv2.boundingRect(c)
                    cv2.rectangle(a, (x, y), (x + w, y + h), (255, 255, 255), 2)
                    cv2.rectangle(thresh, (x, y), (x + w, y + h), (255, 255, 255), 2)

                    if(time.time() - debut) > 5:
                        serial_transmission.serialsending(str(x)+str(y)+str(w)+str(h),'/dev/ttyUSB1')
                        print "Envoyé !"
                        debut = time.time()
                    
                if not contoursFound :
                    debut = time.time()
                        
                contoursFound = False

                # Displays the 3 steps of the image processing in 3 windows
                cv2.imshow('Original Stream',a)
                cv2.imshow('Background Subtraction',gmask)
                cv2.imshow('Threshold Processed', thresh)
                cv2.waitKey(1)
    except Exception:
        traceback.print_exc()
Exemplo n.º 12
0
def run():
    device = "/dev/spidev0.0"

    a = np.zeros((240, 320, 3), dtype=np.uint8)
    lepton_buf = np.zeros((120, 160, 1), dtype=np.uint16)

    pixels = [160, 120]
    length = pixels[0] * pixels[1]

    # pylint: disable=invalid-slice-index
    points = [(math.floor(ix / pixels[1]), (ix % pixels[1])) for ix in range(0, length)]
    grid_x, grid_y = np.mgrid[0:159:160j, 0:119:120j]
    # pylint: enable=invalid-slice-index

    width = pixels[0] * 4
    height = pixels[1] * 4

    displayPixelWidth = 4
    displayPixelHeight = 4

    # pygame
    pygame.init()

    # clock = pygame.time.Clock()

    screen = pygame.display.set_mode((width, height))

    screen.fill((0, 0, 0))
    pygame.display.update()

    # let the sensor initialize
    time.sleep(0.1)

    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                break

        keys = pygame.key.get_pressed()
        if keys[pygame.K_ESCAPE] or keys[pygame.K_q]:
            run = False

        if run == False:
            break

        lepton_min = float("inf")
        lepton_max = float("-inf")

        # read the pixels
        pixels = []

        try:
            with Lepton3(device) as l:
                _, nr = l.capture(lepton_buf)

                # print(_)
                # print(nr)

                for ix, row in enumerate(lepton_buf):  # 120
                    for jx, pixel in enumerate(row):  # 160
                        lepton_buf[ix][jx] = min(max(pixel, MINTEMP), MAXTEMP)

                lepton_buf[0][0] = MAXTEMP
                lepton_buf[0][1] = MINTEMP

                cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)

                # for ix, row in enumerate(lepton_buf):  # 120
                #     lepton_min = min(lepton_min, min(row))
                #     lepton_max = max(lepton_max, max(row))
                # print(lepton_min, lepton_max)

                np.right_shift(lepton_buf, 8, lepton_buf)

        except Exception:
            traceback.print_exc()

        # draw everything
        for ix, row in enumerate(lepton_buf):  # 120
            for jx, pixel in enumerate(row):  # 160
                color = get_color(pixel)
                pygame.draw.rect(
                    screen,
                    color,
                    (
                        # left, top, width, height
                        displayPixelWidth * jx,
                        displayPixelHeight * ix,
                        displayPixelWidth,
                        displayPixelHeight,
                    ),
                )

        pygame.display.update()
        # clock.tick(FRAME_RATE)

    pygame.quit()