Due to the needs of work, the author developed a set of freshman enrollment identity verification system, which is used for real-time verification of freshmen’s identity (the Ministry of Education requires freshmen to conduct face comparison when they enter the university), and real-time statistics of freshmen’s registration situation. The verification process is as follows: Students register with their ID cards, read their ID information (including name, ID number and photo in the chip) through the ID card reader, and obtain their admission information (college, class, student number and photo in the admission library, etc.) according to the ID number. After confirming that they are freshmen in the admission library, their on-site photos are collected by camera. Then compare the id card photos, admission library photos and on-site photos collected, the identity authentication of freshmen can be completed if the three are consistent, and finally can export data result files and archived photo files. In order to reduce the threshold of use, the system adopts C/S structure, the server is ASP.NET core WebAPI, which can be used without configuration, and the client is developed by WPF. In the face comparison algorithm package selection, the author inspected the MAIN several manufacturers of SDK, in a comprehensive consideration of ease of use, document quality and demo quality, the final choice of Hongsoft products. The client interface is as follows:

During the development of this project, I would like to share with you some experiences:

  1. B/S, C/S structure selection

Since the client needs to connect id card reader and a camera (can be used to obtain high quality demand of photos of SLR cameras, the current application support connection Canon cameras), adopts B/S structure requires a separate connection hardware development, and considering the B/S server deployment and operational costs, the project finally chose the C/S structure of development. The server uses asp.net core self-host webapi and can be started by running the program directly. The interface is as follows after the server is started:

2. The choice of face alignment algorithm As application development, also is the first time contact face than application, the author examines the baidu, ali, rainbow soft several SDK library, finally given the recognition efficiency and quality of document and demo (mainly have the free version can learn quickly) and price, finally choose soft rainbow SDK for development. Face comparison on the server side or in the client side, the initial choice was also made. The advantage of comparison on the server side is that SDK authorization on the client side is not required (saving costs), but the disadvantage is that it requires high requirements on the server and requires two requests to obtain the comparison result. The advantage of comparison on the client is that the results can be obtained after obtaining students’ information, but the disadvantage is that the cost increases (each client requires independent authorization). Considering the actual situation of this project, the final face comparison is carried out on the client side, thus reducing the pressure of the server (the server only provides WebAPI service, and ordinary notebook can be competent), and the activation cost of the client side is within the acceptable range. Face recognition engine initialization code is as follows:

        private void InitEnginesAppSettingsReader = 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)); / / judgment CPU digits 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 APP_ID and SDKKEY{0}!, is64CPU ? "64" : "32"));
                return; } // If an error occurs during the online activation, 1. Ensure that the SDK library downloaded from the official website has been placed in the corresponding bin. 2. Int retCode = 0; try { retCode = imageLiveEngine.ASFOnlineActivation(appId, is64CPU ? sdkKey64 : sdkKey32, is64CPU ? activeKey64: activeKey32);if(retCode ! = 0 && retCode ! = 90114) { System.Windows.MessageBox.Show("Failed to activate SDK, error code :" + retCode);
                    return;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Unable to load DLL"))
                {
                    System.Windows.MessageBox.Show("Please put sdK-related DLLS in the x86 or X64 folder corresponding to bin!");
                }
                else
                {
                    MessageBox.Show("Failed to activate SDK, please check dependent environment and SDK platform, version is correct first! \r\n"+ex.Message); } System.Environment.Exit(0); } // DetectionMode detectMode = detectionmode_image; / / Video mode detection face Angle priority value ASF_OrientPriority videoDetectFaceOrientPriority = ASF_OrientPriority. ASF_OP_ALL_OUT; / / Image mode to detect the face Angle priority value ASF_OrientPriority imageDetectFaceOrientPriority = ASF_OrientPriority. ASF_OP_ALL_OUT; Int detectFaceScaleVal = 16; int detectFaceScaleVal = 16; Int detectFaceMaxNum = 5; / / engine initialization time need to initialize the detection combination int combinedMask = FaceEngineMask. ASF_FACE_DETECT | FaceEngineMask. ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE | FaceEngineMask.ASF_IMAGEQUALITY; // Initialize engine, normal value is 0, Other return values retCode = please refer to http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e imageLiveEngine.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask); txtLogAppend("InitEngine Result:" + retCode);
            txtLogAppend((retCode == 0) ? "Engine initialization successful!" : string.Format("Engine initialization failed! Error code :{0}", retCode));
            if(retCode ! = 0) {return;
            }
            isFaceSDKEnabled = true;           
        }
Copy the code

This project involves 3 photos. Users can customize the photos to be compared (at least 2 photos and at most 3 photos), first obtain the characteristic values of the 3 photos, and then compare them in pairs. The code is as follows:

    isPassed = true;
    if(currentExam IsCompareWithIDCardImage) / / acquisition and photo id photo comparisons {similarity = 0 f; // Call the comparison functionif(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) / / collect pictures and admissions library than {similarity = 0 f;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) / / admission library and photo id photo comparisons {similarity = 0 f;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;
    }
Copy the code

Face comparison can choose the photo mode, among which ASF_compareModel.ASF_ID_photo is the document or life photo and document photo comparison mode.

  1. Database selection and query optimization

Considering the deployment cost and the project’s low requirements for database and concurrency, the database is developed using SQLite and based on CodeFirst, and the database structure is automatically generated. The data stored in a separate database every year, in order to realize database switch, can change the database connection string, or rename existing database, or to operate more troublesome, this project implements in management side can set the current use of database and the new database, switch and convenient database query.

The code for database switching is as follows:

// <summary> // update database connection, implement switch 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);
        }
Copy the code

The project uses the domestic DATABASE ORM framework FreeSql, and the database uses a connection pool to support multiple types of database connections. This project only uses SQLite, and you can switch databases in real time depending on the filename you choose.

When querying statistics information, it is time-consuming to query statistics according to colleges, majors and classes when the number of classes is large. Classification data such as professional, class didn’t do the navigation table, if there are 100 classes, respectively to query each class has reported the number of boys and girls, class a total of, total number of girls, boys will need 400 database query, this is unacceptable, then development phase with the test data of enough, did not think of this place has a problem, The problem was discovered only after the actual admission data was imported one day before the project was launched, and it took an all-nighter to solve the problem).As a solution, the author proposes to query all the student data at one time, and then conduct LING query in memory to collect all the data. The above is the author of the rainbow soft face algorithm to develop freshmen registration identity authentication system in some experience, improper place please criticize and correct.To learn more about face recognition products, please visitRainbow soft visual open platformoh