A hair segmentation method and system based on convolutional neural network

Through the hair segmentation method based on convolutional neural network, combined with face detection and BiSeNet network, k-means clustering and canny operator are used to process binary images, which solves the problem of low recognition accuracy when the background color is similar to the hair color. Achieving high accuracy and efficiency in automatically identifying hair areas.

CN114187309BActive Publication Date: 2024-10-15SHENZHEN MAXVISION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210025451.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-11
Publication Date
2024-10-15
Estimated Expiration
2042-01-11

AI Technical Summary

Technical Problem

The existing technology cannot accurately identify the hair area when the background color is similar to the hair color, resulting in low recognition accuracy and unable to adapt to widespread promotion and popularization.

Method used

The hair segmentation method based on convolutional neural network is used, combined with the face detection algorithm RetinaFace to determine the hair area, the BiSeNet dual-channel segmentation network is used for hair segmentation, and the binary image is processed through k-means clustering and canny operator to achieve the hair area accurate identification.

Benefits of technology

It improves the recognition accuracy when the background color is similar to the hair color, realizes the ability to automatically identify the hair area, solves the problem of large face deflection angle and hair recognition on the back, and has high recognition accuracy and processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114187309B_ABST
    Figure CN114187309B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image processing technology, and specifically to a method and system for hair segmentation based on a convolutional neural network. The method comprises: a step of obtaining a video stream image: obtaining a video stream from a camera, dividing the video stream into frames, and forming images one by one, so as to facilitate subsequent processing; a step of determining a face region: using a face detection model to detect the face position and determine the face region. The beneficial effects of the present invention are as follows: through a new convolutional neural network model (a hair full convolutional network model), combined with the hair position information, the hair frequency information, and the hair color information in the image, the hair region of the image can be accurately identified, the face is detected by the face detection algorithm RetinaFace, the approximate position of the hair region is determined, and interference from other similar hair targets in the background is prevented. The BiSeNet dual-channel segmentation network is used to realize hair segmentation in real time, and automatic recognition can be achieved without manual participation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to a hair segmentation method and system based on a convolutional neural network. Background Art

[0002] Image segmentation is an important image processing technology. With the continuous development of artificial intelligence and computer vision, image segmentation has received widespread attention in theoretical research and practical applications. Nowadays, image segmentation is mainly used for auxiliary positioning and auxiliary recognition. A common application is to use segmentation technology to determine or exclude targets in certain areas. Currently, the most widely used applications include skin whitening, hairstyle and color change in face beautification, etc.

[0003] After searching, Chinese patent No. CN106611160B discloses a method and device for image hair recognition based on a convolutional neural network, wherein the method includes: collecting atlases; marking each picture in the atlas; preprocessing each picture in the atlas; detecting the head position of the portrait in each picture in the atlas, and obtaining the head position information corresponding to the training atlas and the head position information corresponding to the test atlas; constructing a hair full convolution network based on the full convolution network; training the hair full convolution network; comparing the output result with the hair area occlusion test atlas to obtain the evaluation result of the hair full convolution network; inputting the picture for which the hair occlusion map is to be obtained into the hair full convolution network to obtain the occlusion map of the hair area of ​​the image.

[0004] The existing hair segmentation method cannot accurately identify the hair area when the background color is similar to the hair color, which is not conducive to wide promotion and popularization. Summary of the invention

[0005] The object of the present invention is to provide a hair segmentation method based on a convolutional neural network to solve the problem of improving recognition accuracy when the background color is similar to the hair color proposed in the above background technology.

[0006] The technical solution of the present invention is: a hair segmentation method based on a convolutional neural network, comprising the following steps:

[0007] Steps for obtaining video stream images: obtain and process the video stream into frames;

[0008] Steps for determining the face area: using the face detection model to detect and determine the face area;

[0009] Image processing steps: crop the face image based on the face area, input the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; Binary image obtaining steps: use the Canny operator to find the edge of the face image and the binary image to obtain a hair edge binary image;

[0010] Step of expanding and increasing the edge area: expanding and increasing the edge area toward the periphery according to the pixel position of the edge binary image;

[0011] Steps for k-means clustering: Use the color value of the extended edge area of ​​the face image as a feature for k-means clustering;

[0012] Merge result step: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area.

[0013] The step of determining the face area comprises:

