problem in connecting with webcam and re

I use this code to take a picture but the picture is very eliminate.but also when I use this command "preview(cam)" on time image is good. what is the problem with the picture?the code is below
cam=videoinput('winvideo' , 2);
set(cam.source , 'Brightness' , 240);
pic=getsnapshot(cam);

4 Comments

Sorry I did not catch what you meant by "very eliminate" ?
Are you displaying the image after you snapshot it?
Could you post some examples?
it is too dark.this is a pic from my face
I would not assume that the default video format is RGB. You should find out which formats your camera can return, and select one specifically. Then if necessary, convert colorspaces into something you can display. If the video format is grayscale, make sure you have a grayscale colormap active when you display it.
imaqhwinfo('winvideo' , 2)
ans =
DefaultFormat: 'YUY2_160x120'
DeviceFileSupported: 0
DeviceName: 'A4TECH USB2.0 PC Camera'
DeviceID: 2
ObjectConstructor: 'videoinput('winvideo', 2)'
SupportedFormats: {1x5 cell}
>> cam = videoinput('winvideo') >> imaqhwinfo(cam)
ans =
AdaptorName: 'winvideo'
DeviceName: 'Integrated Webcam'
MaxHeight: 720
MaxWidth: 1280
NativeDataType: 'uint8'
TotalSources: 1
VendorDriverDescription: 'Windows WDM Compatible Driver'
VendorDriverVersion: 'DirectX 9.0'

Sign in to comment.

Answers (1)

Do you have a weird colormap applied? Is the camera running in monochrome mode? Your videoinput() code doesn't look like mine. Mine looks like:
% Initialize Logitech webcam
vidobj = videoinput('winvideo', 1, 'RGB24_640x480');
if ~isempty(vidobj)
src = getselectedsource(vidobj);
vidobj.FramesPerTrigger = 1;
axes(handles.axesImage);
hImage = findobj(handles.axesImage, 'Type', 'image');
preview(vidobj, hImage);
% src.ZoomMode = 'manual';
% Turn on the live video preview. Display the bounding box over it if there is one selected.
TurnOnLiveVideo(handles); % My own function
end
Are you sure you're supposed to be using camera #2? Why did you not specify an operation mode, such as 'RGB24_640x480', for the video?

9 Comments

imaqhwinfo('winvideo' , 2)
ans =
DefaultFormat: 'YUY2_160x120'
DeviceFileSupported: 0
DeviceName: 'A4TECH USB2.0 PC Camera'
DeviceID: 2
ObjectConstructor: 'videoinput('winvideo', 2)'
SupportedFormats: {1x5 cell}
>> cam = videoinput('winvideo') >> imaqhwinfo(cam)
ans =
AdaptorName: 'winvideo'
DeviceName: 'Integrated Webcam'
MaxHeight: 720
MaxWidth: 1280
NativeDataType: 'uint8'
TotalSources: 1
VendorDriverDescription: 'Windows WDM Compatible Driver'
VendorDriverVersion: 'DirectX 9.0'
Tell us what output you get from
T = imaqhwinfo('winvideo' , 2);
T.SupportedFormats
Your data is currently being collected in YUY2 format, which is one of the reasons that your image comes out wrong.
Columns 1 through 3
'YUY2_160x120' 'YUY2_176x144' 'YUY2_320x240'
Columns 4 through 5
'YUY2_352x288' 'YUY2_640x480'
Odd, your camera can do 720 x 1280, but the largest format returned is 640 x 480.
Anyhow, you should activate that format. And then you need to decide what you want to do with the data returned.
but why preview(cam) gives me a good image
I don't know why there are non-RGB modes in the first place. I only use cameras in RGB mode so I don't really know why, when, or how you'd use non-RGB modes. Since computers only display RGB I don't know if the R is the Y channel and the G is the U channel and the B is the V channel or it's some other arrangement, or if it's somehow converted internally. These would be good questions to ask the Mathworks. Or else just get a camera than can handle RGB.
The comments in the link I posted show how to get the YUY2 space converted to RGB.
Thanks. I forgot. Another good answer from David on the Image Acquisition team: http://www.mathworks.com/matlabcentral/answers/75519#answer_85238

Sign in to comment.

Tags

Asked:

on 2 Nov 2013

Commented:

on 3 Nov 2013

Community Treasure Hunt

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

Start Hunting!