コード例 #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()
        {
            ConfigureDevice();

            AForge.Video.DirectShow.VideoCapabilities cap = null;
            if (device.VideoResolution == null)
            {
                // This device was never connected to in Kinovea, use the first media type.
                AForge.Video.DirectShow.VideoCapabilities[] caps = device.VideoCapabilities;
                if (caps.Length == 0)
                {
                    log.ErrorFormat("Cannot get any media type for the device.");
                    return(ImageDescriptor.Invalid);
                }

                cap = caps[0];

                device.SetMediaTypeAndFramerate(cap.Index, (float)cap.AverageFrameRate);
                log.DebugFormat("Device set to default configuration: Index:{0}. ({1}x{2} @ {3:0.###} fps ({4})).",
                                cap.Index, cap.FrameSize.Width, cap.FrameSize.Height, cap.AverageFrameRate, cap.Compression);
            }
            else
            {
                cap = device.VideoResolution;
            }

            int width  = cap.FrameSize.Width;
            int height = cap.FrameSize.Height;

            resultingFramerate = cap.AverageFrameRate;

            ImageFormat format = ImageFormat.RGB24;

            switch (cap.Compression)
            {
            case "RGB24":
            default:
                format = ImageFormat.RGB24;
                break;

            case "MJPG":
                format = ImageFormat.JPEG;
                break;
            }

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

            return(new ImageDescriptor(format, width, height, topDown, bufferSize));
        }
コード例 #2
0
        /// <summary>
        /// Configure the device according to what is saved in the preferences for it.
        /// </summary>
        private void ConfigureDevice()
        {
            SpecificInfo info = summary.Specific as SpecificInfo;

            if (info == null || info.MediaTypeIndex < 0)
            {
                log.DebugFormat("The device has never been configured in Kinovea.");
                return;
            }

            // Initialize device configuration (Extract and cache media types on the output pin).
            // Double check we have an existing index and set the format.
            AForge.Video.DirectShow.VideoCapabilities[] capabilities = device.VideoCapabilities;
            AForge.Video.DirectShow.VideoCapabilities   match        = capabilities.FirstOrDefault(c => c.Index == info.MediaTypeIndex);
            if (match == null)
            {
                log.ErrorFormat("Could not match the saved media type.");
                return;
            }

            device.SetMediaTypeAndFramerate(info.MediaTypeIndex, info.SelectedFramerate);

            log.DebugFormat("Device set to saved configuration: Index:{0}. ({1}×{2} @ {3:0.###} fps ({4})).",
                            info.MediaTypeIndex, match.FrameSize.Width, match.FrameSize.Height, info.SelectedFramerate, match.Compression);

            // Reload camera properties in case the firmware "forgot" them.
            // This means changes done in other softwares will be overwritten.
            try
            {
                CameraPropertyManager.Write(device, info.CameraProperties);
            }
            catch
            {
                log.ErrorFormat("An error occured while reloading camera properties.");
            }
        }