필터 지우기
필터 지우기

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 (최근 30일)
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
Julius MANILA
Julius MANILA 2017년 4월 16일
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

댓글을 달려면 로그인하십시오.

채택된 답변

R. B.K.
R. B.K. 2017년 3월 26일
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
Julius MANILA
Julius MANILA 2017년 3월 31일
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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jan
Jan 2017년 3월 26일
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
Julius MANILA
Julius MANILA 2017년 3월 31일
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 2017년 4월 16일
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

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2017년 3월 26일
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
Image Analyst
Image Analyst 2017년 4월 3일
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 2017년 4월 4일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by