See G3DCV2021_FinalProject.pdf for more details.
Reflectance Transformation Imaging (RTI) is a technique to capture the reflectance of an object under different lighting conditions. It enables the interactive relighting of the subject from any direction and the mathematical enhancement of subject’s surface shape and color attributes. Typically, RTI uses a static camera and an array of light sources at known (or knowable) positions.
In this project, you’ll explore RTI using a cheaper setup composed by two consumer smartphones equipped with a camera and LED flashlight. The idea is to use one of the two smartphones as a movable light source while the other captures the object from a frontal position. We exploit the camera of the movable light source to recover the light direction vector at each point and provide the same data obtainable with a light dome.
The project must contain 3 different programs:
- A
camera_calibrator
that loads one of the two provided calibration videos and computes the intrinsic parameters of the camera (the intrinsic matrix K and the lens distortion vector assuming a 5-parameters model) without any user intervention. - The
analysis
program to process a video sequence and compute a texture map of the object (ie a function, for each object pixel, mapping light direction to pixel intensity). The whole analysis must be performed without any user intervention. Tunable parameters should not depend on the specific sequence processed. - An
interactive_relighting
program to render a previously processed object according to a user-definable light source direction
Download the assets folder from here.
Create the assets/
folder and extract the G3DCV2021_data archive on the root folder.
The G3DCV2021_data
folder is also stored on the repository into the assets release.
Here a small description of the developed project done, and how it works.
First download the assets
as described before.
This project use python 3.7.
Download the required project libraries.
Here the commands to import required libraries with conda
conda install numpy matplotlib
conda install -c conda-forge opencv
Note: must be 4.2.0 or greater
conda install -c anaconda scipy
conda install ffmpeg-python
conda install -c conda-forge pysoundfile
conda install -c conda-forge moviepy
conda install -c conda-forge svglib
conda install -c anaconda reportlab
conda install scikit-image
conda install -c conda-forge python-dotenv
Note: this is required to run on GPU
conda install numba
conda install cudatoolkit
The project contains the 3 different programs required from the assignment.
camera_calibrator.py
: basic program that read the two chessboard images and save camera intrinsics into assets folder.analysis.py
: core program that perform different tasks, it can require some time to finish (1/2 hours):- sync_videos(): extract the audio offset between the static and moving video (required for sync)
- generate_video_default_frame(): extract and save a default frame from static video (a frame with no light)
- extract_video_frames(): extract the video frames with the class FeatureMatcher
This class will compute the corner detection, intensity extraction and get the camera pose of given frames (static and moving).
Results are saved on storage and can be reused. - compute_intensities(): compute light vectors intensities for each frame pixel.
- interpolate_intensities(): compute the interpolation of pixel intensities, two interpolation function are supported:
- Polynomial Texture Maps (PTM)
- Linear Radial Basis Function (RBF)
- prepare_images_data(): prepare images for each camera position (normalized) with interpolated values. This process is required in order to speed up relighting program.
- Save interpolation results on storage (can require some GB)
interactive_relighting.py
: the final program, require the analysis results in order to execute. It reads the interpolation results and render the relighted image dynamically based on the light direction specified with the cursor.
audio_utils.py
: contains utility functions regarding audio management.email_utils.py
: contains utility functions regarding email management.image_utils.py
: contains utility functions regarding image and video management.utilities.py
: contains misc utility functions.
Each program has some tunable parameters on compute() function:
camera_calibrator.py
: no tunable parameters.analysis.py
:- video_name: specify the name of the video to analyze.
- from_storage: specify whether to read a previous extract_video_frames() results, in this case analysis will start from compute_intensities() phase.
- storage_filepath: specify a different path whether to read extract_video_frames() results
- interpolate_PTM: specify the interpolation function to use
- notification_email: specify if send a notification email when the computation is finish.
Note in order to use this parameter you should rename.env.example
to.env
and fill it with valid google account credentials. The env file is used in order to keep credentials off-repo. - debug: specify whether to compute analysis on debug mode (analyze first pixel only on interpolation)
interactive_relighting.py
:- video_name: specify the name of the video to relight. storage_filepath: specify a different path whether to read analysis() results.
Each program have a compute()
function.
In order to test each program individually there is also a main()
function, that will simply call the compute() function with some pre-set parameters.
- To run all the 3 programs sequentially from skratch simply use
$ python main.py
. - To run them separately use
$ python {program_name}.py
, where program_name is one of the 3 main programs.