Converting livestream RGB video to gray scale

Hello I am wondering if it is possible to convert a livestream RGB into grayscale while still remaining in live video
this is what i have so far to obtain live video however I am stuck on how to make gray scale
or how to put the live video on a plot
cam = webcam
preview(cam)

 Accepted Answer

After you call videoinput set ReturnedColorSpace to 'grayscale'.
vidobj = videoinput(theVideoAdaptor, cameraDeviceID, selectedCameraFormats{selectedFormatIndex});
vidobj.ReturnedColorSpace = 'grayscale';

6 Comments

Hello thank you for the answer I was wondering what that would look like im relatively new to matlab and am trying to learn how to do it
Here is a snippet from the attached program:
% Get the device ID:
cameraDeviceID = cameraInfo.DeviceID;
% Now we know which device/camera they want to use and which format/mode they want to use.
% Now, initialize the camera with the selected mode on its list of supported formats.
vidobj = videoinput(theVideoAdaptor, cameraDeviceID, selectedCameraFormats{selectedFormatIndex});
% Convert to gray scale if that's what is selected.
radGray = get(handles.radGray, 'Value');
if radGray
vidobj.ReturnedColorSpace = 'grayscale';
else
vidobj.ReturnedColorSpace = 'rgb';
end
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);
end
Oh I see, do you think there is a way to do this but on the internal computer camera instead of a webcam. I dont have a build in adapter for the video input
If you have a machine vision camera (USB or otherwise) and you're using the Image Acquisition Toolbox, you'll still have to use VideoInput. Then you can get src and apply the gray scale property if your camera adapter allows it. Otherwise you might have to get a gray scale camera or just grab individual snapshots and call rgb2gray() to convert them from color to gray scale.
hmm do you think it can work on my internal laptop camera?
Maybe - with my Logitech demo you might have to debug it and figure out what the adapter name of your camera is and replace Logitech with your computer camera's name.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!