Ejemplo n.º 1
0
 public void GetMediaInputs <T>(ref List <T> medias)
 {
     if (typeof(T) == typeof(Camera))
     {
         medias = filterVedio.Cast <FilterInfo>()
                  .Select(s => new Camera
         {
             MonikerString = s.MonikerString,
             Name          = s.Name
         }).ToList() as List <T>;
     }
     else if (typeof(T) == typeof(Audio))
     {
         var audios = new List <Audio>();
         for (int i = 0; i < WaveIn.DeviceCount; i++)
         {
             var input = WaveIn.GetCapabilities(i);
             audios.Add(new Audio
             {
                 DevNumber     = i,
                 Name          = input.ProductName,
                 MonikerString = $"@device:cm:{{{input.ProductGuid}}}\\wave:{{{input.ManufacturerGuid}}}",
                 Channels      = input.Channels,
             });
         }
         medias = audios as List <T>;
     }
 }
Ejemplo n.º 2
0
        private bool StartCapture()
        {
            if (lbCameras.SelectedIndex < 0)
            {
                return(false);
            }
            var curSnap      = (CameraSnapshotDescriptor)lbCameras.SelectedItem;
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (videoDevices.Count == 0)
            {
                return(false);
            }
            var monikerStr = string.Empty;

            foreach (var dev in videoDevices.Cast <FilterInfo>().Where(dev => dev.Name == curSnap.cameraName))
            {
                monikerStr = dev.MonikerString;
                break;
            }
            if (string.IsNullOrEmpty(monikerStr))
            {
                return(false);
            }
            CloseVideoSource();
            videoSource                  = new VideoCaptureDevice(monikerStr);
            videoSource.NewFrame        += OnNewFrame;
            videoSource.DesiredFrameSize = curSnap.resolution;
            videoSource.Start();
            return(true);
        }
Ejemplo n.º 3
0
        public List <FilterInfo> RetrieveAvailableCameras()
        {
            //Retrieve all video capture devices
            FilterInfoCollection j      = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            List <FilterInfo>    result = j.Cast <FilterInfo>().ToList();

            return(result);
        }
Ejemplo n.º 4
0
        public async Task InitializeWebCam(List <Image> ListImageControl)
        {
            try
            {
                if (isVideoSourceInitialized)
                {
                    return;
                }

                var VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (VideoCaptureDevices.Count != 0)
                {
                    if (VideoCaptureDevices.Cast <FilterInfo>().Where(w => w.Name.ToLower() == "Microsoft LifeCam Studio".ToLower()).Any())
                    {
                        SelectedCamera = new VideoCaptureDevice(VideoCaptureDevices.Cast <FilterInfo>().Where(w => w.Name.ToLower() == "Microsoft LifeCam Studio".ToLower()).FirstOrDefault().MonikerString);
                    }
                    else
                    {
                        foreach (var item in VideoCaptureDevices)
                        {
                            if (((FilterInfo)item).Name.ToLower().Contains("Cogent Device".ToLower()))
                            {
                                continue;
                            }
                            SelectedCamera = new VideoCaptureDevice(((FilterInfo)item).MonikerString);
                            break;
                        }
                    }
                }
                else
                {
                    throw new ApplicationException("No se dectecto ningun dispositivo conectado");
                }

                if (SelectedCamera != null)
                {
                    await InitializeVideoDevice(SelectedCamera.Source);
                }
            }
            catch (Exception)
            {
                isVideoSourceInitialized = false;
            }
            ImageControls = ListImageControl;
        }
Ejemplo n.º 5
0
        public main()
        {
            InitializeComponent();

            List <FilterInfo> _oDevList = _videoDevices.Cast <FilterInfo>().ToList();

            cmbImagingDevices.DisplayMember = "Name";
            cmbImagingDevices.ValueMember   = "MonikerString";
            cmbImagingDevices.DataSource    = _oDevList;

            tvMenu.ExpandAll();
            this.CenterToScreen();
        }
Ejemplo n.º 6
0
        public List <string> SearchDevices()
        {
            _nameIdDictionary = new Dictionary <string, string>();

            FilterInfoCollection videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            for (int i = 0; i < videoCaptureDevices.Count; i++)
            {
                _nameIdDictionary.Add(videoCaptureDevices[i].Name, videoCaptureDevices[i].MonikerString);
            }

            return(videoCaptureDevices.Cast <FilterInfo>().Select(x => x.Name).ToList());
        }
Ejemplo n.º 7
0
        //-----------------public methods
        /// <summary>
        /// Charge la liste des WebCams connectés à l'ordinateur
        /// </summary>
        public void InitializeWebCamList()
        {
            SelectedDevice = null;
            Devices        = null;

            _videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (_videoDevices.Count == 0)
            {
                return;
            }

            Devices        = _videoDevices.Cast <FilterInfo>().ToList();
            SelectedDevice = Devices[0];
        }
