-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
167 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
clear all; | ||
close all; | ||
|
||
interpolation_on = 0; | ||
|
||
Lm = 2; | ||
|
||
xsc = 300; | ||
ysc = 300; | ||
winLength = 20; | ||
winHeight = 20; | ||
x0 = xsc - winLength/2; | ||
y0 = ysc - winHeight/2; | ||
x1 = x0 + winLength; | ||
y1 = y0 + winHeight; | ||
|
||
g = double(zeros(2, 1)); | ||
|
||
%iterate over frames | ||
for f = 1:400 | ||
|
||
f | ||
|
||
frame = imread(['../pudelko/res_640_480/frame_', num2str(floor(f/100)), num2str(floor(mod(f, 100)/10)), num2str(mod(f,10)), '.ppm']); | ||
gray_frame = frame(:, :, 1); | ||
|
||
% gray_frame_L1 = scaledown(gray_frame); | ||
% gray_frame_L2 = scaledown(gray_frame_L1); | ||
% gray_frame_L3 = scaledown(gray_frame_L2); | ||
gray_frame_L1 = imresize(gray_frame, 0.5, 'bilinear'); | ||
gray_frame_L2 = imresize(gray_frame_L1, 0.5, 'bilinear'); | ||
gray_frame_L3 = imresize(gray_frame_L2, 0.5, 'bilinear'); | ||
|
||
pyramidal_guess_x = 0; | ||
pyramidal_guess_y = 0; | ||
|
||
if f == 1 | ||
|
||
imshow(frame); | ||
|
||
elseif f > 1 | ||
|
||
%piramid loop start | ||
for L = Lm:-1:0 | ||
|
||
L; | ||
|
||
level_x0 = x0/(2^L); | ||
level_y0 = y0/(2^L); | ||
|
||
switch L | ||
|
||
case 3 | ||
level_frame = gray_frame_L3; | ||
level_prev_frame = prev_gray_frame_L3; | ||
case 2 | ||
level_frame = gray_frame_L2; | ||
level_prev_frame = prev_gray_frame_L2; | ||
case 1 | ||
level_frame = gray_frame_L1; | ||
level_prev_frame = prev_gray_frame_L1; | ||
case 0 | ||
level_frame = gray_frame; | ||
level_prev_frame = prev_gray_frame; | ||
end | ||
|
||
%generate G matrix and b vector | ||
G = [0, 0; | ||
0, 0]; | ||
b = [0; | ||
0]; | ||
|
||
for row = level_y0 : 1 : level_y0 + winHeight | ||
for col = level_x0 : 1 : level_x0 + winLength | ||
|
||
if(interpolation_on == 1) | ||
Ix = (interpolation(col+1, row, level_prev_frame) - interpolation(col-1, row, level_prev_frame))/2; | ||
Iy = (interpolation(col, row+1, level_prev_frame) - interpolation(col, row-1, level_prev_frame))/2; | ||
dI = interpolation(col, row, level_prev_frame) - interpolation(col + pyramidal_guess_x, row + pyramidal_guess_y, level_frame); | ||
else | ||
row_ = floor(row); | ||
col_ = floor(col); | ||
Ix = (double(level_prev_frame(row_, col_+1)) - double(level_prev_frame(row_, col_-1)))/2; | ||
Iy = (double(level_prev_frame(row_+1, col_)) - double(level_prev_frame(row_-1, col_)))/2; | ||
dI = double(level_prev_frame(row_, col_)) - double(level_frame(row_ + floor(pyramidal_guess_y), col_ + floor(pyramidal_guess_x))); | ||
end | ||
|
||
dG = [Ix^2, Ix*Iy; | ||
Ix*Iy, Iy^2]; | ||
db = [dI*Ix; | ||
dI*Iy]; | ||
|
||
G = G + dG; | ||
b = b + db; | ||
end | ||
end | ||
|
||
d = linsolve(G, b); | ||
|
||
%guess for higher level of pyramid | ||
if(L ~= 0) | ||
pyramidal_guess_x = 2*(pyramidal_guess_x + d(1)); | ||
pyramidal_guess_y = 2*(pyramidal_guess_y + d(2)); | ||
end | ||
end | ||
|
||
%solution for this frame | ||
x0 = x0 + d(1) + pyramidal_guess_x; | ||
y0 = y0 + d(2) + pyramidal_guess_y; | ||
|
||
if(f == 2 || f == 61 || f == 100 || f == 123 || f == 179 || f == 317) | ||
|
||
% imshow(frame); | ||
% hold on; | ||
% rectangle('Position', [round(x0), round(y0), winLength, winHeight], 'LineWidth', 3, 'EdgeColor', 'r'); | ||
% hold off; | ||
% frame = insertShape(frame, 'Rectangle', [round(xsc), round(ysc), l, h], 'LineWidth', 4, 'Color', 'r'); | ||
% imwrite(frame, ['klt_pyramid_', num2str(floor(f/100)), num2str(floor(mod(f, 100)/10)), num2str(mod(f,10)), '.png']); | ||
% ginput(1); | ||
% imshow(frame); | ||
% hold on; | ||
% rectangle('Position', [x0, y0, winLength, winHeight], 'LineWidth', 2, 'EdgeColor', 'r'); | ||
% hold off; | ||
% ginput(1); | ||
end | ||
|
||
imshow(frame); | ||
hold on; | ||
rectangle('Position', [floor(x0), floor(y0), winLength, winHeight], 'LineWidth', 2, 'EdgeColor', 'r'); | ||
hold off; | ||
ginput(1); | ||
end | ||
|
||
prev_gray_frame = gray_frame; | ||
prev_gray_frame_L1 = gray_frame_L1; | ||
prev_gray_frame_L2 = gray_frame_L2; | ||
prev_gray_frame_L3 = gray_frame_L3; | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters