feat(video): implement buildOpticalFlowPyramid and calcOpticalFlowPyrLK#47
Merged
feat(video): implement buildOpticalFlowPyramid and calcOpticalFlowPyrLK#47
Conversation
Agent-Logs-Url: https://github.com/webarkit/purecv/sessions/860d563a-e3db-4605-9733-ca8952c23b94 Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement buildOpticalFlowPyramid and calcOpticalFlowPyramidLK in video module
feat(video): implement buildOpticalFlowPyramid and calcOpticalFlowPyrLK
Apr 27, 2026
Agent-Logs-Url: https://github.com/webarkit/purecv/sessions/2e3e081f-c8f5-4ffb-abd9-e4b3f02277da Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Agent-Logs-Url: https://github.com/webarkit/purecv/sessions/558ffd16-faf6-4687-bc6e-d5ead9ea5039 Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Agent-Logs-Url: https://github.com/webarkit/purecv/sessions/558ffd16-faf6-4687-bc6e-d5ead9ea5039 Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Add optical_flow_video.rs example demonstrating continuous feature tracking across a video sequence using pyramidal Lucas-Kanade. - Supports animated GIF as a lightweight video input format (decoded via the `image` crate, no new dependencies) - Falls back to synthetic frames from a static image when no GIF is provided - Auto-generates a test GIF (butterfly_motion.gif) on first run - Tracks features across all frames with automatic re-detection when too few points remain - Outputs annotated frame PNGs with coloured flow trails and a CSV summary of per-frame tracking statistics
- Expose calcOpticalFlowPyrLK and buildOpticalFlowPyramid to WASM. - Add OPTFLOW_USE_INITIAL_FLOW and OPTFLOW_LK_GET_MIN_EIGENVALS flag constants. - Implement real-time webcam optical flow demo with trail visualization. - Add optical flow example to the WASM demo index page.
- Added video_bench.rs to measure calc_optical_flow_pyramid_lk performance - Updated Cargo.toml with the new benchmark target - Updated README.md to document new features and purecv-video module - Added Video performance comparison to benches/benchmark_results.md - References PR #44 and #45 features
0fc8a55 to
173f71b
Compare
… and implicit saturating sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves Issue #46, implementing the core Lucas-Kanade Pyramidal Optical Flow functionality in a new
purecv-videomodule. It carefully mirrors the OpenCV API and implementation, providing zero-dependency, safe Rust equivalents for video feature tracking.Closes #46.
Core Features Implemented
build_optical_flow_pyramid: Constructs the image pyramid with an option to also build gradient pyramids (with_derivatives).calc_optical_flow_pyramid_lk: Iterative Lucas-Kanade feature tracking with support for initial flow estimates (OPTFLOW_USE_INITIAL_FLOW), minimum eigenvalue thresholds, and configurable search window sizes.TermCriteriawas already implemented previously insrc/core/types.rs, but is heavily utilized here for configuring the iterative tracking loop termination conditions.Examples & Documentation
examples/optical_flow.rs: A complete, runnable example usingbutterfly.jpg. It synthesizes a subsequent video frame via rigid translation, detects features viagood_features_to_track, tracks them withcalc_optical_flow_pyramid_lk, and outputs a visual representation (optical_flow_result.png) alongside the raw coordinate mapping (optical_flow_vectors.csv).README.mdto introduce the newpurecv-videomodule and shifted the roadmap strategy to track GitHub Milestones (specifically starting with Milestone 3).Benchmarks & Performance
benches/video_bench.rsto validate the performance of pyramid generation and optical flow tracking.benches/benchmark_results.mdto record the baseline performance on standard test resolutions.Code Quality & Interoperability
clippywarnings (option_map_unit_fn,implicit_saturating_sub).as *mut u8raw pointer casts insrc/core/dynamic.rs(data_ptr,data_ptr_mut), fully supporting our WASM/SIMD zero-copy pipeline design.Checks
save_flow_image,draw_line,save_flow_csv)cargo fmtcleancargo clippyclean (0 warnings)cargo test— all tests pass