Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
This package provides quick and easy way to estimate the camera transition on the z axis given an optical flow.
This is a small python package to estimate the camera motion/zoom on the z axis.
what it is:
what it is NOT:
pip install cam-motion-field
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
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.
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.
[1] Srinivasan, M.V., Venkatesh, S., Hosie, R.: Qualitative estimation of camera motion parameters from video sequences. Pattern Recognition 30(4), 593–606 (1997)
@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}
}
FAQs
This package provides quick and easy way to estimate the camera transition on the z axis given an optical flow.
We found that camera-z-transition demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.