7

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 Answers1

10

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

The Architect
  • 665
  • 9
  • 22
  • 1
    How do you write raw RGB to the device? – Saren Tasciyan Apr 18 '20 at 22:02
  • @Genom (and users who find this in the future) - in the gist, the output device is initialized starting around line 69 and then written to at the end of the while loop. Not exactly what you wanted. :D The short answer is that you essentially write to the loopback device as in a regular file. http://wonderingcode.blogspot.com/2017/05/loopback-with-python-and-opencv.html helps in python. – dannysauer May 13 '20 at 23:33