How can I use the same webcam for displaying video on a gui and a function that is run with the gui. I get a error saying winvideo: The device associated with device ID 1 is already in use. A new videoinput object cannot be created ....while in use

2 次查看(过去 30 天)
I am making a GUI and I want to display a live video on my GUI with the same webcam i use for collecting data for a function that i run with the GUI. My function uses the webcam to take a snap shot and than calculates a value that is used later in the function. I think i know whats going on but i don't know how to fix it or even if i can. I need to make something global right...but what and where. THANKS IN ADVANCE and here is the error i get.
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.

回答(2 个)

David Sanchez
David Sanchez 2014-6-26
Before you create the video object using videoinput function:
obj = videoinput('winvideo',1); % or something similar, I guess
declare it as global:
global obj
obj = videoinput('winvideo',1); % or something similar, I guess
Then, declare the global variable within your function, and then, use the variable, for example, taking an image.
function your_fun(inputvars)
global obj
frame = getsnapshot(obj);
I never did it, but I think it could work
  1 个评论
Richard
Richard 2014-6-26
No this did not work....but now i can see live video on my GUI so that's good. I get the same error now when i try to start my function with the push button in my GUI.

请先登录,再进行评论。


Chaitra
Chaitra 2014-6-26
As you have indicated in your code:
videoinput('winvideo', 1, 'YUY2_640x480');
A new video input object is being created on the same device. This object is already created as you are accessing it via GUI. I would suggest you to use the same object handle to perform further operations.
Instead of using custom GUI, you can use Imaqtool GUI that is shipped with MATLAB.
>>imaqtool

Community Treasure Hunt

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

Start Hunting!

Translated by