使用c#自带的DirectShow类对基于uvc协议的摄像头进行亮度参数的更改时,需要打开其自带的一个页面,如果想要实现在代码中更改需要使用DirectShow的扩展类。首先,需要在VideoCaptureDevice.cs
类里添加几个方法

/// <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 setif ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))){throw new ArgumentException("Video source is not specified.");}lock (sync){object tempSourceObject = null;// create source device's objecttry{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;}/// <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 setif ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))){throw new ArgumentException("Video source is not specified.");}lock (sync){object tempSourceObject = null;// create source device's objecttry{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;}/// <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 setif ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))){throw new ArgumentException("Video source is not specified.");}lock (sync){object tempSourceObject = null;// create source device's objecttry{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;}

然后,需要新建类VideoProcAmpProperty(和VideoCaptureDevice.cs在同一目录)

 using System;/// <summary>/// The enumeration specifies a setting on a camera./// </summary>public enum VideoProcAmpProperty{/// <summary>/// Brightness control./// </summary>Brightness = 0,/// <summary>/// Contrast control./// </summary>Contrast,/// <summary>/// Hue control./// </summary>Hue,/// <summary>/// Saturation control./// </summary>Saturation,/// <summary>/// Sharpness control./// </summary>Sharpness,/// <summary>/// Gamma control./// </summary>Gamma,/// <summary>/// ColorEnable control./// </summary>ColorEnable,/// <summary>/// WhiteBalance control./// </summary>WhiteBalance,/// <summary>/// BacklightCompensation control./// </summary>BacklightCompensation,/// <summary>/// Gain control./// </summary>Gain}/// <summary>/// The enumeration defines whether a camera setting is controlled manually or automatically./// </summary>[Flags]public enum VideoProcAmpFlags{/// <summary>/// No control flag./// </summary>None = 0x0,/// <summary>/// Auto control Flag./// </summary>Auto = 0x0001,/// <summary>/// Manual control Flag./// </summary>Manual = 0x0002}

最后需要在Internals文件夹下新建IAMVideoProcAmp类

 using System;using System.Runtime.InteropServices;/// <summary>/// The IAMVideoProcAmp interface controls camera settings such as brightness, contrast, hue,/// or saturation. To obtain this interface, query the filter that controls the camera./// </summary>[ComImport,Guid("C6E13360-30AC-11D0-A18C-00A0C9118956"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]internal interface IAMVideoProcAmp{/// <summary>/// Gets the range and default value of a specified camera property./// </summary>////// <param name="Property">Specifies the property to query.</param>/// <param name="pMin">Receives the minimum value of the property.</param>/// <param name="pMax">Receives the maximum value of the property.</param>/// <param name="pSteppingDelta">Receives the step size for the property.</param>/// <param name="pDefault">Receives the default value of the property. </param>/// <param name="pCapsFlags">Receives a member of the VideoProcAmpFlags enumeration, indicating whether the property is controlled automatically or manually.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int GetRange([In] VideoProcAmpProperty Property,[Out] out int pMin,[Out] out int pMax,[Out] out int pSteppingDelta,[Out] out int pDefault,[Out] out VideoProcAmpFlags pCapsFlags);/// <summary>/// Sets a specified property on the camera./// </summary>////// <param name="Property">Specifies the property to set.</param>/// <param name="lValue">Specifies the new value of the property.</param>/// <param name="Flags">Specifies the desired control setting, as a member of the VideoProcAmpFlags enumeration.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int Set([In] VideoProcAmpProperty Property,[In] int lValue,[In] VideoProcAmpFlags Flags);/// <summary>/// Gets the current setting of a camera property./// </summary>////// <param name="Property">Specifies the property to retrieve.</param>/// <param name="lValue">Receives the value of the property.</param>/// <param name="Flags">Receives a member of the VideoProcAmpFlags enumeration./// The returned value indicates whether the setting is controlled manually or automatically.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int Get([In] VideoProcAmpProperty Property,[Out] out int lValue,[Out] out VideoProcAmpFlags Flags);}

然后进行重新生成解决方案并在想要使用扩展类的项目中更改引用即可使用DirectShow的扩展类。
DirectShow的源代码可从c#的包管理器中点击DirectShow的源路径获取。
嫌麻烦的可以去我上传的资源进行下载。

