C#windows窗体人脸识别

一、创建一个数据库,名为TestFaceDB

里面有一张表就OK了,表名Users,表里面有几个字段我说明一下:

id--------------------bigint----------------------编号

name--------------varchar(50)-----------------用户名

phone--------------varchar(50)----------------电话

password--------------varchar(50)------------密码

address--------------varchar(50)--------------地址

picture--------------varchar(50)---------------脸的图片

数据库脚本:

USE [master]
GO
/****** Object:  Database [TestFaceDB]    Script Date: 2017-11-30 22:09:36 ******/
CREATE DATABASE [TestFaceDB]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'TestFaceDB', FILENAME = N'E:\DB\TestFaceDB.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'TestFaceDB_log', FILENAME = N'E:\DB\TestFaceDB_log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [TestFaceDB] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [TestFaceDB].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [TestFaceDB] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [TestFaceDB] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [TestFaceDB] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [TestFaceDB] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [TestFaceDB] SET ARITHABORT OFF 
GO
ALTER DATABASE [TestFaceDB] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [TestFaceDB] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [TestFaceDB] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [TestFaceDB] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [TestFaceDB] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [TestFaceDB] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [TestFaceDB] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [TestFaceDB] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [TestFaceDB] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [TestFaceDB] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [TestFaceDB] SET  DISABLE_BROKER 
GO
ALTER DATABASE [TestFaceDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [TestFaceDB] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [TestFaceDB] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [TestFaceDB] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [TestFaceDB] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [TestFaceDB] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [TestFaceDB] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [TestFaceDB] SET RECOVERY FULL 
GO
ALTER DATABASE [TestFaceDB] SET  MULTI_USER 
GO
ALTER DATABASE [TestFaceDB] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [TestFaceDB] SET DB_CHAINING OFF 
GO
ALTER DATABASE [TestFaceDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [TestFaceDB] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
EXEC sys.sp_db_vardecimal_storage_format N'TestFaceDB', N'ON'
GO
USE [TestFaceDB]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 2017-11-30 22:09:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
  [id] [bigint] NOT NULL,
  [name] [varchar](50) NULL,
  [age] [int] NULL,
  [phone] [varchar](50) NULL,
  [password] [varchar](50) NULL,
  [address] [varchar](50) NULL,
  [picture] [varchar](max) NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
  [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
USE [master]
GO
ALTER DATABASE [TestFaceDB] SET  READ_WRITE 
GO

二、引入一个AForgeDLL文件库

C#(Winform)通过添加AForge添加并使用系统摄像机-CSDN博客

三、在vs里面新建个项目 Name: Camtest

在新建个sqlhelper,这个文件是用来操作数据库的,主要是人脸注册和认证以及登陆的时候用。

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace face
{
    /// <summary>
    /// 数据库工具类
    /// </summary>
    public class SqlHelper
    {
        #region 获取数据库连接
        private static string GetConnectionString
        {
            get
            {
                return "Data Source=.;Initial Catalog=TestFaceDB;Persist Security Info=True;User ID=sa;Password=171268"; //转换成string类型
            }
        }
        #endregion

        #region 查询多条记录
        /// <summary>
        /// 查询多条记录
        /// params SqlParameter  param  表示既可以传过来数组  也可以传过来单个值
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="type"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static SqlDataReader ExcuteReader(string sql, CommandType type, params SqlParameter[] param)
        {
            SqlConnection conn = new SqlConnection(GetConnectionString);
            SqlCommand cmd = new SqlCommand(sql, conn);
            PreaPareCommand(sql, conn, cmd, type, param);
            //参数是关闭连接
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        #endregion


        #region DataSet
        public static DataSet ExexuteDataset(string sql, CommandType type, params SqlParameter[] param)
        {
            using (SqlConnection conn = new SqlConnection(GetConnectionString))
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                PreaPareCommand(sql, conn, cmd, type, param);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                return ds;
            }
        }
        #endregion


        #region 查询返回一条记录
        /// <summary>
        /// 查询返回一条记录
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="type"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static Object ExecuteScalar(string sql, CommandType type, params SqlParameter[] param)
        {
            using (SqlConnection conn = new SqlConnection(GetConnectionString))
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                PreaPareCommand(sql, conn, cmd, type, param);
                return cmd.ExecuteScalar();
            }
        }
        #endregion

        #region 命令对象装配
        //命令对象装配
        private static void PreaPareCommand(string sql, SqlConnection conn, SqlCommand cmd, CommandType type, params SqlParameter[] param)
        {
            if (conn.State != ConnectionState.Open)
            {
                conn.Close();
                conn.Open();
            }
            cmd.CommandType = type;
            if (param != null)
            {
                foreach (SqlParameter p in param)
                {
                    cmd.Parameters.Add(p);
                }
            }
        }
        #endregion

        #region 增删改
        public static int ExecuteNonQuery(string sql, CommandType type, params SqlParameter[] param)
        {
            using (SqlConnection conn = new SqlConnection(GetConnectionString))
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                PreaPareCommand(sql, conn, cmd, type, param);
                return cmd.ExecuteNonQuery();
            }
        }
        #endregion

    }
}

再新建一个实体类,命名为:Users

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camtest
{
    public class Users
    {
        //编号
        public long id { get; set; }
        //姓名
        public string name { get; set; }
        //密码
        public string password { get; set; }
        //年龄
        public int age { get; set; }
        //电话
        public string phone { get; set; }
        //地址
        public string address { get; set; }
        //脸
        public string picture { get; set; }
    }
}

四、人脸检测

空间组成:

1. videoSourcePlayer,所在的dll是Aforge.Controls.Video这个里面,名称是videoSourcePlayer1

2. groupBox控件,名称是groupBox1

3.comboBox控件,名称是comboBoxCameras和picsize

4.button控件,名称是button2和close

5. label控件,名称是(左边从上到下)label3,label6,label8,label10,label12,label14。右边从上到下:label4,label5,label7,label9,label11,label13

6窗体,名称是facedetection

1.加载窗体的时候先检测一遍我们的摄像头: 

 // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;

2.打开摄像头的方法

 /// <summary>
        /// 打开摄像头
        /// </summary>
        public void openCan()
        {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }

3.保存人脸成一张图片,顺便调用人脸检测库:

//保存图片
        private void button2_Click(object sender, EventArgs e)
        {
            if (videoSource == null)
                return;

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            String path = AppDomain.CurrentDomain.BaseDirectory;

            //将图片保存在服务器里面
            bitmap.Save(path + "\\picture\\" + fileName, ImageFormat.Jpeg);
            bitmap.Dispose();

            //进行面部特征识别
            facemodel facem = face_test.FaceDetect(path + "\\picture\\" + fileName);
            this.label4.Text = facem.age;      //年龄
            this.label5.Text = facem.beauty;  //漂亮度
            string expression = facem.expression;//表情
            if (expression.Equals("0"))
            {
                this.label7.Text = "不笑";
            }
            else if (expression.Equals("1"))
            {
                this.label7.Text = "微笑";
            }
            else if (expression.Equals("2"))
            {
                this.label7.Text = "大笑";
            }
            string gender = facem.gender;//性别
            if (gender.Equals("male"))
            {
                this.label9.Text = "男";
            }
            else
            {
                this.label9.Text = "女";
            }
            string glasses = facem.glasses;//是否戴眼镜
            if (glasses.Equals("0"))
            {
                this.label11.Text = "无眼镜";
            }
            else if (glasses.Equals("1"))
            {
                this.label11.Text = "普通眼镜";
            }
            else
            {
                this.label11.Text = "墨镜";
            }
            string race = facem.race;//人种
            if (race.Equals("yellow"))
            {
                this.label13.Text = "黄人";
            }
            else if (race.Equals("white"))
            {
                this.label13.Text = "白人";
            }
            else if (race.Equals("black"))
            {
                this.label13.Text = "黑人";
            }
            else if (race.Equals("arabs"))
            {
                this.label13.Text = "棕人";
            }

        }

4.解析json的类

using face;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camtest
{
    public class face_test
    {
        public static string Api_Key = "你的Api_Key";
        public static string Secret_Key = "你的Secret_Key";

        /// <summary>
        /// 脸部比对
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public static facemodel FaceDetect(String img)
        {
            var client = new Baidu.Aip.Face.Face(Api_Key, Secret_Key);
            var image = File.ReadAllBytes(img);
            var options = new Dictionary<string, object>()
    {
        {"face_fields", "age,beauty,expression,gender,glasses,race"}
    };
            string result = client.FaceDetect(image, options).ToString();

            //解析json数据
            return json_test(result.ToString());
        }

        /// <summary>
        /// 解析json数据
        /// </summary>
        /// <param name="json"></param>
        public static facemodel json_test(string json)
        {
            //得到根节点
            JObject jo_result = (JObject)JsonConvert.DeserializeObject(json.ToString());
            //得到result节点
            JArray jo_age = (JArray)JsonConvert.DeserializeObject(jo_result["result"].ToString());
            //查找某个字段与值
            facemodel facem = new facemodel();
            foreach (var val in jo_age)
            {
                facem.age = ((JObject)val)["age"].ToString();
                facem.beauty = ((JObject)val)["beauty"].ToString();
                facem.expression = ((JObject)val)["expression"].ToString();
                facem.gender = ((JObject)val)["gender"].ToString();
                facem.glasses = ((JObject)val)["glasses"].ToString();
                facem.race = ((JObject)val)["race"].ToString();
            }

            return facem;
        }

    }
}

5.人脸检测的model类facemodel

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace face
{
   public class facemodel
    {
       //年龄
        public string age { get; set; }
       //美丑
        public string beauty { get; set; }
       //表情
        public string expression { get; set; }
       //性别
        public string gender { get; set; }
       //是否戴眼镜
        public string glasses { get; set; }
       //人种
        public string race { get; set; }


    }
}

6.人脸检测源代码

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.Threading.Tasks;
using System.Windows.Forms;
using AForge;
using AForge.Controls;
using AForge.Imaging;
using AForge.Video;
using AForge.Video.DirectShow;
using face;



namespace Camtest
{
    public partial class facedetection : Form
    {
        /// <summary>
        /// 人脸检测
        /// </summary>
        public facedetection()
        {
            InitializeComponent();
            //启动默认在屏幕中间
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        }
        FilterInfoCollection videoDevices;
        VideoCaptureDevice videoSource;
        public int selectedDeviceIndex = 0;
        public int selectedPICIndex = 0;
        /// <summary>
        /// 加载窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {


            // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;
            this.label4.Text = this.label5.Text = this.label7.Text = this.label9.Text = this.label11.Text = this.label13.Text = "正在识别";
            this.label4.ForeColor = Color.Red;
            this.label5.ForeColor = Color.Red;
            this.label7.ForeColor = Color.Red;
            this.label9.ForeColor = Color.Red;
            this.label11.ForeColor = Color.Red;
            this.label13.ForeColor = Color.Red;
            openCan();

        }
        //关闭窗体
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {


            DialogResult r = MessageBox.Show("确定要退出程序?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (r != DialogResult.OK)
            {

                e.Cancel = true;
            }
            videoSourcePlayer1.Stop();//停止摄像头
            videoSourcePlayer1.Dispose();


        }

        //实时显示照片
        private void videoSourcePlayer1_Click(object sender, EventArgs e)
        {

        }



        /// <summary>
        /// 打开摄像头
        /// </summary>
        public void openCan()
        {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }



        //保存图片
        private void button2_Click(object sender, EventArgs e)
        {
            if (videoSource == null)
                return;

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            String path = AppDomain.CurrentDomain.BaseDirectory;

            //将图片保存在服务器里面
            bitmap.Save(path + "\\picture\\" + fileName, ImageFormat.Jpeg);
            bitmap.Dispose();

            //进行面部特征识别
            facemodel facem = face_test.FaceDetect(path + "\\picture\\" + fileName);
            this.label4.Text = facem.age;      //年龄
            this.label5.Text = facem.beauty;  //漂亮度
            string expression = facem.expression;//表情
            if (expression.Equals("0"))
            {
                this.label7.Text = "不笑";
            }
            else if (expression.Equals("1"))
            {
                this.label7.Text = "微笑";
            }
            else if (expression.Equals("2"))
            {
                this.label7.Text = "大笑";
            }
            string gender = facem.gender;//性别
            if (gender.Equals("male"))
            {
                this.label9.Text = "男";
            }
            else
            {
                this.label9.Text = "女";
            }
            string glasses = facem.glasses;//是否戴眼镜
            if (glasses.Equals("0"))
            {
                this.label11.Text = "无眼镜";
            }
            else if (glasses.Equals("1"))
            {
                this.label11.Text = "普通眼镜";
            }
            else
            {
                this.label11.Text = "墨镜";
            }
            string race = facem.race;//人种
            if (race.Equals("yellow"))
            {
                this.label13.Text = "黄人";
            }
            else if (race.Equals("white"))
            {
                this.label13.Text = "白人";
            }
            else if (race.Equals("black"))
            {
                this.label13.Text = "黑人";
            }
            else if (race.Equals("arabs"))
            {
                this.label13.Text = "棕人";
            }

        }

        //取消的按钮
        private void close_Click(object sender, EventArgs e)
        {
            //停止摄像头
            videoSourcePlayer1.Stop();
            this.Close();
            welcome we = new welcome();
            we.Show();
        }



    }
}

五、人脸注册

新建一个窗体,名称是:faceregiste

 1.调用的是百度的API,所以需要Api_Key和Secret_Key,关于这两个,大家可以自行百度。

    //Api_Key
        public static string Api_Key = "这里是你的Api_Key";
        //Secret_Key
        public static string Secret_Key = "这里是你的Secret_Key ";

2.刷新可用摄像头列表

  //加载项目
        private void faceregiste_Load(object sender, EventArgs e)
        {

            // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;

            //打开摄像头
            openCamera();
        }

3..打开摄像头

//打开摄像头
        public void openCamera() {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }

4.点击注册执行的方法

 //注册的按钮
        private void register_Click(object sender, EventArgs e)
        {
            Users user = new Users();
            user.name = this.name.Text;
            user.id = DateTime.Now.Ticks / 10000;
            user.password = this.password.Text;
            user.phone = this.phone.Text;
            user.age =(int)this.age.Value;
            user.address = this.address.Text;
            user.picture = SavePicture() ;
            //注册人脸通过的话进去
            if (FaceRegister(user))
            {
                int rel = AddUsers(user);//添加信息
                if (rel > 0)
                {
                    MessageBox.Show("注册成功", "提示信息");
                }
                else
                {
                    MessageBox.Show("添加失败", "提示信息");
                }
            }
        }

5.保存图片方法

/// <summary>
        /// 保存图片
        /// </summary>
        public string SavePicture() {
            if (videoSource == null)
            {
                return null;
            }

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string picture = path + "\\picture\\" + fileName;
            //将图片保存在服务器里面
            bitmap.Save(picture, ImageFormat.Jpeg);
            bitmap.Dispose();
            return picture;
        }

6.取消按钮方法

 //取消的按钮
        private void close_Click(object sender, EventArgs e)
        {
            //停止摄像头
            videoSourcePlayer1.Stop();
            this.Close();
            welcome we = new welcome();
            we.Show();
        }

7..用户注册的方法

/// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public int AddUsers(Users users)
        {
            int rel = 0;
            string sql = "insert INTO Users VALUES(@id,@name,@age,@phone,@password,@address,@picture)";
            SqlParameter[] param = {
                                        new SqlParameter("@id",users.id),
                                        new SqlParameter("@name",users.name),
                                        new SqlParameter("@age",users.age),
                                        new SqlParameter("@phone",users.phone),
                                        new SqlParameter("@password",users.password),
                                        new SqlParameter("@address",users.address),
                                        new SqlParameter("@picture",users.picture)
                                        
                                   };
            rel = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
            return rel;
        }

8.人脸注册方法

 /// <summary>
        /// 人脸注册
        /// </summary>
        /// <param name="picture"></param>
        public static bool FaceRegister(Users user)
        {
            var client = new Baidu.Aip.Face.Face(Api_Key, Secret_Key);
            //当前毫秒数可能是负数,取绝对值
            var image1 = File.ReadAllBytes(user.picture);

            var result = client.User.Register(image1, user.id.ToString(), user.name, new[] { "gr_test" });
            //得到根节点
            JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());
            if ((string)jo_result["error_msg"] != null)
            {
                MessageBox.Show("对不起,请把脸放上!","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
                return false;
            }
            
            return true;
        }

9.关闭窗体方法

 //关闭窗体
        private void faceregiste_FormClosing(object sender, FormClosingEventArgs e)
        {

            DialogResult r = MessageBox.Show("确定要退出程序?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (r != DialogResult.OK)
            {

                e.Cancel = true;
            }
            videoSourcePlayer1.Stop();//停止摄像头
            videoSourcePlayer1.Dispose();
        }

10、人脸注册源代码

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 AForge;
using AForge.Controls;
using AForge.Imaging;
using AForge.Video;
using AForge.Video.DirectShow;
using face;
using System.Data.SqlClient;
using System.Drawing.Imaging;
using System.IO;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;



namespace Camtest
{
    public partial class faceregiste : Form
    {
        //Api_Key
        public static string Api_Key = "OVYw5Ok0y9U8n6CfVPYt0wfZ";
        //Secret_Key
        public static string Secret_Key = "aCN3lupCarq3rC9G8Rylqz1d36Towp8G";
        public faceregiste()
        {
            InitializeComponent();
            //启动默认在屏幕中间
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        }
        FilterInfoCollection videoDevices;
        VideoCaptureDevice videoSource;
        public int selectedDeviceIndex = 0;
        public int selectedPICIndex = 0;

        //加载项目
        private void faceregiste_Load(object sender, EventArgs e)
        {

            // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;

            //打开摄像头
            openCamera();
        }




        //打开摄像头
        public void openCamera() {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }

        //注册的按钮
        private void register_Click(object sender, EventArgs e)
        {
            Users user = new Users();
            user.name = this.name.Text;
            user.id = DateTime.Now.Ticks / 10000;
            user.password = this.password.Text;
            user.phone = this.phone.Text;
            user.age =(int)this.age.Value;
            user.address = this.address.Text;
            user.picture = SavePicture() ;
            //注册人脸通过的话进去
            if (FaceRegister(user))
            {
                int rel = AddUsers(user);//添加信息
                if (rel > 0)
                {
                    MessageBox.Show("注册成功", "提示信息");
                }
                else
                {
                    MessageBox.Show("添加失败", "提示信息");
                }
            }
        }


        /// <summary>
        /// 保存图片
        /// </summary>
        public string SavePicture() {
            if (videoSource == null)
            {
                return null;
            }

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string picture = path + "\\picture\\" + fileName;
            //将图片保存在服务器里面
            bitmap.Save(picture, ImageFormat.Jpeg);
            bitmap.Dispose();
            return picture;
        }



        //取消的按钮
        private void close_Click(object sender, EventArgs e)
        {
            //停止摄像头
            videoSourcePlayer1.Stop();
            this.Close();
            welcome we = new welcome();
            we.Show();
        }


        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public int AddUsers(Users users)
        {
            int rel = 0;
            string sql = "insert INTO Users VALUES(@id,@name,@age,@phone,@password,@address,@picture)";
            SqlParameter[] param = {
                                        new SqlParameter("@id",users.id),
                                        new SqlParameter("@name",users.name),
                                        new SqlParameter("@age",users.age),
                                        new SqlParameter("@phone",users.phone),
                                        new SqlParameter("@password",users.password),
                                        new SqlParameter("@address",users.address),
                                        new SqlParameter("@picture",users.picture)

                                   };
            rel = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
            return rel;
        }


        //关闭窗体
        private void faceregiste_FormClosing(object sender, FormClosingEventArgs e)
        {

            DialogResult r = MessageBox.Show("确定要退出程序?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (r != DialogResult.OK)
            {

                e.Cancel = true;
            }
            videoSourcePlayer1.Stop();//停止摄像头
            videoSourcePlayer1.Dispose();
        }


        /// <summary>
        /// 人脸注册
        /// </summary>
        /// <param name="picture"></param>
        public static bool FaceRegister(Users user)
        {
            var client = new Baidu.Aip.Face.Face(Api_Key, Secret_Key);
            //当前毫秒数可能是负数,取绝对值
            var image1 = File.ReadAllBytes(user.picture);

            var result = client.User.Register(image1, user.id.ToString(), user.name, new[] { "gr_test" });
            //得到根节点
            JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());
            if ((string)jo_result["error_msg"] != null)
            {
                MessageBox.Show("对不起,请把脸放上!","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
                return false;
            }

            return true;
        }

    }
}

六、人脸登录

1. 窗体加载刷新摄像头列表:

//窗体加载
        private void faceIdentify_Load(object sender, EventArgs e)
        {
           //显示为正在检测
            this.label1.Text = this.label2.Text = this.label6.Text = this.label9.Text = "正在识别";
          
            // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;

            //打开摄像头
            openCamera();
        }

2.打开摄像头:

//打开摄像头
        public void openCamera()
        {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }

3.点击确定的按钮,(人脸登陆):

/// <summary>
        /// 点击确定的按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //先获取用户名
            //然后在提取图片
            //先查询用户名,看看有没有该用户名
            //有该用户名的话继续判断人脸对应不,没有的话提示没有该用户
            string name = this.textBox1.Text;
            Users user = QueryUsersByName(name);
            if (((string)(user.name))!="")
            {
                //有该用户,判断摄入的人脸和人脸库中的对比
                FaceVerify(SavePicture(),user);
            }
            else { 
               
                //说明没有该用户,提示用户重新输入用户名
                MessageBox.Show("对不起,检测到没有该用户,请重新输入", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            

        }

4.人脸认证【登陆】:

/// <summary>
        /// 人脸认证【登陆】
        /// </summary>
        public  void FaceVerify(string filename,Users users)
        {
            var client = new Baidu.Aip.Face.Face(Api_Key ,Secret_Key);
            var image1 = File.ReadAllBytes(filename);

            var result = client.User.Verify(image1,(users.id).ToString(), new[] { "gr_test" }, 1);


            //先判断脸是不是在上面,在继续看有匹配的没,否则提示放上脸
            //得到根节点
            JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());
            if ((string)jo_result["error_msg"] != null)
            {
                MessageBox.Show("对不起,请把脸放上!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                //检测到脸
                //得到result节点
                JArray jo_age = (JArray)JsonConvert.DeserializeObject(jo_result["result"].ToString());
                string resu = jo_age.ToString();
                int num1 = resu.IndexOf("\n") + 2;
                int num2 = resu.LastIndexOf("]") - 8;
                string ids = resu.Substring(num1, num2);
                if (ids != null || !ids.Equals(""))
                {

                    double scores_num = double.Parse(ids);
                    if (scores_num > 80)
                    {
                        MessageBox.Show("登陆成功,已检测到您的信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("对不起,脸与账户不对应,请换张脸试试", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }

5.根据编号查询用户信息:

/// <summary>
        /// 根据编号查询用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Users QueryUsersByName(string name)
        {
            Users user = new Users();
            string sql = "select * from users where name = @name";
            using (SqlDataReader reader = SqlHelper.ExcuteReader(sql, CommandType.Text, new SqlParameter("@name", name)))
            {
                if (reader.Read())
                {
                    user.id = long.Parse(reader[0].ToString());
                    user.name = reader[1].ToString();
                    user.age = Convert.ToInt32(reader[2]);
                    user.phone = reader[3].ToString();
                    user.password = reader[4].ToString();
                    user.address = reader[5].ToString();
                    user.picture = reader[6].ToString();
                }
            }
            return user;
        }

6..保存图片:

  /// <summary>
        /// 保存图片
        /// </summary>
        public string SavePicture()
        {
            if (videoSource == null)
            {
                return null;
            }

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string picture = path + "\\picture\\" + fileName;
            //将图片保存在服务器里面
            bitmap.Save(picture, ImageFormat.Jpeg);
            bitmap.Dispose();
            return picture;
        }

7.人脸登录facelogin

using AForge.Video.DirectShow;
using face;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Camtest
{
    public partial class facelogin : Form
    {
        //Api_Key
        public static string Api_Key = "OVYw5Ok0y9U8n6CfVPYt0wfZ";
        //Secret_Key
        public static string Secret_Key = "aCN3lupCarq3rC9G8Rylqz1d36Towp8G";
        public facelogin()
        {
            InitializeComponent();
            //启动默认在屏幕中间
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        }


        FilterInfoCollection videoDevices;
        VideoCaptureDevice videoSource;
        public int selectedDeviceIndex = 0;
        public int selectedPICIndex = 0;
        //窗体加载
        private void facelogin_Load(object sender, EventArgs e)
        {
            // 刷新可用相机的列表
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            comboBoxCameras.Items.Clear();

            for (int i = 0; i < videoDevices.Count; i++)
            {
                comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());
            }


            if (comboBoxCameras.Items.Count > 0)
                comboBoxCameras.SelectedIndex = 0;
            picsize.SelectedIndex = 0;

            //打开摄像头
            openCamera();
        }

        //打开摄像头
        public void openCamera()
        {
            selectedPICIndex = picsize.SelectedIndex;

            selectedDeviceIndex = comboBoxCameras.SelectedIndex;
            //连接摄像头。
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            // 枚举所有摄像头支持的像素,设置拍照为1920*1080
            foreach (VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (selectedPICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            videoSourcePlayer1.VideoSource = videoSource;

            // set NewFrame event handler
            videoSourcePlayer1.Start();
        }


        /// <summary>
        /// 点击确定的按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //先获取用户名
            //然后在提取图片
            //先查询用户名,看看有没有该用户名
            //有该用户名的话继续判断人脸对应不,没有的话提示没有该用户
            string name = this.textBox1.Text;
            Users user = QueryUsersByName(name);
            if (((string)(user.name))!="")
            {
                //有该用户,判断摄入的人脸和人脸库中的对比
                FaceVerify(SavePicture(),user);
            }
            else { 

                //说明没有该用户,提示用户重新输入用户名
                MessageBox.Show("对不起,检测到没有该用户,请重新输入", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }


        }
        /// <summary>
        /// 人脸认证【登陆】
        /// </summary>
        public  void FaceVerify(string filename,Users users)
        {
            var client = new Baidu.Aip.Face.Face(Api_Key ,Secret_Key);
            var image1 = File.ReadAllBytes(filename);

            var result = client.User.Verify(image1,(users.id).ToString(), new[] { "gr_test" }, 1);


            //先判断脸是不是在上面,在继续看有匹配的没,否则提示放上脸
            //得到根节点
            JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());
            if ((string)jo_result["error_msg"] != null)
            {
                MessageBox.Show("对不起,请把脸放上!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                //检测到脸
                //得到result节点
                JArray jo_age = (JArray)JsonConvert.DeserializeObject(jo_result["result"].ToString());
                string resu = jo_age.ToString();
                int num1 = resu.IndexOf("\n") + 2;
                int num2 = resu.LastIndexOf("]") - 8;
                string ids = resu.Substring(num1, num2);
                if (ids != null || !ids.Equals(""))
                {

                    double scores_num = double.Parse(ids);
                    if (scores_num > 80)
                    {
                        MessageBox.Show("登陆成功,已检测到您的信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("对不起,脸与账户不对应,请换张脸试试", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }

        /// <summary>
        /// 根据编号查询用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Users QueryUsersByName(string name)
        {
            Users user = new Users();
            string sql = "select * from users where name = @name";
            using (SqlDataReader reader = SqlHelper.ExcuteReader(sql, CommandType.Text, new SqlParameter("@name", name)))
            {
                if (reader.Read())
                {
                    user.id = long.Parse(reader[0].ToString());
                    user.name = reader[1].ToString();
                    user.age = Convert.ToInt32(reader[2]);
                    user.phone = reader[3].ToString();
                    user.password = reader[4].ToString();
                    user.address = reader[5].ToString();
                    user.picture = reader[6].ToString();
                }
            }
            return user;
        }



        /// <summary>
        /// 保存图片
        /// </summary>
        public string SavePicture()
        {
            if (videoSource == null)
            {
                return null;
            }

            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
            //图片名称,年月日时分秒毫秒.jpg
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";

            //获取项目的根目录
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string picture = path + "\\picture\\" + fileName;
            //将图片保存在服务器里面
            bitmap.Save(picture, ImageFormat.Jpeg);
            bitmap.Dispose();
            return picture;
        }

        /// <summary>
        /// 取消的按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void close_Click(object sender, EventArgs e)
        {
            //停止摄像头
            videoSourcePlayer1.Stop();
            this.Close();
            welcome we = new welcome();
            we.Show();
        }




    }
}

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/970183.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

opencv中minAreaRect函数输出角度问题

opencv中minAreaRect函数输出角度问题 新版opencv中minAreaRect函数计算最小外接矩形时&#xff0c;角度范围由旧版的[-90, 0]变为[0, 90]。 cv2.minAreaRect输入&#xff1a;四边形的四个点&#xff08;不要求顺序&#xff09;。 输出&#xff1a;最小外接矩形的中心点坐标x…

Eclipse:关闭多余的工具条

Eclipse默认的工具条非常多&#xff0c;可以通过如下方法选择关闭一些不常用的&#xff1a; 1.选择菜单Window -> Perspective -> Customize Perspective 2.根据需要勾选Toolbar Visbility下面的工具条项

电商小程序(源码+文档+部署+讲解)

引言 随着移动互联网的快速发展&#xff0c;电商小程序成为连接消费者与商家的重要桥梁。电商小程序通过数字化手段&#xff0c;为消费者提供了一个便捷、高效的购物平台&#xff0c;从而提升购物体验和满意度。 系统概述 电商小程序采用前后端分离的架构设计&#xff0c;服…

MySQL单表存多大的数据量比较合适

前言 经常使用MySQL数据库的小伙伴都知道&#xff0c;当单表数据量达到一定的规模以后&#xff0c;查询性能就会显著降低。因此&#xff0c;当单表数据量过大时&#xff0c;我们往往要考虑进行分库分表。那么如何计算单表存储多大的数据量合适&#xff1f;当单表数据达到多大的…

Visual Studio Code支持WSL,直接修改linux/ubuntu中的文件

步骤1 开始通过 WSL 使用 VS Code | Microsoft Learn 点击远程开发扩展包。 步骤2 Remote Development - Visual Studio Marketplace 点击install&#xff0c; 允许打开Visual Studio Code。 步骤3 共有4项&#xff0c;一齐安装。 步骤4 在WSL Linux(Ubuntu)中&#xf…

微服务SpringCloud Alibaba组件nacos教程【详解naocs基础使用、服务中心配置、集群配置,附有案例+示例代码】

一.Nacos教程 文章目录 一.Nacos教程1.1 Nacos简介1.2 nacos基本使用直接下载打包服务源码方式启动 1.3 创建nacos客服端1.4 nacos集群配置1.5 nacos配置中心 1.1 Nacos简介 nacos是spring cloud alibaba生态中非常重要的一个组件&#xff0c;它有两个作用&#xff1a; 1:注册…

2024年终总结和2025年规划

2024年的主线是AI基础的学习和读书&#xff0c;虽然AI学习花费了更多的时间&#xff0c;但是读书长久看来于我是更重要的事情&#xff0c;哈哈哈&#xff0c;因此先简单回顾一下读书记忆&#xff0c;回顾我的2024&#xff0c;再展望一下我的2025. 我的2024年记忆 读万卷书&am…

实时云渲染:驱动XR技术产业化腾飞的核心引擎

在科技飞速发展的当下&#xff0c;扩展现实&#xff08;XR&#xff09;技术正以前所未有的速度融入人们的生活与工作&#xff0c;为用户打造出沉浸式逼真的虚拟环境。据知名XR媒体XR Today的最新数据显示&#xff0c;2024年全球XR市场规模已突破500亿美元&#xff0c;预计到202…

【AI编程】体验a0.dev:专为移动端app的对话式AI编程工具

摘要 体验专为移动端APP开发的AI编程工具 a0.dev&#xff0c;并附上实践过程和价格说明 体验a0.dev&#xff1a;专为移动端app的对话式AI编程工具 最近在探索新的AI编程工具时&#xff0c;发现了a0.dev&#xff0c;一个专注于移动端应用开发的对话式AI编程工具。今天就和大家分…

基于若依开发的工程项目管系统开源免费,用于工程项目投标、进度及成本管理的OA 办公开源系统,非常出色!

一、简介 今天给大家推荐一个基于 RuoYi-Flowable-Plus 框架二次开发的开源工程项目管理系统&#xff0c;专为工程项目的投标管理、项目进度控制、成本管理以及 OA 办公需求设计。 该项目结合了 Spring Boot、Mybatis、Vue 和 ElementUI 等技术栈&#xff0c;提供了丰富的功能…

数据库数据恢复—MongoDB丢失_mdb_catalog.wt文件导致报错的数据恢复案例

MongoDB数据库存储模式为文档数据存储库&#xff0c;存储方式是将文档存储在集合之中。 MongoDB数据库是开源数据库&#xff0c;同时提供具有附加功能的商业版本。 MongoDB中的数据是以键值对(key-value pairs)的形式显示的。在模式设计上&#xff0c;数据库受到的约束更少。这…

小米 R3G 路由器(Pandavan)实现网络打印机功能

小米 R3G 路由器&#xff08;Pandavan&#xff09;实现网络打印机功能 一、前言 家中有多台 PC 设备需要打印服务&#xff0c;但苦于家中的 Epson L380 打印机没有网络打印功能&#xff0c;并且配置 Windows 共享打印机实在是过于繁琐且需要共享机保持唤醒状态过于费电。想到…

笔记8——模式匹配 match语句(仅在Python 3.10及以上版本中可用)

文章目录 模式匹配 match语句(仅在 Python 3.10及以上版本 中可用)基本语法基本匹配操作应用场景 模式匹配 match语句(仅在 Python 3.10及以上版本 中可用) Python 3.10 及以上版本中才引入了 match 语句用于简化复杂的条件判断和数据解构&#xff1b;类似于其他语言中的 swit…

Edge浏览器清理主页

我们都知道&#xff0c;Microsoft Edge浏览器是微软创造的搜索浏览器&#xff0c;Windows10、11自带。但是你可以看到&#xff0c;每次你打开Edge浏览器的时候都可以看到许多的广告&#xff0c;如图&#xff1a; 导致打开Edge浏览器的时候会遭受卡顿&#xff0c;广告骚扰&#…

JVM类加载和垃圾回收(详细)

文章目录 JVM介绍JDK/JRE/JVM的关系 内存结构堆程序计数器虚拟机栈本地方法栈本地内存 类文件字节码文件结构 类加载类的生命周期加载类加载器双亲委派模型 链接初始化类卸载 垃圾回收堆空间的基本结构内存分配和回收原则死亡对象判断方法垃圾收集算法垃圾收集器 JVM 介绍 JD…

算法——结合实例了解深度优先搜索(DFS)

一&#xff0c;深度优先搜索&#xff08;DFS&#xff09;详解 DFS是什么&#xff1f; 深度优先搜索&#xff08;Depth-First Search&#xff0c;DFS&#xff09;是一种用于遍历或搜索树、图的算法。其核心思想是尽可能深地探索分支&#xff0c;直到无法继续时回溯到上一个节点…

[c语言日寄]在不完全递增序中查找特定要素

【作者主页】siy2333 【专栏介绍】⌈c语言日寄⌋&#xff1a;这是一个专注于C语言刷题的专栏&#xff0c;精选题目&#xff0c;搭配详细题解、拓展算法。从基础语法到复杂算法&#xff0c;题目涉及的知识点全面覆盖&#xff0c;助力你系统提升。无论你是初学者&#xff0c;还是…

计算机视觉-局部特征

一、局部特征 1.1全景拼接 先用RANSAC估计出变换&#xff0c;就可以拼接两张图片 ①提取特征 ②匹配特征 ③拼接图像 1.2 点的特征 怎么找到对应点&#xff1f;&#xff08;才能做点对应关系RANSAC&#xff09; &#xff1a;特征检测 我们希望找到的点具有的特征有什么特…

实践记录-NAS入手前后的记录-关于设备选型的练习

快速回顾 知道nas是干啥的不&#xff0c;你买这东西准备干啥&#xff1f;你准备花多少预算啊&#xff1f;在配置性能/价格/需求之间做个取舍和平衡&#xff1b;看看设备到底怎么样&#xff1f;入手体验如何&#xff1f; 参考来源 服务器和网络设备的技术方案设计和设备选型的…

机器学习 - 词袋模型(Bag of Words)实现文本情感分类的详细示例

为了简单直观的理解模型训练&#xff0c;我这里搜集了两个简单的实现文本情感分类的例子&#xff0c;第一个例子基于朴素贝叶斯分类器&#xff0c;第二个例子基于逻辑回归&#xff0c;通过这两个例子&#xff0c;掌握词袋模型&#xff08;Bag of Words&#xff09;实现文本情感…