Sight line correction method and device, computer equipment and readable storage medium
By detecting and correcting the direction of the person's gaze in the face image, the problem of not looking directly is solved, achieving precise correction of the person's eyes and protecting the image quality.
Patent Information
- Application Number
- CN202410832324.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-27
AI Technical Summary
In the field of computer vision, factors such as the shooting viewpoint, camera position, and subject's gaze direction cause the gaze to not look directly at the camera, which brings challenges to the understanding and utilization of facial images. It is difficult to effectively adjust and correct the position of people on the face using existing technology. The direction of view in the image.
By detecting the gaze direction of the image to be processed, the source posture parameters are obtained, the initial feature map is extracted, converted into the target posture, the correlation between the texture feature map and the target feature map is determined, and the gaze correction of the eye area is performed based on this information to generate Target image after vision correction.
It achieves precise correction of people's eyes, keeps the texture and details of other parts of the image natural, retains and restores the visual quality of the original image to the maximum extent, and solves the problem of not looking directly.
Smart Images

Figure CN118710562A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer device, computer-readable storage medium and computer program product for correcting vision. Background Art
[0002] Eye gaze or gaze direction is important information in facial images because it carries a wealth of non-verbal communication signals, which are essential for understanding human emotional states, intentions, and attention directions. It plays an important role in daily photography, human-computer interaction, face recognition, emotion analysis, and other fields.
[0003] However, in practical applications, due to factors such as the camera viewpoint, camera position, and the subject's line of sight, the subject often does not look directly at the camera, which poses a challenge to the understanding and use of facial images. Therefore, developing an eye correction algorithm to adjust and correct the direction of a person's line of sight in a facial image has become an important research topic in the field of computer vision. Summary of the invention
[0004] Based on this, it is necessary to provide a line of sight correction method, device, computer equipment, computer-readable storage medium and computer program product that can adjust and correct the line of sight direction of a person in a face image in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for correcting sight, comprising:
[0006] Performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0007] Extracting features from the image to be processed to obtain an initial feature map under the source posture;
[0008] Based on the source posture parameter, converting the initial feature map from the source posture to a target posture to obtain a target feature map at the target posture;
[0009] Extracting a texture feature map from the initial feature map, and determining a correlation between the texture feature map and the target feature map;
[0010] According to the initial feature map and the correlation degree, line of sight correction is performed on the eye region of the image to be processed to obtain a target image after line of sight correction.
[0011] In one embodiment, performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed includes:
[0012] The image to be processed is subjected to grayscale processing to obtain a grayscale image corresponding to the image to be processed; a preset grayscale threshold is obtained, and the grayscale image is segmented according to the preset grayscale threshold to obtain an eye area image; the eye area image is subjected to edge detection processing to obtain an eye contour curve and a pupil contour closure curve; and source posture parameters of the image to be processed are obtained according to the eye contour curve and the pupil contour closure curve.
[0013] In one embodiment, obtaining the source posture parameter of the image to be processed according to the eye contour curve and the pupil contour closure curve includes:
[0014] The eye contour closed curve is subjected to ellipse fitting processing to obtain the eye center position; the pupil contour closed curve is subjected to ellipse fitting processing to obtain the pupil center position; the distance between the eye center position and the pupil center position is determined; a preset mapping relationship is obtained, and the distance is converted into a source posture parameter of the image to be processed according to the preset mapping relationship.
[0015] In one embodiment, the converting the initial feature map from the source pose to the target pose based on the source pose parameter to obtain the target feature map at the target pose includes:
[0016] Acquire a posture transformation matrix; obtain an affine transformation matrix according to the source posture parameters and the posture transformation matrix; resample the initial feature map according to the affine transformation matrix to obtain a target feature map under the target posture.
[0017] In one embodiment, determining the correlation between the texture feature map and the target feature map includes:
[0018] The texture feature map is converted into a key vector, and the target feature map is converted into a query vector; dot product processing is performed on the key vector and the query vector to obtain a scalar vector; the scalar vector is scaled by a preset scaling factor to obtain a scaled vector; the scaled vector is normalized to obtain an attention weight, and the attention weight is used to characterize the correlation between the texture feature map and the target feature map.
[0019] In one embodiment, performing sight line correction on the eye region of the image to be processed according to the initial feature map and the correlation degree to obtain a target image after sight line correction includes:
[0020] The initial feature map and the attention weights are weighted to obtain a weighted feature map; the original pixel values of the image to be processed are determined; and image reconstruction is performed according to the original pixel values of the image to be processed and the weighted feature map to obtain a target image after line of sight correction.
[0021] In a second aspect, the present application also provides a vision correction device, comprising:
[0022] A detection module, used to detect the sight direction of the image to be processed, and obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0023] An extraction module, used for performing feature extraction on the image to be processed to obtain an initial feature map under the source posture;
[0024] A conversion module, configured to convert the initial feature map from the source pose to a target pose based on the source pose parameter, to obtain a target feature map under the target pose;
[0025] A determination module, configured to extract a texture feature map from the initial feature map, and determine a correlation between the texture feature map and the target feature map;
[0026] A correction module is used to perform line of sight correction on the eye area of the image to be processed according to the initial feature map and the correlation degree to obtain a target image after line of sight correction.
[0027] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0028] Performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0029] Extracting features from the image to be processed to obtain an initial feature map under the source posture;
[0030] Based on the source posture parameter, converting the initial feature map from the source posture to a target posture to obtain a target feature map at the target posture;
[0031] Extracting a texture feature map from the initial feature map, and determining a correlation between the texture feature map and the target feature map;
[0032] According to the initial feature map and the correlation degree, line of sight correction is performed on the eye region of the image to be processed to obtain a target image after line of sight correction.
[0033] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0034] Performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0035] Extracting features from the image to be processed to obtain an initial feature map under the source posture;
[0036] Based on the source posture parameter, converting the initial feature map from the source posture to a target posture to obtain a target feature map at the target posture;
[0037] Extracting a texture feature map from the initial feature map, and determining a correlation between the texture feature map and the target feature map;
[0038] According to the initial feature map and the correlation degree, line of sight correction is performed on the eye region of the image to be processed to obtain a target image after line of sight correction.
[0039] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0040] Performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0041] Extracting features from the image to be processed to obtain an initial feature map under the source posture;
[0042] Based on the source posture parameter, converting the initial feature map from the source posture to a target posture to obtain a target feature map at the target posture;
[0043] Extracting a texture feature map from the initial feature map, and determining a correlation between the texture feature map and the target feature map;
[0044] According to the initial feature map and the correlation degree, line of sight correction is performed on the eye region of the image to be processed to obtain a target image after line of sight correction.
[0045] The above sight line correction method, device, computer equipment, computer readable storage medium and computer program product firstly detect the sight line direction of the image to be processed to obtain the source posture parameters of the image to be processed; the image to be processed includes at least the eye area, and the source posture parameters are used to characterize the source posture of the eye area; and the direction of the person's sight line and the posture of the face are preliminarily determined. The acquired source posture parameters provide a benchmark for subsequent correction operations to ensure that the correction process has a basis. Then, the image to be processed is feature extracted to obtain an initial feature map under the source posture; and the complex image information is simplified into a key form that is easy for computer processing. Next, based on the source posture parameters, the initial feature map is converted from the source posture to the target posture to obtain the target feature map under the target posture; the appearance change of the eye area under different viewing angles is simulated, which is the core step to achieve sight line correction, so that the corrected person's sight line meets the expected direction. Then, a texture feature map is extracted from the initial feature map, and the correlation between the texture feature map and the target feature map is determined; and the similarities and differences between features are captured more finely. Finally, according to the initial feature map and the correlation degree, the eye region of the image to be processed is corrected to obtain a target image after the correction. This can not only achieve accurate correction of the person's eyes, but also keep the natural texture and details of other parts of the image, and maximize the retention and restoration of the visual quality of the original image. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A diagram showing an application environment of a sight correction method in one embodiment;
[0048] Figure 2 is a flow chart of a sight correction method in one embodiment;
[0049] Figure 3 is a training flow chart of a sight correction model in one embodiment;
[0050] Figure 4 is a flow chart of a sight correction method in another embodiment;
[0051] Figure 5 is a structural block diagram of a sight correction device in one embodiment;
[0052] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0054] The sight correction method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The terminal 102 generates a sight correction request, and then sends the sight correction request to the server 104, so that the server 104 performs sight correction on the eye area of the image to be processed according to the initial feature map and the correlation degree, and obtains the target image after sight correction. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0055] In an exemplary embodiment, Figure 2 As shown, a sight correction method is provided, which is applied to Figure 1 The server 104 in the example is used as an example to illustrate, including the following steps 202 to 210. Among them:
[0056] Step 202 , performing gaze direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed includes at least an eye region, and the source posture parameters are used to characterize the source posture of the eye region.
[0057] The image to be processed may be a face image or a partial image including only the eye area in terms of content. The image to be processed may be a static photo or a frame in a dynamic video in terms of form. The specific settings may be made according to actual needs.
[0058] The source posture parameter refers to the quantity used to describe the position and orientation of the pupil of the eye area in the image to be processed in three-dimensional space, and is used to quantitatively reflect the angle at which the line of sight is deflected relative to the shooting device, face recognition device, etc., that is, the line of sight angle.
[0059] Specifically, first confirm the type of image to be processed (still photo or video frame) and ensure that the image quality meets the analysis requirements. If the image contains the entire face, face detection may be required to locate the facial area; if it is known that the image only contains the eye area, go directly to the next step. Optionally, perform necessary preprocessing on the image, such as grayscale, noise reduction, brightness and contrast adjustment, to optimize the recognition effect of eye features. Then use eye detection algorithms, such as gradient histogram HOG, support vector machine SVM, and deep learning models, to accurately locate the position of the eyes in the image to be processed. Key feature points are further extracted from the detected eye area, such as pupil center, eye contour, and eye distance. Finally, based on the geometric relationship between the eye feature points (pupil center, eye contour, and eye distance), the position and orientation of the pupil in the eye area in the image to be processed in three-dimensional space, that is, the sight angle, is determined.
[0060] Step 204: extract features from the image to be processed to obtain an initial feature map under the source posture.
[0061] The initial feature map is an image representation after preliminary feature extraction. It is no longer raw pixel-level data, but a series of feature representations with abstract meanings. For the eyes, the focus may be on the outline and structure of the pupil and eyelid.
[0062] Specifically, first, to ensure image quality, necessary preprocessing operations are performed on the image to be processed, such as grayscale conversion, noise removal, size normalization, etc., to prepare for feature extraction. Then, based on the completed eye area positioning, the image area containing only the eye (including pupil, iris, eyelid, etc.) is accurately segmented through edge detection image processing technology to ensure clear separation of eye features. Next, the preprocessed image to be processed is subjected to preliminary feature extraction processing to obtain the initial feature map. The obtained initial feature map is a high-level image representation that no longer focuses on pixel-level details, but focuses on the abstract expression of key features such as pupil, eye contour and eye structure, providing a basis for subsequent source posture analysis or other advanced visual tasks.
[0063] Step 206: based on the source pose parameters, convert the initial feature map from the source pose to the target pose, and obtain the target feature map under the target pose.
[0064] The target posture is the position and orientation of the pupil in the eye area in three-dimensional space when the line of sight is looking at a camera, face recognition or other equipment.
[0065] Specifically, first, the transformation parameters required from the source pose to the target pose are calculated based on the previously acquired source pose parameters and the defined target pose (i.e., the state of the eyes when the line of sight is directly looking at the camera or face recognition device). Optionally, the rotation angle is determined to correct the line of sight direction, as well as any necessary translation to ensure the correct position of the eye area in the final image. The calculation of the transformation parameters needs to take into account the line of sight deflection in three-dimensional space and map it to the two-dimensional image plane for implementation.
[0066] The initial feature map is then geometrically transformed using the transformation parameters calculated in the previous step. This process involves using mathematical transformation matrices, such as rotation matrices and translation vectors, to adjust the position and orientation of the eye region in the initial feature map to ensure that it meets the requirements of the target pose.
[0067] Finally, after the posture conversion, the initial feature map originally represented by the source posture is adjusted to the image representation under the target posture to form the target feature map. At this time, the eye area in the target feature map is represented as if it is directly facing the camera or face recognition device, regardless of the actual direction of the line of sight in the original image. The target feature map not only retains the key feature information of the eye, but also unifies the representation method under different source postures, which facilitates the consistency and efficiency of subsequent processing.
[0068] Step 208: extracting a texture feature map from the initial feature map, and determining the correlation between the texture feature map and the target feature map.
[0069] Among them, the texture feature map is a further feature representation, which is a feature map obtained after further feature extraction of the initial feature map, focusing on capturing and expressing the texture information in the image. The correlation degree is an attention weight matrix, which is used to represent the correlation degree between each pixel in the texture feature map and each pixel in the target feature map.
[0070] Specifically, we first select a set of filters suitable for capturing textures of different scales and directions, and perform convolution operations on the initial feature map. We then perform pooling operations such as maximum pooling and average pooling on the filtered responses to reduce the data dimension while retaining key texture information. We aggregate the outputs of all filters to generate a high-dimensional feature map that focuses on expressing the texture structure in the image.
[0071] Then ensure that the texture feature map and the target feature map have the same size or adjust them to be consistent through interpolation or other methods. For each pixel in the texture feature map and each pixel in the target feature map, use a suitable similarity metric to calculate the similarity between them. Organize the similarity values between all pixel pairs into an attention weight matrix, which is used to reflect the correlation between the texture feature map and the target feature map.
[0072] Finally, consider optimizing the attention weight matrix to remove noise, enhance important associations, or adapt to specific task requirements. Optionally, the attention weight matrix is normalized (such as row normalization, column normalization, or overall normalization) to ensure that the sum of the weights is 1, thereby converting it into a probability distribution form.
[0073] Step 210, performing sight line correction on the eye region of the image to be processed according to the initial feature map and the correlation degree, and obtaining a target image after sight line correction.
[0074] Specifically, each pixel value in the initial feature map is first multiplied by the corresponding attention weight value to achieve the weighting of the feature map. This enhances the feature expression associated with the target posture while weakening irrelevant or interfering information. After completing the pixel-by-pixel weighting process, a new image representation, namely the weighted feature map, is obtained, which reflects the more important visual features in the sight correction task. Then the original RGB or grayscale pixel values of the image to be processed are directly read or extracted to prepare the basic data for the subsequent image reconstruction step. Finally, the weighted feature map is reconstructed to obtain a reconstructed image with pixel values consistent with the original image, namely the target image after sight correction.
[0075] In one of the embodiments, grayscale processing is performed on the image to be processed to obtain a grayscale image corresponding to the image to be processed; a preset grayscale threshold is obtained, and the grayscale image is segmented according to the preset grayscale threshold to obtain an eye area image; edge detection processing is performed on the eye area image to obtain an eye contour curve and a pupil contour closure curve; based on the eye contour curve and the pupil contour closure curve, source posture parameters of the image to be processed are obtained.
[0076] Specifically, the input image to be processed (whether it is a face image or a partial eye image, whether it is a static or dynamic source) is first grayed and converted into a grayscale representation, thereby obtaining a grayscale image corresponding to the image. Then a threshold is set according to the typical brightness range of the eye area in the grayscale image. The grayscale image is binarized using this threshold to distinguish the eye area from the background, and then the eye area image is extracted. Next, an edge detection algorithm (such as Canny edge detection, Sobel operator, etc.) is applied to process the eye area image. Based on the edge detection results, the eye contour curve and the pupil contour closure curve are determined respectively. Finally, the positional relationship between the eye contour curve and the pupil contour closure curve is combined with a geometric analysis method. The offset of the pupil center relative to the geometric center of the eye, as well as factors such as the opening and closing state of the eyes, are analyzed to infer the inclination angle (line of sight angle) of the line of sight relative to the shooting device.
[0077] Compared with directly extracting complex features on color images, grayscale processing and binary segmentation simplify the image content, reduce the amount of data for subsequent processing, and reduce the algorithm's computational complexity and resource consumption. And through fine eye contour and pupil contour detection, it can more accurately estimate the direction of sight and the position of the eyeball, which is crucial for applications that require high-precision posture information.
[0078] In one of the embodiments, an eye contour closed curve is subjected to ellipse fitting to obtain the eye center position; an eye contour closed curve is subjected to ellipse fitting to obtain the pupil center position; a distance between the eye center position and the pupil center position is determined; a preset mapping relationship is obtained, and the distance is converted into a source posture parameter of the image to be processed according to the preset mapping relationship.
[0079] Specifically, firstly, an ellipse fitting algorithm (such as the least squares method) is applied to fit the eye contour curve, and the geometric center position of the eye is determined from the fitted ellipse. Similarly, an ellipse fitting algorithm is applied to the pupil contour closed curve, and the coordinates of the pupil center are obtained from the fitted pupil ellipse. Then, the straight-line distance between the eye center and the pupil center is calculated using the distance formula between two points in a two-dimensional coordinate system. Finally, based on the measured distance and referring to the preset mapping relationship, the source posture parameter of the image to be processed is calculated, and the source posture parameter is used to quantitatively reflect the angle of deflection of the line of sight relative to the shooting device, face recognition device, etc., i.e., the line of sight angle.
[0080] The ellipse fitting method can accurately locate the center of the eye and pupil, which significantly improves the accuracy and stability of position recognition compared to simple contour detection or geometric center estimation, especially when processing eye images of different sizes and shapes. And the direct conversion from center distance to posture parameters avoids complex 3D reconstruction or physical model simulation, simplifies the subsequent calculation process, and facilitates the realization of real-time applications. It improves the generalization ability of the model in complex application environments.
[0081] In one of the embodiments, a posture transformation matrix is obtained; an affine transformation matrix is obtained according to source posture parameters and the posture transformation matrix; and an initial feature map is resampled according to the affine transformation matrix to obtain a target feature map under a target posture.
[0082] Specifically, firstly based on the known source pose parameters (such as sight angle, pupil position) and the preset target pose (sight directly facing the device), including but not limited to the necessary rotation angle (adjustment along the sight direction) and translation amount (ensuring the correct position of the eye in the image).
[0083] The calculated rotation angles and translation vectors are then combined to form a complete affine transformation matrix. This usually includes a combination of a rotation matrix and a translation vector. Make sure the transformation matrix can handle both rotation and translation to maintain geometric consistency and visual naturalness of the eye features.
[0084] Finally, the affine transformation matrix is applied to the initial feature map using the resampling function in the image processing software or library (such as OpenCV). During the transformation process, the pixel values at the new position are calculated through interpolation algorithms (such as bilinear interpolation and nearest neighbor interpolation) to ensure the continuity and clarity of the image after deformation. After the resampling process, the image originally represented by the source posture is transformed into the target posture, which is directly facing the camera or face recognition device, forming the target feature map.
[0085] Since all input images are converted to the same posture, the subsequent image processing or analysis steps can use a unified algorithm or model, without the need to design specific processing logic for each different posture, simplifying the complexity of the system. And for face recognition or eye tracking systems, accurate line of sight direction and eye position are crucial. By fine-tuning the posture of the eye area, the consistency and accuracy of these key features can be ensured, thereby significantly improving the performance and accuracy of the recognition system.
[0086] In one of the embodiments, the texture feature map is converted into a key vector, and the target feature map is converted into a query vector; the key vector and the query vector are dot-producted to obtain a scalar vector; the scalar vector is scaled by a preset scaling factor to obtain a scaled vector; the scaled vector is normalized to obtain an attention weight, and the attention weight is used to characterize the correlation between the texture feature map and the target feature map.
[0087] Specifically, the previously generated feature map focusing on texture information is first regarded as a large set of feature vectors, and each pixel or a group of pixels can be regarded as an element of a feature vector. This two-dimensional feature map is converted into a one-dimensional key vector K by some means (such as flattening operation), which contains all the texture information of the texture feature map. Similarly, the target feature map is also converted into a one-dimensional query vector Q, each element of which corresponds to the feature representation of a pixel or a group of pixels on the target feature map. This step aims to find the most relevant texture features for each target position.
[0088] Then, for the key vector K and the query vector Q, a dot product operation is performed (i.e., the corresponding elements of the two vectors are multiplied and then summed) to obtain a scalar value. This scalar value can be understood as the matching degree or similarity between a certain part of the feature in the texture feature map and the corresponding part of the feature in the target feature map. It can be understood that the whole process can be regarded as calculating the correlation between each target position and all possible corresponding positions in the texture feature space.
[0089] Next, the result of the dot product often needs to be scaled by a preset scaling factor. This is done to control the numerical range, avoid the attention distribution being too sparse or concentrated due to differences in vector length, and enhance the stability of the model.
[0090] Finally, the scaled vector is normalized, usually row normalization or column normalization, to ensure that the sum of all attention weights is 1, and to convert it into a probability distribution. This means that each target position will have a normalized weight distribution for all positions in the texture feature map, reflecting the importance of each texture feature to the target position.
[0091] By calculating the correlation between the texture feature map and the target feature map and forming an attention weight matrix, it is possible to automatically learn which regions or features are most critical to the current task. This adaptive attention mechanism makes the processing more efficient, focusing on key information and ignoring irrelevant or interfering information, thereby improving model performance.
[0092] In one of the embodiments, the initial feature map and the attention weights are weighted to obtain a weighted feature map; the original pixel values of the image to be processed are determined; and the image is reconstructed based on the original pixel values of the image to be processed and the weighted feature map to obtain a target image after line of sight correction.
[0093] Specifically, first traverse each pixel in the initial feature map and perform an element-by-element multiplication operation on its value and the corresponding attention weight value. The attention weight here reflects the importance of each pixel in the sight correction task. After completing the multiplication operation, the new feature map obtained is the weighted feature map, in which the pixel value reflects its enhancement or weakening under the guidance of the target posture. Then directly extract or read the RGB value (if it is a color image) or grayscale value (if it is a grayscale image) of each pixel from the image to be processed, which constitutes the basic pixel data of the image, that is, the original pixel value. Finally, the weighted feature map is reconstructed by the designed filter, and the resolution is gradually improved after multi-level upsampling, and the corresponding convolution layer is added after each level of upsampling to refine it, and finally a reconstructed image with pixel values consistent with the original image is obtained, that is, the target image after sight correction.
[0094] Optionally, the filter design can use a small-sized convolution kernel to capture local features; in areas where the original pixel values are maintained, the filter is designed to output values close to the input, and even residual connections can be designed to directly transfer information. And the network is designed to process the image in blocks, using specific convolution kernels for areas that need to be corrected, using filters that maintain properties for other areas, or using a learnable gating mechanism to decide whether to apply the correction.
[0095] In one example, the process of “determining the correlation between the texture feature map and the target feature map, weighting the initial feature map and the attention weight to obtain a weighted feature map” is specifically implemented by the following calculation formula:
[0096]
[0097] Among them, Q, K, and V are the query vector, key vector, and initial feature map, respectively. dk is the dimension of the key, i.e., the scaling factor, which is used to scale the dot product to prevent excessive values. Attention (Q, K, V) is the weighted feature map.
[0098] By combining the attention weights with the initial feature map to generate a weighted feature map, the pixel features in the image that are directly related to the sight correction task can be specifically enhanced or weakened, so that the eye area can be accurately adjusted without significantly changing other parts of the image, so that the sight direction naturally matches the target posture, improving the accuracy and naturalness of sight correction. In addition, the RGB or grayscale pixel values of the original image are directly extracted as basic data, ensuring that the reconstructed image is highly consistent with the original image in the non-corrected area, protecting the overall quality and detail information of the image, and avoiding image distortion or information loss that may be caused by traditional methods.
[0099] In one embodiment, the sight line correction model is used to perform sight line correction on the image to be processed, and finally a sight line corrected target image is obtained. The training process of the sight line correction model includes the following process, wherein:
[0100] The first is the data preparation stage. Columbia Gaze Dataset is a relatively high-quality dataset that contains gaze data of 56 subjects. The head poses in the dataset are discrete values, including -30°, -15°, 0°, 15°, and 30°. For each head pose, the dataset contains three pitch angles [-10°, 0°, 10°] and seven yaw angles [-15°, -10°, -5°, 0°, 5°, 10°, 15°] of gaze directions.
[0101] In addition to using the Columbia Gaze Dataset, we also collect paired data of different portraits and non-centered and centered eyes in various scenes to cover more actual landing scenes and improve the robustness of the model in various scenes. It mainly includes: using the internal face detection library to perform face detection and obtain facial key points. These key points include information about facial features such as eyes, nose, and mouth. Calculate the center points of the left and right eyes from the key points. This usually involves taking the average position of the eye key points. Calculate the horizontal and vertical distances between the two eye centers, and then calculate the angle of the two vectors, which represents the relative position of the eyes. Determine the rotation center, which is usually the position in the middle of the eye centers. Create an affine transformation matrix, which is used to rotate the image to a horizontal position and extract the local areas of the left and right eyes. The parameters of the affine transformation matrix include the rotation center, rotation angle, and scaling. Apply the affine transformation matrix to the original image to obtain the local area of the eyes of the face in the horizontal state. Before performing the affine transformation, check whether the eyes are occluded. If the eyes are occluded, subsequent operations will be skipped. The eye gaze direction is calculated by using the pre-trained eye gaze direction detection model to obtain the eye gaze direction representation in two-dimensional space. This eye gaze direction will be used to guide the subsequent eye correction process.
[0102] The second is the model training phase, refer to Figure 3 The gaze correction model mainly includes reconstruction branch, conversion branch, GazeTransformer Module (GTM) module. The GTM module includes context enhancement block, texture transfer block and multi-head cross attention (MHCA) module. Among them:
[0103] In the reconstruction branch, the input is the source image (Xs), the source pose (Gs), and the output is the reconstructed source image (Xs'). The main task of this branch is to reconstruct the source image (Xs) into a new image (Xs') similar to the original image through a mapping function (Fs-s).
[0104] In the conversion branch, the input is the source image (Xs), the target pose (Gt), and the output is the converted target image (Xt). The goal of this branch is to convert from the source image (Xs) to the target image (Xt) while maintaining the style and content of the source image. It first maps the source image (Xs) to an intermediate representation (Fs) through the Gaze Transformer Module, and then applies another mapping function (Fs-t) to generate the final target image (Xt).
[0105] The features in the reconstruction branch and the transformation branch are fused with each other in the Gaze Transformer Module (GTM).
[0106] In the context enhancement block, features are extracted from the reconstruction branch and their contextual representations are enhanced through a multi-head self-attention (MHSA) mechanism. This process allows the model to learn the contextual information of features in different representation subspaces in parallel.
[0107] In the texture transfer block, the features of the reconstruction branch, the texture features of the source image, and the output of the previous texture transfer block are combined to capture the fine-grained correlation between the two tasks through a multi-head criss-cross attention (MHCA) module. This helps transfer the true texture of the source image to the target image, thereby generating more detailed textures.
[0108] The features of the source image (Fs) serve as the value (V), while the features of the source-to-source task (Fs→s) and the features of the source-to-target task (Fs→t) serve as the key (K) and query (Q), respectively. In this way, the MHCA module can calculate the attention scores between the source-to-source features and the source-to-target features, which are then used to weight the sum of the features of the source image to generate a new, enhanced feature representation (F*s→t). This process allows the texture transfer block to optimize the features of the source-to-target task using the contextual information provided by the context enhancement block, so that the generated image can better preserve the texture details of the source image. The interaction between the context enhancement block and the texture transfer block is iterative. Each texture transfer block receives the output of the previous texture transfer block and interacts with the output of the context enhancement block and the features of the source image. In this way, as the iteration proceeds, the model can gradually refine and optimize the feature representation, and finally generate a higher quality target image. Through this design, the context enhancement block and the texture transfer block achieve close information interaction in the GTM module, working together to improve the effect of eye gaze direction generation guided by the sight angle.
[0109] In the Multi-Headed Cross-Attention (MHCA) module, in terms of multi-head attention, the input query (Q), key (K), and value (V) are split into multiple "heads", and each head independently calculates the attention score. This helps the model learn different features in different representation subspaces. Cross-attention allows the model to establish connections between features of two different tasks (source-to-source and source-to-target). This means, for example, features from the source-to-source task can be used as keys (K) and features from the source-to-target task can be used as queries (Q), and vice versa. In this way, the model can learn how to map features from one task to features of another task.
[0110] In the Multi-Head Cross Attention (MHCA) module, the cross attention allows the model to establish connections between features of two different tasks (source-to-source and source-to-target). This means, for example, features from the source-to-source task can be used as keys (K), and features from the source-to-target task can be used as queries (Q), and vice versa. In this way, the model can learn how to map features from one task to features of another task. The attention score is calculated by taking the dot product of the query and the key (or its transformation), and then normalized by a softmax function. This determines how much each key contributes to the query. The calculated attention scores are used to weight the sum value (V) to get the final output. This is achieved through the following calculation formula:
[0111]
[0112] Among them, Q, K, V are query, key and value respectively, and dk is the dimension of the key, i.e., the scaling factor, which is used to scale the dot product to prevent excessively large values.
[0113] The above process is repeated multiple times, each time using a different weight matrix (WQ, WK, WV), and then the outputs of all heads are integrated through splicing and linear transformation. This helps the model understand the pixel-level correspondence between the source image and the target image in the multi-head cross-attention module, so that the texture details of the source image can be better preserved when generating the target image. This mechanism provides the model with a powerful tool for effective feature alignment in complex spatial transformations. Through the collaborative work of these modules, line of sight correction is achieved at any gaze angle while maintaining the texture and details of other parts of the image.
[0114] Finally, the loss function is designed. During the training process, a variety of loss functions (such as computational distance loss, perceptual loss, and style loss) are used to ensure the quality of the generated images, texture consistency, and model stability. The following are the main loss functions and their corresponding formulas and inputs:
[0115] In calculating the distance loss, the distance loss is used to measure the pixel-level difference between the generated image and the real image. The distance loss calculates the absolute difference between two images and is usually used for image reconstruction tasks. It is specifically implemented through the following calculation formula:
[0116]
[0117] Among them, X(i, j) is the pixel value of the real image, Y(i, j) is the pixel value of the generated image, and L1 is the distance loss.
[0118] In calculating the perceptual loss, a pre-trained VGG network is used to calculate the difference between feature layers to ensure that the generated image is visually similar to the real image. This is achieved through the following calculation formula:
[0119]
[0120] Among them, Ti is the i-th layer feature of the VGG network, x is the real image, y is the generated image, Ni is the number of elements in the i-th layer feature map, and L2 is the perceptual loss.
[0121] In calculating the style loss, based on the Gram matrix, it is used to measure the similarity in style between the generated image and the real image. The style loss helps to maintain the texture and color distribution of the image. It is specifically implemented through the following calculation formula:
[0122]
[0123] in, is the Gram matrix of the i-th layer features, is the Frobenius norm, x is the real image, y is the generated image, and L3 is the style loss.
[0124] In calculating the adversarial loss, a discriminator is used to distinguish between generated images and real images to improve the realism of the generated images. This is achieved through the following calculation formula:
[0125]
[0126] Among them, D is the discriminator, x is the real image, y is the generated image, and L4 is the adversarial loss.
[0127] Finally, the above loss functions are weighted and summed to obtain the final total loss value for model training. This is achieved through the following calculation formula:
[0128] L5=λ1L1+λ2L2+λ3L3+λ4L4
[0129] Among them, λ1 is the weight corresponding to the distance loss, λ2 is the weight corresponding to the perceptual loss, λ3 is the weight corresponding to the style loss, λ4 is the weight corresponding to the adversarial loss, and L5 is the total loss.
[0130] During training, these loss functions work together to ensure that the generated images are not only close to real images at the pixel level, but also as similar as possible in visual perception, style, and realism. By optimizing this total loss, the model can learn how to effectively convert from the original gaze angle to the centered gaze angle while maintaining the high quality of the image.
[0131] In an exemplary embodiment, Figure 4As shown, it includes steps 402 to 410. Among them:
[0132] Step 402, grayscale processing is performed on the image to be processed to obtain a grayscale image corresponding to the image to be processed; a preset grayscale threshold is obtained, and the grayscale image is segmented according to the preset grayscale threshold to obtain an eye area image; edge detection is performed on the eye area image to obtain an eye contour curve and a pupil contour closure curve; an ellipse fitting process is performed on the eye contour closure curve to obtain an eye center position; an ellipse fitting process is performed on the pupil contour closure curve to obtain a pupil center position; a distance between the eye center position and the pupil center position is determined; a preset mapping relationship is obtained, and the distance is converted into a source posture parameter of the image to be processed according to the preset mapping relationship; the image to be processed includes at least an eye area, and the source posture parameter is used to characterize the source posture of the eye area;
[0133] Step 404, extracting features from the image to be processed to obtain an initial feature map under the source posture;
[0134] Step 406, obtaining a posture transformation matrix; obtaining an affine transformation matrix according to the source posture parameters and the posture transformation matrix; resampling the initial feature map according to the affine transformation matrix to obtain a target feature map under the target posture;
[0135] Step 408, extracting a texture feature map from the initial feature map, converting the texture feature map into a key vector, and converting the target feature map into a query vector; performing dot product processing on the key vector and the query vector to obtain a scalar vector; scaling the scalar vector by a preset scaling factor to obtain a scaled vector; normalizing the scaled vector to obtain an attention weight, which is used to characterize the correlation between the texture feature map and the target feature map;
[0136] Step 410, weighting the initial feature map and the attention weights to obtain a weighted feature map; determining the original pixel values of the image to be processed; reconstructing the image according to the original pixel values of the image to be processed and the weighted feature map to obtain a target image after line of sight correction.
[0137] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0138] Based on the same inventive concept, the embodiment of the present application also provides a sight correction device for implementing the sight correction method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more sight correction device embodiments provided below can refer to the limitations of the sight correction method above, and will not be repeated here.
[0139] In an exemplary embodiment, Figure 5 As shown, a sight correction device 500 is provided, comprising: a detection module 502, an extraction module 504, a conversion module 506, a determination module 508 and a correction module 510, wherein:
[0140] A detection module 502 is used to detect the sight direction of the image to be processed and obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area;
[0141] An extraction module 504 is used to extract features from the image to be processed to obtain an initial feature map under the source posture;
[0142] A conversion module 506, configured to convert the initial feature map from the source pose to the target pose based on the source pose parameter, to obtain a target feature map at the target pose;
[0143] A determination module 508 is used to extract a texture feature map from the initial feature map and determine the correlation between the texture feature map and the target feature map;
[0144] The correction module 510 is used to perform sight line correction on the eye area of the image to be processed according to the initial feature map and the correlation degree to obtain a target image after sight line correction.
[0145] In one embodiment, the detection module 502 is used to perform grayscale processing on the image to be processed to obtain a grayscale image corresponding to the image to be processed; obtain a preset grayscale threshold, and segment the grayscale image according to the preset grayscale threshold to obtain an eye area image; perform edge detection processing on the eye area image to obtain an eye contour curve and a pupil contour closure curve; and obtain source posture parameters of the image to be processed based on the eye contour curve and the pupil contour closure curve.
[0146] In one embodiment, the detection module 502 is used to perform ellipse fitting on the closed curve of the eye contour to obtain the center position of the eye; perform ellipse fitting on the closed curve of the pupil contour to obtain the center position of the pupil; determine the distance between the center position of the eye and the center position of the pupil; obtain a preset mapping relationship, and convert the distance into a source posture parameter of the image to be processed according to the preset mapping relationship.
[0147] In one embodiment, the conversion module 506 is used to obtain a posture transformation matrix; obtain an affine transformation matrix according to source posture parameters and the posture transformation matrix; and resample the initial feature map according to the affine transformation matrix to obtain a target feature map under the target posture.
[0148] In one embodiment, the determination module 508 is used to convert the texture feature map into a key vector and the target feature map into a query vector; perform dot product processing on the key vector and the query vector to obtain a scalar vector; scale the scalar vector by a preset scaling factor to obtain a scaled vector; normalize the scaled vector to obtain an attention weight, and the attention weight is used to characterize the correlation between the texture feature map and the target feature map.
[0149] In one embodiment, the correction module 510 is used to weight the initial feature map and the attention weight to obtain a weighted feature map; determine the original pixel values of the image to be processed; reconstruct the image according to the original pixel values of the image to be processed and the weighted feature map to obtain a target image after line of sight correction.
[0150] Each module in the above-mentioned sight correction device can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.
[0151] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 6As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to line of sight correction. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a line of sight correction method is implemented.
[0152] Those skilled in the art will understand that Figure 6 The structure shown in the figure 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. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0153] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0154] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0155] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0156] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0157] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0158] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0159] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for correcting sight, characterized in that: The method comprises: Performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area; Extracting features from the image to be processed to obtain an initial feature map under the source posture; Based on the source posture parameter, converting the initial feature map from the source posture to a target posture to obtain a target feature map at the target posture; Extracting a texture feature map from the initial feature map, and determining a correlation between the texture feature map and the target feature map; According to the initial feature map and the correlation degree, line of sight correction is performed on the eye region of the image to be processed to obtain a target image after line of sight correction.
2. The method according to claim 1, characterized in that The performing sight line direction detection on the image to be processed to obtain source posture parameters of the image to be processed includes: Performing grayscale processing on the image to be processed to obtain a grayscale image corresponding to the image to be processed; Obtaining a preset grayscale threshold, and performing segmentation processing on the grayscale image according to the preset grayscale threshold to obtain an eye region image; Performing edge detection processing on the eye region image to obtain an eye contour curve and a pupil contour closure curve; The source posture parameters of the image to be processed are obtained according to the eye contour curve and the pupil contour closure curve.
3. The method according to claim 2, characterized in that The step of obtaining the source posture parameter of the image to be processed according to the eye contour curve and the pupil contour closure curve comprises: Performing ellipse fitting processing on the eye contour closed curve to obtain the eye center position; Performing ellipse fitting processing on the pupil contour closed curve to obtain the pupil center position; Determining the distance between the center position of the eye and the center position of the pupil; A preset mapping relationship is obtained, and the distance is converted into a source posture parameter of the image to be processed according to the preset mapping relationship.
4. The method according to claim 1, characterized in that The step of converting the initial feature map from the source pose to the target pose based on the source pose parameter to obtain the target feature map under the target pose comprises: Get the posture transformation matrix; Obtaining an affine transformation matrix according to the source posture parameters and the posture transformation matrix; According to the affine transformation matrix, the initial feature map is resampled to obtain a target feature map under the target posture.
5. The method according to claim 1, characterized in that The determining the degree of association between the texture feature map and the target feature map comprises: Converting the texture feature map into a key vector and converting the target feature map into a query vector; Performing a dot product process on the key vector and the query vector to obtain a scalar vector; Scaling the scalar vector by a preset scaling factor to obtain a scaled vector; The scaling vector is normalized to obtain an attention weight, where the attention weight is used to characterize the correlation between the texture feature map and the target feature map.
6. The method according to claim 5, characterized in that The performing sight line correction on the eye region of the image to be processed according to the initial feature map and the correlation degree to obtain a target image after sight line correction, comprises: Performing weighted processing on the initial feature map and the attention weight to obtain a weighted feature map; Determining the original pixel value of the image to be processed; Image reconstruction is performed according to the original pixel values of the image to be processed and the weighted feature map to obtain a target image after line of sight correction.
7. A sight correction device, characterized in that: The device comprises: A detection module, used to detect the sight direction of the image to be processed, and obtain source posture parameters of the image to be processed; the image to be processed at least includes an eye area, and the source posture parameters are used to characterize the source posture of the eye area; An extraction module, used for performing feature extraction on the image to be processed to obtain an initial feature map under the source posture; A conversion module, configured to convert the initial feature map from the source pose to a target pose based on the source pose parameter, to obtain a target feature map under the target pose; A determination module, configured to extract a texture feature map from the initial feature map, and determine a correlation between the texture feature map and the target feature map; A correction module is used to perform line of sight correction on the eye area of the image to be processed according to the initial feature map and the correlation degree to obtain a target image after line of sight correction.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
