A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and both Python 2.7 and Python 3.
For more information, along with a detailed code review check out the following posts on the PyImageSearch.com blog:
- http://www.pyimagesearch.com/2015/02/02/just-open-sourced-personal-imutils-package-series-opencv-convenience-functions/
- http://www.pyimagesearch.com/2015/03/02/convert-url-to-image-with-python-and-opencv/
- http://www.pyimagesearch.com/2015/04/06/zero-parameter-automatic-canny-edge-detection-with-python-and-opencv/
- http://www.pyimagesearch.com/2014/09/01/build-kick-ass-mobile-document-scanner-just-5-minutes/
- http://www.pyimagesearch.com/2015/08/10/checking-your-opencv-version-using-python/
Provided you already have NumPy, SciPy, Matplotlib, and OpenCV already installed, the imutils
package is completely pip
-installable:
$ pip install imutils
OpenCV can be a big, hard to navigate library, especially if you are just getting started learning computer vision and image processing. The find_function
method allows you to quickly search function names across modules (and optionally sub-modules) to find the function you are looking for.
Let's find all function names that contain the text contour
:
import imutils imutils.find_function("contour")
1. contourArea 2. drawContours 3. findContours 4. isContourConvex
The contourArea
function could therefore be accessed via: cv2.contourArea
Translation is the shifting of an image in either the x or y direction. To translate an image in OpenCV you would need to supply the (x, y)-shift, denoted as (tx, ty) to construct the translation matrix M:
And from there, you would need to apply the cv2.warpAffine
function.
Instead of manually constructing the translation matrix M and calling cv2.warpAffine
, you can simply make a call to the translate
function of imutils
.
# translate the image x=25 pixels to the right and y=75 pixels up translated = imutils.translate(workspace, 25, -75)