C#使用Aforge对uvc协议摄像头亮度属性的更改相关推荐

  1. linux下uvc协议访问usb摄像头,Ubuntu调用USB摄像头

    FreeBSD Webcam:传送门 1 查看摄像头USB驱动 CMD ls /dev/v* Result /dev/vcs /dev/vcs4 /dev/vcsa1 /dev/vcsa5 /dev/ ...

  2. Android 外接基于UVC协议的摄像头并实现预览

    先来一段从网上找到的理论知识,对UVC协议有初步的印象 UVC协议:USB Video Class,USB视频类,是一种为USB视频捕获设备定义的协议标准. Android 平台支持使用即插即用的 U ...

  3. USB UVC协议分析

    USB描述符分析软件 USB Device Viewer.USBlyzer.BusHound. #define USB_DT_DEVICE 0x01 #define USB_DT_CONFIG    ...

  4. 1.[RK3288][Android6.0] USB UVC 协议简结

    Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 UVC协议官方文档: http://www.usb.org/developers/docs/dev ...

  5. Opencv 3.4.2 +VS2015用摄像头采集图片并更改分辨率出现黑边的解决办法

    Opencv 3.4.2 +VS2015用摄像头采集图片并更改分辨率出现黑边的解决办法 CSDN中已经有相当部分的博客写了如何利用OpenCV通过摄像头获取并保存图片,此处不再赘述.我遇到的问题是利用 ...

  6. UVC协议USB视频捕获设备定义

    UVC(USB Video Class) USB视频捕获设备 UVC,全称为:USB video class 或USB video device class UVC是Microsoft与另外几家设备厂 ...

  7. android 摄像头亮度,[Android相机]通过手机摄像头识别环境亮度

    版权声明:本文使用https://creativecommons.org/licenses/by-nc-nd/4.0/规定的<署名-非商业性使用-禁止演绎 4.0 国际>协议 https: ...

  8. EasyPusher进行Android UVC外接摄像头直播推送实现方法

    最近EasyPusher针对UVC摄像头做了适配.我们结合了UVCCamera与EasyPusher,支持将UVC摄像头的视频推送到RTSP服务器上.在此特别感谢UVCCamera这个牛逼的项目! 来 ...

  9. 安防RTSP协议摄像头实现WEB端无插件直播流媒体服务EasyNVR实现海康大华宇视摄像头网页播放的方法

    背景分析:微信直播的兴起 进入移动互联网时代以来,企业微信公众号已成为除官网以外非常重要的宣传渠道,当3.2亿直播用户与9亿微信用户的势能累加,在微信上开启直播已成为越来越多企业的必然选择. Easy ...

  10. c# 利用AForge.NET组件操作摄像头

    AForge.NET是一个专门为开发者和研究者基于C#框架设计的,这个框架提供了不同的类库和关于类库的资源,还有很多应用程序例子,包括计算机视觉与人工智能,图像处理,神经网络,遗传算法,机器学习,机器 ...

最新文章

  1. 使用version遇到的那些坑
  2. 人,是否应该不要去好高骛远
  3. ROStopic 通信方式
  4. 近世代数--素理想和极大理想--有单位元的交换环,每个极大理想都是素理想
  5. Jquery中使用ajax传json参数并从SpringBoot后台Controller返回消息
  6. python pip安装失败vtk_安装最新的VTK库验证安装出错该怎么解决
  7. MacBook 推出移动硬盘时总是提示有程序在使用它,如何解决?
  8. 源码分析参考:Scheduler
  9. 如何使用scikit-learn工具来进行PCA降维
  10. 探测能源、跨洲安全通信……你所想不到的量子技术!
  11. 苹果iOS系统源码思考:对象的引用计数存储在哪里?--从runtime源码得到的启示...
  12. 【转】对JavaScript调用堆栈和setTimeout用法的深入研究
  13. vmware workstation 12 打开vm14 不兼容问题解决
  14. 阵列matlab程序,阵列信号处理的理论和应用 原书matlab 程序.rar
  15. 第25版 OpenStack Yoga 已发布:稳定性与创新并重
  16. oracle client 客户端 安装 oracle客户端安装
  17. 电动自行车新国标正式发布,推动电池产业转型升级
  18. 高通运行linux,高通、mtk及Linux平台的一点个人感受
  19. YML(YAML)语法(文件后缀为.yml格式)
  20. PL/0 语言简介、PL/0 文法

热门文章

  1. VS2013密钥 VS2013专业版密钥 VS2013旗舰版密钥
  2. c语言 sd卡编程,嵌入式系统基础 嵌入式系统中的C语言编程基础 烧写Superboot到SD卡.docx...
  3. SpringBoot+Vue的房屋租赁系统(含前后台)
  4. java完全自学手册pdf,附答案+考点
  5. 安卓投屏大师_玩转手机投屏,我推荐三款不一样的投屏工具!
  6. java十字链表存储,图的十字链表存储结构
  7. Day22——十字链表
  8. 一种自适应模拟退火粒子群优化算法-附代码
  9. python实现自动化不停打电话
  10. Linux教程(第5版)孟庆昌版 课后答案