How can i capture image from webcome for recognization

3 ビュー (過去 30 日間)
Ha Nguyen
Ha Nguyen 2012 年 4 月 22 日
コメント済み: Image Analyst 2014 年 2 月 4 日
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

採用された回答

Image Analyst
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
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
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
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.
  2 件のコメント
Ha Nguyen
Ha Nguyen 2012 年 4 月 22 日
can you show me Brother - I have Aquisition Toolbox but i dont know where to start - I connect my webcame through USB then i use some commands to show it ( video stream) - But how can i get image - Pls show me methods i can do it
many thanks
Image Analyst
Image Analyst 2012 年 4 月 22 日
See code snippets in my other answer.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by