How to resize video

조회 수: 176(최근 30일)
Alessandro Clocchiatti
Alessandro Clocchiatti 2017년 1월 30일
댓글: Image Analyst 2020년 11월 25일
Hi all, I have to create a program that allows me to resize a video by 50%. Does somebody have any tips? How could I set the code?

답변(4개)

Image Analyst
Image Analyst 2017년 1월 31일
See my attached demo. In the loop over frame, just resize the frame just read in and write it out with writeVideo(). If you can't figure it out, let me know what frame size you want your output in.
  댓글 수: 4
Image Analyst
Image Analyst 2020년 10월 15일
Not sure what that means. Image frames have a certain number of pixels across (wide) and high (tall). If you reduce those, you will reduce both the pixel size across and tall, as well as the spatial resolution (meters per pixel) in real world units, meaning the ability to distinguish between two points in meters (or whatever unit you're using). Increasing the number of pixels will give you more pixels across and tall but will not increase the real world spatial resolution, meaning that you'll have more pixels per meter, but how close two points can be and still be resolved will not be changed.

댓글을 달려면 로그인하십시오.


Takuji Fukumoto
Takuji Fukumoto 2017년 1월 30일
imresize function is fine. Here is the example.
vidobj = vision.VideoFileReader('moviename')
viewer = vision.DeployableVideoPlayer;
while (1)
A = step(vidobj);
viewframe = imresize(A,0.5);
step(viewer, viewframe);
end
release(vidobj);
release(viewer);
  댓글 수: 2
Wenxuan Liang
Wenxuan Liang 2020년 8월 31일
While(1)?~?!!?!?!

댓글을 달려면 로그인하십시오.


Takuji Fukumoto
Takuji Fukumoto 2017년 1월 31일
I think you can write like this
function myfunc()
%code
end
  댓글 수: 4
Takuji Fukumoto
Takuji Fukumoto 2017년 2월 2일
Not in the loop. When you use system object, you should use step function. This is a sample code to save file.
% Set up the reader and writer objects.
videoFReader = vision.VideoFileReader('viplanedeparture.mp4');
videoFWriter = vision.VideoFileWriter('myFile.avi','FrameRate',...
videoFReader.info.VideoFrameRate);
Write the first 50 frames from original file into a newly created AVI file.
for i=1:50
videoFrame = step(videoFReader);
step(videoFWriter,videoFrame);
end
%%Close the input and output files.
release(videoFReader);
release(videoFWriter);

댓글을 달려면 로그인하십시오.


Abdullah Amer Mohammed Salih
Abdullah Amer Mohammed Salih 2020년 11월 24일
Thanks for your code, I need to change video in dimentions means the video for example is 100 x 100 it will be 30 x30. that is a liniear transformation.
I also need to change the shape of the video means I change it from rectangle to polygon for example. any clue how I do that?
  댓글 수: 10
Image Analyst
Image Analyst 2020년 11월 25일
Thanks.
You can make whatever list of (x,y) coordinates you want. Or you can just start with a binary image (mask) that you got from thresholding or wherever.
Are you going to be
  1. creating a mask from a list of (x,y) coordinates (in which case you'll use poly2mask), or
  2. creating a mask by some other means, like thresholding or some other image segmentation method?
If you need help, attach either the list of (x,y) coordinates in a .mat file with the paper clip icon, or attach the mask image itself.

댓글을 달려면 로그인하십시오.

범주

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by