This project implements a motion deblurring pipeline using techniques inspired by Motion Deblurring Using Motion Vectors. It uses dual-camera setups, motion vector extraction, PSF estimation, and deblurring algorithms (Richardson-Lucy and Wiener) to restore motion-blurred images. This implementation is designed for use with Raspberry Pi hardware and Python-based tools.
Motion blur occurs when a camera or subject moves during exposure, resulting in smeared images. De-Lightful Deblur leverages motion estimation techniques like optical flow and fiducial marker tracking to estimate motion paths and compute Point Spread Functions (PSFs), which are then used to reverse blur effects.
The project is implemented using Python, OpenCV, and Raspberry Pi, focusing on computational efficiency and accuracy for motion deblurring tasks.
- Capture and Synchronization:
- Simultaneous image and video capture using a Raspberry Pi dual-camera setup.
- Motion Estimation:
- Extract motion vectors using optical flow or fiducial marker tracking.
- PSF Generation:
- Compute PSF dynamically from motion paths with optional smoothing and interpolation.
- Deblurring:
- Apply deblurring algorithms to restore sharpness to blurred images.
- Results Visualization:
- Save visualizations for motion paths, PSF heatmaps, and deblurred images.
-
Clone the repository:
git clone https://github.com/your-repo/de-lightful-deblur.git cd de-lightful-deblur
-
Set up a Python virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Install OpenCV with GUI support:
pip install opencv-python
-
Run the capture script:
python scripts/capture_images_and_video.py --duration 0.4 --video_output output_video --image_output high_res_image
-
Extract frames from the video:
python scripts/extract_frames.py --video_file output_video.h264 --output_dir frames
-
Crop the high-resolution image to match video FOV:
python scripts/crop_center.py input_image.jpg cropped_image.jpg --width 3072 --height 1728
-
Run the main pipeline (
optical_flow.py
):python scripts/optical_flow.py
-
Provide ROI manually when prompted or set it in the code for automation.
trigger.py
: Captures synchronized high-resolution images and low-resolution videos using dual cameras.extract_frames.py
: Extracts frames from video for further processing.crop.py
: Crops high-resolution images to match the low-resolution video’s field of view.
optical_flow.py
: Main pipeline script for optical flow analysis, PSF estimation, and image deblurring.psf_utils.py
: Includes functions for PSF calculation and visualization.process_video.py
: Handles optical flow computation and motion vector extraction.
The pipeline generates the following outputs:
- Optical Flow Visualizations: Motion paths extracted from video frames.
- PSF Heatmaps: Represents the motion used in deblurring.
- Deblurred Images:
- Richardson-Lucy deblurred result.
- Wiener deblurred result.
Sample outputs are saved in the assets/output/
directory with dynamically generated filenames.
- Motion Deblurring Using Motion Vectors, IEEE.
- OpenCV documentation: https://docs.opencv.org.
- scikit-image documentation: https://scikit-image.org/docs/stable/.