Пример #1
0
        /// <summary>
        /// The event handler for the <see cref="OnCameraControlPropertyChanged"/> event.
        /// Updates the video capture device with new brightness, contrast, etc.
        /// </summary>
        /// <param name="property">The <see cref="VideoProcAmpProperty"/> to be changed</param>
        /// <param name="value">The new value for the property</param>
        public void OnVideoProcAmpPropertyChanged(VideoProcAmpProperty property, int value)
        {
            if (videoProcAmp == null)
            {
                return;
            }

            int min, max, steppingDelta, defaultValue;
            VideoProcAmpFlags flags;

            try
            {
                Console.WriteLine("//ERV ---------- OnVideoProcAmpPropertyChanged(" + property + "," + value);
                videoProcAmp.GetRange(property, out min, out max, out steppingDelta, out defaultValue, out flags);

                if (value >= min && value <= max)
                {
                    videoProcAmp.Set(property, value, flags);
                }
            }
            catch (Exception ex)
            {
                //ErrorLogger.ProcessException(ex, false);
                Console.WriteLine("ERROR! " + ex.ToString());
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 设置亮度
        /// </summary>
        /// <param name="lightValue">亮度值0 到 100</param>
        /// <returns></returns>
        public int SetLightValue(int lightValue)
        {
            int             iResult      = 0;
            IAMVideoProcAmp videoProcAmp = theDevice as IAMVideoProcAmp;

            if (videoProcAmp == null)
            {
                iResult = -1;
                return(iResult);
            }
            int val;
            int min;
            int max;
            int step;
            int defaultValue;
            VideoProcAmpFlags flags = VideoProcAmpFlags.Manual;

            // 设置亮度
            if (lightValue != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Brightness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Brightness, out val, out flags);
                    //val = min + (max - min) * lightValue / 255;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Brightness, lightValue, flags);
                }
            }


            return(iResult);
        }
