Welcome to Jetson Orin NANO Developer Kit repository
06.NV optical flow anomaly detection
DeepStream NV Optical Flow and Motion Direction Analysis
DeepStream NV Optical Flow and Motion Direction Analysis1. Example Goal and Processing Chain2. Official Application and Environment3. Running Entry Points4. Local Video Run5. Camera Runs and Hardware Limitations6. Observation and Acceptance7. Stopping and Common Issues8. References
Applicable environment: JetPack 7.2.1, Ubuntu 24.04, DeepStream 9.1, CUDA 13.2, TensorRT 10.16, Jetson Orin Nano Super. The example is based on the NVIDIA DeepStream
reference_apps/anomaly. It demonstrates TrafficCamNet object detection, NVIDIA hardware optical flow, and motion direction analysisAfter the power mode is set to MAXN, running the example may pop up an over-current warning; just ignore it
1. Example Goal and Processing Chain
This example displays both the detection results and the motion information between adjacent video frames:
Input video/camera ↓Decode and nvstreammux ↓TrafficCamNet object detection ↓nvof hardware optical flow → dsdirection direction analysis ↓ ↓nvofvisual optical flow preview Detection/direction information previewnvof computes pixel motion vectors, nvofvisual renders them into a pseudo-color image, and dsdirection performs direction analysis based on the target motion information. The optical flow window shows motion vectors, not anomaly categories or anomaly probabilities; specific business alerts still require scene rules and application-layer logic.
2. Official Application and Environment
Official reference application: https://github.com/NVIDIA/DeepStream/tree/main/src/apps/reference_apps/anomaly
Source directory:
xxxxxxxxxx~/DeepStream/src/apps/reference_apps/anomaly/apps/deepstream-anomaly-detection-testThe course device already has the application, the TrafficCamNet model and TensorRT engine, and the unified launch script ready. Daily runs do not require re-downloading models, deleting engines, or recompiling the program. The engines are tied to the TensorRT/CUDA environment on the device; when restoring the environment, check and build on the target Jetson according to the official instructions, and do not directly copy engines generated on other devices.
3. Running Entry Points
The unified launch script is located at:
xxxxxxxxxx~/DeepStream/deepstream-shell-demo/| Input Source | Command | Current Output |
|---|---|---|
| Local video | ./run_video.sh anomaly | Detection preview; whether the hardware optical flow works must be verified per Section 5 |
| USB camera | ./run_usb.sh anomaly | Real-time object detection preview; the current configuration bypasses the unavailable PVA optical flow chain |
| CSI camera | ./run_csi.sh anomaly | Real-time object detection preview; the current configuration bypasses the unavailable PVA optical flow chain |
The entry points above only preview, and do not generate or overwrite an MP4. The desktop window requires the Jetson local graphical desktop or a VNC graphical session; a pure SSH session without graphical display cannot view the preview.
4. Local Video Run
Run from the Jetson local desktop or a VNC terminal:
xxxxxxxxxxcd ~/DeepStream/deepstream-shell-demo./run_video.sh anomalyThe default input is the DeepStream sample video sample_1080p_h264.mp4. A detection window is displayed during the run; devices with available PVA/hardware optical flow should also display the optical flow visualization window. On the first launch, if the log shows the TensorRT engine is being loaded or built, wait for it to complete; do not delete the existing .engine files.

Replacing the test video:
xxxxxxxxxx./run_video.sh anomaly --source /home/jetson/videos/test.mp4The path must be an absolute path that exists on the Jetson. To process multiple video streams, you can specify --source repeatedly; the actual input capability is still limited by the course entry and device resources.
5. Camera Runs and Hardware Limitations
USB camera:
xxxxxxxxxxcd ~/DeepStream/deepstream-shell-demo./run_usb.sh anomalyCSI camera:
xxxxxxxxxxcd ~/DeepStream/deepstream-shell-demo./run_csi.sh anomaly
Before running, confirm that the camera is connected and not occupied by another program. The following commands show the devices and supported formats:
xxxxxxxxxxv4l2-ctl --list-devicesv4l2-ctl -d /dev/video0 --list-formats-ext # USBgst-launch-1.0 nvarguscamerasrc # CSI

You can add parameters such as resolution and frame rate yourself. Note: the USB pipeline of LPR is fixed to MJPEG, so when choosing the USB parameters, select the MJPEG ones
x# View all parameters./run_usb.sh anomaly --help./run_csi.sh anomaly --help
# Use the second CSI camera./run_usb.sh anomaly --device /dev/video1./run_csi.sh anomaly --sensor-id 1
# Adjust the input size and frame rate./run_usb.sh anomaly --width 1280 --height 720 --fps 60./run_csi.sh anomaly --width 1920 --height 1080 --fps 30The PVA device node of the current Orin Nano Super system is unavailable. The USB/CSI entries therefore bypass dsdirection and nvof, and only run the TrafficCamNet detection preview; the video entry keeps the official hardware optical flow processing graph.
6. Observation and Acceptance
The detection preview should show the target boxes and categories detected by TrafficCamNet. On devices with hardware optical flow enabled, when an object in the frame moves or the camera moves, the optical flow pseudo-color image should change continuously with the motion; few motion vectors in a static scene is normal.
Acceptance of valid optical flow requires all of the following:
The log contains no persistent PVA device-open errors.
A moving scene produces optical flow results that change over time, rather than fixed noise.
The target boxes in the detection window change with the input frame.
7. Stopping and Common Issues
Press Ctrl+C once in the terminal where the launch command was run, and wait for the program to exit and return to the shell. Do not send interrupt signals repeatedly or use kill -9; the camera can be used by other programs after it exits.
| Symptom | Handling |
|---|---|
Failed to open PVA device node | The current hardware/device tree does not provide a usable PVA; the USB/CSI detection preview can continue to be used, but the hardware optical flow cannot pass acceptance. |
OF METADATA NOT FOUND or the optical flow window is noise | Means no valid optical flow metadata was obtained; the window itself does not mean the optical flow succeeded. Check the PVA/driver status. |
| USB reports the device is busy or shows no picture | Use v4l2-ctl --list-devices and --list-formats-ext to check the device node, format, and occupancy. |
| CSI reports no cameras | Check the CSI flex cable, sensor, sensor-id, and nvargus-daemon; first confirm the basic CSI example can run. |
| Only a window, no target boxes | Check whether the targets are clearly visible and the lighting is sufficient, and confirm the TrafficCamNet engine loads normally. |
| No window after launching over SSH | Run from the Jetson desktop/VNC session, and check DISPLAY and X11 authorization. |
| The usb/csi optical flow window does not show a person | The person needs to move; only continuous changes produce a response |
8. References
NVIDIA DeepStream Anomaly Detection: https://github.com/NVIDIA/DeepStream/tree/main/src/apps/reference_apps/anomaly
NVIDIA DeepStream SDK: https://docs.nvidia.com/metropolis/deepstream/dev-guide/index.html