MatLab (Image Processing/Image Acquisition) How to use trigger/getsnapshot if the preview(vid1) is on a different callback?

3 次查看(过去 30 天)
I already asked this but I will try it in different approach.
I am getting an error saying
winvideo: The device associated with device ID 1 is already in use.
A new videoinput object cannot be created for this device while it is in use.
My preview code is:
vid1 = videoinput('winvideo', 1, 'MJPG_1024x576');
vid1.FramesPerTrigger = 1;
vid1.ReturnedColorspace = 'rgb';
triggerconfig(vid1,'manual');
vid1Res = get(vid1, 'VideoResolution');
imWidth = vid1Res(1);
imHeight = vid1Res(2);
nBands = get(vid1, 'NumberofBands');
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axes7);
axes(handles.axes7);
preview(vid1, hImage);
and my Capture code is:
vid1 = videoinput('winvideo', 1, 'MJPG_1024x576');
vid1.FramesPerTrigger = 1;
vid1.ReturnedColorspace = 'rgb';
triggerconfig(vid1, 'manual');
vid1Res = get(vid1, 'VideoResolution');
im1Width = vid1Res(1);
im1Height = vid1Res(2);
n1Bands = get(vid1, 'NumberOfBands');
h1Image = image(zeros(im1Height, im1Width, n1Bands), 'parent', handles.axes7);
preview(vid1, h1Image);
I know that the error is insanely obvious but I really can't figure out on how to capture the preview using different button. Please guide me dear Sir(s)/Mam(s). Thank you.

采纳的回答

Image Analyst
Image Analyst 2013-11-2
You only need to call videoinput() once, not every time you capture a snapshot. Once you've attached your program to the camera, you are done - you don't need to do it every single time, in fact you can't so that's why you're getting the error. Make vid1 a global variable so that you can see it wherever you need to use it (whatever callback).
  3 个评论
Álvaro Mangado
Álvaro Mangado 2017-4-11
Hi guys. I got the same problem as you had (winvideo: The device associated with device ID 1 is already in use. A new videoinput object cannot be created for this device while it is in use) I´ve tried setting vid as global and i can´t understand where it is. Here i leave you mi code. Please help me:
Image Analyst
Image Analyst 2017-4-11
So try a different number, like 2
vid=videoinput('winvideo', 2, 'MJPG_640x480');
Also, flushdata() needs to come before delete() because it needs the vid object that you deleted.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by