appdesigner : error in a code when playing frames of a video with a slider
2 次查看(过去 30 天)
显示 更早的评论
Hello, I want to make a program that by moving a slider plays all the frames of a video.
I have made this code
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1347274/image.png)
here I have created a property
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1347279/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1347284/image.png)
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.
采纳的回答
Kevin Holly
2023-4-7
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!