示例#1
0
        /* Handles the selection of cameras from the list box. The currently open device is closed and the first
         * selected device is opened. */
        private void deviceListView_SelectedIndexChanged(object sender, EventArgs ev)
        {
            /* Close the currently open image provider. */
            /* Stops the grabbing of images. */
            Stop();
            /* Close the image provider. */
            CloseTheImageProvider();

            /* Open the selected image provider. */
            if (deviceListView.SelectedItems.Count > 0)
            {
                /* Get the first selected item. */
                ListViewItem item = deviceListView.SelectedItems[0];
                /* Get the attached device data. */
                DeviceEnumerator.Device device = item.Tag as DeviceEnumerator.Device;
                try
                {
                    /* Open the image provider using the index from the device data. */
                    m_imageProvider.Open(device.Index);
                }
                catch (Exception e)
                {
                    ShowException(e, m_imageProvider.GetLastErrorMessage());
                }
            }
        }
示例#2
0
        public static Dictionary <string, CameraProperty> Read(PYLON_DEVICE_HANDLE deviceHandle, string fullName)
        {
            Dictionary <string, CameraProperty> properties = new Dictionary <string, CameraProperty>();

            // Enumerate devices again to make sure we have the correct device index and find the device class.
            DeviceEnumerator.Device        device  = null;
            List <DeviceEnumerator.Device> devices = DeviceEnumerator.EnumerateDevices();

            foreach (DeviceEnumerator.Device candidate in devices)
            {
                if (candidate.FullName != fullName)
                {
                    continue;
                }

                device = candidate;
                break;
            }

            if (device == null)
            {
                return(properties);
            }

            string deviceClass = "BaslerGigE";

            try
            {
                deviceClass = Pylon.DeviceInfoGetPropertyValueByName(device.DeviceInfoHandle, Pylon.cPylonDeviceInfoDeviceClassKey);
            }
            catch
            {
                log.ErrorFormat("Could not read Basler device class. Assuming BaslerGigE.");
            }

            properties.Add("width", ReadIntegerProperty(deviceHandle, "Width"));
            properties.Add("height", ReadIntegerProperty(deviceHandle, "Height"));
            properties.Add("enableFramerate", ReadBooleanProperty(deviceHandle, "AcquisitionFrameRateEnable"));

            if (deviceClass == "BaslerUsb")
            {
                properties.Add("framerate", ReadFloatProperty(deviceHandle, "AcquisitionFrameRate"));
                properties.Add("exposure", ReadFloatProperty(deviceHandle, "ExposureTime"));
                properties.Add("gain", ReadFloatProperty(deviceHandle, "Gain"));
            }
            else
            {
                properties.Add("framerate", ReadFloatProperty(deviceHandle, "AcquisitionFrameRateAbs"));
                properties.Add("exposure", ReadFloatProperty(deviceHandle, "ExposureTimeAbs"));
                properties.Add("gain", ReadIntegerProperty(deviceHandle, "GainRaw"));
            }

            return(properties);
        }
示例#3
0
        public static Dictionary <string, CameraProperty> Read(PYLON_DEVICE_HANDLE deviceHandle, string fullName)
        {
            Dictionary <string, CameraProperty> properties = new Dictionary <string, CameraProperty>();

            // Enumerate devices again to make sure we have the correct device index and find the device class.
            DeviceEnumerator.Device        device  = null;
            List <DeviceEnumerator.Device> devices = DeviceEnumerator.EnumerateDevices();

            foreach (DeviceEnumerator.Device candidate in devices)
            {
                if (candidate.FullName != fullName)
                {
                    continue;
                }

                device = candidate;
                break;
            }

            if (device == null)
            {
                return(properties);
            }

            string deviceClass = "BaslerGigE";

            try
            {
                deviceClass = Pylon.DeviceInfoGetPropertyValueByName(device.DeviceInfoHandle, Pylon.cPylonDeviceInfoDeviceClassKey);
            }
            catch
            {
                log.ErrorFormat("Could not read Basler device class. Assuming BaslerGigE.");
            }

            properties.Add("width", ReadIntegerProperty(deviceHandle, "Width"));
            properties.Add("height", ReadIntegerProperty(deviceHandle, "Height"));

            // Camera properties in Kinovea combine the value and the "auto" flag.
            // We potentially need to read several Basler camera properties to create one Kinovea camera property.
            // Furthermore, some properties name or type depends on whether the camera is USB or GigE.
            ReadFramerate(deviceHandle, deviceClass, properties);
            ReadExposure(deviceHandle, deviceClass, properties);
            ReadGain(deviceHandle, deviceClass, properties);

            return(properties);
        }
示例#4
0
        /// <summary>
        /// Instantiates a Bifler Camera.
        /// </summary>
        /// <param name="deviceInfo">Basler Camera device information.</param>
        /// <param name="projectMngr">Project manager which has information about projects.</param>
        public Camera(DeviceEnumerator.Device deviceInfo, ProjectManager projectMngr)
        {
            Index = deviceInfo.Index;

            SaveIndex = (int)Index + 1;

            FullName = deviceInfo.FullName;

            Name = deviceInfo.Name;

            Tooltip = deviceInfo.Tooltip;

            project = projectMngr;

            _triggeredCounter = _savedIndex = 0;

            /*_buffer = new Bitmap [bufferSize];
             * _bufferIndex = 0;*/
        }
