Ejemplo n.º 1
0
def get_temp_max(runopts):
  """
  Gets treatment temperature with the Lepton thermal camera
  """
  if runopts.faket:
    return 24

  run = True
  for rr in range(8):
    try:
      with Lepton("/dev/spidev0.1") as l:
        data,_ = l.capture(retry_limit = 3)
      if l is not None:
         Ts = NP.amax(data[6:50,:,0]) / 100 - 273;
         Tt = NP.amax(data[0:5,:,0]) / 100 - 273;
         mm= NP.where( data == NP.amax(data[6:50,:,0]) )
         print('max point at {},{}'.format(*mm))
         for line in data:
            l = len(line)
            if (l != 80):
                print("error: should be 80 columns, but we got {}".format(l))
            elif Ts > 150:
                print("Measured temperature is too high: {}".format(Ts))
         time.sleep(0.070)
         run = False
    except Exception as e:
      print(e)
      print("\nHardware error on the thermal camera. Lepton restarting...")
      gpio.output(35, gpio.HIGH)
      time.sleep(0.5)
      gpio.output(35, gpio.LOW)
      print("Lepton restart completed!\n\n")

  return [int(mm[0]), int(mm[1])]
Ejemplo n.º 2
0
def get_frame():
    # camera = cv2.VideoCapture(0)
    # while True:
    #     _, img = camera.read()
    #     img2 = face_recognition(img)
    #     imgencode = cv2.imencode('.jpg', img2)[1]
    #     stringData = imgencode.tostring()
    #     yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n')
    # del(camera)
    while True:
        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

        scale_percent = 400  # percent of original size
        width = int(a.shape[1] * scale_percent / 100)
        height = int(a.shape[0] * scale_percent / 100)
        dim = (width, height)
        resized = cv2.resize(a, dim, interpolation=cv2.INTER_AREA)
        a = copy.copy(resized)
        imgencode = cv2.imencode('.jpg', a)[1]
        stringData = imgencode.tostring()
        yield (b'--frame\r\n'
               b'Content-Type: text/plain\r\n\r\n' + stringData + b'\r\n')
Ejemplo n.º 3
0
 def captureFrame(self):
     a,_ = Lepton().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("capture"+str(self.FrameId)+".jpg", np.uint8(a)) # write it!
     self.FrameId = self.FrameId+1
     self.newFrame = a
Ejemplo n.º 4
0
def runCode():
    while True:
        global pixdata, json_data, image, multiplicationFactor
        FileName = "output.png"
        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(FileName, np.uint8(a))
        image = Image.open(FileName)
        imageOrigin = Image.open(FileName)
        image = image.convert('RGB')
        pixdata = image.load()
        analyze()

        imageOrigin = imageOrigin.resize((80 * multiplicationFactor, 60 * multiplicationFactor))
        imageOrigin.save(FileName)

        with open(FileName, 'rb') as f:
            imdata = f.read()
            f.close()

        json_blobs = json.dumps(blobs, default=obj_dict)
        outjson = {
            "blobs": json.loads(json_blobs),
            "img": imdata.encode('base64'),
            "multiplicationFactor": multiplicationFactor
        }
        json_data = json.dumps(outjson)
Ejemplo n.º 5
0
def get_temp(runopts):
    """
  Gets treatment temperature with the Lepton thermal camera
  """
    if runopts.faket:
        return 24
    run = True
    while run:
        try:
            with Lepton("/dev/spidev0.1") as l:
                data, _ = l.capture(retry_limit=3)
            if l is not None:
                Ts = NP.amax(data) / 100 - 273
                for line in data:
                    l = len(line)
                    if (l != 80):
                        print("error: should be 80 columns, but we got {}".
                              format(l))
                    elif Ts > 150:
                        print(
                            "Measured temperature is too high: {}".format(Ts))
                #curtime = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")
                #fname = "{}".format(curtime)
                #Ts = NP.amax(data) / 100 - 273;
                #Ts = NP.true_divide(NP.amax(data[7:50]),100)-273;
                time.sleep(0.050)
                run = False
        except:
            print(
                "\nHardware error on the thermal camera. Lepton restarting...")
            gpio.output(35, gpio.HIGH)
            time.sleep(0.5)
            gpio.output(35, gpio.LOW)
            print("Lepton restart completed!\n\n")
    return Ts
