Exemplo n.º 1
0
        public bool Select(SWebcamConfig config)
        {
            //Close old camera connection
            DeSelect();

            if (_Devices.Count < 1)
            {
                return(false);
            }

            string moniker = _Devices[0].MonikerString;

            if (config.MonikerString != "")
            {
                foreach (SWebcamDevice device in _Devices)
                {
                    if (device.MonikerString == config.MonikerString)
                    {
                        moniker = device.MonikerString;
                        break;
                    }
                }
            }
            _Webcam = new VideoCaptureDevice(moniker);

            _Webcam.VideoResolution = _SelectWebcamConfig(_Webcam.VideoCapabilities, config);

            _Config.Framerate     = _Webcam.VideoResolution.AverageFrameRate;
            _Config.Height        = _Webcam.VideoResolution.FrameSize.Height;
            _Config.Width         = _Webcam.VideoResolution.FrameSize.Width;
            _Config.MonikerString = _Webcam.Source;

            return(true);
        }
Exemplo n.º 2
0
        public bool Select(SWebcamConfig Config)
        {
            //Close old camera connection
            Close();

            if (_WebcamDevices == null)
            {
                return(false);
            }
            if (_WebcamDevices.Count < 1)
            {
                return(false);
            }

            //No MonikerString found, try first webcam
            if (Config.MonikerString == String.Empty)
            {
                _Webcam = new VideoCaptureDevice(_WebcamDevices[0].MonikerString);
            }
            else //Found MonikerString
            {
                _Webcam = new VideoCaptureDevice(Config.MonikerString);
            }

            if (_Webcam == null)
            {
                return(false);
            }

            if (Config.Framerate != 0 && Config.Height != 0 && Config.Width != 0)
            {
                _Webcam.DesiredFrameRate = Config.Framerate;
                _Webcam.DesiredFrameSize = new Size(Config.Width, Config.Height);
            }

            _Config.Framerate     = _Webcam.DesiredFrameRate;
            _Config.Height        = _Webcam.DesiredFrameSize.Height;
            _Config.Width         = _Webcam.DesiredFrameSize.Width;
            _Config.MonikerString = _Webcam.Source;

            return(true);
        }
Exemplo n.º 3
0
        public bool Select(SWebcamConfig Config)
        {
            //Close old camera connection
            Close();

            if (_WebcamDevices == null)
                return false;
            if (_WebcamDevices.Count < 1)
                return false;

            //No MonikerString found, try first webcam
            if (Config.MonikerString == String.Empty)
                _Webcam = new VideoCaptureDevice(_WebcamDevices[0].MonikerString);
            else //Found MonikerString
                _Webcam = new VideoCaptureDevice(Config.MonikerString);

            if (_Webcam == null)
                return false;

            if (Config.Framerate != 0 && Config.Height != 0 && Config.Width != 0)
            {
                _Webcam.DesiredFrameRate = Config.Framerate;
                _Webcam.DesiredFrameSize = new Size(Config.Width, Config.Height);
            }

            _Config.Framerate = _Webcam.DesiredFrameRate;
            _Config.Height = _Webcam.DesiredFrameSize.Height;
            _Config.Width = _Webcam.DesiredFrameSize.Width;
            _Config.MonikerString = _Webcam.Source;

            return true;
        }
Exemplo n.º 4
0
 public static void Select(SWebcamConfig c)
 {
     _Webcam.Select(c);
 }
Exemplo n.º 5
0
        private static VideoCapabilities _SelectWebcamConfig(VideoCapabilities[] capabilities, SWebcamConfig config)
        {
            int configTaken = 0;

            if (config.Framerate != 0 && config.Height != 0 && config.Width != 0)
            {
                float bestMatchScore = 0;
                for (int i = 0; i < capabilities.Length; i++)
                {
                    float score = _GetScore(capabilities[i].AverageFrameRate, config.Framerate);
                    score += _GetScore(capabilities[i].FrameSize.Height, config.Height);
                    score += _GetScore(capabilities[i].FrameSize.Width, config.Width);
                    if (score >= bestMatchScore)
                    {
                        // Take the config with the best score, Higher indizes should indicate a better resolution
                        // so choose the last one with best score if 2 have equal scores
                        bestMatchScore = score;
                        configTaken    = i;
                    }
                }
            }

            return(capabilities[configTaken]);
        }