How can i capture image from webcome for recognization
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ha Nguyen
am 22 Apr. 2012
Kommentiert: Image Analyst
am 4 Feb. 2014
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 22 Apr. 2012
%=====================================================================
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 Kommentare
Explorer
am 4 Feb. 2014
I am not making GUI so there is no variable in my case which stores axes. What to do now?
Image Analyst
am 4 Feb. 2014
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.
Weitere Antworten (1)
Image Analyst
am 22 Apr. 2012
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.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!