Skip to main content

Simple VR180 image converter

Project description

VR180 image converter

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License


Documentation: https://vr180-convert.readthedocs.io

Source Code: https://github.com/34j/vr180-convert


Simple VR180 image converter on top of OpenCV and NumPy.

Installation

Install this via pip (or your favourite package manager):

pipx install vr180-convert

Usage

Simply run the following command to convert 2 fisheye images to a SBS equirectangular VR180 image:

v1c lr left.jpg right.jpg
left.jpg right.jpg Output
left right output

If left and right image paths are the same, the image is divided into two halves (left and right, SBS) and processed as if they were separate images.

Advanced usage

Automatic image search

If one of left or right image path is a directory, the program will search for the closest image (in terms of creation time) in the other directory.

v1c lr left.jpg right_dir
v1c lr left_dir right.jpg

It is recommended to synchronize the clocks of the cameras before shooting. However, it can be adjusted by specifying -ac option.

v1c lr left.jpg right_dir -ac 1 # the clock of the right camera is 1 second faster / ahead
v1c lr left_dir right.jpg -ac 1 # the clock of the right camera is 1 second faster / ahead

Radius estimation

The radius of the non-black area of the input image is assumed by counting black pixels by default, but it would be better to specify it manually to get stable results:

v1c lr left.jpg right.jpg --radius 1000
v1c lr left.jpg right.jpg --radius max # min(width, height) / 2

Calibration

Rotation matching using the least-squares method can be performed by clicking corresponding points that can be regarded as infinitely far away from the camera.

v1c lr left.jpg right.jpg --automatch gui

You can also specify the corresponding points manually:

v1c lr left.jpg right.jpg --automatch "0,0;0,0;1,1;1,1" # left_x1,left_y1;right_x1,right_y1;...

$$ a_k, b_k \in \mathbb{R}^3, \min_{R \in SO(3)} \sum_k ||R a_k - b_k||^2 $$

Anaglyph

--merge option (which exports as anaglyph image) can be used to check if the calibration is successful by checking if the infinitely far points are overlapped.

v1c lr left.jpg right.jpg --automatch gui --merge

Swap

If the camera is mounted upside down, you can simply use the --swap option without changing the transformer or other parameters:

v1c lr left.jpg right.jpg --swap

Custom conversion model

You can also specify the conversion model by adding Python code directly to the --transformer option:

v1c lr left.jpg right.jpg --transformer 'EquirectangularEncoder() * Euclidean3DRotator(from_rotation_vector([0, np.pi / 4, 0])) * FisheyeDecoder("equidistant")'

If tuple, the first transformer is applied to the left image and the second transformer is applied to the right image. If a single transformer is given, it is applied to both images.

Please refer to the API documentation for the available transformers and their parameters. For from_rotation_vector, please refer to the numpy-quaternion documentation.

Single image conversion

To convert a single image, use v1c s instead.

Help

For more information, please refer to the help or API documentation:

v1c --help

Usage as a library

For more complex transformations, it is recommended to create your own Transformer.

Note that the transformation is applied in inverse order (new[(x, y)] = old[transform(x, y)], e.g. to decode orthographic fisheye images, transform_polar should be arcsin(theta), not sin(theta).)

from vr180_convert import PolarRollTransformer, apply_lr

class MyTransformer(PolarRollTransformer):
    def transform_polar(
        self, theta: NDArray, roll: NDArray, **kwargs: Any
    ) -> tuple[NDArray, NDArray]:
        return theta**0.98 + theta**1.01, roll

transformer = EquirectangularEncoder() * MyTransformer() * FisheyeDecoder("equidistant")
apply_lr(transformer, left_path="left.jpg", right_path="right.jpg", out_path="output.jpg")

Tips

How to determine which image is left or right

Left Right
Subject Orientation Right Left
Film Color ${\color{red}\text{Red}}$ ${\color{blue}\text{Blue}}$
Anaglyph Color ${\color{blue}\text{Blue}}$ ${\color{red}\text{Red}}$
  • In a SBS image, the subject is oriented toward the center.

How to edit images

This program cannot read RAW files. To deal with white-outs, etc., it is required to process each image with a program such as Photoshop, Lightroom, RawTherapee, Darktable, etc.

However, this is so exhaustive, so it is recommended to take the images with jpeg format, being careful not to overexpose the images, and convert them with this program, then use Lightroom, RawTherapee, Darktable or other software to adjust colors and exposure, etc.

Example of processing in Photoshop (Exquisite editing)

  1. Open one of the images just for specifying the canvas size.
  2. Add each image as Smart Objects (LRaw, RRaw) and make minimal corrections to match the exposure using Camera Raw Filter.
  3. Make each Smart Object into Smart Objects (L, R) again and do any image-dependent processing, such as removing the background.
  4. Make both images into a single Smart Object (P) and process them as a whole.
  5. Delete the background image created in step 1.
  6. Export as a PNG file.
  7. Hide the other Smart Object (L or R) (created in step 3) in the Smart Object P (created in step 4) and save the Smart Object P, then export as a PNG file.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

This package was created with Copier and the browniebroke/pypackage-template project template.

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

vr180_convert-0.2.1.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

vr180_convert-0.2.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file vr180_convert-0.2.1.tar.gz.

File metadata

  • Download URL: vr180_convert-0.2.1.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for vr180_convert-0.2.1.tar.gz
Algorithm Hash digest
SHA256 59e7f279c88a33de18f0e840b6d83d0021f4e28b552ce8279f569e386c1218d0
MD5 eb2d467af4e7d0378176c2065473d80d
BLAKE2b-256 1fa7ff4550ae3ac6e215b95c992be4b1322605015b7811f21c1dc3842ba34e92

See more details on using hashes here.

File details

Details for the file vr180_convert-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: vr180_convert-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for vr180_convert-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15f0ef504a36d109255180b14f4e23b2a252ba38b156a8beadf5cd0517b088df
MD5 90a3d33a9feab14071807c083defc203
BLAKE2b-256 45879fbd3de9fbab9be84e988844aee5c2d43006aa0b070409769942e486141e

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