[0014] Determine the preliminary face region sub-step: first determine the preliminary face region using the face detection algorithm RetinaFace;

[0015] Face detection sub-step: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively;

[0016] The image processing step comprises:

[0017] Training sub-step: Train BiSeNet using face images and binary images with hair areas annotated;

[0018] Steps to generate a binary image: Input a face image to BiSeNet, complete inference, and generate a binary image of the same size as the input face image;

[0019] The steps to crop a face image including hair are as follows:

[0020] Cropping sub-step: Cropping the face according to the face rectangular frame bbox obtained in the face detection step. Since it is a hair segmentation task, the cropped face must completely contain the hair area, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are ;

[0021] The step of combining the results comprises:

[0022] Merge result sub-step: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is non-hair, set the pixel value to 0; merge the results.

[0023] Furthermore, in the training sub-step, the steps of labeling the corresponding pictures are as follows:

[0024] Image annotation sub-step: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is used as the background, which is a negative sample.

[0025] Furthermore, in the training sub-step, the steps of training BiSeNet corresponding to the binary image are as follows:

[0026] Training image enhancement transition sub-step: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to ; During training, we first randomly select the value S from 0.1 to 0.5 evenly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ;

[0027] Horizontal flip sub-step: swap the image and the corresponding binary labeled pixels left and right;

[0028] Color jitter sub-step: adjust and enhance the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

[0029] Furthermore, in the step of generating a binary image, the step of inputting a face image into BiSeNet includes:

[0030] Binary image sub-step: During the inference process with BiSeNet, there is no need to enhance the input face image, and there is no need to calculate gradients and losses; resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

[0031] Furthermore, the step of expanding and increasing the edge area includes:

[0032] Sub-steps for obtaining the edge binary map: Assume the coordinates of point p to be (x, y), and generate the edge binary map according to the 24-domain expansion of point p.

[0033] Furthermore, the k-means clustering step includes:

[0034] Image overlay sub-step: Overlay the binary image after edge expansion and the original face image, take the RGB pixel values ​​of the original image where the white area is located as the feature of k-means clustering, set category k=2, because the hair color and skin color are relatively concentrated, the clustering will be very accurate.

[0035] A hair segmentation system based on convolutional neural network, including the following modules:

[0036] Video stream image acquisition module: acquire and process the video stream into frames;

[0037] Face region determination module: uses face detection model to detect and determine face region;

[0038] Image processing module: crop the face image based on the face area, input it into the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; binary image module: use the canny operator to find the edge of the face image and the binary image to obtain a binary image of the hair edge;

[0039] Expand and increase edge area module: expand and increase edge area to the periphery according to the pixel position of the edge binary image;

[0040] Build a k-means clustering module: Use the color value of the extended edge area of ​​the face image as a feature to build a k-means clustering module.

[0041] Merge result module: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area.

[0042] The face area determination module includes:

[0043] Determine the preliminary face region submodule: Use the face detection algorithm RetinaFace to first determine the preliminary face region;

[0044] Face detection submodule: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively.

[0045] The image processing module comprises:

[0046] Training submodule: Use face images and binary images with hair areas marked to train BiSeNet;

[0047] Binarized image generation module: Input a face image into BiSeNet, complete inference, and generate a binary image of the same size as the input face image;

[0048] The module corresponding to cropping face images containing hair is as follows:

[0049] Cropping submodule: Cropping the face according to the face rectangular frame bbox obtained by the face detection module. Since it is a hair segmentation task, the cropped face must completely contain the hair area, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are ;

[0050] The merging result module includes:

[0051] Merge result submodule: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is non-hair, set the pixel value to 0; merge the results.

[0052] Furthermore, in the training submodule, the module corresponding to the image annotation is as follows:

[0053] Image annotation submodule: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is used as the background, which is a negative sample.

[0054] Furthermore, in the training submodule, the module for training BiSeNet corresponding to binary images is as follows:

[0055] Training image enhancement transition submodule: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to ; During training, we first randomly select the value S from 0.1 to 0.5 evenly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ;

[0056] Horizontal flip submodule: swap the image and the corresponding binary labeled pixels left and right;

[0057] Color jitter submodule: adjusts and enhances the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

[0058] Furthermore, in the binary image generation module, the module for inputting a face image into BiSeNet includes:

