コード例 #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 (!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));
        }
コード例 #2
0
 private void SetExtraOptionsVisibility()
 {
     cbDebayering.Enabled  = BaumerHelper.IsBayer(selectedStreamFormat);
     cbCompression.Enabled = BaumerHelper.SupportsJPEG(device) && BaumerHelper.FormatCanCompress(device, selectedStreamFormat);
 }