现在位置首页 / 项目实战 /正文

Aforge.net连接摄像头并配置参数使用代码

作者: IT小兵 | 2016年8月22日| 热度:℃ | 评论: |参与:

 以前分享一篇[wpf教程-AForge.net调用摄像头/切换摄像头/保存图片及像素问题] ,今天分享一段aforge连接摄像头,并配置摄像头图像参数和相机控制的代码。

连接相机:

  public void cameraOpen()
        {
  
            // 设定初始视频设备  
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count > 0)
            {   // 默认设备  
            //    CloseCaptureDevice();
                cb.ItemsSource = videoDevices;
                cb.SelectedValuePath = "MonikerString";
                cb.DisplayMemberPath = "Name";
                 cb.SelectedIndex = 1;
                UsbVideo = new VideoCaptureDevice(videoDevices[1].MonikerString);
                camera_Chemistry.vp.videoMonkeyName = videoDevices[1].MonikerString;
                sourcePlayer.VideoSource = UsbVideo;
                UsbVideo.VideoResolution = UsbVideo.VideoCapabilities[0];
                UsbVideo.SnapshotFrame += UsbVideo_SnapshotFrame;
                UsbVideo.NewFrame += UsbVideo_NewFrame;
                sourcePlayer.Start();
            }
            else
            {
                //button_Play.IsEnabled = false;
                //button_Capture.IsEnabled = false;
            }
        }

 

设置图像和控制相机

     #region 视频相关
        private void GanHuaxueCamera()
        {
            camera_Chemistry.Cameratype = CameraType.USB;
            camera_Chemistry.Usage = CameraUsage.干化学;
            camera_Chemistry.videoDevice = UsbVideo;
            camera_Chemistry.ReadProperty(UsbVideo);
            stcvediosliders.Children.Clear();
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Brightness, "亮度", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Gain, "增益", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Contrast, "对比度", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Hue, "色调", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Saturation, "饱和度", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Sharpness, "清晰度", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_Gamma, "伽马值", true);
        //    InitVideoParam(VideoProcAmpProperty.VideoProcAmp_ColorEnable, "对比度", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_WhiteBalance, "白平衡", true);
            InitVideoParam(VideoProcAmpProperty.VideoProcAmp_BacklightCompensation, "逆光对比", true);
            InitVideoParam(VideoProcAmpProperty.VideoProAmp_Red, "红色分量", true);
            InitVideoParam(VideoProcAmpProperty.VideoProAmp_Green, "绿色分量", true);
            InitVideoParam(VideoProcAmpProperty.VideoProAmp_Blue, "蓝色分量", true);
            //  InitVideoParam(VideoProcAmpProperty.VideoProAmp_Electric, "对比度", true);
            InitCameraParam(CameraControlProperty.Pan, "全景", true);
            InitCameraParam(CameraControlProperty.Iris, "光圈", true);
            InitCameraParam(CameraControlProperty.Roll, "Roll_", true);
            InitCameraParam(CameraControlProperty.Tilt, "倾斜", true);
            InitCameraParam(CameraControlProperty.Exposure, "曝光", true);
            InitCameraParam(CameraControlProperty.Focus, "焦点", true);
            InitCameraParam(CameraControlProperty.Zoom, "缩放", true);
            InitCameraParam(CameraControlProperty.Roll, "滚动", true);
            InitCameraParam(CameraControlProperty.LowCompensation, "低亮度补偿", true);
            InitCameraParam(CameraControlProperty.DeNoise, "降噪", true);
        }
        private void InitCameraParam(CameraControlProperty cp, string vslidername, bool Check)
        {
            CameraProperty vpp = (CameraProperty)camera_Chemistry.CameraProperty[cp]; 
            if (vpp == null) return;
            VideoSlider vs = new VideoSlider(camera_Chemistry);
            vs.Name = vslidername;
            vs.VideoProcAmpPropertyItemName = vslidername;
            if (vpp != null)
            {
                vs.CameraPropertyCustom = vpp;
            }
            stccanmreraliders.Children.Add(vs);
        }
        /// <summary>
        /// //////////////////////
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="HBR"></param>
        /// <param name="Check"></param>
        private void InitVideoParam(VideoProcAmpProperty cp, string vslidername, bool Check)
        {
            VideoAMPProperty vpp = (VideoAMPProperty)camera_Chemistry.videoAMPProperty[cp];
            VideoSlider vs = new VideoSlider(camera_Chemistry);
            vs.Name =vslidername;
            vs.VideoProcAmpPropertyItemName = vslidername;
            if (vpp != null)
            {
                vs.AmpProperty = vpp;
            }
            stcvediosliders.Children.Add(vs);
        }

 

点击阅读本文所属分类的更多文章: 项目实战 。和高手一起交流:346717337
友荐云推荐

未注明转发、原文均为本站原创。分享本文请注明 原文链接

给您更多信息和帮助

在这里您可以找到更多:

技术交流群:346717337 Jquery插件交流

投稿:suchso@vip.qq.com

承接:企业网站门户/微网站/微商城/CMS系统/微信公众号运营/业务咨询

抢天猫双11红包
推荐使用阿里云服务器
echarts教程系列
本月最热文章

微信扫一扫,徜徉悠嘻网,您的休闲乐园

微信公众号:快乐每一天

随机文章
标签

技术交流群:346717337

投稿:suchso@vip.qq.com

专业专注:企业网站门户/微网站/微商城/CMS系统/微信公众号运营/付费问题咨询