用Matlab搭建GUI视频处理工具

要实现播放视频,获取视频信息,获取图片序列,抓图等基本功能。

一.搭建的基本GUI界面

在这里插入图片描述

利用guide建立基本的框图 a v i d e l . f i g avidel.fig avidel.fig a v i d e l . m avidel.m avidel.m。基本的按钮标签 T a g Tag Tag如下:

“打开视频文件”: o p e n V i d e o openVideo openVideo,“获取视频信息”: g e t V i d e o I n f o r m a t i o n getVideoInformation getVideoInformation,“获取图像序列”: g e t P i c t u r e L i s t getPictureList getPictureList

“生成视频文件”: p r o d u c t A v i productAvi productAvi,“播放”: p u s h b u t t o n P l a y pushbuttonPlay pushbuttonPlay,“暂停”: p u s h b u t t o n P a u s e pushbuttonPause pushbuttonPause,图像: a x e s V i d e o axesVideo axesVideo

“停止”: p u s h b u t t o n S t o p pushbuttonStop pushbuttonStop,“退出系统”: p u s h b u t t o n E x i t pushbuttonExit pushbuttonExit,“进度条”: s l i d e r V i d e o P l a y sliderVideoPlay sliderVideoPlay。基本的视频信息的标签忽略。

二.打开视频文件的操作函数

返回该视频文件的地址路径。

function filePath = OpenVideoFile()
%用对话框打开文件
%   打开视频文件
%   videoFilePath = fullfile(pwd,aviName);
[filename pathname filterindex] = uigetfile(...
    {'*.avi','视频文件(*.avi)';...
    '*.mpeg','视频文件(*.mpeg)';...
    '*.*','所有文件(*.*)'},...
    '选择视频文件','MultiSelect','off',...
    pwd);
filePath = 0;
if isequal(filename,0)||isequal(pathname,0) %只要这里面表示返回或没有合适的文件时候
    return;
end
filePath = fullfile(pathname,filename);
end

回调函数

function openVideo_Callback(hObject, eventdata, handles)
% hObject    handle to openVideo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.videoFilePath = OpenVideoFile();
guidata(hObject,handles);
set(handles.videoFilePathName,'String',handles.videoFilePath);

三.获取图像序列函数

将视频文件.avi抽出每一帧的图片序列放到video_images文件夹的函数

function I = video2Imags( videoFilePath )
%UNTITLED5 此处显示有关此函数的摘要
%   此处显示详细说明
clc;
xyloObj = VideoReader(videoFilePath);
nFrames = xyloObj.NumberOfFrames;
video_imagesPath = fullfile(pwd,'video_images');
if ~exist(video_imagesPath,'dir')
    mkdir(video_imagesPath);
end
files = dir(fullfile(video_imagesPath,'*.jpg'));
if length(files) == nFrames  %如果之前已经产生了图片序列的话就不用再产生了。
    I = 0;
    msgbox('之前该文件已经提取过文件了!','提示信息');
    return;
end
h = waitbar(0,'','name','获取图像视频序列');
steps = nFrames;
for step = 1:nFrames
    temp = read(xyloObj,step);%提取图像中的某一帧,核心函数
    tempstr = sprintf('%s\\%03d.jpg',video_imagesPath,step);
    imwrite(temp,tempstr);
    pause(0.01);
    waitbar(step/steps,h,sprintf('已处理:%d%%',round(step/steps*100)));
end
I = 1;
close(h);
end


回调函数

function getPictureList_Callback(hObject, eventdata, handles)
% hObject    handle to getPictureList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.videoFilePath,0)
   msgbox('该路径不存在!','错误信息');
    return;
end
I = video2Imags( handles.videoFilePath );
if I ~= 0
msgbox('已经成功生成序列文件video_images!','成功信息');
end

四.获取视频信息的函数

回调函数

function getVideoInformation_Callback(hObject, eventdata, handles)
% hObject    handle to getVideoInformation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if handles.videoFilePathName == 0
    msg('请载入视频文件!','提示信息');
    return;
