how to convert video to image

3 views (last 30 days)
i want to know the command that can help me to convert video frame into image to image processing this image and detect the required extracted features and locate the object
  5 Comments
saeed ahmed
saeed ahmed on 16 Apr 2019
Thank you but i use a live time video not a recorded one
saeed ahmed
saeed ahmed on 16 Apr 2019
if i want to apply that on this algorithm how can i do it
vid=videoinput('winvideo',1,'YUY2_640x480');
%Set the frames&RGB
set(vid,'FramesPerTrigger',inf);
set(vid,'ReturnedColorspace','rgb')
%Set timer of screenshoting of images per millisecond
vid.FrameGrabInterval=0.5;
%Acquiring video
start(vid);
%Set number of Frames in video
while(vid.FramesAcquired<=100)
%To store extracted frames
data=getsnapshot(vid);
a=snapshot(vid);
%extracting the Red color from grayscale image
diff_im=imsubtract(1.3*data(:,:,1),rgb2gray(data));
%Filtering the noise
diff_im=medfilt2(diff_im,[3,3]);
%Converting grayscale image into binary image
diff_im=im2bw(diff_im,0.18);
%remove all pixels less than 300 pixel
diff_im=bwareaopen(diff_im,300);
%Draw rectangular boxes around the red object detected & label image
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid','Orientation');
%Show image
imshow(data);
imshow(a);
hold on
%create a loop for the regtangular box
for(object=1:length(stats))
%saving data of centroid and boundary in BB & BC
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
be=stats(object).Orientation;
%Draw the rectangle with data BB & BC
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
%Plot the rectangle output
plot(bc(1),bc(2),'-m+')
%Output X&Y coordinates
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
b=text(bc(1)-50,bc(2)+45, strcat('angel:', num2str(round(be))));
set(b, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'blue');
end
hold off
end
stop(vid);
%Flush the memory
flushdata(vid);
clear all;

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 16 Apr 2019
See my attached demo that will extract all frames, or you can process each frame one at a time.
  3 Comments
saeed ahmed
saeed ahmed on 16 Apr 2019
can i make it like that ??
data=getsnapshot(vid);
a=snapshot(data);
Image Analyst
Image Analyst on 17 Apr 2019
No. Startup imaqtool and then do a preview. Look in the window for what commands it's doing.
>> imaqtool

Sign in to comment.

More Answers (1)

KSSV
KSSV on 16 Apr 2019
vidObj = VideoReader('C:\Users\Public\Videos\Sample Videos\Wildlife.wmv');
numFrames = 0;
iwant = cell([],1) ;
while hasFrame(vidObj)
F = readFrame(vidObj);
numFrames = numFrames + 1;
imagesc(F)
drawnow
iwant{numFrames} = F ;
end
YOu can access the respective images of frame using iwant{i}.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!