ImageToolsMadeEasy
Tools to simplify using face detection and ArUco recognition with PIL image objects
About
This brings a range of CV2 image functionlaity into a form that is easy to use with PIL Image objects. The module was created to allow me to introduce image based functionality to my students while keeping things as simple as possible (switching between PIL and CV2 was an unnecessary complication I felt).
Key functions currently provided are:
- Taking a photo with the built in camera, returning a PIL image
- Face detection within a PIL image
- ArUco marker detection within a PIL image
Usage: Camera
A basic example
camera = ImageTools.Camera()
img = camera.take_photo()
img.save("my photo.png", "png")
img.show()
Usage: Face detection
For the face detection function to work, you must supply a file path to a haarcascade file. You can obtain the relevant file from https://github.com/opencv/opencv/tree/master/data/haarcascades
The ImageTools.get_faces() function will return a list of lists. The outer list represents the number of faces seen, where as the inner list represent the coordinates for an individual face being the [left, top, width, height] pixel values.
To get the coordinates of each face in an image
from PIL import Image
import ImageTools
# ...
camera = ImageTools.Camera()
img = camera.take_photo()
faces = ImageTools.get_faces(img, "haarcascade_frontalface_default.xml")
print(faces)
To obtain seperate jpg image for each face detected
from PIL import Image
import ImageTools
# ...
counter = 0
camera = ImageTools.Camera()
img = camera.take_photo()
faces = ImageTools.get_faces(img, "haarcascade_frontalface_default.xml")
for a_face in faces: # for each individual face in the list of faces...
x,y,w,h = a_face # extract the left, top, width and height locations of a face
a_face_img = img.crop((x,y,x+w,y+h))
a_face_img.save(f"face_{counter:2}.jpg", "jpg")
a_face_img.show()
counter = counter + 1
To use a drawing tool to put rectangles highlighting the faces found in the original image...
from PIL import Image, ImageDraw
import ImageTools
# ...
camera = ImageTools.Camera()
img = camera.take_photo()
draw = ImageDraw.Draw(img) # create the drawing object
faces = ImageTools.get_faces(img, "haarcascade_frontalface_default.xml")
for a_face in faces: # for each individual face in the list of faces...
x,y,w,h = a_face # extract the left, top, width and height locations of a face
draw.rectangle((x,y,x+w,y+h), outline="#ffff00", width=5) # draw a rectangle around the face
# show the final image, highlighting each face
img.show()
Uuage: ArUco markers
The ImageTools.get_aruco() function when provided a PIL Image object as a parameter, will return a Python list of the ArUco markers it detected within the image.
from PIL import Image
import ImageTools
# ....
camera = ImageTools.Camera()
image = camera.take_photo()
markers = ImageTools.get_aruco(image)
if 70 in markers:
print("I saw ArUco marker 70")
if 71 in markers:
print("I saw ArUco marker 71")
if 72 in markers:
print("I saw ArUco marker 72")
- ArUco Markers are simple black and white printed codes (think of them as QR-code-lite) that resolve to an integer number.
- The OpenCV library has built in functionality for recognising these markers.
- The Python implementation of OpenCV detection was based on this stackoverflow
- Aruco markers I printed to test where were generated from here
- The code has been designed for the "4x4_1000" style of aruco markers but you can easily change that in the
camera_got_imagefunction if you wish
Install
pip install ImageToolsMadeEAsy
Dependencies
These should all be installed for you automatically, so are just provided for informational purposes.
opencv-contrib-pythonnumpyPIL
Author
Paul Baumgarten 2019 @ https://github.com/paulbaumgarten/ImageToolsMadeEasy
Metadata
Release files for ImageToolsMadeEasy 2019.12.30
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ImageToolsMadeEasy-2019.12.30.tar.gz | 5.0 kB | Without provenance | Details for ImageToolsMadeEasy-2019.12.30.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ImageToolsMadeEasy-2019.12.30-py3-none-any.whl | Python 3 | none | any | Details for ImageToolsMadeEasy-2019.12.30-py3-none-any.whl |
Total release size: 10.3 kB
Release files / ImageToolsMadeEasy-2019.12.30.tar.gz
| Download URL | ImageToolsMadeEasy-2019.12.30.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7da3e9e3ee8086213606ebe9655fe9a1ca9dfbd680d5dd461f745d64790c5e41
|
|
BLAKE2b-256 checksum How to use checksums |
929bd081cbc10a76696759c1f9fa7731d4cacd45e3c66c6eb55a90e35bbb3ada
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / ImageToolsMadeEasy-2019.12.30-py3-none-any.whl
| Download URL | ImageToolsMadeEasy-2019.12.30-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
211539595fb5acfcf48a7d69f97b6a808843d3f47800a2b04b97a1128a8ca315
|
|
BLAKE2b-256 checksum How to use checksums |
d705c202431ee006e29f32c2733dcf95a0a2ca8d08a3c1b1fbad4ca70e0c7038
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for ImageToolsMadeEasy 2019.12.30
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.