Error when closing GUI with live video input

4 visualizaciones (últimos 30 días)
jstuda el 15 de Nov. de 2016
Respondida: jstuda el 18 de Nov. de 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(
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( % is the videoinput-object
img = getsnapshot(
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.

Respuesta aceptada

jstuda el 18 de Nov. de 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
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
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.

Más respuestas (1)

Madhura Suresh
Madhura Suresh el 15 de Nov. de 2016
There's a typo in your if condition:
It should be isrunning, not isrunging.
Does that still fail?
  1 comentario
jstuda el 16 de Nov. de 2016
Editada: jstuda el 16 de Nov. de 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)

Iniciar sesión para comentar.


Community Treasure Hunt

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

Start Hunting!

Translated by