Hello, I’m Rich

At the beginning of my writing, I once wrote an article about the face recognition function realized based on Java. At the beginning, I did not know what to write, so I made a simple Demo of personal face recognition.

But to my surprise, in the past year, a lot of fans added me to ask about this little demo. Because there were some small bugs in it, some novice friends could not start it successfully.

From then on, I started to answer all kinds of questions, but my energy was limited, and finally I couldn’t answer them, so I simply created a group of fans to share experience with each other.

Problem area appeared again I thought out a complete version of the demo, can work at home to get a lot of things have no energy at all, have been dragged to now, just now the face recognition login function to use on their own projects, to take this opportunity to share out, this time, as far as possible not for everyone to keep bugs (buried) ha ha ha.

Before the specific operation, please check the effect of the finished product. Online preview address: Fire100. Top, here you can rest assured that facial pictures will not be collected, only facial features are extracted, and not uploaded to the cloud. Below we ice ice to do a demonstration to see the effect, recognition speed and success rate is still good.

Functional process

The whole function of the logic is simple, the front camera, recognition to the face after the photos uploaded to the background, the back-end SDK to identify facial features in the image, and users of the database to face feature do the success (similarity between 0.8 ~ 1 is the same person) login, such as recognition to face but there is no success within the database, as a new user registration.

Note: If you want to apply online, you must use HTTPS to bring up the camera. There are no restrictions on local testing.

To apply for the SDK

Before starting the project, we need to do some preparation. Because we use the face recognition SDK of three parties, we need to apply for an account on the platform first, and then download the corresponding VERSION of SDK.

Website address: ai.arcsoft.com.cn/ucenter/res…

Why don’t you write your own face recognition? Don’t ask. Ask and you won’t!

At present, Linux, Windows, IOS and Android versions are supported. Each real-name authentication account can activate 100 devices. In other words, the SDK applied for by the same account can run on 100 devices, which is generally enough.

Libs is the most important in the downloaded SDK package directory structure, samplecode has samplecode, and doc has API documentation. What we need is arcsoft-SDK-face-3.0.0.0. jar in LIBS, and the engine files of the three corresponding platforms. DLL or.so files.

Project configuration

The project itself is springboot + VUE front-end and back-end separation, but for the sake of friends out of the box, I put this function front-end and back-end integration together, and then use a JPA to do persistence, the table does not need to build, to save you some time.

I encountered a bit of a glitch when using the SDK, so I’ll go into more details below

First, create a lib directory in the root directory of the project where the Springboot startup class is located, and put the arcsoft-sdK-face-3.0.0.0. jar extracted from the SDK into it, and import this jar in the POP.xml file.

<dependency>
   <groupId>com.arcsoft.face</groupId>
    <artifactId>arcsoft-sdk-face</artifactId>
    <version>3.0. 0. 0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/arcsoft-sdk-face-3.0. 0. 0.jar</systemPath>
</dependency>
Copy the code

Maven package configuration must include includeSystemScope so that maven package will include external jar packages (such as those added in the root directory or resource file) into the project JAR so that the project can run on the server.

Without this configuration, it can run locally because external packages can be found locally in lib, but not in jars on the server.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot.version}</version>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
        <fork>true</fork>
        <mainClass>com.firebook.FireBookApplication</mainClass>
        <skip>false</skip>
    </configuration>
</plugin>
Copy the code

The configuration of application.yml file is easier, set up a database to store face feature data, fill in the appId and sdkKey obtained when applying for SDK, and set path to the file path of engine file. DLL or.

spring: datasource: # type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: JDBC: mysql: / / 127.0.0.1:3306 / face? useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: 123456 # face recognition - Windows face: appId: # * * * * * * * * * * * * * * * * * * * * * sdkKey: # * * * * * * * * * * * * * * * * * * * * * path: D: / / faceCopy the code

Configured the direct execution FireControllerApplication, visit: 127.0.0.1:8081 / login/face.

Here I will not be a large section of the source to the post, interested partners to obtain their own links to download the source code to play.

Download the source code

Web face recognition login complete source has been uploaded to Github, source address github.com/chengxy-nds… If you have any questions, please feel free to ask.