Ejemplo n.º 8
0
        private bool StartCapture()
        {
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (videoDevices.Count == 0)
            {
                MessageBox.Show("Активные видеоустройства не найдены");
                return(false);
            }

            var camIndex = 0;

            foreach (var shot in snapshots)
            {
                var monikerStr = string.Empty;
                var camName    = shot.cameraName;
                foreach (var dev in videoDevices.Cast <FilterInfo>().Where(dev => dev.Name ==
                                                                           camName))
                {
                    monikerStr = dev.MonikerString;
                    break;
                }
                if (string.IsNullOrEmpty(monikerStr))
                {
                    CloseAllSources();
                    MessageBox.Show(string.Format("Видеоустройство \"{0}\" не найдено (возможно, отключено)",
                                                  camName));
                    return(false);
                }
                var videoSource = new VideoCaptureDevice(monikerStr);
                videoSource.NewFrame        += camEventHandlers[camIndex++];
                videoSource.DesiredFrameSize = shot.resolution;
                videoSource.Start();
                videoSources.Add(videoSource);
            }
            captureInProcess = true;
            return(true);
        }
Ejemplo n.º 9
0
 public IEnumerable <FilterInfo> GetAllDevices() => _videoDevices.Cast <FilterInfo>().ToList();
Ejemplo n.º 10
0
        /// <summary>
        /// 实始化摄像头集合
        /// </summary>
        /// <returns></returns>
        public List <string> Init()
        {
            var devs = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            return(devs.Cast <FilterInfo>().Select(a => a.Name).ToList());
        }
Ejemplo n.º 11
0
        private bool UpdateDevice()
        {
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            // update devices
            List <string> deviceName = videoDevices.Cast <FilterInfo>().Select(x => x.Name).ToList();

            EnumManager.UpdateEnum(enumDevice, FInDevice[0].Name, deviceName.Count > 0 ? deviceName.ToArray() : new string[] { "None" });

            List <string> videoFormatName = new List <string>();
            List <string> resolutionName  = new List <string>();
            List <string> framerateName   = new List <string>();

            bool valid = false;

            FilterInfo filterInfo = videoDevices.Cast <FilterInfo>().ToList().Find(x => x.Name.Equals(FInDevice[0].Name));

            if (filterInfo != null)
            {
                videoSource = new VideoCaptureDevice(filterInfo.MonikerString);

                // update formats
                videoFormatName = videoSource.VideoCapabilities.Select(x => x.MediaType).Distinct().ToList();
                //videoFormatName.Insert(0, "Default");

                List <VideoCapabilities> videoModeInfo = videoSource.VideoCapabilities.ToList().FindAll(y => y.MediaType.Equals(FInputs[0].IOObject[0].Name)).ToList();
                if (videoModeInfo.Count > 0)
                {
                    // update resolutions
                    List <KeyValuePair <Tuple <int, int>, string> > resolution = videoModeInfo.Select(x => new KeyValuePair <Tuple <int, int>, string>(new Tuple <int, int>(x.FrameSize.Width, x.FrameSize.Height), x.FrameSize.Width + "x" + x.FrameSize.Height)).ToList();
                    resolutionName = resolution.Distinct().OrderBy(x => x.Key).Reverse().ToList().Select(x => x.Value).ToList();
                    //resolutionName.Insert(0, "Default");

                    List <int> framerate = new List <int>();

                    videoModeInfo = videoModeInfo.FindAll(x => (x.FrameSize.Width + "x" + x.FrameSize.Height).Equals(FInputs[1].IOObject[0].Name));
                    if (videoModeInfo.Count > 0)
                    {
                        int res = 0;
                        int.TryParse(FInputs[2].IOObject[0].Name, out res);

                        videoModeInfo.ForEach(delegate(VideoCapabilities vcap)
                        {
                            // forming fps
                            int fps    = vcap.MinimumFrameRate;
                            int fpsMax = vcap.MaximumFrameRate;

                            while (fps <= fpsMax)                             // step by 5 fps
                            {
                                if (!framerate.Contains(fps))
                                {
                                    framerate.Add(fps);
                                }

                                if (fps == fpsMax)
                                {
                                    break;
                                }

                                if (fps % 5 != 0)
                                {
                                    fps = 5 * (int)Math.Ceiling(((double)fps) / 5.0);                                               // starting from 5
                                }
                                else
                                {
                                    fps += 5;
                                }

                                if (fps > fpsMax)
                                {
                                    fps = fpsMax;
                                }
                            }

                            if (framerate.Contains(res))
                            {
                                videoSource.VideoResolution = vcap;
                                videoSource.Framerate       = res;

                                valid = true;
                            }
                        });

                        framerate.Sort();
                        framerate.Reverse();

                        framerateName = framerate.ConvertAll(x => x.ToString()).ToList();
                        //framerateName.Insert(0, "Default");
                    }
                }
            }

            EnumManager.UpdateEnum(enumVideoFormat, FInputs[0].IOObject[0].Name, videoFormatName.Count > 0 ? videoFormatName.ToArray() : new string[] { "Default" });
            EnumManager.UpdateEnum(enumResolution, FInputs[1].IOObject[0].Name, resolutionName.Count > 0 ? resolutionName.ToArray() : new string[] { "Default" });
            EnumManager.UpdateEnum(enumFramerate, FInputs[2].IOObject[0].Name, framerateName.Count > 0 ? framerateName.ToArray() : new string[] { "Default" });

            return(valid);
        }
