Exemplo n.º 1
0
        private void PopulateStreamFormat()
        {
            lblColorSpace.Text = CameraLang.FormConfiguration_Properties_StreamFormat;

            bool readable = Pylon.DeviceFeatureIsReadable(deviceHandle, "PixelFormat");

            if (!readable)
            {
                cmbFormat.Enabled = false;
                return;
            }

            string currentValue = Pylon.DeviceFeatureToString(deviceHandle, "PixelFormat");

            List <GenApiEnum> streamFormats = PylonHelper.ReadEnum(deviceHandle, "PixelFormat");

            if (streamFormats == null)
            {
                cmbFormat.Enabled = false;
                return;
            }

            foreach (GenApiEnum streamFormat in streamFormats)
            {
                cmbFormat.Items.Add(streamFormat);
                if (currentValue == streamFormat.Symbol)
                {
                    selectedStreamFormat    = streamFormat;
                    cmbFormat.SelectedIndex = cmbFormat.Items.Count - 1;
                }
            }
        }
Exemplo n.º 2
0
        private void Open()
        {
            if (grabbing)
            {
                Stop();
            }

            try
            {
                deviceHandle = Pylon.CreateDeviceByIndex(deviceIndex);
                imageProvider.Open(deviceHandle);
            }
            catch (Exception e)
            {
                log.Error("Could not open Basler device.");
                LogError(e, imageProvider.GetLastErrorMessage());
                return;
            }

            if (!deviceHandle.IsValid)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the handle into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Handle = deviceHandle;
            GenApiEnum currentStreamFormat = PylonHelper.ReadEnumCurrentValue(deviceHandle, "PixelFormat");

            if (!string.IsNullOrEmpty(specific.StreamFormat) && specific.StreamFormat != currentStreamFormat.Symbol)
            {
                PylonHelper.WriteEnum(deviceHandle, "PixelFormat", specific.StreamFormat);
            }

            // The bayer conversion mode will be set during Prepare().

            if (firstOpen)
            {
                // Restore camera parameters from the XML blurb.
                // Regular properties, including image size.
                // First we read the current properties from the API to get fully formed properties.
                // We merge the values saved in the XML into the properties.
                // (The restoration from the XML doesn't create fully formed properties, it just contains the values).
                // Then commit the properties to the camera.
                Dictionary <string, CameraProperty> cameraProperties = CameraPropertyManager.Read(deviceHandle, summary.Identifier);
                CameraPropertyManager.MergeProperties(cameraProperties, specific.CameraProperties);
                specific.CameraProperties = cameraProperties;
                CameraPropertyManager.WriteCriticalProperties(deviceHandle, specific.CameraProperties);
            }
            else
            {
                CameraPropertyManager.WriteCriticalProperties(deviceHandle, specific.CameraProperties);
            }
        }
Exemplo n.º 3
0
        private void cmbFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            GenApiEnum selected = cmbFormat.SelectedItem as GenApiEnum;

            if (selected == null || selectedStreamFormat.Symbol == selected.Symbol)
            {
                return;
            }

            selectedStreamFormat = selected;
            specificChanged      = true;

            SetBayerComboVisibility();
        }
Exemplo n.º 4
0
        private static void ReadGain(PYLON_DEVICE_HANDLE deviceHandle, Dictionary <string, CameraProperty> properties)
        {
            CameraProperty prop = ReadFloatProperty(deviceHandle, "Gain");

            if (!prop.Supported)
            {
                prop = ReadIntegerProperty(deviceHandle, "GainRaw");
            }

            prop.CanBeAutomatic      = true;
            prop.AutomaticIdentifier = "GainAuto";
            GenApiEnum auto = PylonHelper.ReadEnumCurrentValue(deviceHandle, prop.AutomaticIdentifier);

            prop.Automatic = auto != null && auto.Symbol == "Continuous";
            properties.Add("gain", prop);
        }
Exemplo n.º 5
0
        private static void ReadExposure(PYLON_DEVICE_HANDLE deviceHandle, string deviceClass, Dictionary <string, CameraProperty> properties)
        {
            CameraProperty prop = null;

            if (deviceClass == "BaslerUsb")
            {
                prop = ReadFloatProperty(deviceHandle, "ExposureTime");
            }
            else
            {
                prop = ReadFloatProperty(deviceHandle, "ExposureTimeAbs");
            }

            prop.CanBeAutomatic      = true;
            prop.AutomaticIdentifier = "ExposureAuto";
            GenApiEnum auto = PylonHelper.ReadEnumCurrentValue(deviceHandle, prop.AutomaticIdentifier);

            prop.Automatic = auto.Symbol == "Continuous";
            properties.Add("exposure", prop);
        }
