GUI with live webcam preview not closing

12 vues (au cours des 30 derniers jours)
Hakan Caldag
Hakan Caldag le 14 Jan 2020
Commenté : Hakan Caldag le 20 Jan 2020
Hey everyone, I am trying to write a MATLAB GUI where I want to display a live output of the webcam on the interface alongside with a DAQ interface with a listener that sends current to coils. I followed several similar topics and now I have something that works fine. There remains a small problem though: I am unable to close the GUI window manually. The only thing that works is
close ALL FORCE
command. If I attempt to close GUI window normally, the command window outputs the warning:
Warning: Error occurred while executing the listener callback for event Custom defined for class asyncio.Channel:
Error using matlab.webcam.internal.PreviewController/closePreview
Invalid or deleted object.
> In asyncio.Channel/onCustomEvent (line 429)
In asyncio.Channel>@(source,data)obj.onCustomEvent(data.Type,data.Data) (line 361)
And the warning repeats each time I attempt to close. It appears that something is deleted before it should have been deleted but I don't understand what is happening. As a side note, the interface does not output such a warning if I remove the code related to live webcam preview.

Réponse acceptée

Ganesh Regoti
Ganesh Regoti le 17 Jan 2020
Hi,
This is a known issue in closePreview function when you try to use custom GUI to preview the data.
This bug is fixed in R2019b. So, you can update your MATLAB to latest version.
The following code which defines its own figure CloseRequestFcn callback can be used as a workaround:
%% Connect to webcam
c = webcam(1);
%% Setup preview window
fig = figure('NumberTitle', 'off', 'MenuBar', 'none');
fig.Name = 'My Camera';
ax = axes(fig);
frame = snapshot(c);
im = image(ax, zeros(size(frame), 'uint8'));
axis(ax, 'image');
%% Start preview
preview(c, im)
setappdata(fig, 'cam', c);
fig.CloseRequestFcn = @closePreviewWindow_Callback;
%% Local functions
function closePreviewWindow_Callback(obj, ~)
c = getappdata(obj, 'cam');
closePreview(c)
delete(obj)
end
Hope this helps!
  1 commentaire
Hakan Caldag
Hakan Caldag le 20 Jan 2020
I have just tried it in Matlab R2019b and I had no errors as you said. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by