I have a video of a man walking.I need to bring this man in middle keeping his motion intact. i.e. appears to be walking but stays at same place
1 view (last 30 days)
Show older comments
</matlabcentral/answers/uploaded_files/60047/001-bg-01-090-041.png> It's in black and white silhouette form. (Man-White, Rest-Black). This man is walking from first frame to last frame, from right to left. I want him to always be in center, but he should appear to be moving. Such that it looks like he is walking on a treadmill.
I did the cropping part with the help of @Image Analyst. I don't know how to fix the centroid at one point, so that the person doesn't appear to vibrate. Also I cant make movie as all bounding boxes are not equal. Here is the code till now
clc;
close all;
clear all;
video_read = VideoReader('D:\PROJECT M.Tech\Databases\Videos\DATA SET B\009\bg-01\090\090.avi');
numframes = video_read.NumberOfFrames;
for j= 1:numframes
frame=read(video_read,j);
im=rgb2gray(frame);
im = bwareaopen(im,50);
siz=size(im); % image dimensions
% Label the disconnected foreground regions (using 8 conned neighbourhood)
L=bwlabel(im,8);
% Get the bounding box around each object
bb=regionprops(L,'BoundingBox');
% Crop the individual objects and store them in a cell
n=max(L(:)); % number of objects
ObjCell=cell(n,1);
for i=1:n
% Get the bb of the i-th object and offest by 2 pixels in all
% directions
bb_i=ceil(bb(i).BoundingBox);
idx_x=[bb_i(1)-2 bb_i(1)+bb_i(3)+2];
idx_y=[bb_i(2)-2 bb_i(2)+bb_i(4)+2];
if idx_x(1)<1, idx_x(1)=1; end
if idx_y(1)<1, idx_y(1)=1; end
if idx_x(2)>siz(2), idx_x(2)=siz(2); end
if idx_y(2)>siz(1), idx_y(2)=siz(1); end
% Crop the object and write to ObjCell
im=L==i;
ObjCell{i}=im(idx_y(1):idx_y(2),idx_x(1):idx_x(2));
end
% Visualize the individual objects
figure
for i=1:n
subplot(1,n,i)
imshow(ObjCell{i})
end
%bbox=regionprops(frame_im,'BoundingBox')
F(j)=getframe;
end
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!