Andrea Torlai
Created September 7, 2024

Astrial - Using the USB Camera

The goal of this tutorial is to show how to use the Innodisk USB Camera to detect different objects

39
Astrial - Using the USB Camera

Things used in this project

Hardware components

Astrial
×1
Innodisk USB Camera EV2U-SGR1
×1
Raspberry Pi Compute Module 4 IO Board
×1

Story

Read more

Code

detection.sh

SH
#!/bin/bash
set -e

CURRENT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

function init_variables() {
    readonly RESOURCES_DIR="${CURRENT_DIR}/resources"
    readonly POSTPROCESS_DIR="/usr/lib/hailo-post-processes"
    readonly DEFAULT_POSTPROCESS_SO="$POSTPROCESS_DIR/libyolo_post.so"
    readonly DEFAULT_NETWORK_NAME="yolov5"
    readonly DEFAULT_VIDEO_SOURCE="/dev/video0"
    readonly DEFAULT_HEF_PATH="${RESOURCES_DIR}/${DEFAULT_NETWORK_NAME}m_yuv.hef"
    readonly DEFAULT_JSON_CONFIG_PATH="$RESOURCES_DIR/configs/yolov5.json"

    postprocess_so=$DEFAULT_POSTPROCESS_SO
    network_name=$DEFAULT_NETWORK_NAME
    input_source=$DEFAULT_VIDEO_SOURCE
    hef_path=$DEFAULT_HEF_PATH
    json_config_path=$DEFAULT_JSON_CONFIG_PATH

    print_gst_launch_only=false
    additional_parameters=""
    width=1920
    height=1080
}

function print_usage() {
    echo "IMX8 Detection pipeline usage:"
    echo ""
    echo "Options:"
    echo "  --help              Show this help"
    echo "  -i INPUT --input INPUT          Set the video source (default $input_source)"
    echo "  -w WIDTH --width WIDTH          Set the input width (default $width)"
    echo "  -h HEIGHT --height HEIGHT       Set the input height (default $height)"
    echo "  --show-fps          Print fps"
    echo "  --print-gst-launch  Print the ready gst-launch command without running it"
    exit 0
}

function parse_args() {
    while test $# -gt 0; do
        if [ "$1" = "--help" ]; then
            print_usage
            exit 0
        elif [ "$1" = "--print-gst-launch" ]; then
            print_gst_launch_only=true
        elif [ "$1" = "--show-fps" ]; then
            echo "Printing fps"
            additional_parameters="-v | grep hailo_display"
        elif [ "$1" = "--input" ] || [ "$1" = "-i" ]; then
            input_source="$2"
            shift
        elif [ "$1" = "--width" ] || [ "$1" = "-w" ]; then
            width="$2"
            shift
        elif [ "$1" = "--height" ] || [ "$1" = "-h" ]; then
            height="$2"
            shift
        else
            echo "Received invalid argument: $1. See expected arguments below:"
            print_usage
            exit 1
        fi

        shift
    done
}

init_variables $@

parse_args $@

PIPELINE="gst-launch-1.0 \
    v4l2src device=$input_source ! video/x-raw,format=YUY2,width=$width,height=$height ! \
    videoscale ! video/x-raw,width=1280,height=720 ! \
    queue leaky=downstream max-size-buffers=5 max-size-bytes=0 max-size-time=0 ! \
    hailonet hef-path=$hef_path ! \
    queue leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 ! \
    hailofilter function-name=$network_name config-path=$json_config_path so-path=$postprocess_so qos=false ! \
    queue leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 ! \
    hailooverlay ! \
    queue leaky=downstream max-size-buffers=5 max-size-bytes=0 max-size-time=0 ! \
    videoconvert ! \
    fpsdisplaysink video-sink=autovideosink name=hailo_display sync=false text-overlay=false ${additional_parameters}"

echo "Running $network_name"
echo ${PIPELINE}

if [ "$print_gst_launch_only" = true ]; then
    exit 0
fi

eval ${PIPELINE}

gst-device-monitor-1.0 output

Plain text
Device found:
    name  : Innodisk USB Camera: Innodisk U
    class : Video/Source
    caps  : video/x-raw, format=YUY2, width=1920, height=1080, pixel-aspect-ratio=1/1, framerate=5/1
--------->  image/jpeg, width=1920, height=1080, pixel-aspect-ratio=1/1, framerate=30/1
            image/jpeg, width=1280, height=720, pixel-aspect-ratio=1/1, framerate=30/1
            image/jpeg, width=640, height=480, pixel-aspect-ratio=1/1, framerate=30/1
    properties:
            udev-probed = true
            device.bus_path = platform-xhci-hcd.1.auto-usb-0:1.1:1.0
            sysfs.path = /sys/devices/platform/soc@0/32f10100.usb/38100000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.1/1-1.1:1.0/video4linux/video3
            device.bus = usb
            device.subsystem = video4linux
            device.vendor.id = 196d
            device.vendor.name = Innodisk\x20Technology\x20Co.\x2c\x20Ltd.
            device.product.id = b202
            device.product.name = Innodisk USB Camera: Innodisk U
            device.serial = Innodisk_Technology_Co.__Ltd._Innodisk_USB_Camera_Y2400B7E4_1713865854
            device.capabilities = :capture:
            device.api = v4l2
  ------->  device.path = /dev/video3
            v4l2.device.driver = uvcvideo
            v4l2.device.card = Innodisk USB Camera: Innodisk U
            v4l2.device.bus_info = usb-xhci-hcd.1.auto-1.1
            v4l2.device.version = 331591 (0x00050f47)
            v4l2.device.capabilities = 2225078273 (0x84a00001)
            v4l2.device.device_caps = 69206017 (0x04200001)
    gst-launch-1.0 v4l2src device=/dev/video3 ! ...

Credits

Andrea Torlai

Andrea Torlai

9 projects • 2 followers

Comments