Ejemplo n.º 12
0
 private void _webcam_DevicesUpdated(FilterInfoCollection obj)
 {
     Cameras = obj.Cast <FilterInfo>().Select(d => d.Name);
 }
Ejemplo n.º 13
0
        private bool UpdateDevice()
        {
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            // update devices
            List<string> deviceName = videoDevices.Cast<FilterInfo>().Select(x => x.Name).ToList();
            EnumManager.UpdateEnum(enumDevice, FInDevice[0].Name, deviceName.Count > 0 ? deviceName.ToArray() : new string[] { "None" });

            List<string> videoFormatName = new List<string>();
            List<string> resolutionName = new List<string>();
            List<string> framerateName = new List<string>();

            bool valid = false;

            FilterInfo filterInfo = videoDevices.Cast<FilterInfo>().ToList().Find(x => x.Name.Equals(FInDevice[0].Name));
            if (filterInfo != null)
            {
                videoSource = new VideoCaptureDevice(filterInfo.MonikerString);

                // update formats
                videoFormatName = videoSource.VideoCapabilities.Select(x=>x.MediaType).Distinct().ToList();
                //videoFormatName.Insert(0, "Default");

                List<VideoCapabilities> videoModeInfo = videoSource.VideoCapabilities.ToList().FindAll(y => y.MediaType.Equals(FInputs[0].IOObject[0].Name)).ToList();
                if (videoModeInfo.Count > 0)
                {
                    // update resolutions
                    List<KeyValuePair<Tuple<int, int>, string>> resolution = videoModeInfo.Select(x => new KeyValuePair<Tuple<int, int>, string>(new Tuple<int, int>(x.FrameSize.Width, x.FrameSize.Height), x.FrameSize.Width + "x" + x.FrameSize.Height)).ToList();
                    resolutionName = resolution.Distinct().OrderBy(x => x.Key).Reverse().ToList().Select(x => x.Value).ToList();
                    //resolutionName.Insert(0, "Default");

                    List<int> framerate = new List<int>();

                    videoModeInfo = videoModeInfo.FindAll(x => (x.FrameSize.Width + "x" + x.FrameSize.Height).Equals(FInputs[1].IOObject[0].Name));
                    if (videoModeInfo.Count > 0)
                    {
                        int res = 0;
                        int.TryParse(FInputs[2].IOObject[0].Name, out res);

                        videoModeInfo.ForEach(delegate(VideoCapabilities vcap)
                        {
                            // forming fps
                            int fps = vcap.MinimumFrameRate;
                            int fpsMax = vcap.MaximumFrameRate;

                            while (fps <= fpsMax) // step by 5 fps
                            {
                                if(!framerate.Contains(fps)) framerate.Add(fps);

                                if (fps == fpsMax) break;

                                if (fps % 5 != 0) fps = 5 * (int)Math.Ceiling(((double)fps) / 5.0); // starting from 5
                                else fps += 5;

                                if (fps > fpsMax) fps = fpsMax;
                            }

                            if (framerate.Contains(res))
                            {
                                videoSource.VideoResolution = vcap;
                                videoSource.Framerate = res;

                                valid  = true;
                            }
                        });

                        framerate.Sort();
                        framerate.Reverse();

                        framerateName = framerate.ConvertAll(x => x.ToString()).ToList();
                        //framerateName.Insert(0, "Default");
                    }
                }
            }

            EnumManager.UpdateEnum(enumVideoFormat, FInputs[0].IOObject[0].Name, videoFormatName.Count > 0 ? videoFormatName.ToArray() : new string[] { "Default" });
            EnumManager.UpdateEnum(enumResolution, FInputs[1].IOObject[0].Name, resolutionName.Count > 0 ? resolutionName.ToArray() : new string[] { "Default" });
            EnumManager.UpdateEnum(enumFramerate, FInputs[2].IOObject[0].Name, framerateName.Count > 0 ? framerateName.ToArray() : new string[] { "Default" });

            return valid;
        }