Initial commit. Working.
This commit is contained in:
Executable
+138
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# install.sh — get a legacy Point Grey / FLIR USB2 camera running on
|
||||
# Ubuntu 24.04 / Linux Mint 22 using the FlyCapture2 SDK (v2.13.3.31).
|
||||
#
|
||||
# These cameras (USB vendor 1e10) predate the Spinnaker SDK and are only
|
||||
# supported by FlyCapture2. On a modern release we install just the core
|
||||
# runtime + development libraries, whose only real dependencies are
|
||||
# libusb and libraw1394. We deliberately skip the GUI packages (FlyCap2,
|
||||
# UpdatorGUI): they need GTK2-era libraries (libgtkmm-2.4, libglademm-2.4,
|
||||
# libgtkglextmm) that no longer exist in Ubuntu 24.04. Instead we install
|
||||
# the prebuilt command-line tool FlyCapture2Test, which links only the
|
||||
# core library, plus the example source tree for building your own apps.
|
||||
#
|
||||
# Run: sudo ./install.sh
|
||||
# Undo: sudo ./uninstall.sh
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
GROUP="flirimaging"
|
||||
USBFS_MB=1000
|
||||
UDEV_RULES="/etc/udev/rules.d/40-flir.rules"
|
||||
GRUB_FILE="/etc/default/grub"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SDK_DIR="${SDK_DIR:-$SCRIPT_DIR/sdk}"
|
||||
|
||||
# The user who should own the camera (the human running sudo, not root).
|
||||
TARGET_USER="${SUDO_USER:-${USER:-}}"
|
||||
|
||||
log() { printf '\n\033[1;32m==>\033[0m %s\n' "$*"; }
|
||||
warn() { printf '\033[1;33m[warn]\033[0m %s\n' "$*" >&2; }
|
||||
die() { printf '\033[1;31m[error]\033[0m %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
[ "$(id -u)" -eq 0 ] || die "Run as root: sudo ./install.sh"
|
||||
[ -n "$TARGET_USER" ] && [ "$TARGET_USER" != "root" ] || \
|
||||
die "Could not determine the target user. Run with sudo from your normal account."
|
||||
[ -d "$SDK_DIR" ] || die "SDK directory not found: $SDK_DIR"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "1/7 Installing dependencies (libusb, libraw1394, build tools, OpenCV)"
|
||||
apt-get update -qq
|
||||
# libusb/libraw1394: core SDK. g++/libopencv-dev: to build the fc2view viewer.
|
||||
apt-get install -y libusb-1.0-0 libraw1394-11 g++ libopencv-dev
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "2/7 Installing FlyCapture2 core libraries"
|
||||
# Order matters: runtime before its -dev, C API after the C++ core.
|
||||
dpkg -i "$SDK_DIR"/libflycapture-2.13.3.31_amd64.deb \
|
||||
"$SDK_DIR"/libflycapture-2.13.3.31_amd64-dev.deb \
|
||||
"$SDK_DIR"/libflycapture-c-2.13.3.31_amd64.deb \
|
||||
"$SDK_DIR"/libflycapture-c-2.13.3.31_amd64-dev.deb
|
||||
ldconfig
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "3/7 Installing the FlyCapture2Test command-line tool + example source"
|
||||
# The prebuilt CLI binaries and the C/C++ example source live inside the
|
||||
# flycap package, but that package's *dependencies* pull in dead GTK2 libs.
|
||||
# So we extract the useful files without installing (dpkg) the package.
|
||||
TMP_EXTRACT="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP_EXTRACT"' EXIT
|
||||
dpkg-deb -x "$SDK_DIR"/flycap-2.13.3.31_amd64.deb "$TMP_EXTRACT"
|
||||
install -m 0755 "$TMP_EXTRACT/usr/bin/FlyCapture2Test" /usr/local/bin/FlyCapture2Test
|
||||
install -m 0755 "$TMP_EXTRACT/usr/bin/FlyCapture2Test_C" /usr/local/bin/FlyCapture2Test_C
|
||||
# Example source tree (build your own apps against the SDK).
|
||||
rm -rf /usr/src/flycapture
|
||||
cp -a "$TMP_EXTRACT/usr/src/flycapture" /usr/src/flycapture
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "4/7 Building the fc2view live viewer"
|
||||
# Native OpenCV-based replacement for the vendor GUI (which needs dead GTK2
|
||||
# libs). Best-effort: a failure here does not abort the core install.
|
||||
if g++ "$SCRIPT_DIR/fc2view.cpp" \
|
||||
-I/usr/include/flycapture $(pkg-config --cflags opencv4) \
|
||||
$(pkg-config --libs opencv4) -lflycapture \
|
||||
-o /usr/local/bin/fc2view; then
|
||||
echo "Installed /usr/local/bin/fc2view"
|
||||
else
|
||||
warn "fc2view build failed; the CLI tools still work. Build it by hand later:"
|
||||
warn " g++ fc2view.cpp -I/usr/include/flycapture \$(pkg-config --cflags --libs opencv4) -lflycapture -o fc2view"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "5/7 Configuring device permissions (udev rule + '$GROUP' group)"
|
||||
groupadd -f "$GROUP"
|
||||
usermod -aG "$GROUP" "$TARGET_USER"
|
||||
# Point Grey / FLIR USB product IDs are 0x2000-0x2005 and 0x3xxx. Grant the
|
||||
# group read/write on matching USB nodes. (Trimmed from FLIR's flycap2-conf;
|
||||
# we drop the blanket "all USB devices" rule it shipped.)
|
||||
{
|
||||
for pid in 2000 2001 2002 2003 2004 2005 \
|
||||
3000 3001 3004 3005 3006 3007 3008 300A 300B \
|
||||
3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3300; do
|
||||
echo "SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1e10\", ATTRS{idProduct}==\"${pid}\", MODE=\"0664\", GROUP=\"${GROUP}\""
|
||||
done
|
||||
} > "$UDEV_RULES"
|
||||
udevadm control --reload-rules
|
||||
udevadm trigger
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "6/7 Raising the USBFS buffer limit to ${USBFS_MB} MB"
|
||||
# Default is 16 MB, too small for camera frames -> grab failures / dropped
|
||||
# images. Apply now for this boot, and persist via the kernel command line.
|
||||
echo "$USBFS_MB" > /sys/module/usbcore/parameters/usbfs_memory_mb || \
|
||||
warn "Could not set usbfs_memory_mb live; a reboot will apply the persistent setting."
|
||||
|
||||
if [ -f "$GRUB_FILE" ]; then
|
||||
if grep -q "usbcore.usbfs_memory_mb" "$GRUB_FILE"; then
|
||||
sed -i -E "s/usbcore\.usbfs_memory_mb=[0-9]+/usbcore.usbfs_memory_mb=${USBFS_MB}/" "$GRUB_FILE"
|
||||
else
|
||||
# Append inside the existing GRUB_CMDLINE_LINUX_DEFAULT="..." quotes.
|
||||
sed -i -E "s/^(GRUB_CMDLINE_LINUX_DEFAULT=\")(.*)\"/\1\2 usbcore.usbfs_memory_mb=${USBFS_MB}\"/" "$GRUB_FILE"
|
||||
fi
|
||||
update-grub
|
||||
else
|
||||
warn "$GRUB_FILE not found; skipped persistent USBFS setting. Set usbcore.usbfs_memory_mb=${USBFS_MB} on your bootloader manually."
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
log "7/7 Done"
|
||||
cat <<EOF
|
||||
|
||||
FlyCapture2 core SDK installed.
|
||||
|
||||
Live viewer : fc2view (streams the camera; 's' saves a snapshot)
|
||||
Test tool : FlyCapture2Test (lists cameras and grabs frames)
|
||||
Headers : /usr/include/flycapture
|
||||
Examples : /usr/src/flycapture/src
|
||||
|
||||
Two things need a fresh login/boot to take effect:
|
||||
* group '$GROUP' membership for '$TARGET_USER' -> log out and back in
|
||||
* the persistent USBFS limit -> applied live now, made
|
||||
permanent on next reboot
|
||||
|
||||
Quick check (after re-login), with the camera plugged in:
|
||||
FlyCapture2Test # confirms detection + grabs frames
|
||||
fc2view # live window
|
||||
|
||||
EOF
|
||||
Reference in New Issue
Block a user