Skip to main content

A bunch of useful wrappers around opencv-python library

Project description

PyCVutils

A bunch of useful wrappers around opencv-python library

Installation:

pip install pycvutils

before using you should manually install any opencv version you like: pip install opencv-python or opencv-python-headless or opencv-contrib-python or opencv-contrib-python-headlesss

Examples:

Let's work with such binary image:

face_large.png

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.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)

face_crop_pad.png

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

face_padded.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycvutils-0.1.2.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

pycvutils-0.1.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file pycvutils-0.1.2.tar.gz.

File metadata

  • Download URL: pycvutils-0.1.2.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.1

File hashes

Hashes for pycvutils-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fb5da7f05255e1eaeb72f3f40114ade08e736d63a48d20e683ef5d05dbd8ef3c
MD5 8e8b33e39d8932dd71f7c4a84ac316d9
BLAKE2b-256 5ca55ef3f8c239b4d182a8f80c6df29598c7e1d216318d38f18446427a96b173

See more details on using hashes here.

File details

Details for the file pycvutils-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pycvutils-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.1

File hashes

Hashes for pycvutils-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8843854b1363230ec0b3020771b7e91b04b4885824d7204c08c9eefabcb53138
MD5 bcb77868997aa88dd45fdaee3a892e20
BLAKE2b-256 eae3183e15e1fae820e6c086a0516ff32faac5d804c48b4b718cc3266bd4f205

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page