function varargout = testing(varargin)

global blueSquareSigns;
blueSquareSigns = loadimage(dir('blueSquareSigns\*.png'));

global blueCirkleSigns;
blueCirkleSigns = loadimage(dir('blueCirkleSigns\*.png'));

% TESTING MATLAB code for testing.fig
%      TESTING, by itself, creates a new TESTING or raises the existing
%      singleton*.
%
%      H = TESTING returns the handle to a new TESTING or the handle to
%      the existing singleton*.
%
%      TESTING('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TESTING.M with the given input arguments.
%
%      TESTING('Property','Value',...) creates a new TESTING or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before testing_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to testing_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 testing

% Last Modified by GUIDE v2.5 29-Apr-2017 19:53:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @testing_OpeningFcn, ...
    'gui_OutputFcn',  @testing_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 testing is made visible.
function testing_OpeningFcn(hObject, ~, 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 testing (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = testing_OutputFcn(~, ~, 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 pushbuttonOpen.
function pushbuttonOpen_Callback(hObject, ~, handles)

[filename, pathname] = uigetfile({'*.avi', 'All Files'});
handles.readerobj = VideoReader([pathname filename]);
% handles.vidFrames = readerobj.read();
handles.numFrames = get(handles.readerobj, 'numberOfFrames');

global actualFrame;
actualFrame = 1;

img = handles.readerobj.read(actualFrame);
imshow(img, 'Parent', handles.axes1);
guidata(hObject, handles);


% hObject    handle to pushbuttonOpen (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 pushbuttonPlay.
function pushbuttonPlay_Callback(~, ~, handles)

global play;
global actualFrame;
play = true;
axes(handles.axes1);
fps=30;

for i=actualFrame : handles.numFrames
    if play
        
        actualFrame = i;
        image = handles.readerobj.read(i);
        imshow(image);
        
        binaryImage=vidihsv(image);
        [blob, shapeID] = getimages(binaryImage, image);
        
        x = useSift(shapeID, blob);
        imshow(x, 'Parent', handles.axes2);
        
        x = useSurf(shapeID, blob);       
        imshow(x, 'Parent', handles.axes3);
        
%         x = useBrisk(shapeID, blob);
%         imshow(x, 'Parent', handles.axes4);
        
        x = useMser(shapeID, blob);
        imshow(x, 'Parent', handles.axes5);
        
        x = useHarris(shapeID, blob);
        imshow(x, 'Parent', handles.axes6);
        
        x = usePixelCount(shapeID, blob);
        imshow(x, 'Parent', handles.axes7);
 
        pause(1/fps);
    end
end

play = false;

% 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)


% --- Executes on button press in pushbuttonPause.
function pushbuttonPause_Callback(~, ~, ~)

global play;
play = false;

% 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)


% --- Executes on button press in pushbuttonExit.
function pushbuttonExit_Callback(~, ~, ~)

global play;
play = false;
close all
close();

% 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)
