Skip to main content

This package provides quick and easy way to estimate the camera transition on the z axis given an optical flow.

Project description

camera_z_transition

Description

This is a small python package to estimate the camera motion/zoom on the z axis.

what it is:

  • Estimates the camera motion/zoom on the z axis

what it is NOT:

  • It does not calcualte optical flow (although you can see example of that in the example.py)
  • It is not a metric estimation. It will not tell you the exact amount of transition on the z axis in meter/feet
  • It does not estimate any other camera motion such az tilling, panning, tracking etc.

Install

pip install cam-motion-field

Usage

from camera_z_transition import estimate_z_transition
import numpy as np

# This is the width and height of the image on which you perform the
# optical flow calculation
width = 1080
height = 720

# You should change this to some real optical flow calculation! see example
# in example.py. Both origins and displacements should be a list of 2D vectors.
origins = np.ones((10,2))*(1080//2)+10
displacements = np.ones((10,2))*(1080//2)+20

# Normalize and scale the optical flow first!
origins[:, 0] = (origins[:, 0] / width) - 0.5
origins[:, 1] = (origins[:, 1] / height) - 0.5
displacements[:, 0] = (displacements[:, 0] / width) - 0.5
displacements[:, 1] = (displacements[:, 1] / height) - 0.5

# Estimate transition on the z axis
z = estimate_z_transition(origins, displacements)

print(z)
Parameters for estimate_z_transition()
----------
origins: numpy array,
    Set of origin vectors. Shape must be (nr_of_points, 2). MUST BE ZERO CENTERED AND SCALED!
displacements: numpy array,
    Set of displacement vectors (coordinates). Shape must be (nr_of_points, 2)
focal_length

How it works

Given any point in the image plane (X,Y) we can estimate their new position on the image plane (X',Y') given a transition on the x axis [1].


Where parameter X and Y are coordinates on the image plane and is the transition on the z axis. X' and Y' are the new coordinates on the image plane given the transition parameter. Notice that both equations require a parameter f which is the focal lenght if the camera. Interestingly it does not seem to have a noticeable effect on the output. It seams that until f and (X,Y) has sensible values the exact value of f does not matter. It is important that I do not have any mathematical proof on this. It is purely come from visually observing the behaviour of the function with different f and (X,Y). You can have a look here: link to Plot

Given an observed optical flow it is easy to perform a parameter search for using the equations above.

Results

Given two consecutive images from a camera:

We first obtain the optical flow using opencv

The estimated parameter value for the images above is 0.053796382332247594

The gif below shows the original optical flow and the one artificially generated using the estimated parameter.

References

[1] Srinivasan, M.V., Venkatesh, S., Hosie, R.: Qualitative estimation of camera motion parameters from video sequences. Pattern Recognition 30(4), 593–606 (1997)

Bib

@article{Srinivasan at al.,
  title={Qualitative estimation of camera motion parameters from video sequences},
  author={Srinivasan, Mandyam V and Venkatesh, Svetha and Hosie, Robin},
  journal={Pattern Recognition},
  volume={30},
  number={4},
  pages={593--606},
  year={1997},
  publisher={Elsevier}
}

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

camera-z-transition-1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

camera_z_transition-1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file camera-z-transition-1.0.tar.gz.

File metadata

  • Download URL: camera-z-transition-1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for camera-z-transition-1.0.tar.gz
Algorithm Hash digest
SHA256 65e707dbdd5f4bda15dc5bd918bee989ae6fd37b418b5636ed4ba29f3910177f
MD5 6004ed8ac7e8ad6b006cc5b191536542
BLAKE2b-256 fcbc4026849d91f0f90db2be31fb11133d1dfd9b2c39c5907c1f04596c701f8c

See more details on using hashes here.

File details

Details for the file camera_z_transition-1.0-py3-none-any.whl.

File metadata

  • Download URL: camera_z_transition-1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for camera_z_transition-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc5cf1f4d0ecd8f68cc3dee50f45981c28fbefb47e3557a689852d8f0c697689
MD5 e64a08e8ab809d6e6854c028a1b9062f
BLAKE2b-256 4065e38e9854e1955187a22d9ecce3ca935f0297f005b0ec0c1ea4436f035752

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page