当前位置: 首页 > news >正文

道路红外目标检测数据集 6500张 带标注 voc yolo

道路红外目标检测数据集 6500张 带标注 voc yolo

道路红外目标检测数据集

数据集描述

该数据集旨在用于道路环境中的红外目标检测任务,涵盖了多种场景下的红外图像。数据集包含大量的图像及其对应的标注信息,可用于训练计算机视觉模型,以识别和定位道路环境中出现的目标物体。

数据规模

数据集共有6500张图像,这些图像都带有详细的标注信息。

类别及数量

虽然没有提供具体的类别和数量,但是假设该数据集包含了道路环境中常见的一些目标类别,例如:

  1. 行人 (person):标注出现在图像中的行人。
  2. 车辆 (car):标注出现在图像中的车辆。
  3. 自行车 (bicycle):标注出现在图像中的自行车。
  4. 摩托车 (motorcycle):标注出现在图像中的摩托车。
  5. 其他目标 (other):标注出现在图像中的其他重要目标。

具体类别可以根据实际情况进行调整或扩展。

标注格式

数据集中的标注信息采用了VOC(Visual Object Classes)格式,每个图像都有一个对应的XML文件,记录了每个对象的位置信息(边界框坐标)和类别标签。此外,也可以选择YOLO格式的标注文件(TXT文件),方便使用YOLO系列模型进行训练。

数据集结构

典型的数据集目录结构如下

1road_ir_target_detection_dataset/
2├── Annotations/
3│   ├── img_0001.xml
4│   ├── img_0002.xml
5│   └── ...
6├── ImageSets/
7│   ├── Main/
8│   │   ├── train.txt
9│   │   ├── val.txt
10│   │   └── test.txt
11├── JPEGImages/
12│   ├── img_0001.jpg
13│   ├── img_0002.jpg
14│   └── ...
15└── labels/
16    ├── train/
17    │   ├── img_0001.txt
18    │   ├── img_0002.txt
19    └── val/
20        ├── img_0001.txt
21        ├── img_0002.txt
应用场景

该数据集可以用于以下应用场景:

  • 交通监控:实时监测道路交通状况,特别是在夜间或能见度较低的情况下。
  • 安防系统:辅助安防系统的视频监控,在复杂光照条件下识别行人和其他目标。
  • 智能驾驶:用于自动驾驶车辆在红外图像中的目标检测,提高车辆在夜间或恶劣天气条件下的行驶安全性。
  • 科研分析:用于研究红外图像处理技术和目标检测算法。

示例代码

以下是一个使用Python和相关库(如OpenCV、PyTorch等)来加载和展示数据集的简单示例代码:

