标注格式如下
{
"type": "instance",
"images": {
"file_name": "00001.jpg",
"height": 2744,
"width": 4800,
"id": 1
},
"annotations": [
{
"poly": [
235.0841064453125,
2551.818359375,
249.3841552734375,
2556.41845703125,
256.6455383300781,
2533.84521484375,
242.34548950195312,
2529.2451171875
],
"area": 356.2015366703272,
"category_id": 0,
"image_id": 1,
"id": 1
},
SODA-A 遥感图像小目标检测 数据处理 代码
实现逻辑:把原图像裁切成为 640x640 大小的子图片,遍历每个标注文件标注框,若在子图片内,则加入。
B站 可视化界面:https://www.bilibili.com/video/BV1Fn4y1o7aw/?spm_id_from=333.999.0.0
import os
import json
from PIL import Image
def open_annotations_json(image_name):
# 构造标注文件名
annotation_name = image_name.replace(".jpg", ".json")
# 构造标注文件路径
# 在 train、val 和 test 文件夹中查找标注文件
for folder in ['train', 'val', 'test']:
annotation_file_path = os.path.join("Annotations", folder, annotation_name)
if os.path.exists(annotation_file_path):
# 如果找到标注文件,则打开并处理
with open(annotation_file_path, "r") as file:
data = json.load(file)
print(f"找到{annotation_file_path}对应的标注文件")
# 在这里对标注文件进行处理
return data # 返回标注文件数据
break
else:
print(f"未找到{annotation_file_path}对应的标注文件")
def is_points_inside_rect(points, left, upper, right, lower):
for i in range(0, len(points), 2):
x = points[i]
y = points[i + 1