Esempio n. 1
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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
        public int GetParameterValue(VideoProcAmpProperty property)
        {
            int iRet;
            VideoProcAmpFlags cameraControlFlags;

            iAMVideoProcAmp.Get(property, out iRet, out cameraControlFlags);
            return(iRet);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取当前饱和度值
        /// </summary>
        /// <returns></returns>
        public int GetSaturationValue()
        {
            int               SaturationValue = 0;
            IAMVideoProcAmp   videoProcAmp    = theDevice as IAMVideoProcAmp;
            VideoProcAmpFlags flags           = VideoProcAmpFlags.Manual;

            videoProcAmp.Get(VideoProcAmpProperty.Saturation, out SaturationValue, out flags);
            return(SaturationValue);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取当前对比度值
        /// </summary>
        /// <returns></returns>
        public int GetContrastValue()
        {
            int               ContrastValue = 0;
            IAMVideoProcAmp   videoProcAmp  = theDevice as IAMVideoProcAmp;
            VideoProcAmpFlags flags         = VideoProcAmpFlags.Manual;

            videoProcAmp.Get(VideoProcAmpProperty.Contrast, out ContrastValue, out flags);
            return(ContrastValue);
        }
Esempio n. 7
0
        /// <summary>
        /// 获取当前亮度值
        /// </summary>
        /// <returns></returns>
        public int GetLightValue()
        {
            int               LightValue   = 0;
            IAMVideoProcAmp   videoProcAmp = theDevice as IAMVideoProcAmp;
            VideoProcAmpFlags flags        = VideoProcAmpFlags.Manual;

            videoProcAmp.Get(VideoProcAmpProperty.Brightness, out LightValue, out flags);
            return(LightValue);
        }
Esempio n. 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;
 }
Esempio n. 9
0
        /// <summary>
        /// Gets the current setting of a camera property.
        /// </summary>
        ///
        /// <param name="property">Specifies the property to retrieve.</param>
        /// <param name="value">Receives the value of the property.</param>
        /// <param name="controlFlags">Receives the value indicating whether the setting is controlled manually or automatically</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 GetVideoProperty(VideoProcAmpProperty property, out int value, 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.Get(property, out value, out controlFlags);

                ret = (hr >= 0);

                Marshal.ReleaseComObject(tempSourceObject);
            }

            return(ret);
        }
Esempio n. 10
0
        /// <summary>
        /// 保存当前的相机设置
        /// </summary>
        public void SaveCurrentOriginSetting(string VideoSettingName, bool AsDefault)
        {
            IAMVideoProcAmp   videoProcAmp = theDevice as IAMVideoProcAmp;
            VideoProcAmpFlags flags        = VideoProcAmpFlags.Manual;
            //亮度值 0到255
            int LightValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Brightness, out LightValue, out flags);
            //对比度 0到255
            int ContrastValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Contrast, out ContrastValue, out flags);
            //饱和度 0到255
            int SaturationValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Saturation, out SaturationValue, out flags);
            //色调 -127 到127
            int HueValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Hue, out HueValue, out flags);
            //清晰度 0到15
            int SharpnessValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Sharpness, out SharpnessValue, out flags);
            //伽玛 1到8
            int GammaValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gamma, out GammaValue, out flags);
            //启用颜色 不支持
            int ColorEnable = 0;

            videoProcAmp.Get(VideoProcAmpProperty.ColorEnable, out ColorEnable, out flags);
            //白平衡 不支持
            int WhiteBalanceValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.WhiteBalance, out WhiteBalanceValue, out flags);
            //背光补偿 1 到 5
            int BacklightCompensation = 0;

            videoProcAmp.Get(VideoProcAmpProperty.BacklightCompensation, out BacklightCompensation, out flags);
            //增益 不支持
            int Gain = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gain, out Gain, out flags);

            VideoSetting setting = new VideoSetting();

            setting.Brightness       = LightValue;
            setting.VideoSettingName = VideoSettingName;
            setting.ContrastRatio    = ContrastValue;
            setting.Saturation       = SaturationValue;
            setting.Hue                   = HueValue;
            setting.Sharpness             = SharpnessValue;
            setting.Gamma                 = GammaValue;
            setting.ColorEnable           = Convert.ToBoolean(ColorEnable);
            setting.WhiteBalance          = WhiteBalanceValue;
            setting.BacklightCompensation = BacklightCompensation;
            setting.Gain                  = Gain;
            setting.DefaultSetting        = AsDefault;
            VideoSettingUtils.Instance.SaveVideoSetting(setting, AsDefault);
        }
Esempio n. 11
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);
                }
            }
        }
        /// <summary>
        /// 读取当前摄像头配置并保存到方案中
        /// </summary>
        /// <param name="VideoSettingName">当前配置的方案名</param>
        /// <param name="AsDefault">是否设为摄像头默认设置</param>
        public bool SaveCameraConfigToSetting(string VideoSettingName, bool AsDefault)
        {
            IAMVideoProcAmp   videoProcAmp = _theCamera as IAMVideoProcAmp;
            VideoProcAmpFlags flags        = VideoProcAmpFlags.Manual;
            //亮度值 0到255
            int LightValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Brightness, out LightValue, out flags);
            //对比度 0到255
            int ContrastValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Contrast, out ContrastValue, out flags);
            //饱和度 0到255
            int SaturationValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Saturation, out SaturationValue, out flags);
            //色调 -127 到127
            int HueValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Hue, out HueValue, out flags);
            //清晰度 0到15
            int SharpnessValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Sharpness, out SharpnessValue, out flags);
            //伽玛 1到8
            int GammaValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gamma, out GammaValue, out flags);
            //启用颜色 不支持
            int ColorEnable = 0;

            videoProcAmp.Get(VideoProcAmpProperty.ColorEnable, out ColorEnable, out flags);
            //白平衡 不支持
            int WhiteBalanceValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.WhiteBalance, out WhiteBalanceValue, out flags);
            //背光补偿 1 到 5
            int BacklightCompensation = 0;

            videoProcAmp.Get(VideoProcAmpProperty.BacklightCompensation, out BacklightCompensation, out flags);
            //增益 不支持
            int Gain = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gain, out Gain, out flags);

            CameraParamPlanEntity setting = new CameraParamPlanEntity();

            setting.PrimaryKey            = Guid.NewGuid().ToString();
            setting.CameraName            = this._bindCameraName;
            setting.Brightness            = LightValue;
            setting.ParamPlanName         = VideoSettingName;
            setting.ContrastRatio         = ContrastValue;
            setting.Saturation            = SaturationValue;
            setting.Hue                   = HueValue;
            setting.Sharpness             = SharpnessValue;
            setting.Gamma                 = GammaValue;
            setting.ColorEnable           = Convert.ToBoolean(ColorEnable);
            setting.WhiteBalance          = WhiteBalanceValue;
            setting.BacklightCompensation = BacklightCompensation;
            setting.Gain                  = Gain;
            setting.DefaultSetting        = AsDefault;

            if (AsDefault)
            {
                List <CameraParamPlanEntity> list = XmlHelper.XmlHelper.FindAll <CameraParamPlanEntity>();
                if (list == null)
                {
                    list = new List <CameraParamPlanEntity>();
                }
                list.ForEach(m => m.DefaultSetting = false);
                list.Add(setting);
                XmlHelper.XmlHelper.SaveList <CameraParamPlanEntity>(list);
            }
            else
            {
                setting.Save();
            }

            return(true);
        }