Integrate RGB Cameras with Foxglove
With Foxglove, you can stream data from any RGB camera (USB webcams, built-in laptop cameras, or IP cameras) for real-time visualization. The Foxglove SDK contains example code that shows how to stream data that you can modify to fit your application.
If you are using ROS, you can launch your camera node, and follow ROS 2 Documentation to start Foxglove Bridge.
Prerequisites
OpenCV Installation
- Ubuntu/Debian
- macOS
- Windows
sudo apt update
sudo apt install libopencv-dev
brew install opencv
Follow the OpenCV installation guide for Windows and ensure the OpenCV environment variables are set.
Installation and Setup
- Python
- C++
- Rust
Python Installation
-
Navigate to the Python example directory:
cd foxglove-sdk/python/foxglove-sdk-examples/rgb-camera-visualization
-
Install dependencies using Poetry:
poetry install
Or using pip:
pip install foxglove-sdk>=0.9.0 opencv-python>=4.5.0 numpy>=1.20.0
C++ Installation
-
Navigate to the C++ directory:
cd foxglove-sdk/cpp
-
Build the project with OpenCV support:
make BUILD_OPENCV_EXAMPLE=ON build
Rust Installation
-
Verify opencv-rust dependencies are installed
-
Navigate to the Rust example directory:
cd foxglove-sdk/rust/examples/rgb_camera_visualization
-
Build the example:
cargo build
Usage
- Python
- C++
- Rust
Running the Python Application
cd foxglove-sdk/python/foxglove-sdk-examples/rgb-camera-visualization
# Use default camera (usually camera 0)
poetry run python main.py
# Specify a different camera ID
poetry run python main.py --camera-id 1
# Use a video file path
poetry run python main.py --camera-id /path/to/video.mp4
Running the C++ Application
cd foxglove-sdk/cpp/build
# Use default camera (usually camera 0)
./example_rgb_camera_visualization
# Specify a different camera ID
./example_rgb_camera_visualization --camera-id 1
# Use a video file path
./example_rgb_camera_visualization --camera-id /path/to/video.mp4
Running the Rust Application
cd foxglove-sdk/rust/examples/rgb_camera_visualization
# Use default camera (usually camera 0)
cargo run
# Specify a different camera ID
cargo run -- --camera-id 1
# Use a video file path
cargo run -- --camera-id /path/to/video.mp4
Command Line Options
Option | Description | Default |
---|---|---|
--camera-id , -c | Camera ID (integer) or video file path | 0 |
--help , -h | Show help message | - |
Visualize RGB Camera Data in Foxglove
To visualize the RGB camera data, open Foxglove and connect to the websocket server.
Make sure you are on the same network as your robot. In Foxglove, select Open connection from the dashboard or left-hand menu.
Select Foxglove WebSocket in the Open a new connection dialog, then enter the URL of the server:
Click "Open" to connect.
Local development: Use ws://localhost:8765
when running the server on the same machine as Foxglove.
Robot connection: Use ws://ROBOT_IP:8765
when connecting to a server running on your robot, where ROBOT_IP
is your robot's IP address on the network.
Visualize Camera Feed
Add an Image panel to your layout by clicking the Add panel button in the top left corner and selecting the Image panel.
Configure the panel by selecting the appropriate image topic from the Topic dropdown in the panel settings.
Learn More
- Explore the Foxglove SDK documentation
- Check out the Python RGB camera stream example
- Check out the Rust RGB camera stream example
- Check out the C++ RGB camera stream example
- Learn more about OpenCV camera capture