示例#1
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);
        }
示例#2
0
 /// <summary>
 /// sets the camera exposure
 /// </summary>
 /// <param name="value"></param>
 public void SetExposure(int value)
 {
     if (m_iVidConfig != null)
     {
         m_iVidConfig.Set(VideoProcAmpProperty.ColorEnable, 1, VideoProcAmpFlags.Manual);
         m_iVidConfig.Set(VideoProcAmpProperty.Saturation, value, VideoProcAmpFlags.Manual);
         m_iVidConfig.Set(VideoProcAmpProperty.Brightness, value, VideoProcAmpFlags.Manual);
     }
     if (m_iCamConfig != null)
     {
         m_iCamConfig.Set(CameraControlProperty.Exposure, value, CameraControlFlags.Manual);
     }
 }
示例#3
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);
        }
示例#4
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);
        }
        /// <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);
            }
        }
示例#6
0
        public void Write()
        {
            // Write values
            if (_CamFilter.Set(_CamProperty, _Value, _Flags) != 0)
            {
                Console.Error.WriteLine("Could not set camera value");
            }

            // Make sure we read it back!
            _ReadDirty = true;
        }
        private void TrackBarExposure_Scroll(object sender, EventArgs e)
        {
            TrackBar trackBar     = ( TrackBar )sender;
            int      Value        = trackBar.Value - trackBar.Value % trackBar.TickFrequency;
            int      inverceValue = trackBar.Maximum - Value + trackBar.Minimum;

            trackBar.Value = Value;
            IAMCameraControl pCameraControl = ( IAMCameraControl )trackBar.Tag;

            pCameraControl.Set(CameraControlProperty.Exposure, inverceValue, CameraControlFlags.Manual);
            ggghhh.Set(VideoProcAmpProperty.WhiteBalance, Value, VideoProcAmpFlags.Manual);
        }
 /// <summary>
 /// Sets the new video proc amp configuration
 /// </summary>
 /// <param name="map">A map with the new video quality settings</param>
 private void SetVideoProcAmpValues(IDictionary <VideoProcAmpProperty, VideoQuality> map)
 {
     if (_videoProcAmp != null && map != null)
     {
         foreach (VideoProcAmpProperty prop in map.Keys)
         {
             VideoQuality quality = map[prop];
             _videoProcAmp.Set(prop, quality.Value, quality.IsManual ? VideoProcAmpFlags.Manual : VideoProcAmpFlags.Auto);
             Log.Log.Info("Set VideoProcAmp - {0} to value: {1}", prop, quality.Value);
         }
     }
 }
示例#9
0
        private void SetPropertyValue(object sender, EventArgs e)
        {
            PropertyControlSave pc = (PropertyControlSave)sender;

            int  value = pc.GetValue();
            bool auto  = pc.GetAutoMode();

            if (Object.ReferenceEquals(pc.GetProperty().GetType(), new CameraControlProperty().GetType()))
            {
                pCameraControl.Set((CameraControlProperty)pc.GetProperty(), value, auto ? CameraControlFlags.Auto : CameraControlFlags.Manual);
            }
            else
            {
                // VideoProcAmpProperty
                pVideoProcAmp.Set((VideoProcAmpProperty)pc.GetProperty(), value, auto ? VideoProcAmpFlags.Auto : VideoProcAmpFlags.Manual);
            }
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsDevice"></param>
        /// <param name="prop"></param>
        /// <param name="value"></param>
        /// <param name="flag"></param>
        public void SetVideoControl(DsDevice dsDevice, VideoProcAmpProperty prop, int value = 0, VideoProcAmpFlags flag = VideoProcAmpFlags.Auto)
        {
            IFilterGraph2 filterGraph = new FilterGraph() as IFilterGraph2;
            IBaseFilter   capFilter   = null;

            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;

                videoControl.Set(prop, value, flag);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// Sets a specified property on the camera.
        /// </summary>
        ///
        /// <param name="property">Specifies the property to set.</param>
        /// <param name="value">Specifies the new value of the property.</param>
        /// <param name="controlFlags">Specifies the desired control setting.</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 SetVideoProperty(VideoProcAmpProperty property, int value, 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.Set(property, value, controlFlags);

                ret = (hr >= 0);

                Marshal.ReleaseComObject(tempSourceObject);
            }

            return(ret);
        }
示例#12
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);
            }
        }
示例#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);
            }
        }
        /// <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);
        }
 public void SetAutoVideoProcAmpParameter(VideoProcAmpProperty property, int iVal)
 {
     iAMVideoProcAmp.Set(property, iVal, VideoProcAmpFlags.Auto);
 }
示例#16
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);
        }
示例#17
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);
                }
            }
        }