Ejemplo n.º 6
0
def capture(flip_v = False, device = "/dev/spidev0.0"):
    with Lepton(device) as l:
        a,_ = l.capture()
    if flip_v:
        cv2.flip(a,0,a)
    cv2.normalize(a, a, 0, 255, cv2.NORM_MINMAX) #Normalization of data
   #print(a)
    return np.uint8(a)
Ejemplo n.º 7
0
def capture(flip_v=False, device="/dev/spidev0.0"):
    with Lepton(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)
Ejemplo n.º 8
0
def capture(device="/dev/spidev0.0"):
    with Lepton(device) as l:
        a, frame = l.capture()

    #cv2.flip(a,0)
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    np.right_shift(a, 8, a)
    return np.uint8(a)
def capture(flip_v=False, device="/dev/spidev0.0"):
    with Lepton(device) as l:
        a, _ = l.capture()
    if flip_v:
        cv2.flip(a, 0, a)
    #cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    #np.left_shift(a, 2, a)
    return np.int16(a)
Ejemplo n.º 10
0
def capture(flip_v=False, device="/dev/spidev0.0"):

    with Lepton(device) as l:
        a, s = l.capture()
    if flip_v:
        cv2.flip(
            a, -1, a
        )  #a flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.
    return a, s
Ejemplo n.º 11
0
def getIm():
    with Lepton() as l:
        a,_ = l.capture()
    cv2.normalize(a,a,0,65535,cv2.NORM_MINMAX)
    np.right_shift(a,8,a)

    cv2.imshow("a",a)

    return a/float(255)
Ejemplo n.º 12
0
def lepton_process(connection, lepton_device):
    print('lepton process running')
    with Lepton(lepton_device) as lepton:
        while not connection.poll():
            lepton_frame = lepton.capture()
            connection.send(lepton_frame)
    print('lepton process exiting')
    connection.close()
    print('lepton process exited')
Ejemplo n.º 13
0
def capture(flip_v=False, device="/dev/spidev0.0"):
    with Lepton(device) as l:
        a, _ = l.capture()
    if flip_v:
        cv2.flip(a, 0, a)
    np.savetxt("Rpi.csv", a, delimiter=",")
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
    np.savetxt("normalizedRpi.csv", a, delimiter=",")
    np.right_shift(a, 8, a)
    return np.uint8(a)
Ejemplo n.º 14
0
def capture_image(filename, size):
    with Lepton() as l:
        a, _ = l.capture()

    #Create a PIL image from numpy array
    image = Image.fromarray(a.astype('uint8'), 'RGB')

    #resize PIL image to match picamera resolution
    image = image.resize(size, Image.BICUBIC)

    image.save(filename, 'JPEG')
Ejemplo n.º 15
0
def main():
    with Lepton() as l:
        # get image
        img, _ = l.capture()
        # extend contrast
        cv2.normalize(img, img, 0, 65535, cv2.NORM_MINMAX)
        # fit data into 8 bits
        np.right_shift(img, 8, img)
        # conver np array to uint8 type
        img = np.uint8(img)
        # create an output image
        cv2.imwrite("out.jpg", img)
Ejemplo n.º 16
0
 def _lept_snap(self):
     """
     takes the image
     """
     print('taking image')
     with Lepton() as l:
         raw, _ = l.capture()
     cv2.normalize(raw, raw, 0, 65535, cv2.NORM_MINMAX)
     np.right_shift(raw, 8, raw)
     raw = np.uint8(raw)
     adj = cv2.applyColorMap(raw, self.colormap)
     return adj
Ejemplo n.º 17
0
def thermal_image(event, x, y, flags, param):
    global i
    if event == cv2.EVENT_LBUTTONUP:
        with Lepton() as l:
            a, _ = l.capture()
            cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
            np.right_shift(a, 8, a)
            thermal_image = np.uint8(a)
            filename = './' + str(i) + '.jpg'
            cv2.imshow('Thermal image', thermal_image)
            cv2.imwrite(filename, thermal_image)
            i += 1
