コード例 #1
0
        public override string GetSummaryAsText(CameraSummary summary)
        {
            string       result = "";
            string       alias  = summary.Alias;
            SpecificInfo info   = summary.Specific as SpecificInfo;

            result = string.Format("{0}", alias);
            try
            {
                if (info != null &&
                    info.StreamFormat != null &&
                    info.CameraProperties.ContainsKey("width") &&
                    info.CameraProperties.ContainsKey("height") &&
                    info.CameraProperties.ContainsKey("framerate"))
                {
                    string format    = info.StreamFormat;
                    int    width     = int.Parse(info.CameraProperties["width"].CurrentValue, CultureInfo.InvariantCulture);
                    int    height    = int.Parse(info.CameraProperties["height"].CurrentValue, CultureInfo.InvariantCulture);
                    double framerate = BaumerHelper.GetResultingFramerate(info.Device);
                    if (framerate == 0)
                    {
                        framerate = double.Parse(info.CameraProperties["framerate"].CurrentValue, CultureInfo.InvariantCulture);
                    }

                    result = string.Format("{0} - {1}×{2} @ {3:0.##} fps ({4}).", alias, width, height, framerate, format);
                }
            }
            catch
            {
            }

            return(result);
        }
コード例 #2
0
        private string SpecificInfoSerialize(CameraSummary summary)
        {
            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null)
            {
                return(null);
            }

            XmlDocument doc     = new XmlDocument();
            XmlElement  xmlRoot = doc.CreateElement("Baumer");

            XmlElement xmlStreamFormat = doc.CreateElement("StreamFormat");

            xmlStreamFormat.InnerText = info.StreamFormat;
            xmlRoot.AppendChild(xmlStreamFormat);

            XmlElement xmlDemosaicing = doc.CreateElement("Demosaicing");

            xmlDemosaicing.InnerText = info.Demosaicing.ToString().ToLowerInvariant();
            xmlRoot.AppendChild(xmlDemosaicing);

            XmlElement xmlCompression = doc.CreateElement("Compression");

            xmlCompression.InnerText = info.Compression.ToString().ToLowerInvariant();
            xmlRoot.AppendChild(xmlCompression);

            XmlElement xmlCameraProperties = doc.CreateElement("CameraProperties");

            foreach (KeyValuePair <string, CameraProperty> pair in info.CameraProperties)
            {
                if (pair.Value == null)
                {
                    continue;
                }

                XmlElement   xmlCameraProperty = doc.CreateElement("CameraProperty");
                XmlAttribute attr = doc.CreateAttribute("key");
                attr.Value = pair.Key;
                xmlCameraProperty.Attributes.Append(attr);

                XmlElement xmlCameraPropertyValue = doc.CreateElement("Value");
                xmlCameraPropertyValue.InnerText = pair.Value.CurrentValue;
                xmlCameraProperty.AppendChild(xmlCameraPropertyValue);

                XmlElement xmlCameraPropertyAuto = doc.CreateElement("Auto");
                xmlCameraPropertyAuto.InnerText = pair.Value.Automatic.ToString().ToLower();
                xmlCameraProperty.AppendChild(xmlCameraPropertyAuto);

                xmlCameraProperties.AppendChild(xmlCameraProperty);
            }

            xmlRoot.AppendChild(xmlCameraProperties);

            doc.AppendChild(xmlRoot);

            return(doc.OuterXml);
        }
コード例 #3
0
        private void BtnReconnect_Click(object sender, EventArgs e)
        {
            if (SelectedStreamFormat == null)
            {
                // This happens when we load the config window and the camera isn't connected.
                return;
            }

            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null)
            {
                return;
            }

            info.StreamFormat     = this.SelectedStreamFormat;
            info.Demosaicing      = this.Demosaicing;
            info.Compression      = this.Compression;
            info.CameraProperties = this.CameraProperties;
            summary.UpdateDisplayRectangle(Rectangle.Empty);
            CameraTypeManager.UpdatedCameraSummary(summary);

            disconnect();
            connect();

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null || specific.Device == null || !specific.Device.IsOpen)
            {
                return;
            }

            device           = specific.Device;
            cameraProperties = CameraPropertyManager.Read(device, summary.Identifier);

            RemoveCameraControls();

            PopulateStreamFormat();
            PopulateBayerConversion();
            PopulateCompression();
            PopulateCameraControls();

            UpdateResultingFramerate();
        }
コード例 #4
0
        public override bool Configure(CameraSummary summary, Action disconnect, Action connect)
        {
            bool         needsReconnection = false;
            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null)
            {
                return(false);
            }

            FormConfiguration form = new FormConfiguration(summary, disconnect, connect);

            FormsHelper.Locate(form);
            if (form.ShowDialog() == DialogResult.OK)
            {
                if (form.AliasChanged)
                {
                    summary.UpdateAlias(form.Alias, form.PickedIcon);
                }

                if (form.SpecificChanged)
                {
                    info.StreamFormat     = form.SelectedStreamFormat;
                    info.Demosaicing      = form.Demosaicing;
                    info.Compression      = form.Compression;
                    info.CameraProperties = form.CameraProperties;

                    summary.UpdateDisplayRectangle(Rectangle.Empty);
                    needsReconnection = true;
                }

                CameraTypeManager.UpdatedCameraSummary(summary);
            }

            form.Dispose();
            return(needsReconnection);
        }
