项目作者: Synthesis-AI-Dev

项目描述 :
Apply a fisheye distortion to rendered images using distortion coefficients [k1, k2, k3, k4]
高级语言: Python
项目地址: git://github.com/Synthesis-AI-Dev/fisheye-distortion.git
创建时间: 2020-08-06T18:28:43Z
项目社区:https://github.com/Synthesis-AI-Dev/fisheye-distortion

开源协议:MIT License

下载


fisheye-distortion

Method

This script applies a fisheye distortion to rendered images. The output images can be cropped to a
rectangle and resized. The fisheye distortion is the same as detailed in OpenCV 4.4 docs.
As mentioned in the docs, the distortion is characterized by 4 parameters, [k1, k2, k3, k4], which are
passed via the config file or command line arguments.

Usage

The arguments for the script are passed via the config file. All the parameters in the
config file can be overriden from the command line. You must specify:

  • The input dir in which to
    search for files,
  • The filename extention of the input files (eg: .rgb.png, .segments.png)
  • Whether to use linear interpolation during distortion. For RGB images, using linear interpolation will give
    smoother results. Other types of images (masks, normals, depth) should never use linear interpolation.

Examples

  • Distorting RGB images: Use linear interpolation to get smoother results

    1. python apply_fisheye_distortion.py dir.input=samples/ file_ext.input=.rgb.png linear_interpolation=True
  • Distorting Masks: Use nearest neighbor interpolation to preserve correct values

    1. python apply_fisheye_distortion.py dir.input=samples/ file_ext.input=.segments.png
  • Saving output files to a different directory. A new directory will be created if it does not exist.

    1. python apply_fisheye_distortion.py dir.output=samples/output

Config file

You can edit the config file, config.yaml, to customize the default parameters:

  1. dir:
  2. input: samples/
  3. output: null # If not specified, outputs files to same dir as input.
  4. file_ext:
  5. input: .rgb.png # The files you want to apply distortion to
  6. info: .info.json # Contains camera intrinsics
  7. linear_interpolation: False # Enable Linear for RGB images. Else use nearest-neighbor for masks, normals and depth.
  8. crop_and_resize_output: True # Disable to get original distorted image. Else output will be of same resolution as input.
  9. workers: 0 # How many processes to use to convert files. 0 for all cores in machine.
  10. distortion_parameters:
  11. # Ref: https://docs.opencv.org/4.4.0/db/d58/group__calib3d__fisheye.html
  12. # These are the distortion parameters of a fisheye camera model as defined in the fisheye module of OpenCV 4.4.0
  13. k1: 0.17149
  14. k2: -0.27191
  15. k3: 0.25787
  16. k4: -0.08054
  17. # Hydra specific params.
  18. hydra:
  19. output_subdir: null # Disable saving of config files.
  20. run:
  21. dir: . # Set working dir to current directory
  22. defaults:
  23. # Disable log files
  24. - hydra/job_logging: default
  25. - hydra/hydra_logging: disabled

Install

Pip

This script requires Python 3.7 or greater. The dependencies can be installed via pip:

  1. pip install requirements.txt

Docker

Alternately, you can use the provided dockerfile.

  1. # Build the docker image
  2. bash docker_build.sh
  3. # Run the docker image
  4. bash docker_run.sh
  5. # Inside container
  6. $ python apply_fisheye_distortion.py dir_input=/data

This will process all the images found in the container’s /data directory. Modify the
docker_run.sh script to change which host directory is mounted to the container’s /data.

Detailed Description

From OpenCV docs,
here is the description of the fisheye camera model used to create the distortion. The
distortion co-efficients [k1, k2, k3, k4] are detailed below:
distortion-description