• 大小: 356KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: 其他
  • 标签: AForge  摄像头  源码  

资源简介

AForge摄像头功能源码

资源截图

代码片段和文件信息

using AForge.Video.DirectShow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AforgeDemo
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;//所有摄像设备
        private VideoCaptureDevice videoDevice;//摄像设备
        private VideoCapabilities[] videoCapabilities;//摄像头分辨率
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//得到机器所有接入的摄像设备
            if (videoDevices.Count != 0)
            {
                foreach (FilterInfo device in videoDevices)
                {
                    cboVideo.Items.Add(device.Name);//把摄像设备添加到摄像列表中
                }
            }
            else
            {
                cboVideo.Items.Add(“没有找到摄像头“);
            }
            cboVideo.SelectedIndex = 0;//默认选择第一个
        }

        private void cboVideo_SelectedIndexChanged(object sender EventArgs e)
        {
            if (videoDevices.Count != 0)
            {
                //获取摄像头
                videoDevice = new VideoCaptureDevice(videoDevices[cboVideo.SelectedIndex].MonikerString);
                GetDeviceResolution(videoDevice);//获得摄像头的分辨率
            }
        }
        //获得摄像头的分辨率
        private void GetDeviceResolution(VideoCaptureDevice videoCaptureDevice)
        {
            cboResolution.Items.Clear();//清空列表
            videoCapabilities = videoCaptureDevice.VideoCapabilities;//设备的摄像头分辨率数组
            foreach (VideoCapabilities capabilty in videoCapabilities)
            {
                //把这个设备的所有分辨率添加到列表
                cboResolution.Items.Add($“{capabilty.frameSize.Width} x {capabilty.frameSize.Height}“);
            }
            cboResolution.SelectedIndex = 0;//默认选择第一个
        }

        private void btnConnect_Click(object sender EventArgs e)
        {
            if (videoDevice != null)//如果摄像头不为空
            {
                if ((videoCapabilities != null) && (videoCapabilities.Length != 0))
                {
                    videoDevice.VideoResolution = videoCapabilities[cboResolution.SelectedIndex];//摄像头分辨率
                    vispShoot.VideoSource = videoDevice;//把摄像头赋给控件
                    vispShoot.Start();//开启摄像头
                    EnableControlStatus(false);
                }
            }
        }
        //控件的显示切换
        private void EnableControlStatus(bool status)
        {
            cboVideo.Enabled = status;
            cboResolution.Enabled = status;
            btnConnect.Enabled = status;
            btnPic.Enabled = !status;
            btnCut.Enabled = !status;
        }

        private void btnCut_Click(object sender EventArgs e)
        {
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5385  2019-02-27 14:18  AforgeDemo\AforgeDemo.csproj

     文件      44544  2013-07-17 23:22  AforgeDemo\bin\Debug\AForge.Controls.dll

     文件      66108  2013-07-17 23:22  AforgeDemo\bin\Debug\AForge.Controls.xml

     文件      17920  2013-07-17 23:15  AforgeDemo\bin\Debug\AForge.dll

     文件     262656  2013-07-17 23:19  AforgeDemo\bin\Debug\AForge.Imaging.dll

     文件     944046  2013-07-17 23:19  AforgeDemo\bin\Debug\AForge.Imaging.xml

     文件      68096  2013-07-17 23:17  AforgeDemo\bin\Debug\AForge.Math.dll

     文件     270650  2013-07-17 23:17  AforgeDemo\bin\Debug\AForge.Math.xml

     文件      61440  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.DirectShow.dll

     文件     195287  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.DirectShow.xml

     文件      20992  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.dll

     文件      53275  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.xml

     文件      78375  2013-07-17 23:15  AforgeDemo\bin\Debug\AForge.xml

     文件      12288  2019-02-27 15:14  AforgeDemo\bin\Debug\AforgeDemo.exe

     文件      24064  2019-02-27 15:14  AforgeDemo\bin\Debug\AforgeDemo.pdb

     文件      22688  2019-02-27 15:01  AforgeDemo\bin\Debug\AforgeDemo.vshost.exe

     文件        490  2015-10-22 09:54  AforgeDemo\bin\Debug\AforgeDemo.vshost.exe.manifest

     文件       4138  2019-02-27 15:12  AforgeDemo\Form1.cs

     文件       7413  2019-02-27 15:01  AforgeDemo\Form1.Designer.cs

     文件       5817  2019-02-27 15:01  AforgeDemo\Form1.resx

     文件       1361  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.csproj.FileListAbsolute.txt

     文件       1012  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.csproj.GenerateResource.Cache

     文件      12288  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.exe

     文件        180  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.Form1.resources

     文件      24064  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.pdb

     文件        180  2019-02-27 15:14  AforgeDemo\obj\Debug\AforgeDemo.Properties.Resources.resources

     文件       7428  2019-02-27 14:18  AforgeDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        513  2019-02-27 14:18  AforgeDemo\packages.config

     文件        491  2019-02-27 14:16  AforgeDemo\Program.cs

     文件       1346  2019-02-27 14:16  AforgeDemo\Properties\AssemblyInfo.cs

............此处省略14个文件信息

评论

共有 条评论