コード例 #5
0
        public FormConfiguration(CameraSummary summary, Action disconnect, Action connect)
        {
            this.summary    = summary;
            this.disconnect = disconnect;
            this.connect    = connect;

            InitializeComponent();
            tbAlias.AutoSize = false;
            tbAlias.Height   = 20;

            tbAlias.Text            = summary.Alias;
            lblSystemName.Text      = summary.Name;
            btnIcon.BackgroundImage = summary.Icon;
            btnReconnect.Text       = CameraLang.FormConfiguration_Reconnect;

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null || specific.Device == null || specific.Device.Id == null || !specific.Device.IsOpen)
            {
                return;
            }

            device           = specific.Device;
            cameraProperties = CameraPropertyManager.Read(device, summary.Identifier);
            if (cameraProperties.Count != specific.CameraProperties.Count)
            {
                specificChanged = true;
            }

            demosaicing = specific.Demosaicing;
            compression = specific.Compression;

            Populate();
            this.Text     = CameraLang.FormConfiguration_Title;
            btnApply.Text = CameraLang.Generic_Apply;
            UpdateResultingFramerate();
        }
コード例 #6
0
        private SpecificInfo SpecificInfoDeserialize(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return(null);
            }

            SpecificInfo info = null;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(new StringReader(xml));

                info = new SpecificInfo();

                string  streamFormat    = "";
                XmlNode xmlStreamFormat = doc.SelectSingleNode("/Baumer/StreamFormat");
                if (xmlStreamFormat != null)
                {
                    streamFormat = xmlStreamFormat.InnerText;
                }

                bool    demosaicing    = false;
                XmlNode xmlDemosaicing = doc.SelectSingleNode("/Baumer/Demosaicing");
                if (xmlDemosaicing != null)
                {
                    demosaicing = XmlHelper.ParseBoolean(xmlDemosaicing.InnerText);
                }

                bool    compression    = false;
                XmlNode xmlCompression = doc.SelectSingleNode("/Baumer/Compression");
                if (xmlCompression != null)
                {
                    compression = XmlHelper.ParseBoolean(xmlCompression.InnerText);
                }

                Dictionary <string, CameraProperty> cameraProperties = new Dictionary <string, CameraProperty>();

                XmlNodeList props = doc.SelectNodes("/Baumer/CameraProperties/CameraProperty");
                foreach (XmlNode node in props)
                {
                    XmlAttribute keyAttribute = node.Attributes["key"];
                    if (keyAttribute == null)
                    {
                        continue;
                    }

                    string         key      = keyAttribute.Value;
                    CameraProperty property = new CameraProperty();

                    string  xpath            = string.Format("/Baumer/CameraProperties/CameraProperty[@key='{0}']", key);
                    XmlNode xmlPropertyValue = doc.SelectSingleNode(xpath + "/Value");
                    if (xmlPropertyValue != null)
                    {
                        property.CurrentValue = xmlPropertyValue.InnerText;
                    }
                    else
                    {
                        property.Supported = false;
                    }

                    XmlNode xmlPropertyAuto = doc.SelectSingleNode(xpath + "/Auto");
                    if (xmlPropertyAuto != null)
                    {
                        property.Automatic = XmlHelper.ParseBoolean(xmlPropertyAuto.InnerText);
                    }
                    else
                    {
                        property.Supported = false;
                    }

                    cameraProperties.Add(key, property);
                }

                info.StreamFormat     = streamFormat;
                info.Demosaicing      = demosaicing;
                info.Compression      = compression;
                info.CameraProperties = cameraProperties;
            }
            catch (Exception e)
            {
                log.ErrorFormat(e.Message);
            }

            return(info);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public FrameGrabber(CameraSummary summary)
 {
     this.summary  = summary;
     this.specific = summary.Specific as SpecificInfo;
 }
コード例 #9
0
ファイル: SnapshotRetriever.cs プロジェクト: weblate/Kinovea
        /// <summary>
        /// Start the device for a frame grab, wait a bit and then return the result.
        /// This method MUST raise a CameraThumbnailProduced event, even in case of error.
        /// </summary>
        public void Run(object data)
        {
            log.DebugFormat("Starting {0} for thumbnail.", summary.Alias);

            SpecificInfo specific = summary.Specific as SpecificInfo;
            bool         opened   = baumerProvider.Open(specific.SystemKey, specific.InterfaceKey, specific.DeviceKey);

            if (!opened)
            {
                log.DebugFormat("Could not open {0} for thumbnail.", summary.Alias);
                if (CameraThumbnailProduced != null)
                {
                    CameraThumbnailProduced(this, new CameraThumbnailProducedEventArgs(summary, null, ImageDescriptor.Invalid, true, false));
                }

                return;
            }

            baumerProvider.BufferProduced += BaumerProducer_BufferProduced;

            // Do not use JPEG compression for the thumbnail.
            wasJpegEnabled = BaumerHelper.GetJPEG(baumerProvider.Device);
            if (wasJpegEnabled)
            {
                BaumerHelper.SetJPEG(baumerProvider.Device, false);
            }

            try
            {
                baumerProvider.AcquireOne();
            }
            catch (Exception e)
            {
                hadError = true;
                LogError(e, null);
            }

            if (!hadError)
            {
                waitHandle.WaitOne(timeoutGrabbing, false);
            }

            lock (locker)
            {
                if (!cancelled)
                {
                    baumerProvider.BufferProduced -= BaumerProducer_BufferProduced;
                    baumerProvider.Stop();
                    if (wasJpegEnabled)
                    {
                        BaumerHelper.SetJPEG(baumerProvider.Device, true);
                    }

                    Close();
                    log.DebugFormat("{0} closed.", summary.Alias);
                }
            }

            if (CameraThumbnailProduced != null)
            {
                CameraThumbnailProduced(this, new CameraThumbnailProducedEventArgs(summary, image, imageDescriptor, hadError, cancelled));
            }
        }