Info

This question is closed. Reopen it to edit or answer.

How to find the mouse hover positions (and preferably time stamps) while playing a video?

1 view (last 30 days)
function varargout = Video_Annotate_GUI(varargin)
% VIDEO_ANNOTATE_GUI MATLAB code for Video_Annotate_GUI.fig
% VIDEO_ANNOTATE_GUI, by itself, creates a new VIDEO_ANNOTATE_GUI or raises the existing
% singleton*.
%
% H = VIDEO_ANNOTATE_GUI returns the handle to a new VIDEO_ANNOTATE_GUI or the handle to
% the existing singleton*.
%
% VIDEO_ANNOTATE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VIDEO_ANNOTATE_GUI.M with the given input arguments.
%
% VIDEO_ANNOTATE_GUI('Property','Value',...) creates a new VIDEO_ANNOTATE_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Video_Annotate_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Video_Annotate_GUI_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 Video_Annotate_GUI
% Last Modified by GUIDE v2.5 02-Oct-2018 20:30:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Video_Annotate_GUI_OpeningFcn, ...
'gui_OutputFcn', @Video_Annotate_GUI_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 Video_Annotate_GUI is made visible.
function Video_Annotate_GUI_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 Video_Annotate_GUI (see VARARGIN)
% Choose default command line output for Video_Annotate_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Video_Annotate_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Video_Annotate_GUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axeshandle=handles.axes1;
set(axeshandle.tx,'string','None');
% Load the video
[filename,pathname]=uigetfile('*.wmv','Pick the video');
if ~isequal(filename,0)
try
axeshandle.mov = VideoReader('A1_PreTBI_01212015.wmv');
axeshandle.AXP = get(axeshandle,'CurrentPoint');
%F=axeshandle.AXP;
set(axeshandle.tx,'string','None')
% Update handles structure
guidata(hObject, handles);
% Display first frame
% img=readframe(mov,1);
subplot(axeshandle.input_frame);
image(axeshandle.mov(1).cdata);
axis off;
set(handles.original_text,'String', ...
sprintf('Original frame:1 of %d',length(axeshandle.mov)));
catch
errordlg(lasterr,'File I/O error');
end
end
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
% function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(axeshandle,'unit','pix');
% Update handles structure
guidata(hObject, handles);
if isempty(axehandle.mov)
errordlg('Please load a movie and try again!');
return;
end
nFrames=length(axeshandle.mov);
tpos=[];
try
disp('Playing the video...');
for ii=1:nFrames
f=axeshandle.mov(ii).cdata;
% f.ButtonDownFcn = @axes1_ButtonDownFcn;
subplot(axeshandle.input_frame);
set(handles.original_text,'String', ...
sprintf('Original frame:%d of %d',ii,length(axeshandle.mov)));
set(P,'windowbuttonmotionfcn',{@fh_wbmfcn_v2,axeshandle}); % Set the motion detector.
tpos{ii}=P;
image(f);
% himage=image(f,'parent', axeshandle);
% imshow(img,himage);
axis off;
drawnow
end
catch
errordlg('lasterr','video error.');
end
end
function fh_wbmfcn_v2(varargin)
% WindowButtonMotionFcn for the figure.
S = varargin{2}; % Get the structure.
F = get(S.AXP,'CurrentPoint'); % The current point w.r.t the figure.
tf1 = S.AXP(1,1)<= F(1) && F(1) <= S.AXP(1,1) + S.AXP(1,3);
tf2 = S.AXP(1,2) <= F(2) && F(2) <= S.AXP(1,2) + S.AXP(1,4);
if tf1 && tf2
set(S.tx(2),'str',['Axes ' num2str(1)])
disp(['Current point(X,Y):(',num2str(F(1)),',',num2str(F(2)),')'])
else
set(S.tx(2),'str',['Axes ' num2str(1)])
disp(['Current point(X,Y):(',num2str(F(1)),',',num2str(F(2)),')'])
end
end
% function axis1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton2.
% function pushbutton2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
end
end
end
When I run, I get the following error:
Error: File: Video_Annotate_GUI.m Line: 133 Column: 9
Functions cannot be indexed using {} or . indexing.
Any help is much appreciated.
-M
  3 Comments
