OpenCV output on V4l2

2020-07-13 09:49发布

问题:

I wanted to know if I can use "opencv" to write on a v4l2 device. I would take a picture, apply small changes with the features of opencv, and then send it on a v4l2 device.

I searched on the web, but there are a lot of examples on how to read from a V4L2 device, but I found nothing about writing on v4l2.

can someone help me?

回答1:

The question is 8 month old, but if you still need an answer (I suppose your OS is Linux):

  1. Install v4l2 loopback module

    1.1. Load and configure it linux: i.e. modprobe.conf: options v4l2loopback video_nr=22,23

  2. Use such C++/OpenCV code: gist

    2.1. Setup device using ioctl() call

    2.2. Write raw RGB data to this device (i.e. /dev/video23)

    2.3. Use it as regular v4l2 device (i.e. webcam or vlc v4l2:///dev/video23)

more: You can use ffmpeg with v4l2 loopback: ffmpeg -f x11grab -r 12 -s 1920x1080 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 -vf 'scale=800:600' /dev/video22



标签: opencv v4l2