Deprecated --- check for updated CV-related tools.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore Adding example output to repo Jul 12, 2017
LICENSE Update Sep 22, 2018


This repo is deprecated in favor of a superset of tools


Providing a padded version of OpenCV's warpAffine() and warpPerspective() functions.

Example image


import padtransf
src_warped, dst_padded = padtransf.warpPerspectivePadded(src, dst, homography)
src_warped, dst_padded = padtransf.warpAffinePadded(src, dst, affine_transf)


test/         contains test images and ground truth homographies; from Oxford's VGG
.gitignore    self-explanatory
LICENSE       MIT License statement     this file
example.png   an example image showing the padding extent    an example script to show usage and compare with standard OpenCV functions  the python module containing the two padded warping functions


Read my Stack Overflow answer which inspired this repository.

When OpenCV warps an image, any pixels that get warped outside of the bounds of dsize are excluded from the resulting warped image. While giving a larger dsize can help retain pixels that get mapped to larger pixel locations, you cannot recover the pixel values that get mapped to negative pixel locations.

The solution requires three steps:

  1. Calculate the warped pixel locations manually
  2. Add translation to the transformation by however much is necessary in pixels to send all pixels values to positive numbers
  3. Pad the destination image to account for the shift and add padding to the edge of the warp

Both warpAffinePadded and warpPerspectivePadded complete this task using minimal overhead and no user input aside from the same information that would be needed for OpenCV's warpAffine() and warpPerspective().


Please feel free to submit any suggestions you have or bugs you find via a GitHub issue. Ports to C++ would be lovely if anyone is bored.

test dataset

The images and ground truth homographies provided in test/ are from Oxford's Visual Geometry Group.