Skip to main content

OpyFlow - Python package for Optical Flow measurements.

Project description

About

OpyFlow : Python package for Optical Flow measurements

Opyflow is a basic image velocimetry tool to simplify your video or frame sequences processing.

It is based on opencv and vtk libraries to detect Good Features to Track (GFT), calculate their displacements by the Lukas Kanade method and interpolate them on a mesh. This method is sometimes called Feature Image Velocimetry or Feature Tracking. It is an alternative to the classical cross-correlation techniques employed in Particle Image Velocimetry (PIV). Compared to this technique, GFT+OpticalFlow may result in better performance when image qualities are poor for velocimetry, i.e. when velocity information on frames is non-uniform.

For flow calculations, the process is mainly inspired by the openCV python sample lktrack.py.

The package also contains some rendering tools built with matplotlib. Velocities can be exported (csv, tecplot, vtk, hdf5).

Author: Gauthier Rousseau

Corresponding e-mail : gauthier.rousseau@gmail.com

Quick Start

To quickly get started with OpyFlow, follow these steps:

  1. Ensure you have Python installed in your environment.

  2. Open your terminal and run the following command to install OpyFlow and its main dependencies (matplotlib, vtk, and opencv):

    pip install opyf
    

    Alternatively, if you have the OpyFlow repository cloned locally, you can run:

    python3 -m pip install ./
    
  3. This will automatically install the OpyFlow library and its dependencies.

To analyze a frame sequence (e.g., PNG, BMP, JPEG, TIFF), use the following code:

import opyf
analyzer = opyf.frameSequenceAnalyzer("folder/toward/images")

For analyzing a video (e.g., MP4, AVI, MKV), use the following code:

analyzer = opyf.videoAnalyzer("video/file/path")

To perform your first analysis, run the following code:

analyzer.extractGoodFeaturesAndDisplacements()

OpyFlow package includes two frames and one video for testing and self-practice:

  1. The two frames were extracted from the frame sequence of the Test case A of the PIV Challenge 2014:

    PIV challenge

    When applied to the entire dataset, OpyFlow can produce the above result (see Test PIV Challenge 2014 - Case A for details on the procedure).

  2. The video is a bird's eye view video of a stream river taken by a drone, from which surface velocities can be extracted (see this tutorial for different possible procedures or the following python file):

    bird's eye view Navizence

  3. A guide is also provided to obtain the free surface velocity in a river from two amateur videos:
    Stabilization, orthorectification (bird's eye view transformation), and free surface velocity estimation on the Brague river with OpyFlow

Contents

This repository is organized as follows:

The setup file:

  • setup.py

The package Folder opyf:

  • opyf

    • Analyzer.py
    • Track.py
    • Interpolate.py
    • Files.py
    • Filters.py
    • Render.py
    • Tools.py
    • custom_cmap.py (based on Chris Slocum file)
  • test

    • Test_case_PIV_Challenge_2014
    • Test_land_slide_youtube_video
    • Test_Navizence
    • Test_Brague_flood

A test on synthetic images is still required.

Installation with anaconda

The package requires python and basic python package: csv, numpy, matplotlib, tqdm, hdf5. Main dependencies are: OpenCV and VTK.

If the pip install opyf command above does not work for you, an alternative way to deal with dependencies is using miniconda or anaconda.

When miniconda/anaconda is installed you may create an environment (here called opyfenv). To create the environment type in the terminal:

conda create -n opyfenv python=3.11

This command line will install an environment with python 3.11 and the main dependencies.

You can access to your environment by typing:

conda activate opyfenv

Installation using the standard python protocol to create a virtual environment

You can also use the standard python protocol (run the command where you want to put the environment):

python -m venv opyfenv
source opyfenv/bin/activate

From you environment, you should be able to install opyf with pip install opyf.

For development mode, you may also install the libraries individually with pip:

pip install ipython vtk opencv-python tqdm h5py matplotlib scipy ipykernel PyQt6

And set the opyf repository in your PATH or in the beginning of your python script using:

import sys
sys.path.append("path/toward/opyf/src")

Tested on:

  • Python: 3.11
  • VTK: 9.2.6
  • OpenCV: 4.7
  • NumPy: 1.24
  • Matplotlib: 3.7.1

Citation

This package has been developed in the course of my PhD at EPFL to study Turbulent flows over rough permeable beds. Outputs are visible in the manuscript as well as in this Video where paraview animations have been rendered thanks to opyf outputs.

@PhdThesis{rousseau2019turbulent, title={Turbulent flows over rough permeable beds in mountain rivers: Experimental insights and modeling}, author={Rousseau, Gauthier}, year={2019}, institution={EPFL} }

An article published in Experiments in Fluids is available in Open Access : Scanning PIV of turbulent flows over and through rough porous beds using refractive index matching

Follow this link to directly access to the annex of the article presenting the opyf algorithms and tests.

@article{rousseau2020scanning, title={Scanning PIV of turbulent flows over and through rough porous beds using refractive index matching}, author={Rousseau, Gauthier and Ancey, Christophe}, journal={Experiments in Fluids}, volume={61}, number={8}, pages={1--24}, year={2020}, publisher={Springer} }

Contributors : Hugo Rousseau, Mohamed Nadeem, LHE team and others

Credits for UAV video : Bob de Graffenried

Credits for 2019 flood video on Brague River (Biot, French Riviera) : Pierre Brigode

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opyf-1.6.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opyf-1.6-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file opyf-1.6.tar.gz.

File metadata

  • Download URL: opyf-1.6.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for opyf-1.6.tar.gz
Algorithm Hash digest
SHA256 e95aa5116989b6b3d2554cfc83fcde6dcfb5cb95c439a8f5ab2fe199a74b7bd4
MD5 cf723939e538eb3b779a09372f8dede6
BLAKE2b-256 eb422428d96ce88f879b842dcd4a9269084fc569036f2fa62af828d31826d0cc

See more details on using hashes here.

File details

Details for the file opyf-1.6-py3-none-any.whl.

File metadata

  • Download URL: opyf-1.6-py3-none-any.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for opyf-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d590bbfb0f948d76b7b4319ab0e8cd446a4cc86847de9a23c940686eb62163a6
MD5 d720b257c2146309b9628a439977c361
BLAKE2b-256 4823ef12ba3bbe1582cce0de03c10e72219c9137e59b041f8e236c52c83cf364

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page