Пример #3
0
        private void controlCameraSettings()
        {
            videoSource.SetCameraProperty(CameraControlProperty.Focus, (int)((255 / 15) * 15), CameraControlFlags.Manual);
            videoSource.SetCameraProperty(CameraControlProperty.Zoom, 2, CameraControlFlags.Manual);
            videoSource.SetCameraProperty(CameraControlProperty.Pan, 1, CameraControlFlags.Manual);
            videoSource.SetCameraProperty(CameraControlProperty.Tilt, -2, CameraControlFlags.Manual);


            object o;
            Guid   IID_IBaseFilter = new Guid("56a86895-0ad4-11ce-b03a-0020af0ba770");

            IAMVideoProcAmp   vpa = (IAMVideoProcAmp)o;
            int               pMin, pMax, pSteppingDelta, pDefault;
            VideoProcAmpFlags pFlags;

            vpa.GetRange(
                VideoProcAmpProperty.Brightness,
                out pMin,
                out pMax,
                out pSteppingDelta,
                out pDefault,
                out pFlags);

            vpa.Set(VideoProcAmpProperty.Gain, 20, pFlags);
            vpa.Set(VideoProcAmpProperty.Contrast, 70, pFlags);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsDevice"></param>
        /// <param name="prop"></param>
        /// <returns></returns>
        public int GetVideoControl(DsDevice dsDevice, VideoProcAmpProperty prop)
        {
            IFilterGraph2 filterGraph = new FilterGraph() as IFilterGraph2;
            IBaseFilter   capFilter   = null;

            int retVal = 0;

            try
            {
                // add the video input device
                int hr = filterGraph.AddSourceFilterForMoniker(dsDevice.Mon, null, "Source Filter", out capFilter);
                DsError.ThrowExceptionForHR(hr);
                IAMVideoProcAmp videoControl = capFilter as IAMVideoProcAmp;

                int min, max, step, default_val;
                VideoProcAmpFlags flag = 0;
                videoControl.GetRange(prop, out min, out max, out step, out default_val, out flag);

                videoControl.Get(prop, out retVal, out flag);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(retVal);
        }
Пример #5
0
        private PropertyControl CreatePropertyControl(object property)
        {
            bool none, autoSupport, manualSupport, auto, manual;
            int  pMax, pMin, pValue, pSteppingDelta, defaultValue;

            if (Object.ReferenceEquals(property.GetType(), new CameraControlProperty().GetType()))
            {
                CameraControlFlags cameraFlags;
                pCameraControl.GetRange((CameraControlProperty)property, out pMin, out pMax, out pSteppingDelta, out defaultValue, out cameraFlags);
                none          = cameraFlags == CameraControlFlags.None;
                autoSupport   = (cameraFlags & CameraControlFlags.Auto) == CameraControlFlags.Auto;
                manualSupport = (cameraFlags & CameraControlFlags.Manual) == CameraControlFlags.Manual;
                pCameraControl.Get((CameraControlProperty)property, out pValue, out cameraFlags);
                auto   = (cameraFlags & CameraControlFlags.Auto) == CameraControlFlags.Auto;
                manual = (cameraFlags & CameraControlFlags.Manual) == CameraControlFlags.Manual;
            }
            else
            {
                // VideoProcAmpProperty
                VideoProcAmpFlags cameraFlags;
                pVideoProcAmp.GetRange(
                    (VideoProcAmpProperty)property, out pMin, out pMax, out pSteppingDelta, out defaultValue, out cameraFlags);
                none          = cameraFlags == VideoProcAmpFlags.None;
                autoSupport   = (cameraFlags & VideoProcAmpFlags.Auto) == VideoProcAmpFlags.Auto;
                manualSupport = (cameraFlags & VideoProcAmpFlags.Manual) == VideoProcAmpFlags.Manual;
                pVideoProcAmp.Get((VideoProcAmpProperty)property, out pValue, out cameraFlags);
                auto   = (cameraFlags & VideoProcAmpFlags.Auto) == VideoProcAmpFlags.Auto;
                manual = (cameraFlags & VideoProcAmpFlags.Manual) == VideoProcAmpFlags.Manual;
            }
            return(new PropertyControl(property, none, autoSupport, manualSupport, auto, manual, pMax, pMin, pValue, pSteppingDelta, defaultValue));
        }
Пример #6
0
        internal WebcamProperty GetProcAmpProperties(VideoProcAmpProperty property)
        {
            HResult result = HResult.ERROR_NOT_READY;

            WebcamProperty settings = new WebcamProperty
            {
                _name        = property.ToString(),
                _procAmpProp = property,
                _isProcAmp   = true
            };

            if (_base._webcamMode)
            {
                IAMVideoProcAmp control = _base.mf_MediaSource as IAMVideoProcAmp;
                result = control.GetRange(property, out settings._min, out settings._max, out settings._step, out settings._default, out VideoProcAmpFlags flags);

                if (result == Player.NO_ERROR)
                {
                    settings._supported   = (flags & VideoProcAmpFlags.Manual) != 0;
                    settings._autoSupport = (flags & VideoProcAmpFlags.Auto) != 0;

                    control.Get(property, out settings._value, out flags);
                    settings._auto = (flags & VideoProcAmpFlags.Auto) != 0;
                }
            }
            _base._lastError = result;
            return(settings);
        }
Пример #7
0
        /// <summary>
        /// 设置饱和度
        /// </summary>
        /// <param name="SaturationValue">饱和度 0到 100</param>
        /// <returns></returns>
        public int SetSaturationValue(int SaturationValue)
        {
            int             iResult      = 0;
            IAMVideoProcAmp videoProcAmp = theDevice as IAMVideoProcAmp;

            if (videoProcAmp == null)
            {
                iResult = -1;
                return(iResult);
            }
            int val;
            int min;
            int max;
            int step;
            int defaultValue;
            VideoProcAmpFlags flags = VideoProcAmpFlags.Manual;

            //设置饱和度
            if (SaturationValue != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Saturation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * SaturationValue / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Saturation, SaturationValue, flags);
                }
            }

            return(iResult);
        }
Пример #8
0
 public void Read()
 {
     if (_CamFilter.GetRange(_CamProperty, out _Min, out _Max, out _Delta, out _Default, out _PossibleFlags) != 0)
     {
         Console.Error.WriteLine("Could not retrieve camera ranges");
     }
     if (_CamFilter.Get(_CamProperty, out _Value, out _Flags) != 0)
     {
         Console.Error.WriteLine("Could not retrieve camera value");
     }
     _ReadDirty = false;
 }
