使用OpenCV写入虚拟视频流

时间:2016-10-03 18:08:00

标签: c++ opencv v4l2 v4l v4l2loopback

我使用OpenCV和v4l2loopback库来模拟视频设备:

modprobe v4l2loopback devices=2

然后我检查一下我的设备:

root@blah:~$ v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000):
        /dev/video1

Dummy video device (0x0001) (platform:v4l2loopback-001):
        /dev/video2

XI100DUSB-SDI (usb-0000:00:14.0-9):
        /dev/video0

video0是我的实际相机,我从中获取帧,然后我打算通过OpenCV处理它们并将其写入video2(我相信这是一个接收器)。

以下是我尝试这样做的方法:

  int width = 320;
  int height = 240;
  Mat frame(height, width, CVX_8UC3, Scalar(0, 0, 255));
  cvtColor(frame, frame, CVX_BGR2YUV);

  int fourcc = CVX_FOURCC('Y', 'U', 'Y', '2');
  cout << "Trying to open video for write: " << FLAGS_out_video << endl;
  VideoWriter outputVideo = VideoWriter(
      FLAGS_out_video, fourcc, 30, frame.size());
  if (!outputVideo.isOpened()) {
    cerr << "Could not open the output video for write: " << FLAGS_out_video
         << endl;
  }

据我所知,视频输出格式应为YUYV(在OpenCV中等于YUY2)。如果我错了,请纠正我。在我的代码中,我还没有写入outputVideo任何内容,只是尝试打开它进行写入,但由于某种原因我不断获得outputVideo.isOpened()==false,输出中没有其他错误/信息:< / p>

root@blah:~$ main --uid='' --in_video='0' --out_video='/dev/video2'
Trying to open video for write: /dev/video2
Could not open the output video for write: /dev/video2

我很感激有关如何调试/解决此问题的任何建议或帮助。提前谢谢!

0 个答案:

没有答案