Skip to main content

Simplifies OpenCV functionalities for image and video i/o and debug-windows.

Project description

OCV_Utils

Simplifies OpenCV functionalities for image and video i/o and debug-windows.

Main Features:

  • uses rgb instead of bgr by default for image and video i/o
  • adds a loop and boomerang mode for video player
  • imshow() accepts lists of images that will be automatically displayed next to each other, independent of their formats
  • easier trackbar integration

Install

pip3 install ocv_utils

Usage

Image Loading

Load image and convert it to a certain channel type definition. Supported types rgb, rgba, gray

from ocv_utils import load_image

img = load_image("my_image.png", channels="rgba")

Video Reading

Play modes: ["normal", "loop", "boomerang"]

from ocv_utils import VideoReader

video = VideoReader("video.mp4", play_mode="normal")

# cv2 like
while True:
    ret, frame = video.read()
    if not ret: # CAUTION: for play_mode "loop" and "boomerang" `ret` is the frame id, so break will be called at frame 0.
        break   # Don't use this with play_mode "loop" or "boomerang"

# Or read certain frame
ret, frame = video.read(frame_id=42)

Video Writing

from ocv_utils import VideoWriter
import numpy as np

img = np.zeros((512, 512, 3))

video_writer = VideoWriter(path="video.mp4", fps=30, channels="rgb")
for i in range(1000):
    video_writer.add_frame(img)

# or with horizontal stacking 
video_writer = VideoWriter("hstack.mp4")
for i in range(1000):
    video_writer.add_frame([img, img])

Window

import numpy as np
from ocv_utils import Window

window = Window(delay=0)
window.add_trackbar("x", 1, 255)
window.add_key_action(ord('h'), lambda: print("Hello World!"))

img1 = np.zeros((256, 256), dtype=np.uint8)
img2 = np.random.random((256, 256, 3))

trackbar_values = window.imshow([img1, img2])
print("Trackbar Values:", trackbar_values) # Trackbar Values: {'x': 1}

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

ocv_utils-0.0.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ocv_utils-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file ocv_utils-0.0.2.tar.gz.

File metadata

  • Download URL: ocv_utils-0.0.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for ocv_utils-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a5eed1549ee0b872f0090491926f2d0ebc23f81fd6037f7d120b199bf982c5dd
MD5 6485bc125c7bbf1add4eac6ba63d2379
BLAKE2b-256 2719e616fb6933d9ea72ed99862c44ce4a5ef26766b2ec3d23fdd5d80a5717f9

See more details on using hashes here.

File details

Details for the file ocv_utils-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ocv_utils-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for ocv_utils-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6db71cb75a792c07032e36c42dd245f5080598d8956f4dfaae27fbc70661f4c
MD5 f2b55d02e9c55cb147e2005a125cbfff
BLAKE2b-256 d855fae8c5a3af4d58152ba3a93a88f184bc6af1d610f7b86888c2a9ac32bf1a

See more details on using hashes here.

Supported by

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