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)

 採用された回答

Image Analyst
Image Analyst 2022 年 7 月 4 日
編集済み: Image Analyst 2022 年 7 月 4 日

0 投票

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

6 件のコメント

Jose
Jose 2022 年 7 月 4 日
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
Image Analyst
Image Analyst 2022 年 7 月 4 日
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
Jose
Jose 2022 年 7 月 4 日
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
Image Analyst
Image Analyst 2022 年 7 月 4 日
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.
Jose
Jose 2022 年 7 月 5 日
hmm do you think it can work on my internal laptop camera?
Image Analyst
Image Analyst 2022 年 7 月 5 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by