• 大小: 0.21M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-03
  • 语言: C#
  • 标签: 摄像头  摄像  拍照  

资源简介

调取本机摄像头拍照  要引用 bin debug下目录下的5个文件 

资源截图

代码片段和文件信息

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

namespace 人脸识别
{
    public partial class Form1 : Form
    {
       private FilterInfoCollection videoDevices;


        public int selectedDeviceIndex = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            try
            {
                // 枚举所有视频输入设备
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (videoDevices.Count == 0)
                    throw new ApplicationException();

                foreach (FilterInfo device in videoDevices)
                {
                    comboBox1.Items.Add(device.Name);
                }
                //下拉框用来更换摄像头
                comboBox1.SelectedIndex = 0;

            }
            catch (ApplicationException)
            {
                comboBox1.Items.Add(“未发现摄像头“);
                comboBox1.SelectedIndex = 0;
                videoDevices = null;
            }
        }

        private void button2_Click(object sender EventArgs e)
        {
            if (videoSourcePlayer1 != null && videoSourcePlayer1.IsRunning)
            {
                videoSourcePlayer1.SignalToStop();
                videoSourcePlayer1.WaitForStop();
            }
        }

        private void button1_Click(object sender EventArgs e)
        {
            button2_Click(null null);
            if (comboBox1.SelectedItem.ToString() == “未发现摄像头“)
            {
                MessageBox.Show(“未发现摄像头“ “错误提示“ MessageBoxButtons.OK MessageBoxIcon.Hand);
                return;
            }

            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[comboBox1.SelectedIndex];

            videoSourcePlayer1.VideoSource = videoSource;
            videoSourcePlayer1.Start();
        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {
            if (comboBox1.SelectedItem.ToString() == “未发现摄像头“)
            {
                comboBox2.Items.Add(“未发现摄像头“);
                comboBox2.SelectedIndex = 0;
                return;
            }
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
            if (videoSource.VideoCapabilities.Count() == 0)
            {
                comboBox2.Items.Add(“摄像头异常“);
                comboBox2.SelectedIndex = 0;
                return;
            }
            c

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\.vs\
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\.vs\人脸识别\
     目录           0  2020-08-15 23:56  调取本机摄像头拍照\.vs\人脸识别\v16\
     文件       41472  2020-08-16 15:44  调取本机摄像头拍照\.vs\人脸识别\v16\.suo
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\bin\
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\bin\Debug\
     文件       44544  2020-08-15 23:24  调取本机摄像头拍照\bin\Debug\AForge.Controls.dll
     文件       17920  2020-08-15 23:24  调取本机摄像头拍照\bin\Debug\AForge.dll
     文件      262656  2020-08-15 23:24  调取本机摄像头拍照\bin\Debug\AForge.Imaging.dll
     文件       61440  2020-08-15 23:24  调取本机摄像头拍照\bin\Debug\AForge.Video.DirectShow.dll
     文件       20992  2020-08-15 23:23  调取本机摄像头拍照\bin\Debug\AForge.Video.dll
     目录           0  2020-08-18 19:43  调取本机摄像头拍照\bin\Debug\Picture\
     文件       12288  2020-08-16 12:59  调取本机摄像头拍照\bin\Debug\人脸识别.exe
     文件       34304  2020-08-16 12:59  调取本机摄像头拍照\bin\Debug\人脸识别.pdb
     文件        4373  2020-08-16 12:59  调取本机摄像头拍照\Form1.cs
     文件        5910  2020-08-16 12:59  调取本机摄像头拍照\Form1.Designer.cs
     文件        5817  2020-08-16 12:59  调取本机摄像头拍照\Form1.resx
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\obj\
     目录           0  2020-08-18 19:47  调取本机摄像头拍照\obj\Debug\
     文件         208  2020-08-15 23:56  调取本机摄像头拍照\obj\Debug\.NETframeworkVersion=v4.0.AssemblyAttributes.cs
     文件       12099  2020-08-16 12:52  调取本机摄像头拍照\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7077  2020-08-16 00:01  调取本机摄像头拍照\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2020-08-15 23:56  调取本机摄像头拍照\obj\Debug\TempPE\
     文件           0  2020-08-16 12:59  调取本机摄像头拍照\obj\Debug\人脸识别.csproj.CopyComplete
     文件          42  2020-08-16 00:05  调取本机摄像头拍照\obj\Debug\人脸识别.csproj.CoreCompileInputs.cache
     文件         634  2020-08-16 00:12  调取本机摄像头拍照\obj\Debug\人脸识别.csproj.FileListAbsolute.txt
     文件        1012  2020-08-16 12:59  调取本机摄像头拍照\obj\Debug\人脸识别.csproj.GenerateResource.cache
     文件        2193  2020-08-16 12:56  调取本机摄像头拍照\obj\Debug\人脸识别.csprojAssemblyReference.cache
     文件       12288  2020-08-16 12:59  调取本机摄像头拍照\obj\Debug\人脸识别.exe
     文件         180  2020-08-16 12:59  调取本机摄像头拍照\obj\Debug\人脸识别.Form1.resources
............此处省略11个文件信息

评论

共有 条评论