Пример #9
0
        /// <summary>
        /// The event handler for the <see cref="OnCameraControlPropertyChanged"/> event.
        /// Updates the video capture device with new brightness, contrast, etc.
        /// </summary>
        /// <param name="property">The <see cref="VideoProcAmpProperty"/> to be changed</param>
        /// <param name="value">The new value for the property</param>
        public void OnVideoProcAmpPropertyChanged(VideoProcAmpProperty property, int value)
        {
            if (videoProcAmp == null)
            {
                return;
            }

            int min, max, steppingDelta, defaultValue;
            VideoProcAmpFlags flags;

            try
            {
                videoProcAmp.GetRange(property, out min, out max, out steppingDelta, out defaultValue, out flags);

                if (value >= min && value <= max)
                {
                    videoProcAmp.Set(property, value, flags);
                }
            }
            catch (Exception ex)
            {
                //ErrorLogger.ProcessException(ex, false);
            }
        }
        public VideoProcAmpRangeParameter GetRangeParameterValue(VideoProcAmpProperty property)
        {
            VideoProcAmpRangeParameter _model = new VideoProcAmpRangeParameter();
            int Min, Max, Step, Default;
            VideoProcAmpFlags _flgs;
            int hr2 = iAMVideoProcAmp.GetRange(property,
                                               out Min, out Max, out Step, out Default, out _flgs);

            DsError.ThrowExceptionForHR(hr2);
            _model.MinValue          = Min;
            _model.MaxValue          = Max;
            _model.SetpValue         = Step;
            _model.DefaultValue      = Default;
            _model.VideoProcAmpFlags = _flgs;
            return(_model);
        }
Пример #11
0
        /// <summary>
        /// Gets the range and default value of a specified camera property.
        /// </summary>
        ///
        /// <param name="property">Specifies the property to query.</param>
        /// <param name="minValue">Receives the minimum value of the property.</param>
        /// <param name="maxValue">Receives the maximum value of the property.</param>
        /// <param name="stepSize">Receives the step size for the property.</param>
        /// <param name="defaultValue">Receives the default value of the property.</param>
        /// <param name="controlFlags">Receives a member of the <see cref="CameraControlFlags"/> enumeration, indicating whether the property is controlled automatically or manually.</param>
        ///
        /// <returns>Returns true on success or false otherwise.</returns>
        ///
        /// <exception cref="ArgumentException">Video source is not specified - device moniker is not set.</exception>
        /// <exception cref="ApplicationException">Failed creating device object for moniker.</exception>
        /// <exception cref="NotSupportedException">The video source does not support camera control.</exception>
        ///
        public bool GetVideoPropertyRange(VideoProcAmpProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out VideoProcAmpFlags controlFlags)
        {
            bool ret = true;

            // check if source was set
            if ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker)))
            {
                throw new ArgumentException("Video source is not specified.");
            }

            lock (sync)
            {
                object tempSourceObject = null;

                // create source device's object
                try
                {
                    tempSourceObject = FilterInfo.CreateFilter(deviceMoniker);
                }
                catch
                {
                    throw new ApplicationException("Failed creating device object for moniker.");
                }

                if (!(tempSourceObject is IAMVideoProcAmp))
                {
                    throw new NotSupportedException("The video source does not support camera control.");
                }

                IAMVideoProcAmp pCamControl = (IAMVideoProcAmp)tempSourceObject;
                int             hr          = pCamControl.GetRange(property, out minValue, out maxValue, out stepSize, out defaultValue, out controlFlags);

                ret = (hr >= 0);

                Marshal.ReleaseComObject(tempSourceObject);
            }

            return(ret);
        }
