GUI with live webcam preview not closing

조회 수: 9 (최근 30일)
Hakan Caldag
Hakan Caldag 2020년 1월 14일
댓글: Hakan Caldag 2020년 1월 20일
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