Esempio n. 1
0
        private void CameraInit(int cameraIndex)
        {
            var camera = _cameras[cameraIndex];

            _capture      = new Capture(cameraIndex);
            _cameraDevice = cameraIndex;

            var w = _capture.GetCaptureProperty(CapProp.FrameWidth);
            var h = _capture.GetCaptureProperty(CapProp.FrameHeight);

            var currentResolution = w + "x" + h;

            var resolutions = VideoDeviceManager.GetAllAvailableResolution(camera).OrderByDescending(x => x.Width).ThenByDescending(x => x.Height).ToList();

            resolutionsList.Items.Clear();
            var strings = resolutions.Select(x => x.Width + "x" + x.Height).Distinct().ToList();
            var index   = -1;

            for (int i = 0; i < strings.Count; i++)
            {
                resolutionsList.Items.Add(strings[i]);
                if (strings[i].Equals(currentResolution))
                {
                    index = i;
                }
            }
            resolutionsList.SelectedIndex = index;
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            panel1.Anchor = AnchorStyles.Right;
            _cameras      = VideoDeviceManager.GetVideoDevices();
            _webCams      = new VideoDevice[_cameras.Length];
            for (int i = 0; i < _cameras.Length; i++)
            {
                _webCams[i] = new VideoDevice(i, _cameras[i].Name, _cameras[i].ClassID); //fill web cam array
                camerasList.Items.Add(_webCams[i].ToString());
            }
            if (camerasList.Items.Count > 0)
            {
                camerasList.SelectedIndex = 0; //Set the selected device the default
            }

            LoadSettings();

            _microsoftCognitiveService = new MicrosoftCognitiveService(_settings.OcpApiSubscriptionKey, _settings.FaceApiSubscriptionKey);

            string appDataPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\App_Data\"));

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataPath);
            _userService = new UserService();
            _userService.Test();
            CameraInit(0);

            this.WindowState     = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.Sizable;
            // panel1.Top = 0;
            panel1.Left           = ClientSize.Width - panel1.Width - 10;
            cameraPictureBox.Top  = 10;
            cameraPictureBox.Left = 10;
            comboBoxDetectorMode.SelectedIndex = _settings.DetectionMode - 1;

            Application.Idle += ShowCameraScreen;
        }