Aforge.net类库调用摄像头拍照(C#)
来源:互联网 发布:ubuntu apt get 换源 编辑:程序博客网 时间:2024/06/05 13:13
官网下载library
http://www.aforgenet.com/framework/downloads.html
添加引用:
AForge.Imaging ——图像处理和过滤器
AForge.Video ——视频处理类库
AForge.Controls—— 图像显示控件
工具箱添加aforge的组件:
添加组件:
先加载列出来所有可用摄像头放到combobox,从combobox选择要用的摄像头
思路:先列出所有摄像头--打开摄像头--抓拍
using System;using System.Drawing;using System.Windows.Forms;using AForge.Video.DirectShow;namespace Aforge{ public partial class Form1 : DevComponents.DotNetBar.OfficeForm { public Form1() { InitializeComponent(); } private FilterInfoCollection videoDevices; private VideoCaptureDevice videoSource; private int Indexof = 0; //添加所有的摄像头到combobox列表里 private void Camlist() { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { MessageBox.Show("未找到摄像头设备"); } foreach (FilterInfo device in videoDevices) { Cameralist.Items.Add(device.Name); } } //选择要调用的摄像头,捕获视频并展示到videoSourcePlayer1 private void Device_Click(object sender, EventArgs e) { Indexof = Cameralist.SelectedIndex; if (Indexof < 0) { MessageBox.Show("请选择一个摄像头"); return; } this.pictureBox1.Visible = false; this.videoSourcePlayer1.Visible = true; //videoDevices[Indexof]确定出用哪个摄像头了。 videoSource = new VideoCaptureDevice(videoDevices[Indexof].MonikerString); //设置下像素,这句话不写也可以正常运行: videoSource.VideoResolution = videoSource.VideoCapabilities[Indexof]; //在videoSourcePlayer1里显示 videoSourcePlayer1.VideoSource = videoSource; videoSourcePlayer1.Start(); } //拍照//这里多了一个pictureBox1,想的是展示下抓拍的照片 private void buttonX1_Click(object sender, EventArgs e) { if (videoSource == null) { MessageBox.Show("请先打开摄像头"); return; } //videoSourcePlayer继承Control父类,定义 GetCurrentVideoFrame能输出bitmap Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame(); pictureBox1.Image = bitmap; this.videoSourcePlayer1.Visible = false; this.pictureBox1.Visible = true; //这里停止摄像头继续工作 当然videoSourcePlayer里也定义了 Stop();用哪个都行 videoSourcePlayer1.Stop(); // videoSourcePlayer1.SignalToStop(); videoSourcePlayer1.WaitForStop(); } private void buttonX2_Click(object sender, EventArgs e) { // 加载出来所有的摄像头 Camlist(); } }}
(新人学习笔记,思路粗劣,让大家见笑了。)
阅读全文
0 0
- Aforge.net类库调用摄像头拍照(C#)
- C# 利用AForge.NET 调用电脑摄像头进行拍照
- AForge类库调用摄像头
- C# 使用AForge调用笔记本摄像头拍照
- C#WPF使用AForge类库操作USB摄像头拍照并保存
- C# 调用AForge类库操作摄像头
- 在WPF中使用AForge.net控制摄像头拍照
- C#学习之 调用 AForge.NET Framework 启动摄像头
- C#学习之 调用 AForge.NET框架启动摄像头抓拍
- Aforge.net摄像头旋转代码
- C# 启动Windows摄像头类 使用Aforge.net
- AForge.NET IterativeThreshold (C#)
- AForge.NET DirectShow (C#)
- AForge.NET TransformFromPolar (C#)
- AForge.NET QuadrilateralTransformation (C#)
- AForge.NET BayerFilter (C#)
- AForge.NET FillHoles (C#)
- AForge.NET CornersMarker (C#)
- java面试宝典:留着慢慢看
- spring配置
- HDU4694 支配树裸题 Important Sisters
- 如何去掉a标签或者input标签点击时候出现的虚线框
- 蒟蒻复习之—–STL
- Aforge.net类库调用摄像头拍照(C#)
- Android Studio如何更改JDK和SDK的路径?
- 设计一个具有getMin()功能的栈
- LightOJ
- Risk UVA
- iOS UITableView reloadData 视图漂移或者闪动解决方法
- 深入理解Spark之ListenerBus监听器
- 洛谷P3410 拍照
- 数列+车辆销售