项目作者: safwankdb

项目描述 :
Affine Tranformation and Homography library for Python
高级语言: Python
项目地址: git://github.com/safwankdb/petyr.git
创建时间: 2020-05-25T13:32:25Z
项目社区:https://github.com/safwankdb/petyr

开源协议:

下载


petyr

Build Status codecov
PyPI
Downloads
Downloads

Affine, Similarity Transformations and Homography for Python. Fast and chainable inplace operations. Produced matrix can be used with cv2.warpAffine and cv2.warpPerspective.

Installation

For stable release

  1. pip3 install petyr

Or, build from source

  1. pip3 install git+https://github.com/safwankdb/petyr

Usage

  1. from petyr import Similarity, Affine, Homography

Affine, Similarity and Homography derive from the Transform2D base class which implements all the basic operations.

Applying Transformation

  1. p = np.array([[0,0],[1,0],[1,1],[0,1]])
  2. rotate_and_move = Affine().rotate(90).translate(2,1)
  3. q = rotate_and_move * p
  4. pt = Homography.from_elements([1,0,0,0,1,0,0.1,0.2,1])
  5. r = pt * p

Finding Transformation

  1. at = Affine.from_points(p, q)
  2. pt = Homography.from_points(p, q)
  3. st = Similarity.from_points(p, q)

Basic Operations

These operations modify the object in-place except for invert() which return a new object.

  • Translation
  • Scaling
  • Shearing
  • Rotation
  • Inversion
  • Reset
  1. at = Affine()
  2. at.translate(1, 3)
  3. at.scale(1.05, 2)
  4. at.rotate(45, degrees=True)
  5. at.shear(10, 45)
  6. at_inv = at.invert()

Same goes for Homography and Transform2D objects.

Chaining

Chaining Operations

Mutiple operations can be chained together.

  1. at = Affine()
  2. at.scale(2,2).rotate(90)
  3. at.shear(10, 0).translate(-3, 4)

Chaining Transforms

Multiple transforms can be multiplied together. This is a non-commutative operation. The rightmost transform will be applied first.

  1. a = Affine()
  2. a.translate(2,3)
  3. b = Homography()
  4. b.scale(4,5)
  5. c = a * b

Testing

To run the inbuilt unit tests,

  1. git clone https://github.com/safwankdb/petyr
  2. cd petyr
  3. python3 -m unittest -v

Maintainers

TODO

  • Add Rigid transformations.
  • Implement petyr.Homography.
  • Add unit tests.
  • Vectorize from_points.
  • Add unit tests for Affine and Homography classes as well.
  • Add Similarity class for similarity transforms.
  • Update all tests for similarity transform
  • Update README with Similarity Transform
  • Generate complete documentation.
  • Move documentation to somwhere other than README.