[0059] Binary image submodule: During the inference process of BiSeNet, there is no need to enhance the input face image, calculate the gradient and loss; resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

[0060] Furthermore, the expansion and addition of the edge area module includes:

[0061] Obtain the edge binary map submodule: Assume the coordinates of point p to be (x, y), and generate an edge binary map based on the 24-domain expansion of point p.

[0062] Furthermore, the k-means clustering module includes:

[0063] Image overlay submodule: The binary image after edge expansion and the original face image are overlaid. The RGB pixel values ​​of the original image where the white area is located are taken as the features of k-means clustering. The category k is set to 2. Since the hair color and skin color are relatively concentrated, the clustering will be very accurate.

[0064] The present invention provides a hair segmentation method and system based on a convolutional neural network through improvement, which has the following improvements and advantages compared with the prior art:

[0065] (1) The present invention uses a new convolutional neural network model (a hair full convolutional network model) and combines the hair position information, hair frequency information and hair color information in the image to accurately identify the hair area of ​​the image. The face is detected by the face detection algorithm RetinaFace to determine the approximate location of the hair area and prevent interference from other similar hair targets in the background.

[0066] (2) The present invention utilizes the BiSeNet dual-channel segmentation network to achieve real-time hair segmentation, which can realize automatic recognition without human intervention.

[0067] (3) The hair segmentation training method of the present invention regards the pixels as binary classification, performs multi-scale, horizontal flipping, color dithering and other methods to enhance the image, which can solve the problem that the hair area cannot be accurately identified when the background color is similar to the hair color, and cannot identify the face with a large deflection angle and the back of the face in the prior art; it has high recognition accuracy.

[0068] (4) After the present invention obtains the hair segmentation binary image through BiSeNet reasoning, the canny operator is used to find the edge of the binary image. Using the canny operator to find the edge of the binary image can be faster and more accurate, which greatly improves the processing efficiency and processing effect of the binary image. BRIEF DESCRIPTION OF THE DRAWINGS

[0069] The present invention will be further explained below in conjunction with the accompanying drawings and Examples:

[0070] Figure 1 It is a structural schematic diagram of the hair segmentation process of the present invention;

[0071] Figure 2 is a schematic diagram of an example structure of training BiSeNet annotation of the present invention;

[0072] Figure 3 This is a schematic diagram of using the canny operator to obtain the edge structure of the BiSeNet segmentation result of the present invention;

[0073] Figure 4 is a schematic diagram of the neighborhood structure of point p of the present invention;

[0074] Figure 5 It is a schematic diagram of the neighborhood extension edge area structure of the present invention;

[0075] Figure 6 It is a schematic diagram of the structure of the superposition effect of the extended edge map and the original face image of the present invention;

[0076] Figure 7 It is a schematic diagram of the structure of the segmentation result after merging of the present invention. DETAILED DESCRIPTION

[0077] The following will be combined with the attached Figures 1 to 7 The present invention is described in detail, and the technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0078] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.

[0079] The present invention provides a hair segmentation method based on convolutional neural network, such as Figure 1-7 As shown, the following steps are included:

[0080] Steps for obtaining video stream images: obtain and process the video stream into frames;

[0081] Steps for determining the face area: using the face detection model to detect and determine the face area;

[0082] Image processing steps: crop the face image based on the face area, input the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; obtain the binary image step: use the canny operator to find the edge of the face image and the binary image, and obtain the hair edge binary image as shown in the figure. Figure 3 As shown;

[0083] Step of expanding and increasing the edge area: expanding and increasing the edge area toward the periphery according to the pixel position of the edge binary image;

[0084] Steps for k-means clustering: Use the color value of the extended edge area of ​​the face image as a feature for k-means clustering;

[0085] Merge result step: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area.

[0086] Furthermore, the step of determining the face area includes:

[0087] Determine the preliminary face region sub-step: first determine the preliminary face region using the face detection algorithm RetinaFace;

[0088] Face detection sub-step: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively.

[0089] Furthermore, the image processing step includes:

[0090] Training sub-step: Train BiSeNet using face images and binary images with hair areas annotated;

[0091] Steps to generate a binary image: Input a face image to BiSeNet, complete inference, and generate a binary image of the same size as the input face image;

[0092] The steps to crop a face image including hair are as follows:

[0093] Cropping sub-step: Cropping the face according to the face rectangular frame bbox obtained in the face detection step. Since it is a hair segmentation task, the cropped face must completely contain the hair area, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are .

[0094] Furthermore, in the training sub-step, the steps of labeling the corresponding pictures are as follows:

[0095] Image annotation sub-step: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is the background, which is a negative sample. Figure 2 shown.

[0096] Furthermore, in the training sub-step, the steps of training BiSeNet corresponding to the binary image are as follows:

[0097] Training image enhancement transition sub-step: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to ; During training, we first randomly select the value S from 0.1 to 0.5 evenly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ;

[0098] Horizontal flip sub-step: swap the image and the corresponding binary labeled pixels left and right;

[0099] Color jitter sub-step: adjust and enhance the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

[0100] Furthermore, in the step of generating a binary image, the step of inputting a face image into BiSeNet includes:

[0101] Binary image sub-step: During the inference process with BiSeNet, there is no need to enhance the input face image, and there is no need to calculate gradients and losses; resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

[0102] Furthermore, the step of expanding and increasing the edge area includes:

[0103] Obtain edge binary graph sub-steps: Let the coordinates of point p be (x, y), then the 8-neighborhood and 24-neighborhood around point p are as follows Figure 4 As shown, the edge binary image generated by the 24-domain expansion of point p is as follows Figure 5 shown.

[0104] Furthermore, the k-means clustering step includes:

[0105] Image overlay sub-step: The binary image after edge expansion and the original face image are overlaid as shown in the figure. Figure 6 As shown in the figure, the RGB pixel values ​​of the original image where the white area is located are taken as the features of k-means clustering, and the category k is set to 2. Since hair color and skin color are relatively concentrated, the clustering will be very accurate.

[0106] Furthermore, the step of merging the results includes:

[0107] Merge result sub-step: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is not hair, set the pixel value to 0; the merge result is as follows Figure 7 shown.

[0108] A hair segmentation system based on convolutional neural network, including the following modules:

[0109] Video stream image acquisition module: acquire and process the video stream into frames;

[0110] Face region determination module: uses face detection model to detect and determine face region;

[0111] Image processing module: crop the face image based on the face area, input the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; obtain the binary image module: use the canny operator to find the edge of the face image and the binary image, and obtain the hair edge binary image as shown in the figure. Figure 3 As shown;

[0112] Expand and increase edge area module: expand and increase edge area to the periphery according to the pixel position of the edge binary image;

[0113] Build a k-means clustering module: Use the color value of the extended edge area of ​​the face image as a feature to build a k-means clustering module.

[0114] Merge result module: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area.

[0115] Furthermore, the face area determination module includes:

[0116] Determine the preliminary face region submodule: Use the face detection algorithm RetinaFace to first determine the preliminary face region;

[0117] Face detection submodule: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively.

[0118] Furthermore, the image processing module includes:

[0119] Training submodule: Use face images and binary images with hair areas marked to train BiSeNet;

[0120] Binarized image generation module: Input a face image into BiSeNet, complete inference, and generate a binary image of the same size as the input face image;

[0121] The module corresponding to cropping face images containing hair is as follows:

[0122] Cropping submodule: Cropping the face according to the face rectangular frame bbox obtained by the face detection module. Since it is a hair segmentation task, the cropped face must completely contain the hair area, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are .

[0123] Furthermore, in the training submodule, the module corresponding to the image annotation is as follows:

[0124] Image annotation submodule: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is the background, which is a negative sample. Figure 2 shown.

[0125] Furthermore, in the training submodule, the module for training BiSeNet corresponding to binary images is as follows:

[0126] Training image enhancement transition submodule: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to ; During training, we first randomly select the value S from 0.1 to 0.5 evenly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ;

[0127] Horizontal flip submodule: swap the image and the corresponding binary labeled pixels left and right;

[0128] Color jitter submodule: adjusts and enhances the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

[0129] Furthermore, in the binary image generation module, the module for inputting a face image into BiSeNet includes:

[0130] Binary image submodule: During the inference process of BiSeNet, there is no need to enhance the input face image, calculate the gradient and loss; resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

[0131] Furthermore, the expansion and addition of the edge area module includes:

