WO2020211347A1 - Facial recognition-based image modification method and apparatus, and computer device - Google Patents

Facial recognition-based image modification method and apparatus, and computer device Download PDF

Info

Publication number
WO2020211347A1
WO2020211347A1 PCT/CN2019/117660 CN2019117660W WO2020211347A1 WO 2020211347 A1 WO2020211347 A1 WO 2020211347A1 CN 2019117660 W CN2019117660 W CN 2019117660W WO 2020211347 A1 WO2020211347 A1 WO 2020211347A1
Authority
WO
WIPO (PCT)
Prior art keywords
face
model
face image
picture
matrix
Prior art date
Application number
PCT/CN2019/117660
Other languages
French (fr)
Chinese (zh)
Inventor
李影
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020211347A1 publication Critical patent/WO2020211347A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/80Geometric correction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V40/00Recognition of biometric, human-related or animal-related patterns in image or video data
    • G06V40/10Human or animal bodies, e.g. vehicle occupants or pedestrians; Body parts, e.g. hands
    • G06V40/16Human faces, e.g. facial parts, sketches or expressions
    • G06V40/168Feature extraction; Face representation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V40/00Recognition of biometric, human-related or animal-related patterns in image or video data
    • G06V40/10Human or animal bodies, e.g. vehicle occupants or pedestrians; Body parts, e.g. hands
    • G06V40/16Human faces, e.g. facial parts, sketches or expressions
    • G06V40/174Facial expression recognition
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10016Video; Image sequence
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/30Subject of image; Context of image processing
    • G06T2207/30196Human being; Person
    • G06T2207/30201Face

