Virtual hairstyle replacement method, electronic device and storage medium
By identifying and cutting the user's hair area, filling the scalp area and combining it with the virtual hairstyle model image, the interference problem during virtual hairstyle trial is solved, and the user experience and display effect are improved.
Patent Information
- Application Number
- CN202110018056.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-07
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2041-01-07
AI Technical Summary
In the existing virtual hairstyle trial-on technology, the virtual hairstyle model image interferes with the user's hair area, affecting the user's trial-on experience.
By acquiring the user's head image, identifying and cutting the hair area, filling the scalp area, and generating the replaced user's head image in combination with the virtual hairstyle model image to avoid interference.
It improves the user's trial-on experience and the display effect of virtual hairstyle model images, avoiding interference between hair and virtual hairstyle.
Smart Images

Figure CN112734633B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method for replacing a virtual hairstyle, an electronic device and a storage medium. Background Art
[0002] With the continuous improvement of living standards, more and more people begin to pay attention to the aesthetics of their hairstyles. The main process of the current hairdressing industry is to let users choose the hairstyle they want based on pictures or videos of hairstyle models. However, it is difficult for users to determine the hairstyle that suits them based on pictures or videos alone, which results in the hairstyle not meeting the user's expectations after the styling is completed, affecting the user experience.
[0003] In the prior art, AR (Augmented Reality) technology is often used to merge images of various virtual hairstyles with the user's head, allowing the user to see the presentation effects of trying on different hairstyles. However, during the trial-wearing process, since the length of the hair in the virtual hairstyle is often shorter than the user's existing hair length, the user's existing hair will interfere with the virtual hairstyle, that is, at least part of the user's hair cannot be covered by the virtual hairstyle, thereby affecting the user's trial-wearing experience. Summary of the invention
[0004] In view of the shortcomings of the existing methods, the present application proposes a virtual hairstyle replacement method, electronic device and storage medium to solve the technical problem in the prior art that during the virtual hairstyle trial, the user's existing hair will interfere with the virtual hairstyle, affecting the user's trial experience.
[0005] In a first aspect, an embodiment of the present application provides a method for replacing a virtual hairstyle, comprising:
[0006] Acquire a first image containing a user head graphic;
[0007] identifying a hair region of the user from the first image;
[0008] After cutting out the hair region from the first image, a first image after hair cutting is obtained;
[0009] Filling the missing scalp area in the first image after hair cutting;
[0010] According to the virtual hairstyle model image and the first image after the scalp area is filled, the user's head image after the virtual hairstyle is replaced is determined.
[0011] In a second aspect, an embodiment of the present application provides an electronic device, including:
[0012] Processor; and
[0013] The memory is communicatively connected to the processor and configured to store machine-readable instructions. When the machine-readable instructions are executed by the processor, the method for replacing a virtual hairstyle as provided in the first aspect is implemented.
[0014] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, where the computer storage medium is used to store computer instructions. When the computer instructions are executed on an electronic device, the method for replacing a virtual hairstyle as provided in the first aspect is implemented.
[0015] The beneficial technical effects brought about by the technical solution provided by the embodiment of the present application include:
[0016] In the virtual hairstyle replacement method provided in the embodiment of the present application, the user's hair area is cut out from the first image containing the user's head portrait, and then the missing scalp area in the first image after the hair is cut is filled, and then the user's head image after the virtual hairstyle is replaced is determined based on the virtual hairstyle model image and the first image after the scalp area is filled, thereby avoiding interference between the virtual hairstyle model image and the user's hair area during the user's virtual hairstyle trial, thereby improving the user's trial experience. At the same time, by filling the missing scalp area in the first image after the hair is cut, it is avoided that the missing scalp area affects the user's visual perception, improves the display effect of the virtual hairstyle model image, and further improves the user's trial experience.
[0017] Additional aspects and advantages of the present application will be partially given in the following description, which will become apparent from the following description, or will be understood through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0019] Figure 1 A schematic diagram of a flow chart of a method for replacing a virtual hairstyle provided in an embodiment of the present application;
[0020] Figure 2a-2f A schematic diagram of the state of the first image of each process in the method for replacing a virtual hairstyle provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of a process of identifying a user's hair area from a first image provided in an embodiment of the present application;
[0022] Figure 4 A schematic flow chart of a method for determining a first hair partition in a face detection area based on face pixels in the face detection area and background pixels outside the face detection area provided in an embodiment of the present application;
[0023] Figure 5 A schematic diagram of the distribution of key facial points in a face detection area in a first image in a method for replacing a virtual hairstyle provided in an embodiment of the present application;
[0024] Figure 6 A schematic diagram of the structure of a virtual hairstyle replacement device provided in an embodiment of the present application;
[0025] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0026] Description of reference numerals:
[0027] 110 - face detection area; 120 - background area; 111 - first hairstyle outline 112 - second hairstyle outline;
[0028] 60-Virtual hairstyle replacement device;
[0029] 601-acquisition module; 602-recognition module; 603-cutting module; 604-filling module; 605-superposition module;
[0030] 70-Electronic equipment;
[0031] 701 - processor; 702 - memory; 703 - bus; 704 - transceiver; 705 - input unit; 706 - output unit. DETAILED DESCRIPTION
[0032] The present application is described in detail below, and examples of embodiments of the present application are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar components or components with the same or similar functions. In addition, if the detailed description of the known technology is unnecessary for the features of the present application shown, it will be omitted. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0033] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0034] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0035] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments.
[0036] The present application embodiment provides a method for replacing a virtual hairstyle, and the flowchart of the method is as follows: Figure 1 As shown, the method includes steps S101-S105:
[0037] S101, obtaining a first image including a user head graphic.
[0038] Optionally, the camera can be used to obtain Figure 2a The first image containing the user's head graphic shown can also be obtained from a memory by obtaining a first image containing the user's head graphic stored in advance.
[0039] Optionally, before acquiring the first image containing the user's head graphic through the camera, the camera may first acquire the environment background where the user is located, or first acquire the environment background where the user is located and then acquire the first image containing the user's head graphic. In this way, the first image containing the user's head graphic and the environment background not containing the user are acquired separately, which can improve the processing efficiency of subsequent steps.
[0040] S102: Identify a hair area of the user from the first image.
[0041] After the above step S102, the hair area corresponding to the user's current hairstyle in the first image can be determined to facilitate the subsequent steps. The method of identifying the user's hair area from the first image in step S102 will be described in detail later and will not be repeated here.
[0042] S103, cutting off the hair area from the first image to obtain a first image after the hair is cut off.
[0043] After the above step S103, the following is obtained: Figure 2d Shown is the first image after the hair cutting.
[0044] S104, filling the missing scalp area in the first image after the hair is cut.
[0045] After the above step S104, the following is obtained: Figure 2e The first image of the missing scalp area is filled. The method of step S104 will be described in detail later and will not be repeated here.
[0046] S105, determining the user head image after the virtual hairstyle is replaced according to the virtual hairstyle model image and the first image after the scalp area is filled.
[0047] Optionally, the method for determining the user head image after replacing the virtual hairstyle according to the virtual hairstyle model image and the first image after the scalp area is filled in the above step S105 includes: superimposing the virtual hairstyle model image on Figure 2e At the designed position in the first image after the scalp area is filled, the following is obtained: Figure 2f The user's head image after replacing the virtual hairstyle is shown.
[0048] In the method for replacing a virtual hairstyle provided in an embodiment of the present application, the hair area of the user is cut out from the first image including the user's avatar, and then the missing scalp area in the first image after the hair is cut is filled, and then the user's head image after the virtual hairstyle is replaced is determined based on the virtual hairstyle model image and the first image after the scalp area is filled, thereby avoiding interference between the virtual hairstyle model image and the user's hair area during the user's virtual hairstyle trial-wearing process, thereby improving the user's trial-wearing experience.
[0049] At the same time, by filling the missing scalp area in the first image after hair cutting, the missing scalp area is avoided from affecting the user's visual perception, the display effect of the virtual hairstyle model image is improved, and the user's trial wearing experience is further improved.
[0050] In one embodiment of the present application, in the above step S102, a flow chart of a method for identifying a user's hair area from a first image is as follows: Figure 3 As shown, the method includes:
[0051] S1021: Determine a user's face detection area 110 from the first image.
[0052] Optionally, the method for determining the user's face detection area 110 from the first image in the above step S1021 includes: identifying a plurality of face key points from the first image; determining the face detection area 110 according to the plurality of face key points and designing an expansion strategy. Figure 2bThe face detection area 110 is shown. In the embodiment of the present application, according to the existing face recognition technology, 72 key points of the user's face are identified from the first image, and then the face detection area 110 of the user in the first image is determined.
[0053] S1022: Determine a first hair partition in the face detection area 110 based on face pixels in the face detection area 110 and background pixels outside the face detection area 110.
[0054] The method for determining the first hair partition in the face detection area 110 based on the face pixels in the face detection area 110 and the background pixels outside the face detection area 110 in the above step S1022 will be described in detail later and will not be repeated here.
[0055] S1023: Determine a hair area based on the hair pixels in the first hair partition.
[0056] The method for determining the hair region based on the hair pixels in the first hair partition in the above step S1023 includes: selecting the pixels in the face detection area 110 that meet the hair features as seed points; starting from the seed points, gradually expanding outward to find multiple similar pixels to obtain the hair region; the hair features include at least one of the following: hair color, reflective features, and appearance characteristics. Based on the hair pixels in the first hair partition, a second hair partition is determined in the background area 120, and the hair region is determined based on the first hair partition and the second hair partition.
[0057] In one embodiment of the present application, a flowchart of a method for determining a first hair partition in the face detection area 110 based on face pixels in the face detection area 110 and background pixels outside the face detection area 110 in the above step S1022 is as follows: Figure 4 As shown, the method includes:
[0058] S10221, select the pixel point that matches the facial skin color in the face detection area 110 as the seed point; take the seed point as the starting point, expand outwards successively to find multiple similar pixel points, and obtain the face area.
[0059] Optionally, in the above step S10221, a pixel point in the face detection area 110 that matches the facial skin color is selected as a seed point; and a method of using the seed point as a starting point and successively expanding outward to find a plurality of similar pixel points to obtain a face area includes:
[0060] Scan each pixel of the face detection area 110 in the first image, determine the pixel points that meet the first similarity condition from the pixel points adjacent to the seed point, and classify them into the face area; the first similarity condition is that the similarity between the adjacent pixel points and the corresponding seed point exceeds the designed threshold; take the pixel point that is most recently classified into the face area as the latest seed point, and continue to expand outward to search for the pixel point that meets the first similarity condition until there is no pixel point that meets the first similarity condition.
[0061] It should be noted that in the embodiment of the present application, the designed threshold is the designed pixel grayscale value.
[0062] S10222: Determine the contour of the face region as the first hairstyle contour line 111 of the first hair partition.
[0063] Alternatively, if Figure 2c As shown, the determined contour of the face area is used as the first hairstyle contour line 111 of the first hair partition in the face detection area 110 .
[0064] S10223, select pixel points outside the face detection area 110 that match the background color as seed points; take the seed points as the starting point, expand outwards successively to find multiple similar pixel points, and obtain the background area 120.
[0065] Optionally, based on the environmental background excluding the user captured by the camera, environmental background pixels are extracted as background color pixels in the first image, so that the background area 120 can be obtained in the first image based on the background color pixels.
[0066] S10224 , determining a second hairstyle contour line 112 of the first hair partition according to the background area 120 and the face detection area 110 .
[0067] Optionally, the method for determining the second hairstyle contour line 112 of the first hair partition according to the background area and the face detection area in the above step S10224 includes: determining whether each pixel in the inner contour line of the background area 120 is located within the frame of the face detection area 110; when a pixel is located within the frame of the face detection area 110, attributing the pixel to the second hairstyle contour line 112 of the first hair partition; when a pixel is not located within the frame of the face detection area 110, attributing the pixels of the frame corresponding to the pixel to the second hairstyle contour line 112 of the first hair partition, thereby obtaining the following: Figure 2c A second hairstyle outline 112 is shown.
[0068] In the embodiment of the present application, in order to distinguish the first hairstyle outline 111 from the second hairstyle outline 112, as shown in FIG. Figure 2cAs shown, the first hairstyle outline 111 is represented by a thin thick line, and the second hairstyle outline 112 is represented by a thick black line.
[0069] S10225: Determine a first hair partition according to the first hairstyle outline and the second hairstyle outline.
[0070] Alternatively, if Figure 2c As shown, the area enclosed by the first hairstyle contour line 111 and the second hairstyle contour line 112 is the first hair partition.
[0071] Since the face detection area 110 includes some pixels having the same color as the background area 120, the second hairstyle contour line 112 of the first hair partition is determined by combining the background area 120 and the face detection area 110, so that the detection accuracy of the first hair partition in the face detection area 110 can be improved, thereby improving the cutting accuracy of the hair area, thereby avoiding interference between the virtual hairstyle model image and the user's hair area during the user's virtual hairstyle trial, and improving the user's trial experience.
[0072] In one embodiment of the present application, the method for filling the missing scalp area in the first image after hair cutting in the above step S104 includes: determining at least two edge points based on multiple facial key points of the first image; determining a curve representing the scalp in the facial area based on a line connecting the facial key points between the at least two edge points, and determining the missing scalp area in the first image based on the curve; and coloring the missing scalp area based on the skin color of the remaining part of the facial area in the first image after hair cutting.
[0073] Alternatively, if Figure 5 As shown, there are 72 key face points of the face detection area 110 in the first image. In the embodiment of the present application, the positions of edge point No. 1 and edge point No. 13 are located at the temples of the user face detection area 110. Therefore, edge point No. 1 is selected as the starting point and edge point No. 13 is selected as the end point. The line connecting edge point No. 1, edge point No. 2, edge point No. 3, edge point No. 4, edge point No. 5, edge point No. 6, edge point No. 7, edge point No. 8, edge point No. 9, edge point No. 10, edge point No. 11, edge point No. 12 and edge point No. 13 is connected to determine the curve representing the scalp of the face area; the curve representing the scalp is the lower curve of the face area, that is, the face area curve below the temple height. According to the lower curve and formula (1), the upper curve of the face area is determined, thereby determining the missing scalp area in the first image; then, according to the skin color of the remaining part of the face area in the first image after the hair is cut, the missing scalp area is colored so that the color of the missing scalp area is adapted to the skin color of the face area. Figure 2c The bold line in the figure represents the upper curve of the face area.
[0074]
[0075] Among them, x is the coordinate points of the curve representing the scalp; α is the radian coefficient, optionally, the value is 1.8 in the embodiment of the present application; y is the coordinate points of the upper curve.
[0076] In one embodiment of the present application, since part of the user's hair is located in the background area 120, and part of the hair may fall on the clothes worn by the user, after the hair area is cut off, the corresponding background area 120 and the clothing area where the clothes are located will be missing. After the virtual hairstyle model image is superimposed on the first image after the scalp area is filled, the virtual hairstyle model image may not cover all the missing parts of the background area 120 and the missing parts of the clothing area. Therefore, after determining the user's head image after replacing the virtual hairstyle according to the virtual hairstyle model image and the first image after the scalp area is filled in the above step S105, it also includes:
[0077] Determine the missing background area in the first image after the scalp area is filled; fill the missing background area according to the background image in the first image; and / or determine the missing clothing area in the first image after the scalp area is filled, and fill the missing clothing area according to the clothing image in the first image.
[0078] In one embodiment of the present application, in order to improve the recognition speed and accuracy of the hair area, in the embodiment of the present application, the method of obtaining the first image containing the user head graphic in the above step S101 includes:
[0079] Displays hair bundling prompt information including hair bundling content to remind the user.
[0080] Optionally, a hair-tying reminder message is sent to the user through sound, light or other signal methods to remind the user to tie up their hair to prevent the user's hair from falling on the user's clothes and to prevent the hair from covering the user's ears, cheeks and other facial areas.
[0081] When the hair bundling feedback information is received in response to the hair bundling prompt information, a first image including a user head graphic is acquired.
[0082] Optionally, according to the reminder of the hair-binding prompt information, after the user ties up his hair, he can send hair-binding feedback information through the touch display screen, and when the hair-binding feedback information is received, the camera can obtain the following information: Figure 2a A first image is shown including a graphic of a user's head.
[0083] In one embodiment of the present application, in order to reduce the influence of pixels of other colors in the background area 120 on the accuracy of hair area recognition and improve the speed of hair area recognition, in the embodiment of the present application, before obtaining the first image containing the user head graphic in the above step S101, the following is further included:
[0084] The display includes a background change prompt for placing a solid color background baffle.
[0085] Optionally, a background change prompt is sent to the user through sound, light or other signal methods.
[0086] When background change feedback information for background change prompt information is received, an environment image including a monochrome background baffle graphic is acquired.
[0087] Optionally, after the user replaces the monochrome background baffle, the user may send background change feedback information through the touch display screen, and when the background change feedback information is received, the environment image containing the monochrome background baffle graphic is acquired through the camera.
[0088] Furthermore, after determining the user head image after replacing the virtual hairstyle according to the virtual hairstyle model image and the first image after the scalp area is filled in the above step S105, the method further includes:
[0089] Determine the missing background area in the first image after the scalp area is filled; fill the missing background area according to the environment image. Here, the environment image is a monochrome background baffle pattern, and the missing background area in the first image after the scalp area is filled can be supplemented by adding pixels with the same color as the monochrome background baffle.
[0090] Optionally, the method for determining the user head image after replacing the virtual hairstyle according to the virtual hairstyle model image and the first image after the scalp area is padded in the above step S105 includes:
[0091] In such Figure 5 Among the 72 facial key points in the face detection area 110 in the first image shown in FIG. 1 , 3 facial key points are selected as positioning points of the virtual hairstyle model image. In the embodiment of the present application, edge point No. 1, edge point No. 7 and edge point No. 13 are selected as positioning points. By adjusting the distance between the center point of the virtual hairstyle model image and the above positioning points, the position to be superimposed of the virtual hairstyle model image in the first image after the scalp area is filled is determined; by superimposing the virtual hairstyle model image on the first image after the scalp area is filled, the virtual hairstyle model image is superimposed on the face detection area 110 shown in FIG. 1 . Figure 2e At the position to be superimposed in the first image after the scalp area is filled, the following is obtained: Figure 2f The user's head image after replacing the virtual hairstyle is shown.
[0092] Based on the same inventive concept, the embodiment of the present application provides a virtual hairstyle replacement device 60. The structural framework diagram of the virtual hairstyle replacement device is shown in FIG. Figure 6 As shown, including:
[0093] An acquisition module 601 is used to acquire a first image including a user head graphic;
[0094] The recognition module 602 is used to recognize the hair area of the user from the first image;
[0095] A cutting module 603 is used to cut out the hair area from the first image to obtain a first image after the hair is cut;
[0096] A filling module 604 is used to fill in the missing scalp area in the first image after the hair is cut;
[0097] The superposition module 605 is used to determine the user's head image after the virtual hairstyle is replaced according to the virtual hairstyle model image and the first image after the scalp area is filled.
[0098] The virtual hairstyle replacement device 60 of this embodiment can execute any virtual hairstyle replacement method provided in the embodiments of the present application, and the implementation principles are similar and will not be repeated here.
[0099] Based on the same inventive concept, the embodiment of the present application provides an electronic device 70, such as Figure 7 As shown, the electronic device 70 includes: a processor 701; and
[0100] The memory 702 is in communication with the processor 701 and is configured to store machine-readable instructions. When the machine-readable instructions are executed by the processor 701, various optional implementations of the virtual hairstyle replacement method provided in the embodiment of the present application are implemented.
[0101] Those skilled in the art will appreciate that the electronic equipment provided by the embodiments of the present application can be specially designed and manufactured for the desired purpose, or can also include known devices in a general-purpose computer. These devices have computer programs stored therein, which are selectively activated or reconstructed. Such computer programs can be stored in a device (e.g., computer) readable medium or in a medium suitable for storing electronic instructions and coupled to any type of bus respectively.
[0102] Optionally, the processor 701 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 701 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0103] The processor 701 and the memory 702 are connected via a bus 703 to achieve communication connection. The bus 703 may include a path to transmit information between the above components. The bus 703 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 703 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0104] The memory 702 can be a ROM (Read-Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (random access memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read-Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.
[0105] Optionally, the electronic device 70 may further include a transceiver 704. The transceiver may be used for receiving and sending signals. The transceiver 704 may allow the electronic device 70 to communicate with other devices wirelessly or by wire to exchange data. It should be noted that in actual applications, the transceiver is not limited to one. For example, in an embodiment of the present application, the transceiver 704 may include a Bluetooth transceiver, and the user may send the first image containing the user's head graphic to the electronic device 70 for processing via the Bluetooth transceiver.
[0106] Optionally, the electronic device 70 may further include an input unit 705. The input unit 705 may be used to receive input digital, character, image and / or sound information, or to generate key signal input related to user settings and function control of the electronic device. The input unit 705 may include, but is not limited to, one or more of a touch screen, a physical keyboard, a function key (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, a camera, a pickup, etc. In the embodiment of the present application, the input unit 705 is a camera, and the first image containing the user head graphic can be obtained through the camera.
[0107] Optionally, the electronic device 70 may further include an output unit 706. The output unit 706 may be used to output or display information processed by the processor 701. The output unit may include but is not limited to one or more of a display device, a speaker, a vibration device, etc. In the embodiment of the present application, the output unit 706 includes a display device, and the user's head image after the virtual hairstyle is replaced can be displayed through the display device.
[0108] It should be noted that Figure 7 The schematic diagram of the computing system that can be used to implement various embodiments of the present application is only schematically shown. Those skilled in the art can understand that the electronic device 70 can be implemented by introducing additional computing devices.
[0109] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which is used to store computer instructions. When the computer instructions are executed on an electronic device, the virtual hairstyle replacement method provided in each embodiment of the present application is implemented.
[0110] The computer-readable storage medium includes, but is not limited to, any type of disk (including floppy disk, hard disk, optical disk, CD-ROM and magneto-optical disk), ROM, RAM, EPROM (Erasable Programmable Read-Only Memory), EEPROM, flash memory, magnetic card or optical card. In other words, the readable storage medium includes any medium that can store or transmit information in a readable form by a device (e.g., a computer).
[0111] The computer-readable storage medium provided in the embodiment of the present application has the same inventive concept as the embodiments described above. The contents not shown in detail in the computer-readable storage medium can be referred to the embodiments described above and will not be repeated here.
[0112] By applying the embodiments of the present application, at least the following beneficial effects can be achieved:
[0113] In the embodiment of the present application, the hair area of the user is cut out from the first image including the user's portrait, and then the missing scalp area in the first image after the hair is cut is filled, and then the user's head image after the virtual hairstyle is replaced is determined based on the virtual hairstyle model image and the first image after the scalp area is filled, thereby avoiding interference between the virtual hairstyle model image and the user's hair area during the user's virtual hairstyle trial, thereby improving the user's trial experience.
[0114] At the same time, by filling the missing scalp area in the first image after hair cutting, the missing scalp area is avoided from affecting the user's visual perception, the display effect of the virtual hairstyle model image is improved, and the user's trial wearing experience is further improved.
[0115] Those skilled in the art will appreciate that the various operations, methods, steps, measures, and schemes in the processes discussed in this application may be alternated, altered, combined, or deleted. Further, other steps, measures, and schemes in the various operations, methods, and processes discussed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted. Further, the steps, measures, and schemes in the prior art that are similar to those disclosed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted.
[0116] The terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more.
[0117] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0118] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for replacing a virtual hairstyle, characterized in that: include: Acquire a first image containing a user head graphic; identifying a hair region of the user from the first image; After cutting out the hair region from the first image, a first image after hair cutting is obtained; Filling the missing scalp area in the first image after the hair cutting; Determining, according to the virtual hairstyle model image and the first image after the scalp area is filled, the user's head image after the virtual hairstyle is replaced; The step of identifying the hair area of the user from the first image includes: determining a face detection area of the user from the first image; Determining a first hair partition in the face detection area based on face pixels in the face detection area and background pixels outside the face detection area; Determining the hair area based on the hair pixels in the first hair partition; The step of determining a first hair partition in the face detection area based on face pixels in the face detection area and background pixels outside the face detection area comprises: Selecting a pixel point in the face detection area that matches the facial skin color as a seed point; starting from the seed point, gradually expanding outward to find multiple similar pixel points to obtain a face area; Determining the outline of the human face region as a first hairstyle outline of the first hair partition; Selecting a pixel point outside the face detection area that matches the background color as a seed point; starting from the seed point, gradually expanding outward to find multiple similar pixel points to obtain a background area; A second hairstyle contour line of the first hair partition is determined according to the background area and the face detection area.
2. The method for replacing a virtual hairstyle according to claim 1, characterized in that: The step of taking the seed point as the starting point and expanding outwards to find multiple similar pixel points to obtain the face region includes: Determine, from each pixel point adjacent to the seed point, a pixel point that satisfies a first similarity condition and classifies the pixel point into a face region; the first similarity condition is that the similarity between the adjacent pixel point and the corresponding seed point exceeds a designed threshold; The pixel point most recently assigned to the face area is used as the latest seed point, and the pixel point satisfying the first similarity condition is continuously expanded outwards until there is no pixel point satisfying the first similarity condition.
3. The method for replacing a virtual hairstyle according to claim 1, characterized in that: The step of determining the second hairstyle contour line of the first hair partition according to the background area and the face detection area comprises: Determine whether each pixel in the inner contour line of the background area is located within the border of the face detection area; When one of the pixels is located within the border of the face detection area, attributing one of the pixels to the second hairstyle contour line of the first hair partition; When one of the pixels is not located within the border of the face detection area, the pixels of the border corresponding to the one of the pixels are attributed to the second hairstyle contour line of the first hair partition.
4. The method for replacing a virtual hairstyle according to claim 1, characterized in that: The determining the hair area based on the hair pixels in the first hair partition includes: Selecting a pixel point in the face detection area that meets the hair feature as a seed point; starting from the seed point, gradually expanding outward to find multiple similar pixel points to obtain the hair area; The hair characteristics include at least one of the following: hair color, reflective characteristics, and appearance characteristics.
5. The method for replacing a virtual hairstyle according to claim 1, characterized in that: The step of filling the missing scalp area in the first image after the hair cutting comprises: Determining at least two edge points according to the plurality of facial key points of the first image; Determine a curve representing the scalp of the face region according to a line connecting the key face points between at least two of the edge points, and determine the missing scalp region in the first image according to the curve; The missing scalp region is colored according to the skin color of the remaining portion of the face region in the first image after the hair is cut.
6. The method for replacing a virtual hairstyle according to claim 1, characterized in that: The step of acquiring a first image containing a user head graphic comprises: Displaying hair-binding prompt information including content to remind the user to bind hair; When the hair bundling feedback information for the hair bundling prompt information is received, the first image including the user head graphic is acquired.
7. The method for replacing a virtual hairstyle according to claim 6, characterized in that: Before acquiring the first image containing the user head graphic, the method further includes: Displaying background change prompt information including placing a single-color background baffle; When background change feedback information for the background change prompt information is received, an environment image including the monochrome background baffle pattern is acquired; And, after determining the user head image after replacing the virtual hairstyle according to the virtual hairstyle model image and the first image after the scalp area is filled, the method further includes: Determining a missing background area in the first image after the scalp area is padded; The missing background area is completed according to the environment image.
8. An electronic device, characterized in that: include: processor; as well as A memory is communicatively connected to the processor and configured to store machine-readable instructions, wherein when the machine-readable instructions are executed by the processor, the method for replacing a virtual hairstyle according to any one of claims 1 to 7 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store computer instructions. When the computer instructions are executed on an electronic device, the method for replacing a virtual hairstyle as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Hair modeling and portrait editing method based on single image
CN102800129A