Пример #12
0
        private void UpdatePropertiesCache()
        {
            AMproperties.Clear();

            IAMVideoProcAmp  vpa = null;
            IAMCameraControl cc  = null;

            try
            {
                vpa = (IAMVideoProcAmp)Marshal.GetObjectForIUnknown(dev.NativePointer);
                foreach (var pVal in Enum.GetValues(typeof(VideoProcAmpProperty)))
                {
                    AMVideoProcAmpProperty p = new AMVideoProcAmpProperty();
                    p.PropertyName = Enum.GetName(typeof(VideoProcAmpProperty), pVal);
                    p.ProperyId    = (int)pVal;
                    VideoProcAmpFlags flags;
                    int hr = vpa.GetRange((VideoProcAmpProperty)pVal, out p.Min, out p.Max, out p.Delta, out p.DefaultValue, out flags);
                    if (hr != 0)
                    {
                        continue;
                    }
                    p.PossibleFlags = (int)flags;
                    hr = vpa.Get((VideoProcAmpProperty)pVal, out p.Value, out flags);
                    if (hr != 0)
                    {
                        continue;
                    }
                    p.Flag = (int)flags;
                    AMproperties.Add(p);
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult != SharpDX.Result.NoInterface.Code)
                {
                    throw;
                }
            }
            finally
            {
                if (vpa != null)
                {
                    Marshal.ReleaseComObject(vpa);
                }
            }

            try
            {
                cc = (IAMCameraControl)Marshal.GetObjectForIUnknown(dev.NativePointer);
                foreach (var pVal in Enum.GetValues(typeof(CameraControlProperty)))
                {
                    AMCameraControlProperty p = new AMCameraControlProperty();
                    p.PropertyName = Enum.GetName(typeof(CameraControlProperty), pVal);
                    p.ProperyId    = (int)pVal;
                    CameraControlFlags flags;
                    int hr = cc.GetRange((CameraControlProperty)pVal, out p.Min, out p.Max, out p.Delta, out p.DefaultValue, out flags);
                    if (hr != 0)
                    {
                        continue;
                    }
                    p.PossibleFlags = (int)flags;
                    hr = cc.Get((CameraControlProperty)pVal, out p.Value, out flags);
                    if (hr != 0)
                    {
                        continue;
                    }
                    p.Flag = (int)flags;
                    AMproperties.Add(p);
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult != SharpDX.Result.NoInterface.Code)
                {
                    throw;
                }
            }
            finally
            {
                if (cc != null)
                {
                    Marshal.ReleaseComObject(cc);
                }
            }
        }
Пример #13
0
        public void SetupProperties(DsDevice dev, int brightness, int contrast, int backlightcompensation, int sharpness)
        {
            object o;
            Guid   IID_IBaseFilter = new Guid("56a86895-0ad4-11ce-b03a-0020af0ba770");

            dev.Mon.BindToObject(null, null, ref IID_IBaseFilter, out o);
            IAMVideoProcAmp vpa = (IAMVideoProcAmp)o;

            int pMin, pMax, pSteppingDelta, pDefault;
            int pMin2, pMax2, pSteppingDelta2, pDefault2;
            int pMin3, pMax3, pSteppingDelta3, pDefault3;
            int pMin4, pMax4, pSteppingDelta4, pDefault4;
            //int pMin5, pMax5, pSteppingDelta5, pDefault5;
            VideoProcAmpFlags pFlags, pFlags2, pFlags3, pFlags4;//, pFlags5;

            vpa.GetRange(
                VideoProcAmpProperty.Brightness,
                out pMin,
                out pMax,
                out pSteppingDelta,
                out pDefault,
                out pFlags);

            vpa.GetRange(
                VideoProcAmpProperty.Sharpness,
                out pMin2,
                out pMax2,
                out pSteppingDelta2,
                out pDefault2,
                out pFlags2);

            vpa.GetRange(
                VideoProcAmpProperty.BacklightCompensation,
                out pMin3,
                out pMax3,
                out pSteppingDelta3,
                out pDefault3,
                out pFlags3);



            vpa.GetRange(
                VideoProcAmpProperty.Contrast,
                out pMin4,
                out pMax4,
                out pSteppingDelta4,
                out pDefault4,
                out pFlags4);

            //vpa.GetRange(
            //VideoProcAmpProperty.ColorEnable,
            //out pMin5,
            //out pMax5,
            //out pSteppingDelta5,
            //out pDefault5,
            //out pFlags5);

            //Here I will change the settings of the camera!

            if (brightness >= pMin && brightness <= pMax)
            {
                vpa.Set(VideoProcAmpProperty.Brightness, brightness, pFlags);
            }
            if (sharpness >= pMin2 && sharpness <= pMax2)
            {
                vpa.Set(VideoProcAmpProperty.Sharpness, sharpness, pFlags2);
            }
            if (backlightcompensation >= pMin3 && backlightcompensation <= pMax3)
            {
                vpa.Set(VideoProcAmpProperty.BacklightCompensation, backlightcompensation, pFlags3);
            }
            if (contrast >= pMin4 && contrast <= pMax)
            {
                vpa.Set(VideoProcAmpProperty.Contrast, contrast, pFlags4);
            }
        }
