Exemplo n.º 1
0
        public override string GetSummaryAsText(CameraSummary summary)
        {
            string       result = "";
            string       alias  = summary.Alias;
            SpecificInfo info   = summary.Specific as SpecificInfo;

            try
            {
                if (info != null &&
                    info.CameraProperties.ContainsKey("Width") &&
                    info.CameraProperties.ContainsKey("Height") &&
                    info.CameraProperties.ContainsKey("AcquisitionFrameRate"))
                {
                    int    width     = int.Parse(info.CameraProperties["Width"].CurrentValue, CultureInfo.InvariantCulture);
                    int    height    = int.Parse(info.CameraProperties["Height"].CurrentValue, CultureInfo.InvariantCulture);
                    double framerate = DahengHelper.GetResultingFramerate(info.Device);
                    if (framerate == 0)
                    {
                        framerate = double.Parse(info.CameraProperties["AcquisitionFrameRate"].CurrentValue, CultureInfo.InvariantCulture);
                    }

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

            return(result);
        }
Exemplo n.º 2
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.CameraProperties = form.CameraProperties;

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

                CameraTypeManager.UpdatedCameraSummary(summary);
            }

            form.Dispose();
            return(needsReconnection);
        }
Exemplo n.º 3
0
        private void BtnReconnect_Click(object sender, EventArgs e)
        {
            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null)
            {
                return;
            }

            info.StreamFormat     = this.selectedStreamFormat;
            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)
            {
                return;
            }

            device           = specific.Device;
            cameraProperties = CameraPropertyManager.Read(device);

            PopulateStreamFormat();
            RemoveCameraControls();
            PopulateCameraControls();
            UpdateResultingFramerate();
        }
Exemplo n.º 4
0
        private void PopulateStreamFormat()
        {
            lblColorSpace.Text = CameraLang.FormConfiguration_Properties_StreamFormat;

            IGXFeatureControl featureControl = device.GetRemoteFeatureControl();

            if (featureControl == null)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;
            List <DahengStreamFormat> streamFormats = DahengHelper.GetSupportedStreamFormats(featureControl);

            cmbFormat.Items.Clear();

            foreach (DahengStreamFormat streamFormat in streamFormats)
            {
                cmbFormat.Items.Add(streamFormat);
                if (streamFormat == specific.StreamFormat)
                {
                    selectedStreamFormat    = streamFormat;
                    cmbFormat.SelectedIndex = cmbFormat.Items.Count - 1;
                }
            }

            if (cmbFormat.SelectedIndex < 0)
            {
                selectedStreamFormat    = (DahengStreamFormat)cmbFormat.Items[0];
                cmbFormat.SelectedIndex = 0;
            }
        }
Exemplo n.º 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)
            {
                return;
            }

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

            PopulateCameraControls();

            this.Text     = CameraLang.FormConfiguration_Title;
            btnApply.Text = CameraLang.Generic_Apply;
            UpdateResultingFramerate();
        }
Exemplo n.º 6
0
        public void Close()
        {
            if (device == null)
            {
                return;
            }

            // Stop everything and destroy resources.

            // Stop acquisition.
            try
            {
                if (featureControl != null)
                {
                    featureControl.GetCommandFeature("AcquisitionStop").Execute();
                    featureControl = null;
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }

            // Close stream.
            try
            {
                if (stream != null)
                {
                    stream.StopGrab();
                    stream.UnregisterCaptureCallback();
                    stream.Close();
                    stream = null;
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }

            // Close device.
            try
            {
                if (device != null)
                {
                    device.Close();
                    device = null;

                    SpecificInfo specific = summary.Specific as SpecificInfo;
                    if (specific != null && specific.Device != null)
                    {
                        specific.Device = null;
                    }
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }
        }
Exemplo n.º 7
0
        private void Open()
        {
            if (device != null)
            {
                Close();
            }

            bool open = false;

            try
            {
                device         = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);
                open = true;
            }
            catch
            {
                log.DebugFormat("Could not open Daheng device.");
            }

            if (!open)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the camera object into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Device = device;

            if (firstOpen)
            {
                // Grab current values.
                Dictionary <string, CameraProperty> cameraProperties = CameraPropertyManager.Read(device);
                specific.CameraProperties = cameraProperties;
            }
            else
            {
                CameraPropertyManager.WriteCriticalProperties(device, specific.CameraProperties);
            }

            try
            {
                stream = device.OpenStream(0);
            }
            catch
            {
                log.DebugFormat("Could not start Daheng device.");
            }
        }
Exemplo n.º 8
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("Daheng");

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

            foreach (KeyValuePair <string, CameraProperty> pair in info.CameraProperties)
            {
                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);
        }
Exemplo n.º 9
0
        private void Open()
        {
            if (device != null)
            {
                Close();
            }

            bool open = false;

            try
            {
                device         = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);
                open = true;
            }
            catch
            {
                log.DebugFormat("Could not open Daheng device.");
            }

            if (!open)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the camera object into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Device = device;
            isColor         = DahengHelper.IsColor(featureControl);

            if (firstOpen)
            {
                // Always default to RGB24 for color cameras and Y800 for mono cameras.
                // Raw mode will have to be switched explicitly everytime for now.
                currentStreamFormat = isColor ? DahengStreamFormat.RGB : DahengStreamFormat.Mono;

                // Grab current values.
                Dictionary <string, CameraProperty> cameraProperties = CameraPropertyManager.Read(device);
                specific.CameraProperties = cameraProperties;
                specific.StreamFormat     = currentStreamFormat;
            }
            else
            {
                CameraPropertyManager.WriteCriticalProperties(device, specific.CameraProperties);
                if (specific.StreamFormat != currentStreamFormat)
                {
                    currentStreamFormat = specific.StreamFormat;
                }
            }

            try
            {
                stream = device.OpenStream(0);
            }
            catch
            {
                log.Debug("Could not start Daheng device.");
            }
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
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();

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

                XmlNodeList props = doc.SelectNodes("/Daheng/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("/Daheng/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.CameraProperties = cameraProperties;
            }
            catch (Exception e)
            {
                log.ErrorFormat(e.Message);
            }

            return(info);
        }