A face recognition method integrating Euclidean distance and homomorphic encryption
Through the facial recognition method that integrates Euclidean distance and homomorphic encryption, the problem of weak data security in facial recognition technology is solved, efficient calculation and accurate recognition under encryption conditions are achieved, and data security and recognition efficiency are ensured. .
Patent Information
- Application Number
- CN202210603236.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-30
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-05-30
AI Technical Summary
Existing facial recognition technology has weak security during data storage and transmission, and traditional encryption methods cannot achieve feature matching on the ciphertext domain, resulting in the risk of privacy leakage.
Using a face recognition method that combines Euclidean distance and homomorphic encryption, the face feature value is obtained locally for homomorphic encryption, and transmits it to the cloud server for Euclidean distance calculation. After returning the ciphertext difference value, it is clear text decrypted and calculated locally. , realize face recognition.
It improves the accuracy and security of facial recognition, ensures that data is not leaked, and greatly improves computing efficiency, and is suitable for practical application scenarios.
Smart Images

Figure CN114973373B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of face recognition, and in particular relates to a face recognition method integrating Euclidean distance and homomorphic encryption. Background Art
[0002] Face-based authentication systems are widely used in law enforcement, payment, transportation, access control, and e-government. Compared with traditional identity authentication mechanisms, face recognition is not easily forgotten or damaged, is easy to use, and can effectively improve the efficiency of authentication. One of the common attacks on face authentication is the face feature template library. For example, the original face image reconstructed by the attacker can be successfully authenticated, and personal attributes such as age and gender can also be inferred. These face feature templates all involve privacy, and the feature template data stored in the cloud template database may be leaked. The usual solution is to encrypt the face feature template and then upload it to an untrusted third party, but feature matching on the ciphertext domain cannot be achieved.
[0003] In today's face recognition, the security factor of the server storing faces is relatively weak, or internal personnel are buying and selling data. The face data in the server is easily leaked or stolen after being stolen during storage or transmission, causing privacy leakage. However, traditional encryption methods cannot match facial features. This requires the use of face recognition based on homomorphic encryption. Summary of the invention
[0004] The purpose of the present invention is to provide a face recognition method integrating Euclidean distance and homomorphic encryption, which is conducive to improving the accuracy and security of face recognition while improving computational efficiency.
[0005] To achieve the above object, the technical solution adopted by the present invention is: a face recognition method integrating Euclidean distance and homomorphic encryption, comprising the following steps:
[0006] Step S1: When the user performs identity recognition, the facial feature value is obtained locally, and then the facial feature value is encrypted based on homomorphic encryption to obtain the facial feature value ciphertext, and then the facial feature value ciphertext and key are sent to the cloud server;
[0007] Step S2: The cloud server loads the key and the facial feature value ciphertext, calculates the Euclidean distance between the facial feature value ciphertext currently uploaded locally and the facial feature value ciphertext of the known name uploaded by the user when registering, and obtains the ciphertext difference; then the calculated ciphertext difference is sent back to the local for subsequent calculation;
[0008] Step S3: Decrypt the ciphertext difference locally, then calculate the local Euclidean distance of the plaintext to obtain the Euclidean distance of the face, and finally give the user identity recognition result based on the obtained Euclidean distance of the face.
[0009] Furthermore, in step S1, the facial feature value is obtained as follows:
[0010] Step S101: locally obtaining an image of a video frame through a camera, adjusting the size of the image to speed up face recognition processing, and then converting the image from BGR color to RGB color;
[0011] Step S102: Perform face detection to find all faces in the image;
[0012] Step S103: Correcting the posture using facial feature points to turn the side face into the front face;
[0013] Step S104: Calculate facial feature values based on facial feature points.
[0014] Furthermore, in step S1, the CKKS encryption scheme in homomorphic encryption is used to generate a key, and the key parameters, private key, and public key are saved locally; then the facial feature value is homomorphically encrypted using the local public key to obtain the facial feature value ciphertext, and then the facial feature value ciphertext and the public key and parameters of the key are sent to the cloud server.
[0015] Furthermore, in step S2, the encapsulated ciphertext subtraction function is used to perform a subtraction calculation on the ciphertext of the facial feature value currently uploaded locally and the ciphertext of the facial feature value of the known name uploaded by the user during registration stored in the database; the Euclidean distance formula for facial feature value calculation and judgment is as follows:
[0016]
[0017] Through the ciphertext subtraction function, we can obtain the Euclidean distance (x i -y i );
[0018] Then, the calculated ciphertext difference is sent back to the local for subsequent calculation.
[0019] Furthermore, the step S3 specifically includes the following steps:
[0020] Step S301: Locally decrypt the ciphertext difference using the private key of the key to obtain a multi-dimensional difference vector;
[0021] Step S302: According to the obtained Euclidean formula (x i -y i ), square the multidimensional difference vector in the plaintext domain to obtain a multidimensional square vector (x i -y i ) 2 ;
[0022] Step S303: Sum the multi-dimensional square vector to obtain
[0023] Step S304: Perform square root calculation to obtain the face Euclidean distance:
[0024]
[0025] Step S305: Update the dictionary with the obtained Euclidean distance of the face, obtain the minimum distance from the dictionary, and determine whether the distance is less than a threshold value obtained based on practice. If so, return the corresponding name in the data dictionary, otherwise it is considered as a recognition failure.
[0026] Compared with the prior art, the present invention has the following beneficial effects: a face recognition method integrating Euclidean distance and homomorphic encryption is proposed. The method uses CKKS homomorphic encryption technology to encrypt facial features, which can realize the calculation, storage and transmission of data under encryption conditions, and can not only realize face recognition, but also ensure that data is not leaked; the method improves the traditional Euclidean distance calculation method in the ciphertext domain, and realizes encrypted lightweight calculation in the ciphertext domain. Calculations with higher complexity and longer time are calculated in the plaintext domain while ensuring security. This not only ensures the accuracy and security of face recognition, but also greatly improves the calculation efficiency, and ensures the efficiency and practicality of actual application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a schematic diagram of the method implementation principle of the embodiment of the present invention.
[0028] Figure 2 It is a flow chart of the method implementation of the embodiment of the present invention. DETAILED DESCRIPTION
[0029] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0030] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0031] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0032] like Figure 1, 2 As shown, this embodiment provides a face recognition method integrating Euclidean distance and homomorphic encryption, comprising the following steps:
[0033] Step S1: Obtain and send the encrypted local facial feature value
[0034] 1. Get facial feature values
[0035] Step 1: Processing of camera images
[0036] Get each frame through the camera
[0037] ret,frame=video_capture.read()
[0038] Resize video frames to 1 / 4 size for faster face recognition processing
[0039] small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
[0040] Convert image from BGR color (used by OpenCV) to RGB color (used by face_recognition)
[0041] rgb_small_frame=small_frame[:,:,::-1]
[0042] Step 2: Face detection: Find all faces in the picture
[0043] Using the Face Recognition library in python:
[0044] The Face Recognition library mainly encapsulates the C++ dlib graphics library and encapsulates it into an API library that can implement face recognition through the Python language.
[0045] The API interface used is:
[0046] face_recognition.face_locations(img,number_of_times_to_upsample=1,model="hog")
[0047] All the faces can be found.
[0048] Step 3: Use feature points to correct posture and turn the side face into the front face
[0049] Detect facial feature points: The API interface used is:
[0050] face_landmarks(face_image,face_locations=None,model="large")
[0051] Facial features include the following parts: chin, left_eyebrow, right_eyebrow, nose_bridge, left_eye, right_eye, nose_tip, bottom_lip. In this way, 68 feature points of the face are obtained.
[0052] Step 4: Get facial feature values
[0053] Calculate the eigenvalue (eigenvector) of this face based on the facial feature points
[0054] The API interface used is:
[0055] face_encodings(face_image, known_face_locations=None, num_jitters=1)
[0056] Through this API, you can obtain a 128-dimensional feature vector of the face from the face in the picture.
[0057] 2. Perform local encryption of feature values
[0058] Step 1: Local key registration
[0059] MicrosoftSEAL is a homomorphic encryption library implemented in C++ and provides BFV and CKKS algorithms, so that customers do not need to share keys with services. In actual use, the CKKS algorithm is more suitable for application scenarios such as requiring real values, evaluating machine learning models of ciphertext data, and calculating ciphertext distances.
[0060] Use the CKKS encryption scheme in homomorphic encryption and select {60,40,40,60} as the poly_modulus_degree parameter of the CKKS encryption scheme. Encapsulate the key registration function into a registration() function for easier subsequent calls.
[0061] And use the encapsulation functions parms.save(file_path) and key.save(key_path) to save parameters, private keys, public keys and other keys locally.
[0062] Step 2: Eigenvalue encryption
[0063] Use the local public key public_key, context, and the encapsulated encrypt(data,context,public_key_path) function (scale is set to pow(2.0,40)) to homomorphically encrypt the previously obtained facial feature values into ciphertext feature values.
[0064] 3. Transmission of ciphertext and key
[0065] Use socket TCP to send the encrypted facial feature values, public keys, and parameters to the cloud server for processing.
[0066] Step S2: Cloud-based ciphertext calculation
[0067] 1. Load the key in the cloud
[0068] Step 1: Get parms
[0069] Also use the SEAL library to obtain the parms of local transmission to build a parameter container: EncryptionParametersparms(scheme_type::ckks);
[0070] Step 2: Generate CKKS framework
[0071] Generate CKKS frame with parameter parms: contextSEALContext context(parms);
[0072] Step 3: Get the public key public_key
[0073] Obtain the public key through local transmission.
[0074] Step 4: Building Modules
[0075] Build the encoder, encryption module, operator and decryption module:
[0076] Encryptor encryptor(context,public_key);
[0077] Evaluator evaluator(context);
[0078] Decryptor decryptor(context, secret_key);
[0079] CKKSEncoder encoder(context).
[0080] 2. Loading ciphertext in the cloud
[0081] Step 1: Read the face ciphertext
[0082] Read the face ciphertext with known name uploaded when the face user registers, and the real-time face ciphertext currently sent locally.
[0083] 3. Cloud-based ciphertext computing
[0084] Step 1: Calculate the difference between ciphertexts
[0085] Use the encapsulated ciphertext subtraction function sub_ciphertext(Ciphertext cip1, Ciphertext cip2, SEALContext context) to subtract the current face ciphertext from the ciphertext in the database.
[0086] At this time, the difference calculation will be performed in parallel in the cloud server to improve the efficiency of ciphertext calculation.
[0087] The Euclidean distance formula for facial feature value calculation is as follows:
[0088]
[0089] Through the ciphertext subtraction function, we can obtain the Euclidean distance (x i -y i )
[0090] The difference is calculated by using the security of the ciphertext. At this time, the difference is irreversible to obtain the original facial feature value, ensuring the absolute security of the information. Other steps involving multiplication calculations in the Euclid formula can be calculated in local plaintext later, ensuring both data security and the efficiency of ciphertext calculation.
[0091] Step 2: Transmit the difference ciphertext
[0092] The multiple groups of ciphertext difference vectors calculated previously are sent back to the local for subsequent calculation.
[0093] Step S3: Local ciphertext decryption and return result
[0094] Step 1: Decryption of ciphertext
[0095] Use the private key secret_key to call the decrypt(cipher,context,secret_key_path) function to decrypt the difference ciphertext and obtain the difference plaintext 128-dimensional vector.
[0096] Step 2: Calculate the local Euclidean distance of plaintext
[0097] At this point we have obtained the Euclid formula:
[0098] (x i -y i )
[0099] Next, square the 128-dimensional difference vector in the plaintext domain to obtain:
[0100] (x i -y i ) 2
[0101] The time consumed by this step in the plaintext domain is much shorter than the time consumed in the ciphertext domain.
[0102] Then sum the 128-dimensional square vectors to obtain:
[0103]
[0104] In this step, since the sum of squares is calculated, the vectors of each dimension of the ciphertext in the previous server do not have to follow the relative order of the previously obtained facial feature values.
[0105] Finally, perform square root calculation to obtain the final face Euclidean distance:
[0106]
[0107] Step 3: Obtain identity
[0108] The dictionary is updated with the obtained Euclidean distance of the face, and the minimum distance is obtained from the dictionary to determine whether the distance is less than the threshold value obtained based on practice. If it is less than, the corresponding name in the data dictionary is returned, otherwise it is considered as a failure.
[0109] The above is only a preferred embodiment of the present invention, and does not limit the present invention in other forms. Any technician familiar with the profession may use the above disclosed technical content to change or modify it into an equivalent embodiment with equivalent changes. However, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the technical solution of the present invention still belongs to the protection scope of the technical solution of the present invention.
Claims
1. A face recognition method integrating Euclidean distance and homomorphic encryption, characterized in that: The following steps are involved: Step S1: When the user performs identity recognition, the facial feature value is obtained locally, and then the facial feature value is encrypted based on homomorphic encryption to obtain the facial feature value ciphertext, and then the facial feature value ciphertext and key are sent to the cloud server; Step S2: The cloud server loads the key and the facial feature value ciphertext, and performs Euclidean distance calculation between the facial feature value ciphertext currently uploaded locally and the facial feature value ciphertext of the known name uploaded by the user when registering, to obtain the ciphertext difference; The calculated ciphertext difference is then sent back to the local computer for subsequent calculation; Step S3: decrypt the ciphertext difference locally, and then calculate the local Euclidean distance of the plaintext to obtain the Euclidean distance of the face, and finally give the user identity recognition result based on the obtained Euclidean distance of the face; In step S1, the facial feature value is obtained as follows: Step S101: locally obtaining an image of a video frame through a camera, adjusting the size of the image to speed up face recognition processing, and then converting the image from BGR color to RGB color; Step S102: Perform face detection to find all faces in the image; Step S103: Correcting the posture using facial feature points to turn the side face into the front face; Step S104: Calculating facial feature values according to facial feature points; In step S1, a CKKS encryption scheme in homomorphic encryption is used to generate a key, and the key parameters, private key, and public key are saved locally; then the facial feature value is homomorphically encrypted using the local public key to obtain a ciphertext of the facial feature value, and then the ciphertext of the facial feature value and the public key and parameters of the key are sent to the cloud server; In step S2, the encapsulated ciphertext subtraction function is used to perform a subtraction calculation on the ciphertext of the facial feature value currently uploaded locally and the ciphertext of the facial feature value of the known name uploaded by the user during registration stored in the database; the Euclidean distance formula for facial feature value calculation and judgment is as follows: Through the ciphertext subtraction function, we can obtain the Euclidean distance (x i -y i ); Then, the calculated ciphertext difference is sent back to the local for subsequent calculation; The step S3 specifically comprises the following steps: Step S301: Locally decrypt the ciphertext difference using the private key of the key to obtain a multi-dimensional difference vector; Step S302: According to the obtained Euclidean formula (x i -y i ), square the multidimensional difference vector in the plaintext domain to obtain a multidimensional square vector (x i -y i ) 2 ; Step S303: Sum the multi-dimensional square vector to obtain Step S304: Perform square root calculation to obtain the face Euclidean distance: Step S305: Update the dictionary with the obtained Euclidean distance of the face, obtain the minimum distance from the dictionary, and determine whether the distance is less than a threshold value obtained based on practice. If so, return the corresponding name in the data dictionary, otherwise it is considered as a recognition failure.
