In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve Baidu face recognition in C#, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.
1. Sign up for Baidu account api and create your own application
Registered address: https://login.bce.baidu.com/
After registering and logging in, find face recognition under the "Product Services" menu, as shown below:
Click to create your own application name, in fact, the most important are API_key and Secret_key
With these, you can further look at the SDK documents provided by Baidu.
This is the SDK address of Baidu: http://ai.baidu.com/sdk
Choose your favorite development language for research. The documentation is very detailed and Demo is available in the download.
I use C# for research.
Reference address: http://ai.baidu.com/docs#/Face-Csharp-SDK/top
2. Create a vs console application and introduce a dynamic link library
Create a console application named FaceRecognition
Then refer to the dynamic link library (install face SDK), I use vs2017, using method one.
Method 1: use Nuget to manage dependencies (recommended)
Search NuGet for Baidu.AI and install the latest version.
Packet address https://www.nuget.org/packages/Baidu.AI/
Method 2: download and install
Face C # SDK directory structure
Baidu.Aip ├── net35 │ ├── AipSdk.dll / / Baidu AI Services windows dynamic library │ ├── AipSdk.xml / / comment file │ └── Newtonsoft.Json.dll / / third-party dependence on ├── net40 ├── net45 └── netstandard2.0 ├── AipSdk.deps.json └── AipSdk.dll
If you need to use it on the Unity platform, you can quote the project source code to compile it yourself.
Installation
1. Download the C # SDK compression kit from the official website.
two。 After decompressing, add AipSdk.dll and Newtonsoft.Json.dll as references.
3. Write code and debug, and view the effect picture.
Register a human face
Face recognition
First of all, we prepare a picture that can recognize the face, put it on the public platform, if Baidu cloud disk, and then share it, copy the image address.
Register faces:
Write code in Program.cs
Using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace FaceRecognition {class Program {static void Main (string [] args) {/ / set APPID/AK/SK var API_KEY = "XFPA49myCG7S37XP1DxjLbXF"; / / your Api Key var SECRET_KEY = "ZvZKigrixMLXNZOLmkrG6iDx9QprlGuT"; / / your Secret Key var client = new Baidu.Aip.Face.Face (API_KEY, SECRET_KEY) Client.Timeout = 60000 / / modify timeout / / depends on image_type parameter Pass in BASE64 string or URL string or FACE_TOKEN string / / the path of the picture you share (click on the path to view the picture directly) var image = "https://thumbnail0.baidupcs.com/thumbnail/32f3cc8f022839a4dbf6b9f9cca76ce8?fid=3145591938-250528-218900036170682&time=1550282400&rt=sh&sign=FDTAER-DCb740ccc5511e5e8fedcff06b081203-sTBqvQbbBy3n5SDQfbtjNwjlSHg%3D&expires=8h&chkv=0&chkbd=0&chkpc=&dp-logid=1077356968076791248&dp-callid=0&size=c710_u400&quality=100&vuk=-&ft=video"; Var imageType = "URL"; / / register face var groupId = "group1"; var userId = "user1"; / / call face registration, which may throw network and other exceptions. Use try/catch to capture var result = client.UserAdd (image, imageType, groupId, userId); Console.WriteLine (result). / / if there are optional parameters var options = new Dictionary {{"user_info", "user's info"}, {"quality_control", "NORMAL"}, {"liveness_control", "LOW"}}; / / call face registration result = client.UserAdd (image, imageType, groupId, userId, options) with parameters Console.WriteLine (result);}
After running, whether the console print is successful or not, Baidu api console to check whether the registration is successful.
Console effect picture:
Baidu api console to view the results:
Obviously, we successfully registered faces, and then we did face recognition, and we used registered pictures and unregistered pictures for verification.
Recognize other people's faces:
Also write the code in Program.cs, and we can comment out the previous code, as follows:
Using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace FaceRecognition {class Program {static void Main (string [] args) {/ / set APPID/AK/SK var API_KEY = "XFPA49myCG7S37XP1DxjLbXF"; / / your Api Key var SECRET_KEY = "ZvZKigrixMLXNZOLmkrG6iDx9QprlGuT"; / / your Secret Key var client = new Baidu.Aip.Face.Face (API_KEY, SECRET_KEY) Client.Timeout = 60000 / / modify timeout / / depends on image_type parameter Pass in BASE64 string or URL string or FACE_TOKEN string / / the path of the picture you share (click on the path to view the picture directly) var image = "https://thumbnail0.baidupcs.com/thumbnail/32f3cc8f022839a4dbf6b9f9cca76ce8?fid=3145591938-250528-218900036170682&time=1550282400&rt=sh&sign=FDTAER-DCb740ccc5511e5e8fedcff06b081203-sTBqvQbbBy3n5SDQfbtjNwjlSHg%3D&expires=8h&chkv=0&chkbd=0&chkpc=&dp-logid=1077356968076791248&dp-callid=0&size=c710_u400&quality=100&vuk=-&ft=video"; Var imageType = "URL"; / / register face / / var groupId = "group1"; / / var userId = "user1"; / / call face registration, which may throw network and other exceptions. Use try/catch to catch / / var result = client.UserAdd (image, imageType, groupId, userId); / / Console.WriteLine (result) / if there are optional parameters / / var options = new Dictionary {/ / {"user_info", "user's info"}, / / {"quality_control", "NORMAL"}, / / {"liveness_control", "LOW"} / /} / call face registration with parameters / / result = client.UserAdd (image, imageType, groupId, userId, options); / / Console.WriteLine (result); / / face recognition (recognition in the registered face database) / / call face detection, which may throw network and other exceptions. Use try / catch to capture var result = client.Detect (image, imageType); Console.WriteLine (result) / / if there are optional parameters var options = new Dictionary {{"face_field", "age"}, {"max_face_num", 2}, {"face_type", "LIVE"}}; / / call face detection result = client.Detect (image, imageType, options) with parameters; Console.WriteLine (result) }}}
Console effect picture:
Obviously, we also succeeded in face recognition.
4. Summary
We just use the console to do a simple registration and identification, delete and update is the same, you can directly go to the official website to copy, the path is: http://ai.baidu.com/docs#/Face-Csharp-SDK/3b8dc2e8
With this simple demo, we can register, identify, update and so on with the camera.
Pay attention to whether the editor is lost or not. Next time we will call the camera to complete the registration, identification, update, deletion and other operations.
Thank you for reading this article carefully. I hope the article "how to realize Baidu face recognition in C#" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.