Пример #14
0
        private void set_camera_par(int CamIdx, WebcamConfig wc)
        {
            if (new FilterGraph() is IFilterGraph2 graphBuilder)
            {
                graphBuilder.AddSourceFilterForMoniker(_CameraChoice.Devices[CamIdx].Mon, null, _CameraChoice.Devices[CamIdx].Name, out IBaseFilter capFilter);

                ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker);
                Resolution     res         = new Resolution(800, 600);
                foreach (var r in resolutions)
                {
                    if (r.Width > res.Width)
                    {
                        res = r;
                    }
                }

                bool new_config = false;
                wc.config_salvar_valor("Resolution", res.Width + "X" + res.Height);
                if (wc.Resolution.Width != res.Width && wc.Resolution.Height != res.Height)
                {
                    new_config = true;
                }
                string n_cam = _CameraChoice.Devices[CamIdx].Name;
                if (n_cam != wc.WebcamName)
                {
                    new_config = true;
                    wc.config_salvar_valor("WebcamName", _CameraChoice.Devices[CamIdx].Name);
                }


                IAMCameraControl _camera = capFilter as IAMCameraControl;
                _camera.Get(CameraControlProperty.Focus, out int v, out CameraControlFlags f);
                if (f != CameraControlFlags.None)
                {
                    if (new_config)
                    {
                        if (n_cam.Contains("Brio"))
                        {
                            _camera.Set(CameraControlProperty.Focus, 115, CameraControlFlags.Manual);
                            wc.config_salvar_valor("Focus", "115");
                        }
                    }
                    else
                    {
                        if (wc.Focus == "Auto")
                        {
                            _camera.Set(CameraControlProperty.Focus, 115, CameraControlFlags.Auto);
                        }
                        else
                        {
                            _camera.Set(CameraControlProperty.Focus, Convert.ToInt32(wc.Focus), CameraControlFlags.Manual);
                        }
                    }
                }
                //_camera.Set(CameraControlProperty.Zoom, wc.Zoom, CameraControlFlags.Manual);

                _camera.Get(CameraControlProperty.Exposure, out int v1, out CameraControlFlags f1);
                IAMVideoProcAmp   _cameraVP = capFilter as IAMVideoProcAmp;
                int               rMin, rMax, rDelta, rDeflt;
                VideoProcAmpFlags vflag;

                if (new_config)
                {
                    _cameraVP.GetRange(VideoProcAmpProperty.Contrast, out rMin, out rMax, out rDelta, out rDeflt, out vflag);

                    wc.config_salvar_valor("Contrast", rDeflt.ToString());
                    _cameraVP.Set(VideoProcAmpProperty.Contrast, rDeflt, VideoProcAmpFlags.Manual);
                    _cameraVP.GetRange(VideoProcAmpProperty.Brightness, out rMin, out rMax, out rDelta, out rDeflt, out vflag);
                    wc.config_salvar_valor("Brightness", (rDeflt).ToString());
                    _cameraVP.Set(VideoProcAmpProperty.Brightness, rDeflt, VideoProcAmpFlags.Manual);
                    _cameraVP.GetRange(VideoProcAmpProperty.BacklightCompensation, out rMin, out rMax, out rDelta, out rDeflt, out vflag);
                    wc.config_salvar_valor("BacklightCompensation", (rDeflt).ToString());
                    _cameraVP.GetRange(VideoProcAmpProperty.Gain, out rMin, out rMax, out rDelta, out rDeflt, out vflag);
                    wc.config_salvar_valor("Gain", (rDeflt).ToString());
                    _cameraVP.GetRange(VideoProcAmpProperty.Gamma, out rMin, out rMax, out rDelta, out rDeflt, out vflag);
                    wc.config_salvar_valor("Gamma", (rDeflt).ToString());
                }
                else
                {
                    _cameraVP.Set(VideoProcAmpProperty.Contrast, wc.Contrast, VideoProcAmpFlags.Manual);
                    _cameraVP.Set(VideoProcAmpProperty.Brightness, wc.Brightness, VideoProcAmpFlags.Manual);
                    _cameraVP.Set(VideoProcAmpProperty.BacklightCompensation, wc.BacklightCompensation, VideoProcAmpFlags.Auto);
                    _cameraVP.Set(VideoProcAmpProperty.Gain, wc.Gain, VideoProcAmpFlags.Manual);
                    _cameraVP.Set(VideoProcAmpProperty.Gamma, wc.Gamma, VideoProcAmpFlags.Manual);
                }
            }
        }
