UCCS数据集官网:http://vast.uccs.edu/Opensetface/
head.xml
<annotation>
<folder>widerface</folder>
<filename>%06d.jpg</filename>
<source>
<database>My Database</database>
<annotation>VOC2007</annotation>
<image>flickr</image>
<flickrid>NULL</flickrid>
</source>
<owner>
<flickrid>NULL</flickrid>
<name>facevise</name>
</owner>
<size>
<width>%d</width>
<height>%d</height>
<depth>%d</depth>
</size>
<segmented>0</segmented>
object.xml
<object>
<name>%s</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>%d</xmin>
<ymin>%d</ymin>
<xmax>%d</xmax>
<ymax>%d</ymax>
</bndbox>
</object>
tail.xml
</annotation>
WiderFace2VOC.m
function WiderFace2VOC()
%% wider face
% The corresponding annotations are in the following format:
% Here, each face bounding boxe is denoted by:
% <x_left y_top width height>.
%% voc
% 000001.jpg car 44 28 132 121
%前面是图片名,中间是目标类别,最后是目标的包围框坐标(左上角和右下角坐标)。
%%
clc;
clear;
fclose all;
[~, ~, ~] = rmdir('Annotations', 's');
[~, ~, ~] = rmdir('ImageSets', 's');
[~, ~, ~] = rmdir('JPEGImages', 's');
[~, ~, ~] = mkdir('Annotations');
[~, ~, ~] = mkdir('ImageSets/Main');
[~, ~, ~] = mkdir('JPEGImages');
train_root = 'training13';
fpn = fopen ('training_results.txt', 'rt');
headXml = fopen('head.xml', 'r');
headXmlFormat = fread(headXml, Inf, '*char');
fclose(headXml);
objectXml = fopen('object.xml', 'r');
objectXmlFormat = fread(objectXml, Inf, '*char');
fclose(objectXml);
tailXml = fopen('tail.xml', 'r');
tailXmlFormat = fread(tailXml, Inf, '*char');
fclose(tailXml);
trainID = fopen('ImageSets/Main/train.txt', 'w');
idx = 30001;
tline=fgetl(fpn);
[index, imagename, x, y, w, h]=strread(tline,'%d %s %f %f %f %f');
imagenamepath=fullfile(train_root,imagename);
sz = size(imread(imagenamepath{1}));
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
fprintf(AnnotationsXml, objectXmlFormat, 'face', x, y, x+w-1, y+h-1);
while 1
tline=fgetl(fpn);
if ~ischar(tline )
break;
end
imagenametemp=imagename;
[index, imagename, x, y, w, h]=strread(tline,'%d %s %f %f %f %f');
if imagename{1}==imagenametemp{1}
fprintf(AnnotationsXml, objectXmlFormat, 'face', x, y, x+w-1, y+h-1);
else
fprintf(AnnotationsXml, tailXmlFormat);
fclose(AnnotationsXml);
fprintf(trainID, '%06d\n', idx);
imagenametemppath=fullfile(train_root,imagenametemp);
copyfile(imagenametemppath{1}, sprintf('JPEGImages/%06d.jpg', idx));
imagenamepath=fullfile(train_root,imagename);
sz = size(imread(imagenamepath{1}));
idx
idx = idx + 1;
AnnotationsXml = fopen(sprintf('Annotations/%06d.xml', idx), 'w');
fprintf(AnnotationsXml, headXmlFormat, idx, sz(2), sz(1),sz(3));
fprintf(AnnotationsXml, objectXmlFormat, 'face', x, y, x+w-1, y+h-1);
end
end
fprintf(AnnotationsXml, tailXmlFormat);
fclose(AnnotationsXml);
fprintf(trainID, '%06d\n', idx);
copyfile(imagenamepath{1}, sprintf('JPEGImages/%06d.jpg', idx));
fclose(trainID);
fclose all;
因为只下到了training_1和training_3所以要从training中筛选出training_1和training_3,C++程序如下:
// UCCSProcessing.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream InputFile("training.txt");
ofstream OutputFile("training_results.txt");
stringstream ss;
string line,filename,filename_temp;
int index, SUBJECT_ID;
double x, y, w, h;
getline(InputFile, line);
Mat image;
int i = 1;
while (getline(InputFile, line))
{
ss.str("");
ss.clear();
ss << line;
ss >> index >> filename >> SUBJECT_ID >> x >> y >> w >> h;
filename_temp = "D:\\UCCS\\training_1_3\\" + filename;
image = imread(filename_temp);
if (image.data)
{
OutputFile << i << " " << filename << " " << x << " " << y << " " << w << " " << h << endl;
i++;
}
}
InputFile.close();
OutputFile.close();
return 0;
}
输入的training_1_3文件输入到WiderFace2VOC.m中