Skip to content

PerForm-Lab-RIT/retinal_flow_toolkit

Repository files navigation

Retinal flow toolkit

( generate gaze-centered optical flow from a movie )

A simple module for the calculation of optic flow.

The most relevant file is video_source.py, in which lives the video_source class for converting a video into optic flow. You also have the option of saving out intermediate frames of image data.

It will take advantage of CUDA if enabled for opencv. I have included instructions on how to get that going at hte bottom of this readme.

To run, create a video_source object from an input movie file, and then calculate_flow()

a_file_path = os.path.join("demo_input_video", "linear_travel.mp4")
source = video_source(a_file_path)
source.calculate_flow(algorithm='tvl1', visualize_as="hsv_stacked", lower_mag_threshold = False, upper_mag_threshold=25,
                           vector_scalar=3, save_input_images=False, save_output_images=False, fps = 30)

If you don't have cuda enabled for opencv, set <video_source>.cuda_enabled = False It will work, but it will be very slow (like 10x slower).

Flow algorithms and settings.

Nothing elegant here - you'll have to go into the code for more info. I encourage the user to look at <video_source>.create_flow_object() to see the different algorithms that are enabled, and to see the parameters for existing flow algorithms. I have not made all parameters for all algorithms visible. Use the opencv docs to play around.

At the time of writing this, I have implemented...

  • deepflow
  • farneback
  • brox with cuda support
  • tvl1 with cuda support
  • pyrLK with cuda support

I've had the best quality output with tvl1. \n I tried to implement cuda_NvidiaOpticalFlow_2_0, but ran into indecipherable errors. So, it lingers, half impelemented.

Options for "visualize_as" include:

"hsv_stacked"

image

"hsv_overlay"

image

"vectors"

image

"streamlines"

image

Output

Output frames and movies will be organized in sensibly-named subfolders of /flow_out/<movie_name>.

Setting the upper_mag_threshold

Output will be placed in /flow_out/<movie_name>. HSV color representations of flow are best if scaled to a range defined by a reasonable maximum value. For that reason, after processing with upper_mag_threshold = False, /flow_out/<movie_name>/magnitude_data will contain images of the cumulative distribution function of magnitude of flow vector length. Set your threshold somewhere around where the CDF reaches 1. This will vary for algorithm and by the motion statistics of the environment / task / stimulus class (?) represented in your video.

image

Dependencies

Tested with py3.8 and opencv 4.6 compiled with CUDA.

Dependencies include...

  • numpy
  • av for movie makin'
  • logging
  • pickle
  • tqdm for the nifty progress bar that shows up in your console.
  • matplotlib

image


Some notes on installing OpenCV with CUDA:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages