Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function probality = generateTemporalPairwise( sequence, densematch, model, normalize_ratio)
addpath(genpath('/BS/pedestrian-detection-tracking/work/project/3rd/liblinear-1.94/'));
addpath /home/tang/Projects/multicut_tracking/tracking-multicut-git/utils
% In this function we generate edges and cost of edges detections in
% neighboring frames
% sequence - the structure contains image list and detection list
% densematch: in densematch.mat
% model: obtained by loading the pairwise model
% normalize_ratio: obtained by loading the pairwise model
% load data from eldar
img_list = {sequence.image};
detection_list = {sequence.detections};
num_frames = length(img_list);
assert (length(detection_list) == num_frames);
img_size = size(imread(img_list{1}));
% hard code part size
box_size = 40;
% convert detection coordinates to bounding boxes
detection_all = cell(num_frames,1);
for i = 1:num_frames
det = load(detection_list{i});det = det.detection_coordinates;
box = [det(:,1)-box_size/2, det(:,2)-box_size/2,det(:,1)+box_size/2, det(:,2)+box_size/2];
detection_all{i} = box;
end
% compute pairwise probality between detections in the neighboring frames
probality = cell(num_frames);
for i = 1:num_frames -1
fprintf('Compute pairwise cost for frame: %d \n', i);
det_1 = detection_all{i};
det_2 = detection_all{i+1};
cur_dm = densematch{i,i+1};
cur_prob = compute_pairwise_cost_block_densematch(det_1,det_2,model,normalize_ratio,cur_dm,img_size);
probality{i,i+1} = cur_prob;
end
end
function edges_prob = compute_pairwise_cost_block_densematch(b1,b2,model,normalize_ratio,cur_dm,img_size)
num_det_1 = size(b1,1);
num_det_2 = size(b2,1);
b1(b1(:,1)<=0,1) = 1;
b1(b1(:,2)<=0,2) = 1;
b1(b1(:,3)==0,3) = 1;b1(b1(:,3)> img_size(2),3) = img_size(2);
b1(b1(:,4)==0,4) = 1;b1(b1(:,4)> img_size(1),4) = img_size(1);
b2(b2(:,1)<=0,1) = 1;
b2(b2(:,2)<=0,2) = 1;
b2(b2(:,3)==0,3) = 1;b2(b2(:,3)> img_size(2),3) = img_size(2);
b2(b2(:,4)==0,4) = 1;b2(b2(:,4)> img_size(1),4) = img_size(1);
f_dm = zeros(num_det_2,num_det_1);
parfor i = 1 : num_det_1
d1 = b1(i,:); rowidx1 = ceil(d1(2)):floor(d1(4));colidx1 = ceil(d1(1)):floor(d1(3));
rowsub1 = repmat(rowidx1',1,length(colidx1));
colsub1 = repmat(colidx1,length(rowidx1),1);
d1_ind = sub2ind(img_size(1:2), rowsub1(:), colsub1(:));
[~,ia_1,~] = intersect(cur_dm(:,1),d1_ind);
for j = 1:num_det_2
d2 = b2(j,:); rowidx2 = ceil(d2(2)):floor(d2(4));colidx2 = ceil(d2(1)):floor(d2(3));
rowsub2 = repmat(rowidx2',1,length(colidx2));
colsub2 = repmat(colidx2,length(rowidx2),1);
d2_ind = sub2ind(img_size(1:2), rowsub2(:), colsub2(:));
[~,ia_2,~] = intersect(cur_dm(:,2),d2_ind);
i_box = intersect(ia_1,ia_2);
u_box = union(ia_1,ia_2);
if isempty(u_box)
f_dm(j,i) = 0
else
f_dm(j,i) = length(i_box)/length(u_box);
end
end
end
f = [f_dm(:)];
[exp_num, dim] = size(f);
f_quad = zeros(exp_num, (dim-1)*dim/2);
dim_count = 1;
for m = 1:dim
for n = 1:dim
f_quad(:,dim_count) = f(:,m).*f(:,n);
dim_count = dim_count + 1;
end
end
f = [f f_quad];
%%
f = normalize_feature(f, normalize_ratio);
f = sparse(double(f));
label = ones(size(f,1),1);
[~, ~,pro_estimate] = predict(label, f, model, '-b 1 -q');
edges_prob = reshape(pro_estimate(:,1),num_det_2,num_det_1);
end