Ejemplo n.º 18
0
def thermo(path, file_name, format):

    with Lepton() as l:
        a, _ = l.capture()
    # print(a)
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)  # extend contrast
    np.right_shift(a, 8, a)  # fit data into 8 bits

    cv2.imwrite(path + file_name + format, np.uint8(a))
    thermo = Thermo()
    thermo.name = file_name
    thermo.image = file_name + format
    thermo.save()
Ejemplo n.º 19
0
def main(flip_v=False, alpha=128, device="/dev/spidev0.0", numpics=1, freq=1):
    # 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 = (320, 240)
        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:
            start = time.time()
            time.sleep(0.2)  # give the overlay buffers a chance to initialize
            for i in range(1, numpics + 1):
                with Lepton(device) as l:
                    frame_ushort, frame_id = l.capture(lepton_buf)

                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))
                filename = "output_" + str(i) + ".jpg"
                cv2.imwrite(filename, lepton_buf)
                time.sleep(1 / freq)


#	print filename
        except Exception:
            traceback.print_exc()
        finally:
            time_spent = time.time() - start
            print "\n\tSUMMARY"
            print "================================"
            print "Time spent:\t\t" + str(time_spent)
            print "Photos taken:\t\t" + str(numpics)
            print "Adjusted frequency:\t" + str(float(numpics / time_spent))
            print "\n"
            camera.remove_overlay(o)
Ejemplo n.º 20
0
async def get_temp_a(runopts):
    """
  Gets treatment temperature with the Lepton thermal camera
  """
    if runopts.faket:
        return 24

    run = True
    while run:
        try:
            with Lepton("/dev/spidev0.1") as l:
                data, _ = l.capture(retry_limit=3)
            if l is not None:
                ##print(data[10:80]);
                Ts = NP.amax(data[6:60, :, 0]) / 100 - 273
                Tt = NP.amax(data[0:5, :, 0]) / 100 - 273
                mm = NP.where(data == NP.amax(data))

                Ts_lin = data[int(mm[0]), :, 0] / 100 - 273
                Ts2 = (Ts_lin[int(mm[1]) + 2] + Ts_lin[int(mm[1]) - 2]) / 2
                Ts3 = (Ts_lin[int(mm[1]) + 6] + Ts_lin[int(mm[1]) - 6]) / 2
                for line in data:
                    l = len(line)
                    if (l != 80):
                        print("error: should be 80 columns, but we got {}".
                              format(l))
                    elif Ts > 150:
                        print(
                            "Measured temperature is too high: {}".format(Ts))

                if runopts.save_therm:
                    curtime = datetime.datetime.now().strftime(
                        "%Y-%m-%d_%H%M%S.%f")
                    fname = "{}".format(curtime)
                    save_data(SAVEDIR_therm, data / 100.0 - 273, fname)

                time.sleep(0.050)
                run = False

        except Exception as e:
            print(e)
            print(
                "\nHardware error on the thermal camera. Lepton restarting...")
            gpio.output(35, gpio.HIGH)
            time.sleep(0.5)
            gpio.output(35, gpio.LOW)
            print("Lepton restart completed!\n\n")

    #print(Ts)
    return [Ts, Ts2, Ts3, Ts_lin, Tt, data]
Ejemplo n.º 21
0
def capture(flip_v=False, device="/dev/spidev0.1"):
    with Lepton(device) as l:
        data, _ = l.capture()

    minVal, maxVal, _, _ = cv2.minMaxLoc(data)
    resized_data = cv2.resize(data[:, :], (800, 480))
    _, _, minLoc, maxLoc = cv2.minMaxLoc(resized_data)

    # Detect leaf
    # resized_data     = detect_leaf(data)

    image = raw_to_8bit(resized_data)

    return (data, image, minVal, maxVal, minLoc, maxLoc)
Ejemplo n.º 22
0
def capture_ir(flip_v=False, device="/dev/spidev0.0"): # add the BB-SPIDEV0-00A0.dtbo for beaglebone green!
    with Lepton(device) as l:
        data, _ = l.capture()

    minVal, maxVal, _, _ = cv2.minMaxLoc(data)
    resized_data = cv2.resize(data[:,:], (800, 480))
    _, _, minLoc, maxLoc = cv2.minMaxLoc(resized_data)

    # Detect leaf
    # resized_data     = detect_leaf(data)

    image = raw_to_8bit(resized_data)

    return (data, image, minVal, maxVal, minLoc, maxLoc)
