Skip to content

Latest commit

 

History

History
152 lines (102 loc) · 4.48 KB

SOD_INTEGRATION.md

File metadata and controls

152 lines (102 loc) · 4.48 KB

SOD Integration in LightNVR

This document explains how SOD (an embedded computer vision & machine learning library) is integrated into LightNVR and how to build the project with or without SOD support.

Overview

SOD provides embedded motion and object detection that runs inside LightNVR, with no external detection service. It is built as a separate shared library (libsod.so) and is optional.

Building Options

Building with SOD (Default)

By default, LightNVR is built with SOD support. This means:

  1. SOD is compiled as a shared library (libsod.so)
  2. LightNVR is linked against this library
  3. The SOD code is directly accessible to LightNVR

To build with SOD support:

# Using the standard build script (SOD is enabled by default)
./scripts/build.sh --release

# Or explicitly enable SOD
./scripts/build.sh --release --with-sod

# Or manually
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SOD=ON ..
make -j$(nproc)

Building without SOD

You can also build LightNVR without SOD support. In this case:

  1. SOD is not compiled
  2. LightNVR is not linked against SOD
  3. LightNVR will attempt to dynamically load libsod.so at runtime if it's available

To build without SOD support:

# Using the standard build script with the --without-sod option
./scripts/build.sh --release --without-sod

# Or manually
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SOD=OFF ..
make -j$(nproc)

Runtime Behavior

When Built with SOD

When LightNVR is built with SOD support:

  • All SOD functionality is available
  • Detection models that require SOD can be loaded and used

When Built without SOD

When LightNVR is built without SOD support:

  • The system will attempt to dynamically load libsod.so at runtime
  • If libsod.so is found, SOD functionality will be available
  • If libsod.so is not found, SOD functionality will be disabled, but LightNVR will still run
  • Detection models that require SOD will not be loadable if SOD is not available

Installation Options

Installing with SOD (Default)

By default, the installation script will install both LightNVR and the SOD library:

# Build with SOD support first
./scripts/build.sh --release

# Install with SOD support (default)
sudo ./scripts/install.sh

# Or explicitly specify SOD installation
sudo ./scripts/install.sh --with-sod

Installing without SOD

You can also install LightNVR without the SOD library:

# Build without SOD support first
./scripts/build.sh --release --without-sod

# Install without SOD
sudo ./scripts/install.sh --without-sod

Installing SOD Separately

If you build LightNVR without SOD support, you can still install SOD separately:

# Clone the repository
git clone https://github.com/opensensor/lightNVR.git
cd lightNVR

# Build just the SOD library
mkdir -p build_sod
cd build_sod
cmake ../src/sod
make -j$(nproc)

# Install the SOD library
sudo cp lib/libsod.so.1.1.9 /usr/local/lib/
sudo ln -sf /usr/local/lib/libsod.so.1.1.9 /usr/local/lib/libsod.so.1
sudo ln -sf /usr/local/lib/libsod.so.1 /usr/local/lib/libsod.so
sudo ldconfig

This will make SOD available to LightNVR at runtime, even if it was built without SOD support.

Detection Models

The following detection model types are supported:

  • SOD models (.sod extension)
  • SOD RealNet models (.realnet.sod extension)
  • TensorFlow Lite models (.tflite extension)

SOD and SOD RealNet models require SOD to be available (either built-in or dynamically loaded). TensorFlow Lite models run on the in-process LiteRT engine, which needs a build with -DENABLE_LITERT=ON and [detection_engine] enabled = true (see Configuration). For larger models, an external detector such as light-object-detect is usually the better fit; see Detection Engines.

Unified Detection Interface

LightNVR now includes a unified detection interface that supports both RealNet and CNN model architectures. This allows you to use either model type with the same API, making it easy to switch between models based on your requirements.

For more information, see SOD Unified Detection.

Test program

test_sod_unified runs a RealNet or CNN model against a still image, detecting the model type automatically. It is built with the test suite (-DBUILD_TESTS=ON) when SOD is enabled:

./test_sod_unified test.jpg face.realnet.sod output.jpg
./test_sod_unified test.jpg face_cnn.sod output.jpg