从 h264 流解码帧到 OpenCV Mat

Decode frame from h264 stream to OpenCV Mat

产品:Bebop 产品版本:软件版本v2.0.29 SDK 版本:ARSDK3_version_3_14_0 使用 libARController:是 SDK平台:UNIX 可通过官方应用重现:否

我一直在尝试使用 Ubuntu 18.04 将 ARCONTROLLER_Frame_t 从 ARSDK 3 转换为 OpenCV 图像,最初,提供的示例程序使用 MPlayer 打开一个 FIFO,其中程序写入了它从无人机接收到的所有帧,我设法在 运行 时使用 ffmpeg 从所述流中获取图像。我也试图给 OpenCV 说文件作为 VideoCapture 的源,它工作但被严重延迟。我目前正在尝试逐帧提供 OpenCV。

This is a screenshot ARCONTROLLER_Frame_t 的定义,文档对一切如何工作非常模糊。

我目前得到以下图像: Screen shot of the image obtained

我之前用它来尝试解码它,假设它是 RGB 格式,这张图像会对与相机的交互做出反应,所以我认为它是正确的数据:

void rawToMat(Mat &destImage, ARCONTROLLER_Frame_t &sourceImage) {
  if (sourceImage.used == 0) {
    return;
  }
  uchar *pointerImage = destImage.ptr(0);

  for (int i = 0; i < 480 * 856; i++) {
    pointerImage[3 * i] = sourceImage.data[3 * i + 2];
    pointerImage[3 * i + 1] = sourceImage.data[3 * i + 1];
    pointerImage[3 * i + 2] = sourceImage.data[3 * i];
  }
}

但我发现这提供了相同的输出:

ARCONTROLLER_Frame_t newFrame = getCurrentFrame();
Mat currentImage = Mat(480, 856, CV_8UC3, newFrame.data);

有人知道从中获取实际图像的方法吗?

ARCONTROLLER_Frame_t 不包含 RGB 图像;它包含一个 H.264 帧,必须使用 H.264 解码器将其转换为 RGB 图像(例如,请参阅 Parrot 开发者论坛上的 this response)。

Parrot 的这个旧示例代码演示了如何使用 ffmpeg/libav 库解码帧(这里 post 太长了):https://github.com/Parrot-Developers/Samples/tree/59b6ba5cdc268fb6932d228db7b9169d9b69384c/Unix/BebopDroneDecodeStream