public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { List <CameraSummary> summaries = new List <CameraSummary>(); foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != CameraType) { continue; } string alias = blurb.Alias; string identifier = blurb.Identifier; Bitmap icon = blurb.Icon ?? defaultIcon; Rectangle displayRectangle = blurb.DisplayRectangle; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } object specific = SpecificInfoDeserialize(blurb.Specific); CameraSummary summary = new CameraSummary(alias, defaultName, identifier, icon, displayRectangle, aspectRatio, specific, this); summaries.Add(summary); } return(summaries); }
public void UpdateAspectRatio(CaptureAspectRatio aspectRatio) { if (aspectRatio == this.AspectRatio) { return; } this.AspectRatio = aspectRatio; }
private ImageAspectRatio Convert(CaptureAspectRatio aspectRatio) { switch (aspectRatio) { case CaptureAspectRatio.Auto: return(ImageAspectRatio.Auto); case CaptureAspectRatio.Force43: return(ImageAspectRatio.Force43); case CaptureAspectRatio.Force169: return(ImageAspectRatio.Force169); default: return(ImageAspectRatio.Auto); } }
private void ChangeAspectRatio(ImageAspectRatio aspectRatio) { CaptureAspectRatio ratio = Convert(aspectRatio); if (ratio == cameraSummary.AspectRatio) { return; } cameraSummary.UpdateAspectRatio(ratio); cameraSummary.UpdateDisplayRectangle(Rectangle.Empty); // update display rectangle. Disconnect(); Connect(); }
public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { List <CameraSummary> summaries = new List <CameraSummary>(); // We don't do the discover step every time to avoid UI freeze since Enumerate takes some time. if (discoveryStep > 0) { discoveryStep = (discoveryStep + 1) % discoverySkip; foreach (CameraSummary summary in cache.Values) { summaries.Add(summary); } return(summaries); } discoveryStep = 1; List <CameraSummary> found = new List <CameraSummary>(); List <DeviceEnumerator.Device> devices = DeviceEnumerator.EnumerateDevices(); foreach (DeviceEnumerator.Device device in devices) { string identifier = device.FullName; bool cached = cache.ContainsKey(identifier); if (cached) { deviceIndices[identifier] = device.Index; summaries.Add(cache[identifier]); found.Add(cache[identifier]); continue; } string alias = device.Name; Bitmap icon = null; SpecificInfo specific = new SpecificInfo(); Rectangle displayRectangle = Rectangle.Empty; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; deviceIndices[identifier] = device.Index; if (blurbs != null) { foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier) { continue; } alias = blurb.Alias; icon = blurb.Icon ?? defaultIcon; displayRectangle = blurb.DisplayRectangle; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } // Restore saved parameters. specific = SpecificInfoDeserialize(blurb.Specific); break; } } icon = icon ?? defaultIcon; CameraSummary summary = new CameraSummary(alias, device.Name, identifier, icon, displayRectangle, aspectRatio, specific, this); summaries.Add(summary); found.Add(summary); cache.Add(identifier, summary); } List <CameraSummary> lost = new List <CameraSummary>(); foreach (CameraSummary summary in cache.Values) { if (!found.Contains(summary)) { lost.Add(summary); } } foreach (CameraSummary summary in lost) { cache.Remove(summary.Identifier); } return(summaries); }
public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { // DirectShow has active discovery. We just ask for the list of cameras connected to the PC. List <CameraSummary> summaries = new List <CameraSummary>(); List <CameraSummary> found = new List <CameraSummary>(); FilterInfoCollection cameras = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo camera in cameras) { if (bypass.Contains(camera.Name)) { continue; } // For now consider that the moniker string is like a serial number. // Cameras that don't have a serial number will appear to be new when changing USB port. string identifier = camera.MonikerString; bool cached = cache.ContainsKey(identifier); string alias = camera.Name; Bitmap icon = null; SpecificInfo specific = null; Rectangle displayRectangle = Rectangle.Empty; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; if (blurbs != null) { foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier) { continue; } alias = blurb.Alias; icon = blurb.Icon ?? SelectDefaultIcon(identifier); displayRectangle = blurb.DisplayRectangle; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } specific = SpecificInfoDeserialize(blurb.Specific); VendorHelper.IdentifyModel(identifier); break; } } if (icon == null) { icon = SelectDefaultIcon(identifier); } CameraSummary summary = new CameraSummary(alias, camera.Name, identifier, icon, displayRectangle, aspectRatio, specific, this); summaries.Add(summary); if (cached) { found.Add(cache[identifier]); } if (!cached) { cache.Add(identifier, summary); found.Add(summary); log.DebugFormat("DirectShow device enumeration: {0} (moniker:{1}).", summary.Alias, identifier); } } // TODO: do we need to do all this. Just replace the cache with the current list. List <CameraSummary> lost = new List <CameraSummary>(); foreach (CameraSummary summary in cache.Values) { if (!found.Contains(summary)) { lost.Add(summary); } } foreach (CameraSummary summary in lost) { cache.Remove(summary.Identifier); } return(summaries); }
public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { List <CameraSummary> summaries = new List <CameraSummary>(); List <CameraSummary> found = new List <CameraSummary>(); uEye.Types.CameraInformation[] devices; uEye.Info.Camera.GetCameraList(out devices); foreach (uEye.Types.CameraInformation device in devices) { string identifier = device.SerialNumber; bool cached = cache.ContainsKey(identifier); if (cached) { deviceIds[identifier] = device.DeviceID; summaries.Add(cache[identifier]); found.Add(cache[identifier]); continue; } string alias = device.Model; Bitmap icon = null; SpecificInfo specific = new SpecificInfo(); Rectangle displayRectangle = Rectangle.Empty; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; ImageRotation rotation = ImageRotation.Rotate0; deviceIds[identifier] = device.DeviceID; if (blurbs != null) { foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier) { continue; } // We already know this camera, restore the user custom values. alias = blurb.Alias; icon = blurb.Icon ?? defaultIcon; displayRectangle = blurb.DisplayRectangle; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } if (!string.IsNullOrEmpty(blurb.Rotation)) { rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation); } specific = SpecificInfoDeserialize(blurb.Specific); break; } } icon = icon ?? defaultIcon; CameraSummary summary = new CameraSummary(alias, device.Model, identifier, icon, displayRectangle, aspectRatio, rotation, specific, this); summaries.Add(summary); found.Add(summary); cache.Add(identifier, summary); //log.DebugFormat("IDS uEye device enumeration: {0} (id:{1}).", summary.Alias, identifier); } List <CameraSummary> lost = new List <CameraSummary>(); foreach (CameraSummary summary in cache.Values) { if (!found.Contains(summary)) { lost.Add(summary); } } foreach (CameraSummary summary in lost) { cache.Remove(summary.Identifier); } return(summaries); }
public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { List <CameraSummary> summaries = new List <CameraSummary>(); List <CameraSummary> found = new List <CameraSummary>(); List <IGXDeviceInfo> devices = new List <IGXDeviceInfo>(); igxFactory.UpdateDeviceList(200, devices); foreach (IGXDeviceInfo device in devices) { string identifier = device.GetSN(); bool cached = cache.ContainsKey(identifier); if (cached) { // We've already seen this camera in the current Kinovea session. //deviceIds[identifier] = device.GetDeviceID(); summaries.Add(cache[identifier]); found.Add(cache[identifier]); continue; } string alias = device.GetDisplayName(); Bitmap icon = null; SpecificInfo specific = new SpecificInfo(); Rectangle displayRectangle = Rectangle.Empty; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; ImageRotation rotation = ImageRotation.Rotate0; //deviceIndices[identifier] = device.GetDeviceID(); if (blurbs != null) { foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier) { continue; } // We know this camera from a previous Kinovea session, restore the user custom values. alias = blurb.Alias; icon = blurb.Icon ?? defaultIcon; displayRectangle = blurb.DisplayRectangle; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } if (!string.IsNullOrEmpty(blurb.Rotation)) { rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation); } specific = SpecificInfoDeserialize(blurb.Specific); break; } } icon = icon ?? defaultIcon; CameraSummary summary = new CameraSummary(alias, device.GetDisplayName(), identifier, icon, displayRectangle, aspectRatio, rotation, specific, this); summaries.Add(summary); found.Add(summary); cache.Add(identifier, summary); } List <CameraSummary> lost = new List <CameraSummary>(); foreach (CameraSummary summary in cache.Values) { if (!found.Contains(summary)) { lost.Add(summary); } } foreach (CameraSummary summary in lost) { cache.Remove(summary.Identifier); } return(summaries); }
public CameraSummary(string alias, string name, string identifier, Bitmap icon, Rectangle displayRectangle, CaptureAspectRatio aspectRatio, ImageRotation rotation, object specific, CameraManager manager) { this.Alias = alias; this.Name = name; this.Identifier = identifier; this.Icon = icon; this.DisplayRectangle = displayRectangle; this.AspectRatio = aspectRatio; this.Rotation = rotation; this.Specific = specific; this.Manager = manager; }
public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs) { List <CameraSummary> summaries = new List <CameraSummary>(); List <CameraSummary> found = new List <CameraSummary>(); //--------------------------------------------- // Lifecycles of objects in the Baumer API: // - systemList: entire application. Will initialize all systems, not clear how to uninitialize non Baumer systems. // - system: entire application. Should be kept open. // - interface: entire application. Allow listing of devices even if they are opened by another application. // - device: camera session. //--------------------------------------------- try { foreach (KeyValuePair <string, BGAPI2.System> systemPair in systems) { BGAPI2.System system = systemPair.Value; if (!system.Vendor.Contains("Baumer")) { continue; } if (!system.IsOpen) { system.Open(); } if (string.IsNullOrEmpty(system.Id)) { continue; } system.Interfaces.Refresh(200); foreach (KeyValuePair <string, BGAPI2.Interface> interfacePair in system.Interfaces) { BGAPI2.Interface iface = interfacePair.Value; //log.DebugFormat("Opening interface {0}", iface.DisplayName); if (!iface.IsOpen) { iface.Open(); } if (string.IsNullOrEmpty(iface.Id)) { continue; } iface.Devices.Refresh(200); //log.DebugFormat("Devices found in interface {0}: {1}.", iface.DisplayName, iface.Devices.Count); foreach (KeyValuePair <string, BGAPI2.Device> devicePair in iface.Devices) { BGAPI2.Device device = devicePair.Value; //log.DebugFormat("Found device: {0} ({1})", device.DisplayName, device.SerialNumber); string identifier = device.SerialNumber; bool cached = cache.ContainsKey(identifier); if (cached) { // We've already seen this camera in the current Kinovea session. //deviceIds[identifier] = device.GetDeviceID(); //log.DebugFormat("Known device from current session."); summaries.Add(cache[identifier]); found.Add(cache[identifier]); continue; } string alias = device.DisplayName; Bitmap icon = null; SpecificInfo specific = new SpecificInfo(); Rectangle displayRectangle = Rectangle.Empty; CaptureAspectRatio aspectRatio = CaptureAspectRatio.Auto; ImageRotation rotation = ImageRotation.Rotate0; bool mirror = false; // Check if we already know this camera from a previous Kinovea session. if (blurbs != null) { foreach (CameraBlurb blurb in blurbs) { if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier) { continue; } // We know this camera from a previous Kinovea session, restore the user custom values. log.DebugFormat("Known device from previous session."); alias = blurb.Alias; icon = blurb.Icon ?? defaultIcon; displayRectangle = blurb.DisplayRectangle; if (!string.IsNullOrEmpty(blurb.AspectRatio)) { aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio); } if (!string.IsNullOrEmpty(blurb.Rotation)) { rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation); } mirror = blurb.Mirror; specific = SpecificInfoDeserialize(blurb.Specific); break; } } // Keep temporary info in order to find it back later. specific.SystemKey = systemPair.Key; specific.InterfaceKey = interfacePair.Key; specific.DeviceKey = devicePair.Key; specific.Device = null; icon = icon ?? defaultIcon; CameraSummary summary = new CameraSummary(alias, device.DisplayName, identifier, icon, displayRectangle, aspectRatio, rotation, mirror, specific, this); summaries.Add(summary); found.Add(summary); cache.Add(identifier, summary); } //iface.Close(); } //system.Close(); } } catch (Exception e) { log.ErrorFormat("Error while scanning for devices. {0}", e.Message); } List <CameraSummary> lost = new List <CameraSummary>(); foreach (CameraSummary summary in cache.Values) { if (!found.Contains(summary)) { lost.Add(summary); } } foreach (CameraSummary summary in lost) { log.DebugFormat("Lost device: {0}", summary.Name); cache.Remove(summary.Identifier); } return(summaries); }