¿Why the webcam changes its parameter everytime i start running the code?

조회 수: 4 (최근 30일)
mack cartagena
mack cartagena 2018년 5월 31일
편집: Florian Morsch 2018년 6월 4일
I'm using a webcam to count some squares using a UV ilumination. so i setup the webcam parameters (Contrast, Exposure, etc) to later make some binarization, but every time i close matlab or disconect the camera the parameters i already set at the begining of the code, change or are ignored. heres the code, and i attached 2 images. I need the settings of the webcam always the same for a proper count of objects.
clear('vid');
vid=webcam('USB Camera');
vid.Resolution='2048x1536';
vid.Exposure=-5.7;
vid.Gain=0;
vid.Hue=0; %-40 40
vid.Gamma=72; %72-500
vid.Contrast=64;
vid.Saturation=35;
vid.WhiteBalanceMode='manual';
vid.Sharpness=1;
vid.Brightness=15; %-64 64
vid.WhiteBalance=6500; %2800-6500
vid.ExposureMode='manual';
vid.BacklightCompensation=2; %0-2
imagen=snapshot(vid);
imagen=imrotate(imagen,180.8); %0.8
imagen=imcrop(imagen,roi);
imagenG=rgb2gray(imagen);
imagenG=imadjust(imagenG);
imagenB=im2bw(imagenG,0.7);%0.7 %0.35
imagenB = bwareaopen(imagenB,Open1); %Elimina impuerzas al inicio
s=strel('disk',Streel); %
imagenB2=imerode (imagenB,s); %Erosion para eliminar impurezas
imagenB2=imclearborder(imagenB2);
imagenB2 = bwareaopen(imagenB2,Open2); %Elimina impurezas al final
imagenBSUP=imcrop(imagenB2,roiSup);
imagenBSUP=imclearborder(imagenBSUP);
c1=bwconncomp(imagenBSUP,8);
totalSUP=c1.NumObjects;
imagenBINF=imcrop(imagenB2,roiInf);
imagenBINF=imclearborder(imagenBINF);
c2=bwconncomp(imagenBINF,8);
totalINF=c2.NumObjects;
TOTAL=totalSUP+totalINF;

답변 (1개)

Florian Morsch
Florian Morsch 2018년 6월 4일
편집: Florian Morsch 2018년 6월 4일
This is normal behavior of most cameras. They have initial starting values which are used when you connect the camera.
Now if you start MATLAB and change those parameters the camera will run with the parameters as long as its connected to that MATLAB script/function. If you clear the camera object and reinitialize it, the standart parameters will be loaded again.
If you disconnect the camera or close MATLAB you also delete the camera object and so the camera will load the default parameters the next time.
You can try to change the parameter by accessing the camera configuration (mostly with a developer SDK or a camera driver, config file or something like that). If you have no information about that try to contact the manufacturer of the camera and ask for instructions to change those parameters.
EDIT: You could also store those values into a config file yourself and everytime the camera loads you automatically give the parameters to the camera (similar like you doing now, initialize the camera and then change the parameters, just with a pre-defined config file)

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by