Exemplo n.º 1
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.Value;
                    info.CameraProperties = form.CameraProperties;

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

                CameraTypeManager.UpdatedCameraSummary(summary);
            }

            form.Dispose();
            return(needsReconnection);
        }
Exemplo n.º 2
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("framerate"))
                {
                    int    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 = double.Parse(info.CameraProperties["framerate"].CurrentValue, CultureInfo.InvariantCulture);

                    uEye.Defines.ColorMode colorMode = (uEye.Defines.ColorMode)format;

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

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

            // Changing the image size will trigger a memory re-allocation inside uEye,
            // and we'll stop receiving the frame events which is causing all kinds of problems.
            // We can't just wait until we get out of this form because the framerate range depends on image size.
            // We also can't simply disconnect when user is changing size, because then we no longer have access to exposure and framerate.
            // Force a full connection cycle to reload the camera on the new settings.
            // This may reallocate the delay buffer.
            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null)
            {
                return;
            }

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

            disconnect();
            connect();

            ReloadProperty("framerate");
            ReloadProperty("exposure");
        }
Exemplo n.º 4
0
        public FormConfiguration(CameraSummary summary)
        {
            this.summary = summary;

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

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

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null || specific.Camera == null || !specific.Camera.IsOpened)
            {
                return;
            }

            camera = specific.Camera;
            int temp;

            camera.Device.GetDeviceID(out temp);
            deviceId = (long)temp;

            cameraProperties = CameraPropertyManager.Read(camera, deviceId);

            if (cameraProperties.Count != specific.CameraProperties.Count)
            {
                specificChanged = true;
            }

            Populate();
        }
Exemplo n.º 5
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("/IDS/StreamFormat");
                 * if (xmlStreamFormat != null)
                 *  streamFormat = xmlStreamFormat.InnerText;
                 *
                 * Dictionary<string, CameraProperty> cameraProperties = new Dictionary<string, CameraProperty>();
                 *
                 * XmlNodeList props = doc.SelectNodes("/IDS/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("/IDS/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.CameraProperties = cameraProperties;*/
            }
            catch (Exception e)
            {
                log.ErrorFormat(e.Message);
            }

            return(info);
        }
Exemplo n.º 6
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("IDS");

            doc.AppendChild(xmlRoot);

            return(doc.OuterXml);
        }
