• 大小: 13.93MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-31
  • 语言: C#
  • 标签: c#  AForge  .net  

资源简介

此程序是基于AForge库开发的调用USB摄像头进行录像和图片抓拍功能demo,希望对不熟悉此库的开发人员有所借鉴和帮助。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Imaging;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Windows.Media.Imaging;
using AForge;
using AForge.Controls;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Timers;
using System.Runtime.InteropServices;
using System.Drawing;
using AForge.Video.FFMPEG;


namespace OperateCamera
{
    

    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;
        private VideoCaptureDevice videoSource;
        private delegate void WriteLabelDelegate(object entry);

        private bool stopREC = true;
        private bool createNewFile = true;
        int frameRate = 25; //默认帧率
        private VideoFileWriter videoWriter = null;
        private string videoFileFullPath = string.Empty; //视频文件全路径
        private string imageFileFullPath = string.Empty; //图像文件全路径
        private string videoPath = @“E:\video\“; //视频文件路径
        private string videoFileName = string.Empty; //视频文件名
        private string drawDate = string.Empty;
        private VideoFileReader _reader;
        private VideoFileWriter _writer;
        static int intFlag = 0;

        [DllImport(“gdi32“)]
        static extern int Deleteobject(IntPtr o);

        static System.Timers.Timer timerPic;

        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)
                {
                    tscbxCameras.Items.Add(device.Name);
                }

                tscbxCameras.SelectedIndex = 0;

            }
            catch (ApplicationException)
            {
                tscbxCameras.Items.Add(“没有找到摄像透“);
                videoDevices = null;
            }
        }

        private void btnConnect_Click(object sender EventArgs e)
        {
            CameraConn();
        }
        //连接摄像头
        private void CameraConn()
        {
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString);
            videoSource.DesiredframeSize = new System.Drawing.Size(320 240);
            videoSource.DesiredframeRate = 1;

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

        //关闭摄像头
        private void btnClose_Click(object sender EventArgs e)
        {
            videoSourcePlayer.SignalToStop();
            videoSourcePlayer.WaitFo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-07-05 13:54  OperateCamera\
     文件         246  2015-07-04 15:30  OperateCamera\App.config
     文件       11592  2015-07-04 23:29  OperateCamera\Form1.Designer.cs
     文件       11386  2015-07-05 12:51  OperateCamera\Form1.cs
     文件        6212  2015-07-04 23:29  OperateCamera\Form1.resx
     文件        5543  2015-07-04 23:50  OperateCamera\OperateCamera.csproj
     文件         227  2014-02-16 20:18  OperateCamera\OperateCamera.csproj.user
     文件         867  2015-07-01 09:51  OperateCamera\OperateCamera.sln
     文件       25088  2015-07-05 12:53  OperateCamera\OperateCamera.suo
     文件         494  2014-02-16 17:21  OperateCamera\Program.cs
     目录           0  2015-07-02 20:37  OperateCamera\Properties\
     文件        1358  2014-02-16 17:21  OperateCamera\Properties\AssemblyInfo.cs
     文件        2866  2015-07-04 23:50  OperateCamera\Properties\Resources.Designer.cs
     文件        5612  2014-02-16 17:21  OperateCamera\Properties\Resources.resx
     文件        1113  2015-07-04 23:50  OperateCamera\Properties\Settings.Designer.cs
     文件         249  2014-02-16 17:21  OperateCamera\Properties\Settings.settings
     目录           0  2015-07-05 13:55  OperateCamera\Service References\
     文件        9187  2015-07-04 23:19  OperateCamera\VideoOperate.cs
     目录           0  2015-07-05 13:54  OperateCamera\bin\
     目录           0  2015-07-05 13:54  OperateCamera\bin\Debug\
     文件       44544  2013-07-15 23:04  OperateCamera\bin\Debug\AForge.Controls.dll
     文件      262656  2013-07-15 23:04  OperateCamera\bin\Debug\AForge.Imaging.dll
     文件       61440  2013-07-15 23:04  OperateCamera\bin\Debug\AForge.Video.DirectShow.dll
     文件       61952  2013-07-15 23:07  OperateCamera\bin\Debug\AForge.Video.FFMPEG.dll
     文件       20992  2013-07-15 23:04  OperateCamera\bin\Debug\AForge.Video.dll
     文件       17920  2013-07-15 23:04  OperateCamera\bin\Debug\AForge.dll
     文件       20480  2015-07-05 12:51  OperateCamera\bin\Debug\OperateCamera.exe
     文件         246  2015-07-04 15:30  OperateCamera\bin\Debug\OperateCamera.exe.config
     文件       30208  2015-07-05 12:51  OperateCamera\bin\Debug\OperateCamera.pdb
     文件       11608  2015-07-05 12:50  OperateCamera\bin\Debug\OperateCamera.vshost.exe
     文件         246  2015-07-04 15:30  OperateCamera\bin\Debug\OperateCamera.vshost.exe.config
............此处省略51个文件信息

评论

共有 条评论