matlab webcam inconsistencies?
9 views (last 30 days)
Show older comments
Hi.
I'm having difficulty with the webcam toolbox. I realize its free, but I'm hoping to get some support since I have some time invested in this already.
So in my application, the focus on the webcam needs to be kept constant. This can be done a number of ways such as by turning off the auto focus or fixing the focal depth of the camera.
The problem I'm having appears to be some kind of weird behavior with the way the objects are being created. I'm not sure I understand this.
The example problems I'm going to try to demonstrate were made from the matlab example code. Ill repost here for clarity.
% This code utilizes the MATLAB support package for USB webcams.
% http://www.mathworks.com/hardware-support/matlab-webcam.html
% Follow the video included in the link.
clear
cam1 = 'Logitech HD Webcam C615';
cam2 = 'Integrated Webcam';
cam3 = 'Endoscope';
bore = webcam(cam2);
bore.Resolution = '320x240';
vidWriter = VideoWriter('frames2.avi');
open(vidWriter);
for index = 1:1
%[img(index) ts(index)] = snapshot(bore);
img = snapshot(bore);
writeVideo(vidWriter, img);
end
close(vidWriter);
clear bore
So we are declaring "bore" for boroscope, by the way, not that it matters.. The issue I'm having is that bore keeps having different attributes each time I call it, and not just with one camera, with 3 of the same type (Logitech) but also with my integrated webcam.
So with my application, I had found that if I use 'cam1' (Logitech) there is a focusmode property which when set to manual, will allow me to keep the camera on the target. It works in that I can keep the camera from going out of focus ... but well... It really only works about 50% of the time I run the code. The 'focusmode' property is not always part of the bore object.
bore=
Name: 'Logitech HD Webcam C615'
Resolution: '640x480'
AvailableResolutions: {1x15 cell}
WhiteBalance: 3528
Tilt: 0
Sharpness: 22
Brightness: 128
Gain: 62
BacklightCompensation: 1
Pan: 0
Zoom: 1
FocusMode: 'manual'
Focus: 255
Saturation: 32
Contrast: 32
Exposure: -6
ExposureMode: 'auto'
Now if I poll 'bore', by just typing 'bore' at the command line a minute later... I get the following. Well, technically note that in this example I was playing with the focus setting (bore.focus=0) and rerunning the code a few times but this is not really the issue ...
so I run the 'bore' command a few minutes later, I get the outputs in a different order...and also, the 'focusmode' property is gone
Name: 'Logitech HD Webcam C615'
Resolution: '640x480'
AvailableResolutions: {1x15 cell}
Zoom: 1
Brightness: 128
Tilt: 0
Gain: 54
Saturation: 32
Exposure: -5
Contrast: 32
WhiteBalance: 3684
Sharpness: 22
Pan: 0
ExposureMode: 'auto'
Focus: 0
BacklightCompensation: 1
I then tried to see if these inconsistencies are just with the Logitech or my other cameras. I reproduced this behavior with 3 Logitech cameras (not a personnel use application obviously)
This odd behavior seems to occur with my integrated webcam, if I poll it one minute I get this..
Name: 'Integrated Webcam'
Resolution: '640x480'
AvailableResolutions: {'640x480' '640x360' '320x240' '424x240' '320x180' '160x120'}
Gamma: 100
WhiteBalanceMode: 'auto'
Contrast: 0
WhiteBalance: 4600
Hue: 0
Saturation: 64
BacklightCompensation: 3
Sharpness: 2
Brightness: 0
a few minutes later I poll 'bore' again and get ONLY this
Name: 'Integrated Webcam'
Resolution: '640x480'
AvailableResolutions: {'640x480' '640x360' '320x240' '424x240' '320x180' '160x120'}
I've played with this for a long time, the outputs are always in different orders.
This doesn't make any sense to me.
0 Comments
Answers (1)
Image Analyst
on 23 Dec 2015
The webcam capability is not a toolbox. It's a "Hardware Support Package" that people can access from the "Add-Ons" button on the "Home" tab of the toolstrip. One needs to install both the "USB webcams" package as well as the "OS Generic Video Interface". Please make sure you have both of those installed, but I suspect you do already.
When I remove the video writer stuff and run it, I sometimes get 3 properties and sometimes get 12. If I remove the last line about clearing bore, I always get all 12 properties, though they seem to be printed out in random order for some reason. I don't have a FocusMode property - apparently my built in webcam does not allow to you change the autofocus mode.
I just wanted to let you know that at least one person can reproduce what you are observing.
The way I fixed it was to keep trying until I got all the properties. I don't know if it's a timing thing or what, but if I don't get all the properties the first time, I would always get them the second time. I never had to go more than twice without getting all the properties. Here is the fixed code:
cam1 = 'Logitech HD Webcam C615';
cam2 = 'Integrated Webcam';
cam3 = 'Endoscope';
maxAttempts = 30;
attempt = 1;
hasProperty = false;
while attempt < maxAttempts
bore = webcam(cam2);
hasProperty = max(ismember(properties(bore), 'Contrast'));
if hasProperty
% We got all the properties so we can quit trying.
fprintf('We have all camera properties after %d attempts. Now continuing with program.\n', attempt);
break;
end
fprintf('We do not have all camera properties after %d attempts. Trying again.\n', attempt);
attempt = attempt + 1;
clear('bore');
end
% Now we should have all properties and can continue....
bore.Resolution = '320x240';
0 Comments
See Also
Categories
Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!