Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
HELP ME, Arrgh.. close(vid) on image acquisition

Subject: HELP ME, Arrgh.. close(vid) on image acquisition

From: Ashar

Date: 24 Apr, 2010 08:12:06

Message: 1 of 5

Arghh... so frustating...

anybody knows how to use close(vid) ? I'm Matlab GUI user but I've problem using close(vid) in push_button_2 callback function, say... my GUI has two push button and one axis to display image. i use push_button_1 to set video using image acquisition toolbox, and display it into axis. but when i press push_button_2 to stop video input the error occur. matlab says Reference to non-existent field 'vid'. i tried close(handles.vid) instead of close(vid), but it doesnt work. here is my simple code :


%%%%%% PUSH_BUTTON_1_CALL_BACK_FUNCTION %%%%%%%%
function pushbutton1_Callback(hObject, eventdata, handles)
handles.vid = videoinput('winvideo',1,'RGB24_320x240');
set(handles.vid,'TriggerRepeat',inf);
triggerconfig(handles.vid,'manual');
set(handles.vid,'FramesPerTrigger',1);
start(handles.vid);
while (handles.vid.FramesAcquired<=50)
   trigger(handles.vid);
   data_image=getdata(handles.vid,1);
   handles.axes1,imshow(data_image);
   flushdata(vid);
end
stop(handles.vid);


%%%%%% PUSH_BUTTON_2_CALL_BACK_FUNCTION %%%%%%%%
function pushbutton2_Callback(hObject, eventdata, handles)
stop(handles.vid);

the close(vid) only works when i use it in the same call_back_function where start(vid) is exist. please helpme... thanks for reading my post.

Subject: HELP ME, Arrgh.. close(vid) on image acquisition

From: Ashish Uthama

Date: 26 Apr, 2010 12:04:59

Message: 2 of 5

On Sat, 24 Apr 2010 05:12:06 -0300, Ashar <zero_fauzi@yahoo.com> wrote:

> Arghh... so frustating...
>
> anybody knows how to use close(vid) ? I'm Matlab GUI user but I've
> problem using close(vid) in push_button_2 callback function, say... my
> GUI has two push button and one axis to display image. i use
> push_button_1 to set video using image acquisition toolbox, and display
> it into axis. but when i press push_button_2 to stop video input the
> error occur. matlab says Reference to non-existent field 'vid'. i tried
> close(handles.vid) instead of close(vid), but it doesnt work. here is my
> simple code :
>
>
> %%%%%% PUSH_BUTTON_1_CALL_BACK_FUNCTION %%%%%%%%
> function pushbutton1_Callback(hObject, eventdata, handles)
> handles.vid = videoinput('winvideo',1,'RGB24_320x240');
> set(handles.vid,'TriggerRepeat',inf);
> triggerconfig(handles.vid,'manual');
> set(handles.vid,'FramesPerTrigger',1);
> start(handles.vid);
> while (handles.vid.FramesAcquired<=50)
> trigger(handles.vid);
> data_image=getdata(handles.vid,1);
> handles.axes1,imshow(data_image);
> flushdata(vid);
> end
> stop(handles.vid);
>
>
> %%%%%% PUSH_BUTTON_2_CALL_BACK_FUNCTION %%%%%%%%
> function pushbutton2_Callback(hObject, eventdata, handles)
> stop(handles.vid);
>
> the close(vid) only works when i use it in the same call_back_function
> where start(vid) is exist. please helpme... thanks for reading my post.

Dont you have to use GUIDATA to store the updated handles value?
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/guidata.html

Subject: HELP ME, Arrgh.. close(vid) on image acquisition

From: Ashar

Date: 28 Apr, 2010 06:02:05

Message: 3 of 5

problem solved

just use Global variabel...

ex :
 function button_1
  global vid
  vid=...

  function button_2
  global vid
  

anyway, thans all

Subject: HELP ME, Arrgh.. close(vid) on image acquisition

From: Adrian

Date: 13 Aug, 2010 20:13:05

Message: 4 of 5

Globals will work but arn't required. If you are using the handles to store vid (i.e., handles.vid) then you have to be sure to update the handles at the end of the function in which it is first stored to the handles, using:

% Choose default command line output for IS_Photorefraction
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

Another approach is to store anything you want to access in another function in the appdata. Such as the following:

% In your Opening_Fcn you can create the vid obj
% Create a video object
vidobj = videoinput('winvideo', 1, info.DeviceInfo(1,1).SupportedFormats{22});
% put the video object into the appdata
setappdata(gcf, 'VidObj', vidobj);

Then later you can retrieve the vidobj from the appdata in your other pushbutton functions or Delete_Fcn using:

% get the last image from the video object
vidobj = getappdata(gcf, 'VidObj');
close(VidObj);

The appdata is a powerful feature of MATLAB that permits versitility.

Subject: HELP ME, Arrgh.. close(vid) on image acquisition

From: Adrian

Date: 13 Aug, 2010 20:18:05

Message: 5 of 5

....sorry, that last command should have been

close(vidobj); % .... not close(VidObj);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us