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类库是非常的强大,这里只是冰山一角,文章不足之处还请大家多多指正,欢迎提出宝贵意见和建议。谢谢。。。
  • CloudCone:KVM月付1.99美元起,洛杉矶机房,支持PayPal/支付宝

    CloudCone的[2021 Flash Sale]活动仍在继续,针对独立服务器、VPS或者Hosted email,其中VPS主机基于KVM架构,最低每月1.99美元,支持7天退款到账户,可使用PayPal或者支付宝付款,先充值后下单的方式。这是一家成立于2017年的国外VPS主机商,提供独立服务器租用和VPS主机,其中VPS基于KVM架构,多个不同系列,也经常提供一些促销套餐,数据中心在洛杉...

    Hostodo美国独立日优惠套餐年付13.99美元起,拉斯维加斯/迈阿密机房

    Hostodo又发布了几款针对7月4日美国独立日的优惠套餐(Independence Day Super Sale),均为年付,基于KVM架构,采用NVMe硬盘,最低13.99美元起,可选拉斯维加斯或者迈阿密机房。这是一家成立于2014年的国外VPS主机商,主打低价VPS套餐且年付为主,基于OpenVZ和KVM架构,产品性能一般,支持使用PayPal或者支付宝等付款方式。商家客服响应也比较一般,推...

    舍利云30元/月起;美国CERA云服务器,原生ip,低至28元/月起

    目前舍利云服务器的主要特色是适合seo和建站,性价比方面非常不错,舍利云的产品以BGP线路速度优质稳定而著称,对于产品的线路和带宽有着极其严格的讲究,这主要表现在其对母鸡的超售有严格的管控,与此同时舍利云也尽心尽力为用户提供完美服务。目前,香港cn2云服务器,5M/10M带宽,价格低至30元/月,可试用1天;;美国cera云服务器,原生ip,低至28元/月起。一、香港CN2云服务器香港CN2精品线...

    aforge net为你推荐
    抓包什么是"抓包"?怎样"抓包"?settimervc++6.0 settimer函数是怎么用的啊,能给个例子在讲解一下行么策略组组策略是什么,命令是什么???jdk6JDK6和JDK7两个版本有什么区别,初学者选那个好?数秦科技数秦科技旗下有哪些区块链项目?imqq官网如何伸请QQ?弹幕网站A站B站网址是什么,国内很出名嗎?有什么网站特点..问卷星登陆请问问卷星怎么设置答题时间?什么是SOA什么是中子刀?您了解吗?中科红旗北京中科红旗软件技术有限公司的介绍
    免备案虚拟主机 域名主机空间 mediafire下载工具 创宇云 线路工具 网页背景图片 阿里云浏览器 web服务器架设 网站cdn加速 服务器是干什么的 php空间购买 流媒体加速 新世界服务器 域名dns 便宜空间 中国linux 中国联通宽带测速 xuni 登陆qq空间 域名和主机 更多