Exemplo n.º 6
0
        private static void ReadGain(PYLON_DEVICE_HANDLE deviceHandle, Dictionary <string, CameraProperty> properties)
        {
            CameraProperty p = ReadFloatProperty(deviceHandle, "Gain");

            if (!p.Supported)
            {
                p = ReadIntegerProperty(deviceHandle, "GainRaw", null);
            }

            string autoIdentifier = "GainAuto";

            p.AutomaticIdentifier = autoIdentifier;
            GenApiEnum auto = PylonHelper.ReadEnumCurrentValue(deviceHandle, p.AutomaticIdentifier);

            p.CanBeAutomatic = auto != null;
            p.Automatic      = false;
            if (p.CanBeAutomatic && !string.IsNullOrEmpty(auto.Symbol))
            {
                p.Automatic = auto.Symbol == GetAutoTrue(autoIdentifier);
            }

            properties.Add("gain", p);
        }
Exemplo n.º 7
0
        public static GenApiEnum ReadEnumCurrentValue(PYLON_DEVICE_HANDLE deviceHandle, string enumerationName)
        {
            GenApiEnum sf = null;

            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, enumerationName);

            if (!nodeHandle.IsValid)
            {
                return(null);
            }

            string selected = GenApi.NodeToString(nodeHandle);

            uint itemCount = GenApi.EnumerationGetNumEntries(nodeHandle);

            for (uint i = 0; i < itemCount; i++)
            {
                NODE_HANDLE entryHandle = GenApi.EnumerationGetEntryByIndex(nodeHandle, i);
                string      symbol      = GenApi.EnumerationEntryGetSymbolic(entryHandle);
                if (selected != symbol)
                {
                    continue;
                }

                if (!GenApi.NodeIsAvailable(entryHandle))
                {
                    continue;
                }

                string displayName = GenApi.NodeGetDisplayName(entryHandle);
                sf = new GenApiEnum(symbol, displayName);
                break;
            }

            return(sf);
        }
Exemplo n.º 8
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
            {
                deviceHandle = Pylon.CreateDeviceByIndex(deviceIndex);
                imageProvider.Open(deviceHandle);
            }
            catch (Exception e)
            {
                log.Error("Could not open Basler device.");
                LogError(e, imageProvider.GetLastErrorMessage());
                return;
            }

            if (!deviceHandle.IsValid)
            {
                return;
            }

            SpecificInfo specific = summary.Specific as SpecificInfo;

            if (specific == null)
            {
                return;
            }

            // Store the handle into the specific info so that we can retrieve device informations from the configuration dialog.
            specific.Handle = deviceHandle;

            GenApiEnum currentStreamFormat = PylonHelper.ReadEnumCurrentValue(deviceHandle, "PixelFormat");

            // Some properties can only be changed when the camera is opened but not streaming.
            // 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)
            {
                if (specific.StreamFormat != currentStreamFormat.Symbol)
                {
                    PylonHelper.WriteEnum(deviceHandle, "PixelFormat", specific.StreamFormat);
                }

                if (specific.CameraProperties != null && specific.CameraProperties.ContainsKey("framerate"))
                {
                    if (specific.CameraProperties.ContainsKey("enableFramerate") && specific.CameraProperties["enableFramerate"].Supported)
                    {
                        bool enabled = bool.Parse(specific.CameraProperties["enableFramerate"].CurrentValue);
                        if (!enabled && !specific.CameraProperties["enableFramerate"].ReadOnly)
                        {
                            specific.CameraProperties["enableFramerate"].CurrentValue = "true";
                            CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["enableFramerate"]);
                        }
                    }

                    CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["framerate"]);
                }

                if (specific.CameraProperties != null && specific.CameraProperties.ContainsKey("width") && specific.CameraProperties.ContainsKey("height"))
                {
                    CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["width"]);
                    CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["height"]);
                }
            }
            else
            {
                specific.StreamFormat = currentStreamFormat.Symbol;
            }
        }