Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
karper1986 said:Hello,
there here is example how to grab images from web cameras, also function for webcam initialization in matlab.
Best regards,
Karper.
%%%first check what adaptor type use imaqtool
%%%for ex. it might be 'coreco', 'winvideo'...
camName = {'winvideo'}; %adaptor type
camID1 = 1; %camera ID
camFormat = {'RGB32_1280x1024'}; %suported format you can see in imaqtool
camRes = [1024 1280]; %resolulion the same as format
%%now function below find your camera and initialize it
if ~exist('camera','var')
disp('Initializing video capture...');
camera = imaqfind('Type','videoinput');
for i = 1:length(camera)
delete(camera{i});
end
context = camInit_one(camName,camID1,camFormat);%%init
end
Image = camCapture(context); %%grab image from cam
%%for example you can save image like this:
imwrite(Image{1,1},'name.bmp');
camStop(context);
%%%%%%function for initialize camera (below) -- you must save in
%%%%%%"camInit_one.m" file
function camera = camInit_one(camName,camID,camFormat)
% Initialize camera(s) using Image Acquisition Toolbox.
nCameras = length(camName);
camera = cell(1,nCameras);
for i = 1:nCameras
camera{i} = videoinput(camName{i},camID(i),camFormat{i});
set(camera{i},'ReturnedColorSpace','rgb');
triggerconfig(camera{i},'manual');
set(camera{i},'FramesPerTrigger',1);
set(camera{i},'TriggerRepeat',128);
src = getselectedsource(camera{i});
%Turn off auto setings
%Note: to turn it back type instead of 'manual' - 'auto'
%%%%%%%%for example some functions below%%%%%%%
% set(src,'BacklightCompensation','off');
% set(src,'FocusMode','manual');
% set(src,'WhiteBalanceMode','manual');
% set(src,'TiltMode','manual');
% set(src,'PanMode','manual');
% set(src,'ZoomMode','manual');
% set(src,'ExposureMode','manual');
% set(src,'BrightnessMode','manual');
% set(src,'ContrastMode','manual');
% set(src,'ExposureMode','manual');
% set(src,'SaturationMode','manual');
% set(src,'SharpnessMode','manual');
%%%%%%%and now manual enter some values like below for example%%%%%%
% src.zoom = 145;
% scr.WhiteBalance = 10000;
% scr.brightness = 54;
% scr.contrast = 32;
% src.exposure = -11;
% src.focus = 0;
% src.gain = 255;
% src.saturation = 36;
% src.sharpness = 255;
% scr.Tilt = 10;
% scr.Pan = 10;
% src.spotmetering = 3;
start(camera{i});
end
%%%%%%%%end of "camInit_one.m"
%%%%%fulction below you must save in "camCapture.m" file
function I = camCapture(camera)
% CAMCAPTURE Captures a frame from each active camera.
% CAMCAPTURE captures frame from camera(s) supported
% by the Matlab Image Acquisition Toolbox.
% Capture frame from camera(s) using Image Acquisition Toolbox.
nCameras = length(camera);
I = cell(1,nCameras);
for i = 1:nCameras
% Restart camera (if it is not running).
if strcmp(camera{i}.Running,'off')
start(camera{i});
end
% Capture an image (wait until new image is available).
frmIdx = camera{i}.FramesAcquired;
trigger(camera{i});
while frmIdx == camera{i}.FramesAcquired
pause(0.01);
end
I{i} = getdata(camera{i});
end
%%%%%%%%%end of "camCapture.m" file
%%%%%%%%%function stop Camera must be saved in "camStop.m" file
function camStop(camera)
% CAMSTOP Stops active camera(s).
% CAMSTOP stops camera(s) supported by the Matlab
% Image Acquisition Toolbox.
%
% Close camera(s) using Image Acquisition Toolbox.
nCameras = length(camera);
for i = 1:nCameras
delete(camera{i});
end
%%%%%%%%end of "camStop.m" file