C#读取摄像头处理图片AForge

5 篇文章 8 订阅
4 篇文章 1 订阅

上一篇文章是用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();
        }


    }
}

还有其他功能的需求的话就就参考最上面分享的那个链接就行了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值