Real time Rgb2gray convert

1 Ansicht (letzte 30 Tage)
Zakaria Boussaid
Zakaria Boussaid am 31 Mai 2021
hey guys i want to know if it is possible to convert in real time a RGB form video to a gray Form.
I tried to use rgbgray function and min function but i wasn't able to get what i want
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
%===============================================================================
%activate the integrated camera
web = webcam('HD Webcam')
set(web,'Resolution','640x480')
preview(web)
pause(5)
img = snapshot(web)
imshow(img)
%===============================================================================
% Read in a demo image.
%grayImage= min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
grayImage = rgbgray(web); % Useful for finding image and color map regions of image.
imshow(grayImage)
clear('web')

Akzeptierte Antwort

Image Analyst
Image Analyst am 31 Mai 2021
Bearbeitet: Image Analyst am 31 Mai 2021
You need to pass in the color image, not the webcam object. And you need to call rgb2gray(), not rgbgray().
rgbimage = snapshot(web)
grayImage = rgb2gray(rgbImage);
imshow(grayImage);
drawnow;
  3 Kommentare
Image Analyst
Image Analyst am 2 Jun. 2021
Not that I know of. You might be able to do it with the Image Acquisition Toolbox if you set the returned output space to RGB but I don't know if you can do that for the real-time LIVE webcam object. However you can do it not in real time by grabbing and image, converting it, and then displaying it like I showed. Not sure how much this would slow down the frame rate as compared to just letting it go full speed. And of course you can convert a non-real-time, saved video that is recalled from disk to gray scale very easily.
Zakaria Boussaid
Zakaria Boussaid am 2 Jun. 2021
thank you for this informative answer

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by