end
videoInfo = VideoReader(handles.videoFilePath);
handles.videoInfo = videoInfo;
guidata(hObject,handles);%获取并保存信息。
set(handles.editFrameNum,'String',sprintf('%d',videoInfo.NumberOfFrames));
set(handles.editFrameWidth,'String',sprintf('%d px',videoInfo.Width));
set(handles.editFrameHeight,'String',sprintf('%d px',videoInfo.Height));
set(handles.editFrameRate,'String',sprintf('%d f/s',videoInfo.FrameRate));
set(handles.editDuration,'String',sprintf('%.1f s',videoInfo.Duration));
set(handles.editVideoFormat,'String',sprintf('%s',videoInfo.VideoFormat));
msgbox('获取信息成功并且已经显示!','提示信息');

五.生成视频文件的函数

将地址为imagesfolder的文件夹中的.jpg文件变成.avi视频存到文件夹地址为videofilename的文件中

function Images2Video( imagesfolder,videofilename )
%UNTITLED3 此处显示有关此函数的摘要
% 将imagesfolder文件夹中的.jpg文件变成视频存到文件夹地址为videofilename的文件中
startFrame = 1;%起始帧
endFrame = size(ls(fullfile(imagesfolder,'*.jpg')),1);
hwrite = VideoWriter(videofilename);
hwrite.FrameRate = 34;%设置帧率
open(hwrite);
hwaitbar = waitbar(0,'','name','生成视频文件...');
steps = endFrame - startFrame;
for i = startFrame:endFrame
    imagFile = sprintf('%03d.jpg',i);
    imagFile = fullfile(imagesfolder,imagFile);
    imagFrame = imread(imagFile);
    imagFrame = im2frame(imagFrame);
    writeVideo(hwrite,imagFrame);
    pause(0.01);
    step = i - startFrame;
    waitbar(step/steps,hwaitbar,sprintf('已处理:%d%%',round(step/steps*100)));
end
close(hwrite);
close(hwaitbar);

end

回调函数

function productAvi_Callback(hObject, eventdata, handles)
% hObject    handle to productAvi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 videoPath = OutputVideoFile();
 if isequal(videoPath,0)
     return;
 end
 %输出文件
 imagefolder = fullfile(pwd,'video_images');
 Images2Video(imagefolder,videoPath);%将video_images文件夹中的文件转化成.avi文件并存到out文件夹中
 msgbox('导出成功!','提示信息');

六.播放,暂停,停止按钮回调函数

播放按钮回调函数

function pushbuttonPlay_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonPlay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.pushbuttonPause,'Enable','On');
set(handles.pushbuttonPause,'String','暂停');
set(handles.sliderVideoPlay,'Max',handles.videoInfo.NumberOfFrames,'Min',0,'Value',1);
set(handles.editSlider,'String',sprintf('%d\\%d',0,handles.videoInfo.NumberOfFrames));
for i = 1:handles.videoInfo.NumberOfFrames
    waitfor(handles.pushbuttonPause,'tag','pushbuttonPause');
    I = imread(fullfile(pwd,sprintf('video_images\\%03d.jpg',i)));
    try
        imshow(I,[],'Parent',handles.axesVideo);%很重要
        %设置进度条
        set(handles.sliderVideoPlay,'Value',i);
        set(handles.editSlider,'String',sprintf('%d/%d',i,handles.videoInfo.NumberOfFrames));
    catch
        return;
    end
    drawnow;
end
%播放完了之后得暂停
set(handles.pushbuttonPause,'Enable','Off');

暂停按钮回调函数

function pushbuttonPause_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonPause (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
str = get(handles.pushbuttonPause,'tag');
if strcmp(str,'pushbuttonPause') == 1
    set(handles.pushbuttonPause,'tag','pushbuttonContinue','String','暂停');
    pause on;
else
    set(handles.pushbuttonPause,'tag','pushbuttonPause','String','播放');
    pause off;
end

停止按钮回调函数

function pushbuttonStop_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonStop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axesVideo);
cla;axis on;box on;
set(gca,'Color',[0.7020 0.7804 1.0000]);
set(handles.editSlider,'String','0/0');
set(handles.pushbuttonPause,'tag','pushbuttonContinue','String','继续');
set(handles.pushbuttonPause,'Enable','off','String','暂停');

七.总代码avidel.m

