GUI with live webcam preview not closing
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!