【人脸检测】wider_face数据集转voc数据格式

wider_face数据格式说明

下载链接:http://shuoyang1213.me/WIDERFACE/index.html
说明:wider_face是从真实场景中选取出来的。其只标注出了人脸的矩形框区域,没有人脸对齐标注

code

import cv2
import os
xml_head = '''<annotation>
    <folder>VOC2007</folder>
    <!--文件名-->
    <filename>{}</filename>.
    <source>
        <database>The VOC2007 Database</database>
        <annotation>PASCAL VOC2007</annotation>
        <image>flickr</image>
        <flickrid>325991873</flickrid>
    </source>
    <owner>
        <flickrid>null</flickrid>
        <name>null</name>
    </owner>    
    <size>
        <width>{}</width>
        <height>{}</height>
        <depth>{}</depth>
    </size>
    <segmented>0</segmented>
    '''
xml_obj = '''
    <object>        
        <name>{}</name>
        <pose>Rear</pose>
        <!--是否被裁减,0表示完整,1表示不完整-->
        <truncated>0</truncated>
        <!--是否容易识别,0表示容易,1表示困难-->
        <difficult>0</difficult>
        <!--bounding box的四个坐标-->
        <bndbox>
            <xmin>{}</xmin>
            <ymin>{}</ymin>
            <xmax>{}</xmax>
            <ymax>{}</ymax>
        </bndbox>
    </object>
    '''
xml_end = '''
</annotation>'''
 

txt_path = '/home/yangna/data/WIDER_FACE/wider_face_split/wider_face_train_bbx_gt.txt'
imgs_path = '/home/yangna/data/WIDER_FACE/WIDER_train/images/'
labels = 'face'                #label for datasets
 
cnt = 0
cnt_line = 0
with open(txt_path,'r') as train_list:
    lst = train_list.readlines()
    while (cnt_line < len(lst)):
        img_name = lst[cnt_line]
        if '.jpg' in img_name:
            per_nums = int(lst[cnt_line + 1].rstrip())
            per_lines = lst[cnt_line + 2:cnt_line+2+per_nums]
            cnt_line = cnt_line + per_nums + 2

            if per_nums == 0:
                cnt_line += 1
                continue

            # process one image
            img_path = imgs_path + img_name.rstrip()
            img = cv2.imread(img_path)
            img_h,img_w = img.shape[0],img.shape[1]
            head = xml_head.format(str(img_path),str(img_w),str(img_h),3)

            obj = ''

            out_txt_name = './data/wider_face/voc/' + img_path.split('/')[-1].replace('.jpg', '.xml')
            for f in per_lines:
                f = [int(x) for x in f.rstrip().split(' ')]
                if f[2]*f[3] < 10:
                    continue
                xmin = str(f[0])
                ymin = str(f[1])
                xmax = str(f[0] + f[2])
                ymax = str(f[1] + f[3])

                obj += xml_obj.format(labels,xmin,ymin,xmax,ymax)
            
            if obj == '':
                continue

            with open(out_txt_name,'w') as f_xml:
                f_xml.write(head+obj+xml_end)
            cnt += 1
            print(cnt)
            if cnt == 279:
                temp = 1

result
在这里插入图片描述
处理后xml下载地址
百度云链接, 提取码: wrk3


wider_face带5个关键点的标注

下载链接:https://pan.baidu.com/s/1Laby0EctfuJGgGMgRRgykA
数据格式:

# 0--Parade/0_Parade_marchingband_1_849.jpg
449 330 122 149 488.906 373.643 0.0 542.089 376.442 0.0 515.031 412.83 0.0 485.174 425.893 0.0 538.357 431.491 0.0 0.82
# 0--Parade/0_Parade_Parade_0_904.jpg
361 98 263 339 424.143 251.656 0.0 547.134 232.571 0.0 494.121 325.875 0.0 453.83 368.286 0.0 561.978 342.839 0.0 0.89
# 0--Parade/0_Parade_marchingband_1_799.jpg
78 221 7 8 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 0.2

格式 人脸矩形框(4个值),5个关键点(5×3个值),1个置信度值


reference

  1. https://blog.csdn.net/angelbeats11/article/details/88427359
发布了244 篇原创文章 · 获赞 147 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/u011622208/article/details/104038213
今日推荐