function varargout = avidel(varargin)
% AVIDEL MATLAB code for avidel.fig
%      AVIDEL, by itself, creates a new AVIDEL or raises the existing
%      singleton*.
%
%      H = AVIDEL returns the handle to a new AVIDEL or the handle to
%      the existing singleton*.
%
%      AVIDEL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in AVIDEL.M with the given input arguments.
%
%      AVIDEL('Property','Value',...) creates a new AVIDEL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before avidel_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to avidel_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help avidel

% Last Modified by GUIDE v2.5 13-Nov-2020 21:34:50

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @avidel_OpeningFcn, ...
                   'gui_OutputFcn',  @avidel_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before avidel is made visible.
function avidel_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to avidel (see VARARGIN)

% Choose default command line output for avidel
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes avidel wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = avidel_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbuttonExit.
function pushbuttonExit_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonExit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function editFrameNum_Callback(hObject, eventdata, handles)
% hObject    handle to editFrameNum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFrameNum as text
%        str2double(get(hObject,'String')) returns contents of editFrameNum as a double


% --- Executes during object creation, after setting all properties.
function editFrameNum_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editFrameNum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editFrameWidth_Callback(hObject, eventdata, handles)
% hObject    handle to editFrameWidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFrameWidth as text
%        str2double(get(hObject,'String')) returns contents of editFrameWidth as a double


