This repository contains a real-time movement analysis tool using video capture and Mediapipe's pose estimation. The tool is designed to help biomedical engineering students track and analyze movements using a laptop camera or a connected mobile phone camera. The analysis can be performed in real-time or on recorded data, and various metrics and visualizations are provided.
- Real-time movement tracking using Mediapipe and OpenCV.
- Capture video from a laptop camera or a mobile phone camera.
- Extract and track key points of interest (e.g., ankles, knees, hips, shoulders, elbows, wrists, and center of gravity).
- Save tracked data to CSV files for further analysis.
- Analyze movement data with various analytical tools.
- Calculate correlations between movements.
- Visualize correlation matrices and skeleton heatmaps.
- Multiple modes of operation:
- track: Capture and track movements in real-time.
- analyze: Analyze saved movement data.
- corr: Compute and visualize correlations between movement datasets.
biomedical_workshops/
├── main.py
├── README.md
├── requirements.txt
└── src/
├── tracking.py
├── corr.py
└── analysis.py
-
Clone the repository:
git clone https://github.com/manuelmariscal/biomedical_workshops.git cd biomedical_workshops
-
Create a virtual environment and activate it:
python -m venv bioworkshops # On Windows: bioworkshops\Scripts\activate # On Unix or MacOS: source bioworkshops/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
The tool operates in different modes: track
, analyze
, and corr
. You can specify the mode using the --mode
argument.
To run the real-time movement tracking:
python main.py --mode track --source 0
Where 0
is the default source for the laptop camera. You can also use a URL or another device index for a mobile phone camera or an external camera.
To analyze saved movement data:
python main.py --mode analyze --data_folder data
This mode processes the CSV files in the specified data_folder
and performs analysis, including plotting movements and calculating metrics.
To compute and visualize correlations between movement datasets:
python main.py --mode corr --data_folder data
This mode processes the CSV files in the specified data_folder
, computes correlation matrices between pairs of datasets, and visualizes the results, including skeleton heatmaps.
--mode
: Mode of operation (track
,analyze
, orcorr
).--source
: Video source (e.g.,0
for laptop camera, URL for mobile camera). Used only intrack
mode.--data_folder
: Folder where CSV data files are stored. Used inanalyze
andcorr
modes.
The tool captures video data and extracts key points of interest, saving the results in CSV files within the specified data_folder
. It provides various visualizations and analyses, depending on the mode:
-
Tracking Mode (
track
):- Real-time skeleton movement: Displays the real-time movement of the skeleton with tracked key points and lines connecting them.
- Data Saving: Saves the tracked data to CSV files for later analysis.
-
Analysis Mode (
analyze
):- Movement Plots: Visualizes the movements from the saved data.
- Animations: Creates animations comparing valid and invalid movements.
- Correlation Calculations: Computes correlations between movements.
-
Correlation Mode (
corr
):- Correlation Matrices: Generates and displays correlation matrices for each pair of movement datasets.
- Skeleton Heatmaps: Plots the skeleton with a heatmap based on average keypoint correlations.
- Correct Orientation: The skeleton is displayed with the correct orientation.
- Enhanced Visualization: Thicker lines and larger keypoints are used for better visibility.
- Blue Color Map: A blue color map is used for the heatmap.
- Visualization of Results: Both the correlation matrices and the skeleton heatmap are displayed simultaneously with appropriate titles.
To run the tool in corr
mode and analyze data in the data
folder:
python main.py --mode corr --data_folder data
Feel free to contribute to this project by opening issues or submitting pull requests. Please ensure your code follows the coding standards and includes tests where applicable.
This project is licensed under the MIT License.
This project uses the following libraries:
For more information, please visit the project repository.