Skip to content

cpslab-asu/optical-flow-cpv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Optical Flow Emulation based on PAW3902

This script simulates a sliding bar animation and computes optical flow using Lucas–Kanade (LK) tracking, mimicking the behavior of the PixArt PAW3902 optical flow sensor. It outputs flow values in radians and visualizes them in real time.

Features

  • Generates a synthetic bar animation (red, green, blue columns) for testing flow detection.
  • Implements optical flow calculation using OpenCV’s calcOpticalFlowPyrLK.
  • Scales pixel displacements into radians using PAW3902’s datasheet constants (11.914 CPI per meter, 39.3701 in/m).
  • Provides an optional debug plotting window for flow_x and flow_y over time.

Code Structure

  • SlidingBarAnimation: Generates the RGB sliding bar test pattern.
  • CalculateOpticalFlow: Core class that
    • Computes optical flow,
    • Converts raw displacements into radians,
    • Plots flow values in real time using the nested FlowPlotter class for visualization.

Attack / Sliding Bar Parameters

The stimulus pattern (used to drive or “attack” the optical flow algorithm) is controlled by:

  • num_rgb_sets → Number of repeating RGB groups across the frame.
  • switching_frequency → Frequency (Hz) at which the frames switch between red, green, and blue patterns.
  • frame size → Defined in SlidingBarAnimation as width=900, height=900.
  • padding → White border around the bars (default: 100 pixels).

Sensor Parameters

Inside CalculateOpticalFlow, the following parameters are defined to emulate PAW3902 behavior:

  • SENSOR_RESOLUTION_PIXELS = 35
  • FPS = 126.0 (Bright mode)
  • PIXART_RESOLUTION = 11.914 (counts per inch per meter)
  • INCHES_PER_METER = 39.3701
  • SCALE = 1 / (PIXART_RESOLUTION * INCHES_PER_METER) → counts to radians

Requirements

Usage

Run the script directly:

python3 optical_flow_emulation.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%