Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "Start")
            {
                //MessageBox.Show(_videoDevices[0].ToString());
                //Console.WriteLine(_videoDevices[0].ToString());
                _videoSource.VideoResolution = videoCapabilities[comboBox1.SelectedIndex];
                //_videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);



                _videoSource.GetCameraProperty(CameraControlProperty.Zoom, out int zoom, out CameraControlFlags controlFlags);
                _videoSource.GetCameraProperty(CameraControlProperty.Exposure, out int exposure, out CameraControlFlags controlFlags2);
                _videoSource.GetCameraProperty(CameraControlProperty.Focus, out int focus, out CameraControlFlags controlFlags3);
                _videoSource.GetCameraProperty(CameraControlProperty.Iris, out int iris, out CameraControlFlags controlFlags4);
                _videoSource.GetCameraProperty(CameraControlProperty.Roll, out int roll, out CameraControlFlags controlFlags5);

                //_videoSource.Start();
                modifiedVideoSourcePlayer1.VideoSource = _videoSource;
                modifiedVideoSourcePlayer1.Start();
                sendImageToAWS();

                button1.Text = "Stop";
            }
            else
            {
                _videoSource.SignalToStop();
                sendImageToAWS();
                button1.Text = "Start";
            }
        }
        /// <summary>
        /// 输出所有设备信息
        /// </summary>
        public static void OutputCaptureDeviceInfo()
        {
            foreach (FilterInfo info in new FilterInfoCollection(FilterCategory.VideoInputDevice))
            {
                String format = $"CaptureDevice Name:[{info.Name}]  MonikerString:[{info.MonikerString}]";

                VideoCaptureDevice device = new VideoCaptureDevice(info.MonikerString);

                format += $"\nVideoCapabilities FrameSize: ";
                foreach (VideoCapabilities cap in device.VideoCapabilities)
                {
                    format += $"{cap.FrameSize}  ";
                }

                format += $"\nSnapshotCapabilities FrameSize: ";
                foreach (VideoCapabilities cap in device.SnapshotCapabilities)
                {
                    format += $"{cap.FrameSize}  ";
                }

                format += $"\nCamera Control Properties:";
                for (CameraControlProperty pro = CameraControlProperty.Pan; pro <= CameraControlProperty.Focus; pro++)
                {
                    if (device.GetCameraProperty(pro, out int value, out CameraControlFlags flags))
                    {
                        if (device.GetCameraPropertyRange(pro, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags rFlags))
                        {
                            format += $"(CameraControlFlags.{pro}({(int)pro}) value:{value} minValue:{minValue} maxValue:{maxValue} stepSize:{stepSize} defaultValue:{defaultValue} flags:[{flags}] cFlags:[{rFlags}])  ";
                        }
Example #3
0
            }             // func TryGetPropertyRange

            public bool TryGetProperty(VideoCaptureDevice device, out int value, out bool isAuto)
            {
                if (device.GetCameraProperty(property, out var curValue, out var curFlags))
                {
                    value  = curValue;
                    isAuto = curFlags == CameraControlFlags.Auto;
                    return(true);
                }
Example #4
0
        private bool move(int howMuch)
        {
            int curP;

            theDevice.GetCameraProperty(camProp, out curP, out camFlags);
            curP += howMuch;
            bool retVal = theDevice.SetCameraProperty(camProp, curP, camFlags);

            return(retVal);
        }
Example #5
0
        private void GetExposureSetting()
        {
            int exposure;
            CameraControlFlags exposureFlag;

            videoSource.GetCameraProperty(CameraControlProperty.Exposure,
                                          out exposure,
                                          out exposureFlag);
            VideoProperties.Exposure     = exposure;
            VideoProperties.ExposureFlag = exposureFlag;
        }
        private static CameraProperty ReadProperty(VideoCaptureDevice device, CameraControlProperty property)
        {
            CameraProperty p = new CameraProperty();

            p.Identifier     = property.ToString();
            p.Specific       = "CameraControl";
            p.ReadOnly       = false;
            p.Type           = CameraPropertyType.Integer;
            p.Representation = CameraPropertyRepresentation.LinearSlider;
            p.CanBeAutomatic = true;

            try
            {
                int min;
                int max;
                int step;
                int defaultValue;
                CameraControlFlags flags;
                bool success = device.GetCameraPropertyRange(property, out min, out max, out step, out defaultValue, out flags);

                if (!success)
                {
                    p.Supported = false;
                }
                else
                {
                    p.Supported = true;
                    p.Minimum   = min.ToString(CultureInfo.InvariantCulture);
                    p.Maximum   = max.ToString(CultureInfo.InvariantCulture);

                    int currentValue;
                    success = device.GetCameraProperty(property, out currentValue, out flags);

                    if (!success)
                    {
                        p.Supported = false;
                    }
                    else
                    {
                        p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture);
                        p.Automatic    = flags == CameraControlFlags.Auto;
                    }
                }
            }
            catch
            {
                p.Supported = false;
            }

            return(p);
        }
Example #7
0
        public int GetExposure()
        {
            int val;
            CameraControlFlags flags;

            try {
                if (_videoSource.GetCameraProperty(CameraControlProperty.Exposure, out val, out flags))
                {
                    return(val);
                }
            } catch {
                // ignored
            }
            return(-1);
        }
Example #8
0
        public void PrintAllProperties()
        {
            int minValue     = 0;
            int maxValue     = 0;
            int stepSize     = 1;
            int defaultValue = 0;
            CameraControlFlags controlFlags = 0;
            bool success;

            //for (int i = 0; i <= 6; i++)
            //{

            //    success = cam.GetCameraPropertyRange((CameraControlProperty)i, out minValue, out maxValue, out stepSize, out defaultValue, out controlFlags);
            //}

            success = cam.GetCameraProperty(0, out minValue, out controlFlags);
        }
Example #9
0
        public CameraProperty(VideoCaptureDevice camera, CameraControlProperty prop)
        {
            theDevice = camera;
            camProp   = prop;
            int  defval, steps, cur;
            bool fail = false;

            try
            {
                fail = !theDevice.GetCameraPropertyRange(prop, out minLimit, out maxLimit, out steps, out defval, out camFlags);
                theDevice.GetCameraProperty(camProp, out cur, out camFlags);
            }
            catch (Exception e)
            {
                controllable = false;
            }
            if (fail)
            {
                controllable = false;
            }
        }
            /// <summary>
            /// Initialize access to the camera hardware
            /// </summary>
            public Cam()
            {
                // Event used to wait for completion of camera tasks
                _finished = new EventWaitHandle(false, EventResetMode.ManualReset);

                // Find the integrated camera device
                var coll = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (!coll.Any(fi => fi.MonikerString.StartsWith(@"@device:pnp:\\?\usb#vid_5986&pid_2115")))
                {
                    throw new Exception("Integrated Camera device not found");
                }
                _vdev = new VideoCaptureDevice(coll.First(fi => fi.MonikerString.StartsWith(@"@device:pnp:\\?\usb#vid_5986&pid_2115")).MonikerString);

                // Initial settings and hook handlers
                _vdev.VideoResolution  = _vdev.VideoCapabilities.First(sn => sn.FrameSize == new System.Drawing.Size(320, 240));
                _vdev.PlayingFinished += (sender, e) => _finished.Set();
                _vdev.NewFrame        += (sender, e) =>
                {
                    int o_exp = -3;
                    CameraControlFlags o_flag = CameraControlFlags.Auto;
                    if (_cnt == 0)
                    {
                        // 1st frame, camera is open and working. Change settings to fixed constants.
                        _vdev.GetCameraProperty(CameraControlProperty.Exposure, out o_exp, out o_flag);
                        _vdev.SetCameraProperty(CameraControlProperty.Exposure, -3, CameraControlFlags.Manual);
                    }
                    if (_cnt == 4)
                    {
                        // 5th frame, keep this frame. Revert camera settings. Signal to stop querying for frames.
                        _img = e.Frame.Clone(new System.Drawing.Rectangle(0, 0, e.Frame.Width, e.Frame.Height), System.Drawing.Imaging.PixelFormat.DontCare);
                        _vdev.SetCameraProperty(CameraControlProperty.Exposure, o_exp, o_flag);
                        _vdev.SignalToStop();
                    }
                    _cnt++;
                };
            }
Example #11
0
        private VideoParm GetCameraParm()
        {
            var exposureValue = 0; //曝光-4 -10
            var exposureFlage = CameraControlFlags.Auto;

            device.GetCameraProperty(CameraControlProperty.Exposure, out exposureValue, out exposureFlage);

            var brightnessValue = 0;//亮度 -64  64
            var brightnessFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.Brightness, out brightnessValue, out brightnessFlage);

            var contrastValue = 0;//对比度 0 95
            var contrastFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.Contrast, out contrastValue, out contrastFlage);

            var sharpnessValue = 0;//清晰度 1 7
            var sharpnessFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.Sharpness, out sharpnessValue, out sharpnessFlage);

            var whiteBalanceValue = 0;  //白平衡
            var whiteBalanceFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.WhiteBalance, out whiteBalanceValue, out whiteBalanceFlage);

            var saturationValue = 0;  //饱和度
            var saturationFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.Saturation, out saturationValue, out saturationFlage);

            var gammaValue = 0;  //伽马
            var gammaFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.Gamma, out gammaValue, out gammaFlage);

            var backlightCompensationValue = 0;  //逆光对比
            var backlightCompensationFlage = VideoProcAmpFlags.Auto;

            device.GetVideoProperty(VideoProcAmpProperty.BacklightCompensation, out backlightCompensationValue, out backlightCompensationFlage);

            //var hueValue = 0;  //色调
            //var hueFlage = VideoProcAmpFlags.Auto;
            //device.GetVideoProperty(VideoProcAmpProperty.Hue, out hueValue, out hueFlage);

            VideoParm parm = new VideoParm
            {
                Baoguang     = exposureValue,
                Liangdu      = brightnessValue,
                Duibidu      = contrastValue,
                Qingxidu     = sharpnessValue,
                Baipingheng  = whiteBalanceValue,
                Baohedu      = saturationValue,
                Gama         = gammaValue,
                Niguangduibi = backlightCompensationValue,
                //Sediao = hueValue
            };

            return(parm);
        }