I am running Ubuntu 18.04 on the host and Ubuntu 20.04 inside LXC container. My goal is to run ROS2 (which requires Ubuntu 20.04) inside an LXC container, then use it to connect to two dynamixel servo motors and a USB Logitech webcam. I have also installed miniconda inside the container so that I can install OpenCV and dlib. I am also using conda virtual environment inside the container.
All the mentioned software works fine. Now I need to access the webcam with OpenCV, I use this command for testing
python -c "import cv2;print(cv2.VideoCapture(0).isOpened())"
which returns True
on host but returns
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
False
from inside the container.
So far I tried:
lxc config device add rosfoxy video0 unix-char path=/dev/video0
with video0
, video1
and video2
and still getting the same error.lxc config device add rosfoxy logitech usb vendorid=046d productid=082b
resulted in
Device logitech added to rosfoxy
, but still, same error.lxc profile device add ros logitech usb vendorid=046d productid=082b
which results in
Device logitech added to ros
. When testing I get the same error.glxgears
and glxinfo
on host, both works fine. However, when testing them from inside the LXC container it works fine but with this error first:libGL error: MESA-LOADER: failed to retrieve device information
libGL error: Version 4 or later of flush extension not found
libGL error: failed to load driver: i915
libGL error: failed to open /dev/dri/card0: No such file or directory
libGL error: failed to load driver: i965
3073 frames in 5.0 seconds = 614.256 FPS
5238 frames in 5.0 seconds = 1047.546 FPS
3766 frames in 5.0 seconds = 753.186 FPS
4214 frames in 5.0 seconds = 842.731 FPS
4926 frames in 5.0 seconds = 985.092 FPS
6007 frames in 5.0 seconds = 1201.399 FPS
5694 frames in 5.0 seconds = 1138.660 FPS
guvcview
on host, works fine. But on container, it doesn't work, it gives:V4L2_CORE: ERROR opening V4L2 interface for /dev/video2
V4L2_CORE: ERROR opening V4L2 interface for /dev/video3
V4L2_CORE: ERROR opening V4L2 interface for /dev/video0
V4L2_CORE: ERROR opening V4L2 interface for /dev/video1
GUVCVIEW: version 2.0.6
GUVCVIEW: couldn't open /home/ubuntu//.config/guvcview2/video0 for read: No such file or directory
V4L2_CORE: ERROR opening V4L interface: Permission denied
GUVCVIEW (1): Guvcview error
no video device found
(guvcview:1526): dbind-WARNING **: 19:29:55.201: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-EhmzLUeJ8h: Connection refused
(guvcview:1526): Gtk-WARNING **: 19:29:55.307: Theme parsing error: <data>:1:17: not a number
(guvcview:1526): Gtk-WARNING **: 19:29:55.307: Theme parsing error: <data>:1:31: Using Pango syntax for the font: style property is deprecated; please use CSS syntax
(guvcview:1526): Gtk-WARNING **: 19:29:55.307: Theme parsing error: <data>:1:17: not a number
(guvcview:1526): Gtk-WARNING **: 19:29:55.307: Theme parsing error: <data>:1:32: Using Pango syntax for the font: style property is deprecated; please use CSS syntax
Would you advise what to do?
UPDATE 1:
Tried lxc config device add rosfoxy video0 unix-char path=/dev/video0 gid=1000
but it doesn't seem to work.
From inside the container I them tried
(base) ubuntu@rosfoxy:~$ v4l2-ctl --all
Failed to open /dev/video0: Permission denied
But when I added sudo
I got:
(base) ubuntu@rosfoxy:~$ sudo v4l2-ctl --all
Driver Info:
Driver name : uvcvideo
Card type : Webcam C170: Webcam C170
Bus info : usb-0000:00:14.0-1
Driver version : 5.4.86
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
...
Which seems to me that the webcam is detected!
but I still get
(py38) ubuntu@rosfoxy:~$ python -c "import cv2;print(cv2.VideoCapture(0).isOpened())"
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
False
UPDATE 2:
I should have issued first lxc config device remove rosfoxy video0
then lxc config device add rosfoxy video0 unix-char path=/dev/video0 gid=1000
Thanks to Simos https://discuss.linuxcontainers.org/t/cant-open-camera-by-index-on-lxc-container/10452/8
These two commands are the answer to my question:
First lxc config device remove rosfoxy video0
then lxc config device add rosfoxy video0 unix-char path=/dev/video0 gid=1000
Thanks to Simos https://discuss.linuxcontainers.org/t/cant-open-camera-by-index-on-lxc-container/10452/8