How can I use imellipse on a GUI?

I want to draw a circle using imellipse on an image in a gui and then using a button get the position of that circle. However when I try to run the code, it gives an error saying there are not enough input arguments, eventhough the syntax is imellipse(hparent).
function SAMPLE(hObject,eventdata, handles)
vid = VideoReader('filename.avi');
frames = read(vid);
conv = rgb2gray(frames);
fig = uifigure;
[yax, xax] = size(conv);
ax = uiaxes('Parent',fig,'XLim',[0,xax],'YLim',[0,yax]);
imagesc(ax, conv)
btn = uibutton(fig,'push','Text','Ready','Position',[420,218,100,22],'ButtonPushedFcn', @expCirc);
circ = imellipse(handles.axes);
function expCirc(btn,event)
pos = getPosition(circ);
x = pos(1,1);
y = pos(1,2);
w = pos(1,3);
h = pos(1,4);
center = [x+(w/2),y+(h/2)];
radius = w/2*1.5;
ncirc = viscircles(center, radius);
end
end

6 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 6 月 3 日
Rossy - why are you using handles.axes instead of ax?
ax = uiaxes('Parent',fig,'XLim',[0,xax],'YLim',[0,yax]);
imagesc(ax, conv)
btn = uibutton(fig,'push','Text','Ready','Position',[420,218,100,22],'ButtonPushedFcn', @expCirc);
circ = imellipse(ax);
Rossy Drucker Shaooli
Rossy Drucker Shaooli 2019 年 6 月 3 日
I tried doing that but it also gave me an error:
Error using event.proplistener
While adding a PostSet listener, property 'XDir' in class 'matlab.ui.control.UIAxes' is not
defined to be SetObservable.
Geoff Hayes
Geoff Hayes 2019 年 6 月 3 日
And is handles.axes a valid axes object in your GUI? Where does it get set?
Rossy Drucker Shaooli
Rossy Drucker Shaooli 2019 年 6 月 3 日
What do you mean get set? I though it was included in the handles from the hObject?
Geoff Hayes
Geoff Hayes 2019 年 6 月 3 日
Are you using GUIDE? Did you create the axes already (in the GUI editor)? What is the value for handles.axes?
Rossy Drucker Shaooli
Rossy Drucker Shaooli 2019 年 6 月 4 日
I solved it, my problem was that I was triying to use a GUI but I didn't really need it. Thanks for your help anyways!

サインインしてコメントする。

回答 (1 件)

Dennis
Dennis 2019 年 6 月 4 日

0 投票

When asking a question you should always include the complete error message.
My guess is that your error message tells you that you do not have enough input arguments, because your SAMPLE function is not a callback.
Beyond that i think you might run into a few problems using the uifigure/uiaxes instead of figure/axes.
function SAMPLE
vid = VideoReader('filename.avi');
frames = read(vid);
conv = rgb2gray(frames);
fig = figure;
[yax, xax] = size(conv);
ax = axes('Parent',fig,'XLim',[0,xax],'YLim',[0,yax]);
imagesc(ax, conv)
btn = uicontrol('style','pushbutton','string','Ready','Position',[420,218,100,22],'callback', @expCirc);
circ = imellipse(ax);
function expCirc(btn,event)
pos = getPosition(circ);
x = pos(1,1);
y = pos(1,2);
w = pos(1,3);
h = pos(1,4);
center = [x+(w/2),y+(h/2)];
radius = w/2*1.5;
ncirc = viscircles(center, radius);
end
end

1 件のコメント

Rossy Drucker Shaooli
Rossy Drucker Shaooli 2019 年 6 月 4 日
Thank you!! This worked perfectly!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by