imutils
A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
A Python package of convenience functions that simplify common OpenCV image operations like rotating, resizing, and translating images, plus helpers for webcam video streams and color format fixes.
This repository contains a Python package called imutils, which is a small collection of helper functions for working with images in OpenCV. OpenCV is a popular library for computer vision tasks, but many of its built-in operations require writing several lines of code to accomplish something fairly basic, like rotating or resizing an image while keeping its proportions intact. imutils wraps those operations into simpler, shorter calls so developers spend less time on boilerplate.
The package covers a handful of common image operations. The translate function shifts an image left, right, up, or down without requiring you to build the underlying transformation matrix by hand. The rotate function handles rotation, and a separate rotate_bound variant makes sure the entire rotated image stays visible instead of getting clipped at the edges. The resize function scales images up or down while automatically preserving the aspect ratio, which is easy to get wrong when doing it manually. There is also a skeletonize function that reduces shapes in a black-and-white image to their bare outlines, which is useful in certain shape detection tasks.
Some utility functions handle common friction points in OpenCV workflows. One converts an image loaded from a web URL directly into the format OpenCV uses in memory. Another fixes a color ordering mismatch that occurs when you try to display an OpenCV image using the Matplotlib charting library. There are also helpers for checking which version of OpenCV is installed, and a find_function tool that lets you search OpenCV's function names by keyword when you can't remember the exact name.
The package also includes tools for working with video streams from webcams or video files, and supports threaded capture to keep frame reading from slowing down the main processing loop.
Installing imutils requires pip and assumes you already have OpenCV, NumPy, SciPy, and Matplotlib installed. The PyImageSearch blog, linked in the README, has detailed walkthroughs for most of the functions in the package.
Where it fits
- Resize an image while automatically preserving its aspect ratio with a single function call instead of manual calculations
- Rotate an image without clipping its edges using the rotate_bound helper
- Capture video from a webcam with threaded frame reading to prevent slow I/O from blocking your image processing loop
- Fix the color ordering mismatch that appears when displaying OpenCV images in Matplotlib