[0132] Get the edge binary graph submodule: Let the coordinates of point p be (x, y), then the 8-neighborhood and 24-neighborhood around point p are as follows Figure 4 As shown, the edge binary image generated by the 24-domain expansion of point p is as follows Figure 5 shown.

[0133] Furthermore, the k-means clustering module includes:

[0134] Image overlay submodule: The binary image after edge expansion and the original face image are overlaid. Figure 6As shown in the figure, the RGB pixel values ​​of the original image where the white area is located are taken as the features of k-means clustering, and the category k is set to 2. Since hair color and skin color are relatively concentrated, the clustering will be very accurate.

[0135] Furthermore, the merging result module includes:

[0136] Merge result submodule: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is not hair, set the pixel value to 0; the merge result is as follows Figure 7 shown.

[0137] Compared with the prior art, the hair segmentation method and system based on convolutional neural network in the embodiment of the present invention have at least the following improvements and advantages:

[0138] 1. Through a new convolutional neural network model (hair full convolutional network model), combined with the hair position information, hair frequency information and hair color information in the image, the hair area of ​​the image can be accurately identified. The face detection algorithm RetinaFace is used to detect the face and determine the approximate position of the hair area to prevent interference from other similar hair targets in the background.

[0139] 2. Use BiSeNet dual-channel segmentation network to realize hair segmentation in real time, which can realize automatic recognition without human intervention.

[0140] 3. The hair segmentation training method is regarded as binary classification of pixels, and the image is enhanced by multi-scale, horizontal flipping, color dithering and other methods. This can solve the problem that the hair area cannot be accurately identified when the background color is similar to the hair color, and the problem that the face cannot be identified at a large deflection angle and the back in the prior art; it has high recognition accuracy.

[0141] 4. After obtaining the hair segmentation binary image through BiSeNet inference, the canny operator is used to find the edge of the binary image. Using the canny operator to find the edge of the binary image can be faster and more accurate, which greatly improves the processing efficiency and processing effect of the binary image.

[0142] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A hair segmentation method based on convolutional neural network, characterized in that: The following steps are involved: Steps for obtaining video stream images: obtain and process the video stream into frames; Steps for determining the face area: using the face detection model to detect and determine the face area; Image processing steps: crop the face image based on the face area, input the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; Binary image obtaining steps: use the Canny operator to find the edge of the face image and the binary image to obtain a hair edge binary image; Step of expanding and increasing the edge area: expanding and increasing the edge area toward the periphery according to the pixel position of the edge binary image; Steps for k-means clustering: Use the color value of the extended edge area of ​​the face image as a feature for k-means clustering; Merge result step: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area. The step of determining the face area comprises: Determine the preliminary face region sub-step: first determine the preliminary face region using the face detection algorithm RetinaFace; Face detection sub-step: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively; The image processing step comprises: Training sub-step: Train BiSeNet using face images and binary images with hair areas annotated; Steps to generate a binary image: Input a face image into BiSeNet, complete inference, and generate a binary image of the same size as the input face image; The steps to crop a face image including hair are as follows: Cropping sub-step: Based on the face rectangular frame bbox obtained in the face detection step, crop the face that completely contains the hair area, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are ; The step of combining the results comprises: Merge result sub-step: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is non-hair, set the pixel value to 0; merge the results.

2. The hair segmentation method based on convolutional neural network according to claim 1, characterized in that: In the training sub-step, the steps for labeling the corresponding pictures are as follows: Image annotation sub-step: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is used as the background, which is a negative sample.

3. The hair segmentation method based on convolutional neural network according to claim 1, characterized in that: In the training sub-step, the steps for training BiSeNet for binary images are as follows: Training image enhancement transition sub-step: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to; in training, we first randomly select the value S from 0.1 to 0.5 uniformly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ; Horizontal flip sub-step: swap the image and the corresponding binary labeled pixels left and right; Color jitter sub-step: adjust and enhance the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

4. The hair segmentation method based on convolutional neural network according to claim 1, characterized in that: In the step of generating a binary image, the step of inputting a face image into BiSeNet includes: Binary image sub-step: resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

5. The hair segmentation method based on convolutional neural network according to claim 1, characterized in that: The step of expanding and increasing the edge area comprises: Sub-steps for obtaining the edge binary map: Assume the coordinates of point p to be (x, y), and generate the edge binary map according to the 24-domain expansion of point P.

