一.硬件要求:
①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-113linux-hwe-5.4-headers-5.4.0-121 linux-hwe-5.4-headers-5.4.0-122linux-hwe-5.4-headers-5.4.0-124 linux-hwe-5.4-headers-5.4.0-84python-rosdistro
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:libv4l2rds0 ros-melodic-camera-calibration-parsersros-melodic-camera-info-manager v4l-utils
The following NEW packages will be installed:libv4l2rds0 ros-melodic-camera-calibration-parsersros-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 hereint 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 hereint 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 hereint 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 hereint 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 hereint 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 hereint 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/video0NODES/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:11311setting /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来源于自己的报错信息,注意查看,如果出现无法定位软件包,改连接符"-“为”_"试试。

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

  1. 双目摄像头和单目摄像头_挑战激光雷达,MAXIEYE要重新定义单目摄像头?

    周圣砚认为:以往业内对单目摄像头的顾虑更像是一种偏见,并非不能逾越的鸿沟,而偏见正是用来打破的. 作者 | 安琪 自动驾驶的"唯激光雷达论"正在受到冲击. 前不久恩智浦的全球CTO ...

  2. Mobileye采用单目摄像头做ADAS太不精确

    Mobileye采用单目摄像头做ADAS太不精确?用双目摄像头的"中科慧眼"认为双目测距算法才是最精确的 Nicholas • 2016-01-05 18:53 ADAS(Adva ...

  3. Mobileye采用单目摄像头做ADAS太不精确?用双目摄像头的“中科慧眼”认为双目测距算法才是最精确的

    Mobileye采用单目摄像头做ADAS太不精确?用双目摄像头的"中科慧眼"认为双目测距算法才是最精确的 时间 2016-01-05 18:53:01   36氪 原文   htt ...

  4. ORB-SLAM2:一个支持单目、双目和RGB-D摄像头(相机)的开源SLAM系统(翻译)

    书读百遍其义自见,为了日后能方便快速回顾ORB-SLAM2的原理和思想,这里本人将论文翻译成中文母语,网上也有其他的翻译版本,诸君也可参照.本文不求诸君全信,但求无误导之嫌疑.小经验:研究源码以及修改 ...

  5. 单目摄像头检测6D姿态

    单目摄像头检测6D姿态 CVPR2019: ROI-10D: Monocular Lifting of 2D Detection to 6D Pose and Metric Shape 论文链接: h ...

  6. 单目摄像头的内外参标定

    任务动机:基于ORB-SLAM3+单目广角摄像头进行二次开发,辅助激光导航实现机器人全局重定位.需要对单目摄像头进行内参和外参标定. 任务描述: 1. 镜头畸变和内参标定 用棋盘格标定 2. 摄像机与 ...

  7. python opencv 摄像头标定_(五)单目摄像头标定与畸变矫正(C++,opencv)

    本文将梳理一种单目摄像头标定和矫正的方法,在梳理的过程中,首先使用网上离线的图片数据跑通流程,然后接入自己的camera,手动采集标定图像,实时矫正相机的畸变,然后输出矫正后的图像.全文基于Openc ...

  8. 【AI简报20210910期】联想发布LA2智能嵌入式控制器、单目摄像头实时感知车辆形状...

    嵌入式 AI 1. 历时三年量产列装:联想发布LA2智能嵌入式控制器 原文链接: http://finance.sina.com.cn/tech/2021-09-08/doc-iktzqtyt4856 ...

  9. 单目摄像头光学图像测距_摄像头与毫米波雷达(Radar)融合解析

    01 摄像头和雷达的融合是很多做ADAS当前所关注的关键问题之一.因为单纯摄像头和雷达都无法解决测距问题.不仅在测距,今后可能所应用到的高精度地图也都是需要使用摄像头和雷达的融合才能够实现.当前寻求到 ...

最新文章

  1. php中的empty和isset
  2. 联系 Contact
  3. oracle 中的闪回
  4. window如何杀掉java进程_windows下java -jar 后台运行以及杀死后台进程的操作
  5. 执行计划 分析一条sql语句的效率 mysql_mysql的SQL语句执行计划分析:EXPLAIN
  6. UnrealScript语言基础
  7. 计算机课又叫什么课,计算机课学电脑的书叫什么?
  8. 了解一下运行软件的自我保护(RASP)
  9. Tomcat 下载、安装与配置
  10. 便携式频谱仪无人机机载频谱仪解决方案
  11. 第一次用vc写的文件切割小软件_CutFile
  12. 使用百度地图API在页面添加百度地图应用
  13. 编译内核使tilera支持网桥和netfilter功能
  14. wordpress网站被黑后怎么解决
  15. npm i 命令安装失败提示:npm WARN read-shrinkwrap,解决方法
  16. C/C++ Linux 键盘检测
  17. 【番外篇】Excel:一行转多行
  18. 浮点型数据判断相等不能直接使用==
  19. Ublox GPS模块型号入门介绍
  20. 夹在在按键和鼠标之间的生活

热门文章

  1. Android LinearLayout横排和竖排布局
  2. 人脸检测及识别下一步的工作安排:
  3. Deep Learning in Natural Language Processing中文连载(一)
  4. Android-Camera内存问题剖析,小白也能看明白
  5. 科目二和科目三找准30厘米位置的点位
  6. 如何给latex加批注
  7. 对utf-8字符串计算长度
  8. 云扩科技与帆软软件达成战略合作,携手共建RPA+BI新生态
  9. python希腊字母怎么生成_#python sympy怎样把狄克拉函数定义出来#
  10. 形象思维法与抽象思维法