C#读取摄像头处理图片AForge
2015-12-08 21:27
435 查看
上一篇文章是用avicap读取摄像头处理图片的,很麻烦,而本篇文章是用新的方法AForge,该方法是很方便很好用的,其中有一篇文章很好,链接如下:
http://blog.csdn.net/chenhongwu666/article/details/40594365
该文章是讲如何使用AForge的,而且也有程序,主要分几步:
(1)到该网址
http://www.aforgenet.com/ 下载并安装AForge.NETFramework.exe文件
(2)在安装路径下的AForge.NET文件夹---Framework---Release文件夹中,把AForge.Controls.dll,AForge.dll,AForge.Imaging.dll,AForge.Video.dll,AForge.Video.DirectShow.dll等几个库文件copy到我们工程根目录下。
(3)对于VS系列软件的使用者来说,要把AForge.Controls.dll(工具)添加到左侧的工具箱中,方法如下:
A.工具箱右键---选择项----.NET Framework组件----浏览---到根目录下选择上面dll库中的,AForge.Controls.dll库,因为这是一个控件。
(4)添加成功后,会出现VideoSourcePlayer控件,我们主要用的就是他,该控件的功能比pictureBox还要强大。
(5)右键工程项目----添加引用---把根目录下的几个dll文件都加进来。
(6)在using中加入这个几个dll引用。
基本上配置完成了,下面就是程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Imaging;
using AForge.Imaging.Filters;
namespace Camera
{
public partial class Form1 : Form
{
private FilterInfoCollection videoDevices;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new System.Drawing.Point(0, 0);
this.WindowState = FormWindowState.Maximized;
try
{
// 枚举所有视频输入设备
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
throw new ApplicationException();
foreach (FilterInfo device in videoDevices)
{
tscbxCameras.Items.Add(device.Name);
}
tscbxCameras.SelectedIndex = 0;
}
catch (ApplicationException)
{
tscbxCameras.Items.Add("No local capture devices");
videoDevices = null;
}
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
CameraConn();
}
//测试
int count;
//测试
private void CameraConn()
{
VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString);
videoSource.DesiredFrameSize = new Size(640,640);//320, 240
videoSource.DesiredFrameRate = 1;
videPlayer.VideoSource = videoSource;
videPlayer.Start();
//测试
count = videoSource.BytesReceived;
//测试
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
videPlayer.SignalToStop();
videPlayer.WaitForStop();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
toolStripButton2_Click(null, null);
}
private void videPlayer_MouseDown(object sender, MouseEventArgs e)
{
this.textBox1.Text = count.ToString();
}
}
}
还有其他功能的需求的话就就参考最上面分享的那个链接就行了。
http://blog.csdn.net/chenhongwu666/article/details/40594365
该文章是讲如何使用AForge的,而且也有程序,主要分几步:
(1)到该网址
http://www.aforgenet.com/ 下载并安装AForge.NETFramework.exe文件
(2)在安装路径下的AForge.NET文件夹---Framework---Release文件夹中,把AForge.Controls.dll,AForge.dll,AForge.Imaging.dll,AForge.Video.dll,AForge.Video.DirectShow.dll等几个库文件copy到我们工程根目录下。
(3)对于VS系列软件的使用者来说,要把AForge.Controls.dll(工具)添加到左侧的工具箱中,方法如下:
A.工具箱右键---选择项----.NET Framework组件----浏览---到根目录下选择上面dll库中的,AForge.Controls.dll库,因为这是一个控件。
(4)添加成功后,会出现VideoSourcePlayer控件,我们主要用的就是他,该控件的功能比pictureBox还要强大。
(5)右键工程项目----添加引用---把根目录下的几个dll文件都加进来。
(6)在using中加入这个几个dll引用。
基本上配置完成了,下面就是程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Imaging;
using AForge.Imaging.Filters;
namespace Camera
{
public partial class Form1 : Form
{
private FilterInfoCollection videoDevices;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new System.Drawing.Point(0, 0);
this.WindowState = FormWindowState.Maximized;
try
{
// 枚举所有视频输入设备
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
throw new ApplicationException();
foreach (FilterInfo device in videoDevices)
{
tscbxCameras.Items.Add(device.Name);
}
tscbxCameras.SelectedIndex = 0;
}
catch (ApplicationException)
{
tscbxCameras.Items.Add("No local capture devices");
videoDevices = null;
}
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
CameraConn();
}
//测试
int count;
//测试
private void CameraConn()
{
VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString);
videoSource.DesiredFrameSize = new Size(640,640);//320, 240
videoSource.DesiredFrameRate = 1;
videPlayer.VideoSource = videoSource;
videPlayer.Start();
//测试
count = videoSource.BytesReceived;
//测试
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
videPlayer.SignalToStop();
videPlayer.WaitForStop();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
toolStripButton2_Click(null, null);
}
private void videPlayer_MouseDown(object sender, MouseEventArgs e)
{
this.textBox1.Text = count.ToString();
}
}
}
还有其他功能的需求的话就就参考最上面分享的那个链接就行了。
相关文章推荐
- c#调用COM组件
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#实现子窗体与父窗体通信方法实例总结
- C#通用邮件发送类分享
- C#中this的用法集锦
- C#数据结构之顺序表(SeqList)实例详解
- C#.NET获取拨号连接的宽带连接方法
- C#异步绑定数据实现方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#比较二个数组并找出相同或不同元素的方法
- C#生成饼形图及添加文字说明实例代码
- C#判等对象是否相等的方法汇总
- C#简单的向量用法实例教程