Skip to content

Commit

Permalink
add new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jiweeo committed Dec 6, 2017
1 parent 2339d1c commit 8d9737d
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 26 deletions.
6 changes: 3 additions & 3 deletions compute_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
import numpy as np
def compute_desc():
net=SiameseNetwork()
net=SiameseNetwork().cuda()

net.load_state_dict(torch.load('model.pt'))
net.train(False)
Expand All @@ -20,10 +20,10 @@ def compute_desc():
img=img.reshape(1,1,img.shape[0],img.shape[1])
X=torch.from_numpy(img)

_,output=net(Variable(X.float()),Variable(X.float()))
_,output=net(Variable(X.float()).cuda(),Variable(X.float()).cuda())

#print 'time:'+str(end-start)
mat[i]=output.data.numpy()
mat[i]=output.data.cpu().numpy()
scipy.io.savemat('learned_desc.mat',mdict={'desc':mat})
# print mat.tolist()
return 0
Expand Down
29 changes: 29 additions & 0 deletions getNewImg.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function newImg = getNewImg(myim1, myim2, matches, locs1, locs2)
% INPUT
% im1, im2 - grayscale images, scaled into [0 1]
% matches - the list of matches returned by briefMatch()
% locs1, locs 2 - the locations of keypoints returne by briefLite() .
% m1 x 3 and m2 x3 respectively. each row corresponds to the
% space-scale position: [x_coordinate,y_coordiante,scale]


im1= im2double(myim1);
im2= im2double(myim2);

width = size(im1,2) + size(im2,2);
height = max(size(im1,1), size(im2,1));
nchannel = size(im1,3);
img = zeros(height, width,nchannel);
% size(img)
img(1:size(im1,1),1:size(im1,2),:) = im1;
img(1:size(im2,1),size(im1,2)+1:size(im1,2) + size(im2,2),:) = im2;

position = zeros(size(matches,1),4);

for i = 1:size(matches,1)
p1 = locs1(matches(i,1),:);
p2 = locs2(matches(i,2),:);
position(i,:) = [p1(1) p1(2) size(im1,2)+p2(1) p2(2)];
end
newImg = insertShape(img,'Line',position,'Color','r','LineWidth',1);
end
Binary file modified learned_desc.mat
Binary file not shown.
Binary file modified net1.pyc
Binary file not shown.
44 changes: 44 additions & 0 deletions new_testMatch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
myim1 = imread('../data/book.jpg');
myim1 = imrotate(myim1,-90);
myim1 = imresize(myim1,0.1);
im1 = im2double(myim1);
if size(im1,3)==3
im1= rgb2gray(im1);
end
[locs1, desc1] = learned_siftLite(im1);
%
% im2 = imrotate(im1,45);
% [locs2, desc2] = briefLite(im2);
% [matches] = briefMatch(desc1, desc2);
% plotMatches(im1, im2, matches, locs1, locs2);

video_file='../data/IMG_0918.mp4';
video=VideoReader(video_file);
frame_number=floor(video.Duration * video.FrameRate)-1;

myvideo = zeros(384,461,3,frame_number);
for i=1:frame_number
myim2 = read(video,i);
myim2 = imresize(myim2,0.2);
im2 = im2double(myim2);
if size(im2,3)==3
im2= rgb2gray(im2);
end
[locs2, desc2] = learned_siftLite(im2);

[matches] = siftMatch(desc1, desc2);
newImg = getNewImg(myim1, myim2, matches, locs1, locs2);
myvideo(:,:,:,i) = newImg;
disp(i);
end
% save('../data/myvideo_brief.mat','myvideo');
% load('../data/myvideo_brief.mat');
% implay(myvideo);
writer = VideoWriter('..\data\myvideo_SIFT.avi', ...
'Uncompressed AVI');
writer.FrameRate = video.FrameRate;
open(writer);
for i=1:size(myvideo,4)
writeVideo(writer,myvideo(:,:,:,i));
end
close(writer);
Binary file modified patch.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion siftMatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
% into desc1 and the second column are indices into desc2

if nargin<3
ratio = .6;
ratio = .8;
end

% compute the pairwise Hamming distance
Expand Down
22 changes: 0 additions & 22 deletions testMatch.m~

This file was deleted.

0 comments on commit 8d9737d

Please sign in to comment.