A minimal C++ example that streams live video from a FLIR Blackfly GigE camera using the Spinnaker SDK and displays it with OpenCV.
- Auto-discovery and connection of GigE Vision cameras via Spinnaker SDK
- Automatic detection of color (BGR8) and mono (Mono8) cameras
- Real-time FPS measurement and logging
- Persistent IP configuration (
--set-ip) - Camera selection by serial number
| Dependency | Tested Version | Notes |
|---|---|---|
| OS | Ubuntu 22.04 (x86_64) | Other Linux distros may work if Spinnaker SDK supports them |
| CMake | 3.30.5 | Minimum 3.16 (per CMakeLists.txt) |
| C++ Compiler | GCC 11.4.0 | C++17 required |
| Spinnaker SDK | 4.3.0.189 | Download from FLIR/Teledyne website |
| OpenCV | 4.5.4 | apt install libopencv-dev |
| spdlog | 1.10.0 | Source build or apt install libspdlog-dev |
| fmt | 8.1.1 | apt install libfmt-dev |
Download Spinnaker SDK for Linux from the FLIR website: https://www.flir.com/products/spinnaker-sdk/
# Install downloaded .deb package (example)
sudo dpkg -i spinnaker-<version>_amd64.deb
sudo apt-get install -f
# Or extract tar.gz to /opt/spinnaker
# Default expected path: /opt/spinnakerNote: After installation,
/opt/spinnaker/include/Spinnaker.hmust exist.
sudo apt update
sudo apt install -y libopencv-dev libfmt-dev libspdlog-devIf building spdlog from source:
git clone https://github.com/gabime/spdlog.git
cd spdlog && mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/spdlog
make -j$(nproc) && sudo make installJumbo frames are recommended for GigE Vision cameras:
# Check your network interface name
ip link show
# Enable jumbo frames (e.g., for eno1)
sudo ip link set eno1 mtu 9000
# Make it persistent (add mtu 9000 in /etc/netplan/ or /etc/network/interfaces)Increase the receive buffer size:
sudo sysctl -w net.core.rmem_max=10485760
sudo sysctl -w net.core.rmem_default=10485760
# Make it persistent
echo "net.core.rmem_max=10485760" | sudo tee -a /etc/sysctl.conf
echo "net.core.rmem_default=10485760" | sudo tee -a /etc/sysctl.confgit clone https://github.com/warhammer50K/blackfly-gige-viewer.git
cd blackfly-gige-viewer
mkdir build && cd build
# Default build (Spinnaker: /opt/spinnaker, spdlog: /opt/spdlog)
cmake ..
make -j$(nproc)
# Specify custom spdlog path
cmake -DSPDLOG_INCLUDE_DIR=/path/to/spdlog/include ..
make -j$(nproc)# Use the first detected camera
./bfly_test
# Select a specific camera by serial number
./bfly_test 12345678
# Set persistent IP on the camera (192.168.1.30)
./bfly_test --set-ip
# Set persistent IP on a specific camera
./bfly_test --set-ip 12345678| Key | Action |
|---|---|
q / ESC |
Quit |
Ctrl+C |
Quit (signal) |
Edit the default values in set_persistent_ip() in main.cpp:
constexpr int64_t NEW_IP = ip_to_int(192, 168, 1, 30);
constexpr int64_t NEW_MASK = ip_to_int(255, 255, 255, 0);
constexpr int64_t NEW_GW = ip_to_int(192, 168, 1, 1);bfly_test/
├── CMakeLists.txt # Build configuration
├── main.cpp # Main source code
└── README.md # This file
- "No cameras found": Ensure the camera and PC are on the same subnet. Test with
SpinViewfirst. - Frame drops / Incomplete image: Check jumbo frame (MTU 9000) and receive buffer size settings.
- Permission errors: To run without
sudo, copy the udev rules provided by the Spinnaker installer to/etc/udev/rules.d/.
This project's source code is licensed under the MIT License.
This project depends on the following libraries, each with its own license:
| Library | License |
|---|---|
| Spinnaker SDK | FLIR/Teledyne proprietary (must be downloaded separately) |
| OpenCV | Apache 2.0 |
| spdlog | MIT |
| fmt | MIT (with optional exception) |