%% Main file for VOC tests

clear all;close all;clc

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

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

fv_cache('unlock')

startup
% compile
try
    matlabpool close
catch
end

% matlabpool open 4

% cd ~/Escritorio/voc-self

%% Test Trained model

close all; clc

cd ~/Dropbox/VOC/voc-kitti-rgbd

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);

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


%% Try to train with kitti data

close all; clc

fv_cache('unlock')

cd ~/Dropbox/VOC/voc-kitti-rgbd
addpath '/home/jorge/Escritorio/kitti/devkit/matlab'


kitti_train('car',3)



