GUI with live webcam preview not closing

2 次查看(过去 30 天)
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.

采纳的回答

Ganesh Regoti
Ganesh Regoti 2020-1-17
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 个评论
Hakan Caldag
Hakan Caldag 2020-1-20
I have just tried it in Matlab R2019b and I had no errors as you said. Thank you so much.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by