Using the Sonix Webcam with ROS - OxRAMSociety/RobotArm GitHub Wiki
Requires usb_cam
package; to install: sudo apt install ros-noetic-usb-cam
-
Connect the webcam to your computer via USB. If using Virtualbox, you will have to add the device in the Virtualbox Manager. To do so, navigate to Settings > Ports > USB with the board plugged into your PC and click the 'add USB filter' icon to the right of the tab. Select the device. NOTE: You will have to do this again for every device you use. If permission to access serial ports is asked when subsequently loading Ubuntu, allow permission.
-
Run
usb_cam
node to stream camera feed to ROS topics:rosrun usb_cam usb_cam_node _image_width:=1280 _image_height:=720
The relevant topic for the raw camera feed will be /camera/color/image_raw
- you can subscribe to this to receive the camera feed in ROS Image message format.
- If you want to view the raw camera feed:
rosrun rqt_image_view rqt_image_view
You can subscribe to the camera/color/image_raw
topic just like any other ROS topic. If you want to use the camera in a Python script, you could use something like this:
# Imports
import rospy
import cv2
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import Image
bridge = CvBridge()
...
# Function to convert a received ROS Image into an OpenCV image
def image_callback(image):
try:
cv_image = bridge.imgmsg_to_cv2(image, "passthrough")
return cv_image
except CvBridgeError as e:
rospy.logerr(e)
...
# In main
img_bgr = image_callback(rospy.wait_for_message("/camera/color/image_raw", Image)) # Note - OpenCV images are BGR by default
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
TODO: Camera calibration
I suggest using camera_calibration
to generate camera intrinsics and image_proc
to process the camera data using those intrinsics