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