Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

i am taking image as input to the code.But image are not proper.

Asked by jay on 27 Dec 2013
Latest activity Commented on by ravi on 20 Feb 2014

This is my code

close all;
clear all;
obj = videoinput('winvideo', 1);
set(obj, 'SelectedSourceName', 'input1');
src_obj = getselectedsource(obj);
frame = getsnapshot(obj);

Its simple image from videoinput.....But i am attaching picture that matlab shows me....Is there any kind of setting need while using this code....Code is correct at has been taking from library file of videoinput() function.I have changed two camera. Check out attachment of image.



2 Answers

Answer by Image Analyst on 27 Dec 2013
Accepted answer

Is it color or black and white? What function are you using to display it, imshow(), image(), or imagesc()?


jay on 31 Dec 2013

winvideo_1 YUY2_160x120; YUY2_352x288; YUY2_320x240; YUY2_176x144;

Image Analyst on 31 Dec 2013

Oh bummer. You have one of those cameras that doesn't have an RGB mode. All is not lost though. There is an option of videoinput() that lets you set the returned video mode to convert it into an RGB image. Check out this link by David Tarkowski, the developer of this toolbox at the Mathworks:

vid = videoinput('winvideo', 1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
jay on 31 Dec 2013

oh man..... really thanks a lot.....:).

Image Analyst
Answer by Walter Roberson on 27 Dec 2013

It appears to me that you are getting something that is not in RGB colorspace. Use


to see the available formats. See


jay on 28 Dec 2013

Still same kind of image is coming.

Walter Roberson on 28 Dec 2013

imaqfind() does not change the image format, it shows you the available image formats. You then have to pick an appropriate one and add it to the videoinput() call.

ravi on 20 Feb 2014

use obj.ReturnedColorSpace='rgb'; just after obj = videoinput('winvideo', 1);

Walter Roberson

Contact us