Ejemplo n.º 23
0
    def frames():
        

        # getImage = a.copy()
        # if not camera.isOpened():
        #     raise RuntimeError('Could not start camera.')

        while True:
            # read current frame
            
            with Lepton() as l:
                a,_ = l.capture()

            a = cv2.resize(a[:,:], (640, 480))
            # encode as a jpeg image and return it
            yield a#cv2.imencode('.jpg', img)[1].tobytes()
Ejemplo n.º 24
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((60, 80, 1), dtype=np.uint16)

    with picamera.PiCamera() as camera:
        camera.resolution = (320, 240)
        camera.framerate = 24
        camera.vflip = flip_v
        camera.hflip = True
        camera.start_preview()
        camera.crop = (0.25, 0.25, 0.5, 0.5)
        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,
                               hflip=True)
        time.sleep(2)
        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 KeyboardInterrupt:
            print "hello"
            traceback.print_exc()
        finally:
            camera.remove_overlay(o)
Ejemplo n.º 25
0
def capture(
    flip_v=False,
    device="/dev/spidev0.0"
):  # update for the BBG and /boot/uEnv.txt should show BB-SPIDEV0-00A0.dtbo for overlays!
    with Lepton(device) as l:
        data, _ = l.capture()

    minVal, maxVal, _, _ = cv2.minMaxLoc(data)
    resized_data = cv2.resize(data[:, :], (800, 480))
    _, _, minLoc, maxLoc = cv2.minMaxLoc(resized_data)

    # Detect leaf
    # resized_data     = detect_leaf(data)

    image = raw_to_8bit(resized_data)

    return (data, image, minVal, maxVal, minLoc, maxLoc)
def capture(flip_v = False, device = "/dev/spidev0.1"):
  with Lepton(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, 16, a)

  '''
  print np.max(a)
  print np.min(a)
  
  return np.uint16(a)
  '''
Ejemplo n.º 27
0
def CaptureImage():
    HPix = 80  # Image resolution in the the horizontal direction
    VPix = 60  # Image resolution in the the vertical direction

    # Code for capturing thermal image from FLIR Lepton sensor
    with Lepton() as l:
        a, _ = l.capture()

    # extend contrast
    cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)

    # fit data into 8 bits
    np.right_shift(a, 8, a)

    # reshape data
    b = np.reshape(a, (VPix, HPix))
    return b
Ejemplo n.º 28
0
def capture(flip_v = False, device = "/dev/spidev0.0"):
  threading.Timer(5,capture).start();
  with Lepton(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)
  image_captured = np.uint8(a)z

  pub=rospy.Publisher("chatter", Image , queue_size=10)
  rospy.init_node("talker", anonymous=True)
  rate = rospy.Rate(2)

  birdge=CvBridge();
  cv_image = birdge.cv2_to_imgmsg(image_captured, 'passthrough' );

  pub.publish(cv_image)
  rate.sleep()
Ejemplo n.º 29
0
    def capture(self):
        with Lepton("/dev/spidev0.0") as l:
            lepton_buf = np.zeros((60, 80, 1), dtype=np.uint16)
            last_nr = 0
            #print "Getting Image"
            _, nr = l.capture(lepton_buf)
            print "got image"
            if nr != self.last_nr:
                self.last_nr = nr
                cv2.normalize(lepton_buf, lepton_buf, 0, 65535,
                              cv2.NORM_MINMAX)
                np.right_shift(lepton_buf, 8, lepton_buf)
                lepton_buf = np.uint8(lepton_buf)
                finalImage = []

                for x in lepton_buf:
                    for y in x:
                        for z in y:
                            finalImage.append(z)

                self._receivedImage.publish(finalImage)
Ejemplo n.º 30
0
def capture_video():
    with Lepton("/dev/spidev0.0") as l:
        #a = np.zeros((240, 320, 3), dtype=np.uint8)
        lepton_buf = np.zeros((60, 80, 1), dtype=np.uint16)

        last_nr = 0

        while True:
            time.sleep(.1)
            _, 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
            resizedImage = cv2.resize(lepton_buf, (800, 600))
            cv2.imshow('image', np.uint8(
                resizedImage))  #just overwriting the saved file repeatedly
            cv2.waitKey(1)