Пример #15
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DsDevice[]         capDev;
            IFilterGraph2      m_FilterGraph = new FilterGraph() as IFilterGraph2;
            IBaseFilter        pDeviceFilter = null;
            IAMCameraControl   pCameraControl;
            IAMVideoProcAmp    pVideoProcAmp;
            CameraControlFlags pCapsFlags;
            VideoProcAmpFlags  pCapsFlags2;
            int pSteppingDelta;
            int pMin;
            int pMax;
            int pDefault;
            int pValue;

            int       yLocation = 40;
            const int yStep     = 113;

            overWindowToggleButton.Appearance = Appearance.Button;

            // TODO
            updateButton.Visible = false;

            // Get the collection of video devices
            capDev = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            foreach (DsDevice d in capDev)
            {
                //listBox1.Items.Add(d.Name);


                int    hr;
                object camDevice;
                Guid   iid = typeof(IBaseFilter).GUID;
                d.Mon.BindToObject(null, null, ref iid, out camDevice);
                IBaseFilter camFilter = camDevice as IBaseFilter;
                pCameraControl = camFilter as IAMCameraControl;
                pVideoProcAmp  = camFilter as IAMVideoProcAmp;


                if (pCameraControl != null)
                {
                    GroupBox gb           = new GroupBox();
                    CheckBox cbFocus      = cbFocusHID = new CheckBox();
                    CheckBox cbExposure   = new CheckBox();
                    Button   butForce     = new Button();
                    TrackBar tBarFocus    = tBarFocusHID = new TrackBar();
                    TrackBar tBarExposure = new TrackBar();

                    gb.Text     = d.Name;
                    gb.Width    = 295;
                    gb.Height   = 106;
                    gb.Location = new Point(13, yLocation);


                    pCameraControl.GetRange(CameraControlProperty.Focus, out pMin, out pMax, out pSteppingDelta, out pDefault, out pCapsFlags);

                    cbFocus.Text            = "Auto focus";
                    cbFocus.Width           = 78;
                    cbFocus.Height          = 17;
                    cbFocus.Location        = new Point(6, 23);
                    cbFocus.Tag             = butForce;
                    cbFocus.Checked         = (pCapsFlags == CameraControlFlags.Auto);
                    cbFocus.CheckedChanged += new EventHandler(this.checkBoxFocus_CheckedChanged);

                    butForce.Text     = "Force";
                    butForce.Width    = 75;
                    butForce.Height   = 23;
                    butForce.Location = new Point(90, 19);
                    //butForce.Enabled = false;
                    butForce.Tag    = pCameraControl;
                    butForce.Click += new EventHandler(this.ButtonForce_Click);

                    // TODO
                    //butBind.Visible = false;
                    //butBind.Text = "Bind key";
                    //butBind.Width = 75;
                    //butBind.Height = 23;
                    //butBind.Location = new Point(214, 19);

                    tBarFocus.Minimum       = pMin;
                    tBarFocus.Maximum       = pMax;
                    tBarFocus.Value         = pDefault;
                    tBarFocus.Name          = "TrackBarFocus";
                    tBarFocus.AutoSize      = false;
                    tBarFocus.Width         = 283;
                    tBarFocus.Height        = 23;
                    tBarFocus.TickFrequency = pSteppingDelta;
                    tBarFocus.Location      = new Point(6, 46);
                    tBarFocus.Tag           = pCameraControl;
                    tBarFocus.Enabled       = (pCapsFlags == CameraControlFlags.Manual);
                    pCameraControl.Get(CameraControlProperty.Focus, out pValue, out pCapsFlags);
                    tBarFocus.Value   = pMax - pValue + pMin;
                    tBarFocus.Scroll += new EventHandler(this.TrackBarFocus_Scroll);

                    if (pVideoProcAmp != null)
                    {
                        ggghhh = pVideoProcAmp;
                        //pCameraControl.GetRange(CameraControlProperty.Exposure, out pMin, out pMax, out pSteppingDelta, out pDefault, out pCapsFlags);
                        ggghhh.GetRange(VideoProcAmpProperty.WhiteBalance, out pMin, out pMax, out pSteppingDelta, out pDefault, out pCapsFlags2);

                        cbExposure.Text            = "Auto exposure";
                        cbExposure.Width           = 98;
                        cbExposure.Height          = 17;
                        cbExposure.Location        = new Point(191, 23);
                        cbExposure.Tag             = butForce;
                        cbExposure.Checked         = true;
                        cbExposure.CheckedChanged += new EventHandler(this.checkBoxExposure_CheckedChanged);

                        tBarExposure.Minimum       = pMin;
                        tBarExposure.Maximum       = pMax;
                        tBarExposure.Value         = pDefault;
                        tBarExposure.Name          = "TrackBarExposure";
                        tBarExposure.AutoSize      = false;
                        tBarExposure.Width         = 283;
                        tBarExposure.Height        = 23;
                        tBarExposure.TickFrequency = pSteppingDelta;
                        tBarExposure.Location      = new Point(6, 73);
                        tBarExposure.Tag           = pCameraControl;
                        tBarExposure.Enabled       = false;
                        //pCameraControl.Get(CameraControlProperty.Exposure, out value, out pCapsFlags);
                        //tBarExposure.Value = pMax - value + pMin;
                        tBarExposure.Scroll += new EventHandler(this.TrackBarExposure_Scroll);
                    }
                    gb.Controls.Add(cbFocus);
                    gb.Controls.Add(butForce);
                    gb.Controls.Add(cbExposure);
                    gb.Controls.Add(tBarFocus);
                    gb.Controls.Add(tBarExposure);
                    Controls.Add(gb);

                    yLocation += yStep;
                }
                pVideoProcAmp = pDeviceFilter as IAMVideoProcAmp;
            }
            this.Height          = 13 + yLocation + 39;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;

            foreach (var x in HidDevices.Enumerate(VendorId, ProductId))
            {
                device = x;
                device.OpenDevice();
                byte      data = 0xff;
                HidReport out1 = new HidReport(data);
                x.WriteReport(out1);
                //byte[] str = new byte[x.Capabilities.OutputReportByteLength - 1]; ;
                //x.ReadManufacturer(out str);
                // Debug.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(str));
                device.ReadReport(OnReport);
            }
        }
