文章大纲
- 开源数据集简介
- xml 格式数据转化为 txt
- 项目地址
- 参考文献与学习路径
开源数据集简介
现有的跌倒公开数据集有UR Fall Detection Dataset、Multicam、Fall detection Dataset、Le2i Fall detection Dataset等。
数据集的内容以视频或连续的图像帧为主要呈现形式,部分图像帧不包含人物,包含人物的图像帧存在跌倒和正常两种行为,但是这是一种典型的不平衡数据,跌倒行为数据量远小于正常行为数据量。
数据中的摄像机一般固定与室内环境的屋顶,也存在平行视角,但是都是较远的距离,基本上可以把人体的轮廓全部包含,存在人物的图像帧中,基本上均为单一人物,且人物以年轻人和中年人为主。
数据的存在形式有GRB、也有深度和热成像图形。
UR Fall Detection Dataset
数据集大小:共包含30条跌倒数据以及40条正常生活数集
数据集格式:
跌倒数据由2个摄像机以及相应的加速度计进行记录数据,摄像机一个平行安装于地板,一个安装于天花板
正常生活数据集有1个相机以及加速度计进行数据记录,摄像机平行安装于地板
数据集内容:
相机深度数据、相机RGB数据、视频
Synchronization data.csv : (帧数,视频中的时间(毫秒),SV_total三个维度平方和求根加速度值)
Raw accelerometric.csv : (视频中的时间(毫秒), SV_total, x, y, z(加速度计4个方向))
光线 : 有明有暗
Multicam
数据集大小:共有24个场景,每个场景用8个摄像机记录,前22个场景包含跌倒和正常时间,后两个场景仅包含混杂事件。
数据集格式
视频中包含正常也包含跌倒部分,不包含标签文档
Fall detection Dataset
数据集大小: 数据集总共有21499张图像,其中训练集图像有16794, 测试集图像3299,验证集图像2543
数据集组成:由5名参与者,两名男性分别为32岁与50岁,三名女性,分别为19岁,28岁,40岁,所有图像为按顺序排列,并没有位置重复,且所有集合都添加了原始图像和水平翻转图像,以增加数据集.
摄像头位置 : 固定于房顶位置,高约2.4米
数据集内容
RGB图像数据
Depth图像数据
labels (Frame, label),其中动作一共有6种标签,分别为Standing: class 1, Sitting: class 2, Lying: class 3, Bending: class 4, Crawling: class 5, Empty: class 0
Le2i Fall detection Dataset
数据集大小:共有191个视频,视频中存在假摔部分,且存在视频中没有人的帧数
数据集内容:
Video
视频部分
Annotations
标签格式为txt格式
标签前两行为跌倒帧数的起始与终止点,也存在没有这两行的文件
之后一行就是六个字段,帧编号, XX,人物bbx
Thermal Simulated Fall dataset
数据集大小:有44个视频,其中9个视频数据全部都是正常数据,其中35个数据有正常也有跌倒的数据,共有22116帧数据
xml 格式数据转化为 txt
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import os
import random
# 清理隐藏文件
def clear_hidden_files(path):
dir_list = os.listdir(path)
for i in dir_list:
abspath = os.path.join(os.path.abspath(path), i)
if os.path.isfile(abspath):
if i.startswith("._"):
os.remove(abspath)
else:
clear_hidden_files(abspath)
# 将数据集切分为train,test,val
def split_dataset_with_txt(trainval_percent,train_percent):
total_xml = os.listdir(annotation_dir)
num = len(total_xml)
list = range(num)
tv = int(num * trainval_percent)
tr = int(tv * train_percent)
trainval = random.sample(list, tv)
train = random.sample(trainval, tr)
ftrainval = open('trainval.txt', 'w', encoding='utf-8')
ftest = open('test.txt', 'w', encoding='utf-8')
ftrain = open('train.txt', 'w', encoding='utf-8')
fval = open('val.txt', 'w', encoding='utf-8')
for i in list:
name = total_xml[i][:-4] + '\n'
if i in trainval:
ftrainval.write(name)
if i in train:
ftrain.write(name)
else:
fval.write(name)
else:
ftest.write(name)
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()
def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
def convert_annotation(image_id):
out_file = open(txt_dir+'%s.txt' % image_id, 'w', encoding='utf-8')
in_file = open(annotation_dir+'%s.xml' % image_id, encoding='utf-8')
tree = ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
for obj in root.iter('object'):
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult) == 1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
print(b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
in_file.close()
out_file.close()
if __name__ == '__main__':
# 类名
classes = ['person']
# 划分训练验证测试集,自行修改
sets = ['train', 'test', 'val']
root_dir = "detection/"
annotation_dir = root_dir + "Annotations/"
image_dir = root_dir + "images/"
txt_dir = root_dir + 'labels/'
if not os.path.isdir(annotation_dir):
os.mkdir(annotation_dir)
if not os.path.isdir(image_dir):
os.mkdir(image_dir)
if not os.path.exists(txt_dir):
os.makedirs(txt_dir)
clear_hidden_files(image_dir)
clear_hidden_files(annotation_dir)
# 切分数据集,txt文件处理
trainval_percent = 1 # 训练验证集与测试集比例
train_percent = 0.8 # 训练集验证集比例
split_dataset_with_txt(trainval_percent, train_percent)
# 对训练集,验证集,测试集进行处理
for image_set in sets:
image_ids = open('%s.txt' % (image_set), encoding='utf-8').read().strip().split()
# 打开对应的train.txt 文件对其进行写入准备
list_file = open(root_dir+'%s.txt' % (image_set), 'w', encoding='utf-8')
# 将对应的文件_id以及全路径写进去并换行
for image_id in image_ids:
list_file.write(image_dir+'%s.jpg\n' % (image_id))
convert_annotation(image_id)
# 关闭文件
list_file.close()
项目地址
- https://gitcode.net/wangyaninglm/falldetection
参考文献与学习路径
参考:
-
https://blog.csdn.net/guyuealian/article/details/130184256
-
https://www.yuque.com/nalaeur/bstyo8/pyacvh
跌倒检测数据集Fall detection Dataset
- https://aistudio.baidu.com/aistudio/datasetdetail/105389
fall-detection-dataset
https://imvia.u-bourgogne.fr/basededonnees/fall-detection-dataset.html