[SOLVED] how to connect a webcam with matlab

Status
Not open for further replies.
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
 

Hey raychen,
I would really appreciate if you could send me the code as well. I am about to work on my project and I would like to perform object tracking using matlab.
Thanks.
hassanzafargill@gmail.com
 

i am need of matlab code plz coz i am doing a real time project for face recognition using web cam

Hey rachen My project is face recognation at real time,.İ read that you have codes about my project.Do you send me this codes?



raychen..
can u sent to me the matlab code to connect webcam with matlab..

my email id is sabiha_anjum786@yahoo.com
 

im hoping for code that detect face from side view? anyone has the code?
 

hi raychen
i am doing my final year btech project in matlab(face recognition using pca)
and i want to try interface matlab with web cam so im in need of ur code
can u please mail it to brohitv@yahoo.co.in
 

hi raychen,
I also need those codes.
pls send to my email: usamasaqib(at)gmail.com

thnks
 

Hey raychen,

I have other problem in MATLAB,
I'm not sure you have any time for help me?
I have a problem of finding degree function in MATLAB.
I want to know the shifting degree of the box in the vdo file (vdo file to show a box on the conveyor).
In vdo a box put incorrect direction, i want to rotate it, How to do?
Please give more information or the way to program.

Very thank you.
Naja
 

you can use the matlab image processing toolbox, it has a collection of powerfull functions
and you have to learn to program with matlab language, its pretty much like c
,im using matlab intensivly
 

Hi raychen,
I hope you will be okay, I heared about your projects on matlab. Its first time I am doing such type of project, so I have no idea.

I need your help in object traking through matlab.

My email id is momal.umar(at)gmail.com

I am waiting for your reply.
 

I am doing project on face recognition system using multi resolution technology . Here i need to interface camera with my program so that it can directly take image and recognize kindly help for the same
Code:

Added after 9 minutes:

If any body has this code than please mail me a t manoj_gawde@live.com
 

hey dear i have interfaced the camra with matlab how to capture the image and save it for the processing
 

Hi to everybody,

I know I'm a little bit in late respect this post,
but I need too the email raychen was providing to you.

Can someone send me to my email those files please???

My email is ctenti(at)cs.ucsd.edu

thank you in advance to everybody
 

hi everybody
i m looking for the code to connect webcam with matlab and other things concerning processing image.
if anybody has the code please send it to me at soukaina.sbitti@gmail.com
i really need it!!!
thx
 

hi raychen,

i need that code also...
send to me at mansur15(at)gmail.com

TQ.
 

hii , thanks for the information.. really i need the code.

i am trying to work on my laptop camera, and i need to compress the video and send it to another laptop by wireless

if any one can help me in that, i need it for my graduation project.. i tried many times .. but without result..

thanks again.

my mail is: engineer.ahmed.hilal.2010(at)live.co.uk
 


Hi karper1986,

im new in matlab... may i know every steps to make dis code work?
TQ.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…