%% Trials

clear all;close all;clc

% Start building the mex command
mexcmd = 'mex -outdir ../bin';

% Add optimizations if requested
mexcmd = [mexcmd ' -O'];
  
%Jorge - Added optimization support for SSE, without it this does not
%work
mexcmd = [mexcmd ' CXXOPTIMFLAGS="-O3 -DNDEBUG -msse -msse2 -msse3 -mfpmath=sse"'];
mexcmd = [mexcmd ' LDOPTIMFLAGS="-O3"'];

% Turn all warnings on
mexcmd = [mexcmd ' CXXFLAGS="\$CXXFLAGS -Wall"'];
mexcmd = [mexcmd ' LDFLAGS="\$LDFLAGS -Wall"'];

% mexcmd = [mexcmd ' -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann'];
% mexcmd = [mexcmd ' -lfftw3 -lm'];
mexcmd = [mexcmd '-lm'];

eval([mexcmd ' lbp_c.cc']);
% eval([mexcmd ' clbp.cc']);
% eval([mexcmd ' clbp_wh.cc']);
% eval([mexcmd ' clbp_wh_u2.cc']);
% eval([mexcmd ' lbp_simple.cc MxArray.cpp LBP/LBP.cpp -I"LBP"']);
% eval([mexcmd ' hog_4d.cc']);

% error('stop here')

%%

cd ..

addpath_recurse('../voc-release5')

cd ../voc-release5

% compile

cd ../voc-kitti/LBP

%%
 
clc

addpath disCLBP
addpath ../bin

addpath ../../voc-release5/bin

i=imread('figures/c000000.png');
id=imread('figures/d000000.png');

% figure,imshow(i)
% figure,imshow(id)

% ginput(2)

bb=[704 313 814 147];

pos_i = i(bb(4):bb(2),bb(1):bb(3),:);
pos_id = id(bb(4):bb(2),bb(1):bb(3),:);

% figure,imshow(pos_i)
% figure,imshow(pos_id)

sbin = 8;

conf.lbp.overlapping = 0;
conf.lbp.mapping='riu2';
conf.lbp.clbp='S+M';

ih=im2double(cat(3,i,id));
idh=im2double(id);

% window = ih(1:9,1:9,1);
% window = ih(1:150,1:50,1);
window = ih(1:end,1:end,1);

% window

N=100;
t=zeros(1,N);
for i=1:N
    tic
%     fCLBP_wh=clbp_wh_u2(window,sbin);
    fCLBP_wh=lbp_c(window,sbin);
    t(i)=toc;
    fprintf('i: %d\n',i);
    if sum(sum(isnan(fCLBP_wh)))
        error('nan')
    end
%     fprintf('clbp no table: %f\n',toc)
end

fprintf('mean: %.4f\n',mean(t))
fprintf('std: %.4f\n',std(t))

% tic
% fCLBP_wh=clbp_wh(window,sbin);
% fprintf('hog: %f\n',toc);

for x=size(fCLBP_wh,1):-1:1
    for y=size(fCLBP_wh,2):-1:1
        
        
        b=reshape(fCLBP_wh(x,y,:),1,256+1);
        stem(b)
        pause(1)

    end
end


% tic
% fHOG=features_m(ih(:,:,1:3),sbin);
% fHOG=features_m(ih(1:15,1:18,1:3),sbin);
% fprintf('hog: %f\n',toc);

% tic
% a=lbp_simple(idh,8);
% a=lbp_simple(ih(:,:,4),120);
% fprintf('lbp_simple: %f\n',toc)

% 
% tic
% a=hog_4d(ih,8);
% fprintf('hog_4d: %f\n',toc)
% 

% tic
% a=features_lbp(ih(:,:,1),sbin,conf);
% fprintf('features_lbp: %f\n',toc)

% tic
% mapping = getmapping(8,conf.lbp.mapping);
% [clbp_S, clbp_M, ~] = clbp_o(window,1,8,mapping,'h');
% fprintf('features_lbp: %f\n',toc)
% 
% hi=[clbp_S clbp_M];
% fi=reshape(fCLBP,1,20);
% 
% close all
% figure('position',[100 100 750 800])
% stem(hi);
% hold on
% h=stem(fi);
% 
% set(h,'color','r')






