kotoha 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. kotoha-0.1.0/PKG-INFO +206 -0
  2. kotoha-0.1.0/README.md +173 -0
  3. kotoha-0.1.0/kotoha/__init__.py +163 -0
  4. kotoha-0.1.0/kotoha/annotation.py +126 -0
  5. kotoha-0.1.0/kotoha/common.py +421 -0
  6. kotoha-0.1.0/kotoha/dataset_info.py +21 -0
  7. kotoha-0.1.0/kotoha/eval/__init__.py +23 -0
  8. kotoha-0.1.0/kotoha/eval/cls.py +465 -0
  9. kotoha-0.1.0/kotoha/eval/det.py +486 -0
  10. kotoha-0.1.0/kotoha/eval/pose.py +81 -0
  11. kotoha-0.1.0/kotoha/eval/reid.py +216 -0
  12. kotoha-0.1.0/kotoha/eval/text.py +357 -0
  13. kotoha-0.1.0/kotoha/experiments/mcdm/__init__.py +17 -0
  14. kotoha-0.1.0/kotoha/experiments/mcdm/_core.py +161 -0
  15. kotoha-0.1.0/kotoha/experiments/mcdm/ranking.py +79 -0
  16. kotoha-0.1.0/kotoha/experiments/mcdm/weights.py +113 -0
  17. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/__init__.py +3 -0
  18. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/byte_track.py +94 -0
  19. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/tracker/__init__.py +0 -0
  20. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/tracker/basetrack.py +53 -0
  21. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/tracker/byte_tracker.py +349 -0
  22. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/tracker/kalman_filter.py +259 -0
  23. kotoha-0.1.0/kotoha/experiments/model/tracker/byte_track/tracker/matching.py +193 -0
  24. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/__init__.py +3 -0
  25. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/ocsort.py +27 -0
  26. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/tracker/__init__.py +0 -0
  27. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/tracker/association.py +381 -0
  28. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/tracker/kalmanfilter.py +1533 -0
  29. kotoha-0.1.0/kotoha/experiments/model/tracker/oc_sort/tracker/ocsort.py +343 -0
  30. kotoha-0.1.0/kotoha/experiments/voc.py +409 -0
  31. kotoha-0.1.0/kotoha/geo/__init__.py +17 -0
  32. kotoha-0.1.0/kotoha/geo/_types.py +263 -0
  33. kotoha-0.1.0/kotoha/geo/affine.py +51 -0
  34. kotoha-0.1.0/kotoha/geo/circle.py +33 -0
  35. kotoha-0.1.0/kotoha/geo/line.py +120 -0
  36. kotoha-0.1.0/kotoha/geo/polygon.py +62 -0
  37. kotoha-0.1.0/kotoha/geo/transform.py +29 -0
  38. kotoha-0.1.0/kotoha/image_filter/__init__.py +3 -0
  39. kotoha-0.1.0/kotoha/image_filter/cpp/__init__.py +3 -0
  40. kotoha-0.1.0/kotoha/image_filter/hashing.py +165 -0
  41. kotoha-0.1.0/kotoha/image_filter/image_filter.py +282 -0
  42. kotoha-0.1.0/kotoha/io.py +449 -0
  43. kotoha-0.1.0/kotoha/model/__init__.py +0 -0
  44. kotoha-0.1.0/kotoha/model/mmlab/__init__.py +3 -0
  45. kotoha-0.1.0/kotoha/model/mmlab/pose_heatmap.py +137 -0
  46. kotoha-0.1.0/kotoha/model/mmlab/utils.py +54 -0
  47. kotoha-0.1.0/kotoha/model/ultralytics/__init__.py +10 -0
  48. kotoha-0.1.0/kotoha/model/ultralytics/base.py +142 -0
  49. kotoha-0.1.0/kotoha/model/ultralytics/utils.py +314 -0
  50. kotoha-0.1.0/kotoha/model/ultralytics/yolo26sem.py +114 -0
  51. kotoha-0.1.0/kotoha/model/ultralytics/yolov5.py +110 -0
  52. kotoha-0.1.0/kotoha/model/ultralytics/yolov8.py +92 -0
  53. kotoha-0.1.0/kotoha/model/ultralytics/yolov8cls.py +138 -0
  54. kotoha-0.1.0/kotoha/model/ultralytics/yolov8obb.py +126 -0
  55. kotoha-0.1.0/kotoha/model/ultralytics/yolov8pose.py +134 -0
  56. kotoha-0.1.0/kotoha/model/ultralytics/yolov8seg.py +106 -0
  57. kotoha-0.1.0/kotoha/py.typed +1 -0
  58. kotoha-0.1.0/kotoha/typing.py +43 -0
  59. kotoha-0.1.0/kotoha/visual/__init__.py +20 -0
  60. kotoha-0.1.0/kotoha/visual/color.py +74 -0
  61. kotoha-0.1.0/kotoha/visual/visual.py +423 -0
  62. kotoha-0.1.0/kotoha.egg-info/PKG-INFO +206 -0
  63. kotoha-0.1.0/kotoha.egg-info/SOURCES.txt +81 -0
  64. kotoha-0.1.0/kotoha.egg-info/dependency_links.txt +1 -0
  65. kotoha-0.1.0/kotoha.egg-info/requires.txt +12 -0
  66. kotoha-0.1.0/kotoha.egg-info/top_level.txt +1 -0
  67. kotoha-0.1.0/pyproject.toml +78 -0
  68. kotoha-0.1.0/setup.cfg +4 -0
  69. kotoha-0.1.0/tests/test_color.py +28 -0
  70. kotoha-0.1.0/tests/test_common.py +87 -0
  71. kotoha-0.1.0/tests/test_eval.py +49 -0
  72. kotoha-0.1.0/tests/test_eval_public.py +149 -0
  73. kotoha-0.1.0/tests/test_geo.py +47 -0
  74. kotoha-0.1.0/tests/test_geo_public.py +65 -0
  75. kotoha-0.1.0/tests/test_image_filter.py +158 -0
  76. kotoha-0.1.0/tests/test_io.py +152 -0
  77. kotoha-0.1.0/tests/test_mcdm.py +50 -0
  78. kotoha-0.1.0/tests/test_model_providers.py +46 -0
  79. kotoha-0.1.0/tests/test_model_typing.py +98 -0
  80. kotoha-0.1.0/tests/test_typing.py +150 -0
  81. kotoha-0.1.0/tests/test_ultralytics_tasks.py +58 -0
  82. kotoha-0.1.0/tests/test_visual.py +74 -0
  83. kotoha-0.1.0/tests/test_vocio.py +9 -0
