appdesigner : error in a code when playing frames of a video with a slider
1 view (last 30 days)
Show older comments
Marina Llopis Segura
on 6 Apr 2023
Commented: Marina Llopis Segura
on 11 Apr 2023
Hello, I want to make a program that by moving a slider plays all the frames of a video.
I have made this code
here I have created a property
I would like the slider to change its length to the length of the video that I have already saved in a variable that I have called longitudvideo and I would like to know if someone can find the error that I have in the code because only some color points are reproduced and not the frames of the video.
Accepted Answer
Kevin Holly
on 7 Apr 2023
It looks like you are using imshow with a double.
imshow(app.AllFrames(:,:,:,idx),'Parent',app.video)
If you have an 8 bit image, you can convert the image from a double to an int8 as such:
uint8(app.AllFrames(:,:,:,idx))
imshow(uint8(app.AllFrames(:,:,:,idx)),'Parent',app.video)
You could create something as shown below with an if condition (app attached):
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
tiempo matlab.ui.control.NumericEditField
tiempoEditFieldLabel matlab.ui.control.Label
Slider matlab.ui.control.Slider
SliderLabel matlab.ui.control.Label
seleccionvideoButton matlab.ui.control.Button
video matlab.ui.control.UIAxes
end
properties (Access = private)
AllFrames % Description
v
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: seleccionvideoButton
function seleccionvideoButtonPushed(app, event)
tipos = {'*.mp4;*.avi;*webm;*.mov'};
[file,path] = uigetfile(tipos);
if isequal(file,0)
disp('seleccion cancelada')
else
videopath = fullfile(path,file);
app.v = VideoReader(videopath);
numFrames = app.v.NumFrames;
app.AllFrames = zeros(app.v.Height,app.v.Width,3,numFrames);
for a = 1:numFrames
frame = read(app.v,a);
app.AllFrames(:,:,:,a) = frame;
end
end
end
% Value changing function: Slider
function SliderValueChanging(app, event)
changingValue = event.Value;
idx = floor(changingValue);
if app.v.BitsPerPixel == 24
imshow(uint8(app.AllFrames(:,:,:,idx)),'Parent',app.video)
end
b = roundn(changingValue,-2);
app.tiempo.Value = b;
end
end
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!