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
        private void UpdateImageData(IBaseData objIBaseData)
        {
            try
            {
                GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                if (null != objIBaseData)
                {
                    emValidBits = DahengHelper.GetBestValidBit(objIBaseData.GetPixelFormat());
                    if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                    {
                        if (isColor)
                        {
                            IntPtr buffer = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, true);
                            FillRGB24(buffer);
                        }
                        else
                        {
                            IntPtr buffer = objIBaseData.GetBuffer();
                            FillY800(buffer);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            waitHandle.Set();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configure device and report frame format that will be used during streaming.
        /// This method must return a proper ImageDescriptor so we can pre-allocate buffers.
        /// </summary>
        public ImageDescriptor Prepare()
        {
            Open();

            if (device == null || featureControl == null)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen          = false;
            resultingFramerate = (float)DahengHelper.GetResultingFramerate(device);

            width   = (int)featureControl.GetIntFeature("Width").GetValue();
            height  = (int)featureControl.GetIntFeature("Height").GetValue();
            isColor = DahengHelper.IsColor(featureControl);

            ImageFormat format = ImageFormat.RGB24;

            incomingBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, format);
            incomingBuffer     = new byte[incomingBufferSize];

            int  outgoingBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, format);
            bool topDown            = false;

            return(new ImageDescriptor(format, width, height, topDown, outgoingBufferSize));
        }
Exemplo n.º 4
0
        private void UpdateResultingFramerate()
        {
            float resultingFramerate = (float)DahengHelper.GetResultingFramerate(device);

            if (resultingFramerate == 0)
            {
                lblResultingFramerate.Visible      = false;
                lblResultingFramerateValue.Visible = false;
                return;
            }

            lblResultingFramerateValue.Text = string.Format("{0:0.##}", resultingFramerate);

            bool discrepancy = false;

            if (cameraProperties.ContainsKey("AcquisitionFrameRate") && cameraProperties["AcquisitionFrameRate"].Supported)
            {
                float framerate;
                bool  parsed = float.TryParse(cameraProperties["AcquisitionFrameRate"].CurrentValue, NumberStyles.Any, CultureInfo.InvariantCulture, out framerate);
                if (parsed && Math.Abs(framerate - resultingFramerate) > 1)
                {
                    discrepancy = true;
                }
            }

            lblResultingFramerateValue.ForeColor = discrepancy ? Color.Red : Color.Black;
        }
Exemplo n.º 5
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.º 6
0
        public SnapshotRetriever(CameraSummary summary, IGXFactory igxFactory)
        {
            this.summary = summary;

            try
            {
                stopwatch.Start();
                device = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                log.DebugFormat("{0} opened in {1} ms.", summary.Alias, stopwatch.ElapsedMilliseconds);
                stopwatch.Stop();

                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);

                width   = (int)featureControl.GetIntFeature("Width").GetValue();
                height  = (int)featureControl.GetIntFeature("Height").GetValue();
                isColor = DahengHelper.IsColor(featureControl);

                stream = device.OpenStream(0);
            }
            catch (Exception e)
            {
                LogError(e, "Failed to open device");
            }
        }
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 void UpdateImageData(IBaseData objIBaseData)
        {
            try
            {
                GX_VALID_BIT_LIST emValidBits = GX_VALID_BIT_LIST.GX_BIT_0_7;
                if (null != objIBaseData)
                {
                    emValidBits = DahengHelper.GetBestValidBit(objIBaseData.GetPixelFormat());
                    if (GX_FRAME_STATUS_LIST.GX_FRAME_STATUS_SUCCESS == objIBaseData.GetStatus())
                    {
                        if (isColor)
                        {
                            if (currentStreamFormat == DahengStreamFormat.RGB)
                            {
                                IntPtr buffer = objIBaseData.ConvertToRGB24(emValidBits, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, true);
                                FillRGB24(buffer);
                            }
                            else if (currentStreamFormat == DahengStreamFormat.Raw)
                            {
                                IntPtr bufferRaw = objIBaseData.ConvertToRaw8(emValidBits);
                                FillY800(bufferRaw);
                            }
                        }
                        else
                        {
                            IntPtr buffer = objIBaseData.GetBuffer();
                            FillY800(buffer);

                            //IntPtr pBufferMono = IntPtr.Zero;
                            //if (IsPixelFormat8(objIBaseData.GetPixelFormat()))
                            //{
                            //    pBufferMono = objIBaseData.GetBuffer();
                            //}
                            //else
                            //{
                            //    pBufferMono = objIBaseData.ConvertToRaw8(emValidBits);
                            //}

                            //Marshal.Copy(pBufferMono, m_byMonoBuffer, 0, width * height);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 9
0
        public SnapshotRetriever(CameraSummary summary, IGXFactory igxFactory)
        {
            this.summary = summary;

            try
            {
                device         = igxFactory.OpenDeviceBySN(summary.Identifier, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                featureControl = device.GetRemoteFeatureControl();
                DahengHelper.AfterOpen(featureControl);

                width   = (int)featureControl.GetIntFeature("Width").GetValue();
                height  = (int)featureControl.GetIntFeature("Height").GetValue();
                isColor = DahengHelper.IsColor(featureControl);

                stream = device.OpenStream(0);
            }
            catch (Exception e)
            {
                LogError(e, "Failed to open device");
            }
        }
Exemplo n.º 10
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.");
            }
        }