CuriousThinker
CuriousThinker on 8 Oct 2018
Edited: CuriousThinker on 9 Oct 2018
I have modified the code as follows:
function varargout = Video_Annotate_GUI(varargin)
% VIDEO_ANNOTATE_GUI MATLAB code for Video_Annotate_GUI.fig
% VIDEO_ANNOTATE_GUI, by itself, creates a new VIDEO_ANNOTATE_GUI or raises the existing
% singleton*.
%
% H = VIDEO_ANNOTATE_GUI returns the handle to a new VIDEO_ANNOTATE_GUI or the handle to
% the existing singleton*.
%
% VIDEO_ANNOTATE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VIDEO_ANNOTATE_GUI.M with the given input arguments.
%
% VIDEO_ANNOTATE_GUI('Property','Value',...) creates a new VIDEO_ANNOTATE_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Video_Annotate_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Video_Annotate_GUI_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
Video_Annotate_GUI
% Last Modified by GUIDE v2.5 02-Oct-2018 20:30:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@Video_Annotate_GUI_OpeningFcn, ...
'gui_OutputFcn',
@Video_Annotate_GUI_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 Video_Annotate_GUI is made
visible.
function Video_Annotate_GUI_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
Video_Annotate_GUI (see VARARGIN)
% Choose default command line output for
Video_Annotate_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
end
% UIWAIT makes Video_Annotate_GUI wait for user
response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the
command line.
function varargout =
Video_Annotate_GUI_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;
% guidata(hObject, axeshandle);
pushbutton1_Callback(hObject, eventdata, handles)
pushbutton2_Callback(hObject, eventdata, handles)
uiwait(handles.axes1);
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata,
handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axeshandle=handles.axes1;
set(axeshandle.tx,'string','None');
% Load the video
[filename,pathname]=uigetfile('*.wmv','Pick the
video');
if ~isequal(filename,0)
try
axeshandle.mov =
vision.VideoFileReader(pathname,filename);
Frames = 0;
axeshandle.AXP = get(axeshandle,'CurrentPoint');
% F=axeshandle.AXP;
set(axeshandle.txt,'string','None')
% Update handles structure
guidata(hObject, handles);
% Display first frame
% img=readframe(mov,1);
subplot(axeshandle.input_frame);
image(axeshandle.mov(1).cdata);
axis off;
set(handles.original_text,'String', ...
sprintf('Original frame:1 of
%d',length(axeshandle.mov)));
catch
errordlg(lasterr,'File I/O error');
end
end
end
% --- If Enable == 'on', executes on mouse press in 5
pixel border.
% --- Otherwise, executes on mouse press in 5 pixel
border or over pushbutton1.
% function pushbutton1_ButtonDownFcn(hObject,
eventdata, handles)
% hObject handle to pushbutton1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata,
handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
axeshandle=handles.axes1;
set(axeshandle,'unit','pix');
% Update handles structure
guidata(hObject, handles);
if isempty(axehandle.mov)
errordlg('Please load a movie and try again!');
return;
end
nFrames=length(axeshandle.videoSrc);
tpos=[];
try
disp('Playing the video...');
while ~isDone(videoSrc)
axeshandle.vFrame=step(videoSrc);
f=axeshandle.vFrame;
guidata(hObject, handles);
% f.ButtonDownFcn = @axes1_ButtonDownFcn;
subplot(f);
set(handles.original_text,'String', ...
sprintf('Original frame:%d of
%d',ii,length(axeshandle.mov)));
set(P,'windowbuttonmotionfcn',
{@fh_wbmfcn_v2,axeshandle}); % Set the motion
detector.
% tpos{ii}=P;
Frames = Frames+1;
image(f);
% himage=image(f,'parent', axeshandle);
% imshow(img,himage);
axis off;
drawnow
end
catch
errordlg('lasterr','video error.');
end
end
function fh_wbmfcn_v2(varargin)
% WindowButtonMotionFcn for the figure.
S = varargin{2}; % Get the structure.
F = get(S.AXP,'CurrentPoint'); % The current
point w.r.t the figure.
tf1 = S.AXP(1,1)<= F(1) && F(1) <= S.AXP(1,1) +
S.AXP(1,3);
tf2 = S.AXP(1,2) <= F(2) && F(2) <= S.AXP(1,2) +
S.AXP(1,4);
if tf1 && tf2
set(S.tx(2),'str',['Axes ' num2str(1)])
disp(['Current point(X,Y):
(',num2str(F(1)),',',num2str(F(2)),')'])
else
set(S.tx(2),'str',['Axes ' num2str(1)])
disp(['Current point(X,Y):
(',num2str(F(1)),',',num2str(F(2)),')'])
end
end
% function axis1_ButtonDownFcn(hObject,
eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
% end
% --- If Enable == 'on', executes on mouse press in
5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel
border or over pushbutton2.
% function pushbutton2_ButtonDownFcn(hObject,
eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data
(see GUIDATA)
% end
% end
end
Then I have the following error:
No appropriate method, property, or field 'tx' for
class 'matlab.graphics.axis.Axes'.
Error in Video_Annotate_GUI/pushbutton1_Callback
(line 91)
set(axeshandle.tx,'string','None');
Error in
Video_Annotate_GUI/Video_Annotate_GUI_OutputFcn (line
79)
pushbutton1_Callback(hObject, eventdata, handles)
Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [],
gui_Handles);
Error in Video_Annotate_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!