图像标注格式转换器,能让你自由转换YOLO、COCO、VOC格式的图像标注文件
Project description
图像标注格式转换器(image-annotations)
使用方法
from image_annotations import yolo2coco, yolo2voc # YOLO格式转COCO格式, YOLO格式转VOC格式 from image_annotations import voc2coco, voc2yolo # VOC格式转COCO格式, VOC格式转YOLO格式 from image_annotations import coco2yolo, coco2voc # COCO格式转YOLO格式, COCO格式转VOC格式 from image_annotations import yolo_classes_ids, coco_classes, voc_classes # 获取YOLO、COCO、VOC格式的所有类别根据需要导入相关函数,按照函数签名及注释填入相关参数即可。参数中
**_path表示文件的路径,**_dir表示文件夹路径,均推荐使用绝对路径。
标注文件说明
| 标注格式 | 文件类型 | 一张图片对应 | 一个检测框对应 |
|---|---|---|---|
| YOLO | txt | 一个txt文件 | txt文件中的一行 |
| VOC | xml | 一个xml文件 | xml文件中的一个object标签 |
| COCO | json | json文件中images的一项 | json文件中annotations的一项 |
YOLO格式
YOLO格式的目标检测标注文件通常以txt文件给出,一个txt标注文件对应一张图片,txt文件的一行对应一个目标检测框。标注格式如下:class_id x_center/width y_center/height w/width h/height其中,class_id表示类别ID,x_center表示标注框中心点x坐标,y_center表示标注框中心点y坐标,w表示标注框宽度,h表示标注框高度,width表示图片宽度,height表示图片高度。
txt标注文件示例如下:
2 0.079166666 0.6759259 0.090625 0.11666667 1 0.22552083 0.67314816 0.015625 0.048148148 1 0.21484375 0.6759259 0.0140625 0.04074074 1 0.1890625 0.6726852 0.016666668 0.047222223 1 0.17916666 0.67083335 0.014583333 0.049074072 1 0.15520833 0.6712963 0.015625 0.05
VOC格式
VOC格式的目标检测文件通常以xml文件给出,一个xml标注文件对应一张图片,xml文件的一个object标签对应一个目标检测框。xml标注文件示例如下:
<annotation> <folder>Desktop</folder> <filename>test.jpg</filename> <path>/home/DrZon/test.jpg</path> <source> <database>Unknown</database> </source> <size> <width>194</width> <height>259</height> <depth>3</depth> </size> <segmented>0</segmented> <object> <name>categoryName</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <bndbox> <xmin>56</xmin> <ymin>22</ymin> <xmax>132</xmax> <ymax>229</ymax> </bndbox> </object> </annotation>
COCO格式
COCO格式的目标检测标注文件通常以json文件给出,将所有图片的所有标注写在同一个文件里面,示例格式如下:{
"info": {
"year": 2024,
"version": "1.0",
"description": "目标检测训练数据集",
"contributor": "Your Name",
"url": "",
"date_created": "2024-06-15"
},
"licenses": [{
"id": 1,
"name": "Academic Use Only",
"url": ""
}],
"images": [
{
"id": 1,
"license": 1,
"file_name": "000001.jpg",
"height": 600,
"width": 800,
"date_captured": "2024-06-15 10:30:00"
},
{
"id": 2,
"license": 1,
"file_name": "000002.jpg",
"height": 480,
"width": 640,
"date_captured": "2024-06-15 10:31:00"
}
],
"annotations": [
{
"id": 1,
"image_id": 1,
"category_id": 1,
"bbox": [120, 150, 80, 120],
"area": 9600,
"segmentation": [],
"iscrowd": 0
},
{
"id": 2,
"image_id": 1,
"category_id": 2,
"bbox": [350, 200, 100, 60],
"area": 6000,
"segmentation": [],
"iscrowd": 0
},
{
"id": 3,
"image_id": 2,
"category_id": 1,
"bbox": [50, 80, 60, 100],
"area": 6000,
"segmentation": [],
"iscrowd": 0
}
],
"categories": [
{
"id": 1,
"name": "person",
"supercategory": "human"
},
{
"id": 2,
"name": "car",
"supercategory": "vehicle"
}
]
}
更新日志
| 版本 | 更新内容 | 更新日期 |
|---|---|---|
| 0.1.0 | 实现YOLO、COCO、VOC三种格式的目标检测标注文件相互转换 | 2026年1月6日 |
| 0.2.0 | 新增获取全部类名的功能 | 2026年1月7日 |
| 0.2.1 | Updated YOLO to VOC and COCO conversion functions to iterate over image files instead of annotation files, improving robustness for various image formats. | 2026年1月11日 |
| 0.2.2 | Exposes conversion functions between YOLO, VOC, and COCO formats, as well as class retrieval utilities, at the package level. | 2026年1月12日 |
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
image_annotations-0.2.2.tar.gz
(23.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file image_annotations-0.2.2.tar.gz.
File metadata
- Download URL: image_annotations-0.2.2.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b6676319055b7a361f2022741504d856fd1609ed301ad1bec362fec74d5753
|
|
| MD5 |
aed9bc4b38cc446cb261cfec33eca3a4
|
|
| BLAKE2b-256 |
b914bd420b88698a1879215d60f138f50e289f9200495745680a608d66cea234
|
File details
Details for the file image_annotations-0.2.2-py3-none-any.whl.
File metadata
- Download URL: image_annotations-0.2.2-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cb794a821d341c72811fc3f7b5f7948d217a8389bd9a7c1cd2d4212905a15b7
|
|
| MD5 |
c3438f8b0694bb01e025fe407f871c49
|
|
| BLAKE2b-256 |
66c188181e73a56a465f1d1d3303b5a4863fc13ad1bea14567c3354ea439312c
|