Exemplo n.º 7
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("IDS");

            /*XmlElement xmlStreamFormat = doc.CreateElement("StreamFormat");
             * xmlStreamFormat.InnerText = info.StreamFormat;
             * xmlRoot.AppendChild(xmlStreamFormat);
             *
             * 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.º 8
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();
            }
            catch (Exception e)
            {
                log.ErrorFormat(e.Message);
            }

            return(info);
        }
Exemplo n.º 9
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;
            btnImport.Text          = CameraLang.FormConfiguration_ImportParameters;

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null || specific.Camera == null || !specific.Camera.IsOpened)
            {
                return;
            }

            camera = specific.Camera;
            int temp;

            camera.Device.GetDeviceID(out temp);
            deviceId         = (long)temp;
            cameraProperties = CameraPropertyManager.Read(camera, deviceId);

            if (cameraProperties.Count != specific.CameraProperties.Count)
            {
                specificChanged = true;
            }

            Populate();
            this.Text     = CameraLang.FormConfiguration_Title;
            btnApply.Text = CameraLang.Generic_Apply;
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        private void Open()
        {
            // Unlike in the DirectShow module, we do not backup and restore camera configuration.
            // If the user configured the camera outside of Kinovea we respect the new settings.
            // Two reasons:
            // 1. In DirectShow we must do the backup/restore to work around drivers that inadvertently reset the camera properties.
            // 2. Industrial cameras have many properties that won't be configurable in Kinovea
            // so the user is more likely to configure the camera from the outside.

            if (grabbing)
            {
                Stop();
            }

            try
            {
                uEye.Defines.Status status = camera.Init((Int32)deviceId | (Int32)uEye.Defines.DeviceEnumeration.UseDeviceID);

                if (status != uEye.Defines.Status.SUCCESS)
                {
                    log.ErrorFormat("Error trying to open IDS uEye camera.");
                    return;
                }

                // Load parameter set.
                ProfileHelper.Load(camera, summary.Identifier);
            }
            catch (Exception e)
            {
                log.Error("Could not open IDS uEye camera.", e);
                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.Camera = camera;

            int currentColorMode = IDSHelper.ReadCurrentStreamFormat(camera);

            // Some properties can only be changed when the camera is opened but not streaming. Now is the time.
            // We store them in the summary when coming back from FormConfiguration, and we write them to the camera here.
            // Only do this if it's not the first time we open the camera, to respect any change that could have been done outside Kinovea.
            if (firstOpen)
            {
                specific.StreamFormat = currentColorMode;
            }
            else
            {
                if (specific.StreamFormat != currentColorMode)
                {
                    IDSHelper.WriteStreamFormat(camera, specific.StreamFormat);
                }

                CameraPropertyManager.WriteCriticalProperties(camera, specific.CameraProperties);

                // Save parameter set.
                ProfileHelper.Save(camera, ProfileHelper.GetProfileFilename(summary.Identifier));
            }

            // Reallocate IDS internal buffers after changing the format.
            Int32[] memList;
            camera.Memory.GetList(out memList);
            camera.Memory.Free(memList);
            camera.Memory.Allocate();

            int memId;

            camera.Memory.GetActive(out memId);

            int width, height, bitsPerPixel, pitch;

            camera.Memory.Inquire(memId, out width, out height, out bitsPerPixel, out pitch);

            log.DebugFormat("IDS internal buffers allocated: {0}x{1}, {2} bits per pixel, pitch:{3}.", width, height, bitsPerPixel, pitch);
        }
Exemplo n.º 12
0
        private void BtnImport_Click(object sender, EventArgs e)
        {
            // Locate an .ini file.
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title = CameraLang.FormConfiguration_ImportParameters;
            //openFileDialog.InitialDirectory = Path.GetDirectoryName(ProfileHelper.GetProfileFilename(summary.Identifier));
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Filter           = "Ini file (*.ini)" + "|*.ini;";
            openFileDialog.FilterIndex      = 0;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string filename = openFileDialog.FileName;

            if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                return;
            }

            // The timing here is finnicky.
            // connect() will start the delay buffer allocation on the current image size and start receiving frames.
            // disconnect prevents reading the new values from the camera.
            // Load with new sizes while the camera is streaming will fail because the buffers are wrong.
            // So we need to load the new values with the camera opened but not streaming.

            this.SuspendLayout();

            disconnect();
            ProfileHelper.Replace(summary.Identifier, filename);

            // Reopen the camera but do not start grabbing.
            uEye.Defines.Status status = camera.Init((Int32)deviceId | (Int32)uEye.Defines.DeviceEnumeration.UseDeviceID);
            if (status != uEye.Defines.Status.SUCCESS)
            {
                log.ErrorFormat("Error trying to open IDS uEye camera.");
                return;
            }

            // Load new parameters.
            ProfileHelper.Load(camera, summary.Identifier);
            cameraProperties = CameraPropertyManager.Read(camera, deviceId);
            SpecificInfo info = summary.Specific as SpecificInfo;

            PopulateStreamFormat();
            info.StreamFormat     = this.SelectedStreamFormat.Value;
            info.CameraProperties = cameraProperties;
            summary.UpdateDisplayRectangle(Rectangle.Empty);
            CameraTypeManager.UpdatedCameraSummary(summary);

            // Reconnect.
            camera.Exit();
            connect();

            // Reload UI.
            RemoveCameraControls();
            PopulateCameraControls();

            this.ResumeLayout();
        }