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 日間)
Richard
Richard 2014 年 6 月 26 日
回答済み: Chaitra 2014 年 6 月 26 日
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