Info

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

How can I store the mouse position (and preferably time stamps) while playing a video?

1 view (last 30 days)
I have to do video annotation, for storing the actual mouse cursor position at different instant of a video. I checked MATLAB VideoPlayer documentation. How can I have a GUI handle for the video in order to get the mouse position (and preferably the time)? Also, how can I have a condition not to have the mouse positions saved during the instants object is absent in the video. Thanks a lot, in advance.
  1 Comment
CuriousThinker
CuriousThinker on 2 Oct 2018
Edited: CuriousThinker on 2 Oct 2018
Hi. This is the code I have:
function varargout = Annotate_GUI(varargin)
% ANNOTATE_GUI MATLAB code for Annotate_GUI.fig
% ANNOTATE_GUI, by itself, creates a new ANNOTATE_GUI or raises the existing
% singleton*.
%
% H = ANNOTATE_GUI returns the handle to a new ANNOTATE_GUI or the handle to
% the existing singleton*.
%
% ANNOTATE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANNOTATE_GUI.M with the given input arguments.
%
% ANNOTATE_GUI('Property','Value',...) creates a new ANNOTATE_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Annotate_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to 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 Annotate_GUI
% Last Modified by GUIDE v2.5 02-Oct-2018 01:39:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Annotate_GUI_OpeningFcn, ...
'gui_OutputFcn', @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 Annotate_GUI is made visible.
function 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 Annotate_GUI (see VARARGIN)
% Choose default command line output for Annotate_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Annotate_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = 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;
% 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)
handles=guidata(hObject);
if true
handles.output = hObject;
axeshandle= handles.axes1;
axes(axeshandle);
axeshandle.fh = figure('numbertitle', 'off', ...
'name', 'Video In Custom GUI', ...
'menubar','none', ...
'toolbar','none', ...
'resize', 'on', ...
'tag',figTag, ...
'renderer','painters', ...
'position',[680 678 480 240],...
'HandleVisibility','callback'); % hide the handle to prevent
unintended modifications of our custom UI
% Fill the structure with data.
axeshandle.AXP = get(axeshandle.ax,'pos');
axeshandle.tx(1) = uicontrol('style','tex',...
'unit','pix',...
'posit',[50 395 250 22],...
'backg',get(axeshandle.fh,'color'),...
'fontsize',12,'fontweight','bold',...
'string','Current Pointer Axes:');
% This textbox will display the current position of the mouse.
axeshandle.tx(2) = uicontrol('style','tex',...
'unit','pix',...
'position',[310 395 120 25],...
'backg',get(axeshandle.fh,'color'),...
'fontsize',12,'fontweight','bold' );
set(axeshandle.fh,'windowbuttonmotionfcn',{@fh_wbmfcn_v2,axeshandle}) %
Set the motion detector.
mov = vision.VideoFileReader('A1_PreTBI_01212015.wmv');
% himage=image(zeros(640, 480, 3),'parent', handles.axes1);
% preview(vid,himage);
nFrames=mov.NumberOfFrames;
v=findall(0, 'type', 'axes', 'tag', 'VideoAxes');
axeshandle.ax=v;
set(axeshandle.ax,'unit','pix');
for i=1:nFrames
img=readframe(mov,i);
himage=image(size(img),'parent', axeshandle);
imshow(img,himage);
drawnow;
end
% guidata(hObject,handles)
end
guidata(hObject,handles)
end
% --- 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)
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
end
function exit_Callback(hObject, eventdata, handles)
if isfield(handles.axes1, 'mov') && ~isempty(handles.axes1.mov)
delete(handles.axes1.mov); % or close, whatever is relevant
handles.axes1.mov = [];
guidata(hObject, handles)
end
end
function fh_wbmfcn_v2(varargin)
% WindowButtonMotionFcn for the figure.
S = varargin{3}; % Get the structure.
set(S.tx(2),'string','None')
F = get(S.fh,'CurrentPoint'); % The current point w.r.t the figure.
% Figure out of the current point is over the axes or not -> logicals.
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
end
end
function frequency_axes_Createfcn(varargin)
end
end
end
But when I am running the code, I get the following error:
Undefined function or variable 'Annotate_GUI_OutputFcn'.
Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in Annotate_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Undefined function or variable 'pushbutton1_Callback'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Annotate_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Annotate_
GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Appreciate help. Thanks in advance.

Answers (0)

Community Treasure Hunt

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

Start Hunting!