function InitializeVideoCamera(handles)
global vidobj;
try
vidobj = videoinput('winvideo', 1, 'RGB24_640x480');
if ~isempty(vidobj)
src = getselectedsource(vidobj);
vidobj.FramesPerTrigger = 1;
axes(handles.axesImage);
hImage = findobj(handles.axesImage, 'Type', 'image');
preview(vidobj, hImage);
TurnOnLiveVideo(handles);
end
TurnOnLiveVideo(handles);
catch ME
errorMessage = sprintf('Error in function logitech_webcam_OpeningFcn.\nNo Logitech webcam detected!\n\nError Message:\n%s', ME.message);
set(handles.txtInfo, 'string', errorMessage);
uiwait(warndlg(errorMessage));
end
global imgOriginal;
global vidobj;
if isempty(vidobj), return, end;
try
snappedImage = getsnapshot(vidobj);
axes(handles.axesImage);
hold off;
axis auto;
imshow(snappedImage, 'InitialMagnification', 'fit');
grayImage = rgb2gray(snappedImage);
[pixelCount grayLevels] = imhist(grayImage);
axes(handles.axesPlot);
bar(pixelCount);
title('Histogram of image');
xlim([0 grayLevels(end)]);
imgOriginal = snappedImage;
catch ME
errorMessage = sprintf('Error in function btnPreviewVideo_Callback.\nError Message:\n%s', ME.message);
set(handles.txtInfo, 'string', errorMessage);
msgboxw(errorMessage);
end
function TurnOnLiveVideo(handles)
global vidobj;
if isempty(vidobj), return, end;
axes(handles.axesImage);
hold off;
axis auto;
hImage = findobj(handles.axesImage, 'Type', 'image');
preview(vidobj, hImage);
hold on;
GetImageMask(handles);
global maskVerticesXCoordinates;
global maskVerticesYCoordinates;
if ~(isempty(maskVerticesXCoordinates) || isempty(maskVerticesYCoordinates))
plot(maskVerticesXCoordinates, maskVerticesYCoordinates);
end
return;