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类库是非常的强大,这里只是冰山一角,文章不足之处还请大家多多指正,欢迎提出宝贵意见和建议。谢谢。。。
  • iHostART:罗马尼亚VPS/无视DMCA抗投诉vps;2核4G/40GB SSD/100M端口月流量2TB,€20/年

    ihostart怎么样?ihostart是一家国外新商家,主要提供cPanel主机、KVM VPS、大硬盘存储VPS和独立服务器,数据中心位于罗马尼亚,官方明确说明无视DMCA,对版权内容较为宽松。有需要的可以关注一下。目前,iHostART给出了罗马尼亚vps的优惠信息,罗马尼亚VPS无视DMCA、抗投诉vps/2核4G内存/40GB SSD/100M端口月流量2TB,€20/年。点击直达:ih...

    台湾CN2云服务器 2核2G 5M 5IP 台湾物理服务器 E5x2 64G 20M 5IP

    提速啦(www.tisula.com)是赣州王成璟网络科技有限公司旗下云服务器品牌,目前拥有在籍员工40人左右,社保在籍员工30人+,是正规的国内拥有IDC ICP ISP CDN 云牌照资质商家,2018-2021年连续4年获得CTG机房顶级金牌代理商荣誉 2021年赣州市于都县创业大赛三等奖,2020年于都电子商务示范企业,2021年于都县电子商务融合推广大使。资源优势介绍:Ceranetwo...

    Friendhosting四五折促销,VPS半年付7.5欧元起

    Friendhosting发布了针对“系统管理日”(每年7月的最后一个星期五)的优惠活动,针对VPS主机提供55%的优惠(相当于四五折),支持1-6个月付款使用,首付折扣非永久,优惠后最低套餐首半年7.18欧元起。这是一家保加利亚主机商,成立于2009年4月,商家提供VDS和独立服务器租用等,数据中心目前可选美国洛杉矶、保加利亚、乌克兰、荷兰、拉脱维亚、捷克和波兰等8个地区机房。下面以最低套餐为例...

    aforge net为你推荐
    开票系统怎样开普通发票系统附清单weakhashmap在Java中ArrayList、LinkedList、HashMap的区别是什么md5值游戏安装包的MD5值怎么用?策略组组策略是什么,命令是什么???郭凡生慧聪网公司怎么样郭凡生慧聪的董事长是谁?跟马云比,怎么样?郭凡生馬云的簡介3Qbindserviceonserviceconnected什么时候执行jdk6Java 中的 JDK 6 Update 6 到哪下载啊 ? 有一点急spawning急救!编好C++程序后(确认无误),再编译时总出现error spawning 是什么意思?是不是系统出了问题
    域名注册公司 服务器租用托管 域名主机基地 免费com域名申请 中国万网虚拟主机 google电话 缓存服务器 商家促销 牛人与腾讯客服对话 好看qq空间 中国智能物流骨干网 天互数据 193邮箱 股票老左 183是联通还是移动 网站卫士 东莞服务器 国外ip加速器 网站加速软件 英雄联盟台服官网 更多