Skip to main content

Utilities for OpenCV in Python

Project description

cvpack

OpenCV extensions for more Pythonic interactions.

Install

pip install cvpack-alkasm

Types

cvpack includes types that exist in the main C++ OpenCV codebase, but that aren't included in the Python bindings. They are compatible as arguments to OpenCV functions, and they implement the same interfaces (with some new additions). The types that are included are Point, Point3, Rect, RotatedRect, Size, TermCriteria. They are implemented as namedtuples, and as such are immutable.

import cvpack

img = cvpack.imread("img.png")
p1 = cvpack.Point(50, 50)
p2 = cvpack.Point(100, 100)
rect = cvpack.Rect.from_points(p1, p2)
roi = img[rect.slice()]
roi_size = cvpack.Size.from_image(roi)
assert roi_size == rect.size()

The overloaded constructors are available as from_ classmethods, like from_points shown above. They also follow the same operator overloads that OpenCV has: two points summed is a point, adding a point to a rectangle shifts it, you can & two rectangles to get the intersection as a new rectangle, and so on.

Image IO

Wrappers for imread, imwrite, and imshow simplify usage by checking errors and allowing path-like objects for path arguments. Additionally, cvpack provides functions to read images from a URL (imread_url), display to a browser (imshow_browser) for statically serving images while working in an interpreter, and displaying images in a Jupyter notebook (imshow_jupyter) as HTML directly rather than the typical plt.imshow from matplotlib. Some other utilities related to display are also included.

from pathlib import Path
import cvpack

for path in Path("folder").glob("*.png"):
    img = cvpack.imread(path)
    big = cvpack.add_grid(cvpack.enlarge(img))
    cvpack.imshow_browser(img, route=str(path))

Video IO

Working with video requires acquiring and releasing resources, so cvpack provides context managers for video readers and writers which wrap the classes from OpenCV. Reading video frames is simplified to iterating over the capture object.

import cv2
import cvpack

with cvpack.VideoCapture("video.mp4") as cap:
    with cvpack.VideoWriter("reversed.mp4", fourcc=int(cap.fourcc), fps=cap.fps) as writer:
        for frame in cap:
            flipped = cv2.flip(frame, 0)
            writer.write(flipped)

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

cvpack-alkasm-1.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

cvpack_alkasm-1.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file cvpack-alkasm-1.1.0.tar.gz.

File metadata

  • Download URL: cvpack-alkasm-1.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.7.7 Darwin/18.7.0

File hashes

Hashes for cvpack-alkasm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 68c59689580424e7e9c58e04edd6e79d5c5d6fdaa6b3eff447064ca541385a8c
MD5 bfdfe4761e7ca61cb257dace51a0decd
BLAKE2b-256 2f51197280f285f9b9f736cf4c48fcb3db57c535d03f67a0228b6e9b4bc0ade4

See more details on using hashes here.

File details

Details for the file cvpack_alkasm-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: cvpack_alkasm-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.7.7 Darwin/18.7.0

File hashes

Hashes for cvpack_alkasm-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28b9e236442c58634b62e757f0c1166429bb54242f398dab9aae881716cc369e
MD5 1d5b54738541b02a1a897d1d3cd655a9
BLAKE2b-256 ea8460f26576b7c8e4ef1a709b35aa1099d29553d03ef4f610818f5de8fcaaba

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