ubuntu各种版本上测试usb摄像头(支持单目摄像头、乐视、realsense等)是否正常工作

2023-05-16

一.硬件要求:
①ubuntu20.04(ubuntu18.04的话,需要把下面出现的noetic改为melodic;ubuntu16.04的话,需要把下面出现的noetic改为kinetic;)
②ROS版本:noetic
③任意USB摄像头(我这里用的是乐视三合一体感摄像头)
二.安装使用

2.1 ubuntu20.04 ros为noetic版本

①下载usb_cam软件包

sudo apt install ros-noetic-usb-cam 
//(ubuntu18.04的话,需要把下面出现的noetic改为melodic;ubuntu16.04的话,需要把下面出现的noetic改为kinetic;)

在这里插入图片描述

②启动usb相机节点
A.查找摄像头接口

ls /dev/video*

这里可以先在插入usb摄像头的时候检查一下接口,然后拔出usb摄像头的时候再检查一下接口(看看少了哪些,少了的就是usb摄像头的)
在这里插入图片描述
很明显, /dev/video2 或者 /dev/video3 是我的摄像头usb接口号(好像ubuntu下摄像头是有两个号的,用任意一个就可以了);
B.在该路径下修改launch文件,换成你自己的摄像头接口
到达该路径:

cd /opt/ros/noetic/share/usb_cam/launch/

编辑该文件

sudo gedit usb_cam-test.launch

在这里插入图片描述
原本这里是 /dev/video0,将其改为/dev/video2在这里插入图片描述
保存后退出,然后运行:

roslaunch usb_cam usb_cam-test.launch

然后就可以运行摄像头了:
在这里插入图片描述

2.2 ubuntu18.04 ros为melodic版本

2.2.1 直接通过命令行安装usb-cam包(推荐,适合网络状态好的时候)

sudo apt install ros-melodic-usb-cam

如果网络不好,就无法安装,会报错让你sudo apt-get upgrade --fix-missing之类的,如果网络行,那么sudo apt install ros-melodic-usb-cam安装命令就会一次成功,如果不行,那就都没用…如果你是无法命令行安装,可以看我下面的教程,用源码安装;

命令行安装过程:

smile@smile-X3-S:~/app_install$ sudo apt install ros-melodic-usb-cam 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-hwe-5.4-headers-5.4.0-107 linux-hwe-5.4-headers-5.4.0-113
  linux-hwe-5.4-headers-5.4.0-121 linux-hwe-5.4-headers-5.4.0-122
  linux-hwe-5.4-headers-5.4.0-124 linux-hwe-5.4-headers-5.4.0-84
  python-rosdistro
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libv4l2rds0 ros-melodic-camera-calibration-parsers
  ros-melodic-camera-info-manager v4l-utils
The following NEW packages will be installed:
  libv4l2rds0 ros-melodic-camera-calibration-parsers
  ros-melodic-camera-info-manager ros-melodic-usb-cam v4l-utils
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 422 kB/583 kB of archives.
After this operation, 2,182 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.ustc.edu.cn/ubuntu bionic/main amd64 libv4l2rds0 amd64 1.14.2-1 [15.6 kB]
Get:2 https://mirrors.ustc.edu.cn/ubuntu bionic/universe amd64 v4l-utils amd64 1.14.2-1 [407 kB]
Fetched 422 kB in 3s (129 kB/s)    
Selecting previously unselected package libv4l2rds0:amd64.
(Reading database ... 369439 files and directories currently installed.)
Preparing to unpack .../libv4l2rds0_1.14.2-1_amd64.deb ...
Unpacking libv4l2rds0:amd64 (1.14.2-1) ...
Selecting previously unselected package v4l-utils.
Preparing to unpack .../v4l-utils_1.14.2-1_amd64.deb ...
Unpacking v4l-utils (1.14.2-1) ...
Selecting previously unselected package ros-melodic-camera-calibration-parsers.
Preparing to unpack .../ros-melodic-camera-calibration-parsers_1.11.13-0bionic.20220127.151909_amd64.deb ...
Unpacking ros-melodic-camera-calibration-parsers (1.11.13-0bionic.20220127.151909) ...
Selecting previously unselected package ros-melodic-camera-info-manager.
Preparing to unpack .../ros-melodic-camera-info-manager_1.11.13-0bionic.20220127.153034_amd64.deb ...
Unpacking ros-melodic-camera-info-manager (1.11.13-0bionic.20220127.153034) ...
Selecting previously unselected package ros-melodic-usb-cam.
Preparing to unpack .../ros-melodic-usb-cam_0.3.6-0bionic.20220127.153459_amd64.deb ...
Unpacking ros-melodic-usb-cam (0.3.6-0bionic.20220127.153459) ...
Setting up libv4l2rds0:amd64 (1.14.2-1) ...
Setting up v4l-utils (1.14.2-1) ...
Setting up ros-melodic-camera-calibration-parsers (1.11.13-0bionic.20220127.151909) ...
Setting up ros-melodic-camera-info-manager (1.11.13-0bionic.20220127.153034) ...
Setting up ros-melodic-usb-cam (0.3.6-0bionic.20220127.153459) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

