Box in GUI for select your camera device

Hello, I'm doing a program that uses the pc's camera. I'd like to know if there is an option to put in my gui some kind of box that will help the user found his camera and it appears in the code like when i do it manually:
vidPM25 = videoinput('winvideo', 1,'I420_1280x720');
But I do it in code, i want that user is able to choose it by his own. Any idea?
For be more clarify, i want that the user have the option to choose something like this:

 Accepted Answer

You need to get the adapter first, then the available formats and present them in a listbox. Study the attached function and then adapt it to put the various device formats into a listbox.

8 Comments

Regarding your "Answer" below...
I know what you're looking for. But I'm not going to write your whole interface for you. I'm showing you how you can get the information. Then, once you have that information you can present it in your own GUI in a listbox. Here are the key lines:
hardwareInfo = imaqhwinfo % Print what cameras are there.
adaptorNames = hardwareInfo.InstalledAdaptors
% Might look something like:
% InstalledAdaptors: {'dcam' 'gentl' 'gige' 'lumeneraimaqw64' 'matrox' 'winvideo'}
matches = strfind(adaptorNames, 'lumenera');
% Find out which index is the Lumenera Camera.
LumeneraIndex = find(~cellfun(@isempty, matches))
devName = devInfo.DeviceName
devID = devInfo.DeviceID
supportedFormats = devInfo.SupportedFormats
Hello, first of all, sorry if I offended you. I'm trying to understand your tracks but I'm a little confused. You have a lumenera camera, but i don't, i have a winvideo. And every person may have a different camera, so I can't call it. Does winvideo works for every computer? I'm a little lost.
I know not everyone has a Lumenera camera. You are supposed to replace Lumenera with whatever adaptor you are using of course. Sorry it confused you, I guess I needed to call that out explicitly. If you're using winvideo, then use that. Here is the fixed code:
matches = strfind(adaptorNames, 'winvideo');
% Find out which index is the winvideo adapter.
winvideoIndex = find(~cellfun(@isempty, matches))
I know it's hard to explain. Or maybe I am not understanding, but now, using winvideo. If someone else that use my program in his computer, and doesn't have a winvideo, and for example has a gige camera... it won't detect his cameras.
Lots of thanks for the fast answering.
Carlos, you put the adapter names into a listbox on your gui:
adaptorNames = hardwareInfo.InstalledAdaptors
set(handles.lstAdaptors, 'String', adaptorNames);
Then in the callback for the listbox you can get what they selected and set up your video object
adaptorNames = hardwareInfo.InstalledAdaptors
usersChosenIndex = get(handles.lstAdaptors, 'Value');
usersAdaptor = adaptorNames(usersChosenIndex);
hardwareInfo2 = imaqhwinfo(usersAdaptor)
devInfo = hardwareInfo2.DeviceInfo
if size(devInfo, 2) == 0
% No camera is attached.
UserSettings.useSamplePictures = true;
errorMessage = sprintf('Error in function InitializeVideoCamera().\nWindows does not see a video camera attached.\nIf you think there is, then use Device Manager to check\nthe "Imaging Devices" category.');
ME = MException('CameraDetect:NoCameraPresent', errorMessage);
% Launch Device Manager. Use trailing ampersand, otherwise program does not continue until user closes Device Manager.
system('C:\Windows\System32\devmgmt.msc &')
throw(ME);
end
devName = devInfo.DeviceName
devID = devInfo.DeviceID
supportedFormats = devInfo.SupportedFormats
I have a problem with the hardwareInfo.InstalledAdaptors.
It show the next error:
Undefined variable "hardwareInfo" or class
"hardwareInfo.InstalledAdaptors".
I have to set it in an specific place?
You were supposed to call
hardwareInfo = imaqhwinfo
before that.
i have already done it!
x=1
while x=0
thanks;
end

Sign in to comment.

More Answers (1)

Carlos
Carlos on 30 Mar 2014
Edited: Carlos on 30 Mar 2014
I think that it is not what I'm looking. I want that, when anybody click on the first box (figure of this message), appear something like a hardware browser where there are his cameras and the possible formats, like in the image of my fist message.

Asked:

on 30 Mar 2014

Commented:

on 1 Apr 2014

Community Treasure Hunt

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

Start Hunting!