PyCVutils
A bunch of useful wrappers around opencv-python library
Installation:
pip install pycvutils
You can install opencv separately. But just for fun, some extra options exist:
pip install pycvutils[opencv] - adds opencv-python as a subdependency.
pip install pycvutils[headless] - adds opencv-python-headless as a subdependency.
pip install pycvutils[contrib] - adds opencv-contrib-python as a subdependency.
pip install pycvutils[contrib-headless] - adds opencv-contrib-python-headless as a subdependency.
Be aware that different
opencvversions are incompatible with each other.
Examples:
Let's work with such binary image:
import cv2
from pycvutils import convert
from pycvutils.blobs import get_bright_rect
face_img = cv2.imread("docs/img_samples/face.png")
assert get_bright_rect(face_img) == (1, 2, 10, 7)
# works with 3 channels arrays and boolean arrays too
face_img = convert.bgr_to_gray(face_img)
assert get_bright_rect(face_img) == (1, 2, 10, 7)
import cv2
from pycvutils.blobs import get_all_borders
face_img = cv2.imread("docs/img_samples/face.png", flags=cv2.IMREAD_GRAYSCALE)
face_img = face_img.any(axis=0)
assert tuple(get_all_borders(face_img)) == ((3, 6), (7, 10))
import cv2
from pycvutils.brightness import crop_bright_area_and_pad
face_img = cv2.imread("docs/img_samples/face.png")
# useful for colored images
assert crop_bright_area_and_pad(face_img, pad_size=5).shape == (15, 19, 3)
import cv2
from pycvutils.brightness import has_any_bright_border, has_any_bright_corner
face_img = cv2.imread("docs/img_samples/face.png")
# returns True if any border has non-zero pixel
assert not has_any_bright_border(face_img)
# returns True if any corner pixel is non-zero
assert not has_any_bright_corner(face_img)
import cv2
from pycvutils.channels import split_view
face_img = cv2.imread("docs/img_samples/face.png")
# works like cv2.split, but returns views instead of copies
views = split_view(face_img)
assert isinstance(views, tuple)
assert len(views) == 3
assert (views[0].base == face_img).all() # 'is' doesn't work for some reason
import cv2
from pycvutils.filling import brighten_areas_near_borders, flood_fill_binary
face_img = cv2.imread("docs/img_samples/face.png", flags=cv2.IMREAD_GRAYSCALE)
# wrapper around cv2.floodFill
assert (flood_fill_binary(face_img, x_y=(1, 1)) == 255).all()
# fills with white any black area touching borders of image
assert (brighten_areas_near_borders(face_img) == 255).all()
import cv2
from pycvutils.matching import compare_one_to_one, compare_with_crop
face_img = cv2.imread("docs/img_samples/face.png")
template = face_img[5:-2, 6:-2]
# makes small crop before making comparison
assert compare_with_crop(face_img, template, crop_ratio=0.1) == 1.0
# resize template to size of original img before making comparison
assert compare_one_to_one(face_img, template) != 1.0
import cv2
from pycvutils import padding
face_img = cv2.imread("docs/img_samples/face.png", flags=cv2.IMREAD_GRAYSCALE)
padded = padding.unequal(face_img, value=125, top=2, left=2, right=1)
assert padded.shape[0] == face_img.shape[0] + 2
assert padded.shape[1] == face_img.shape[1] + 3
Metadata
Release files for PyCVutils 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycvutils-0.1.6.tar.gz | 11.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycvutils-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.3 kB
Release files / pycvutils-0.1.6.tar.gz
| Download URL | pycvutils-0.1.6.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86fd2d85391e91c349d3c8beddf1532627e182c3a2996a4963e1a0a30f674c80
|
|
BLAKE2b-256 checksum How to use checksums |
18c05407f97ad706249c67fba283751dd431d567a06b3556422d9bb5ebb463f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.18
|
Release files / pycvutils-0.1.6-py3-none-any.whl
| Download URL | pycvutils-0.1.6-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed93698c237961a577a0777d1a91cd22e5851d7aadc11c96aa07135f9c26710f
|
|
BLAKE2b-256 checksum How to use checksums |
5b6a96fd8ad1dfbfac018394b7a9138bda181584e38a93cfa11962257a9cbb4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.18
|