aforge netAForge.net如何加到C#工程里边

aforge net  时间:2022-02-24  阅读:()

AForge.net如何加到C#工程里边

首先用到e类库下载地址 然后引用e,e.Controls(这个是控件,可以添加到工具箱中),e.Imaging,e.Video,e.Video.DirectShow; 然后直接上代码 [csharp] view plain copy print?
  • private?FilterInfoCollection?videoDevices;??
  • private?VideoCaptureDevice?videoSource;??
  • public?int?selectedDeviceIndex?=?0;??
  • private FilterInfoCollection videoDevices;
  • ? ? ? ?private VideoCaptureDevice videoSource;
  • ? ? ? ?public int selectedDeviceIndex = 0; 下面是获取设备 [csharp] view plain copy print?
  • public?FilterInfoCollection?GetDevices()??
  • {??
  • try??
  • {??
  • //枚举所有视频输入设备??
  • videoDevices?=?new?FilterInfoCollection(FilterCategory.VideoInputDevice);??
  • if?(videoDevices.Count?!=?0)??
  • {??
  • LogClass.WriteFile("已找到视频设备.");??
  • return?videoDevices;??
  • }??
  • else??
  • return?null;??
  • }??
  • catch?(Exception?ex)??
  • {??
  • LogClass.WriteFile("error:没有找到视频设备!具体原因:"?+?ex.Message);??
  • return?null;??
  • }??
  • }??
  • public FilterInfoCollection GetDevices()
  • ??????? {
  • ??????????? try
  • ??????????? {
  • ??????????????? //枚举所有视频输入设备
  • ??????????????? videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  • ??????????????? if (videoDevices.Count != 0)
  • ??????????????? {
  • ??????????????????? LogClass.WriteFile("已找到视频设备.");
  • ??????????????????? return videoDevices;
  • ??????????????? }
  • ??????????????? else
  • ??????????????????? return null;
  • ??????????? }
  • ??????????? catch (Exception ex)
  • ??????????? {
  • ??????????????? LogClass.WriteFile("error:没有找到视频设备!具体原因:" + ex.Message);
  • ??????????????? return null;
  • ??????????? }
  • ??????? } 选择设备,然后连接摄像头 [csharp] view plain copy print?
  • <p>?///?<summary>??
  • ///?连接视频摄像头??
  • ///?</summary>??
  • ///?<param?name="deviceIndex"></param>??
  • ///?<param?name="resolutionIndex"></param>??
  • ///?<returns></returns>??
  • public?VideoCaptureDevice?VideoConnect(int?deviceIndex?=?0,?int?resolutionIndex?=?0)??
  • {??
  • if?(videoDevices.Count?<=?0)??
  • return?null;??
  • selectedDeviceIndex?=?deviceIndex;??
  • videoSource?=?new?VideoCaptureDevice(videoDevices[deviceIndex].MonikerString);</p><p>????????????return?videoSource;??
  • }</p>??
  • <p>?/// <summary>
  • ??????? /// 连接视频摄像头
  • ??????? /// </summary>
  • ??????? /// <param name="deviceIndex"></param>
  • ??????? /// <param name="resolutionIndex"></param>
  • ??????? /// <returns></returns>
  • ??????? public VideoCaptureDevice VideoConnect(int deviceIndex = 0, int resolutionIndex = 0)
  • ??????? {
  • ??????????? if (videoDevices.Count <= 0)
  • ??????????????? return null;
  • ??????????? selectedDeviceIndex = deviceIndex;
  • ??????????? videoSource = new VideoCaptureDevice(videoDevices[deviceIndex].MonikerString);</p><p>??????????? return videoSource;
  • ??????? }</p> [csharp] view plain copy print?
  • //抓图,拍照,单帧??
  • public?void?GrabBitmap(string?path)??
  • {??
  • if?(videoSource?==?null)??
  • return;??
  • g_Path?=?path;??
  • videoSource.NewFrame?+=?new?NewFrameEventHandler(videoSource_NewFrame);??
  • }??
  • //抓图,拍照,单帧
  • public void GrabBitmap(string path)
  • ? ? ? ?{
  • ? ? ? ? ? ?if (videoSource == null)
  • ? ? ? ? ? ? ? ?return;
  • ? ? ? ? ? ?g_Path = path;
  • ? ? ? ? ? ?videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
  • ? ? ? ?} [csharp] view plain copy print?
  • void?videoSource_NewFrame(object?sender,?e.Video.NewFrameEventArgs?eventArgs)??
  • {??
  • Bitmap?bmp?=?(Bitmap)eventArgs.Frame.Clone();??
  • string?fullPath?=?path?+?"temp\";??
  • if?(!Directory.Exists(fullPath))??
  • Directory.CreateDirectory(fullPath);??
  • string?img?=?fullPath?+?DateTime.Now.ToString("yyyyMMdd?hhmmss")?+?".bmp";??
  • bmp.Save(img);??
  • void videoSource_NewFrame(object sender, e.Video.NewFrameEventArgs eventArgs)
  • ? ? ? ?{
  • ? ? ? ? ? ?Bitmap bmp = (Bitmap)eventArgs.Frame.Clone();
  • ? ? ? ? ? ?string fullPath = path + "temp\";
  • ? ? ? ? ? ?if (!Directory.Exists(fullPath))
  • ? ? ? ? ? ? ? ?Directory.CreateDirectory(fullPath);
  • ? ? ? ? ? ?string img = fullPath + DateTime.Now.ToString("yyyyMMdd hhmmss") + ".bmp";
  • ? ? ? ? ? ?bmp.Save(img); [csharp] view plain copy print?
  • //如果这里不写这个,一会儿会不停的拍照,??
  • videoSource.NewFrame?-=?new?NewFrameEventHandler(videoSource_NewFrame);??
  • }??
  • //如果这里不写这个,一会儿会不停的拍照,
  • ? ? ? ? ? ?videoSource.NewFrame -= new NewFrameEventHandler(videoSource_NewFrame);
  • ? ? ? ?} 这样就完成了操作摄像头的工作 但是发现一个问题,如果要拍照得到的照片先要处理在保存,这里就有问题了,所以需要在界面前台中添加控件,医用e.Controls,然后添加到工具箱,然后将VideoSourcePlayer控件拖到窗体中,想要得到单张图像处理: Bitmap bmp = videoSourcePlayer1.GetCurrentFrame(); 这样就可以拿来处理了,e类库是非常的强大,这里只是冰山一角,文章不足之处还请大家多多指正,欢迎提出宝贵意见和建议。谢谢。。。
  • 美国云服务器 1核 1G 30M 50元/季 兆赫云

    【双十二】兆赫云:全场vps季付六折优惠,低至50元/季,1H/1G/30M/20G数据盘/500G流量/洛杉矶联通9929商家简介:兆赫云是一家国人商家,成立2020年,主要业务是美西洛杉矶联通9929线路VPS,提供虚拟主机、VPS和独立服务器。VPS采用KVM虚拟架构,线路优质,延迟低,稳定性强。是不是觉得黑五折扣力度不够大?还在犹豫徘徊中?这次为了提前庆祝双十二,特价推出全场季付六折优惠。...

    Ftech:越南vps,2核/2G/20G SSD/1Gbps不限流量/可安装Windows系统,$12.5月

    ftech怎么样?ftech是一家越南本土的主机商,成立于2011年,比较低调,国内知道的人比较少。FTECH.VN以极低的成本提供高质量服务的领先提供商之一。主营虚拟主机、VPS、独立服务器、域名等传统的IDC业务,数据中心分布在河内和胡志明市。其中,VPS提供1G的共享带宽,且不限流量,还可以安装Windows server2003/2008的系统。Ftech支持信用卡、Paypal等付款,但...

    提速啦(900元/月),杭州BGP E5-2665/89*2 32核 48G 100G防御

    提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑提速啦的市场定位提速啦主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。提速啦的售后保证提速啦退款 通过于合作商的友好协商,云服务器提供3天内全额退款,超过3天不退款 物理机部分支持当天全额退款提速啦提现 充...

    aforge net为你推荐
    元宝网vap数字资产是不是传销微信收款语音播报怎么设置两部手机微信收款语音播报怎么设置论坛源码求高手推荐一个好的论坛源码?要可以购买版权的那种,要便宜的知识库管理系统急求一款电子文档管理系统,有好用的推荐下~?策略组简述组策略的概念 急急急editplus破解版手机的常用软件和ngage的破解版丁奇海贼王里“D”的意思是什么?php论坛怎样快速在个人电脑上建立一个自己的PHP论坛服务器?民生电商民生电商与传统的电商有什么区别?ruby语言Ruby是一种什么样的语言,主要用来做什么,现在有一家公司让我从java转ruby,我很犹豫?
    域名到期查询 欧洲欧洲vps 香港加速器 韩国俄罗斯 vmsnap3 2017年黑色星期五 win8升级win10正式版 亚洲小于500m 元旦促销 共享主机 cdn加速原理 shopex主机 域名dns 域名与空间 lick 云服务器比较 华为云建站 电信宽带测速软件 测试网速命令 云销售系统 更多