% --- Executes during object creation, after setting all properties.
function editFrameWidth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editFrameWidth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editFrameHeight_Callback(hObject, eventdata, handles)
% hObject    handle to editFrameHeight (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFrameHeight as text
%        str2double(get(hObject,'String')) returns contents of editFrameHeight as a double


% --- Executes during object creation, after setting all properties.
function editFrameHeight_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editFrameHeight (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editFrameRate_Callback(hObject, eventdata, handles)
% hObject    handle to editFrameRate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editFrameRate as text
%        str2double(get(hObject,'String')) returns contents of editFrameRate as a double


% --- Executes during object creation, after setting all properties.
function editFrameRate_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editFrameRate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editDuration_Callback(hObject, eventdata, handles)
% hObject    handle to editDuration (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editDuration as text
%        str2double(get(hObject,'String')) returns contents of editDuration as a double


% --- Executes during object creation, after setting all properties.
function editDuration_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editDuration (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editVideoFormat_Callback(hObject, eventdata, handles)
% hObject    handle to editVideoFormat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editVideoFormat as text
%        str2double(get(hObject,'String')) returns contents of editVideoFormat as a double


% --- Executes during object creation, after setting all properties.
function editVideoFormat_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editVideoFormat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function videoFilePathName_Callback(hObject, eventdata, handles)
% hObject    handle to videoFilePathName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of videoFilePathName as text
%        str2double(get(hObject,'String')) returns contents of videoFilePathName as a double


% --- Executes during object creation, after setting all properties.
function videoFilePathName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to videoFilePathName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in OpenVideo.
function OpenVideo_Callback(hObject, eventdata, handles)
% hObject    handle to OpenVideo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on button press in getVideoInformation.
function getVideoInformation_Callback(hObject, eventdata, handles)
% hObject    handle to getVideoInformation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if handles.videoFilePathName == 0
    msg('请载入视频文件!','提示信息');
    return;
end
videoInfo = VideoReader(handles.videoFilePath);
handles.videoInfo = videoInfo;
guidata(hObject,handles);%获取并保存信息。
set(handles.editFrameNum,'String',sprintf('%d',videoInfo.NumberOfFrames));
set(handles.editFrameWidth,'String',sprintf('%d px',videoInfo.Width));
set(handles.editFrameHeight,'String',sprintf('%d px',videoInfo.Height));
set(handles.editFrameRate,'String',sprintf('%d f/s',videoInfo.FrameRate));
set(handles.editDuration,'String',sprintf('%.1f s',videoInfo.Duration));
set(handles.editVideoFormat,'String',sprintf('%s',videoInfo.VideoFormat));
msgbox('获取信息成功并且已经显示!','提示信息');



% --- Executes on button press in getPictureList.
function getPictureList_Callback(hObject, eventdata, handles)
% hObject    handle to getPictureList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.videoFilePath,0)
   msgbox('该路径不存在!','错误信息');
    return;
end
I = video2Imags( handles.videoFilePath );
if I ~= 0
msgbox('已经成功生成序列文件video_images!','成功信息');
end

% --- Executes on button press in productAvi.
function productAvi_Callback(hObject, eventdata, handles)
% hObject    handle to productAvi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 videoPath = OutputVideoFile();
 if isequal(videoPath,0)
     return;
 end
 %输出文件
 imagefolder = fullfile(pwd,'video_images');
 Images2Video(imagefolder,videoPath);%将video_images文件夹中的文件转化成.avi文件并存到out文件夹中
 msgbox('导出成功!','提示信息');

% --- Executes on slider movement.
function sliderVideoPlay_Callback(hObject, eventdata, handles)
% hObject    handle to sliderVideoPlay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function sliderVideoPlay_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderVideoPlay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function editSlider_Callback(hObject, eventdata, handles)
% hObject    handle to editSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editSlider as text
%        str2double(get(hObject,'String')) returns contents of editSlider as a double


% --- Executes during object creation, after setting all properties.
function editSlider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbuttonPlay.
function pushbuttonPlay_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonPlay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.pushbuttonPause,'Enable','On');
set(handles.pushbuttonPause,'String','暂停');
set(handles.sliderVideoPlay,'Max',handles.videoInfo.NumberOfFrames,'Min',0,'Value',1);
set(handles.editSlider,'String',sprintf('%d\\%d',0,handles.videoInfo.NumberOfFrames));
for i = 1:handles.videoInfo.NumberOfFrames
    waitfor(handles.pushbuttonPause,'tag','pushbuttonPause');
    I = imread(fullfile(pwd,sprintf('video_images\\%03d.jpg',i)));
    try
        imshow(I,[],'Parent',handles.axesVideo);%很重要
        %设置进度条
        set(handles.sliderVideoPlay,'Value',i);
        set(handles.editSlider,'String',sprintf('%d/%d',i,handles.videoInfo.NumberOfFrames));
    catch
        return;
    end
    drawnow;
end
%播放完了之后得暂停
set(handles.pushbuttonPause,'Enable','Off');


% --- Executes on button press in pushbuttonPause.
function pushbuttonPause_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonPause (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
str = get(handles.pushbuttonPause,'tag');
if strcmp(str,'pushbuttonPause') == 1
    set(handles.pushbuttonPause,'tag','pushbuttonContinue','String','暂停');
    pause on;
else
    set(handles.pushbuttonPause,'tag','pushbuttonPause','String','播放');
    pause off;
end


% --- Executes on button press in pushbuttonStop.
function pushbuttonStop_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonStop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axesVideo);
cla;axis on;box on;
set(gca,'Color',[0.7020 0.7804 1.0000]);
set(handles.editSlider,'String','0/0');
set(handles.pushbuttonPause,'tag','pushbuttonContinue','String','继续');
set(handles.pushbuttonPause,'Enable','off','String','暂停');

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in openVideo.
function openVideo_Callback(hObject, eventdata, handles)
% hObject    handle to openVideo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.videoFilePath = OpenVideoFile();
guidata(hObject,handles);
set(handles.videoFilePathName,'String',handles.videoFilePath);

八.结果界面

将上述部分函数放到一个文件夹并用matlab切换到当前目录中

在这里插入图片描述

点击打开视频文件,获取视频信息,获取图像按钮的信息后会在该目录下生成一个新的包含图像序列文件的文件夹:

在这里插入图片描述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JbifauyF-1605278316516)(C:\Users\pc\Desktop\图像处理\4.png)]

此时的GUI界面图像如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fiLOTjbc-1605278316519)(C:\Users\pc\Desktop\图像处理\5.png)]

若此时点击生成视频文件就会出现选择以下保存界面:

在这里插入图片描述

就可以将视频文件保存到固定的目录中了。如果点击退出的按钮的话会出现以下界面:
在这里插入图片描述

按下确定就可以退出了。

具体的代码链接:

链接:百度网盘链接
提取码:dpk1
复制这段内容后打开百度网盘手机App,操作更方便哦

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值