How to return the state of preivew camera?

1 次查看(过去 30 天)
thank you for your help in advance.
Is there something like fopen for gige camera "Preview(g)"?
here is what the code looks like.
Camlist = gigecamlist;
IP = string(Camlist{1,3});
g= gigecam(IP,'PixelFormat','mono8');
g_Res = [g.Width g.Height];
%----------------lines to created figure with tabs-------------------------------------------------------
streamingHandle = uicontrol(tab_ini,'Style','PushButton','String', 'Streaming','Position',[135 10 80 20],'Callback', {@streaming,tab_ini,g_Res,g});
%------------------------------------------------------ callback funtion for push button
function streaming(object_handle,event, tab_ini, g_Res, g)
%% How can i return a value from 'preview(g)' to condition "if"
% if Preview(g) ==1; is opened
% closePreview(g);
% end
dock_tab = axes(tab_ini,'units','pixels','Position',[35,40,g_Res(1),g_Res(2)],'box','on');
nBands = 1; % grey scale
I = image(zeros(g_Res(2),g_Res(1), nBands),'Parent',dock_tab);
preview(g, I);

采纳的回答

Walter Roberson
Walter Roberson 2019-6-13
编辑:Walter Roberson 2019-6-13
%avoid warnings about struct() preventing hiding implementation details
old_warning_state = warning('off', 'MATLAB:structOnObject');
gs = struct(g);
gsw = struct(gs.webcamImpl);
gscpc = struct(gsw.CamPreviewController);
warning(old_warning_state);
if gscpc.IsPreviewing
closePreview(g)
end
Note: you cannot do this directly: several of the properties are hidden properties.
  1 个评论
shin hsu
shin hsu 2019-6-13
The gigecam has the 'CamPreviewController' so it works preferectly.
%avoid warnings about struct() preventing hiding implementation details
old_warning_state = warning('off', 'MATLAB:structOnObject');
gs = struct(g);
%gsw = struct(gs.webcamImpl);
gscpc = struct(gs.CamPreviewController);
warning(old_warning_state);
if gscpc.IsPreviewing
closePreview(g)
end
thank you Walter for you help. I won't be able to figure this out myself.
Sincerely

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by