MATLAB Answers

jay
0

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

clc;
close all;
clear all;
obj = videoinput('winvideo', 1);
set(obj, 'SelectedSourceName', 'input1');
src_obj = getselectedsource(obj);
get(src_obj);
preview(obj);
frame = getsnapshot(obj);
image(frame);
delete(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.

  0 Comments

Log in to comment.

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()?

  13 Comments

winvideo_1 YUY2_160x120; YUY2_352x288; YUY2_320x240; YUY2_176x144;

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: http://www.mathworks.com/matlabcentral/answers/5634#answer_8178

vid = videoinput('winvideo', 1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
imshow(img)

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

Log in to comment.


Answer by Walter Roberson
on 27 Dec 2013

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

imaqfind

to see the available formats. See http://www.mathworks.com/help/imaq/examples/managing-image-acquisition-objects.html

  3 Comments

Still same kind of image is coming.

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.

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

Log in to comment.


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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!