function varargout = MainFrame(varargin)
% MAINFRAME MATLAB code for MainFrame.fig
% MAINFRAME, by itself, creates a new MAINFRAME or raises the existing
% singleton*.
%
% H = MAINFRAME returns the handle to a new MAINFRAME or the handle to
% the existing singleton*.
%
% MAINFRAME('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAINFRAME.M with the given input arguments.
%
% MAINFRAME('Property','Value',...) creates a new MAINFRAME or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MainFrame_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MainFrame_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 MainFrame
% Last Modified by GUIDE v2.5 30-Mar-2014 17:05:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MainFrame_OpeningFcn, ...
'gui_OutputFcn', @MainFrame_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 MainFrame is made visible.
function MainFrame_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 MainFrame (see VARARGIN)
% Choose default command line output for MainFrame
handles.output = hObject;
warning off all;
clc;
handles.videoFilePath = 0;
handles.videoInfo = 0;
handles.videoImgList = 0;
handles.videoStop = 1;
handles.videoTrackFlag = 0;
handles.pts = 0;
handles.tms = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MainFrame wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MainFrame_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 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)
% 播放按钮
if isequal(handles.videoFilePath, 0) || isequal(handles.videoInfo, 0)
msgbox('请先获取视频信息', '提示信息');
return;
end
[pathstr, name, ext] = fileparts(handles.videoFilePath);
set(handles.pushbuttonPause, 'Enable', 'On');
set(handles.pushbuttonPause, 'tag', '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('%s_images\\%04d.jpg', name, 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 pushbuttonOpenVideoFile.
function pushbuttonOpenVideoFile_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonOpenVideoFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 打开视频文件按钮
videoFilePath = OpenVideoFile();
if videoFilePath == 0
return;
end
set(handles.edit_videowidth, 'String', '');
set(handles.editVideoFilePath, 'String', videoFilePath);
msgbox('打开视频文件成功!', '提示信息');
handles.videoFilePath = videoFilePath;
guidata(hObject, handles);
% --- Executes on button press in pushbuttonkemspgz.
function pushbuttonkemspgz_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonkemspgz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
videoFilePath = handles.videoFilePath;
if videoFilePath == 0
return;
end
% [Xpoints1, Ypoints1, Xpoints2, Ypoints2, tms, yc] = ProcessVideo(videoFilePath);
load tmp.mat
handles.pts = {[Ypoints1' Xpoints1'], [Ypoints2' Xpoints2']};
handles.tms = tms;
handles.yc = yc;
% Update handles structure
guidata(hObject, handles);
msgbox('定位成功!', '提示信息');
% --- Executes on button press in pushbuttonImageList.
function pushbuttonImageList_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonImageList (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) || isequal(handles.videoInfo, 0)
msgbox('请先获取视频信息', '提示信息');
return;
end
Video2Images(handles.videoFilePath);
% Update handles structure
guidata(hObject, handles);
msgbox('获取图像序列成功!', '提示信息');
% --- Executes on button press in pushbuttonStopCheck.
function pushbuttonStopCheck_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonStopCheck (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.pts, 0)
msgbox('请先获取定位信息', '提示信息');
return;
end
pts = handles.pts;
pts1 = pts{1}; pts2 = pts{2};
[pathstr, name, ext] = fileparts(handles.videoFilePath);
set(handles.pushbuttonPause, 'Enable', 'On');
set(handles.pushbuttonPause, 'tag', '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 : min(handles.videoInfo.NumberOfFrames, size(pts1, 1))
waitfor(handles.pushbuttonPause,'tag','pushbuttonPause');
I = imread(fullfile(pwd, sprintf('%s_images\\%04d.jpg', name, i)));
imshow(I, [], 'Parent', handles.axesVideo);
set(handles.sliderVideoPlay, 'Value', i);
set(handles.editSlider, 'String', sprintf('%d/%d', i, handles.videoInfo.NumberOfFrames));
axes(handles.axesVideo); hold on;
plot(pts1(i, 1), pts1(i, 2), 'go-', 'MarkerFaceColor', 'g');
plot(pts2(i, 1), pts2(i, 2), 'bo-', 'MarkerFaceColor', 'b');
hold off;
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', '继续');