%% Main file for VOC tests

clear all;close all;clc

addpath_recurse('../voc-release5')
addpath LBP
addpath LBP/disCLBP

cd ../voc-release5

fv_cache('unlock')

startup
% compile
try
%     matlabpool close
%     matlabpool open 4
catch
end

cd ../voc-kitti

addpath(genpath('../../mexopencv/'))

% error('ere')
%% Test Trained model
% 
% close all; clc
% 
% cd ../voc-kitti
% 
% load models/car_final.mat
% 
% image_number = 3000;
% dataset = 'training';
% 
% im = imread(sprintf('~/Escritorio/kitti/2012_object/%s/image_2/%06d.png',dataset,image_number));
% im_disp = imread(sprintf('~/Escritorio/kitti/2012_object/%s/image_disp/%06d.png',dataset,image_number));
% 
% im_disp = color(im_disp);
% 
% disp('Starting detection ...');
% % [bbox, fbbox] = process(im, im_disp, model, -0.5);
% [bbox, fbbox] = process(im, im_disp, model, 0.2);
% 6
% fprintf('Detections %d\n',size(bbox,1));

%%

% for det=1:size(bbox,1) 
%     figure
%     showboxes(im,[bbox(det,1:4) fbbox(det,:)])
% end

% if ~isempty(bbox)
%     showboxes(im, [bbox(1:4) fbbox]);
% else
% if isempty(bbox)
%     disp('No detection')
% end

% figure
% imshow(im)
% imshow(im_disp)

% visualizemodel(model)

%%
% close all
% 
% load VOC2007/car_final.mat;
% im = imread('000034.jpg');
% 
% fprintf('Starting detection\n');
% tic
% [bbox, fbbox] = process(im, model, -0.5);
% fprintf(['Detection time: ' num2str(toc) 's \n'] )
% 
% % fbbox = reshape(fbbox,length(fbbox)/4,5)
% if ~isempty(bbox)
%     showboxes(im, [bbox(1:4) fbbox]);
% else
%     disp('No detection')
% end

%% Do full training

close all; clc

fv_cache('unlock')

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

try
% matlabpool open 4
catch
end

% kitti_train('Pedestrian',1)

%% Try to train with kitti data
% 
close all; clc
% 
fv_cache('unlock')

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

try
% % matlabpool open 4
catch
end

short_train('Pedestrian',1)



