Skip to main content

YOLO segmentation utilities for video streams

Project description

mini_vision

Simple Python library for object segmentation in video streams using YOLO models.

The goal of this library is to provide a modular pipeline to:

  • consume video streams
  • perform object segmentation
  • render contours or masks

The library follows data-oriented design and low coupling principles, allowing easy replacement of computer vision models.


Installation

pip install mini-vision

Usage

Example showing how to use vision-seg to consume a video stream, run YOLO segmentation, and render object contours.

Import the library

from vision_seg import (
    YoloSegmenter,
    SegmentationRenderer,
    WSFrameClient
)

Components:

Component Description
YoloSegmenter Runs object segmentation using a YOLO segmentation model
SegmentationRenderer Draws segmentation contours on the frame
WSFrameClient Connects to a WebSocket video stream and yields frames

YoloSegmenter

Runs object segmentation using a YOLO segmentation model.

segmenter = YoloSegmenter("yolov8n-seg.pt")
detections = segmenter.segment(frame)

SegmentationRenderer

Responsible for rendering segmentation contours on frames.

renderer = SegmentationRenderer()
frame = renderer.draw(
    frame,
    detections,
    mode="contour",
    detect_object=["car","person","dog"],
    detect_color=["gold","neon_pink","lime"],
    thickness=2
)
JSON Output (optional)

SegmentationRenderer can optionally return structured detection data in JSON format. This allows integration with logging systems, APIs, analytics pipelines, or other downstream processing tools. To enable this feature, pass return_json=True

frame, data = renderer.draw(
    frame,
    detections,
    mode="contour",
    detect_object=["car","person","dog"],
    detect_color=["gold","neon_pink","lime"],
    thickness=2,
    return_json=True
)

Example JSON output:

{
  "detections": [
    {
      "label": "person",
      "confidence": 0.92,
      "bbox": [120, 80, 240, 300]
    },
    {
      "label": "car",
      "confidence": 0.88,
      "bbox": [400, 210, 560, 350]
    }
  ]
}

If return_json is not enabled, the renderer behaves normally and only returns the processed frame.

TOON Output

the renderer can also return detections in TOON format, a lightweight text representation designed for agent pipelines, logging, and token-efficient LLM processing. Enable it using return_toon=True

frame, toon = renderer.draw(
    frame,
    detections,
    return_toon=True
)

Example TOON output:

frame_width=1280 frame_height=720
label=person x=412 y=210 w=120 h=260 cx=472 cy=340 area=31200 score=0.91
label=car x=102 y=320 w=180 h=90 cx=192 cy=365 area=16200 score=0.88

WSFrameClient

Connects to a WebSocket video stream and yields frames.

client = WSFrameClient("ws://127.0.0.1:8000/ws/frames")
async for frame in client.frames():

The image was created using AI, but the detection was done by the library.

descricao

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

mini_vision-0.2.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

mini_vision-0.2.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mini_vision-0.2.4.tar.gz.

File metadata

  • Download URL: mini_vision-0.2.4.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mini_vision-0.2.4.tar.gz
Algorithm Hash digest
SHA256 7c1fcc6334b152bc4bd57396ecc0d564c91202f95cf4b9dd2dc6202ecf0c6d88
MD5 0487266a233849a3bd559cd7723310b7
BLAKE2b-256 cc845ad1362f4d88bd822af92eb4f87490d3b8ea45f81faf36cd6a39d0938331

See more details on using hashes here.

File details

Details for the file mini_vision-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: mini_vision-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mini_vision-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 23abc118770508cf97651b640349f5f5d7ac76a71ab9857ca2ecf1ec94fe6049
MD5 326f44c6643cb7dbee41e5b494ed8bc2
BLAKE2b-256 74c8b15a3effb59fb598ee70e4c4e638cb7e3bf0f5dd0c0ce08d066530458f91

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