示例#5
0
        public static Dictionary <string, CameraProperty> Read(PYLON_DEVICE_HANDLE deviceHandle, string fullName)
        {
            Dictionary <string, CameraProperty> properties = new Dictionary <string, CameraProperty>();

            // Enumerate devices again to make sure we have the correct device index and find the device class.
            DeviceEnumerator.Device        device  = null;
            List <DeviceEnumerator.Device> devices = DeviceEnumerator.EnumerateDevices();

            foreach (DeviceEnumerator.Device candidate in devices)
            {
                if (candidate.FullName != fullName)
                {
                    continue;
                }

                device = candidate;
                break;
            }

            if (device == null)
            {
                return(properties);
            }

            try
            {
                properties.Add("width", ReadIntegerProperty(deviceHandle, "Width", "WidthMax"));
                properties.Add("height", ReadIntegerProperty(deviceHandle, "Height", "HeightMax"));

                // Camera properties in Kinovea combine the value and the "auto" flag.
                // We potentially need to read several Basler camera properties to create one Kinovea camera property.
                ReadFramerate(deviceHandle, properties);
                ReadExposure(deviceHandle, properties);
                ReadGain(deviceHandle, properties);
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while reading Basler camera properties. {0}.", e.Message);
            }


            return(properties);
        }
示例#6
0
        /* Handles the selection of cameras from the list box. The currently open device is closed and the first
         * selected device is opened. */
        private void deviceListView_SelectedIndexChanged(object sender, EventArgs ev)
        {
            /* Close the currently open image provider. */
            /* Stops the grabbing of images. */
            Stop();
            /* Close the image provider. */
            CloseTheImageProvider();


            /* Open the selected image provider. */
            if (deviceListView.SelectedItems.Count > 0)
            {
                /* Get the first selected item. */
                ListViewItem item = deviceListView.SelectedItems[0];
                /* Get the attached device data. */
                DeviceEnumerator.Device device = (DeviceEnumerator.Device)item.Tag;
                try
                {
                    /* Open the image provider using the index from the device data. */
                    m_imageProvider.Open(device.Index);
                    m_imageProvider.GetNodeFromDevice(device.Name);
                    hDev = Pylon.CreateDeviceByIndex(device.Index);
                }
                catch (Exception e)
                {
                    ShowException(e, m_imageProvider.GetLastErrorMessage());
                }
            }
            //          Console.WriteLine(m_imageProvider.get_integerParam("Width").ToString());

//            hDev = new PYLON_DEVICE_HANDLE();
//          Pylon.Initialize();

            /* Enumerate all camera devices. You must call
             * PylonEnumerateDevices() before creating a device. */

/*            if (0 == Pylon.EnumerateDevices())
 *          {
 *              throw new Exception("No devices found.");
 *          }
 */
        }
示例#7
0
        /* Updates the list of available devices in the upper left area. */
        private void UpdateDeviceList()
        {
            try
            {
                /* Ask the device enumerator for a list of devices. */
                List <DeviceEnumerator.Device> list = DeviceEnumerator.EnumerateDevices();

                ListView.ListViewItemCollection items = deviceListView.Items;

                /* Add each new device to the list. */
                foreach (DeviceEnumerator.Device device in list)
                {
                    bool newitem = true;
                    /* For each enumerated device check whether it is in the list view. */
                    foreach (ListViewItem item in items)
                    {
                        /* Retrieve the device data from the list view item. */
                        DeviceEnumerator.Device tag = item.Tag as DeviceEnumerator.Device;

                        if (tag.FullName == device.FullName)
                        {
                            /* Update the device index. The index is used for opening the camera. It may change when enumerating devices. */
                            tag.Index = device.Index;
                            /* No new item needs to be added to the list view */
                            newitem = false;
                            break;
                        }
                    }

                    /* If the device is not in the list view yet the add it to the list view. */
                    if (newitem)
                    {
                        ListViewItem item = new ListViewItem(device.Name);
                        if (device.Tooltip.Length > 0)
                        {
                            item.ToolTipText = device.Tooltip;
                        }
                        item.Tag = device;

                        /* Attach the device data. */
                        deviceListView.Items.Add(item);
                    }
                }

                /* Delete old devices which are removed. */
                foreach (ListViewItem item in items)
                {
                    bool exists = false;

                    /* For each device in the list view check whether it has not been found by device enumeration. */
                    foreach (DeviceEnumerator.Device device in list)
                    {
                        if (((DeviceEnumerator.Device)item.Tag).FullName == device.FullName)
                        {
                            exists = true;
                            break;
                        }
                    }
                    /* If the device has not been found by enumeration then remove from the list view. */
                    if (!exists)
                    {
                        deviceListView.Items.Remove(item);
                    }
                }
            }
            catch (Exception e)
            {
                ShowException(e, m_imageProvider.GetLastErrorMessage());
            }
        }