Camera selection bug in WebCam service

Hi all,

There's a bug in UpdateDeviceInternal that will affect systems with one or more camera of the same brand (highlighted below):

Code Snippet

foreach (object obj in new vision.CameraCollection())
{
using (vision.Camera camera = obj as vision.Camera)
{
if ((!string.IsNullOrEmpty(selected.FriendlyName) && camera.Name == selected.FriendlyName) ||
(!string.IsNullOrEmpty(selected.DevicePath) && camera.Path == selected.DevicePath))
{
selected.FriendlyName = camera.Name;
selected.DevicePath = selected.DevicePath;
//selected.FrameGrabber = vision.FrameGrabber.FromCamera(camera);
selected.FrameGrabber = Braintech.FrameGrabber.FromCamera(camera);
selected.SupportedFormats = ConvertFormats(selected.FrameGrabber.Formats);
selected.FrameGrabber.CaptureFrame += OnCaptureFrame;
selected.FrameGrabber.StartCapture();
selected.Format = new Format(selected.FrameGrabber.Format);

updated = true;
break;
}
}
}


Supposing you have two cameras with the same FriendlyName on your system (eg. Logitech QuickCam Pro etc), then due to the OR in the if statement, you'll only be able to select the first such camera, regardless of what you put in selected.DeviceName. For the reason described below, this bug only appears you use an initial state partner (not when you configure via the web interface).

Unlike an initial state partner, which stores both the device path and the friendly name, the HTTP Post handler leaves FriendlyName null, so the correct device path can be configured via the web. That complicates the fix- if you change the || to &&, you need to properly set the FriendlyName in HTTPPostHandler (which is non-trivial because the POST event doesn't receive the friendly name... :-( Maybe the best solution is to ignore the friendly name altogether?

[2130 byte] By [RobSim--Braintech] at [2008-2-13]
# 1

Hi Rob,

Thanks for pointing this one out.

Another possible solution would be to compare both (with &&) if both are provided and otherwise only compare whichever is provided. This would allow a InitialState file using a FriendlyName to be deployable to multiple machines with the same hardware (although with the limitations if there are multiple cameras with the same FriendlyName of course) and still allow the HttpPost functionality to work.

Cheers

Paul

PaulCRoberts at 2007-10-11 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Hardware Configuration and Troubleshooting...

Microsoft Robotics Studio

Site Classified