Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ankanbansal authored Apr 14, 2017
1 parent a4b3f3c commit 9634b9f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
60 changes: 60 additions & 0 deletions convertEllipseToRect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys, os
import numpy as np
from math import *
from PIL import Image

def filterCoordinate(c,m):
if c < 0:
return 0
elif c > m:
return m
else:
return c


ellipse_filename = '../FDDB-folds/FDDB-fold-10-ellipseList.txt'
rect_filename = '../FDDB-folds/FDDB-fold-10-rectList.txt'

with open(ellipse_filename) as f:
lines = [line.rstrip('\n') for line in f]

f = open(rect_filename,'wb')
i = 0
while i < len(lines):
img_file = '/path-to-data/FDDB/images/' + lines[i] + '.jpg'
img = Image.open(img_file)
w = img.size[0]
h = img.size[1]
num_faces = int(lines[i+1])
for j in range(num_faces):
ellipse = lines[i+2+j].split()[0:5]
a = float(ellipse[0])
b = float(ellipse[1])
angle = float(ellipse[2])
centre_x = float(ellipse[3])
centre_y = float(ellipse[4])

tan_t = -(b/a)*tan(angle)
t = atan(tan_t)
x1 = centre_x + (a*cos(t)*cos(angle) - b*sin(t)*sin(angle))
x2 = centre_x + (a*cos(t+pi)*cos(angle) - b*sin(t+pi)*sin(angle))
x_max = filterCoordinate(max(x1,x2),w)
x_min = filterCoordinate(min(x1,x2),w)

if tan(angle) != 0:
tan_t = (b/a)*(1/tan(angle))
else:
tan_t = (b/a)*(1/(tan(angle)+0.0001))
t = atan(tan_t)
y1 = centre_y + (b*sin(t)*cos(angle) + a*cos(t)*sin(angle))
y2 = centre_y + (b*sin(t+pi)*cos(angle) + a*cos(t+pi)*sin(angle))
y_max = filterCoordinate(max(y1,y2),h)
y_min = filterCoordinate(min(y1,y2),h)

text = img_file + ',' + str(x_min) + ',' + str(y_min) + ',' + str(x_max) + ',' + str(y_max) + '\n'
f.write(text)

i = i + num_faces + 2


f.close()
43 changes: 43 additions & 0 deletions generateLabels.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
root_dir = '/path-to-data/FDDB/';
labels_dir = [root_dir 'labels/'];
images_dir = [root_dir 'images/'];
train_file = [root_dir 'train.txt'];
f_train = fopen(train_file,'w');

for i = 1:10
fold_file = [root_dir 'FDDB-folds/FDDB-fold-' sprintf('%02d',i) '-rectList.txt'];
A = importdata(fold_file);
for j = 1:length(A.textdata)
img_fname = A.textdata{j};
img = imread(img_fname);
img_width = size(img,2);
img_height = size(img,1);
temp = strsplit(img_fname,'.');
labels_fname = [strrep(temp{1},'images','labels') '.txt'];
labels_fname_split = strsplit(labels_fname,'/');
month_dir = [labels_dir labels_fname_split{end-4} '/' labels_fname_split{end-3} '/'];
date_dir = [month_dir labels_fname_split{end-2} '/'];
size_dir = [date_dir labels_fname_split{end-1} '/'];
if ~exist(month_dir,'dir')
system(['mkdir ' month_dir]);
end
if ~exist(date_dir, 'dir')
system(['mkdir ' date_dir]);
end
if ~exist(size_dir,'dir')
system(['mkdir ' size_dir]);
end
if ~exist(labels_fname)
f = fopen(labels_fname,'w');
fprintf(f_train,'%s\n',img_fname);
else
f = fopen(labels_fname,'a');
end
x = (A.data(j,1) + A.data(j,3))/(2*img_width);
w = (A.data(j,3) - A.data(j,1))/img_width;
y = (A.data(j,2) + A.data(j,4))/(2*img_height);
h = (A.data(j,4) - A.data(j,2))/img_height;
fprintf(f,'%d %f %f %f %f\n',0,x,y,w,h);
fclose(f);
end
end

0 comments on commit 9634b9f

Please sign in to comment.