Skip to main content

compute the iou, slice picture etc.

Project description

ai_tool

ai tool

slice picture

from ai_tool.img_slide import yield_sub_img
# yield the sub image from the jpg
for bbox, sub_img in yield_sub_img("test.jpg", 0, 0, 180, 60):
    clip = "-".join([str(x) for x in bbox])
    print("sub img:{}".format(clip))
    cv2.imshow(clip, sub_img)
    cv2.waitKey(0)

IoU

compute the iou for tow boxes,

example box1 1, 2, 101, 102. location(1,2) is left-up, location(101,102) is right-down.

from ai_tool.bbox import BBox
bbox1 = BBox([1, 2, 101, 102])
bbox2 = BBox([11, 12, 121, 122])
iou = bbox1 / bbox2
print("iou", iou)
assert iou > 0.5

print('box1 S is', bbox1.S)
print('box1 & box2', bbox1 & bbox2)
print('box1 == box2', bbox1 == bbox2)
print('merge box1 + box2', bbox1 + bbox2)
print('merge box1 | box2', bbox1 | bbox2)

result is :

iou 0.5785714285714286
box1 S is 10000
box1 & box2 [11, 12, 101, 102]
box1 == box2 True
merge box1 + box2 [1, 2, 121, 122]
merge box1 | box2 [1, 2, 121, 122]

multi bbox operation

from ai_tool.bbox import BBoxes, BBox
bb1 = BBoxes(iou_thresh=0.6)
bb2 = BBoxes()

bb1.append([1,2, 101, 102])
bb1.append([1000, 2, 1101, 102])

bb2.append([11, 12, 111, 112])
bb2.append([1, 1002, 101, 1102])

# judge the bbox in bb1
print("[5, 5, 100, 100] in bb1", BBox([5, 5, 100, 100]) in bb1)
print("[100, 5, 200, 100] in bb1", BBox([100, 5, 200, 100]) in bb1)

# bb1 & bb2
print("bb1 & bb2", bb1 & bb2)
print("bb1 - bb2", bb1 - bb2)
print("bb2 - bb1", bb2 - bb1)

result is

[5, 5, 100, 100] in bb1 True
[100, 5, 200, 100] in bb1 False
bb1 & bb2 [[1, 2, 101, 102]]
bb1 - bb2 [[1000, 2, 1101, 102]]
bb2 - bb1 [[1, 1002, 101, 1102]]

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

ai_tool-1.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

ai_tool-1.4-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ai_tool-1.4.tar.gz.

File metadata

  • Download URL: ai_tool-1.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for ai_tool-1.4.tar.gz
Algorithm Hash digest
SHA256 652e6be827a3cecec038c30f4cb0158b66536719530e97e47c287e56d5e4caf4
MD5 871d20dc4e2d5051eeea18b3789a7942
BLAKE2b-256 f1f84ce50ea6212f293c3f409c5b5487f59669cd3d8271e467d09f7ab5dd8669

See more details on using hashes here.

File details

Details for the file ai_tool-1.4-py3-none-any.whl.

File metadata

  • Download URL: ai_tool-1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for ai_tool-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7441c6858c3f322abc73259a00585e50f6a2878fc8d9f7f901e6f1559199d623
MD5 a032cc8534aa306b7b79be9bd78f719f
BLAKE2b-256 496edb37c16dfb6cc45111fb23139d0e581481a5cd3c6a0ce4f667ec8b04f0f0

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