Error when closing GUI with live video input

5 Ansichten (letzte 30 Tage)
jstuda
jstuda am 15 Nov. 2016
Beantwortet: jstuda am 18 Nov. 2016
I followed the instructions from another question to get a live preview of my camera in the GUI for image acquisition (see here: Link). The only difference is, that I used a GigE-Camera of Basler. When I am closing the GUI i get the following Error:
"Error using imaqdevice/getsnapshot (line 65)
Image acquisition object OBJ has been deleted. OBJ is now an invalid object."
I have not found any solution to this problem. It seems that the Capture Image Button in where the getsnapshot-function is used tries to acquire an image even after the camera object is stopped and therefore closed. Even with checking, if the camera object is running through
if isrunning(handles.video)
getsnapshot(handles.video)
end
the error occurs.
Is there any Workaround? Thank you.
UPDATE: Today I tried to check if the Image Acquisition Object exists and if it is valid. Only when both conditions are true the Trigger-Button should acquire one frame of the video object. Therefore I use:
if ~isempty(imaqfind)
if isvalid(handles.video) % handles.video is the videoinput-object
img = getsnapshot(handles.video)
end
end
But even with this safety check, I get the same error! I am a bit confused though I thought that the callback function of a button is only executed on button press. This behavior disagrees with my understanding of the callback functions.

Akzeptierte Antwort

jstuda
jstuda am 18 Nov. 2016
I found the answer so I post it here for others with the same problem. The tutorial for having a live video preview in a GUI window uses
uiwait(handles.figure1)
for blocking the execution of other programs. The output data is therefore written, when the GUI is already closed and this means that handles like a video-object are already deleted and the output data cannot get any information about this object because it does not exist anymore. By adding
uiresume()
in the CloseRequestFcn before any other command. The output data is written while the GUI is still open and therefore the objects still exist and are valid for the output function.

Weitere Antworten (1)

Madhura Suresh
Madhura Suresh am 15 Nov. 2016
There's a typo in your if condition:
It should be isrunning, not isrunging.
Does that still fail?
  1 Kommentar
jstuda
jstuda am 16 Nov. 2016
Bearbeitet: jstuda am 16 Nov. 2016
I double-checked my files and the if condition is correct there. So the typo is only in the above explanation of the error, which means that even with a correct if condition the error appears. (I corrected the condition in the explanation)

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by