How can i capture image from webcome for recognization
3 次查看(过去 30 天)
显示 更早的评论
Pls help me this, i have a webcame and i want to capture and save it in a folder for compare with the sample image is saved before.
Many thanks
0 个评论
采纳的回答
Image Analyst
2012-4-22
%=====================================================================
function InitializeVideoCamera(handles)
% Initialize the video camera.
global vidobj; % Video camera object.
try
% Initialize Logitech webcam
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);
% src.ZoomMode = 'manual';
% Turn on the live video preview. Display the bounding box over it if there is one selected.
TurnOnLiveVideo(handles);
end
% Turn on the live video preview. Display the bounding box over it if there is one selected.
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
%===================================================================== function snappedImage = SnapImage(handles)
% Declare imgOriginal. It might be filled with values here.
global imgOriginal; % Declare global so that other functions can see it, if they also declare it global.
global vidobj; % Video camera object.
if isempty(vidobj), return, end;
try
snappedImage = getsnapshot(vidobj);
axes(handles.axesImage);
hold off;
axis auto;
imshow(snappedImage, 'InitialMagnification', 'fit');
grayImage = rgb2gray(snappedImage);
% Just for fun, let's get its histogram.
[pixelCount grayLevels] = imhist(grayImage);
axes(handles.axesPlot);
bar(pixelCount);
title('Histogram of image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
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
%=====================================================================
% Turn on the live video preview. Display the bounding box over it if there is one selected.
function TurnOnLiveVideo(handles)
global vidobj; % Video camera object.
% Bail out if there is no video object class instantiated.
if isempty(vidobj), return, end;
% Switch the current graphic axes to handles.axesImage.
% This is where we want the video to go.
axes(handles.axesImage);
% Reset image magnification. Required if you ever displayed an image
% in the axes that was not the same size as your webcam image.
hold off;
axis auto;
% Get the handle to the image in the axes.
hImage = findobj(handles.axesImage, 'Type', 'image');
% Turn on the live video.
preview(vidobj, hImage);
% Put hold on so that displaying our bounding box doesn't blow away the image.
hold on;
% Retrieve our x,y coordinates of the bounding box corners.
GetImageMask(handles);
% They have been previously set elsewhere as global variables.
global maskVerticesXCoordinates;
global maskVerticesYCoordinates;
if ~(isempty(maskVerticesXCoordinates) || isempty(maskVerticesYCoordinates))
% If the bounding box coordinates exist,
% plot the bounding box over the live video.
plot(maskVerticesXCoordinates, maskVerticesYCoordinates);
end
% stoppreview(vidobj);
return; % from TurnOnLiveVideo
7 个评论
Explorer
2014-2-4
I am not making GUI so there is no variable in my case which stores axes. What to do now?
Image Analyst
2014-2-4
Create an axes with uicontrol(), that is, if the preview function doesn't do it for you if you omit the handle to the axes.
更多回答(1 个)
Image Analyst
2012-4-22
Do you have the Image Acquisition Toolbox and have you run imaqtool yet? You can control the camera and see what it puts in the command window and then paste that into your own m-file.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!