C# 调用摄像头拍照(AForge实现)

本文介绍如何在C#项目中利用AForge库进行摄像头拍照,包括下载AForge库,通过Visual Studio添加引用,添加组件到工具箱,以及代码实现,适用于工厂物资管理系统中的人脸识别功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、前言:

C#调用摄像头是为了完成一个项目( 工厂物资管理系统. )中的人脸识别功能。
对人脸识别感兴趣的小伙伴可以移步至:https://blog.csdn.net/qq_41971768/article/details/103823308

在 C # 调用摄像头的实现过程中,我曾在博客上借鉴其他人的做法。在这里给出相应的博客地址如下:

本文也是借鉴于第四篇博客。

2、正文:

2.1 下载 AForge 库

进入AForge官网:http://www.aforgenet.com/framework/downloads.html下载AForge库:
AForge.NET

2.2 通过VS添加引用

  • AForge.Imaging ——图像处理和过滤器
  • AForge.Video ——视频处理类库
  • AForge.Controls—— 图像显示控件
  • 进入引用管理器如下图:引用管理器
  • 点击浏览:
找到AForge.NET Framework-2.2.5-(libs only)\Release目录
添加以下文件:
	"AForge.Video.dll"
	"AForge.Controls.dll" 
	"AForge.dll" 
	"AForge.Imaging.dll" 
	"AForge.Video.DirectShow.dll" 

添加引用

  • 添加结果如下:

添加结果图

2.3 工具箱添加AForge的组件

  • 打开工具箱>>右键>>添加选项卡>>输入名称AForge
    添加结果
  • 选中AForge>>右键>>选择项>>浏览进入AForge.NET Framework-2.2.5-(libs only)\Release目录>>选中 “AForge.Controls.dll”>>打开确认
  • 添加工具

2.4 添加组件

  • 创建窗体>>添加图中组件;
  • 其中的videoSorcePlayer位于刚添加的工具集AForge中。
    添加组件
  • 我的设计效果
    设计效果

2.5 代码:

可以同时参考前言中第四位作者的代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using System.Drawing;
using AForge.Video.DirectShow;
using 工厂物资管理.Face;
using Newtonsoft.Json;
using System.Data.SqlClient;

namespace 工厂物资管理
{
   
    public partial class FaceLoginForm : Form
    {
   

        private FilterInfoCollection videoDevices = null;
        private VideoCaptureDevice videoSource = null;
        private string EmployeeID = null;
        private int Indexof = 0;

        private SqlConnection sqlConnection = null;
        private SqlCommand sqlCommand = null;
        public FaceLoginForm()
        {
   
            InitializeComponent()
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值