Пример #16
0
 /// <summary>
 /// Checks the capabilites of a possbile available video proc amp interface
 /// </summary>
 /// <param name="graph">The stored graph</param>
 private void CheckCapabilitiesVideoProcAmp(Graph graph)
 {
     _videoProcAmp = _filterVideoCapture as IAMVideoProcAmp;
     _defaultVideoProcAmpValues = new Dictionary <VideoProcAmpProperty, VideoQuality>();
     if (_videoProcAmp != null)
     {
         int min, max, steppingDelta, defaultValue;
         VideoProcAmpFlags flags;
         VideoQuality      tempValue;
         int hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Brightness, out min, out max, out steppingDelta,
                                         out defaultValue,
                                         out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Brightness, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Contrast, out min, out max, out steppingDelta, out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Contrast, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Hue, out min, out max, out steppingDelta, out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Hue, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Saturation, out min, out max, out steppingDelta,
                                     out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Saturation, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Sharpness, out min, out max, out steppingDelta,
                                     out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Sharpness, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Gamma, out min, out max, out steppingDelta, out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Gamma, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.ColorEnable, out min, out max, out steppingDelta,
                                     out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.ColorEnable, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.WhiteBalance, out min, out max, out steppingDelta,
                                     out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.WhiteBalance, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.BacklightCompensation, out min, out max, out steppingDelta,
                                     out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.BacklightCompensation, tempValue);
         }
         hr = _videoProcAmp.GetRange(VideoProcAmpProperty.Gain, out min, out max, out steppingDelta, out defaultValue,
                                     out flags);
         if (hr == 0)
         {
             tempValue = new VideoQuality(min, max, steppingDelta, defaultValue, flags == VideoProcAmpFlags.Manual,
                                          defaultValue);
             _defaultVideoProcAmpValues.Add(VideoProcAmpProperty.Gain, tempValue);
         }
         graph.Capture.VideoProcAmpValues = _defaultVideoProcAmpValues;
     }
 }
