Sir I'm working a current project image process or image data acquistion my problem is i have to identify a color red and green when it pass to a live web cam or take a snapshot and i'm confused about the rgb color in matlab ex. if(rgb == red)

1 visualizzazione (ultimi 30 giorni)
Sir I'm working a current project image process or image data acquistion my problem is i have to identify a color red and green when it pass to a live web cam or take a snapshot and i'm confused about the rgb color in matlab ex. if(image == red) disp ('red'); if(image == green) disp ('green'); else ......
  1 Commento
Julius MANILA
Julius MANILA il 16 Apr 2017
function pbStart_Callback(hObject, eventdata, handles) % hObject handle to pbStart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if ~isfield(handles, 'vid') warndlg('Please do the preview first!'); return; end vid=handles.vid; vid.FramesPerTrigger = 1; vid.ReturnedColorspace = 'rgb'; triggerconfig(vid, 'manual'); vidRes = get(vid, 'VideoResolution'); imWidth = vidRes(1); imHeight = vidRes(2); nBands = get(vid, 'NumberOfBands'); hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview) preview(vid, hImage); handles.vid=vid; guidata(hObject, handles);
% prepare for capturing the image preview start(vid); % pause for 3 seconds to give our webcam a "warm-up" time pause(3); % do capture! trigger(vid); % stop the preview % stoppreview(vid); % get the captured image data and save it on capt1 variable
% now write capt1 into file named captured.png while(vid.FramesAcquired <= 500)%run time =500/fps
data = getsnapshot(vid);
r= imsubtract(data(:,:,1),rgb2gray(data));
r = medfilt2(r, [4 4]);
red = im2bw(r,0.17);
R = sum(red(:));
end
if(R > 0) % display red if red color is being detected count = str2num(get(handles.numred, 'String')); count = count + 1; set(handles.numred, 'String', num2str(count));
else count = str2num(get(handles.numgreen, 'String')); count = count + 1; set(handles.numgreen, 'String', num2str(count));
end
delete(vid); guidata(hOject,handles); %Ineed to detect red and green color on this gui please help

Accedi per commentare.

Risposta accettata

R. B.K.
R. B.K. il 26 Mar 2017
I think you should read Image Types for better understanding on rgb image in matlab.
Matlab splits red channel, green channel and blue channel in a m-by-n-by-3 data array where m and n are width and height. For example:
rgbImage = imread('yellowlily.jpg'); % Read image
redChannel = rgbImage(:,:,1); % Red channel
greenChannel = rgbImage(:,:,2); % Green channel
blueChannel = rgbImage(:,:,3); % Blue channel
  1 Commento
Julius MANILA
Julius MANILA il 31 Mar 2017
Sir read about this i have only 3 separate channel but it does answer how can return this channel to identify if it is red or green please give me an exam i will send you a link about my project https://www.youtube.com/watch?v=TI61dQbY4lU please help thanks to you sir R.b.k

Accedi per commentare.

Più risposte (2)

Jan
Jan il 26 Mar 2017
It is unlikely that you get a 100% signal for the red channel. So better convert the RGB image to HSV colors and check with a certain tolerance.
  2 Commenti
Julius MANILA
Julius MANILA il 31 Mar 2017
Sir read about this i have only 3 separate channel but it does answer how can return this channel to identify if it is red or green please give me an exam i will send you a link about my project https://www.youtube.com/watch?v=TI61dQbY4lU please help thanks to you sir jan simmon
Julius MANILA
Julius MANILA il 16 Apr 2017
function pbStart_Callback(hObject, eventdata, handles) % hObject handle to pbStart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if ~isfield(handles, 'vid') warndlg('Please do the preview first!'); return; end vid=handles.vid; vid.FramesPerTrigger = 1; vid.ReturnedColorspace = 'rgb'; triggerconfig(vid, 'manual'); vidRes = get(vid, 'VideoResolution'); imWidth = vidRes(1); imHeight = vidRes(2); nBands = get(vid, 'NumberOfBands'); hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview) preview(vid, hImage); handles.vid=vid; guidata(hObject, handles);
% prepare for capturing the image preview start(vid); % pause for 3 seconds to give our webcam a "warm-up" time pause(3); % do capture! trigger(vid); % stop the preview % stoppreview(vid); % get the captured image data and save it on capt1 variable
% now write capt1 into file named captured.png while(vid.FramesAcquired <= 500)%run time =500/fps
data = getsnapshot(vid);
r= imsubtract(data(:,:,1),rgb2gray(data));
r = medfilt2(r, [4 4]);
red = im2bw(r,0.17);
R = sum(red(:));
end
if(R > 0) % display red if red color is being detected count = str2num(get(handles.numred, 'String')); count = count + 1; set(handles.numred, 'String', num2str(count));
else count = str2num(get(handles.numgreen, 'String')); count = count + 1; set(handles.numgreen, 'String', num2str(count));
end
delete(vid); guidata(hOject,handles); % I need to detect the red and green color and count them on a static text pls help

Accedi per commentare.


Image Analyst
Image Analyst il 26 Mar 2017
See my attached demo for tracking a green Sharpie marker in an image. You can easily adapt it to find red.
See other color segmentation methods and demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
  7 Commenti
Image Analyst
Image Analyst il 3 Apr 2017
Basically try the same thing except instead of this
r= imsubtract(data(:,:,1),rgb2gray(data));
use channels 2 and 3:
r= imsubtract(data(:,:,2),rgb2gray(data));
r= imsubtract(data(:,:,3),rgb2gray(data));
You'll probably want to compute rgb2gray(data) in advance so you're not doing it 3 times.
Julius MANILA
Julius MANILA il 4 Apr 2017
Sir Image Analyst this a link to a youtube video that i hoping that will be the output of my program except for the shape the demostrate in this video
please watch this hoping for your feedback https://www.youtube.com/watch?v=TI61dQbY4lU

Accedi per commentare.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by