Lepton.py
def capture(self, data_buffer = None, log_time = False, debug_print = True, retry_reset = True):
    """Capture a frame of data.
    Captures 80x60 uint16 array of non-normalized (raw 12-bit) data. Returns that frame and a frame_id (which
    is currently just the sum of all pixels). The Lepton will return multiple, identical frames at a rate of up
    to ~27 Hz, with unique frames at only ~9 Hz, so the frame_id can help you from doing additional work
    processing duplicate frames.

    Args:
      data_buffer (numpy.ndarray): Optional. If specified, should be ``(60,80,1)`` with `dtype`=``numpy.uint16``.

    Returns:
      tuple consisting of (data_buffer, frame_id)
    """
    start = time.time()
    #print(start)
    if data_buffer is None:
      data_buffer = np.ndarray((Lepton.ROWS, Lepton.COLS, 1), dtype=np.uint16)
    elif data_buffer.ndim < 2 or data_buffer.shape[0] < Lepton.ROWS or data_buffer.shape[1] < Lepton.COLS or data_buffer.itemsize < 2:
      raise Exception("Provided input array not large enough")
    
    self.__handle = open(self.__spi_dev, "wb+", buffering=0)
    #print(self.__handle)
    ioctl(self.__handle, SPI_IOC_RD_MODE, struct.pack("=B", Lepton.MODE))
    ioctl(self.__handle, SPI_IOC_WR_MODE, struct.pack("=B", Lepton.MODE))
    ioctl(self.__handle, SPI_IOC_RD_BITS_PER_WORD, struct.pack("=B", Lepton.BITS))
    ioctl(self.__handle, SPI_IOC_WR_BITS_PER_WORD, struct.pack("=B", Lepton.BITS))
    ioctl(self.__handle, SPI_IOC_RD_MAX_SPEED_HZ, struct.pack("=I", Lepton.SPEED))
    ioctl(self.__handle, SPI_IOC_WR_MAX_SPEED_HZ, struct.pack("=I", Lepton.SPEED))
    
    while True:
      Lepton.capture_segment(self.__handle, self.__xmit_buf, self.__msg_size, self.__capture_buf[0])
      if retry_reset and (self.__capture_buf[20, 0] & 0xFF0F) != 0x1400: # make sure that this is a well-formed frame, should find line 20 here
        # Leave chip select deasserted for at least 185 ms to reset
        if debug_print:
          print("Garbage frame number reset waiting...")
        time.sleep(0.185)
      else:
        break

    self.__capture_buf.byteswap(True)
    data_buffer[:,:] = self.__capture_buf[:,2:]
    end = time.time()

    if debug_print:
      print("---")
      for i in range(Lepton.ROWS):
        fid = self.__capture_buf[i, 0, 0]
        crc = self.__capture_buf[i, 1, 0]
        fnum = fid & 0xFFF
        print("0x{0:04x} 0x{1:04x} : Row {2:2} : crc={1}".format(fid, crc, fnum))
      print("---")

    if log_time:
      print("frame processed int {0}s, {1}hz".format(end-start, 1.0/(end-start)))

    # TODO: turn on telemetry to get real frame id, sum on this array is fast enough though (< 500us)
    return data_buffer, data_buffer.sum()
Capture a frame of data.
    Captures 80x60 uint16 array of non-normalized (raw 12-bit) data. Returns that frame and a frame_id (which
    is currently just the sum of all pixels). The Lepton will return multiple, identical frames at a rate of up
    to ~27 Hz, with unique frames at only ~9 Hz, so the frame_id can help you from doing additional work
    processing duplicate frames.

    Args:
      data_buffer (numpy.ndarray): Optional. If specified, should be ``(60,80,1)`` with `dtype`=``numpy.uint16``.

    Returns:
      tuple consisting of (data_buffer, frame_id)
    
