简体   繁体   中英

Getting Mouse Points using Matlab App Designer

I realize that App designer does not support interactive figure manipulation, but I am wondering if I can open a separate figure window (not a UI window) with my graphic displayed on it so that I can still get the location of my mouse clicks. Currently the code below displays the figure on my GUI, and then opens another blank figure that records my mouse clicks. This is fine, but I need to also display the figure in the new window as well, and am having trouble doing so.

first frame = vid(:,:,:,1);
imshow(firstframe,'Parent',app.UIAxes); 
[centers_X centers_Y]=getpts;

What worked for me was setting a callback on the image rather than the axes:

ih = imshow(firstframe,'Parent',app.UIAxes);
ih.ButtonDownFcn = {@im_ButtonDownFcn, app}; %app will be passed to the callback

Then in a separate file in the same folder (or as a private function within the appdesigner... it should work but I haven't tried it):

function im_ButtonDownFcn(im, hit, app)
mouse_pos = flip(hit.IntersectionPoint(1:2)); %gives floats. Round if you want integers e.g. for indexing pixels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM