使用OpenCV VideoWriter保存灰度图像时出现Gstreamer错误



我可能遗漏了一些非常明显的东西,但我似乎无法做到这一点。我正在从灰度相机读取帧,然后我想通过OpenCV VideoWriter中的gstreamer将其编码为H265。

这是我的gstreamer管道:

gst_out =('appsrc caps=video/x-raw,format=GRAY8,width=1280,height=800,framerate=30/1 ! '
'videoconvert ! omxh265enc ! video/x-h265, stream-format=byte-stream ! '
'h265parse ! filesink location=test.h265 ')
writer= cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 30, (1280, 800), True)

但是当我尝试在其中写入帧时,我会得到错误

[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1629) writeFrame OpenCV | GStreamer warning: cvWriteFrame() needs images with depth = IPL_DEPTH_8U and nChannels = 3.

我不理解,因为它应该接受GRAY8格式,并且我已经验证了该帧只是一个通道。如果我将帧转换为BGR,它会起作用,但这不是我想要的,因为我只需要保存灰度图像,而且我也不明白为什么当我在管道中指定GRAY8时,它会接受BGR帧。

如有任何帮助,我们将不胜感激。

您正在构建cv::VideoWriterisColor设置为true:

VideoWriter (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)

这就是为什么OpenCV希望使用彩色图像(具有3个通道(而不是灰度图像。

(注意:这已经在评论中讨论过了,我只是为了结束问题而写下它作为答案(

最新更新