2.2.1 通过源代码安装usb-cam包

创建一个文件夹(后面要在这个文件夹下编译源代码、安装程序包)

mkdir -p ~/app_install/catkin_ws/src

在这里插入图片描述
然后创建工作空间

cd ~/app_install/catkin_ws/
catkin_make

在这里插入图片描述在这里插入图片描述
然后source一下(告诉计算机你在这个路径下准备要编译包了,这一步是将创建的工作空间加入到环境路径中。):

source devel/setup.bash

过程如下

smile@smile-X3-S:~$ mkdir -p ~/app_install/catkin_ws/src
smile@smile-X3-S:~$ cd ~/app_install/catkin_ws/
smile@smile-X3-S:~/app_install/catkin_ws$ catkin_make
Base path: /home/smile/app_install/catkin_ws
Source space: /home/smile/app_install/catkin_ws/src
Build space: /home/smile/app_install/catkin_ws/build
Devel space: /home/smile/app_install/catkin_ws/devel
Install space: /home/smile/app_install/catkin_ws/install
Creating symlink "/home/smile/app_install/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/melodic/share/catkin/cmake/toplevel.cmake"
####
#### Running command: "cmake /home/smile/app_install/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/smile/app_install/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/smile/app_install/catkin_ws/install -G Unix Makefiles" in "/home/smile/app_install/catkin_ws/build"
####
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/smile/app_install/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/smile/app_install/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/smile/app_install/catkin_ws/build
####
#### Running command: "make -j16 -l16" in "/home/smile/app_install/catkin_ws/build"
####
smile@smile-X3-S:~/app_install/catkin_ws$ source devel/setup.bash
smile@smile-X3-S:~/app_install/catkin_ws$ 

在src目录下新建了一个程序包,$catkin_create_pkg usb_cam std_msgs rospy roscpp

cd src/
catkin_create_pkg usb_cam std_msgs rospy roscpp

在这里插入图片描述

然后需要编译一下,把它的工作空间加入到当前的工作空间下,source一下将工作空间加入到环境路径下。

cd ..
catkin_make
source devel/setup.bash

过程如下

smile@smile-X3-S:~/app_install/catkin_ws/src$ cd ..
smile@smile-X3-S:~/app_install/catkin_ws$ catkin_make
Base path: /home/smile/app_install/catkin_ws
Source space: /home/smile/app_install/catkin_ws/src
Build space: /home/smile/app_install/catkin_ws/build
Devel space: /home/smile/app_install/catkin_ws/devel
Install space: /home/smile/app_install/catkin_ws/install
####
#### Running command: "cmake /home/smile/app_install/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/smile/app_install/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/smile/app_install/catkin_ws/install -G Unix Makefiles" in "/home/smile/app_install/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/smile/app_install/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/smile/app_install/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/smile/app_install/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/smile/app_install/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - usb_cam
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'usb_cam'
-- ==> add_subdirectory(usb_cam)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/smile/app_install/catkin_ws/build
####
#### Running command: "make -j16 -l16" in "/home/smile/app_install/catkin_ws/build"
smile@smile-X3-S:~/app_install/catkin_ws$ 

进入工作目录并下载usb_cam包

git clone https://github.com/bosch-ros-pkg/usb_cam.git usb_cam
smile@smile-X3-S:~/app_install/catkin_ws$ ls
build  devel  src
smile@smile-X3-S:~/app_install/catkin_ws$ cd src
smile@smile-X3-S:~/app_install/catkin_ws/src$ git clone https://github.com/bosch-ros-pkg/usb_cam.git usb_cam
fatal: destination path 'usb_cam' already exists and is not an empty directory.

把之前新建的usb_cam删掉
在这里插入图片描述
然后在下载一下

