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类库是非常的强大,这里只是冰山一角,文章不足之处还请大家多多指正,欢迎提出宝贵意见和建议。谢谢。。。
  • ZoeCloud:香港BGP云服务器,1GB内存/20GB SSD空间/2TB流量/500Mbps/KVM,32元/月

    zoecloud怎么样?zoecloud是一家国人商家,5月成立,暂时主要提供香港BGP KVM VPS,线路为AS41378,并有首发永久8折优惠:HKBGP20OFF。目前,解锁香港区 Netflix、Youtube Premium ,但不保证一直解锁,谢绝以不是原生 IP 理由退款。不保证中国大陆连接速度,建议移动中转使用,配合广州移动食用效果更佳。点击进入:zoecloud官方网站地址zo...

    新版本Apache HTTP Server 2.4.51发布更新(有安全漏洞建议升级)

    今天中午的时候看到群里网友在讨论新版本的Apache HTTP Server 2.4.51发布且建议更新升级,如果有服务器在使用较早版本的话可能需要升级安全,这次的版本中涉及到安全漏洞的问题。Apache HTTP 中2.4.50的修复补丁CVE-2021-41773 修复不完整,导致新的漏洞CVE-2021-42013。攻击者可以使用由类似别名的指令配置将URL映射到目录外的文件的遍历攻击。这里...

    触摸云 26元/月 ,美国200G高防云服务器

    触摸云触摸云(cmzi.com),国人商家,有IDC/ISP正规资质,主营香港线路VPS、物理机等产品。本次为大家带上的是美国高防2区的套餐。去程普通线路,回程cn2 gia,均衡防御速度与防御,防御值为200G,无视UDP攻击,可选择性是否开启CC防御策略,超过峰值黑洞1-2小时。最低套餐20M起,多数套餐为50M,适合有防御型建站需求使用。美国高防2区 弹性云[大宽带]· 配置:1-16核· ...

    aforge net为你推荐
    混淆矩阵confusionmat函数的功能是什么?云图片云相册是什么意思deviceid如何查看自己安卓手机的Android Device ID网页微信客户端什么叫微信网页版?和电脑版是一回事吗?php论坛怎样快速在个人电脑上建立一个自己的PHP论坛服务器?欢迎页面如何设置电脑的欢迎界面?欢迎页面怎样在开机制造欢迎页面?色库赤峰中色库博红烨锌业有限公司就是冶炼厂在 赤峰的 什么地方,一 人知道吗???色库photoshop7.0怎么改PANTONE色号booth算法用Booth算法计算-4×3的4位补码乘法运算,要求写出每一步运算过程及运算结果 麻烦详细说明每一步的操作
    短域名 新加坡服务器 windows2003iso 论坛空间 40g硬盘 百兆独享 免费活动 服务器合租 腾讯总部在哪 华为云建站 免费个人主页 七牛云存储 服务器防御 万网服务器 hdchina SmartAXMT800 美国主机 美国vpn代理 优惠服务器 qq空间打开很慢 更多