%% Main file for VOC tests

clear all;close all;clc

addpath_recurse('../voc-release5')


%%
% 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/label_2');
test_dir  = fullfile(root_dir,'/training/test_rgbd64_5000/detections'); % location of your testing dir
images_dir = fullfile(root_dir,'/training/image_2');
images_disp_dir = fullfile(root_dir,'/training/image_disp');

% read objects of first training image

% first 500 with 0.0 threshold

NIMAGES = 7481;
test_set_start = 0;
test_set_end = 7481;

load models/car_rgbd_5000/car_final

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));
    im_disp = imread(sprintf('%s/%06d.png',images_disp_dir,n));
    im_disp = repmat(im_disp,[1 1 3]);
    
    [bbox, fbbox] = process(im, im_disp, model, -0.5);
    
    test_objects=[];
    
    for det=1:size(bbox,1)
        test_objects(det).type = 'Car';
        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

fprintf('All done, in %.1f sec\n',toc(t_start));

%% Do detections in standard 2D mode

clear all;close all;clc

cd ~/Dropbox/VOC/voc-kitti
addpath_recurse('~/Dropbox/VOC/voc-release5')

cd '~/Dropbox/VOC/voc-release5'

startup
% compile

matlabpool open 4

%%
% clear and close everything
cd ~/Dropbox/VOC/voc-kitti

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/label_2');
test_dir  = fullfile(root_dir,'/training/test_0'); % location of your testing dir
images_dir = fullfile(root_dir,'/training/image_2');
images_disp_dir = fullfile(root_dir,'/training/image_disp');

% read objects of first training image

NIMAGES = 7481;
test_set_start = 0;
test_set_end = 3200;

load models/car_final.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, -0.5);
    
    test_objects=[];
    
    for det=1:size(bbox,1)
        test_objects(det).type = 'Car';
        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

fprintf('All done, in %.1f sec\n',toc(t_start));

