Petyr
Affine Tranformation and Homography library for Python
Install / Use
/learn @safwankdb/PetyrREADME
petyr
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
pip3 install petyr
Or, build from source
pip3 install git+https://github.com/safwankdb/petyr
Usage
from petyr import Similarity, Affine, Homography
Affine, Similarity and Homography derive from the Transform2D base class which implements all the basic operations.
Applying Transformation
p = np.array([[0,0],[1,0],[1,1],[0,1]])
rotate_and_move = Affine().rotate(90).translate(2,1)
q = rotate_and_move * p
pt = Homography.from_elements([1,0,0,0,1,0,0.1,0.2,1])
r = pt * p
Finding Transformation
at = Affine.from_points(p, q)
pt = Homography.from_points(p, q)
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
at = Affine()
at.translate(1, 3)
at.scale(1.05, 2)
at.rotate(45, degrees=True)
at.shear(10, 45)
at_inv = at.invert()
Same goes for Homography and Transform2D objects.
Chaining
Chaining Operations
Mutiple operations can be chained together.
at = Affine()
at.scale(2,2).rotate(90)
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.
a = Affine()
a.translate(2,3)
b = Homography()
b.scale(4,5)
c = a * b
Testing
To run the inbuilt unit tests,
git clone https://github.com/safwankdb/petyr
cd petyr
python3 -m unittest -v
Maintainers
TODO
- [ ] Add
Rigidtransformations. - [x] Implement
petyr.Homography. - [x] Add unit tests.
- [x] Vectorize
from_points. - [x] Add unit tests for
AffineandHomographyclasses as well. - [x] Add
Similarityclass for similarity transforms. - [x] Update all tests for similarity transform
- [ ] Update README with Similarity Transform
- [ ] Generate complete documentation.
- [ ] Move documentation to somwhere other than README.
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
83.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
339.3kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
