c - 使用 Nucleo-f401re 板从 Lepton FLIR 相机获取连续流

标签 c microcontroller stm32 flir nucleo

我将 Flir Lepton 相机连接到了我的主板上,并且借助 ThermalView 程序(源代码:https://github.com/groupgets/LeptonModule/tree/master/software/ThermalView),我尝试获得连续的图像流。 我在我的板上编译并下载了以下代码:

    int main(void)
{

  //HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  SystemClock_Config();

  leptonEnd();
  // LEPTON VDD OFF
  HAL_Delay(1000);
  // LEPTON VDD ON
  HAL_Delay(185);

  LeptonConfigure_I2C(); 

  while(1)
  {
    LeptonReadFrame();
    frameToPc(); 
  }
}

// Output image buffer to USART2
void frameToPc()
{
  static uint8_t frameSkipper = 0;

  uint8_t timeStamp = (HAL_GetTick() - last_frame_millis); // calculate time passed since last been here

  last_frame_millis = HAL_GetTick();



  if(frameSkipper==4)
  {
    //PSEDO//
    //IMGtoRGB();

    ////////
    uint8_t thermalView_header[] = {0xDE,0xAD,0xBE,0xEF}; // 4-byte header for ThermalView application
    HAL_Delay(1000);
    HAL_UART_Transmit_DMA(&huart2, &thermalView_header[0], 4); // print header

    while(huart2.gState != HAL_UART_STATE_READY); // wait for transmission to complete

    HAL_UART_Transmit_DMA(&huart2, &IMG[0], LEPTON_IMG_SIZE_BYTES);

    frameSkipper = 0;
  }

  frameSkipper++;
}uint8_t LeptonReadFrame()
{  
  uint8_t i, frame_number, frame_complete=0;
  uint16_t bad_frame_counter=0;

  while(!frame_complete)
  {
    leptonBegin();

    HAL_SPI_Receive(&hspi1, &FramePacket[0], LEPTON_PACKET_LENGTH, 1000);  // READ LINE    

    leptonEnd();

    //HAL_UART_Transmit(&huart2,  &FramePacket[0], LEPTON_PACKET_LENGTH, 1000); // PRINT LINE

    if( (FramePacket[0] & 0x0f) != 0x0f ) // not discard frame
    {
       frame_number = FramePacket[1];

       if(frame_number < 60) // valid frame
       {
         bad_frame_counter = 0; 

         for(i= 0; i<LEPTON_PACKET_CONTENT_LENGTH; i++)
         {
           IMG[frame_number*LEPTON_PACKET_CONTENT_LENGTH+i] = FramePacket[i+4]; // copy line into IMG buffer, ignoring ID and CRC
         }
       }
       else
       {
         bad_frame_counter++;
       }

       if(frame_number == 59)
       {
          frame_complete = 1;
       }

       if(bad_frame_counter>1000) // 800 lines = 5 bad frames = resync needed
       {
          bad_frame_counter = 0;
          HAL_Delay(185);  // CS is already disabled so the delay is enougth
       }
    }
  }
  return 1;
}

我已成功获取流,但我必须在每个帧之间设置 1 秒的延迟,并且必须在发送到计算机的 2 帧之间跳过帧。如果您注意到代码中存在阻止提高帧速率的错误,请告诉我。

最佳答案

您使用的是 Lepton 2 还是 Lepton 3? Lepton 3 不仅需要采集“帧”,还需要采集 4 个“段”。Lepton 模块还输出 2 个空白屏幕。本文档的更多详细信息:

http://www.flir.com/uploadedFiles/OEM/Products/LWIR-Cameras/Lepton/Lepton-vs-Lepton-3-App-Note.pdf

比较 Lepton 2X 系列 (80x60) 分辨率和 Lepton 3 (160x120) 分辨率。 Lepton 和 Lepton 3 VoSPI 接口(interface)之间的四个最显着的区别是: 1) 在 Lepton 上,从各个数据包重建视频帧需要主机从每个数据包 header 中解码数据包编号。在 Lepton 3 上,主机必须解码数据包编号和段编号。 2) Lepton 3 的每帧总位数是 Lepton 的 4 倍。因此,最小 SPI 时钟速率快了 4 倍。两个模块的最大 SPI 时钟速率均为 20 MHz。 3) Lepton 和 Lepton 3 都提供了在 GPIO3 上输出同步脉冲的选项。 Lepton 3 上的脉冲频率比 Lepton 上高 4 倍。对于 Lepton 3,同步脉冲表示下一个可用段何时可用,而对于 Lepton 则表示下一个可用帧何时可用。 4) 当在 Lepton 中启用遥测时,会产生三个额外的视频线(每帧总共 63 个数据包)。当 Lepton 3 中启用遥测功能时,每个段会产生 1 个额外数据包,总共 2 条额外视频线路。

我正在尝试让 lepton 3 在我的 stm32f746g-discovery 板上工作。

关于c - 使用 Nucleo-f401re 板从 Lepton FLIR 相机获取连续流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41467204/

相关文章:

c - 这是C中的定义吗?

c - Fletcher 校验和从 32 位重制为 8 位

c - Arduino串口阅读

debugging - STM32CubeProgrammer : Problem occurred while trying to connect 上的 ST-LINK 错误

c - STM32 USB CDC 长包接收

c++ - 如何在一定数量的小数位后截断 float (不四舍五入)?

c - C 中的身份验证(从给定文件读取和检查)

c++ - 如何直接操作终端输出缓冲区

c - 在功能有限的微 Controller 上加载和运行小脚本?

c - STM32 VCP驱动——只有优化后指针才会失效