First install usb_cam
sudo apt-get install ros-melodic-usb-cam
run:
roscore
roslaunch usb_cam usb_cam-test.launch
If an error is reported when running, first confirm whether /dev/video0 exists
You can use ls /dev/video* to view, if not, the camera is not connected, the settings are as follows:
If the above operation still fails to run with an error report, you need to set the following
Compatibility select usb3.1
If you are not using the camera that comes with the laptop, you can edit the configuration file to modify it
cd /opt/ros/melodic/share/usb_cam/launch
sudo gedit usb_cam-test.launch