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类库是非常的强大,这里只是冰山一角,文章不足之处还请大家多多指正,欢迎提出宝贵意见和建议。谢谢。。。
  • 提速啦(69元起)香港大带宽CN2+BGP独享云服务器

    香港大带宽服务器香港大带宽云服务器目前市场上可以选择的商家十分少,这次给大家推荐的是我们的老便宜提速啦的香港大带宽云服务器,默认通用BGP线路(即CN2+BGP)是由三网直连线路 中国电信骨干网以及HGC、NTT、PCCW等国际线路混合而成的高品质带宽(精品带宽)线路,可有效覆盖全球200多个国家和地区。(适用于绝大部分应用场景,适合国内外访客访问,域名无需备案)提速啦官网链接:点击进入香港Cer...

    GigsGigsCloud($26/年)KVM-1GB/15G SSD/2TB/洛杉矶机房

    GigsGigsCloud新上了洛杉矶机房国际版线路VPS,基于KVM架构,采用SSD硬盘,年付最低26美元起。这是一家成立于2015年的马来西亚主机商,提供VPS主机和独立服务器租用,数据中心包括美国洛杉矶、中国香港、新加坡、马来西亚和日本等。商家VPS主机基于KVM架构,所选均为国内直连或者优化线路,比如洛杉矶机房有CN2 GIA、AS9929或者高防线路等。下面列出这款年付VPS主机配置信息...

    pacificrack:2021年七夕VPS特别促销,$13.14/年,2G内存/2核/60gSSD/1T流量,支持Windows

    pacificrack官方在搞2021年七夕促销,两款便宜vps给的配置都是挺不错的,依旧是接入1Gbps带宽,KVM虚拟、纯SSD raid10阵列,支持包括Linux、Windows 7、10、server2003、2008、2012、2016、2019在内多种操作系统。本次促销的VPS请特别注意限制条件,见本文末尾!官方网站:https://pacificrack.com支持PayPal、支...

    aforge net为你推荐
    知识库管理系统知识库管理软件与档案管理软件有什么区别查字网衾字怎么读音是什么mindmanager破解版谁有MindManager破解版的李昊天铠甲勇士2刑天的李昊天秘密是什么备忘录模式手机如何设置备忘录提醒jdk6我是win7的系统,安装了JDK6,环境配置都正确了。但是安装完没有应用程序啊~radius认证电信或网通的RADIUS认证都记录些什么?谁能说说ISP的宽带帐号检查流程微信论坛手机微信论坛如何实现imqq官网中国v家官网网址清除电脑垃圾怎么删除电脑垃圾?
    免费美国主机 国外域名 域名服务dns的主要功能为 泛域名绑定 asp.net主机 mach5 suspended xfce 网站实时监控 debian7 mysql主机 cpanel空间 蜗牛魔方 godaddy域名证书 789电视网 135邮箱 佛山高防服务器 无限流量 网页提速 网络速度 更多