kotoha-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: kotoha
3
+ Version: 0.1.0
4
+ Summary: Image-processing utilities with geometry primitives, I/O helpers, visualization tools, and typed model outputs.
5
+ Keywords: image-processing
6
+ Classifier: Development Status :: 5 - Production/Stable
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Intended Audience :: Education
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Topic :: Software Development
15
+ Classifier: Topic :: Scientific/Engineering
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Operating System :: Microsoft :: Windows
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: opencv-python
23
+ Requires-Dist: numpy
24
+ Requires-Dist: pyyaml
25
+ Requires-Dist: xmltodict
26
+ Requires-Dist: requests
27
+ Requires-Dist: pillow
28
+ Requires-Dist: tqdm
29
+ Requires-Dist: matplotlib
30
+ Provides-Extra: model
31
+ Requires-Dist: onnx; extra == "model"
32
+ Requires-Dist: onnxruntime; extra == "model"
33
+
34
+ # kotoha
35
+
36
+ `kotoha` 是一个面向计算机视觉工程的 Python 工具箱。它把几何数据、算法结果、文件读写和可视化能力收拢为一套轻量且类型明确的接口,让传统视觉、人工标注和模型推理可以使用相同的数据结构协作。
37
+
38
+ ## 特性
39
+
40
+ - 不可变的二维几何类型:点、关键点、矩形、四边形、多边形、直线、圆和仿射变换。
41
+ - 统一的视觉任务结果:分类、检测、实例分割、姿态、旋转框和语义分割。
42
+ - 常用几何计算:面积、点线关系、线段相交、点在多边形内、旋转等。
43
+ - 面向工程的文件和图像工具:JSON、YAML、CSV、TXT、Pickle、XML、YOLO 标注及 Unicode 路径图像读写。
44
+ - OpenCV 绘制与视频读取工具。
45
+ - 可选的 ONNX YOLO 推理适配,包括检测、分割、姿态、分类和旋转框任务。
46
+
47
+ ## 安装
48
+
49
+ 需要 Python 3.12 或更高版本。
50
+
51
+ 安装核心功能:
52
+
53
+ ```bash
54
+ pip install kotoha
55
+ ```
56
+
57
+ 如需使用 ONNX 模型适配,安装 `model` 扩展:
58
+
59
+ ```bash
60
+ pip install "kotoha[model]"
61
+ ```
62
+
63
+ 从源码开发时,推荐使用 `uv`:
64
+
65
+ ```bash
66
+ uv sync --all-extras --dev
67
+ ```
68
+
69
+ ## 快速开始
70
+
71
+ ### 用几何类型表达和变换区域
72
+
73
+ `Rect`、`Polygon` 和 `KeyPoint` 都支持平移、缩放、旋转和镜像变换。坐标以 `(x, y)` 表示;`rotate_deg` 的角度单位为度。
74
+
75
+ ```python
76
+ from kotoha import Rect
77
+
78
+ box = Rect.from_xyxy(10, 20, 110, 80)
79
+ polygon = box.to_polygon()
80
+
81
+ rotated = polygon.rotate_deg(30, pivot=(60, 50))
82
+ print(rotated.to_list())
83
+ ```
84
+
85
+ ### 使用统一的检测结果
86
+
87
+ 模型输出、传统算法结果和人工标注都可以使用相同的标注对象。每种对象均提供 `to_dict()`,检测类结果还提供适合导出的 `to_numpy()`。
88
+
89
+ ```python
90
+ from kotoha import Detection, Rect
91
+
92
+ detection = Detection(
93
+ box=Rect.from_xyxy(10, 20, 110, 180),
94
+ score=0.95,
95
+ class_id=0,
96
+ label="person",
97
+ )
98
+
99
+ print(detection.to_dict())
100
+ # {'box': {'pmin': [10, 20], 'pmax': [110, 180]}, ...}
101
+ ```
102
+
103
+ 可用的结果类型如下:
104
+
105
+ | 类型 | 用途 |
106
+ | --- | --- |
107
+ | `Classification` | 图像分类的类别与置信度 |
108
+ | `Detection` | 轴对齐目标框 |
109
+ | `SegmentationDetection` | 目标框、二值掩码与可选轮廓 |
110
+ | `PoseDetection` | 目标框与关键点 |
111
+ | `ObbDetection` | 由四个顶点表示的旋转框 |
112
+ | `SemanticSegmentation` | 整张图的语义类别图 |
113
+
114
+ ### 读写图像并绘制结果
115
+
116
+ `imread` 和 `imwrite` 支持包含中文等非 ASCII 字符的本地路径。`draw_bbox` 会直接在传入图像上绘制并返回该图像。
117
+
118
+ ```python
119
+ from kotoha.visual import draw_bbox, imread, imwrite
120
+
121
+ image = imread("input.jpg")
122
+ if image is None:
123
+ raise RuntimeError("无法读取 input.jpg")
124
+
125
+ draw_bbox(
126
+ image,
127
+ box=[10, 20, 110, 180],
128
+ score=0.95,
129
+ obj_id="person",
130
+ )
131
+ imwrite("result.jpg", image)
132
+ ```
133
+
134
+ ### 运行 YOLO ONNX 检测
135
+
136
+ 安装 `model` 扩展后,传入已导出的 ONNX 模型文件即可推理。模型适配器接收 BGR 图像,返回标准的 `Detection` 对象。
137
+
138
+ ```python
139
+ from kotoha.model.ultralytics import YOLOv8
140
+ from kotoha.visual import imread, imwrite
141
+
142
+ model = YOLOv8("yolov8n.onnx")
143
+ image = imread("input.jpg")
144
+ if image is None:
145
+ raise RuntimeError("无法读取 input.jpg")
146
+
147
+ detections = model.detect(image, conf_thres=0.4)
148
+ rendered = model.draw_bbox(image, detections)
149
+ imwrite("result.jpg", rendered)
150
+ ```
151
+
152
+ 可用的适配器包括 `YOLOv5`、`YOLOv8`、`YOLOv8Cls`、`YOLOv8Seg`、`YOLOv8Pose`、`YOLOv8Obb` 和 `YOLO26Sem`。不同模型需要与对应任务和导出格式匹配的 ONNX 文件。
153
+
154
+ ## 模块一览
155
+
156
+ | 模块 | 内容 |
157
+ | --- | --- |
158
+ | `kotoha` / `kotoha.typing` | 稳定的核心几何类型与标注类型 |
159
+ | `kotoha.annotation` | 分类、检测、分割、姿态、旋转框等任务结果 |
160
+ | `kotoha.geo` | 几何算法,如面积、相交判断和点集旋转 |
161
+ | `kotoha.io` | 通用文件、标注文件的读写与文件枚举 |
162
+ | `kotoha.visual` | 图像读写、框/关键点/掩码绘制和 `VideoReader` |
163
+ | `kotoha.model.ultralytics` | ONNX YOLO 系列模型适配器 |
164
+ | `kotoha.eval` | 分类、检测、姿态、重识别和文本任务的评估工具 |
165
+
166
+ 顶层 `kotoha` 命名空间只导出稳定的值类型和标注类型;工具函数请从对应子模块导入:
167
+
168
+ ```python
169
+ from kotoha.geo import polygon_area, rotate_points
170
+ from kotoha.io import read_json, save_yaml
171
+ from kotoha.visual import draw_bbox, imread
172
+ ```
173
+
174
+ ## 开发与验证
175
+
176
+ 安装开发依赖后运行测试:
177
+
178
+ ```bash
179
+ uv run pytest
180
+ ```
181
+
182
+ 代码质量检查可使用:
183
+
184
+ ```bash
185
+ uv run ruff check .
186
+ uv run ruff format --check .
187
+ ```
188
+
189
+ ## 兼容性说明
190
+
191
+ 标注结果类型已统一移动到 `kotoha.annotation`。旧的模型或几何命名空间导入方式不再支持:
192
+
193
+ ```python
194
+ # 旧写法(不再支持)
195
+ from kotoha.model.typing import Detection
196
+ from kotoha.typing import PoseDetection
197
+
198
+ # 新写法
199
+ from kotoha.annotation import Detection, PoseDetection
200
+ ```
201
+
202
+ 为了兼容简洁用法,结果类型仍可从顶层导入:
203
+
204
+ ```python
205
+ from kotoha import Detection, PoseDetection
206
+ ```
kotoha-0.1.0/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # kotoha
2
+
3
+ `kotoha` 是一个面向计算机视觉工程的 Python 工具箱。它把几何数据、算法结果、文件读写和可视化能力收拢为一套轻量且类型明确的接口,让传统视觉、人工标注和模型推理可以使用相同的数据结构协作。
4
+
5
+ ## 特性
6
+
7
+ - 不可变的二维几何类型:点、关键点、矩形、四边形、多边形、直线、圆和仿射变换。
8
+ - 统一的视觉任务结果:分类、检测、实例分割、姿态、旋转框和语义分割。
9
+ - 常用几何计算:面积、点线关系、线段相交、点在多边形内、旋转等。
10
+ - 面向工程的文件和图像工具:JSON、YAML、CSV、TXT、Pickle、XML、YOLO 标注及 Unicode 路径图像读写。
11
+ - OpenCV 绘制与视频读取工具。
12
+ - 可选的 ONNX YOLO 推理适配,包括检测、分割、姿态、分类和旋转框任务。
13
+
14
+ ## 安装
15
+
16
+ 需要 Python 3.12 或更高版本。
17
+
18
+ 安装核心功能:
19
+
20
+ ```bash
21
+ pip install kotoha
22
+ ```
23
+
24
+ 如需使用 ONNX 模型适配,安装 `model` 扩展:
25
+
26
+ ```bash
27
+ pip install "kotoha[model]"
28
+ ```
29
+
30
+ 从源码开发时,推荐使用 `uv`:
31
+
32
+ ```bash
33
+ uv sync --all-extras --dev
34
+ ```
35
+
36
+ ## 快速开始
37
+
38
+ ### 用几何类型表达和变换区域
39
+
40
+ `Rect`、`Polygon` 和 `KeyPoint` 都支持平移、缩放、旋转和镜像变换。坐标以 `(x, y)` 表示;`rotate_deg` 的角度单位为度。
41
+
42
+ ```python
43
+ from kotoha import Rect
44
+
45
+ box = Rect.from_xyxy(10, 20, 110, 80)
46
+ polygon = box.to_polygon()
47
+
48
+ rotated = polygon.rotate_deg(30, pivot=(60, 50))
49
+ print(rotated.to_list())
50
+ ```
51
+
52
+ ### 使用统一的检测结果
53
+
54
+ 模型输出、传统算法结果和人工标注都可以使用相同的标注对象。每种对象均提供 `to_dict()`,检测类结果还提供适合导出的 `to_numpy()`。
55
+
56
+ ```python
57
+ from kotoha import Detection, Rect
58
+
59
+ detection = Detection(
60
+ box=Rect.from_xyxy(10, 20, 110, 180),
61
+ score=0.95,
62
+ class_id=0,
63
+ label="person",
64
+ )
65
+
66
+ print(detection.to_dict())
67
+ # {'box': {'pmin': [10, 20], 'pmax': [110, 180]}, ...}
68
+ ```
69
+
70
+ 可用的结果类型如下:
71
+
72
+ | 类型 | 用途 |
73
+ | --- | --- |
74
+ | `Classification` | 图像分类的类别与置信度 |
75
+ | `Detection` | 轴对齐目标框 |
76
+ | `SegmentationDetection` | 目标框、二值掩码与可选轮廓 |
77
+ | `PoseDetection` | 目标框与关键点 |
78
+ | `ObbDetection` | 由四个顶点表示的旋转框 |
79
+ | `SemanticSegmentation` | 整张图的语义类别图 |
80
+
81
+ ### 读写图像并绘制结果
82
+
83
+ `imread` 和 `imwrite` 支持包含中文等非 ASCII 字符的本地路径。`draw_bbox` 会直接在传入图像上绘制并返回该图像。
84
+
85
+ ```python
86
+ from kotoha.visual import draw_bbox, imread, imwrite
87
+
88
+ image = imread("input.jpg")
89
+ if image is None:
90
+ raise RuntimeError("无法读取 input.jpg")
91
+
92
+ draw_bbox(
93
+ image,
94
+ box=[10, 20, 110, 180],
95
+ score=0.95,
96
+ obj_id="person",
97
+ )
98
+ imwrite("result.jpg", image)
99
+ ```
100
+
101
+ ### 运行 YOLO ONNX 检测
102
+
103
+ 安装 `model` 扩展后,传入已导出的 ONNX 模型文件即可推理。模型适配器接收 BGR 图像,返回标准的 `Detection` 对象。
104
+
105
+ ```python
106
+ from kotoha.model.ultralytics import YOLOv8
107
+ from kotoha.visual import imread, imwrite
108
+
109
+ model = YOLOv8("yolov8n.onnx")
110
+ image = imread("input.jpg")
111
+ if image is None:
112
+ raise RuntimeError("无法读取 input.jpg")
113
+
114
+ detections = model.detect(image, conf_thres=0.4)
115
+ rendered = model.draw_bbox(image, detections)
116
+ imwrite("result.jpg", rendered)
117
+ ```
118
+
119
+ 可用的适配器包括 `YOLOv5`、`YOLOv8`、`YOLOv8Cls`、`YOLOv8Seg`、`YOLOv8Pose`、`YOLOv8Obb` 和 `YOLO26Sem`。不同模型需要与对应任务和导出格式匹配的 ONNX 文件。
120
+
121
+ ## 模块一览
122
+
123
+ | 模块 | 内容 |
124
+ | --- | --- |
125
+ | `kotoha` / `kotoha.typing` | 稳定的核心几何类型与标注类型 |
126
+ | `kotoha.annotation` | 分类、检测、分割、姿态、旋转框等任务结果 |
127
+ | `kotoha.geo` | 几何算法,如面积、相交判断和点集旋转 |
128
+ | `kotoha.io` | 通用文件、标注文件的读写与文件枚举 |
129
+ | `kotoha.visual` | 图像读写、框/关键点/掩码绘制和 `VideoReader` |
130
+ | `kotoha.model.ultralytics` | ONNX YOLO 系列模型适配器 |
131
+ | `kotoha.eval` | 分类、检测、姿态、重识别和文本任务的评估工具 |
132
+
133
+ 顶层 `kotoha` 命名空间只导出稳定的值类型和标注类型;工具函数请从对应子模块导入:
134
+
135
+ ```python
136
+ from kotoha.geo import polygon_area, rotate_points
137
+ from kotoha.io import read_json, save_yaml
138
+ from kotoha.visual import draw_bbox, imread
139
+ ```
140
+
141
+ ## 开发与验证
142
+
143
+ 安装开发依赖后运行测试:
144
+
145
+ ```bash
146
+ uv run pytest
147
+ ```
148
+
149
+ 代码质量检查可使用:
150
+
151
+ ```bash
152
+ uv run ruff check .
153
+ uv run ruff format --check .
154
+ ```
155
+
156
+ ## 兼容性说明
157
+
158
+ 标注结果类型已统一移动到 `kotoha.annotation`。旧的模型或几何命名空间导入方式不再支持:
159
+
160
+ ```python
161
+ # 旧写法(不再支持)
162
+ from kotoha.model.typing import Detection
163
+ from kotoha.typing import PoseDetection
164
+
165
+ # 新写法
166
+ from kotoha.annotation import Detection, PoseDetection
167
+ ```
168
+
169
+ 为了兼容简洁用法,结果类型仍可从顶层导入:
170
+
171
+ ```python
172
+ from kotoha import Detection, PoseDetection
173
+ ```
@@ -0,0 +1,163 @@
1
+ from .annotation import (
2
+ Classification,
3
+ Detection,
4
+ ObbDetection,
5
+ PoseDetection,
6
+ SegmentationDetection,
7
+ SemanticSegmentation,
8
+ )
9
+ from .common import (
10
+ FuzzyMatchingSet,
11
+ is_url,
12
+ is_valid_image,
13
+ parallel_process,
14
+ scale_bbox_xyxy,
15
+ url_to_image,
16
+ )
17
+ from .dataset_info import CocoConfig
18
+ from .eval import (
19
+ average_precision,
20
+ bleu,
21
+ confusion,
22
+ edit_distance,
23
+ evaluate_detection,
24
+ evaluate_reid_market1501,
25
+ evaluate_reid_roc,
26
+ f1_score,
27
+ match_detections,
28
+ mean_average_precision,
29
+ pairwise_box_iou,
30
+ pck_accuracy,
31
+ rouge,
32
+ safe_divide,
33
+ topk_accuracy,
34
+ )
35
+ from .geo import (
36
+ circle_from_three_points,
37
+ fit_line,
38
+ intersect_lines,
39
+ is_point_in_polygon,
40
+ is_point_on_segment,
41
+ polygon_area,
42
+ rotate_points,
43
+ segment_intersection,
44
+ )
45
+ from .image_filter import ImageFilter
46
+ from .io import (
47
+ list_files,
48
+ read_csv,
49
+ read_json,
50
+ read_pkl,
51
+ read_txt,
52
+ read_xml,
53
+ read_yaml,
54
+ read_yolo_txt,
55
+ save_csv,
56
+ save_json,
57
+ save_pkl,
58
+ save_txt,
59
+ save_xml,
60
+ save_yaml,
61
+ save_yolo_txt,
62
+ )
63
+ from .typing import (
64
+ Affine2D,
65
+ Circle,
66
+ KeyPoint,
67
+ Line,
68
+ Point2f,
69
+ PointGeometryMixin,
70
+ PointLike,
71
+ PointSet,
72
+ Polygon,
73
+ PolygonLike,
74
+ Rect,
75
+ Vector2,
76
+ )
77
+ from .visual import (
78
+ VideoReader,
79
+ draw_bbox,
80
+ draw_keypoints,
81
+ draw_masks,
82
+ generate_distinct_colors,
83
+ get_color,
84
+ imread,
85
+ imwrite,
86
+ )
87
+
88
+ __all__ = [
89
+ "Affine2D",
90
+ "Circle",
91
+ "Classification",
92
+ "CocoConfig",
93
+ "Detection",
94
+ "FuzzyMatchingSet",
95
+ "ImageFilter",
96
+ "KeyPoint",
97
+ "Line",
98
+ "ObbDetection",
99
+ "Point2f",
100
+ "PointGeometryMixin",
101
+ "PointLike",
102
+ "PointSet",
103
+ "Polygon",
104
+ "PolygonLike",
105
+ "PoseDetection",
106
+ "Rect",
107
+ "SegmentationDetection",
108
+ "SemanticSegmentation",
109
+ "Vector2",
110
+ "VideoReader",
111
+ "average_precision",
112
+ "bleu",
113
+ "circle_from_three_points",
114
+ "confusion",
115
+ "draw_bbox",
116
+ "draw_keypoints",
117
+ "draw_masks",
118
+ "edit_distance",
119
+ "evaluate_detection",
120
+ "evaluate_reid_market1501",
121
+ "evaluate_reid_roc",
122
+ "f1_score",
123
+ "fit_line",
124
+ "generate_distinct_colors",
125
+ "get_color",
126
+ "imread",
127
+ "imwrite",
128
+ "intersect_lines",
129
+ "is_point_in_polygon",
130
+ "is_point_on_segment",
131
+ "is_url",
132
+ "is_valid_image",
133
+ "list_files",
134
+ "match_detections",
135
+ "mean_average_precision",
136
+ "pairwise_box_iou",
137
+ "parallel_process",
138
+ "pck_accuracy",
139
+ "polygon_area",
140
+ "read_csv",
141
+ "read_json",
142
+ "read_pkl",
143
+ "read_txt",
144
+ "read_xml",
145
+ "read_yaml",
146
+ "read_yolo_txt",
147
+ "rotate_points",
148
+ "rouge",
149
+ "safe_divide",
150
+ "save_csv",
151
+ "save_json",
152
+ "save_pkl",
153
+ "save_txt",
154
+ "save_xml",
155
+ "save_yaml",
156
+ "save_yolo_txt",
157
+ "scale_bbox_xyxy",
158
+ "segment_intersection",
159
+ "topk_accuracy",
160
+ "url_to_image",
161
+ ]
162
+
163
+ __version__ = "0.1.0"
@@ -0,0 +1,126 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict, dataclass
4
+
5
+ import numpy as np
6
+
7
+ from kotoha.geo._types import KeyPoint, Polygon, Rect
8
+
9
+ __all__ = [
10
+ "Classification",
11
+ "Detection",
12
+ "ObbDetection",
13
+ "PoseDetection",
14
+ "SegmentationDetection",
15
+ "SemanticSegmentation",
16
+ ]
17
+
18
+
19
+ @dataclass(slots=True)
20
+ class Classification:
21
+ """One ranked category prediction for an image."""
22
+
23
+ score: float
24
+ class_id: int
25
+ label: str | None = None
26
+
27
+ def to_numpy(self) -> np.ndarray:
28
+ return np.array([self.score, self.class_id], dtype=np.float32)
29
+
30
+ def to_dict(self) -> dict[str, object]:
31
+ return asdict(self)
32
+
33
+
34
+ @dataclass(slots=True)
35
+ class SemanticSegmentation:
36
+ """Dense semantic class map for one image."""
37
+
38
+ mask: np.ndarray
39
+
40
+ def to_numpy(self) -> np.ndarray:
41
+ return self.mask
42
+
43
+ def to_dict(self) -> dict[str, object]:
44
+ return {"mask": self.mask.tolist()}
45
+
46
+
47
+ @dataclass(slots=True)
48
+ class Detection:
49
+ box: Rect
50
+ score: float
51
+ class_id: int
52
+ label: str | None = None
53
+
54
+ def to_numpy(self) -> np.ndarray:
55
+ return np.array(
56
+ [*self.box.to_list(), self.score, self.class_id],
57
+ dtype=np.float32,
58
+ )
59
+
60
+ def to_dict(self) -> dict[str, object]:
61
+ data = asdict(self)
62
+ data["box"] = self.box.to_dict()
63
+ return data
64
+
65
+
66
+ @dataclass(slots=True)
67
+ class SegmentationDetection:
68
+ box: Rect
69
+ score: float
70
+ class_id: int
71
+ mask: np.ndarray
72
+ polygon: Polygon | None = None
73
+ label: str | None = None
74
+
75
+ def to_numpy(self) -> np.ndarray:
76
+ return np.array(
77
+ [*self.box.to_list(), self.score, self.class_id],
78
+ dtype=np.float32,
79
+ )
80
+
81
+ def to_dict(self) -> dict[str, object]:
82
+ data = asdict(self)
83
+ data["box"] = self.box.to_dict()
84
+ data["mask"] = self.mask.tolist()
85
+ if self.polygon is not None:
86
+ data["polygon"] = self.polygon.to_dict()
87
+ return data
88
+
89
+
90
+ @dataclass(slots=True)
91
+ class PoseDetection:
92
+ box: Rect
93
+ score: float
94
+ class_id: int
95
+ keypoints: list[KeyPoint]
96
+ label: str | None = None
97
+
98
+ def to_numpy(self) -> np.ndarray:
99
+ values: list[float] = [*self.box.to_list(), self.score, float(self.class_id)]
100
+ for keypoint in self.keypoints:
101
+ values.extend([keypoint.p.x, keypoint.p.y, keypoint.score or 0.0])
102
+ return np.array(values, dtype=np.float32)
103
+
104
+ def to_dict(self) -> dict[str, object]:
105
+ data = asdict(self)
106
+ data["keypoints"] = [keypoint.to_dict() for keypoint in self.keypoints]
107
+ data["box"] = self.box.to_dict()
108
+ return data
109
+
110
+
111
+ @dataclass(slots=True)
112
+ class ObbDetection:
113
+ quad: Polygon
114
+ score: float
115
+ class_id: int
116
+ label: str | None = None
117
+
118
+ def to_numpy(self) -> np.ndarray:
119
+ values = [coord for point in self.quad.vertices for coord in (point.x, point.y)]
120
+ values.extend([self.score, float(self.class_id)])
121
+ return np.array(values, dtype=np.float32)
122
+
123
+ def to_dict(self) -> dict[str, object]:
124
+ data = asdict(self)
125
+ data["quad"] = self.quad.to_dict()
126
+ return data