1import os
2import cv2
3import xml.etree.ElementTree as ET
4from PIL import Image
5import numpy as np
6
7# 数据集路径
8dataset_path = 'path/to/road_ir_target_detection_dataset/'
9
10# 加载图像和标签
11def load_image_and_label(image_path, annotation_path):
12    # 读取图像
13    image = Image.open(image_path).convert('RGB')
14    # 解析XML文件
15    tree = ET.parse(annotation_path)
16    root = tree.getroot()
17    objects = []
18    for obj in root.findall('object'):
19        name = obj.find('name').text
20        bbox = obj.find('bndbox')
21        xmin = int(bbox.find('xmin').text)
22        ymin = int(bbox.find('ymin').text)
23        xmax = int(bbox.find('xmax').text)
24        ymax = int(bbox.find('ymax').text)
25        objects.append([xmin, ymin, xmax, ymax, name])
26    return image, objects
27
28# 展示图像
29def show_image_with_boxes(image, boxes):
30    img = np.array(image)
31    for box in boxes:
32        xmin, ymin, xmax, ymax, name = box
33        cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)
34        cv2.putText(img, name, (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
35    cv2.imshow('Image with Boxes', img)
36    cv2.waitKey(0)
37    cv2.destroyAllWindows()
38
39# 主函数
40if __name__ == "__main__":
41    images_dir = os.path.join(dataset_path, 'JPEGImages')
42    annotations_dir = os.path.join(dataset_path, 'Annotations')
43    
44    # 获取图像列表
45    image_files = [f for f in os.listdir(images_dir) if f.endswith('.jpg')]
46    
47    # 随机选择一张图像
48    selected_image = np.random.choice(image_files)
49    image_path = os.path.join(images_dir, selected_image)
50    annotation_path = os.path.join(annotations_dir, selected_image.replace('.jpg', '.xml'))
51    
52    # 加载图像和标签
53    image, boxes = load_image_and_label(image_path, annotation_path)
54    
55    # 展示带有标注框的图像
56    show_image_with_boxes(image, boxes)

这段代码展示了如何加载图像和其对应的VOC XML标注文件,并在图像上绘制边界框和类别标签。您可以根据实际需求进一步扩展和修改这段代码,以适应您的具体应用场景。

示例代码:从VOC格式转换为YOLO格式

以下是将VOC格式的标注文件转换为YOLO格式的标签文件的示例代码

1import os
2import xml.etree.ElementTree as ET
3import shutil
4
5# 数据集路径
6dataset_path = 'path/to/road_ir_target_detection_dataset/'
7
8# VOC标注文件目录
9voc_annotations_dir = os.path.join(dataset_path, 'Annotations')
10# 输出YOLO标签文件目录
11yolo_labels_dir = os.path.join(dataset_path, 'labels')
12
13# 创建YOLO标签目录
14os.makedirs(yolo_labels_dir, exist_ok=True)
15
16# 复制VOC图像集划分文件到YOLO目录
17for split in ['train', 'val']:
18    shutil.copy(os.path.join(dataset_path, 'ImageSets/Main/{}.txt'.format(split)), os.path.join(yolo_labels_dir, '{}.txt'.format(split)))
19
20# 从VOC格式转换为YOLO格式
21def convert_voc_to_yolo(voc_path, yolo_path, width, height):
22    with open(voc_path, 'r') as infile:
23        tree = ET.parse(infile)
24        root = tree.getroot()
25        objects = []
26        for obj in root.findall('object'):
27            name = obj.find('name').text
28            bbox = obj.find('bndbox')
29            xmin = int(bbox.find('xmin').text)
30            ymin = int(bbox.find('ymin').text)
31            xmax = int(bbox.find('xmax').text)
32            ymax = int(bbox.find('ymax').text)
33            x_center = (xmin + xmax) / 2.0
34            y_center = (ymin + ymax) / 2.0
35            w = xmax - xmin
36            h = ymax - ymin
37            x_center /= width
38            y_center /= height
39            w /= width
40            h /= height
41            objects.append([name, x_center, y_center, w, h])
42
43    with open(yolo_path, 'w') as outfile:
44        for obj in objects:
45            class_index = {'person': 0, 'car': 1, 'bicycle': 2, 'motorcycle': 3, 'other': 4}[obj[0]]
46            line = f"{class_index} {obj[1]} {obj[2]} {obj[3]} {obj[4]}\n"
47            outfile.write(line)
48
49# 主函数
50if __name__ == "__main__":
51    # 获取VOC标注文件列表
52    voc_files = [f for f in os.listdir(voc_annotations_dir) if f.endswith('.xml')]
53    
54    # 遍历VOC文件并转换为YOLO格式
55    for voc_file in voc_files:
56        # 获取图像尺寸
57        image_file = os.path.join(dataset_path, 'JPEGImages', voc_file.replace('.xml', '.jpg'))
58        image = Image.open(image_file)
59        width, height = image.size
60        
61        # 转换并保存YOLO标签文件
62        yolo_file = os.path.join(yolo_labels_dir, voc_file.replace('.xml', '.txt'))
63        convert_voc_to_yolo(os.path.join(voc_annotations_dir, voc_file), yolo_file, width, height)

这段代码展示了如何将VOC格式的标注文件转换为YOLO格式的标签文件,方便使用YOLO系列模型进行训练。您可以根据实际需求进一步扩展和修改这段代码,以适应您的具体应用场景。如果您的数据集中有多个类别,请调整 class_index 字典中的映射关系

 


http://www.mrgr.cn/news/30686.html

相关文章:

  • golang学习笔记30——golang 中代码仓库的 h1 和 go.mod h1 不一致的修正方法
  • C++ | Leetcode C++题解之第419题棋盘上的战舰
  • SharePoint Online 计划 1 部署方案
  • DOM XMLHttpRequest
  • nginx和php-fpm连接超时的相关配置以及Nginx中的try_files以及root、alias的使用
  • 末端回路漏电监测仪为何不可或缺?
  • AI学习指南深度学习篇-Adagrad在深度学习中的应用
  • NISP 一级 | 7.3 信息安全事件与应急响应
  • [Unity Demo]从零开始制作空洞骑士Hollow Knight第五集:再制作更多的敌人
  • 每日学习一个数据结构-哈夫曼树Huffman Tree
  • 江协科技STM32学习- P14 示例程序(定时器定时中断和定时器外部时钟)
  • MATLAB 在数学建模中的深入应用:从基础到高级实践
  • php的require() 和 require_once() 之间的主要区别
  • 职场人生-外企福利待遇
  • 中科曙光嵌入式面试大全及参考答案(3万字长文)
  • Golang | Leetcode Golang题解之第419题棋盘上的战舰
  • Kubernetes集群架构、安装和配置全面指南
  • C语言 | Leetcode C语言题解之第417题太平洋大西洋水流问题
  • IBM中国研发中心撤离背后的IT行业人才挑战与产业未来展望
  • 茴香豆:企业级知识问答工具实践闯关任务