UCCSデータセットをVOCデータセットに変換します。

5056 ワード

UCCSデータセット公式サイト:http://vast.uccs.edu/Opensetface/
head.xml

    widerface
    %06d.jpg
    
        My Database
        VOC2007
        flickr
        NULL
    
    
        NULL
        facevise
    
    
        %d
        %d
        %d
    
    0
object.xml

        %s
        Unspecified
        0
        0
        
            %d
            %d
            %d
            %d
        
    
tail.xml



Wider Face 2 VOC.m
function WiderFace2VOC()
%% wider face
% The corresponding annotations are in the following format:
% Here, each face bounding boxe is denoted by:
% .

%% 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
', 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
', idx); copyfile(imagenamepath{1}, sprintf('JPEGImages/%06d.jpg', idx)); fclose(trainID); fclose all;
トラッキングにしか降りられなかったので。1とtrining_3ですから、triningからトラスティングを絞り出します。1とtrining_3,C++プログラムは以下の通りです。
// UCCSProcessing.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include
#include
#include
#include
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;
}

入力のtrining_1_3ファイルはWider Face 2 VOC.mに入力されます。