%% Do detections in standard 2D mode

clear all;close all;clc

addpath_recurse('../voc-release5')

cd ../voc-release5

fv_cache('unlock')

startup
% compile
try
    matlabpool close
    matlabpool open 4
catch
end

cd ../voc-kitti

%%
% clear and close everything

clc

addpath '/home/jorge/Escritorio/kitti/devkit/matlab';

disp('======= KITTI Dataset test =======');

root_dir  = '/home/jorge/Escritorio/kitti/2012_object';
train_dir = fullfile(root_dir,'/training-testing/label_2');
test_dir  = fullfile(root_dir,'/training-testing/test_rgb_pedestrian_root_only'); % location of your testing dir
images_dir = fullfile(root_dir,'/training-testing/image_2');
images_disp_dir = fullfile(root_dir,'/training-testing/image_disp');

test_set_start = 3741;
test_set_end = 7480;

load models/Pedestrian_mix.mat

t_start = tic;
for n=test_set_start:test_set_end
    
    fprintf('processing n: %d (%d-%d)\n',n,test_set_start,test_set_end);
    tic
    
%     train_objects = readLabels(train_dir,n);
    
    im = imread(sprintf('%s/%06d.png',images_dir,n));
    
    [bbox, fbbox] = process(im, model, -1.0);
    
    test_objects=[];
    
    for det=1:size(bbox,1)
        test_objects(det).type = model.class;
        test_objects(det).x1 = bbox(det,1);
        test_objects(det).y1 = bbox(det,2);
        test_objects(det).x2 = bbox(det,3);
        test_objects(det).y2 = bbox(det,4);
        test_objects(det).alpha = pi/2;
        test_objects(det).score = bbox(det,6);
    end

    writeLabels(test_objects,test_dir,n);
    
    fprintf('done in %.1f sec\n',toc);
end

total_time = toc(t_start);
hours = floor(total_time/(60*60));
minutes = floor(total_time/60) - hours*60;
seconds = floor(total_time) - hours*60*60 - minutes*60;

fprintf('Training finished in %d hours %d minutes %d seconds\n',hours,minutes,seconds);



