版主你好,我在删除vid的时候遇见问题了 Error using imaqdevice/getsnapshot (line 62)

Image acquisition object OBJ has been deleted. OBJ is now an invalid object.

报的是 getsnapshot(vid); 的错误 请问怎么解决 跪谢啊~

一共三个按钮,一个开始Start,一个暂停Stop,一个退出Exit 点退出了时候删除vid,但是貌似Start里的getsnapshot(vid)还在运行?要不怎么会报错getsnapshot, 什么原因,跪谢

function pushStart_Callback(hObject, eventdata, handles)

% hObject    handle to pushStart (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global vid;

global StopSignal;

global GridVertical;

global GridHorizontal;

StopSignal=0;

vid = videoinput('winvideo',1,'YUY2_640x480');

vidRes = vid.VideoResolution;

nBands = vid.NumberOfBands;

hImage = image( zeros(vidRes(2), vidRes(1), nBands) );

preview(vid, hImage);

set(hObject,'enable','off');

while ~StopSignal

% pause(1);

if isempty(vid) %exist('vid','var')

frame = getsnapshot(vid);

% your main image process programe

imageprocess(frame, GridVertical, GridHorizontal);

end

end

function pushStop_Callback(hObject, eventdata, handles)

% hObject    handle to pushStop (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global vid;

global StopSignal;

StopSignal=1;

stoppreview(vid);

set(handles.pushStart,'enable','on');

function pushExit_Callback(hObject, eventdata, handles)

% hObject    handle to pushExit (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global vid;

global StopSignal;

StopSignal=1;

stoppreview(vid);

delete(vid);

%clear all;

vid=[];

delete(gcf);

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