Exemple #1
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 (!camera.IsOpened)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen = false;

            ImageFormat format = IDSHelper.GetImageFormat(camera);

            // FIXME: Force a supported format if the current one is unsuitable.
            if (format == ImageFormat.None)
            {
                return(ImageDescriptor.Invalid);
            }

            // FIXME: RGB24 should allocate buffers aligned to 4 bytes.
            // It is usually the case because none of the UI let the user choose a non aligned width.
            Rectangle rect;

            camera.Size.AOI.Get(out rect);
            incomingBufferSize = ImageFormatHelper.ComputeBufferSize(rect.Width, rect.Height, format);
            incomingBuffer     = new byte[incomingBufferSize];

            resultingFramerate = IDSHelper.GetFramerate(camera);
            int width  = rect.Width;
            int height = rect.Height;

            finishline.Prepare(width, height, format, resultingFramerate);
            if (finishline.Enabled)
            {
                height             = finishline.Height;
                resultingFramerate = finishline.ResultingFramerate;
            }

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

            resultingFramerate = IDSHelper.GetFramerate(camera);

            return(new ImageDescriptor(format, width, height, topDown, outgoingBufferSize));
        }
Exemple #2
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 (deviceHandle == null || !deviceHandle.IsValid)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen = false;

            // Get the configured framerate for recording support.
            resultingFramerate = PylonHelper.GetResultingFramerate(deviceHandle);

            SpecificInfo specific           = summary.Specific as SpecificInfo;
            string       streamFormatSymbol = specific.StreamFormat;

            bool hasWidth                  = Pylon.DeviceFeatureIsReadable(deviceHandle, "Width");
            bool hasHeight                 = Pylon.DeviceFeatureIsReadable(deviceHandle, "Height");
            bool hasPixelFormat            = Pylon.DeviceFeatureIsReadable(deviceHandle, "PixelFormat");
            bool canComputeImageDescriptor = hasWidth && hasHeight && hasPixelFormat;

            if (!canComputeImageDescriptor)
            {
                return(ImageDescriptor.Invalid);
            }

            int    width       = (int)Pylon.DeviceGetIntegerFeature(deviceHandle, "Width");
            int    height      = (int)Pylon.DeviceGetIntegerFeature(deviceHandle, "Height");
            string pixelFormat = Pylon.DeviceFeatureToString(deviceHandle, "PixelFormat");

            EPylonPixelType pixelType = Pylon.PixelTypeFromString(pixelFormat);

            if (pixelType == EPylonPixelType.PixelType_Undefined)
            {
                return(ImageDescriptor.Invalid);
            }

            // Note: the image provider will perform the Bayer conversion itself and only output two formats.
            // - Y800 for anything monochrome.
            // - RGB32 for anything color.
            imageProvider.SetDebayering(specific.Bayer8Conversion);

            bool        isBayer    = Pylon.IsBayer(pixelType);
            bool        isBayer8   = PylonHelper.IsBayer8(pixelType);
            bool        bayerColor = (isBayer && !isBayer8) || (isBayer8 && specific.Bayer8Conversion == Bayer8Conversion.Color);
            bool        color      = !Pylon.IsMono(pixelType) || bayerColor;
            ImageFormat format     = color ? ImageFormat.RGB32 : ImageFormat.Y800;

            finishline.Prepare(width, height, format, resultingFramerate);
            if (finishline.Enabled)
            {
                height             = finishline.Height;
                resultingFramerate = finishline.ResultingFramerate;
            }

            int  bufferSize = ImageFormatHelper.ComputeBufferSize(width, height, format);
            bool topDown    = true;

            return(new ImageDescriptor(format, width, height, topDown, bufferSize));
        }
Exemple #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 (!baumerProvider.IsOpen)
            {
                return(ImageDescriptor.Invalid);
            }

            firstOpen = false;
            Device device = baumerProvider.Device;

            // Get the configured framerate for recording support.
            resultingFramerate = BaumerHelper.GetResultingFramerate(device);

            bool hasWidth                  = BaumerHelper.NodeIsReadable(device, "Width");
            bool hasHeight                 = BaumerHelper.NodeIsReadable(device, "Height");
            bool hasPixelFormat            = BaumerHelper.NodeIsReadable(device, "PixelFormat");
            bool canComputeImageDescriptor = hasWidth && hasHeight && hasPixelFormat;

            if (!canComputeImageDescriptor)
            {
                return(ImageDescriptor.Invalid);
            }

            int    width       = BaumerHelper.GetInteger(device, "Width");
            int    height      = BaumerHelper.GetInteger(device, "Height");
            string pixelFormat = BaumerHelper.GetString(device, "PixelFormat");

            // We output in three possible formats: Y800, RGB24 or JPEG.
            // The output format depends on the stream format and the options.
            // Mono or raw -> Y800, Otherwise -> RGB24.

            // Camera-side JPEG compression.
            compression = specific.Compression;
            if (BaumerHelper.SupportsJPEG(device))
            {
                if (BaumerHelper.FormatCanCompress(device, pixelFormat))
                {
                    BaumerHelper.SetJPEG(device, compression);
                }
                else
                {
                    BaumerHelper.SetJPEG(device, false);
                    compression = false;
                }
            }
            else
            {
                compression = false;
            }

            // Debayering.
            demosaicing = specific.Demosaicing;
            if (demosaicing)
            {
                if (imgProcessor.NodeList.GetNodePresent("DemosaicingMethod"))
                {
                    // Options: NearestNeighbor, Bilinear3x3, Baumer5x5
                    imgProcessor.NodeList["DemosaicingMethod"].Value = "NearestNeighbor";
                }
                else
                {
                    demosaicing = false;
                }
            }

            imageFormat     = BaumerHelper.ConvertImageFormat(pixelFormat, compression, demosaicing);
            frameBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, imageFormat);
            frameBuffer     = new byte[frameBufferSize];

            finishline.Prepare(width, height, imageFormat, resultingFramerate);
            if (finishline.Enabled)
            {
                height             = finishline.Height;
                resultingFramerate = finishline.ResultingFramerate;
            }

            int  outgoingBufferSize = ImageFormatHelper.ComputeBufferSize(width, height, imageFormat);
            bool topDown            = true;

            return(new ImageDescriptor(imageFormat, width, height, topDown, outgoingBufferSize));
        }