Skip to main content

Bounding box clustering: group overlapped box into a large box

Project description

boxjoin

Install

pip install boxjoin

How it works

It works by detecting overlapped bounding box. Overlapped box will be grouped as one large bouding box. It is useful for grouping some bounding box (from YOLO, etc). But, currently it is not label aware and working based on coordinate.

Showcase

Group of people

Inference Grouped

Walking at the park

Inference Grouped

Group of text from Medium

Source: https://stackoverflow.com/questions/66490374/how-to-merge-nearby-bounding-boxes-opencv

Medium Grouped

Example

import boxjoin
import cv2

filename = "people-walking-original.jpg"
save_path = "people-walking-original-grouped.jpg"

img = cv2.imread(filename)

# Each box is in the format of [x1, y1, x2, y2]
# They can be extracted from YOLO output.
# This example is simply for demonstration
boxes = [
    [143, 91, 174, 118],
    [142, 98, 164, 123],
    [143, 87, 204, 165],
    [127, 118, 225, 181],
    [371, 195, 386, 220],
    [334, 152, 380, 243],
    [293, 193, 335, 301],
    [470, 136, 494, 167],
    [464, 123, 500, 214],
    [565, 234, 586, 260],
    [554, 178, 582, 261],
    [219, 313, 261, 405],
    [182, 297, 223, 387],
    [151, 315, 196, 421]
]

clusters = boxjoin.BoxClustering(boxes=boxes, img=img, save_path=save_path)

for i, cluster in enumerate(clusters):
    print(f"Cluster {i}: {cluster}")
    # The output should look like this:
    # Cluster 0: [[143, 91, 174, 118], [142, 98, 164, 123], [143, 87, 204, 165], [127, 118, 225, 181]]
    # Cluster 1: [[371, 195, 386, 220], [334, 152, 380, 243], [293, 193, 335, 301]]
    # Cluster 2: [[470, 136, 494, 167], [464, 123, 500, 214]]
    # Cluster 3: [[565, 234, 586, 260], [554, 178, 582, 261]]
    # Cluster 4: [[219, 313, 261, 405], [182, 297, 223, 387], [151, 315, 196, 421]]

Full example can be found in example directory

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

boxjoin-0.3.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

boxjoin-0.3.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file boxjoin-0.3.2.tar.gz.

File metadata

  • Download URL: boxjoin-0.3.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for boxjoin-0.3.2.tar.gz
Algorithm Hash digest
SHA256 2d7fdfa26de918c079d46112be3f1c4eac45a0749b876c6a81bd180e0afca460
MD5 e4eb983c58d4e6cb6c5b37be810b028f
BLAKE2b-256 2a6a8189a11d90622decb39b0484285561d35dc291584fd57bc3b54d41a567ae

See more details on using hashes here.

File details

Details for the file boxjoin-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: boxjoin-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for boxjoin-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2097ecd6b41fd0fb9a4006736e5dbef0ab7307ae81ad02f4accb273170da993
MD5 75b5dec86f07ac94b9d62befcdc1451c
BLAKE2b-256 751be6d657c83e53504be102d54292b60fa369dce41db8cf5d5c9a96285f05cd

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