public static void Write(VideoCaptureDevice device, CameraProperty property)
        {
            if (!property.Supported)
            {
                return;
            }

            switch (property.Specific)
            {
            case "CameraControl":
            {
                CameraControlProperty p = (CameraControlProperty)Enum.Parse(typeof(CameraControlProperty), property.Identifier, true);
                WriteProperty(device, p, property);
                break;
            }

            case "VideoProcAmp":
            {
                VideoProcAmpProperty p = (VideoProcAmpProperty)Enum.Parse(typeof(VideoProcAmpProperty), property.Identifier, true);
                WriteProperty(device, p, property);
                break;
            }

            case "Logitech":
            {
                WriteLogitechProperty(device, property);
                break;
            }
            }
        }
示例#2
0
        public CameraPropertySettings GetCameraControlPropertySettings(CameraControlProperty property)
        {
            int         filterHandle;
            IBaseFilter captureFilter = null;

            filterHandle = filterGraph.FindFilterByName("Video input", out captureFilter);
            if (captureFilter != null)
            {
                int min          = 0;
                int max          = 0;
                int stepDelta    = 1;
                int defaultValue = 0;
                CameraControlFlags cameraControlFlags;
                IAMCameraControl   iC = captureFilter as IAMCameraControl;
                ((IAMCameraControl)iC).GetRange(property, out min, out max, out stepDelta, out defaultValue, out cameraControlFlags);
                CameraPropertySettings videoPropertySettings = new CameraPropertySettings();
                videoPropertySettings.Minimum      = min;
                videoPropertySettings.Maximum      = max;
                videoPropertySettings.Step         = stepDelta;
                videoPropertySettings.DefaultValue = defaultValue;
                return(videoPropertySettings);
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// 设置属性值
 /// </summary>
 /// <param name="cameraControlProperty"></param>
 /// <param name="propertyValue"></param>
 public void SetCameraControlParameterValue(CameraControlProperty cameraControlProperty, int propertyValue)
 {
     VideoCapturePlayer.Dispatcher.BeginInvoke((Action) delegate
     {
         VideoCapturePlayer.CameraControlSetter?.SetParameterValue(cameraControlProperty, propertyValue);
     });
 }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsDevice"></param>
        /// <param name="prop"></param>
        /// <returns></returns>
        public int GetCameraControl(DsDevice dsDevice, CameraControlProperty 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);
                IAMCameraControl cameraControl = capFilter as IAMCameraControl;

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

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

            return(retVal);
        }
示例#5
0
        /// <summary>
        /// サポート状況の確認
        /// </summary>
        /// <param name="prop"></param>
        /// <returns>
        ///		サポートしている場合は true を返します。
        ///		それ以外は false を返します。
        /// </returns>
        private bool Camera_IsSupported(CameraControlProperty prop)
        {
            if (CameraControl == null)
            {
                return(false);
            }

            try
            {
                #region レンジの取得を試みる.
                int min  = 0;
                int max  = 0;
                int step = 0;
                int def  = 0;
                int flag = 0;

                var hr = (HRESULT)CameraControl.GetRange(prop, ref min, ref max, ref step, ref def, ref flag);
                if (hr < HRESULT.S_OK)
                {
                    return(false);
                }

                return(true);

                #endregion
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// The event handler for the <see cref="OnVideoProcAmpPropertyChanged"/> event.
        /// Updates the video capture device with new zoom, pan, etc.
        /// </summary>
        /// <param name="property">The <see cref="CameraControlProperty"/> to be changed</param>
        /// <param name="value">The new value for the property</param>
        public void OnCameraControlPropertyChanged(CameraControlProperty property, int value)
        {
            Console.WriteLine("//ERV --- trying... ------- OnCameraControlPropertyChanged(" + property + "," + value);
            if (cameraControl == null)
            {
                return;
            }

            // Todo: Disabled focus as it turns on autofocus
            if (property.Equals(CameraControlProperty.Focus))
            {
                return;
            }

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

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

                if (value >= min && value <= max)
                {
                    Console.WriteLine("//ERV --- set it! ------- OnCameraControlPropertyChanged(" + property + "," + value);
                    cameraControl.Set(property, value, flags);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR! " + ex.ToString());
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 输出所有设备信息
        /// </summary>
        public static void OutputCaptureDeviceInfo()
        {
            foreach (FilterInfo info in new FilterInfoCollection(FilterCategory.VideoInputDevice))
            {
                String format = $"CaptureDevice Name:[{info.Name}]  MonikerString:[{info.MonikerString}]";

                VideoCaptureDevice device = new VideoCaptureDevice(info.MonikerString);

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

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

                format += $"\nCamera Control Properties:";
                for (CameraControlProperty pro = CameraControlProperty.Pan; pro <= CameraControlProperty.Focus; pro++)
                {
                    if (device.GetCameraProperty(pro, out int value, out CameraControlFlags flags))
                    {
                        if (device.GetCameraPropertyRange(pro, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags rFlags))
                        {
                            format += $"(CameraControlFlags.{pro}({(int)pro}) value:{value} minValue:{minValue} maxValue:{maxValue} stepSize:{stepSize} defaultValue:{defaultValue} flags:[{flags}] cFlags:[{rFlags}])  ";
                        }
 public CamControlProperty(CameraPropertyDescriptor descriptor, IAMCameraControl cameraControl, CameraControlProperty cameraProperty)
 {
     Descriptor      = descriptor;
     _cameraControl  = cameraControl;
     _cameraProperty = cameraProperty;
     UpdateRange();
 }
示例#9
0
        public bool GetCameraPropertyRange(CameraControlProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags controlFlags)
        {
            bool flag = true;

            if (deviceMoniker == null || string.IsNullOrEmpty(deviceMoniker))
            {
                throw new ArgumentException("Video source is not specified.");
            }
            lock (sync)
            {
                object obj = null;
                try
                {
                    obj = FilterInfo.CreateFilter(deviceMoniker);
                }
                catch
                {
                    throw new ApplicationException("Failed creating device object for moniker.");
                }
                if (!(obj is IAMCameraControl))
                {
                    throw new NotSupportedException("The video source does not support camera control.");
                }
                IAMCameraControl iAMCameraControl = (IAMCameraControl)obj;
                int range = iAMCameraControl.GetRange(property, out minValue, out maxValue, out stepSize, out defaultValue, out controlFlags);
                flag = (range >= 0);
                Marshal.ReleaseComObject(obj);
                return(flag);
            }
        }
        private static void WriteProperty(VideoCaptureDevice device, CameraControlProperty property, CameraProperty value)
        {
            if (!value.Supported)
            {
                return;
            }

            try
            {
                CameraControlFlags flags = value.Automatic ? CameraControlFlags.Auto : CameraControlFlags.Manual;
                int  v;
                bool parsed = int.TryParse(value.CurrentValue, NumberStyles.Any, CultureInfo.InvariantCulture, out v);
                if (parsed)
                {
                    device.SetCameraProperty(property, v, flags);
                }
                else
                {
                    log.ErrorFormat("Could not parse property {0}, value: {1}.", value.Identifier, value.CurrentValue);
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("Could not write property {0}. {1}.", value.Identifier, e.Message);
            }
        }
示例#11
0
        /// <summary>
        /// The event handler for the <see cref="OnVideoProcAmpPropertyChanged"/> event.
        /// Updates the video capture device with new zoom, pan, etc.
        /// </summary>
        /// <param name="property">The <see cref="CameraControlProperty"/> to be changed</param>
        /// <param name="value">The new value for the property</param>
        private void OnCameraControlPropertyChanged(CameraControlProperty property, int value)
        {
            if (this.cameraControl == null)
            {
                return;
            }

            // Todo: Disabled focus as it turns on autofocus
            if (property.Equals(CameraControlProperty.Focus))
            {
                return;
            }

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

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

                if (value >= min && value <= max)
                {
                    this.cameraControl.Set(property, value, flags);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.ProcessException(ex, false);
            }
        }
示例#12
0
        static void SetCameraValue(DsDevice[] devs, string cameraName, CameraControlProperty camProperty, int val)
        {
            IAMCameraControl camera = GetCamera(devs.Where(d => d.Name.ToLower().Contains(cameraName.ToLower())).FirstOrDefault());

            if (camera != null)
            {
                // Get the current settings from the webcam
                camera.Get(camProperty, out int v, out CameraControlFlags f);

                // If the camera value differs from the desired value, adjust it leaving flag the same.
                if (v != val)
                {
                    camera.Set(camProperty, val, f);
                    Console.WriteLine($"{cameraName} {camProperty} value set to {val}");
                }
                else
                {
                    Console.WriteLine($"{cameraName} {camProperty} value already {val}");
                }
            }
            else
            {
                Console.WriteLine($"No physical camera matching \"{cameraName}\" found");
            }
        }
示例#13
0
        static void SetCameraFlag(DsDevice[] devs, string cameraName, CameraControlProperty camProperty, CameraControlFlags flagVal)
        {
            IAMCameraControl camera = GetCamera(devs.Where(d => d.Name.Contains(cameraName)).FirstOrDefault());

            if (camera != null)
            {
                // Get the current settings from the webcam
                camera.Get(camProperty, out int v, out CameraControlFlags f);

                // If the camera property differs from the desired value, adjust it leaving value the same.
                if (f != flagVal)
                {
                    camera.Set(camProperty, v, flagVal);
                    Console.WriteLine($"{cameraName} {camProperty} set to {flagVal}");
                }
                else
                {
                    Console.WriteLine($"{cameraName} {camProperty} already {flagVal}");
                }
            }
            else
            {
                Console.WriteLine($"No camera matching \"{cameraName}\" found");
            }
        }
示例#14
0
 private void PropertyChanged(CameraControlProperty cameraControlProperty, int value)
 {
     if (OnCameraControlPropertyChanged != null)
     {
         OnCameraControlPropertyChanged(cameraControlProperty, value);
     }
 }
示例#15
0
        private static void WriteProperty(VideoCaptureDevice device, CameraControlProperty property, CameraProperty value)
        {
            CameraControlFlags flags = value.Automatic ? CameraControlFlags.Auto : CameraControlFlags.Manual;
            int v = int.Parse(value.CurrentValue, CultureInfo.InvariantCulture);

            device.SetCameraProperty(property, v, flags);
        }
示例#16
0
        internal WebcamProperty GetControlProperties(CameraControlProperty property)
        {
            HResult result = HResult.ERROR_NOT_READY;

            WebcamProperty settings = new WebcamProperty
            {
                _name        = property.ToString(),
                _controlProp = property
            };

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

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

                    control.Get(property, out settings._value, out flags);
                    settings._auto = (flags & CameraControlFlags.Auto) != 0;
                }
            }
            _base._lastError = result;
            return(settings);
        }
        public int GetParameterValue(CameraControlProperty property)
        {
            int iRet;
            CameraControlFlags cameraControlFlags;

            iAMCameraControl.Get(property, out iRet, out cameraControlFlags);
            return(iRet);
        }
 /// <summary>
 /// 获取<see cref="CameraControlProperty"/>的设置范围为作<paramref name="callBack"/>的参数
 /// </summary>
 /// <param name="cameraControlProperty"></param>
 /// <param name="callBack"></param>
 public void GetCameraControlRangeParameterAsnyc(CameraControlProperty cameraControlProperty, Action <CameraControlRangeParameter> callBack)
 {
     VideoCapturePlayer.Dispatcher.BeginInvoke((Action) delegate
     {
         callBack?.Invoke(
             VideoCapturePlayer.CameraControlSetter?.GetRangeParameterValue(cameraControlProperty));
     });
 }
示例#19
0
        public CamSetting(IAMCameraControl filter, CameraControlProperty property)
        {
            _CamFilter   = filter;
            _CamProperty = property;
            _Name        = property.ToString();

            // Update all defaults min max, etc...
            Read();
        }
 /// <summary>
 /// 设置CameraControlProperty的值
 /// 有做有效值判断
 /// </summary>
 /// <param name="cameraControlProperty"></param>
 /// <param name="perpertyValue"></param>
 public void SetParameterValue(CameraControlProperty cameraControlProperty, int perpertyValue)
 {
     if (_propertyToRangeParameter.ContainsKey(cameraControlProperty) || this.GetRangeParameterValue(cameraControlProperty) != null)
     {
         CameraControlRangeParameter cameraControlRangeParameter = _propertyToRangeParameter[cameraControlProperty];
         int ensureValue = Math.Min(Math.Max(cameraControlRangeParameter.MinValue, perpertyValue), cameraControlRangeParameter.MaxValue);
         this._cameraControl.Set(cameraControlProperty, ensureValue, CameraControlFlags.Manual);
     }
 }
 /// <summary>
 /// 获取<see cref="CameraControlProperty"/>的单值作为回调CALLBACK的参数
 /// </summary>
 /// <param name="cameraControlProperty"></param>
 /// <param name="callBack"></param>
 public void GetCameraControlParameterAsnyc(CameraControlProperty cameraControlProperty, Action <int> callBack)
 {
     VideoCapturePlayer.Dispatcher.BeginInvoke((Action) delegate
     {
         int?getValue = VideoCapturePlayer.CameraControlSetter?.GetParameterValue(cameraControlProperty);
         if (getValue != null)
         {
             callBack?.Invoke((int)getValue);
         }
     });
 }
示例#22
0
        public void SetCameraControlProperty(CameraControlProperty property, int propertyValue)
        {
            int         filterHandle;
            IBaseFilter captureFilter = null;

            filterHandle = filterGraph.FindFilterByName("Video input", out captureFilter);
            if (captureFilter != null)
            {
                IAMCameraControl iC = captureFilter as IAMCameraControl;
                ((IAMCameraControl)iC).Set(property, propertyValue, CameraControlFlags.Manual);
            }
        }
        private static CameraProperty ReadProperty(VideoCaptureDevice device, CameraControlProperty property)
        {
            CameraProperty p = new CameraProperty();

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

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

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

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

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

            return(p);
        }
        /// <summary>
        /// 获取属性单值
        /// </summary>
        /// <param name="cameraControlProperty"></param>
        /// <returns></returns>
        public int GetParameterValue(CameraControlProperty cameraControlProperty)
        {
            int iret = 0;

            try
            {
                int    hr = this._cameraControl.Get(cameraControlProperty, out int getValue, out CameraControlFlags cameraControlFlags);
                string s  = DsError.GetErrorText(hr);
                iret = getValue;
            }
            catch (Exception)
            {
            }
            return(iret);
        }
        public CameraControlRangeParameter GetRangeParameterValue(CameraControlProperty property)
        {
            CameraControlRangeParameter _model = new CameraControlRangeParameter();
            int Min, Max, Step, Default;
            CameraControlFlags _flgs;
            int hr2 = iAMCameraControl.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.CameraControlFlags = _flgs;
            return(_model);
        }
示例#26
0
        public int GetCameraControlProperty(CameraControlProperty property)
        {
            int         filterHandle;
            IBaseFilter captureFilter = null;

            filterHandle = filterGraph.FindFilterByName("Video input", out captureFilter);
            int propertyValue = 0;
            CameraControlFlags cameraControlFlags;

            if (captureFilter != null)
            {
                IAMCameraControl iC = captureFilter as IAMCameraControl;
                ((IAMCameraControl)iC).Get(property, out propertyValue, out cameraControlFlags);
            }
            return(propertyValue);
        }
示例#27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsDevice"></param>
        /// <param name="prop"></param>
        /// <param name="value"></param>
        /// <param name="flag"></param>
        public void SetCameraControl(DsDevice dsDevice, CameraControlProperty prop, int value, CameraControlFlags flag = CameraControlFlags.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);
                IAMCameraControl cameraControl = capFilter as IAMCameraControl;

                cameraControl.Set(prop, value, flag);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 /// <summary>
 /// set webcam property
 /// </summary>
 /// <param name="property">property to adjust</param>
 /// <param name="propertyValue">desired value of property</param>
 public void setCameraParameter(CameraControlProperty property, int propertyValue)
 {
     try
     {
         this.videoDeviceForCapture.SetCameraProperty(property, propertyValue, CameraControlFlags.Manual);
     }
     catch (ArgumentException argEx)
     {
         ConsoleBuddy.WriteException(argEx, "setCameraParameter");
     }
     catch (ApplicationException appEx)
     {
         ConsoleBuddy.WriteException(appEx, "setCameraParameter");
     }
     catch (NotSupportedException notSuppEx)
     {
         ConsoleBuddy.WriteException(notSuppEx, "setCameraParameter");
     }
 }
示例#29
0
        public ControlPropertyInfo GetControlPropertyInfo(CameraControlProperty prop, bool getCurrentValue)
        {
            IAMCameraControl icc = VidControl as IAMCameraControl;

            if (icc != null)
            {
                ControlPropertyInfo ret = new ControlPropertyInfo();
                if (0 == icc.GetRange(prop, out ret.Min, out ret.Max, out ret.Delta, out ret.Default, out ret.Flags))
                {
                    if (!getCurrentValue)
                    {
                        return(ret);
                    }
                    if (0 == icc.Get(prop, out ret.Value, out ret.ValueFlags))
                    {
                        return(ret);
                    }
                }
            }
            return(null);
        }
示例#30
0
        public CameraProperty(VideoCaptureDevice camera, CameraControlProperty prop)
        {
            theDevice = camera;
            camProp   = prop;
            int  defval, steps, cur;
            bool fail = false;

            try
            {
                fail = !theDevice.GetCameraPropertyRange(prop, out minLimit, out maxLimit, out steps, out defval, out camFlags);
                theDevice.GetCameraProperty(camProp, out cur, out camFlags);
            }
            catch (Exception e)
            {
                controllable = false;
            }
            if (fail)
            {
                controllable = false;
            }
        }
        /// <summary>
        /// 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 sucee 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 GetCameraPropertyRange( CameraControlProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags 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 IAMCameraControl ) )
                {
                    throw new NotSupportedException( "The video source does not support camera control." );
                }

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

                ret = ( hr >= 0 );

                Marshal.ReleaseComObject( tempSourceObject );
            }

            return ret;
        }
示例#32
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="graph">フィルタグラフ</param>
 /// <param name="property">プロパティの種別</param>
 public CxAMCameraControl(IxDSGraphBuilderProvider graph, CameraControlProperty property)
 {
     Graph = graph;
     Property = property;
 }
示例#33
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 sucee 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 GetCameraProperty( CameraControlProperty property, out int value, out CameraControlFlags controlFlags )
        {
            bool ret;

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

            lock ( _sync )
            {
                object tempSourceObject;

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

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

                var pCamControl = (IAMCameraControl) tempSourceObject;
                int hr = pCamControl.Get( property, out value, out controlFlags );

                ret = ( hr >= 0 );

                Marshal.FinalReleaseComObject( tempSourceObject );
            }

            return ret;
        }
示例#34
0
        void IAMMove(VideoCaptureDevice d, CameraControlProperty p, int i)
        {
            int v, minv, maxv, stepSize, defVal;
            CameraControlFlags f, cf;
            d.GetCameraProperty(p, out v, out f);
            d.GetCameraPropertyRange(p, out minv, out maxv, out stepSize, out defVal, out cf);

            int newv = v + i*stepSize;
            if (newv<minv)
                newv = minv;
            if (newv>maxv)
                newv = maxv;

            if (i == 0)
                newv = defVal;

            if (cf== CameraControlFlags.Manual)
            {
                d.SetCameraProperty(p, newv, CameraControlFlags.Manual);
            }
            else
            {
                MainForm.LogMessageToFile("Camera control flags are not manual");
            }
        }
示例#35
0
 private void PropertyChanged(CameraControlProperty cameraControlProperty, int value)
 {
     if (OnCameraControlPropertyChanged != null)
     {
         OnCameraControlPropertyChanged(cameraControlProperty, value);
     }
 }
示例#36
0
    /// <summary>
    /// The event handler for the <see cref="OnVideoProcAmpPropertyChanged"/> event.
    /// Updates the video capture device with new zoom, pan, etc.
    /// </summary>
    /// <param name="property">The <see cref="CameraControlProperty"/> to be changed</param>
    /// <param name="value">The new value for the property</param>
    public void OnCameraControlPropertyChanged(CameraControlProperty property, int value)
    {
      if (cameraControl == null)
        return;

      // Todo: Disabled focus as it turns on autofocus
      if (property.Equals(CameraControlProperty.Focus))
      {
        return;
      }

      int min, max, steppingDelta, defaultValue;
      CameraControlFlags flags;
      try
      {
        cameraControl.GetRange(property, out min, out max, out steppingDelta, out defaultValue, out flags);

        if (value >= min && value <= max)
          cameraControl.Set(property, value, flags);
      }
      catch (Exception)
      {
        //ErrorLogger.ProcessException(ex, false);
      }
    }
示例#37
0
文件: MainForm.cs 项目: cogorou/DSLab
        /// <summary>
        /// サポート状況の確認
        /// </summary>
        /// <param name="prop"></param>
        /// <returns>
        ///		サポートしている場合は true を返します。
        ///		それ以外は false を返します。
        /// </returns>
        private bool Camera_IsSupported(CameraControlProperty prop)
        {
            if (CameraControl == null) return false;

            try
            {
                #region レンジの取得を試みる.
                int min = 0;
                int max = 0;
                int step = 0;
                int def = 0;
                int flag = 0;

                var hr = (HRESULT)CameraControl.GetRange(prop, ref min, ref max, ref step, ref def, ref flag);
                if (hr < HRESULT.S_OK)
                    return false;

                return true;
                #endregion
            }
            catch (System.Exception)
            {
                return false;
            }
        }
示例#38
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 sucee 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 GetCameraPropertyRange( CameraControlProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags controlFlags )
        {
            bool ret = true;

            // check if source was set
            if ( ( deviceMoniker == null ) || ( string.IsNullOrEmpty( deviceMoniker ) ) )
            {
                throw new ArgumentException( "Видеоисточник не указан." );
            }

            lock ( sync )
            {
                object tempSourceObject = null;

                // create source device's object
                try
                {
                    tempSourceObject = FilterInfo.CreateFilter( deviceMoniker );
                }
                catch
                {
                    throw new ApplicationException( "Не удалось создать объект устройства." );
                }

                if ( !( tempSourceObject is IAMCameraControl ) )
                {
                    throw new NotSupportedException( "Видеисточник не поддерживает управление камерой." );
                }

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

                ret = ( hr >= 0 );

                Marshal.ReleaseComObject( tempSourceObject );
            }

            return ret;
        }