Definitions

  • This application relates to the field of artificial intelligence technology, in particular to a method, device and computer equipment for modifying pictures based on face recognition.
  • the image processing software can automatically recognize the face of the person in the picture to be processed, and then replace other faces that the user needs to replace with the face on the picture to be processed.
  • the face of the person in the picture is sideways, the other face information that the user needs to replace is all upright, resulting in inconsistent angles between the face and the body in the processed picture.
  • the main purpose of this application is to provide a method, device and computer equipment for modifying a picture based on face recognition that can modify the picture according to the deflection angle of the face in the picture.
  • this application proposes a method for modifying pictures based on face recognition, including:
  • This application also provides a device for modifying pictures based on face recognition, including:
  • the extraction module is configured to extract the face image in the video after receiving the instruction to modify the picture sent by the user, and the instruction includes the object to be loaded on the face image;
  • a projection module configured to project the 3D model according to the deflection angle to obtain a replacement picture
  • the loading module is used to load the replacement picture on the face image.
  • the present application also provides a computer device, including a memory and a processor, the memory stores a computer program, and the processor implements the steps of any one of the foregoing methods when the computer program is executed.
  • the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the above methods are implemented.
  • the method, device and computer equipment for modifying pictures based on face recognition of the present application when replacing a face picture, according to the deflection angle of the face in the picture or video, the angle of the pre-replaced face is also replaced with The deflection angle of the face in the video is the same, which makes the replaced picture more realistic.
  • FIG. 1 is a schematic flowchart of a method for modifying a picture based on face recognition according to an embodiment of the application
  • FIG. 2 is a schematic block diagram of the structure of an apparatus for modifying pictures based on face recognition according to an embodiment of the application;
  • FIG. 3 is a schematic block diagram of the structure of a computer device according to an embodiment of the application.
  • an embodiment of the present application provides a method for modifying a picture based on face recognition, including the steps:
  • the execution body of this embodiment is applied to an image processing APP on a mobile phone, and the execution body is the processor of the mobile phone.
  • the processor receives the modified picture sent by the user, reads the video file, scans the video file to form an image, or directly extracts the frame pictures in the video, and then extracts the face in the video Image, extract the face image in the video in real time according to the video playback.
  • the above-mentioned video files include video files that are included in the mobile phone, video files played in the browser, dynamic pictures, and video files generated by online video chats.
  • the step for the user to issue an instruction to modify the picture is to receive the instruction to modify the picture from the user on the APP interface, and load multiple objects in the database to be loaded on the face image on the interface for the user to select, and to receive the user’s choice
  • There are multiple objects stored in the database and each object is displayed in the form of an image or text or a combination of the two, so that the user can quickly understand the specific information of the object and select the object the user wants. For example, there are ten objects in the database, and each object is the face of an entertainment star.
  • the APP interface When the APP interface receives the user's instruction to modify the picture, it loads these ten objects on the interface at the same time, allowing the user to select one of the face images as the object loaded on the above face image; then the APP packs the object Enter the instruction to form an instruction issued by the user to modify the picture.
  • the processor extracts the face image in the video, it calculates the deflection angle of the face according to the face feature points.
  • the processor extracts the face image in the video, it can determine the deflection angle of the face image by using the facial features information.
  • the deflection angle is the deflection angle set for the face image relative to the preset reference position. If the preset reference position is the face image when the user is looking straight ahead, when the face in the video turns left or right or tilts up or When looking down, the deflection angle is relative to the rotation angle of head-up view.
  • the preset reference position is the face image when the user is looking straight ahead, when the face in the video turns left or right or tilts up or When looking down, the deflection angle is relative to the rotation angle of head-up view.
  • the relative position of the facial features and the size of some symmetrical facial features can be used to calculate the deflection angle of the face image.
  • the two eyes in the face picture are identified, and the width dimensions of the two eyes are calculated respectively, and then the ratio of the width dimensions of the two eyes is calculated. Calculate the deflection angle. For example, in a captured image, the width of the left eye of a person is 3000, and the width of the right eye is 4000.
  • y represents the deflection angle of deflection to the left
  • x represents the ratio of the width of the left eye to the width of the right eye 3/4.
  • the final calculated y is an angle between negative 90 degrees and positive 90 degrees, that is, the deflection angle of leftward deflection. If the obtained value is negative, it means the absolute value of the rightward deflection angle.
  • a 3D model refers to a three-dimensional image corresponding to an object stored in the user's face, animal avatar, glasses and hat waiting to be loaded on the face image.
  • the three-dimensional image is formed by the user by taking a 360-degree photograph of an object or person in advance
  • Three-dimensional images can also be downloaded from the Internet.
  • step S3 after the processor calls the 3D model, it obtains the calculated deflection angle, and then projects the 3D model from the deflection angle to obtain a two-dimensional picture of the 3D model projected at the deflection angle. That is, the above replacement picture.
  • step S4 the processor then loads the replacement picture on the face image in the video, so that the replacement picture is overlaid on the face image, which achieves the purpose of replacing the face in the video.
  • the calculation of the deflection angle of the face image is also calculated in real time after receiving the user's instruction, and the corresponding loaded replacement image is also loaded in real time.
  • the aforementioned 3D model is a human face 3D model
  • the aforementioned step of projecting the 3D model according to the deflection angle to obtain a replacement picture includes:
  • the 3D model refers to a 3D model of a human face.
  • the processor After the processor extracts the face image in the video, it preprocesses the face image.
  • the preprocessing is the processing before the feature extraction, segmentation and matching of the image.
  • the main purpose of image preprocessing is to eliminate irrelevant images in the image. Information, restore useful real information, enhance the detectability of relevant information and simplify data to the greatest extent, thereby improving the reliability of feature extraction, image segmentation, matching and recognition.
  • the preprocessed face image is input to the trained training model for expression recognition, and the expression recognition result of the face image sequence is obtained; wherein, the input end to the output end of the training model are sequentially performed by the convolutional neural network
  • the model, the long and short-term memory cyclic neural network model, the first pooling layer and the logistic regression model are constructed, and the training model is obtained by training a collection of continuous frame images with annotated expression categories.
  • the processor controls the 3D face model to simulate an expression consistent with the expression of the aforementioned face image, and the method of simulating the corresponding expression is: first obtain the first feature point of the aforementioned face 3D model , And then multiply the first feature point by the adjustment matrix corresponding to the above expression to obtain the second feature point with the expression, and then map the second feature point on the above-mentioned face 3D model, then the person with the above expression is obtained 3D model of face.
  • Each expression corresponds to an adjustment matrix, and the characteristic matrix corresponding to each expression is obtained by the staff after a lot of calculation and debugging.
  • the processor first divides the various parts of the face 3D model into regions, such as face region, nose region, mouth region, eyebrow region, etc., and can continue to subdivide each region into multiple sub-regions. Area, and then adjust the type according to the expression type and the preset area. After obtaining the expression, obtain the area or sub-area corresponding to the expression, then obtain the feature points of the area or sub-area corresponding to the expression, and then multiply the feature points by the expression
  • the corresponding region adjustment matrix is used to obtain feature points with expressions, and then the feature points with expressions are mapped to corresponding regions or sub-regions to obtain a 3D face model with the above expressions.
  • the deflection angle of the aforementioned image is the y value calculated in the formula, and the replacement picture with the aforementioned expression of the 3D face model is obtained by projection.
  • the adjustment area corresponding to the smile expression type is the mouth area and the adjustment matrix corresponding to the mouth area, and then the above 3D model The mouth area in is multiplied by the above adjustment matrix to obtain a 3D face model with a smiling expression.
  • the 3D face model with the smile expression is rotated at the above deflection angle, and then project the rotated 3D face model with the smile expression from the direction facing the original 3D face model on the initial
  • a replacement picture with a smiling expression is finally obtained.
  • the 3D face model with the above expression is centered on the axis of symmetry of the 3D face model, and the angle of the y value calculated above is rotated, and then a camera is simulated, from the initial 3D face model (not rotated) Take a picture of the opposite place, and the resulting picture is the above replacement picture.
  • the aforementioned 3D model is a human face 3D model
  • the aforementioned step of projecting the 3D model according to the deflection angle to obtain a replacement picture includes:
  • S311 Control each organ of the human face 3D model to simulate the facial action
  • the extracted face image in the video is preprocessed and input into a trained organ recognition model.
  • the organ recognition model segments the aforementioned face image and recognizes each of the face images.
  • Organs The image area containing the various organs in the above face image is defined as the first organ.
  • the first organ includes multiple organs that can move on the face. Specifically, the first organ includes eyes, mouth, nose, eyebrows, and cheeks. muscle.
  • Each first organ is compared with the preset second organ state under the normal state one by one, and the action of each organ is determined according to the comparison result.
  • the specific process of judging the actions of the organs is to perform image analysis on the first organ and the corresponding second organ, and establish a matrix with the same number of rows and columns for the first organ and the second organ according to the pigment difference, and then subtract the matrix of the first organ.
  • the matrix of the second organ is removed to obtain the matrix difference, and then the rank of the matrix difference is calculated.
  • the facial movement of the organ is determined from the correspondence between the rank of the organ and the facial movement.
  • the result of the rank is less than a certain value, it is determined that the organ is in a normal state, and the corresponding organ in the aforementioned 3D face model does not need to simulate other facial movements.
  • the various organs of the human face 3D model are identified, and it is confirmed that the first organ has an abnormal facial movement in the above-mentioned organ.
  • a two-dimensional picture of the 3D face model with the same facial action is obtained by projection, and then the two-dimensional picture is loaded at the position of the face image in the video.
  • the steps of projecting the 3D face model with facial action to obtain the replacement picture are the same as the method of S35.
  • the above-mentioned organ recognition model is based on a deep neural network model training.
  • the staff first collects a number of pictures containing the face of a person, and annotates each organ on the face of each person in the picture, and then the picture And each annotation is input into the deep neural network model for training, and the organ recognition model is obtained.
  • the above step of loading the replacement picture on the face image includes:
  • S41 Acquire the size of the display screen in the attribute information of the terminal and the proportion of the face image in the display screen in the playback interface;
  • the processor calculates the size of the aforementioned face image according to the video information. Specifically, it obtains the attribute information of the mobile phone where the APP is located, and obtains the size of the display screen. Proportion, which simulates loading a face image on the playback interface, and then calculates the size of the face image in the playback interface. Then compare the size with the preset standard size to get the ratio between the two.
  • the standard size is set manually. The setting process is to place a standard face at a specified distance from the specified camera and then collect the size of the face.
  • the 3D model corresponding to the object in the database is also specified according to the specified camera. Captured after the distance.
  • the step of extracting the face image in the video after receiving the instruction to modify the picture from the user includes:
  • the processor After the processor receives the replacement or addition instruction issued by the user, it obtains the video played in the specified APP, then reads the detailed information of the video, intercepts the frame picture played at the current moment of the video, and then the frame The picture is input into the preset face recognition model, and the recognition is performed according to the face recognition model, and the face image is obtained by outputting.
  • the method before the step of inputting the frame picture into the preset face recognition model and outputting the face image, the method includes:
  • S101 Input a plurality of pictures containing human face images in a training set into a preset neural network model for training, and obtain a neural network model for recognizing human faces in the pictures as the face recognition model.
  • the staff selects a number of pictures containing human face images in advance to form a training set, and then inputs these pictures into a preset neural network model for training.
  • the neural network model is automatically based on the gray in the face image.
  • the trajectory formed by the degree is calculated and optimized to obtain the feature coefficients of the face picture, even if the neural network model can be used to identify whether there is a face image in the picture.
  • the frame picture is processed to obtain the grayscale of the picture, and then the grayscale trajectory is calculated whether the feature coefficient obtained by the above training is included, and if it is, the human face image in the video is judged. According to the gray trajectory corresponding to the feature coefficient, the face image is extracted.
  • the above step of loading the replacement picture on the face image it includes:
  • the object is stored in the database, and the corresponding information of each object is also stored in the database.
  • the attributes of each object include whether it is face information. If it is face information, the replacement picture corresponds to the person’s face information. The face information is in an irregular shape, and the replacement pictures formed rarely cover the above On the face image, therefore, it is necessary to delete the face image in the video to make the overall replacement video information more coordinated.
  • the processor reads the attribute information of the object, and judges whether the attribute information is face information. If it is face information, delete the face image.
  • the attribute information of the object includes two types of facial information and accessory information, where the facial information includes human faces, dog faces, and cat faces, and the accessory information includes glasses, earrings, and hats. If it is determined that the object is not facial information, only the replacement picture is loaded on the face image to form the effect of wearing accessories to the characters in the video, which gives the user a better experience.
  • the method for modifying a picture based on face recognition of the present application when replacing a face picture, according to the deflection angle of the face in the picture or video, the angle of the pre-replaced face is also replaced with The deflection angle of the face in the video is the same, which makes the replaced picture more realistic.
  • an embodiment of the present application also provides an apparatus for modifying pictures based on face recognition, including:
  • the extraction module 1 is configured to extract a face image in a video after receiving an instruction to modify a picture issued by a user, and the instruction includes an object to be loaded on the face image;
  • the projection module 3 is used to project the 3D model according to the deflection angle to obtain a replacement picture
  • the loading module 4 is used to load the replacement picture on the face image.
  • an embodiment of the present application also provides a computer device.
  • the computer device may be a server, and its internal structure may be as shown in FIG. 3.
  • the computer equipment includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the computer designed processor is used to provide calculation and control capabilities.
  • the memory of the computer device includes a storage medium and an internal memory.
  • the storage medium may be a non-volatile storage medium or a volatile storage medium, and the storage medium stores an operating system, a computer program, and a database.
  • the memory provides an environment for the operation of the operating system and computer programs in the storage medium.
  • the database of the computer equipment is used to store data such as 3D models.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the computer program is executed by the processor to realize a method of modifying pictures based on face recognition.
  • FIG. 3 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied.
  • An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored.
  • a computer program is stored on which a computer program is stored.
  • the computer program is executed by a processor, a method for modifying a picture based on face recognition is implemented.
  • the computer program can be stored in a computer readable storage medium.
  • the computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium.
  • the computer program When executed, it may include the processes of the above-mentioned method embodiments.
  • any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and/or volatile memory.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Oral & Maxillofacial Surgery (AREA)
  • Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Theoretical Computer Science (AREA)
  • General Health & Medical Sciences (AREA)
  • Human Computer Interaction (AREA)
  • Multimedia (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Processing Or Creating Images (AREA)
  • Image Processing (AREA)
  • Image Analysis (AREA)

Abstract

Disclosed in the present application are a facial recognition-based image modification method and apparatus, and a computer device. The method comprises: extracting a face image in a video after receiving an image modification instruction sent by a user, wherein the instruction comprises an object to be loaded on the face image; calculating a deflection angle of the face image, and calling a 3D model corresponding to the object in a database; projecting the 3D model according to the deflection angle to obtain a replacement image; and loading the replacement image on the face image. In the present application, during replacement of a face image, according to the deflection angle of the face in the image or the video, the angle of a pre-replacement face is also replaced with the same deflection angle as the face in the video, so that the image obtained after replacement is more realistic.

Description

基于人脸识别的修改图片的方法、装置和计算机设备Method, device and computer equipment for modifying pictures based on face recognition
本申请要求于2019年4月16日提交中国专利局、申请号为201910305175.6,发明名称为“基于人脸识别的修改图片的方法、装置和计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on April 16, 2019, the application number is 201910305175.6, and the invention title is "Method, Apparatus, and Computer Equipment for Modifying Images Based on Face Recognition", and its entire contents Incorporated in this application by reference.
技术领域Technical field
本申请涉及到人工智能技术领域,特别是涉及到一种基于人脸识别的修改图片的方法、装置和计算机设备。This application relates to the field of artificial intelligence technology, in particular to a method, device and computer equipment for modifying pictures based on face recognition.
背景技术Background technique
目前市场上有很多图像处理软件,图像处理软件可以自动识别出待图片中人的脸部,然后将用户需要替换的其他脸部替换到待处理的图片上的脸部。但是当图片中的人的脸部是侧着的时候,用户需要替换的其他脸部信息都是正着的,导致处理后的图片中脸部与身体的角度不协调。At present, there are many image processing software on the market. The image processing software can automatically recognize the face of the person in the picture to be processed, and then replace other faces that the user needs to replace with the face on the picture to be processed. However, when the face of the person in the picture is sideways, the other face information that the user needs to replace is all upright, resulting in inconsistent angles between the face and the body in the processed picture.
技术问题technical problem
本申请的主要目的为提供一种可以根据图片中的人脸偏转角度来进行修改图片的基于人脸识别的修改图片的方法、装置和计算机设备。The main purpose of this application is to provide a method, device and computer equipment for modifying a picture based on face recognition that can modify the picture according to the deflection angle of the face in the picture.
技术解决方案Technical solutions
为了实现上述发明目的,本申请提出一种基于人脸识别的修改图片的方法,包括:In order to achieve the above-mentioned object of the invention, this application proposes a method for modifying pictures based on face recognition, including:
接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;After receiving the instruction to modify the picture issued by the user, extract the face image in the video, and the instruction includes the object to be loaded on the face image;
根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; According to the formula: y=18.75x 2 -135x+116.25, calculate the deflection angle of the face image, and call the 3D model corresponding to the object in the database, where y represents the deflection angle to the left, and x represents the face The ratio of the size of the left organ in the image to the size of the corresponding right organ;
将所述3D模型按照所述偏转角度进行投影,得到替换图片;Project the 3D model according to the deflection angle to obtain a replacement picture;
将所述替换图片加载在所述人脸图像上。Loading the replacement picture on the face image.
本申请还提供一种基于人脸识别的修改图片的装置,包括:This application also provides a device for modifying pictures based on face recognition, including:
提取模块,用于接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;The extraction module is configured to extract the face image in the video after receiving the instruction to modify the picture sent by the user, and the instruction includes the object to be loaded on the face image;
计算角度模块,用于根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; The calculation angle module is used to calculate the deflection angle of the face image according to the formula: y=18.75x 2 -135x+116.25, and call the 3D model corresponding to the object in the database, where y represents the deflection to the left Angle, x represents the ratio of the left organ size to the corresponding right organ size in the face image;
投影模块,用于将所述3D模型按照所述偏转角度进行投影,得到替换图片;A projection module, configured to project the 3D model according to the deflection angle to obtain a replacement picture;
加载模块,用于将所述替换图片加载在所述人脸图像上。The loading module is used to load the replacement picture on the face image.
本申请还提供一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述任一项所述方法的步骤。The present application also provides a computer device, including a memory and a processor, the memory stores a computer program, and the processor implements the steps of any one of the foregoing methods when the computer program is executed.
本申请还提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述任一项所述的方法的步骤。The present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the above methods are implemented.
有益效果Beneficial effect
本申请的基于人脸识别的修改图片的方法、装置和计算机设备,在替换人脸图片时,根据图片或视频中的人脸的偏转角度后,将预替换的脸部的角度也替换成与视频中的人脸的偏转角度相同,使替换出来的画面更加真实。The method, device and computer equipment for modifying pictures based on face recognition of the present application, when replacing a face picture, according to the deflection angle of the face in the picture or video, the angle of the pre-replaced face is also replaced with The deflection angle of the face in the video is the same, which makes the replaced picture more realistic.
附图说明Description of the drawings
图1为本申请一实施例的基于人脸识别的修改图片的方法的流程示意图;FIG. 1 is a schematic flowchart of a method for modifying a picture based on face recognition according to an embodiment of the application;
图2为本申请一实施例的基于人脸识别的修改图片的装置的结构示意框图;2 is a schematic block diagram of the structure of an apparatus for modifying pictures based on face recognition according to an embodiment of the application;
图3为本申请一实施例的计算机设备的结构示意框图。FIG. 3 is a schematic block diagram of the structure of a computer device according to an embodiment of the application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。 本发明的最佳实施方式 The realization, functional characteristics, and advantages of the purpose of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. The best mode of the invention
参照图1,本申请实施例提供一种基于人脸识别的修改图片的方法,包括步骤:1, an embodiment of the present application provides a method for modifying a picture based on face recognition, including the steps:
S1、接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;S1. After receiving an instruction to modify a picture from a user, extract a face image in the video, where the instruction includes an object to be loaded on the face image;
S2、根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; S2. According to the formula: y=18.75x 2 -135x+116.25, calculate the deflection angle of the face image, and call the 3D model corresponding to the object in the database, where y represents the deflection angle to the left, and x represents The ratio of the left organ size to the corresponding right organ size in the face image;
S3、将所述3D模型按照所述偏转角度进行投影,得到替换图片;S3. Project the 3D model according to the deflection angle to obtain a replacement picture;
S4、将所述替换图片加载在所述人脸图像上。S4. Load the replacement picture on the face image.
如上述步骤S1所述,本实施例的执行主体应用于一款手机上的图像处理APP,执行主体是该手机的处理器。当该APP加载了视频文件后,处理器接收到用户发出的修改图片后,读取该视频文件,扫描该视频文件以形成图像,或者直接提取视频中的帧图片,然后提取视频中的人脸图像,根据视频的播放实时提取视频中的人脸图像。上述视频文件包括手机中自带的视频文件、浏览器中播放的视频文件、动态图、在线视频聊天产生的视频文件等。用户发出修改图片的指令的步骤为,在APP界面接收到用户发出的修改图片的指令,将数据库中的多个要加载在人脸图像上的对象加载在界面上以供用户选择,接收用户选择的对象后,生成修改图片的指令。数据库中存储有多个对象,每一个对象均是以图像或文字或两者结合的形式展示出来,以供用户快速了解对象的具体信息,以选择出用户想要的对象。例如,数据库中有十个对象,每一个对象分别是一个娱乐明星的人脸头像。当APP界面接收到用户发出的修改图片的指令后,将这十个对象同时加载在界面上,供用户选择其中一个人脸图像作为加载在上述人脸图像上的对象;然后APP将该对象打包进指令中,以形成用户发出的修改图片的指令。As described in step S1 above, the execution body of this embodiment is applied to an image processing APP on a mobile phone, and the execution body is the processor of the mobile phone. When the APP loads the video file, the processor receives the modified picture sent by the user, reads the video file, scans the video file to form an image, or directly extracts the frame pictures in the video, and then extracts the face in the video Image, extract the face image in the video in real time according to the video playback. The above-mentioned video files include video files that are included in the mobile phone, video files played in the browser, dynamic pictures, and video files generated by online video chats. The step for the user to issue an instruction to modify the picture is to receive the instruction to modify the picture from the user on the APP interface, and load multiple objects in the database to be loaded on the face image on the interface for the user to select, and to receive the user’s choice After the object, generate instructions to modify the picture. There are multiple objects stored in the database, and each object is displayed in the form of an image or text or a combination of the two, so that the user can quickly understand the specific information of the object and select the object the user wants. For example, there are ten objects in the database, and each object is the face of an entertainment star. When the APP interface receives the user's instruction to modify the picture, it loads these ten objects on the interface at the same time, allowing the user to select one of the face images as the object loaded on the above face image; then the APP packs the object Enter the instruction to form an instruction issued by the user to modify the picture.
如上述步骤S2所述,处理器提取出了视频中的人脸图像后,根据人脸特征点计算脸部的偏转角度。处理器提取出了视频中的人脸图像后,利用五官信息可以判断出人脸图像的偏转角度。该偏转角度为人脸图像相对预设参考位置设置的偏转角度,如预设参考位置为用户平视正前方时的人脸图像,则当视频中的人脸向左转或向右转或向上仰或向下看时,其偏转角度为相对于平视时的转动角度,由于人脸图像进行不同程度的偏转时,所采集到的五官具有不同的相对位置,而且一些对称的五官的大小会发生变化,例如人向左边偏转,则左边的耳朵离摄像头远一些,对应的在视频中的左边耳朵相对右边耳朵小一些。因此利用五官的相对位置以及一些对称的五官的大小,可以计算出人脸图像的偏转角度。在一具体实施例中,提取出了视频中的人脸图片后,识别出人脸图片中的两个眼睛,并分别计算两只眼睛的宽度尺寸,然后根据两个眼睛的宽度尺寸的比例来计算偏转角度。如,在一个采集的图像中,人的左眼宽度是3000,右眼宽度是4000,上述宽度单位是在图像中的切割后得出最小尺寸单位。然后计算左眼与右眼的比例是3:4,即左眼宽度是右眼宽度的3/4,然后输出到预设的公式y=f(x)中,计算出向左偏转的偏转角度,上述公式中,y表示向左偏转的偏转角度,x表示左眼宽度与右眼宽度的比例3/4。最终计算得到的y是一个负90度到正90度之间的角度,即向左偏转的偏转角度,如果得出的是负值,表示是向右偏转的角度的绝对值。在一个固定的像素中经过一基础的测试,具体的公式是:y=18.75x 2-135x+116.25。 As described in step S2 above, after the processor extracts the face image in the video, it calculates the deflection angle of the face according to the face feature points. After the processor extracts the face image in the video, it can determine the deflection angle of the face image by using the facial features information. The deflection angle is the deflection angle set for the face image relative to the preset reference position. If the preset reference position is the face image when the user is looking straight ahead, when the face in the video turns left or right or tilts up or When looking down, the deflection angle is relative to the rotation angle of head-up view. When the face image is deflected to different degrees, the collected facial features have different relative positions, and the size of some symmetric facial features will change. For example, if a person deflects to the left, the left ear is farther away from the camera, and the corresponding left ear in the video is smaller than the right ear. Therefore, the relative position of the facial features and the size of some symmetrical facial features can be used to calculate the deflection angle of the face image. In a specific embodiment, after extracting the face picture in the video, the two eyes in the face picture are identified, and the width dimensions of the two eyes are calculated respectively, and then the ratio of the width dimensions of the two eyes is calculated. Calculate the deflection angle. For example, in a captured image, the width of the left eye of a person is 3000, and the width of the right eye is 4000. The above-mentioned width unit is the smallest size unit obtained after cutting the image. Then calculate the ratio of the left eye to the right eye to be 3:4, that is, the width of the left eye is 3/4 of the width of the right eye, and then output to the preset formula y=f(x) to calculate the deflection angle to the left, In the above formula, y represents the deflection angle of deflection to the left, and x represents the ratio of the width of the left eye to the width of the right eye 3/4. The final calculated y is an angle between negative 90 degrees and positive 90 degrees, that is, the deflection angle of leftward deflection. If the obtained value is negative, it means the absolute value of the rightward deflection angle. After a basic test in a fixed pixel, the specific formula is: y=18.75x 2 -135x+116.25.
同时,用户发出修改图片的指令时,首先选择一个加载的对象用于加载在视频中的人脸图像上。其中,用户可以在手机上自带的数据库中选择一个待加载的对象。数据库中存储有多个对象,以及与各对象对应的3D模型。当用户在APP上需要对视频中的人脸图像进行替换或者增加图片时,在APP中的数据库中选择一个对象,处理器接收到用户发出的指令后,根据指令中的对象,调用出用户选择的对象对应的3D模型。3D模型是指用户预先存储的人脸、动物头像、眼镜帽子等待加载在人脸图像上的对象对应的三维立体图,其中三维立体图是用户通过事先对一个物体或人等进行360度拍照后形成的三维立体图,也可以是从网络上下载等得到。At the same time, when the user issues an instruction to modify the picture, first select a loaded object for loading on the face image in the video. Among them, the user can select an object to be loaded in the database that comes with the mobile phone. Multiple objects and 3D models corresponding to each object are stored in the database. When the user needs to replace the face image in the video or add a picture on the APP, select an object in the database in the APP. After the processor receives the instruction from the user, it calls the user selection according to the object in the instruction The 3D model corresponding to the object. A 3D model refers to a three-dimensional image corresponding to an object stored in the user's face, animal avatar, glasses and hat waiting to be loaded on the face image. The three-dimensional image is formed by the user by taking a 360-degree photograph of an object or person in advance Three-dimensional images can also be downloaded from the Internet.
如上述步骤S3所述,处理器调用出了3D模型后,再获取上述计算出的偏转角度,然后从偏转角度对3D模型进行投影,得到该3D模型的在偏转角度投影生成的二维图片,即上述替换图片。As described in step S3 above, after the processor calls the 3D model, it obtains the calculated deflection angle, and then projects the 3D model from the deflection angle to obtain a two-dimensional picture of the 3D model projected at the deflection angle. That is, the above replacement picture.
如上述步骤S4所述,处理器再将该替换图片加载在视频中的人脸图像上,使替换图片覆盖在人脸图像上,即实现了对视频中的人脸进行替换的目的。As described in step S4, the processor then loads the replacement picture on the face image in the video, so that the replacement picture is overlaid on the face image, which achieves the purpose of replacing the face in the video.
本实施例中,因视频是连续播放的,因此,接收到用户的指令后,计算人脸图像的偏转角度也是实时计算的,对应的加载的替换图像也是实时加载的。In this embodiment, because the video is played continuously, the calculation of the deflection angle of the face image is also calculated in real time after receiving the user's instruction, and the corresponding loaded replacement image is also loaded in real time.
在一个实施例中,上述3D模型为人脸3D模型,上述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:In one embodiment, the aforementioned 3D model is a human face 3D model, and the aforementioned step of projecting the 3D model according to the deflection angle to obtain a replacement picture includes:
S31、将所述人脸图像进行预处理后,输入到训练后的表情识别模型中识别,以获取所述人脸图像的表情;S31. After preprocessing the face image, it is input into a trained expression recognition model for recognition, so as to obtain the expression of the face image;
S32、获取所述人脸3D模型的第一特征点以及所述表情对应的调整矩阵,其中,表情以及调整矩阵的对应关系是预先设置的;S32. Acquire the first feature point of the human face 3D model and the adjustment matrix corresponding to the expression, wherein the correspondence between the expression and the adjustment matrix is preset;
S33、将所述第一特征点乘以所述调整矩阵,得到所述第二特征点;S33. Multiply the first feature point by the adjustment matrix to obtain the second feature point;
S34、将所述第二特征点映射在所述人脸3D模型上,控制所述人脸3D模型模拟出所述表情;S34. Map the second feature point on the 3D face model, and control the 3D face model to simulate the expression;
S35、将模拟出所述表情的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。S35. After rotating the face 3D model that simulates the expression by the degree of the deflection angle, map it to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
本实施例中,3D模型是指人脸3D模型。处理器提取了视频中的人脸图像后,将人脸图像进行预处理,预处理是将图像进行特征抽取、分割和匹配前所进行的处理,图像预处理的主要目的是消除图像中无关的信息,恢复有用的真实信息,增强有关信息的可检测性和最大限度地简化数据,从而改进特征抽取、图像分割、匹配和识别的可靠性。然后将预处理后的人脸图像输入已训练好的训练模型进行表情识别,得到所述人脸图像序列的表情识别结果;其中,所述训练模型的输入端到输出端依次由卷积神经网络模型、长短时记忆循环神经网络模型、第一池化层和逻辑回归模型构建,且所述训练模型通过标注表情类别的连续帧图像集合训练得到。获取得到人脸图像的表情后,处理器控制将人脸3D模型模拟出与上述人脸图像的表情一致的表情,模拟出对应表情的方法为:首先获取上述人脸3D模型的第一特征点,然后将该第一特征点乘以上述表情对应的调整矩阵,得到具有表情的第二特征点,然后将该第二特征点映射在上述人脸3D模型上,则得到了具有上述表情的人脸3D模型。每一个表情对应一个调整矩阵,各表情对应的特征矩阵是工作人员经过大量计算调试后得出的。在进一步的具体调整过程中,处理器首先将人脸3D模型的各个部位进行区域划分,比如分为脸区域、鼻子区域、嘴巴区域、眉毛区域等,还可以继续将各个区域细分为多个子区域,然后将根据表情类型与预设的区域调整类型,首先获取了表情后,获取表情对应的区域或子区域,然后获取表情对应的区域或子区域的特征点,再将特征点乘以表情对应的区域调整矩阵,得到带有表情的特征点,再将带有表情的特征点映射到对应的区域或子区域中,得到带有上述表情的人脸3D模型。实现人脸3D模型模拟出与上述人脸图像表情相同的表情。然后根据上述图像的偏转角度,偏转角度即公式中计算得到的y值,投影得到该3D人脸模型的带有上述表情的替换图片。如,当识别出表情是微笑的时候,则在表情类型与区域调整方式的对应关系中,找到微笑这一表情类型对应的调整区域是嘴巴区域以及嘴巴区域对应的调整矩阵,然后将上述3D模型中的嘴巴区域乘以上述调整矩阵,得到带有微笑表情的3D人脸模型。然后将上述带有微笑表情的3D人脸模型以上述偏转角度进行旋转,然后从初始的3D人脸模型的正对着的方向对旋转后的带有微笑表情的3D人脸模型进行投影在初始的3D人脸模型背后的平面上,最终得到带有微笑表情的替换图片。具体的,将带有上述表情的3D人脸模型以3D人脸模型的对称轴为中心,转动上述计算得到的y值的角度,然后模拟出一个照相机,从初始3D人脸模型(未转动)的正对处进行拍照,得到的图片即为上述替换图片。In this embodiment, the 3D model refers to a 3D model of a human face. After the processor extracts the face image in the video, it preprocesses the face image. The preprocessing is the processing before the feature extraction, segmentation and matching of the image. The main purpose of image preprocessing is to eliminate irrelevant images in the image. Information, restore useful real information, enhance the detectability of relevant information and simplify data to the greatest extent, thereby improving the reliability of feature extraction, image segmentation, matching and recognition. Then, the preprocessed face image is input to the trained training model for expression recognition, and the expression recognition result of the face image sequence is obtained; wherein, the input end to the output end of the training model are sequentially performed by the convolutional neural network The model, the long and short-term memory cyclic neural network model, the first pooling layer and the logistic regression model are constructed, and the training model is obtained by training a collection of continuous frame images with annotated expression categories. After obtaining the expression of the face image, the processor controls the 3D face model to simulate an expression consistent with the expression of the aforementioned face image, and the method of simulating the corresponding expression is: first obtain the first feature point of the aforementioned face 3D model , And then multiply the first feature point by the adjustment matrix corresponding to the above expression to obtain the second feature point with the expression, and then map the second feature point on the above-mentioned face 3D model, then the person with the above expression is obtained 3D model of face. Each expression corresponds to an adjustment matrix, and the characteristic matrix corresponding to each expression is obtained by the staff after a lot of calculation and debugging. In the further specific adjustment process, the processor first divides the various parts of the face 3D model into regions, such as face region, nose region, mouth region, eyebrow region, etc., and can continue to subdivide each region into multiple sub-regions. Area, and then adjust the type according to the expression type and the preset area. After obtaining the expression, obtain the area or sub-area corresponding to the expression, then obtain the feature points of the area or sub-area corresponding to the expression, and then multiply the feature points by the expression The corresponding region adjustment matrix is used to obtain feature points with expressions, and then the feature points with expressions are mapped to corresponding regions or sub-regions to obtain a 3D face model with the above expressions. Realize the 3D model of the human face to simulate the same expression as the above-mentioned facial image expression. Then, according to the deflection angle of the aforementioned image, the deflection angle is the y value calculated in the formula, and the replacement picture with the aforementioned expression of the 3D face model is obtained by projection. For example, when it is recognized that the expression is a smile, in the corresponding relationship between the expression type and the area adjustment method, the adjustment area corresponding to the smile expression type is the mouth area and the adjustment matrix corresponding to the mouth area, and then the above 3D model The mouth area in is multiplied by the above adjustment matrix to obtain a 3D face model with a smiling expression. Then rotate the 3D face model with the smile expression at the above deflection angle, and then project the rotated 3D face model with the smile expression from the direction facing the original 3D face model on the initial On the plane behind the 3D face model, a replacement picture with a smiling expression is finally obtained. Specifically, the 3D face model with the above expression is centered on the axis of symmetry of the 3D face model, and the angle of the y value calculated above is rotated, and then a camera is simulated, from the initial 3D face model (not rotated) Take a picture of the opposite place, and the resulting picture is the above replacement picture.
在一个实施例中,上述3D模型为人脸3D模型,上述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:In one embodiment, the aforementioned 3D model is a human face 3D model, and the aforementioned step of projecting the 3D model according to the deflection angle to obtain a replacement picture includes:
S36、将所述人脸图像输入到预设的器官识别模型中,得到所述人脸图像中的第一器官;S36. Input the face image into a preset organ recognition model to obtain the first organ in the face image;
S37、将所述第一器官与预设的常态下的第二器官根据色素差建立同样行列数的矩阵,分别得到第一矩阵和第二矩阵;S37. Build a matrix with the same number of rows and columns according to the pigment difference between the first organ and the second organ under the preset normal state to obtain the first matrix and the second matrix respectively;
S38、将所述第一矩阵减去第二矩阵,得到矩阵差;S38. Subtract the second matrix from the first matrix to obtain a matrix difference;
S39、计算所述矩阵差的秩;S39. Calculate the rank of the matrix difference;
S310、调用预设的秩与面部动作的对应关系,根据所述矩阵差的秩获取所述第一器官对应的面部动作;S310. Invoke a preset correspondence relationship between a rank and a facial action, and obtain the facial action corresponding to the first organ according to the rank of the matrix difference;
S311、控制所述人脸3D模型的各个器官模拟出所述面部动作;S311: Control each organ of the human face 3D model to simulate the facial action;
S312、将模拟出所述面部动作的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以投影,得到替换图片。S312: After rotating the face 3D model that simulates the facial motion by the degree of the deflection angle, map the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
本实施例中,将提取出的视频中的人脸图像进行预处理后,输入到一个训练后的器官识别模型中,该器官识别模型对上述人脸图像进行分割,识别出该人脸的各个器官,将上述人脸图像中包含有各器官的图像区域定义为第一器官,第一器官包括多个脸上可以活动的器官,具体的,第一器官包括眼睛、嘴巴、鼻子、眉毛、脸颊肌肉。将各个第一器官与预设的正常状态下的第二器官状态一一比较,根据比较结果来判断出各器官的动作。判断器官的动作的具体过程为,将第一器官与对应的第二器官进行图像分析,分别为第一器官和第二器官根据色素差建立同样行列数的矩阵,然后将第一器官的矩阵减去第二器官的矩阵,得到矩阵差,再计算矩阵差的秩,根据秩的结果在该器官的秩与面部动作的对应关系中判定该器官的面部动作。另,如果秩的结果小于一定值,判定该器官是处于正常状态下的,则上述人脸3D模型中的对应的器官是不需要模拟出其他面部动作的。然后识别出人脸3D模型的各个器官,并确认上述第一器官中具有非正常状态下的面部动作的器官。然后将人脸3D模型的各个器官乘以与该器官对应的面部动作的动作矩阵相乘,得到人脸模型的各个器官的面部动作,使人脸3D模型做出与上述变化的面部动作做出相同的动作。然后根据上述图像的偏转角度,投影得到该3D人脸模型的有上述面部动作相同的二维图片,再将该二维图片加载在视频中的人脸图像位置处。将带有面部动作人脸3D模型进行投影得到替换图片的步骤与上述S35的方法相同。In this embodiment, the extracted face image in the video is preprocessed and input into a trained organ recognition model. The organ recognition model segments the aforementioned face image and recognizes each of the face images. Organs. The image area containing the various organs in the above face image is defined as the first organ. The first organ includes multiple organs that can move on the face. Specifically, the first organ includes eyes, mouth, nose, eyebrows, and cheeks. muscle. Each first organ is compared with the preset second organ state under the normal state one by one, and the action of each organ is determined according to the comparison result. The specific process of judging the actions of the organs is to perform image analysis on the first organ and the corresponding second organ, and establish a matrix with the same number of rows and columns for the first organ and the second organ according to the pigment difference, and then subtract the matrix of the first organ. The matrix of the second organ is removed to obtain the matrix difference, and then the rank of the matrix difference is calculated. According to the result of the rank, the facial movement of the organ is determined from the correspondence between the rank of the organ and the facial movement. In addition, if the result of the rank is less than a certain value, it is determined that the organ is in a normal state, and the corresponding organ in the aforementioned 3D face model does not need to simulate other facial movements. Then, the various organs of the human face 3D model are identified, and it is confirmed that the first organ has an abnormal facial movement in the above-mentioned organ. Then multiply each organ of the face 3D model by the action matrix of the facial action corresponding to the organ to obtain the facial action of each organ of the face model, and make the face 3D model make facial actions with the above changes The same action. Then, according to the deflection angle of the image, a two-dimensional picture of the 3D face model with the same facial action is obtained by projection, and then the two-dimensional picture is loaded at the position of the face image in the video. The steps of projecting the 3D face model with facial action to obtain the replacement picture are the same as the method of S35.
上述器官识别模型是基于一个深度神经网络模型训练得到的,工作人员首先采集多个包含有人的脸部的图片,并将图片中每个人有脸部上的各个器官分别进行标注,然后将该图片以及各个标注输入到该深度神经网络模型中进行训练,得到了器官识别模型。The above-mentioned organ recognition model is based on a deep neural network model training. The staff first collects a number of pictures containing the face of a person, and annotates each organ on the face of each person in the picture, and then the picture And each annotation is input into the deep neural network model for training, and the organ recognition model is obtained.
在一个实施例中,上述将所述替换图片加载在所述人脸图像上的步骤,包括:In one embodiment, the above step of loading the replacement picture on the face image includes:
S41、获取终端的属性信息中的显示屏的尺寸大小以及所述人脸图像在播放界面占显示屏的比例;S41: Acquire the size of the display screen in the attribute information of the terminal and the proportion of the face image in the display screen in the playback interface;
S42、模拟将所述人脸图像加载在播放界面上,计算播放界面中所述人脸图像的尺寸大小;S42. Simulate loading the face image on the playback interface, and calculate the size of the face image in the playback interface;
S43、计算所述人脸图像的尺寸大小与预设的标准尺寸大小之间的比例;S43. Calculate the ratio between the size of the face image and the preset standard size;
S44、将所述替换图片按照所述比例进行缩放处理;S44. Perform scaling processing on the replacement picture according to the scale;
S45、将所述缩放处理后的替换图片加载在所述人脸图像上。S45. Load the replacement picture after the scaling process on the face image.
本实施例中,处理器根据视频信息计算得到上述人脸图像的尺寸大小,具体的,获取APP所在的手机的属性信息,得到显示屏的尺寸大小,然后根根据APP的播放界面占显示屏的比例,模拟将人脸图像加载在播放界面上,然后计算播放界面中该人脸图像的尺寸大小。然后将该尺寸大小与预设的标准尺寸大小进行比较,得出两者之间的比例。标准尺寸大小是人为设置的,设置的过程是将一个标准人脸放置在距离指定摄像头的指定距离后采集得到的人脸的尺寸大小,数据库中的对象对应的3D模型也是根据该指定摄像头在指定距离后拍摄采集的。计算到人脸图像的尺寸大小与标准尺寸大小的比例,然后将替换图像也按照上述比例进行缩放,以使替换图像的尺寸与人脸图像的尺寸相匹配,替换图片的尺寸大小与人脸图像的尺寸大小接近,以便于将替换图片加载在人脸图像上时尺寸合适,看起来比较协调。然后将缩放后的替换图片加载在人脸图像上。In this embodiment, the processor calculates the size of the aforementioned face image according to the video information. Specifically, it obtains the attribute information of the mobile phone where the APP is located, and obtains the size of the display screen. Proportion, which simulates loading a face image on the playback interface, and then calculates the size of the face image in the playback interface. Then compare the size with the preset standard size to get the ratio between the two. The standard size is set manually. The setting process is to place a standard face at a specified distance from the specified camera and then collect the size of the face. The 3D model corresponding to the object in the database is also specified according to the specified camera. Captured after the distance. Calculate the ratio of the size of the face image to the standard size, and then scale the replacement image according to the above ratio, so that the size of the replacement image matches the size of the face image, and the size of the replacement image is the same as that of the face image. The size is close, so that when the replacement image is loaded on the face image, the size is appropriate and looks more coordinated. Then load the zoomed replacement picture on the face image.
在一个实施例中,上述接收到用户发出的修改图片的指令后,提取视频中的人脸图像的步骤,包括:In one embodiment, the step of extracting the face image in the video after receiving the instruction to modify the picture from the user includes:
S11、接收到用户发出的修改图片的指令后,采集视频中的帧图片;S11. After receiving the instruction to modify the picture sent by the user, collect the frame picture in the video;
S12、将所述帧图片输入到预设的人脸识别模型中,输出得到所述人脸图像。S12. Input the frame picture into a preset face recognition model, and output the face image.
本实施例中,处理器接收到用户发出的替换或添加指令后,获取指定APP中播放的视频,然后读取视频的详细信息,将视频的当前时刻播放的帧图片截取出来,然后将该帧图片输入到预设的人脸识别模型中,根据人脸识别模型进行辨认识别,输出得到人脸图像。In this embodiment, after the processor receives the replacement or addition instruction issued by the user, it obtains the video played in the specified APP, then reads the detailed information of the video, intercepts the frame picture played at the current moment of the video, and then the frame The picture is input into the preset face recognition model, and the recognition is performed according to the face recognition model, and the face image is obtained by outputting.
在一个实施例中,上述将所述帧图片输入到预设的人脸识别模型中,输出得到所述人脸图像的步骤之前,包括:In an embodiment, before the step of inputting the frame picture into the preset face recognition model and outputting the face image, the method includes:
S101、将训练集中的多个包含有人脸图像的图片输入到预设的神经网络模型进行训练,得到用于识别出图片中的人脸的神经网络模型作为所述人脸识别模型。S101: Input a plurality of pictures containing human face images in a training set into a preset neural network model for training, and obtain a neural network model for recognizing human faces in the pictures as the face recognition model.
本实施例中,工作人员事先挑选出多个包含有人脸图像的图片,形成训练集,然后将这些图片输入到预设的神经网络模型中进行训练,神经网络模型自动根据人脸图像中的灰度形成的轨迹来计算优化得到人脸图片的特征系数,即使该神经网络模型可以用于识别出图片中是否有人脸图像。在后续提取视频中的人脸图像时,将帧图片进行处理,得到图片的灰度,然后计算灰度轨迹中是否包含有上述训练得到的特征系数,如果是,则判断视频中有人脸图片,根据特征系数对应的灰度轨迹,提取出人脸图像。In this embodiment, the staff selects a number of pictures containing human face images in advance to form a training set, and then inputs these pictures into a preset neural network model for training. The neural network model is automatically based on the gray in the face image. The trajectory formed by the degree is calculated and optimized to obtain the feature coefficients of the face picture, even if the neural network model can be used to identify whether there is a face image in the picture. In the subsequent extraction of the face image in the video, the frame picture is processed to obtain the grayscale of the picture, and then the grayscale trajectory is calculated whether the feature coefficient obtained by the above training is included, and if it is, the human face image in the video is judged. According to the gray trajectory corresponding to the feature coefficient, the face image is extracted.
在一个实施例中,上述将所述替换图片加载在所述人脸图像上的步骤之后,包括:In one embodiment, after the above step of loading the replacement picture on the face image, it includes:
S5、获取所述对象的属性信息;S5. Obtain attribute information of the object;
S6、判断所述属性信息是否是脸部信息;S6. Determine whether the attribute information is face information;
S7、若是,将所述人脸图像删除。S7. If yes, delete the face image.
本实施例中,对象是存储在数据库中的,对应的每个对象的信息也均存储在数据库中。每个对象的属性包括是否是脸部信息,如果是脸部信息,则替换图片对应的也是人的脸部信息,脸部信息呈不规则的形状,形成的替换图片很少可以全面覆盖在上述人脸图像上,因此,需要将视频中的人脸图像删除,使整体的替换后的视频信息更加协调。处理器读取对象的属性信息,判断该属性信息是否是脸部信息。若是脸部信息,则将人脸图像删除。在一具体实施例中,对象的属性信息包括脸部信息与佩饰信息两类,其中脸部信息包括人脸、狗脸、猫脸,佩饰信息包括眼镜、耳环、帽子。如果判定对象不是脸部信息,则只是将替换图片加载在人脸图像上,形成给视频中的人物佩戴饰品的效果,给用户更好的体验效果。In this embodiment, the object is stored in the database, and the corresponding information of each object is also stored in the database. The attributes of each object include whether it is face information. If it is face information, the replacement picture corresponds to the person’s face information. The face information is in an irregular shape, and the replacement pictures formed rarely cover the above On the face image, therefore, it is necessary to delete the face image in the video to make the overall replacement video information more coordinated. The processor reads the attribute information of the object, and judges whether the attribute information is face information. If it is face information, delete the face image. In a specific embodiment, the attribute information of the object includes two types of facial information and accessory information, where the facial information includes human faces, dog faces, and cat faces, and the accessory information includes glasses, earrings, and hats. If it is determined that the object is not facial information, only the replacement picture is loaded on the face image to form the effect of wearing accessories to the characters in the video, which gives the user a better experience.
综上所述,本申请的基于人脸识别的修改图片的方法,在替换人脸图片时,根据图片或视频中的人脸的偏转角度后,将预替换的脸部的角度也替换成与视频中的人脸的偏转角度相同,使替换出来的画面更加真实。In summary, the method for modifying a picture based on face recognition of the present application, when replacing a face picture, according to the deflection angle of the face in the picture or video, the angle of the pre-replaced face is also replaced with The deflection angle of the face in the video is the same, which makes the replaced picture more realistic.
参照图2,本申请实施例中还提供一种基于人脸识别的修改图片的装置,包括:2, an embodiment of the present application also provides an apparatus for modifying pictures based on face recognition, including:
提取模块1,用于接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;The extraction module 1 is configured to extract a face image in a video after receiving an instruction to modify a picture issued by a user, and the instruction includes an object to be loaded on the face image;
计算角度模块2,用于根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; The angle calculation module 2 is used to calculate the deflection angle of the face image according to the formula: y=18.75x 2 -135x+116.25, and call the 3D model corresponding to the object in the database, where y represents the left deflection Deflection angle, x represents the ratio of the size of the left organ in the face image to the size of the corresponding right organ;
投影模块3,用于将所述3D模型按照所述偏转角度进行投影,得到替换图片;The projection module 3 is used to project the 3D model according to the deflection angle to obtain a replacement picture;
加载模块4,用于将所述替换图片加载在所述人脸图像上。The loading module 4 is used to load the replacement picture on the face image.
参照图3,本申请实施例中还提供一种计算机设备,该计算机设备可以是服务器,其内部结构可以如图3所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设计的处理器用于提供计算和控制能力。该计算机设备的存储器包括存储介质、内存储器。存储介质可以是非易失性存储介质,也可以是易失性存储介质,该存储介质存储有操作系统、计算机程序和数据库。该内存器为存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储3D模型等数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种基于人脸识别的修改图片的方法。3, an embodiment of the present application also provides a computer device. The computer device may be a server, and its internal structure may be as shown in FIG. 3. The computer equipment includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the computer designed processor is used to provide calculation and control capabilities. The memory of the computer device includes a storage medium and an internal memory. The storage medium may be a non-volatile storage medium or a volatile storage medium, and the storage medium stores an operating system, a computer program, and a database. The memory provides an environment for the operation of the operating system and computer programs in the storage medium. The database of the computer equipment is used to store data such as 3D models. The network interface of the computer device is used to communicate with an external terminal through a network connection. The computer program is executed by the processor to realize a method of modifying pictures based on face recognition.
本领域技术人员可以理解,图3中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定。Those skilled in the art can understand that the structure shown in FIG. 3 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied.
本申请一实施例还提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现一种基于人脸识别的修改图片的方法。An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, a method for modifying a picture based on face recognition is implemented.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读取存储介质中,该计算机可读存储介质可以是非易失性计算机可读存储介质,也可以是易失性计算机可读存储介质。该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的和实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可以包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双速据率SDRAM(SSRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。A person of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing relevant hardware through a computer program. The computer program can be stored in a computer readable storage medium. The computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. When the computer program is executed, it may include the processes of the above-mentioned method embodiments. Wherein, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and/or volatile memory. Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not a limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。It should be noted that in this article, the terms "including", "including" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements not only includes those elements, It also includes other elements that are not explicitly listed, or elements inherent to the process, device, article, or method. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, device, article or method that includes the element.
以上所述仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only the preferred embodiments of this application, and do not limit the scope of this application. Any equivalent structure or equivalent process transformation made using the content of this application description and drawings, or directly or indirectly applied to other related The technical field is equally included in the scope of patent protection of this application.

Claims (20)

  1. 一种基于人脸识别的修改图片的方法,其特征在于,包括:A method for modifying pictures based on face recognition, which is characterized in that it includes:
    接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;After receiving the instruction to modify the picture issued by the user, extract the face image in the video, and the instruction includes the object to be loaded on the face image;
    根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; According to the formula: y=18.75x 2 -135x+116.25, calculate the deflection angle of the face image, and call the 3D model corresponding to the object in the database, where y represents the deflection angle to the left, and x represents the face The ratio of the size of the left organ in the image to the size of the corresponding right organ;
    将所述3D模型按照所述偏转角度进行投影,得到替换图片;Project the 3D model according to the deflection angle to obtain a replacement picture;
    将所述替换图片加载在所述人脸图像上。Loading the replacement picture on the face image.
  2. 如权利要求1所述的基于人脸识别的修改图片的方法,其特征在于,所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:The method for modifying a picture based on face recognition according to claim 1, wherein the 3D model is a face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture ,include:
    将所述人脸图像进行预处理后,输入到训练后的表情识别模型中识别,以获取所述人脸图像的表情;After the face image is preprocessed, it is input into a trained expression recognition model for recognition, so as to obtain the expression of the face image;
    获取所述人脸3D模型的第一特征点以及所述表情对应的调整矩阵,其中,表情以及调整矩阵的对应关系是预先设置的;Acquiring a first feature point of the human face 3D model and an adjustment matrix corresponding to the expression, wherein the corresponding relationship between the expression and the adjustment matrix is preset;
    将所述第一特征点乘以所述调整矩阵,得到所述第二特征点;Multiply the first feature point by the adjustment matrix to obtain the second feature point;
    将所述第二特征点映射在所述人脸3D模型上,控制所述人脸3D模型模拟出所述表情;Mapping the second feature point on the face 3D model, and controlling the face 3D model to simulate the expression;
    将模拟出所述表情的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the expression is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  3. 如权利要求1所述的基于人脸识别的修改图片的方法,其特征在于,所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:The method for modifying a picture based on face recognition according to claim 1, wherein the 3D model is a face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture ,include:
    将所述人脸图像输入到预设的器官识别模型中,得到所述人脸图像中的第一器官;Inputting the face image into a preset organ recognition model to obtain the first organ in the face image;
    将所述第一器官与预设的常态下的第二器官根据色素差建立同样行列数的矩阵,分别得到第一矩阵和第二矩阵;Establishing a matrix with the same number of rows and columns according to the pigment difference between the first organ and the preset second organ under normal conditions to obtain the first matrix and the second matrix respectively;
    将所述第一矩阵减去第二矩阵,得到矩阵差;Subtract the second matrix from the first matrix to obtain a matrix difference;
    计算所述矩阵差的秩;Calculating the rank of the matrix difference;
    调用预设的秩与面部动作的对应关系,根据所述矩阵差的秩获取所述第一器官对应的面部动作;Calling a preset correspondence relationship between a rank and a facial movement, and acquiring the facial movement corresponding to the first organ according to the rank of the matrix difference;
    控制所述人脸3D模型的各个器官模拟出所述面部动作;Controlling each organ of the human face 3D model to simulate the facial action;
    将模拟出所述面部动作的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the facial motion is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  4. 如权利要求1所述的基于人脸识别的修改图片的方法,其特征在于,所述将所述替换图片加载在所述人脸图像上的步骤,包括:The method for modifying a picture based on face recognition according to claim 1, wherein the step of loading the replacement picture on the face image comprises:
    获取终端的属性信息中的显示屏的尺寸大小以及所述人脸图像在播放界面占显示屏的比例;Acquiring the size of the display screen in the attribute information of the terminal and the ratio of the face image to the display screen in the playback interface;
    模拟将所述人脸图像加载在播放界面上,计算播放界面中所述人脸图像的尺寸大小;Simulate loading the face image on the playback interface, and calculate the size of the face image in the playback interface;
    计算所述人脸图像的尺寸大小与预设的标准尺寸大小之间的比例;Calculating the ratio between the size of the face image and the preset standard size;
    将所述替换图片按照所述比例进行缩放处理;Performing zoom processing on the replacement picture according to the scale;
    将所述缩放处理后的替换图片加载在所述人脸图像上。The replacement picture after the scaling process is loaded on the face image.
  5. 如权利要求1所述的基于人脸识别的修改图片的方法,其特征在于,所述接收到用户发出的修改图片的指令后,提取视频中的人脸图像的步骤,包括:The method for modifying a picture based on face recognition according to claim 1, wherein the step of extracting the face image in the video after receiving the instruction to modify the picture from the user includes:
    接收到用户发出的替换人脸的指令后,采集视频中的帧图片;After receiving the user's instruction to replace the face, collect frame pictures in the video;
    将所述帧图片输入到预设的人脸识别模型中,输出得到所述人脸图像。Input the frame picture into a preset face recognition model, and output the face image.
  6. 如权利要求5所述的基于人脸识别的修改图片的方法,其特征在于,所述将所述帧图片输入到预设的人脸识别模型中,输出得到所述人脸图像的步骤之前,包括:The method for modifying a picture based on face recognition according to claim 5, wherein before the step of inputting the frame picture into a preset face recognition model, and outputting the face image, include:
    将训练集中的多个包含有人脸图像的图片输入到预设的神经网络模型进行训练,得到用于识别出图片中的人脸的神经网络模型作为所述人脸识别模型。A plurality of pictures containing human face images in the training set are input to a preset neural network model for training, and a neural network model for recognizing the human face in the picture is obtained as the face recognition model.
  7. 如权利要求1所述的基于人脸识别的修改图片的方法,其特征在于,所述将所述替换图片加载在所述人脸图像上的步骤之后,包括:The method for modifying a picture based on face recognition according to claim 1, wherein after the step of loading the replacement picture on the face image, the method comprises:
    获取所述对象的属性信息;Acquiring attribute information of the object;
    判断所述属性信息是否是脸部信息;Judging whether the attribute information is face information;
    若是,将所述人脸图像删除。If yes, delete the face image.
  8. 一种基于人脸识别的修改图片的装置,其特征在于,包括:A device for modifying pictures based on face recognition, characterized in that it comprises:
    提取模块,用于接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;The extraction module is configured to extract the face image in the video after receiving the instruction to modify the picture sent by the user, and the instruction includes the object to be loaded on the face image;
    计算角度模块,用于根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; The calculation angle module is used to calculate the deflection angle of the face image according to the formula: y=18.75x 2 -135x+116.25, and call the 3D model corresponding to the object in the database, where y represents the deflection to the left Angle, x represents the ratio of the left organ size to the corresponding right organ size in the face image;
    投影模块,用于将所述3D模型按照所述偏转角度进行投影,得到替换图片;A projection module, configured to project the 3D model according to the deflection angle to obtain a replacement picture;
    加载模块,用于将所述替换图片加载在所述人脸图像上。The loading module is used to load the replacement picture on the face image.
  9. 如权利要求8所述的基于人脸识别的修改图片的装置,其特征在于,所述3D模型为人脸3D模型,所述投影模块包括:8. The device for modifying pictures based on face recognition according to claim 8, wherein the 3D model is a face 3D model, and the projection module comprises:
    获取表情单元,用于将所述人脸图像进行预处理后,输入到训练后的表情识别模型中识别,以获取所述人脸图像的表情;An expression acquiring unit, configured to preprocess the face image and input it into a trained expression recognition model for recognition, so as to acquire the expression of the face image;
    特征点单元,用于获取所述人脸3D模型的第一特征点以及所述表情对应的调整矩阵,其中,表情以及调整矩阵的对应关系是预先设置的;The feature point unit is used to obtain the first feature point of the human face 3D model and the adjustment matrix corresponding to the expression, wherein the corresponding relationship between the expression and the adjustment matrix is preset;
    相乘单元,用于将所述第一特征点乘以所述调整矩阵,得到所述第二特征点;The multiplication unit is configured to multiply the first feature point by the adjustment matrix to obtain the second feature point;
    模拟表情单元,用于将所述第二特征点映射在所述人脸3D模型上,控制所述人脸3D模型模拟出所述表情;The emoticon simulation unit is configured to map the second feature point on the face 3D model, and control the face 3D model to simulate the emoticon;
    第一投影单元,用于将模拟出所述表情的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。The first projection unit is configured to rotate the face 3D model that simulates the expression by the degree of the deflection angle, and then map the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  10. 如权利要求8所述的基于人脸识别的修改图片的装置,其特征在于,所述D模型为人脸3D模型,所述投影模块包括:The device for modifying pictures based on face recognition of claim 8, wherein the D model is a 3D face model, and the projection module comprises:
    得到器官单元,用于将所述人脸图像输入到预设的器官识别模型中,得到所述人脸图像中的第一器官;The obtaining organ unit is used to input the face image into a preset organ recognition model to obtain the first organ in the face image;
    建立矩阵单元,用于将所述第一器官与预设的常态下的第二器官根据色素差建立同样行列数的矩阵,分别得到第一矩阵和第二矩阵;A matrix establishment unit, configured to establish a matrix with the same number of rows and columns according to the pigment difference between the first organ and the second organ under a preset normal state, to obtain the first matrix and the second matrix respectively;
    相减单元,用于将所述第一矩阵减去第二矩阵,得到矩阵差;The subtraction unit is configured to subtract the second matrix from the first matrix to obtain a matrix difference;
    计算秩单元,用于计算所述矩阵差的秩;A calculating rank unit for calculating the rank of the matrix difference;
    获取动作单元,用于调用预设的秩与面部动作的对应关系,根据所述矩阵差的秩获取所述第一器官对应的面部动作;An obtaining action unit, configured to call a preset correspondence relationship between rank and facial action, and obtain the facial action corresponding to the first organ according to the rank of the matrix difference;
    模拟动作单元,用于控制所述人脸3D模型的各个器官模拟出所述面部动作;The simulation action unit is used to control the various organs of the human face 3D model to simulate the facial action;
    第二投影单元,用于将模拟出所述面部动作的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以投影,得到替换图片。The second projection unit is configured to rotate the face 3D model that simulates the facial action by the degree of the deflection angle, and then map the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  11. 如权利要求8所述的基于人脸识别的修改图片的装置,其特征在于,所述加载模块包括:The device for modifying pictures based on face recognition according to claim 8, wherein the loading module comprises:
    获取尺寸单元,用于获取终端的属性信息中的显示屏的尺寸大小以及所述人脸图像在播放界面占显示屏的比例;The obtaining size unit is used to obtain the size of the display screen in the attribute information of the terminal and the proportion of the face image in the display screen in the playback interface;
    计算尺寸单元,用于模拟将所述人脸图像加载在播放界面上,计算播放界面中所述人脸图像的尺寸大小;The size calculation unit is used to simulate loading the face image on the playback interface and calculate the size of the face image in the playback interface;
    计算比例单元,用于计算所述人脸图像的尺寸大小与预设的标准尺寸大小之间的比例;A calculating ratio unit for calculating the ratio between the size of the face image and the preset standard size;
    缩放单元,用于将所述替换图片按照所述比例进行缩放处理;A scaling unit, configured to perform scaling processing on the replacement picture according to the scale;
    加载单元,用于将所述缩放处理后的替换图片加载在所述人脸图像上。The loading unit is configured to load the zoomed replacement picture on the face image.
  12. 如权利要求8所述的基于人脸识别的修改图片的装置,其特征在于,所述提取模块包括:The device for modifying pictures based on face recognition according to claim 8, wherein the extraction module comprises:
    采集单元,用于接收到用户发出的修改图片的指令后,采集视频中的帧图片;The collection unit is used to collect the frame picture in the video after receiving the instruction to modify the picture sent by the user;
    输出单元,用于将所述帧图片输入到预设的人脸识别模型中,输出得到所述人脸图像。The output unit is configured to input the frame picture into a preset face recognition model, and output the face image.
  13. 如权利要求12所述的基于人脸识别的修改图片的装置,其特征在于,所述基于人脸识别的修改图片的装置还包括:The device for modifying a picture based on face recognition of claim 12, wherein the device for modifying a picture based on face recognition further comprises:
    训练模块,用于将训练集中的多个包含有人脸图像的图片输入到预设的神经网络模型进行训练,得到用于识别出图片中的人脸的神经网络模型作为所述人脸识别模型。The training module is used for inputting a plurality of pictures containing human face images in the training set to a preset neural network model for training, and obtaining a neural network model for recognizing the human face in the picture as the face recognition model.
  14. 如权利要求8所述的基于人脸识别的修改图片的装置,其特征在于,所述基于人脸识别的修改图片的装置还包括:The device for modifying pictures based on face recognition according to claim 8, wherein the device for modifying pictures based on face recognition further comprises:
    获取模块,用于获取所述对象的属性信息;An obtaining module, used to obtain attribute information of the object;
    判断模块,用于判断所述属性信息是否是脸部信息;The judgment module is used to judge whether the attribute information is face information;
    删除模块,用于若所述属性信息是脸部信息,将所述人脸图像删除。The deleting module is used to delete the face image if the attribute information is face information.
  15. 一种计算机设备,包括存储器和处理器,所述存储器存储有计算机程序,其特征在于,所述处理器执行所述计算机程序时实现一种基于人脸识别的修改图片的方法,该方法包括步骤:A computer device includes a memory and a processor, the memory stores a computer program, and is characterized in that, when the processor executes the computer program, a method for modifying a picture based on face recognition is implemented, and the method includes the steps :
    接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;After receiving the instruction to modify the picture issued by the user, extract the face image in the video, and the instruction includes the object to be loaded on the face image;
    根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; According to the formula: y=18.75x 2 -135x+116.25, calculate the deflection angle of the face image, and call the 3D model corresponding to the object in the database, where y represents the deflection angle to the left, and x represents the face The ratio of the size of the left organ in the image to the size of the corresponding right organ;
    将所述3D模型按照所述偏转角度进行投影,得到替换图片;Project the 3D model according to the deflection angle to obtain a replacement picture;
    将所述替换图片加载在所述人脸图像上。Loading the replacement picture on the face image.
  16. 如权利要求15所述的计算机设备,其特征在于,所述所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:15. The computer device of claim 15, wherein the 3D model is a human face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture comprises:
    将所述人脸图像进行预处理后,输入到训练后的表情识别模型中识别,以获取所述人脸图像的表情;After the face image is preprocessed, it is input into a trained expression recognition model for recognition, so as to obtain the expression of the face image;
    获取所述人脸3D模型的第一特征点以及所述表情对应的调整矩阵,其中,表情以及调整矩阵的对应关系是预先设置的;Acquiring a first feature point of the human face 3D model and an adjustment matrix corresponding to the expression, wherein the corresponding relationship between the expression and the adjustment matrix is preset;
    将所述第一特征点乘以所述调整矩阵,得到所述第二特征点;Multiply the first feature point by the adjustment matrix to obtain the second feature point;
    将所述第二特征点映射在所述人脸3D模型上,控制所述人脸3D模型模拟出所述表情;Mapping the second feature point on the face 3D model, and controlling the face 3D model to simulate the expression;
    将模拟出所述表情的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the expression is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  17. 如权利要求15所述的计算机设备,其特征在于,所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:15. The computer device according to claim 15, wherein the 3D model is a human face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture comprises:
    将所述人脸图像输入到预设的器官识别模型中,得到所述人脸图像中的第一器官;Inputting the face image into a preset organ recognition model to obtain the first organ in the face image;
    将所述第一器官与预设的常态下的第二器官根据色素差建立同样行列数的矩阵,分别得到第一矩阵和第二矩阵;Establishing a matrix with the same number of rows and columns according to the pigment difference between the first organ and the preset second organ under normal conditions to obtain the first matrix and the second matrix respectively;
    将所述第一矩阵减去第二矩阵,得到矩阵差;Subtract the second matrix from the first matrix to obtain a matrix difference;
    计算所述矩阵差的秩;Calculating the rank of the matrix difference;
    调用预设的秩与面部动作的对应关系,根据所述矩阵差的秩获取所述第一器官对应的面部动作;Calling a preset correspondence relationship between a rank and a facial movement, and acquiring the facial movement corresponding to the first organ according to the rank of the matrix difference;
    控制所述人脸3D模型的各个器官模拟出所述面部动作;Controlling each organ of the human face 3D model to simulate the facial action;
    将模拟出所述面部动作的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the facial motion is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  18. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现一种基于人脸识别的修改图片的方法,该方法包括步骤:接收到用户发出的修改图片的指令后,提取视频中的人脸图像,所述指令中包括待加载在所述人脸图像上的对象;A computer-readable storage medium having a computer program stored thereon is characterized in that, when the computer program is executed by a processor, a method for modifying pictures based on face recognition is realized, the method comprising the steps of: After the instruction to modify the picture, extract the face image in the video, and the instruction includes the object to be loaded on the face image;
    根据公式:y=18.75x 2-135x+116.25,计算所述人脸图像的偏转角度,并调用数据库中与所述对象对应的3D模型,其中y表示向左偏转的偏转角度,x表示人脸图像中左边器官尺寸与对应的右边器官尺寸的比例值; According to the formula: y=18.75x 2 -135x+116.25, calculate the deflection angle of the face image, and call the 3D model corresponding to the object in the database, where y represents the deflection angle to the left, and x represents the face The ratio of the size of the left organ in the image to the size of the corresponding right organ;
    将所述3D模型按照所述偏转角度进行投影,得到替换图片;Project the 3D model according to the deflection angle to obtain a replacement picture;
    将所述替换图片加载在所述人脸图像上。Loading the replacement picture on the face image.
  19. 如权利要求18所述的计算机可读存储介质,其特征在于,所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:18. The computer-readable storage medium of claim 18, wherein the 3D model is a human face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture comprises:
    将所述人脸图像进行预处理后,输入到训练后的表情识别模型中识别,以获取所述人脸图像的表情;After the face image is preprocessed, it is input into a trained expression recognition model for recognition, so as to obtain the expression of the face image;
    获取所述人脸3D模型的第一特征点以及所述表情对应的调整矩阵,其中,表情以及调整矩阵的对应关系是预先设置的;Acquiring a first feature point of the human face 3D model and an adjustment matrix corresponding to the expression, wherein the corresponding relationship between the expression and the adjustment matrix is preset;
    将所述第一特征点乘以所述调整矩阵,得到所述第二特征点;Multiply the first feature point by the adjustment matrix to obtain the second feature point;
    将所述第二特征点映射在所述人脸3D模型上,控制所述人脸3D模型模拟出所述表情;Mapping the second feature point on the face 3D model, and controlling the face 3D model to simulate the expression;
    将模拟出所述表情的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the expression is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
  20. 如权利要求18所述的计算机可读存储介质,其特征在于,所述3D模型为人脸3D模型,所述将所述3D模型按照所述偏转角度进行投影,得到替换图片的步骤,包括:18. The computer-readable storage medium of claim 18, wherein the 3D model is a human face 3D model, and the step of projecting the 3D model according to the deflection angle to obtain a replacement picture comprises:
    将所述人脸图像输入到预设的器官识别模型中,得到所述人脸图像中的第一器官;Inputting the face image into a preset organ recognition model to obtain the first organ in the face image;
    将所述第一器官与预设的常态下的第二器官根据色素差建立同样行列数的矩阵,分别得到第一矩阵和第二矩阵;Establishing a matrix with the same number of rows and columns according to the pigment difference between the first organ and the preset second organ under normal conditions to obtain the first matrix and the second matrix respectively;
    将所述第一矩阵减去第二矩阵,得到矩阵差;Subtract the second matrix from the first matrix to obtain a matrix difference;
    计算所述矩阵差的秩;Calculating the rank of the matrix difference;
    调用预设的秩与面部动作的对应关系,根据所述矩阵差的秩获取所述第一器官对应的面部动作;Calling a preset correspondence relationship between a rank and a facial movement, and acquiring the facial movement corresponding to the first organ according to the rank of the matrix difference;
    控制所述人脸3D模型的各个器官模拟出所述面部动作;Controlling each organ of the human face 3D model to simulate the facial action;
    将模拟出所述面部动作的所述人脸3D模型旋转所述偏转角度的度数后,映射在未旋转时所述人脸3D模型的背面以进行投影,得到替换图片。After the face 3D model that simulates the facial motion is rotated by the degree of the deflection angle, it is mapped to the back of the face 3D model when it is not rotated for projection to obtain a replacement picture.
PCT/CN2019/117660 2019-04-16 2019-11-12 Facial recognition-based image modification method and apparatus, and computer device WO2020211347A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910305175.6 2019-04-16
CN201910305175.6A CN110163814B (en) 2019-04-16 2019-04-16 Method, device and computer equipment for modifying pictures based on face recognition

Publications (1)

Publication Number Publication Date
WO2020211347A1 true WO2020211347A1 (en) 2020-10-22

Family

ID=67639600

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/117660 WO2020211347A1 (en) 2019-04-16 2019-11-12 Facial recognition-based image modification method and apparatus, and computer device

Country Status (2)

Country Link
CN (1) CN110163814B (en)
WO (1) WO2020211347A1 (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113486694A (en) * 2020-10-26 2021-10-08 青岛海信电子产业控股股份有限公司 Face image processing method and terminal equipment
CN113780158A (en) * 2021-09-08 2021-12-10 宁波书写芯忆科技有限公司 Intelligent attention force detection method
WO2023019699A1 (en) * 2021-08-16 2023-02-23 武汉大学 High-angle facial recognition method and system based on 3d facial model
CN116597472A (en) * 2023-05-05 2023-08-15 普曼(杭州)工业科技有限公司 Welding production line safety protection method based on visual AI
CN116645299A (en) * 2023-07-26 2023-08-25 中国人民解放军国防科技大学 Method and device for enhancing depth fake video data and computer equipment
CN116708918A (en) * 2022-05-12 2023-09-05 北京生数科技有限公司 Video face changing processing method, related device and storage medium
CN117974853A (en) * 2024-03-29 2024-05-03 成都工业学院 Self-adaptive switching generation method, system, terminal and medium for homologous micro-expression image

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110163814B (en) * 2019-04-16 2024-09-20 平安科技(深圳)有限公司 Method, device and computer equipment for modifying pictures based on face recognition
CN112785681B (en) * 2019-11-07 2024-03-08 杭州睿琪软件有限公司 Method and device for generating 3D image of pet
CN113469043B (en) * 2021-06-30 2024-10-18 南方科技大学 Method and device for detecting wearing state of helmet, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130100227A1 (en) * 2011-10-19 2013-04-25 Hon Hai Precision Industry Co., Ltd. Video communication system and method
CN105893984A (en) * 2016-04-29 2016-08-24 北京工业大学 Face projection method for facial makeup based on face features
CN107067429A (en) * 2017-03-17 2017-08-18 徐迪 Video editing system and method that face three-dimensional reconstruction and face based on deep learning are replaced
CN108550176A (en) * 2018-04-19 2018-09-18 咪咕动漫有限公司 Image processing method, equipment and storage medium
CN110163814A (en) * 2019-04-16 2019-08-23 平安科技(深圳)有限公司 The method, apparatus and computer equipment of modification picture based on recognition of face

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100940862B1 (en) * 2007-12-17 2010-02-09 한국전자통신연구원 Head motion tracking method for 3d facial model animation from a video stream
CN109151540B (en) * 2017-06-28 2021-11-09 武汉斗鱼网络科技有限公司 Interactive processing method and device for video image
CN109376518A (en) * 2018-10-18 2019-02-22 深圳壹账通智能科技有限公司 Privacy leakage method and relevant device are prevented based on recognition of face

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130100227A1 (en) * 2011-10-19 2013-04-25 Hon Hai Precision Industry Co., Ltd. Video communication system and method
CN105893984A (en) * 2016-04-29 2016-08-24 北京工业大学 Face projection method for facial makeup based on face features
CN107067429A (en) * 2017-03-17 2017-08-18 徐迪 Video editing system and method that face three-dimensional reconstruction and face based on deep learning are replaced
CN108550176A (en) * 2018-04-19 2018-09-18 咪咕动漫有限公司 Image processing method, equipment and storage medium
CN110163814A (en) * 2019-04-16 2019-08-23 平安科技(深圳)有限公司 The method, apparatus and computer equipment of modification picture based on recognition of face

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113486694A (en) * 2020-10-26 2021-10-08 青岛海信电子产业控股股份有限公司 Face image processing method and terminal equipment
WO2023019699A1 (en) * 2021-08-16 2023-02-23 武汉大学 High-angle facial recognition method and system based on 3d facial model
CN113780158A (en) * 2021-09-08 2021-12-10 宁波书写芯忆科技有限公司 Intelligent attention force detection method
CN113780158B (en) * 2021-09-08 2023-10-31 宁波书写芯忆科技有限公司 Intelligent concentration detection method
CN116708918A (en) * 2022-05-12 2023-09-05 北京生数科技有限公司 Video face changing processing method, related device and storage medium
CN116708918B (en) * 2022-05-12 2024-01-23 北京生数科技有限公司 Video face changing processing method, related device and storage medium
CN116597472A (en) * 2023-05-05 2023-08-15 普曼(杭州)工业科技有限公司 Welding production line safety protection method based on visual AI
CN116645299A (en) * 2023-07-26 2023-08-25 中国人民解放军国防科技大学 Method and device for enhancing depth fake video data and computer equipment
CN116645299B (en) * 2023-07-26 2023-10-10 中国人民解放军国防科技大学 Method and device for enhancing depth fake video data and computer equipment
CN117974853A (en) * 2024-03-29 2024-05-03 成都工业学院 Self-adaptive switching generation method, system, terminal and medium for homologous micro-expression image
CN117974853B (en) * 2024-03-29 2024-06-11 成都工业学院 Self-adaptive switching generation method, system, terminal and medium for homologous micro-expression image

Also Published As

Publication number Publication date
CN110163814B (en) 2024-09-20
CN110163814A (en) 2019-08-23

Similar Documents

Publication Publication Date Title
WO2020211347A1 (en) Facial recognition-based image modification method and apparatus, and computer device
US11270488B2 (en) Expression animation data processing method, computer device, and storage medium
WO2020103700A1 (en) Image recognition method based on micro facial expressions, apparatus and related device
JP4449723B2 (en) Image processing apparatus, image processing method, and program
Le et al. Live speech driven head-and-eye motion generators
US20230049533A1 (en) Image gaze correction method, apparatus, electronic device, computer-readable storage medium, and computer program product
WO2023109753A1 (en) Animation generation method and apparatus for virtual character, and storage medium and terminal
CN110148191B (en) Video virtual expression generation method and device and computer readable storage medium
WO2017177259A1 (en) System and method for processing photographic images
CN111652123B (en) Image processing and image synthesizing method, device and storage medium
US20220270324A1 (en) Systems and methods for generating a model of a character from one or more images
CN114202615A (en) Facial expression reconstruction method, device, equipment and storage medium
CN116437137B (en) Live broadcast processing method and device, electronic equipment and storage medium
CN114494556A (en) Special effect rendering method, device and equipment and storage medium
US20220103891A1 (en) Live broadcast interaction method and apparatus, live broadcast system and electronic device
WO2023185398A1 (en) Facial processing method and apparatus, and computer device and storage medium
JP7175529B1 (en) Display device and display method
CN115665361A (en) Video fusion method in virtual environment and online video conference communication method
KR101734212B1 (en) Facial expression training system
CN117011449A (en) Reconstruction method and device of three-dimensional face model, storage medium and electronic equipment
CN112132107A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
CN113706430A (en) Image processing method and device for image processing
CN113408452A (en) Expression redirection training method and device, electronic equipment and readable storage medium
KR20200134623A (en) Apparatus and Method for providing facial motion retargeting of 3 dimensional virtual character
KR20200071008A (en) 2d image processing method and device implementing the same

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19924984

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19924984

Country of ref document: EP

Kind code of ref document: A1