Selecting points on a streaming webcam image in a GUI

1 回表示 (過去 30 日間)
Daniel Leib
Daniel Leib 2017 年 9 月 8 日
Good morning!
I'm trying to figure out how to select a point in streaming webcam data that is being displayed in a GUI (the intent is to then track those points and do some simple math with them like calculate angles as they change in real time).
Where I'm stuck is that I can't figure out how to appropriately assign the ButtonDownFcn in order to get the x,y coordinates on click.
How it's set up:
I made a GUI with GUIDE, put in an axis object, and have it labeled as handles.axesCamera1. To stream, I made a togglebutton handles.onOff, and use this to start/stop streaming. When it's on: while handles.onOff == 1 handles.time = now; handles.imgCurr = snapshot(handles.cam); imshow(handles.imgCurr,'Parent',handles.axesCamera1); drawnow(); handles.onOff = get(handles.togglebuttonStream,'Value'); guidata(hObject, handles); end
I then have a button that has a callback that starts with this line: h = get('Parent',handles.axes1Camera); set(h,'ButtonDownFcn',@captureImageClick);
where
function captureImageClick(handles,eventdata,hObject)
h = findobj(handles.axesCamera1,'Parent');
coords = get(h,'CurrentPoint');
x = coords(1);
y = coords(2);
% if isempty(handles.ptType) % handles.ptType(1:length(coords(1))) = {'p'}; % elseif ~isempty(handles.ptType) % handles.ptType(end+1:end+1+length(x)-1) = {'p'}; % end
%append coordinates for points
if ~isempty(handles.trackPoints)
handles.trackPoints = [handles.trackPoints; [x y]];
else
handles.trackPoints = [x y];
end
% handles.numClicked = handles.numClicked + 1;
guidata(hObject, handles);
But in debugging captureImageClick never fires. Am I thinking about this correctly? Or am I just getting the handle reference wrong?
Thanks for any help!

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by