6. The hair segmentation method based on convolutional neural network according to claim 1, characterized in that: The k-means clustering steps include: Image overlay sub-step: Overlay the binary image after edge expansion with the original face image, take the RGB pixel values ​​of the original image where the white area is located as the feature of k-means clustering, and set category k=2.

7. A hair segmentation system based on convolutional neural network, characterized in that: Includes the following modules: Video stream image acquisition module: acquire and process the video stream into frames; Face region determination module: uses face detection model to detect and determine face region; Image processing module: crop the face image based on the face area, input it into the hair segmentation network BiSeNet, and obtain a binary image of the same size as the input face image; binary image module: use the canny operator to find the edge of the face image and the binary image to obtain a binary image of the hair edge; Expand and increase edge area module: expand and increase edge area to the periphery according to the pixel position of the edge binary image; Build a k-means clustering module: Use the color value of the extended edge area of ​​the face image as a feature to build a k-means clustering module. Merge result module: Merge the k-means clustering result with the BiSeNet binary segmentation result. The position with a pixel value of 1 in the merged binary image is the hair area. Mark the corresponding area in the face image to segment the hair area. The face area determination module comprises: Determine the preliminary face region submodule: Use the face detection algorithm RetinaFace to first determine the preliminary face region; Face detection submodule: If there is a face in the image, the face area bbox will be returned. The bbox coordinates are (x1, y1, x2, y2), which correspond to the coordinates of the upper left and lower right points of the face respectively; The image processing module comprises: Training submodule: Use face images and binary images with hair areas marked to train BiSeNet; Binarized image generation module: Input a face image into BiSeNet, complete inference, and generate a binary image of the same size as the input face image; The module corresponding to cropping face images containing hair is as follows: Cropping submodule: Based on the face rectangular frame bbox obtained by the face detection module, the face that completely contains the hair area is cropped, where the width w of the bbox is equal to , height h is equal to , set the cropping scale to s times, so the cropping coordinates are ; The merging result module includes: Merge result submodule: On the binary image of the BiSeNet segmentation result, modify the pixel value of the extended edge position. If the k-means clustering result is hair, set the pixel value to 255; if the clustering result is non-hair, set the pixel value to 0; merge the results.

8. The hair segmentation system based on convolutional neural network according to claim 7, characterized in that: In the training submodule, the modules corresponding to the image annotation are as follows: Image annotation submodule: When annotating, the pixels in the hair area are positive samples, and the rest of the face image except the hair area is used as the background, which is a negative sample.

9. The hair segmentation system based on convolutional neural network according to claim 7, characterized in that: In the training submodule, the module corresponding to the binary image training BiSeNet is as follows: Training image enhancement transition submodule: The training images read from disk and the corresponding binary labeled images are of the same size. , by setting the scales transformation parameter to [0.1,0.5], cropsize to; in training, we first randomly select the value S from 0.1 to 0.5 uniformly, and then resize the image and the corresponding binary annotation to The size of If it is greater than 256, it is necessary to randomly crop out the image and the corresponding binary annotation. The image blocks participate in the training. If it is less than 256, you need to fill 0 around the image and the corresponding binary label. The number of zero-filled pixels around is ; Horizontal flip submodule: swap the image and the corresponding binary labeled pixels left and right; Color jitter submodule: adjusts and enhances the brightness, contrast, and saturation of the image, which involves adjusting the brightness, contrast, and saturation of the image.

10. The hair segmentation system based on convolutional neural network according to claim 7, characterized in that: In the binary image generation module, the module for inputting a face image into BiSeNet includes: Binary image submodule: resize the face image to Size, input BiSeNet, will be obtained in the last layer of the network A binary image of .

11. The hair segmentation system based on convolutional neural network according to claim 7, characterized in that: The module for expanding and increasing the edge area includes: Obtain the edge binary map submodule: Assume the coordinates of point p to be (x, y), and generate an edge binary map based on the 24-domain expansion of point p.

12. The hair segmentation system based on convolutional neural network according to claim 7, characterized in that: The k-means clustering module includes: Image overlay submodule: The binary image after edge expansion and the original face image are overlaid, and the RGB pixel values ​​of the original image where the white area is located are taken as the features of k-means clustering, and the category k is set to 2.