Пример #17
0
        /// <summary>
        /// 设置摄像头为此配置
        /// </summary>
        /// <param name="setting">摄像头的配置</param>
        /// <param name="asDefault">是否并设为默认</param>
        /// <returns></returns>
        public int SetSettingValue(VideoSetting setting, bool asDefault = false)
        {
            if (asDefault)
            {
                VideoSettingUtils.Instance.SetDefaultSettings(setting);
            }

            int             iResult      = 0;
            IAMVideoProcAmp videoProcAmp = theDevice as IAMVideoProcAmp;

            if (videoProcAmp == null)
            {
                iResult = -1;
                return(iResult);
            }
            int val;
            int min;
            int max;
            int step;
            int defaultValue;
            VideoProcAmpFlags flags = VideoProcAmpFlags.Manual;

            // 设置亮度
            if (setting.Brightness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Brightness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Brightness, out val, out flags);
                    //val = min + (max - min) * setting.Brightness / 255;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Brightness, setting.Brightness, flags);
                }
            }
            //设置对比度
            if (setting.ContrastRatio != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Contrast, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Contrast, out val, out flags);
                    //val = min + (max - min) * setting.ContrastRatio / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Contrast, setting.ContrastRatio, flags);
                }
            }//设置饱和度
            if (setting.Saturation != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Saturation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Saturation, setting.Saturation, flags);
                }
            }
            //设置色调
            if (setting.Hue != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Hue, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Hue, setting.Hue, flags);
                }
            }
            //设置清晰度
            if (setting.Sharpness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Sharpness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Sharpness, setting.Sharpness, flags);
                }
            }
            //设置伽玛
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gamma, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gamma, setting.Gamma, flags);
                }
            }
            //设置启用颜色
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.ColorEnable, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.ColorEnable, Convert.ToInt32(setting.ColorEnable), flags);
                }
            }
            //白平衡
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.WhiteBalance, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.WhiteBalance, setting.WhiteBalance, flags);
                }
            }
            //背光补偿
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.BacklightCompensation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.BacklightCompensation, setting.BacklightCompensation, flags);
                }
            }
            //增益
            if (setting.Gain != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gain, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gain, setting.Gain, flags);
                }
            }
            return(iResult);
        }
        /// <summary>
        /// 切换摄像头配置为指定配置方案
        /// 配置方案可以由GetAllCameraSettings进行传参
        /// </summary>
        /// <param name="setting">摄像头配置方案</param>
        /// <param name="asDefault">是否将此配置设为默认配置</param>
        /// <returns></returns>
        public int ChangeCameraConfigToSetting(CameraParamPlanEntity setting, bool asDefault = false)
        {
            if (asDefault)
            {
                List <CameraParamPlanEntity> list = XmlHelper.XmlHelper.FindAll <CameraParamPlanEntity>();
                list.ForEach(m => m.DefaultSetting = false);
                var oldPlan = list.Find(m => m.CameraName == this._bindCameraName && m.ParamPlanName == setting.ParamPlanName);
                oldPlan.DefaultSetting = true;
                XmlHelper.XmlHelper.SaveList <CameraParamPlanEntity>(list);
            }

            int             iResult      = 0;
            IAMVideoProcAmp videoProcAmp = _theCamera as IAMVideoProcAmp;

            if (videoProcAmp == null)
            {
                iResult = -1;
                return(iResult);
            }
            int val;
            int min;
            int max;
            int step;
            int defaultValue;
            VideoProcAmpFlags flags = VideoProcAmpFlags.Manual;

            // 设置亮度
            if (setting.Brightness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Brightness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Brightness, out val, out flags);
                    //val = min + (max - min) * setting.Brightness / 255;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Brightness, setting.Brightness, flags);
                }
            }
            //设置对比度
            if (setting.ContrastRatio != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Contrast, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Contrast, out val, out flags);
                    //val = min + (max - min) * setting.ContrastRatio / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Contrast, setting.ContrastRatio, flags);
                }
            }//设置饱和度
            if (setting.Saturation != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Saturation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Saturation, setting.Saturation, flags);
                }
            }
            //设置色调
            if (setting.Hue != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Hue, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Hue, setting.Hue, flags);
                }
            }
            //设置清晰度
            if (setting.Sharpness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Sharpness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Sharpness, setting.Sharpness, flags);
                }
            }
            //设置伽玛
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gamma, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gamma, setting.Gamma, flags);
                }
            }
            //设置启用颜色
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.ColorEnable, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.ColorEnable, Convert.ToInt32(setting.ColorEnable), flags);
                }
            }
            //白平衡
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.WhiteBalance, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.WhiteBalance, setting.WhiteBalance, flags);
                }
            }
            //背光补偿
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.BacklightCompensation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.BacklightCompensation, setting.BacklightCompensation, flags);
                }
            }
            //增益
            if (setting.Gain != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gain, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gain, setting.Gain, flags);
                }
            }
            return(iResult);
        }