smile@smile-X3-S:~/app_install/catkin_ws/src$ git clone https://github.com/bosch-ros-pkg/usb_cam.git usb_cam
Cloning into 'usb_cam'...
remote: Enumerating objects: 1481, done.
remote: Counting objects:   0% (1/307remote: Counting objects:   1% (4/307remote: Counting objects:   2% (7/307remote: Counting objects:   3% (10/30remote: Counting objects:   4% (13/30remote: Counting objects:   5% (16/30remote: Counting objects:   6% (19/30remote: Counting objects:   7% (22/30remote: Counting objects:   8% (25/30remote: Counting objects:   9% (28/30remote: Counting objects:  10% (31/30remote: Counting objects:  11% (34/30remote: Counting objects:  12% (37/30remote: Counting objects:  13% (40/30remote: Counting objects:  14% (43/30remote: Counting objects:  15% (47/30remote: Counting objects:  16% (50/30remote: Counting objects:  17% (53/30remote: Counting objects:  18% (56/30remote: Counting objects:  19% (59/30remote: Counting objects:  20% (62/30remote: Counting objects:  21% (65/30remote: Counting objects:  22% (68/30remote: Counting objects:  23% (71/30remote: Counting objects:  24% (74/30remote: Counting objects:  25% (77/30remote: Counting objects:  26% (80/30remote: Counting objects:  27% (83/30remote: Counting objects:  28% (86/30remote: Counting objects:  29% (90/30remote: Counting objects:  30% (93/30remote: Counting objects:  31% (96/30remote: Counting objects:  32% (99/30remote: Counting objects:  33% (102/3remote: Counting objects:  34% (105/3remote: Counting objects:  35% (108/3remote: Counting objects:  36% (111/3remote: Counting objects:  37% (114/3remote: Counting objects:  38% (117/3remote: Counting objects:  39% (120/3remote: Counting objects:  40% (123/3remote: Counting objects:  41% (126/3remote: Counting objects:  42% (129/3remote: Counting objects:  43% (133/3remote: Counting objects:  44% (136/3remote: Counting objects:  45% (139/3remote: Counting objects:  46% (142/3remote: Counting objects:  47% (145/3remote: Counting objects:  48% (148/3remote: Counting objects:  49% (151/3remote: Counting objects:  50% (154/3remote: Counting objects:  51% (157/3remote: Counting objects:  52% (160/3remote: Counting objects:  53% (163/3remote: Counting objects:  54% (166/3remote: Counting objects:  55% (169/3remote: Counting objects:  56% (172/3remote: Counting objects:  57% (175/3remote: Counting objects:  58% (179/3remote: Counting objects:  59% (182/3remote: Counting objects:  60% (185/3remote: Counting objects:  61% (188/3remote: Counting objects:  62% (191/3remote: Counting objects:  63% (194/3remote: Counting objects:  64% (197/3remote: Counting objects:  65% (200/3remote: Counting objects:  66% (203/3remote: Counting objects:  67% (206/3remote: Counting objects:  68% (209/3remote: Counting objects:  69% (212/3remote: Counting objects:  70% (215/3remote: Counting objects:  71% (218/3remote: Counting objects:  72% (222/3remote: Counting objects:  73% (225/3remote: Counting objects:  74% (228/3remote: Counting objects:  75% (231/3remote: Counting objects:  76% (234/3remote: Counting objects:  77% (237/3remote: Counting objects:  78% (240/3remote: Counting objects:  79% (243/3remote: Counting objects:  80% (246/3remote: Counting objects:  81% (249/3remote: Counting objects:  82% (252/3remote: Counting objects:  83% (255/3remote: Counting objects:  84% (258/3remote: Counting objects:  85% (261/3remote: Counting objects:  86% (265/3remote: Counting objects:  87% (268/3remote: Counting objects:  88% (271/3remote: Counting objects:  89% (274/3remote: Counting objects:  90% (277/3remote: Counting objects:  91% (280/3remote: Counting objects:  92% (283/3remote: Counting objects:  93% (286/3remote: Counting objects:  94% (289/3remote: Counting objects:  95% (292/3remote: Counting objects:  96% (295/3remote: Counting objects:  97% (298/3remote: Counting objects:  98% (301/3remote: Counting objects:  99% (304/3remote: Counting objects: 100% (307/3remote: Counting objects: 100% (307/307), done.
remote: Compressing objects:   0% (1/remote: Compressing objects:   1% (2/remote: Compressing objects:   2% (4/remote: Compressing objects:   3% (5/remote: Compressing objects:   4% (7/remote: Compressing objects:   5% (8/remote: Compressing objects:   6% (10remote: Compressing objects:   7% (12remote: Compressing objects:   8% (13remote: Compressing objects:   9% (15remote: Compressing objects:  10% (16remote: Compressing objects:  11% (18remote: Compressing objects:  12% (19remote: Compressing objects:  13% (21remote: Compressing objects:  14% (23remote: Compressing objects:  15% (24remote: Compressing objects:  16% (26remote: Compressing objects:  17% (27remote: Compressing objects:  18% (29remote: Compressing objects:  19% (31remote: Compressing objects:  20% (32remote: Compressing objects:  21% (34remote: Compressing objects:  22% (35remote: Compressing objects:  23% (37remote: Compressing objects:  24% (38remote: Compressing objects:  25% (40remote: Compressing objects:  26% (42remote: Compressing objects:  27% (43remote: Compressing objects:  28% (45remote: Compressing objects:  29% (46remote: Compressing objects:  30% (48remote: Compressing objects:  31% (49remote: Compressing objects:  32% (51remote: Compressing objects:  33% (53remote: Compressing objects:  34% (54remote: Compressing objects:  35% (56remote: Compressing objects:  36% (57remote: Compressing objects:  37% (59remote: Compressing objects:  38% (61remote: Compressing objects:  39% (62remote: Compressing objects:  40% (64remote: Compressing objects:  41% (65remote: Compressing objects:  42% (67remote: Compressing objects:  43% (68remote: Compressing objects:  44% (70remote: Compressing objects:  45% (72remote: Compressing objects:  46% (73remote: Compressing objects:  47% (75remote: Compressing objects:  48% (76remote: Compressing objects:  49% (78remote: Compressing objects:  50% (79remote: Compressing objects:  51% (81remote: Compressing objects:  52% (83remote: Compressing objects:  53% (84remote: Compressing objects:  54% (86remote: Compressing objects:  55% (87remote: Compressing objects:  56% (89remote: Compressing objects:  57% (91remote: Compressing objects:  58% (92remote: Compressing objects:  59% (94remote: Compressing objects:  60% (95remote: Compressing objects:  61% (97remote: Compressing objects:  62% (98remote: Compressing objects:  63% (10remote: Compressing objects:  64% (10remote: Compressing objects:  65% (10remote: Compressing objects:  66% (10remote: Compressing objects:  67% (10remote: Compressing objects:  68% (10remote: Compressing objects:  69% (11remote: Compressing objects:  70% (11remote: Compressing objects:  71% (11remote: Compressing objects:  72% (11remote: Compressing objects:  73% (11remote: Compressing objects:  74% (11remote: Compressing objects:  75% (11remote: Compressing objects:  76% (12remote: Compressing objects:  77% (12remote: Compressing objects:  78% (12remote: Compressing objects:  79% (12remote: Compressing objects:  80% (12remote: Compressing objects:  81% (12remote: Compressing objects:  82% (13remote: Compressing objects:  83% (13remote: Compressing objects:  84% (13remote: Compressing objects:  85% (13remote: Compressing objects:  86% (13remote: Compressing objects:  87% (13remote: Compressing objects:  88% (14remote: Compressing objects:  89% (14remote: Compressing objects:  90% (14remote: Compressing objects:  91% (14remote: Compressing objects:  92% (14remote: Compressing objects:  93% (14remote: Compressing objects:  94% (14remote: Compressing objects:  95% (15remote: Compressing objects:  96% (15remote: Compressing objects:  97% (15remote: Compressing objects:  98% (15remote: Compressing objects:  99% (15remote: Compressing objects: 100% (15remote: Compressing objects: 100% (158/158), done.
Receiving objects:  50% (741/1481), 2Receiving objects:  51% (756/1481), 2Receiving objects:  52% (771/1481), 2Receiving objects:  53% (785/1481), 2Receiving objects:  54% (800/1481), 2Receiving objects:  55% (815/1481), 2Receiving objects:  56% (830/1481), 2Receiving objects:  57% (845/1481), 2Receiving objects:  58% (859/1481), 2Receiving objects:  59% (874/1481), 2Receiving objects:  60% (889/1481), 2Receiving objects:  61% (904/1481), 2Receiving objects:  62% (919/1481), 2Receiving objects:  63% (934/1481), 2Receiving objects:  64% (948/1481), 2Receiving objects:  65% (963/1481), 2Receiving objects:  66% (978/1481), 2Receiving objects:  67% (993/1481), 2Receiving objects:  68% (1008/1481), Receiving objects:  69% (1022/1481), Receiving objects:  70% (1037/1481), Receiving objects:  71% (1052/1481), Receiving objects:  72% (1067/1481), Receiving objects:  73% (1082/1481), Receiving objects:  74% (1096/1481), Receiving objects:  75% (1111/1481), Receiving objects:  76% (1126/1481), Receiving objects:  77% (1141/1481), Receiving objects:  78% (1156/1481), Receiving objects:  79% (1170/1481), Receiving objects:  80% (1185/1481), Receiving objects:  81% (1200/1481), Receiving objects:  82% (1215/1481), Receiving objects:  83% (1230/1481), Receiving objects:  84% (1245/1481), Receiving objects:  85% (1259/1481), Receiving objects:  86% (1274/1481), Receiving objects:  87% (1289/1481), remote: Total 1481 (delta 145), reused 230 (delta 116), pack-reused 1174
Receiving objects:  88% (1304/1481), Receiving objects:  89% (1319/1481), Receiving objects:  90% (1333/1481), Receiving objects:  91% (1348/1481), Receiving objects:  92% (1363/1481), Receiving objects:  93% (1378/1481), Receiving objects:  94% (1393/1481), Receiving objects:  95% (1407/1481), Receiving objects:  96% (1422/1481), Receiving objects:  97% (1437/1481), Receiving objects:  98% (1452/1481), Receiving objects:  99% (1467/1481), Receiving objects: 100% (1481/1481), Receiving objects: 100% (1481/1481), 618.33 KiB | 827.00 KiB/s, done.
Resolving deltas: 100% (610/610), done.
smile@smile-X3-S:~/app_install/catkin_ws/src$ 

编译

cd ..
catkin_make

过程如下

smile@smile-X3-S:~/app_install/catkin_ws/src$ cd ..
smile@smile-X3-S:~/app_install/catkin_ws$ catkin_make
Base path: /home/smile/app_install/catkin_ws
Source space: /home/smile/app_install/catkin_ws/src
Build space: /home/smile/app_install/catkin_ws/build
Devel space: /home/smile/app_install/catkin_ws/devel
Install space: /home/smile/app_install/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/smile/app_install/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/smile/app_install/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/smile/app_install/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/smile/app_install/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/smile/app_install/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - usb_cam
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'usb_cam'
-- ==> add_subdirectory(usb_cam)
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'libavcodec'
--   Found libavcodec, version 57.107.100
-- Checking for module 'libswscale'
--   Found libswscale, version 4.8.100
-- Configuring done
-- Generating done
-- Build files have been written to: /home/smile/app_install/catkin_ws/build
####
#### Running command: "make -j16 -l16" in "/home/smile/app_install/catkin_ws/build"
####
Scanning dependencies of target usb_cam
[ 25%] Building CXX object usb_cam/CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp: In member function ‘int usb_cam::UsbCam::init_mjpeg_decoder(int, int):
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:386:89: warning:int avpicture_alloc(AVPicture*, AVPixelFormat, int, int)’ is deprecated [-Wdeprecated-declarations]
 T_RGB24, image_width, image_height);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:5626:5: note: declared here
 int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
     ^~~~~~~~~~~~~~~
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:397:90: warning:int avpicture_get_size(AVPixelFormat, int, int)’ is deprecated [-Wdeprecated-declarations]
 YUV422P, image_width, image_height);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:5653:5: note: declared here
 int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
     ^~~~~~~~~~~~~~~~~~
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:398:85: warning:int avpicture_get_size(AVPixelFormat, int, int)’ is deprecated [-Wdeprecated-declarations]
 T_RGB24, image_width, image_height);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:5653:5: note: declared here
 int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
     ^~~~~~~~~~~~~~~~~~
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp: In member function ‘void usb_cam::UsbCam::mjpeg2rgb(char*, int, char*, int):
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:422:94: warning:int avcodec_decode_video2(AVCodecContext*, AVFrame*, int*, const AVPacket*)’ is deprecated [-Wdeprecated-declarations]
 rame_camera_, &got_picture, &avpkt);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:4993:5: note: declared here
 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
     ^~~~~~~~~~~~~~~~~~~~~
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:441:76: warning:int avpicture_get_size(AVPixelFormat, int, int)’ is deprecated [-Wdeprecated-declarations]
 ec_context_->pix_fmt, xsize, ysize);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:5653:5: note: declared here
 int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
     ^~~~~~~~~~~~~~~~~~
/home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:454:123: warning:int avpicture_layout(const AVPicture*, AVPixelFormat, int, int, unsigned char*, int)’ is deprecated [-Wdeprecated-declarations]
  (uint8_t *)RGB, avframe_rgb_size_);
                                   ^
In file included from /home/smile/app_install/catkin_ws/src/usb_cam/include/usb_cam/usb_cam.h:44:0,
                 from /home/smile/app_install/catkin_ws/src/usb_cam/src/usb_cam.cpp:55:
/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h:5645:5: note: declared here
 int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt,
     ^~~~~~~~~~~~~~~~
[ 50%] Linking CXX shared library /home/smile/app_install/catkin_ws/devel/lib/libusb_cam.so
[ 50%] Built target usb_cam
Scanning dependencies of target usb_cam_node
[ 75%] Building CXX object usb_cam/CMakeFiles/usb_cam_node.dir/nodes/usb_cam_node.cpp.o
[100%] Linking CXX executable /home/smile/app_install/catkin_ws/devel/lib/usb_cam/usb_cam_node
[100%] Built target usb_cam_node
smile@smile-X3-S:~/app_install/catkin_ws$ 

上面的编译过程中,到了100%就行,可能会报红或者警告,不要管他;

启动节点测试roslaunch us b_cam usb_cam-test.launch
这里因为没有告诉新开的终端准备要用包的路径,所以会报错

smile@smile-X3-S:~/app_install/catkin_ws$ roslaunch us
b_cam usb_cam-test.launch
RLException: [usb_cam-test.launch] is neither a launch file in package [usb_cam] nor is [usb_cam] a launch file name
The traceback for the exception was written to the log file

在工作路径下source一下(如果用这个方法,每次打开一个终端都需要一次source!)

source devel/setup.bash

如果不设置好source,那你就无法在新终端下run起来,会报错找不到roslaunch文件

bash: /home/smile/app_install/catkin_ws/devel/setup.bash: Permission denied
smile@smile-X3-S:~$ roslaunch usb_cam usb_cam-test.launch
RLException: [usb_cam-test.launch] is neither a launch file in package [usb_cam] nor is [usb_cam] a launch file name
The traceback for the exception was written to the log file

也可以一劳永逸source
为了不每次运行程序的时候都source一次devel文件夹里的setup.bash,可以打开主目录 按下Crtl+h 显示隐藏文件,双击打开bashrc文件,或者到这个目录下打开终端然后:sudo gedit .bashrc

在最后加入
source/home/############/catkin_ws/devel/setup.bash,其中###部分为你的计算机账户,保存后再重新打开终端,显示无错误即可。

source /home/smile/app_install/catkin_ws/devel/setup.bash
如果不加source后面就会报错:bash: /home/smile/app_install/catkin_ws/devel/setup.bash: Permission denied
在这里插入图片描述
修改好后,激活一下source ~/.bashrc

就可以用了

smile@smile-X3-S:~/
catkin_wssmile@smile-X3-S:~/app_install/catkin_ws$ roslaunch us
b_cam usb_cam-test.launch
RLException: [usb_cam-test.launch] is neither a launch file in package [usb_cam] nor is [usb_cam] a launch file name
The traceback for the exception was written to the log file
smile@smile-X3-S:~/
catkin_wssmile@smile-X3-S:~/app_install/catkin_ws$ source devel
/setup.bash
smile@smile-X3-S:~/
catkin_wssmile@smile-X3-S:~/app_install/catkin_ws$ source devel        roslaunch us
b_cam usb_cam-test.launch
... logging to /home/smile/.ros/log/156d2af4-4390-11ed-a099-3c58c26f458c/roslaunch-smile-X3-S-26383.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://smile-X3-S:40005/

SUMMARY
========

PARAMETERS
 * /image_view/autosize: True
 * /rosdistro: melodic
 * /rosversion: 1.14.13
 * /usb_cam/camera_frame_id: usb_cam
 * /usb_cam/image_height: 480
 * /usb_cam/image_width: 640
 * /usb_cam/io_method: mmap
 * /usb_cam/pixel_format: yuyv
 * /usb_cam/video_device: /dev/video0

NODES
  /
    image_view (image_view/image_view)
    usb_cam (usb_cam/usb_cam_node)

auto-starting new master
process[master]: started with pid [26393]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 156d2af4-4390-11ed-a099-3c58c26f458c
process[rosout-1]: started with pid [26404]
started core service [/rosout]
process[usb_cam-2]: started with pid [26407]
process[image_view-3]: started with pid [26411]
[ INFO] [1664852163.724025585]: Initializing nodelet with 16 worker threads.
[ INFO] [1664852163.736597435]: using default calibration URL
[ INFO] [1664852163.736978102]: camera calibration URL: file:///home/smile/.ros/camera_info/head_camera.yaml
[ INFO] [1664852163.737007231]: Unable to open camera calibration file [/home/smile/.ros/camera_info/head_camera.yaml]
[ WARN] [1664852163.737016572]: Camera calibration file /home/smile/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1664852163.737028096]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (yuyv) at 30 FPS
[ INFO] [1664852163.777121709]: Using transport "raw"
[ WARN] [1664852163.806821536]: unknown control 'white_balance_temperature_auto'

[ WARN] [1664852163.808830397]: unknown control 'focus_auto'

^C[image_view-3] killing on exit
[usb_cam-2] killing on exit
[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done

2.3 启动usb相机节点

A.查找摄像头接口

ls /dev/video*

这里可以先在插入usb摄像头的时候检查一下接口,然后拔出usb摄像头的时候再检查一下接口(看看少了哪些,少了的就是usb摄像头的)
在这里插入图片描述
很明显, /dev/video2 或者 /dev/video3 是我的摄像头usb接口号(好像ubuntu下摄像头是有两个号的,用任意一个就可以了);
B.在该路径下修改launch文件,换成你自己的摄像头接口
到达该路径:

cd /opt/ros/noetic/share/usb_cam/launch/

编辑该文件

sudo gedit usb_cam-test.launch

在这里插入图片描述
原本这里是 /dev/video0,将其改为/dev/video2在这里插入图片描述
保存后退出,然后运行:

roslaunch usb_cam usb_cam-test.launch

然后就可以运行摄像头了:
在这里插入图片描述

如果报错:ERROR: cannot launch node of type [image_view/image_view]: image_viewROS path [0]=/opt/ros/noetic/s

ERROR: cannot launch node of type [image_view/image_view]: image_view
ROS path [0]=/opt/ros/noetic/share/ros
ROS path [1]=/home/zxf/catkin_ws/src
ROS path [2]=/opt/ros/noetic/share

解决方法:
sudo apt-get install ros-noetic-image-view
注意:noetic那个地方为ROS版本号,需要替换为自己的。后面的image-view来源于自己的报错信息,注意查看,如果出现无法定位软件包,改连接符"-“为”_"试试。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ubuntu各种版本上测试usb摄像头(支持单目摄像头、乐视、realsense等)是否正常工作 的相关文章

  • STM32之串口通信USART模块学习(1)

    一 通信接口 通信的目的 xff1a 将一个设备的数据传送到另一个设备 xff0c 扩展硬件系统通信协议 xff1a 制定通信的规则 xff0c 通信双方按照协议规则进行数据收发 单端信号通信的双方必须要共地 xff0c 因为都是对GND的
  • 2019电赛总结(一)

    2019电赛总结 xff08 一 xff09 文章目录 2019电赛总结 xff08 一 xff09 4 那之前5 电赛初期6 电赛中期7 电赛强化练习8 电赛预热阶段8月初9 那以后 4 那之前 2019电赛总结 序 xff09 5 电赛
  • 统计从键盘输入的一行字符中小写字母,大写字母,数字字符和其它字符的个数。

    统计从键盘输入的一行字符中小写字母 xff0c 大写字母 xff0c 数字字符和其它字符的个数 C语言实现 vs 2019 span class token macro property span class token directive
  • c语言求1~10的阶乘和

    求1 43 2 43 3 43 43 10 的和 span class token macro property span class token directive keyword include span span class toke
  • C和Cpp区别

    1 输入 xff0c 输出不同 xff08 out xff0c put xff09 c语言 xff1a include lt stdio h gt scanf 34 d 34 amp a printf 34 a 61 d n 34 a cp
  • C++实现基于顺序搜索的动态分区分配算法

    目录 1 需求分析 2 代码实现 3 测试用例 4 总结与收获 1 需求分析 动态分区分配又称为可变分区分配 xff0c 他是根据进程的实际需要 xff0c 动态地为之分配内存空间 在实现动态分区分配时 xff0c 将涉及到分区分配中所有的
  • C语言实现TCP编程

    C语言实现TCP编程 1 主机字节序和网络字节序2 套接字的地址结构IP地址转化的方法 3 TCP的网络接口4 TCP服务器端的编程流程5 TCP客户端的编程流程6 运行结果 1 主机字节序和网络字节序 主机字节序 xff1a 不同的芯片
  • QT---用户登录注册案例实现

    用户登录 注册 span class token macro property span class token directive hash span span class token directive keyword include
  • C++中list详解

    list详解 list的介绍list函数说明成员类型构造函数元素访问迭代器容量修改器操作 vector和list区别总结vector和list的使用场景 仿写END xff01 96 在这里插入代码片 96 list的介绍 list是序列容
  • sip response 摘要认证

    详解摘要认证 1 什么是摘要认证 摘要认证与基础认证的工作原理很相似 xff0c 用户先发出一个没有认证证书的请求 xff0c Web服务器回复一个带有WWW Authenticate头的响应 xff0c 指明访问所请求的资源需要证书 但是
  • Prim算法实现最小生成树

    Prim算法实现最小生成树 1 最小生成树是什么2 最小生成树的用途3 Prim算法描述4 Prim算法演示最小生成树过程5 Prim算法实现END 1 最小生成树是什么 对连通图进行遍历 过程中所经过的边和顶点的组合可看做是一棵普通树 通
  • 哈夫曼树,哈夫曼编码及应用——(代码实现)

    哈夫曼树 xff0c 哈夫曼编码及应用 1 哈夫曼树1 1 什么是哈夫曼树 2 如何构造哈夫曼树 xff08 哈夫曼算法 xff09 2 1 举例实现哈夫曼树2 1 1手动实现具体步骤2 1 2代码实现具体步骤 3 哈夫曼编码3 1 什么是
  • 二叉排序树详解及实现

    二叉排序树详解及实现 1 什么是二叉排序树2 二叉排序树的数据结构2 1二叉排序树的节点类型2 2二叉排序树中插入某个元素2 3 二叉排序树中按值查找元素2 4 找排序二叉树中的最小值2 5返回排序二叉树中ptr中序遍历的后续节点2 6 寻
  • 平衡二叉树的一系列操作:删除、插入(在二叉排序树中插入新结点后,如何保持平衡)、调整平衡等等等

    平衡二叉树的插入 xff08 在二叉排序树中插入新结点后 xff0c 如何保持平衡 xff09 1 平衡二叉树的定义2 平衡二叉树的插入 xff08 调整最小不平衡子树A xff09 2 1LL xff08 在A的左孩子的左子树中插入导致不
  • 网络 UDP协议(C++|代码通过udp协议实现客户端与服务端之间的通信)

    这里写目录标题 udp通信编程各端的操作流程 xff1a 服务端操作流程 xff1a 客户端操作流程 xff1a 第2 3步与服务端不同 socket接口介绍udp客户服务端代码实现 推荐阅读 socket套接字编程就是在网络程序中编写代码
  • 网络 TCP协议(C++代码|通过tcp协议实现客户端与服务端之间的通信)

    目录 TCP通信编程各端的操作流程 xff1a 服务端操作流程 xff1a 客户端操作流程 xff1a 推荐先学习UDP协议在学习TCP协议 在UDP协议博客中讲解得更详细 xff0c 看懂UDP协议就很容易理解TCP了 网络 UDP协议
  • Matlab学习-箱型图绘制

    1 箱型图简介 xff1a 参考链接 xff1a boxplot函数用法详解 箱型图简介 箱型图主要包括的数据有 xff1a 最大值 最小值 上四分位数 下四分位数和中位数 xff0c 以及异常值 2 箱型图绘制 X span class
  • Matlab学习-CDF(累积分布函数图)绘制

    累积分布函数图绘制 参考链接 xff1a 1 Matlab官方说明 2 参考链接 3 属性设置 CDF xff1a 累积分布函数图 xff0c 顾名思义就是能够直观的反应某组数列分布的概率情况 xff0c 能够非常直观的反应误差精度大小 图
  • Matlab学习-频率分布直方图绘制

    参考链接 xff1a hist xff08 xff09 函数用法 频率分布直方图 xff1a 在数理统计中 xff0c 会经常使用到频率分布直方图 xff0c 能够直观的反应频率分布的范围大小 xff0c 在直角坐标系中 xff0c 横轴为
  • Matlab学习-经纬度在matlab内置地图显示

    已知经纬度坐标 xff0c 将其显示是地图上 参考链接 xff1a 使用matlab绘制世界地图并根据经纬度绘制点位 附m map的下载与安装说明 wm span class token operator 61 span webmap sp

随机推荐