Due to the needs of work and business, the author has developed a set of freshman enrollment identity verification system, which is used to verify the identity of Freshmen in real time when they enter school (the Ministry of education requires freshmen to conduct face comparison when they enter school), and count the check-in situation of Freshmen in real time. The name of ID number is that the student reads the ID card and reads the ID card information (including the name, ID number and photos in the chip). The student's admission information is obtained according to the ID card number (college, class, student number, and photo in the Library). It is confirmed that the photo is collected by the camera after the enrollment of the library, and then the photo is compared with the ID card photo. The identity authentication of freshmen can be completed if the library photos and the collected on-site photos are consistent, and finally the data result file and archived photo file can be exported. In order to reduce the use threshold, the system adopts C/S structure and the server is ASP Net core webapi, which can be used without configuration, and the client is developed by WPF. When selecting the face comparison algorithm package, the author investigated the SDKs of several major manufacturers. After comprehensively considering the ease of use, document quality and demo quality, the author finally chose Hongruan company Products. The client operation interface is as follows:
During the development of the project, I would like to share with you some experiences:
- Selection of B/S and C/S structure because the client needs to connect the ID card reader and camera (SLR camera can be used for those with high requirements on the quality of collected photos, and the current program supports connecting Canon camera), the websocket connection hardware needs to be developed separately for the B/S structure, and considering the cost of B/S server deployment and operation and maintenance, the C/S structure is finally selected for the development of the project. The server adopts ASP Net core self host webapi, which can be started by directly running the program. After the server is started, the interface is as follows:
2. The selection of face comparison algorithm is due to application development and the first contact with face comparison application. The author inspected several sdk libraries of Baidu, Alibaba and hongruan. Finally, considering the recognition efficiency, document quality, demo quality (mainly free version for quick learning) and cost performance, the author finally chose hongruan sdk for development. At first, a choice was made as to whether the face comparison should be carried out on the server or on the client. The advantage of server-side comparison is that there is no need to authorize the sdk on the client (saving cost), but the disadvantage is that it requires high requirements on the server and requires two requests to get the comparison results; The advantage of client-side comparison is that after obtaining the student information, the comparison can be carried out to obtain the results. The disadvantage is that the cost increases (each client needs independent authorization). Considering the actual situation of this project, the final face comparison is carried out on the client, so as to reduce the pressure of the server (the server only provides webapi services, and ordinary notebooks can be competent), and the activation cost of the client is within the acceptable range. The initialization code of face recognition engine is as follows:
private void InitEngines() { //Read configuration file AppSettingsReader reader = new AppSettingsReader(); string appId = (string)reader.GetValue("APPID", typeof(string)); string sdkKey64 = (string)reader.GetValue("SDKKEY64", typeof(string)); string sdkKey32 = (string)reader.GetValue("SDKKEY32", typeof(string)); string activeKey64 = (string)reader.GetValue("ACTIVEKEY64", typeof(string)); string activeKey32 = (string)reader.GetValue("ACTIVEKEY32", typeof(string)); //Judge CPU bits var is64CPU = Environment.Is64BitProcess; string appId = is64CPU ? appId64 : appId32; if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(is64CPU ? sdkKey64 : sdkKey32) || string.IsNullOrWhiteSpace(is64CPU ? activeKey64 : activeKey32)) { System.Windows.MessageBox.Show(string.Format("Please configure first APP_ID and SDKKEY{0}!", is64CPU ? "64" : "32")); return; } //If an error occurs in the online activation engine, 1 Please confirm that the sdk library downloaded from the official website has been placed in the corresponding bin, 2 The currently selected CPU is x86 or x64 int retCode = 0; try { retCode = imageLiveEngine.ASFOnlineActivation(appId, is64CPU ? sdkKey64 : sdkKey32, is64CPU ? activeKey64: activeKey32); if (retCode != 0 && retCode != 90114) { System.Windows.MessageBox.Show("activation SDK fail,Error code:" + retCode); return; } } catch (Exception ex) { if (ex.Message.Contains("Unable to load DLL")) { System.Windows.MessageBox.Show("Will please SDK relevant DLL Put bin Corresponding x86 or x64 Folder under!"); } else { MessageBox.Show("activation SDK fail,Please check the environment first SDK Is the platform and version correct! \r\n"+ex.Message); } System.Environment.Exit(0); } //Initialize engine DetectionMode detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE; //Detecting the angle priority value of the face in Video mode ASF_OrientPriority videoDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_ALL_OUT; //Priority value of face angle detection in Image mode ASF_OrientPriority imageDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_ALL_OUT; //The proportion of faces in the picture. If you need to adjust the size of the detected face, please modify this value. The valid values are 2-32 int detectFaceScaleVal = 16; //Maximum number of faces to detect int detectFaceMaxNum = 5; //Detection function combination that needs to be initialized during engine initialization int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE | FaceEngineMask.ASF_IMAGEQUALITY; //Initialize the engine. The normal value is 0. Please refer to other return values http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e retCode = imageLiveEngine.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask); txtLogAppend("InitEngine Result:" + retCode); txtLogAppend((retCode == 0) ? "Engine initialization succeeded!" : string.Format("Engine initialization failed!The error code is:{0}", retCode)); if (retCode != 0) { return; } isFaceSDKEnabled = true; }
This project involves 3 photos. Users can customize and select the photos to be compared (at least 2, up to 3). First obtain the eigenvalues of 3 photos, and then compare them in pairs. The code is as follows:
isPassed = true; if (currentExam.IsCompareWithIDCardImage)//Collect photos and compare ID photos { similarity = 0f; //Call the comparison function if (imageLiveFeature.Feature != null && imageICFeature.Feature != null) ret = imageLiveEngine.ASFFaceFeatureCompare(imageLiveFeature.Feature, imageICFeature.Feature, out similarity, ASF_CompareModel.ASF_ID_PHOTO); if (similarity.ToString().IndexOf("E") > -1) similarity = 0f; if (similarity * 100 < threashHold) isPassed = false; } if (currentExam.IsCompareWithRegImage)//Comparison of collected photos and admission library photos { similarity = 0f; if (imageLiveFeature.Feature != null && imageStudentFeature.Feature != null) ret = imageLiveEngine.ASFFaceFeatureCompare(imageLiveFeature.Feature, imageStudentFeature.Feature, out similarity, ASF_CompareModel.ASF_ID_PHOTO); if (similarity.ToString().IndexOf("E") > -1) { similarity = 0f; } if (similarity * 100 < threashHold) isPassed = false; } if (currentExam.IsCompareRegWithIDCardImage)//Comparison of admission library photos and ID card photos { similarity = 0f; if (imageICFeature.Feature != null && imageStudentFeature.Feature != null) ret = imageLiveEngine.ASFFaceFeatureCompare(imageICFeature.Feature, imageStudentFeature.Feature, out similarity, ASF_CompareModel.ASF_ID_PHOTO); if (similarity.ToString().IndexOf("E") > -1) { similarity = 0f; } if (similarity * 100 < threashHold) isPassed = false; }
Photo mode can be selected for face comparison, in which ASF_CompareModel.ASF_ID_PHOTO is the comparison mode between certificate photo or life photo and certificate photo.
- Database selection and query optimization are based on the consideration of deployment cost and low requirements of the project itself for database and concurrency. The database adopts SQLite and is developed based on CodeFirst, and the database structure will be generated automatically. The annual data is stored in a separate database. To realize database switching, you can modify the database connection string or rename the existing database, which is still troublesome. In this project, you can set the currently used database and the newly built database at the management end, so as to facilitate database switching and query.
The code of database switching is as follows:
/// <summary> ///Update the database connection to switch the database SQLite. /// </summary> public static void SqliteSelect(string strDatabaseName) { if (ConnectionPool.ContainsKey("Sqlite")) ConnectionPool.Remove("Sqlite"); string conn = getConnectionString("Sqlite"); conn = conn.Replace("Database.db", strDatabaseName); var freesql = new FreeSql.FreeSqlBuilder() .UseConnectionString(EnumHelper.StringConvertToEnum<DataType>("Sqlite"), conn) .UseAutoSyncStructure(true) .UseLazyLoading(false) .Build(); freesql.Aop.ConfigEntityProperty += Aop_ConfigEntityProperty; ConnectionPool.Add("Sqlite", freesql); }
The project uses the domestic database ORM framework FreeSql , the database uses a connection pool that supports multiple types of database connections. This project only uses SQLite, and the database can be switched in real time according to the selected file name.
When querying statistical information, statistics need to be divided into colleges, majors and classes. When the number of classes is large, one query is very time-consuming. Since there is no navigation table for classified data such as majors and classes, if there are 100 classes, 400 database queries are needed to query the reported number of boys and girls, the total number of boys and girls in each class, This is unacceptable (at that time, there were not enough test data used in the development stage, so I didn't think there was a problem in this place. It was found that the problem was serious after importing the actual admission data the day before the project went online, and it took all night to solve the problem). As a solution, the scheme given by the author is to query all student data at one time, and then conduct LING query in memory to count various data. The above is the author's experience in using hongruan face algorithm to develop the freshman check-in identity authentication system. Please criticize and correct any wrongdoing. For more information about face recognition products, please visit Hongruan vision open platform oh