Capture a frame of data.
Captures 80x60 uint16 array of non-normalized (raw 12-bit) data. Returns that frame and a frame_id (which
is currently just the sum of all pixels). The Lepton will return multiple, identical frames at a rate of up
to ~27 Hz, with unique frames at only ~9 Hz, so the frame_id can help you from doing additional work
processing duplicate frames.
Capture a frame of data . Captures 80x60 uint16 array of non - normalized ( raw 12 - bit ) data . Returns that frame and a frame_id ( which is currently just the sum of all pixels ) . The Lepton will return multiple identical frames at a rate of up to ~27 Hz with unique frames at only ~9 Hz so the frame_id can help you from doing additional work processing duplicate frames .
def capture(self, data_buffer = None, log_time = False, debug_print = True, retry_reset = True):
    start = time.time()
    if data_buffer is None:
      data_buffer = np.ndarray((Lepton.ROWS, Lepton.COLS, 1), dtype=np.uint16)
    elif data_buffer.ndim < 2 or data_buffer.shape[0] < Lepton.ROWS or data_buffer.shape[1] < Lepton.COLS or data_buffer.itemsize < 2:
      raise Exception("Provided input array not large enough")
    self.__handle = open(self.__spi_dev, "wb+", buffering=0)
    ioctl(self.__handle, SPI_IOC_RD_MODE, struct.pack("=B", Lepton.MODE))
    ioctl(self.__handle, SPI_IOC_WR_MODE, struct.pack("=B", Lepton.MODE))
    ioctl(self.__handle, SPI_IOC_RD_BITS_PER_WORD, struct.pack("=B", Lepton.BITS))
    ioctl(self.__handle, SPI_IOC_WR_BITS_PER_WORD, struct.pack("=B", Lepton.BITS))
    ioctl(self.__handle, SPI_IOC_RD_MAX_SPEED_HZ, struct.pack("=I", Lepton.SPEED))
    ioctl(self.__handle, SPI_IOC_WR_MAX_SPEED_HZ, struct.pack("=I", Lepton.SPEED))
    while True:
      Lepton.capture_segment(self.__handle, self.__xmit_buf, self.__msg_size, self.__capture_buf[0])
      if retry_reset and (self.__capture_buf[20, 0] & 0xFF0F) != 0x1400: 
        if debug_print:
          print("Garbage frame number reset waiting...")
        time.sleep(0.185)
      else:
        break
    self.__capture_buf.byteswap(True)
    data_buffer[:,:] = self.__capture_buf[:,2:]
    end = time.time()
    if debug_print:
      print("---")
      for i in range(Lepton.ROWS):
        fid = self.__capture_buf[i, 0, 0]
        crc = self.__capture_buf[i, 1, 0]
        fnum = fid & 0xFFF
        print("0x{0:04x} 0x{1:04x} : Row {2:2} : crc={1}".format(fid, crc, fnum))
      print("---")
    if log_time:
      print("frame processed int {0}s, {1}hz".format(end-start, 1.0/(end-start)))
    return data_buffer, data_buffer.sum()
def capture ( self , data_buffer = None , log_time = False , debug_print = True , retry_reset = True ) : start = time . time ( ) if data_buffer is None : data_buffer = np . ndarray ( ( Lepton . ROWS , Lepton . COLS , 1 ) , dtype = np . uint16 ) elif data_buffer . ndim < 2 or data_buffer . shape [ 0 ] < Lepton . ROWS or data_buffer . shape [ 1 ] < Lepton . COLS or data_buffer . itemsize < 2 : raise Exception ( "Provided input array not large enough" ) self . __handle = open ( self . __spi_dev , "wb+" , buffering = 0 ) ioctl ( self . __handle , SPI_IOC_RD_MODE , struct . pack ( "=B" , Lepton . MODE ) ) ioctl ( self . __handle , SPI_IOC_WR_MODE , struct . pack ( "=B" , Lepton . MODE ) ) ioctl ( self . __handle , SPI_IOC_RD_BITS_PER_WORD , struct . pack ( "=B" , Lepton . BITS ) ) ioctl ( self . __handle , SPI_IOC_WR_BITS_PER_WORD , struct . pack ( "=B" , Lepton . BITS ) ) ioctl ( self . __handle , SPI_IOC_RD_MAX_SPEED_HZ , struct . pack ( "=I" , Lepton . SPEED ) ) ioctl ( self . __handle , SPI_IOC_WR_MAX_SPEED_HZ , struct . pack ( "=I" , Lepton . SPEED ) ) while True : Lepton . capture_segment ( self . __handle , self . __xmit_buf , self . __msg_size , self . __capture_buf [ 0 ] ) if retry_reset and ( self . __capture_buf [ 20 , 0 ] & 0xFF0F ) != 0x1400 : if debug_print : print ( "Garbage frame number reset waiting..." ) time . sleep ( 0.185 ) else : break self . __capture_buf . byteswap ( True ) data_buffer [ : , : ] = self . __capture_buf [ : , 2 : ] end = time . time ( ) if debug_print : print ( "---" ) for i in range ( Lepton . ROWS ) : fid = self . __capture_buf [ i , 0 , 0 ] crc = self . __capture_buf [ i , 1 , 0 ] fnum = fid & 0xFFF print ( "0x{0:04x} 0x{1:04x} : Row {2:2} : crc={1}" . format ( fid , crc , fnum ) ) print ( "---" ) if log_time : print ( "frame processed int {0}s, {1}hz" . format ( end - start , 1.0 / ( end - start ) ) ) return data_buffer , data_buffer . sum ( )
Capture a frame of data.
Capture a frame of data .
"""Capture a frame of data.
    Captures 80x60 uint16 array of non-normalized (raw 12-bit) data. Returns that frame and a frame_id (which
    is currently just the sum of all pixels). The Lepton will return multiple, identical frames at a rate of up
    to ~27 Hz, with unique frames at only ~9 Hz, so the frame_id can help you from doing additional work
    processing duplicate frames.

    Args:
      data_buffer (numpy.ndarray): Optional. If specified, should be ``(60,80,1)`` with `dtype`=``numpy.uint16``.

    Returns:
      tuple consisting of (data_buffer, frame_id)
    """ #print(start) #print(self.__handle) # make sure that this is a well-formed frame, should find line 20 here # Leave chip select deasserted for at least 185 ms to reset # TODO: turn on telemetry to get real frame id, sum on this array is fast enough though (< 500us)
tuple consisting of (data_buffer, frame_id)
tuple consisting of ( data_buffer frame_id )
self
data_buffer
None
log_time
debug_print
retry_reset