This Python sample is available with all Metavision Intelligence Plans. The corresponding C++ sample is available only with our Professional plan.
Optical Flow Sample using Python
The Python bindings of Metavision Computer Vision API can be used to compute the optical flow of objects moving in front of the camera. The optical flow is computed in a sparse way: flow information is generated on clusters of events and not for each event.
metavision_sparse_optical_flow.py shows how to use the python bindings of Metavision CV SDK to implement
a pipeline for computing the sparse optical flow.
The sample visualizes events and the output optical flow with arrows indicating direction and magnitude of motion:
How to start
To start the sample, you need to provide recorded data with the full path to a RAW file (here, we use a file from our Sample Recordings):
python3 metavision_sparse_optical_flow.py -i pedestrians.raw
python metavision_sparse_optical_flow.py -i pedestrians.raw
To check for additional options:
python3 metavision_sparse_optical_flow.py -h
python metavision_sparse_optical_flow.py -h
Metavision Optical Flow sample implements the following pipeline:
Spatio Temporal Contrast Filter
metavision_sdk_cv.SpatioTemporalContrastAlgorithm is applied to reduce the noise in the events
The filtered events are then sent to both the optical flow and frame generation stages.
Sparse Optical Flow
metavision_sdk_cv.SparseOpticalFlowAlgorithm is applied on the events stream and produces
metavision_sdk_cv.EventOpticalFlow events for each internally detected events cluster. Events are clustered
together based on their speed and directions: events with a similar speed and direction are clustered and flow is
computed for them.
metavision_sdk_cv.FlowFrameGeneratorAlgorithm generates a frame that will be used later on
in the display stage to visualize the result of the
metavision_sdk_cv.SparseOpticalFlowAlgorithm by rendering the
estimated flows on the top of the events.
When ready, the output frame is displayed on the screen: