Image distortion correction method, device, electronic device and storage medium

By calculating the degree of deformation of the foreground object and performing distortion correction and spherical projection processing when it is greater than the threshold, the problem of ultra-wide-angle camera image distortion and deformation is solved, and the aesthetics and real-time preview of the image are achieved.

CN113222862BActive Publication Date: 2024-09-17BLACK SESAME TECH (SHANGHAI) CO LTD
View PDF 21 Cites 0 Cited by

Patent Information

Application Number
CN202110624642.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-04
Publication Date
2024-09-17
Estimated Expiration
2041-06-04

AI Technical Summary

Technical Problem

Images captured by ultra-wide-angle cameras are distorted due to distortion, especially in the edge areas around the image, and existing distortion correction methods may cause deformation of images containing foreground objects, affecting the aesthetics of the image.

Method used

By calculating the degree of deformation of the foreground object, when it is greater than a predetermined threshold, the original image is processed using distortion correction and spherical projection methods to obtain the result image, avoid deformation of the foreground object, and reduce the amount of calculation to achieve real-time preview.

Benefits of technology

It effectively avoids the deformation of foreground objects caused by distortion correction, improves the aesthetics and correction effect of the image, and at the same time, due to the small amount of calculation, real-time preview is achieved and the user experience is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113222862B
    Figure CN113222862B
Patent Text Reader

Abstract

The present application relates to an image distortion correction method, device, electronic device and computer-readable storage medium. The image distortion correction method comprises: obtaining an original image taken by a camera; when the original image includes a foreground object, calculating the degree of deformation of the foreground object; and when the degree of deformation of the foreground object is greater than a predetermined threshold, performing distortion correction and spherical projection on the original image to obtain a result image. The image distortion correction method proposed in the present application can realize fast distortion correction of ultra-wide-angle images with low computational complexity and obtain better correction effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to an image distortion correction method, device, electronic device and computer-readable storage medium. Background Art

[0002] Currently, more and more mobile phones are integrated with ultra-wide-angle camera modules. The field of view (FOV) of ultra-wide-angle camera modules is generally greater than 100°, which can obtain a wider shooting field of view, but at the same time introduces image distortion to the captured image, resulting in image distortion, especially in the edge areas around the image.

[0003] The camera module can be calibrated to obtain the camera's intrinsic parameters, and the input image can be distorted based on the camera's intrinsic parameters to eliminate the distortion in the original image. However, if there is a foreground object (such as a portrait) in the original image, the distortion correction performed on the original image will cause the foreground object in the result image to be deformed because the distortion correction has a stretching-like operation. Summary of the invention

[0004] Based on this, it is necessary to provide an improved image distortion correction method, an image distortion correction device, an electronic device and a computer-readable storage medium.

[0005] According to a first aspect of the present application, there is provided an image distortion correction method, comprising:

[0006] Get the original image taken by the camera;

[0007] When the original image includes a foreground object, calculating the degree of deformation of the foreground object; and

[0008] When the deformation degree of the foreground object is greater than a predetermined threshold, distortion correction and spherical projection are performed on the original image to obtain a result image.

[0009] In one embodiment, the method further comprises:

[0010] When the original image does not include a foreground object, performing the distortion correction on the original image to obtain a result image; or

[0011] When the deformation degree of the foreground object is not greater than the predetermined threshold, the distortion correction is performed on the original image to obtain a result image.

[0012] In one embodiment, when the original image includes a foreground object, calculating the deformation degree of the foreground object includes:

[0013] Acquire a foreground object frame in the original image, a position parameter of the foreground object frame, and a size parameter of the foreground object frame; and

[0014] The degree of deformation of the foreground object frame is calculated based on the position parameter of the foreground object frame and the size parameter of the foreground object frame.

[0015] In one embodiment, the position parameters of the foreground object frame include: the distance between the foreground object frame in the original image and the center point of the original image; the size parameters of the foreground object frame include: the width of the foreground object frame and the height of the foreground object frame;

[0016] The deformation degree of the foreground object is calculated based on the following formula

[0017] S=w1×l1+w2×l2

[0018] Among them, S represents the deformation degree of the foreground object; l1 represents the distance between the foreground object border in the original image and the center point of the original image; l2 represents the larger value between the width of the foreground object border and the height of the foreground object border; w1 is the first weight value; w2 is the second weight value.

[0019] In one embodiment, when the deformation degree of the foreground object is greater than a predetermined threshold, performing distortion correction and spherical projection on the original image to obtain a result image includes:

[0020] Based on the spherical projection transformation formula and the distortion correction transformation formula, calculating the correspondence between the pixel points of the result image and the pixel points of the original image; and

[0021] The pixel values ​​of the pixels of the original image are assigned to the pixels of the result image corresponding to the pixels of the original image to obtain the pixel values ​​of the pixels in the result image.

[0022] In one embodiment, based on the spherical projection transformation formula and the distortion correction transformation formula, the correspondence between the pixel points of the result image and the pixel points of the original image is calculated, including:

[0023] Based on the spherical projection transformation formula, the coordinates of the pixel points of the resulting image are calculated (u i , v i ) corresponds to the coordinates of the pixel point after distortion correction is performed on the original image (u i ',v i '), the pixel points of the result image, the corresponding pixel points after distortion correction is performed on the original image, and the center point of the result image are on the same straight line;

[0024] Based on the distortion correction transformation formula, the coordinates of the pixel points after the distortion correction of the original image are calculated (u i ',v i ') corresponds to the coordinates of the pixel point of the original image (u i ”,v i ”);

[0025] The spherical projection transformation formula is:

[0026]

[0027] Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r1 represents the distance from the pixel point of the result image to the center point of the result image, and r2 represents the distance from the pixel point of the distortion-corrected image to the center point of the result image;

[0028] The distortion correction transformation is:

[0029]

[0030] Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y is the longitudinal offset of the image origin relative to the optical center imaging point; k1 is the first radial distortion coefficient of the camera, k2 is the second radial distortion coefficient of the camera, k3 is the third radial distortion coefficient of the camera, k4 is the fourth radial distortion coefficient of the camera, k5 is the fifth radial distortion coefficient of the camera, k6 is the sixth radial distortion coefficient of the camera, p1 is the first tangential distortion coefficient of the camera, and p2 is the second tangential distortion coefficient of the camera.

[0031] According to a second aspect of the present application, there is provided an image correction device, comprising:

[0032] An image acquisition module, configured to acquire an original image taken by a camera;

[0033] a deformation calculation module, configured to calculate the deformation degree of the foreground object when the original image includes the foreground object; and

[0034] The correction calculation module is configured to perform distortion correction and spherical projection on the original image to obtain a result image when the deformation degree of the foreground object is greater than a predetermined threshold.

[0035] In one embodiment, the correction calculation module is further configured as follows:

[0036] When the original image does not include a foreground object, performing the distortion correction on the original image to obtain a result image; or

[0037] When the deformation degree of the foreground object calculated by the deformation calculation module is not greater than the predetermined threshold, the distortion correction is performed on the original image to obtain a result image.

[0038] In one embodiment, the deformation calculation module is further configured as follows:

[0039] Acquire a foreground object frame in the original image, a position parameter of the foreground object frame, and a size parameter of the foreground object frame; and

[0040] The degree of deformation of the foreground object is calculated based on the position parameter of the foreground object frame and the size parameter of the foreground object frame.

[0041] In one embodiment, the position parameters of the foreground object frame include: the distance between the foreground object frame in the original image and the center point of the original image; the size parameters of the foreground object frame include: the width of the foreground object frame and the height of the foreground object frame;

[0042] The deformation calculation module is further configured to calculate the deformation degree of the foreground object frame based on the following formula:

[0043] S=w1×l1+w2×l2

[0044] Among them, S represents the degree of deformation; l1 represents the distance between the foreground object border in the original image and the center point of the original image; l2 represents the larger value between the width of the foreground object border and the height of the foreground object border; w1 is the first weight value; w2 is the second weight value.

[0045] In one embodiment, the correction calculation module includes:

[0046] A mapping calculation unit configured to calculate the correspondence between the pixel points of the result image and the pixel points of the original image based on the spherical projection transformation formula and the distortion correction transformation formula; and

[0047] The pixel assignment unit is configured to assign pixel values ​​of the pixels of the original image to the pixels of the result image corresponding to the pixels of the original image to obtain the result image.

[0048] In one embodiment, the mapping calculation unit is further configured to:

[0049] Based on the spherical projection transformation formula, the coordinates of the pixel points of the resulting image are calculated (u i ,v i) corresponds to the coordinates of the pixel point after distortion correction is performed on the original image (u i ',v i '), the pixel points of the result image, the corresponding pixel points after distortion correction is performed on the original image, and the center point of the result image are on the same straight line;

[0050] Based on the distortion correction transformation formula, the coordinates of the pixel points after the distortion correction of the original image are calculated (u i ',v i ') corresponds to the coordinates of the pixel point of the original image (u i ”,v i ”);

[0051] The spherical projection transformation formula is:

[0052]

[0053] Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r1 represents the distance from the pixel point of the result image to the center point of the result image, and r2 represents the distance from the pixel point of the distortion-corrected image to the center point of the result image;

[0054] The distortion correction transformation is:

[0055]

[0056] Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y is the longitudinal offset of the image origin relative to the optical center imaging point; k1 is the first radial distortion coefficient of the camera, k2 is the second radial distortion coefficient of the camera, k3 is the third radial distortion coefficient of the camera, k4 is the fourth radial distortion coefficient of the camera, k5 is the fifth radial distortion coefficient of the camera, k6 is the sixth radial distortion coefficient of the camera, p1 is the first tangential distortion coefficient of the camera, and p2 is the second tangential distortion coefficient of the camera.

[0057] According to a third aspect of the present application, an electronic device is provided, comprising a memory and a processor, wherein the memory is connected to the processor; the memory stores a computer program; and the processor implements the above-mentioned image correction method when executing the computer program.

[0058] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned image correction method is implemented.

[0059] According to the image distortion correction method, device, electronic device and storage medium of the above aspects, when there is a foreground object (such as a portrait) in the original image and the deformation degree of the foreground object is greater than a predetermined threshold, the original image is subjected to distortion correction and spherical projection to avoid deformation of the foreground object due to the distortion correction, so that the correction effect of the foreground object in the result image is good, and the imaging is beautiful and natural. In addition, since the processing method of distortion correction and spherical projection has a small amount of calculation, the calculation requirements of the computing platform are low, and the result image can be previewed in real time. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] Figure 1 is an original image captured by an ultra-wide-angle camera according to an embodiment;

[0061] Figure 2 A reference image obtained by performing distortion correction on an original image according to an embodiment;

[0062] Figure 3 is a schematic diagram of an electronic device according to an embodiment;

[0063] Figure 4 is a flow chart of an image distortion correction method according to an embodiment;

[0064] Figure 5 is a flow chart of an image distortion correction method according to an embodiment;

[0065] Figure 6 is a schematic diagram of applying the image distortion correction method according to the embodiment;

[0066] Figure 7 is a flow chart of an image distortion correction method according to an embodiment;

[0067] Figure 8 is a mapping relationship diagram of the coordinates of the pixel points of the original image and the result image according to the embodiment;

[0068] Fig. 9 is a mapping relationship diagram of the coordinates of the pixel points of the original image and the result image according to the embodiment;

[0069] Fig.10 is a schematic block diagram of an image distortion correction device according to an embodiment;

[0070] Fig.11 is a schematic block diagram of an image distortion correction device according to an embodiment;

[0071] Fig.12 is a schematic diagram of the internal structure of an electronic device according to an embodiment. DETAILED DESCRIPTION

[0072] 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.

[0073] The original images captured by the ultra-wide-angle camera module usually have image distortion. Figure 1 This is the original image taken by the ultra-wide-angle camera module. Figure 1 As shown, due to the distortion characteristics of the wide-angle lens, the farther the original image is from the image center, the more obvious the image distortion is.

[0074] In order to eliminate the distortion in the image, the internal parameters of the ultra-wide-angle camera module can be used to correct the distortion of the original image. The image after distortion correction is as follows: Figure 2 As shown in the figure. Since distortion correction is similar to stretching, for areas with more severe deformation in the original image, stronger stretching needs to be applied to eliminate the distortion. Therefore, the distortion correction will stretch more for areas farther from the center of the original image. If there are foreground objects in these areas, for example, faces at the four corners of the image, the faces in the distortion-corrected image will be disproportionate due to stretching.

[0075] In some embodiments, a grid point optimization method based on the least squares method can be used to correct the distortion of the original image. The least squares method grid point optimization method has a large amount of calculation, requires high computing power of the computing platform, and takes a long time, usually taking several seconds to complete the correction. In other embodiments, a method based on facial key point detection can be used to adjust the shape of the facial area when the deformation of the face is detected. The method based on facial key point detection may result in false detection, resulting in poor image correction effect.

[0076] The image distortion correction method provided in this application can be applied to Figure 3 In the electronic device 300 shown, the electronic device 300 may be, but is not limited to, various smart phones, digital cameras, personal computers, laptop computers, tablet computers, etc. The electronic device 300 may be equipped with a camera 301, and the electronic device 300 obtains an original image by real-time shooting with the camera 301, and performs the image distortion correction method of the embodiment of the present application on the original image to perform distortion correction on the original image to obtain a corrected result image. The electronic device 300 may also include a display screen 302, so that the electronic device 300 can display the corrected result image on the display screen 302 in real time for the user to view. For example, when a user uses the camera 301 of the electronic device 300 to shoot an image, the image captured by the camera 301 can be previewed in real time on the display screen 302, and the user can view the previewed image on the display screen 302 at any time and perform a shooting operation.

[0077] In one embodiment, a method for image distortion correction is provided, which can be applied to Figure 3 In the electronic device 300 shown in FIG. 1 , the image distortion correction method of the present application refers to a method for correcting a distorted image taken with a wide-angle camera. Figure 4 As shown, the method includes the following steps S420-S460.

[0078] S420: Acquire an original image captured by a camera.

[0079] In this embodiment, the camera may be an ultra-wide-angle camera, and the lens in the ultra-wide-angle camera may be an ultra-wide-angle lens. In various embodiments of the present application, the camera may include various devices capable of capturing images, such as a camera head, a camera module, and the like.

[0080] The original image is an unprocessed image taken by a camera. In this embodiment, taking the method applied to an electronic device 300 as an example, the camera 301 of the electronic device 300 takes the original image in real time and transmits it to the processor of the electronic device 300, so that the electronic device 300 obtains the original image. In other embodiments, the original image may also be downloaded from the network or transmitted from other terminal devices to the electronic device 300, or the electronic device 300 may also read the original image from its own memory, etc.

[0081] S440: When the original image includes a foreground object, calculate the deformation degree of the foreground object.

[0082] The original image may or may not include a foreground object. Foreground objects, for example, refer to target objects captured within the field of view of the camera, such as portraits, animals, food, etc. In the original image, the part outside the foreground object is the background. The background refers to other content outside the target object captured within the field of view of the camera, such as distant mountains, sky, buildings, indoor or outdoor environments, etc. Compared with the foreground object, the background is usually farther away from the camera in the object space. Correspondingly, compared with the background, the foreground object is usually closer to the camera in the object space.

[0083] The degree of deformation of the foreground object refers to the degree of deformation of the shape of the foreground object in the original image relative to the original shape of the foreground object (for example, the shape presented when the foreground object is photographed using a standard lens).

[0084] S460: When the deformation degree of the foreground object is greater than a predetermined threshold, distortion correction and spherical projection are performed on the original image to obtain a result image.

[0085] Distortion correction refers to the correction of the deformation of the captured image caused by the distortion of the camera lens. Distortion mainly includes radial distortion and tangential distortion. The camera intrinsic parameters of the camera module can be used to correct the distortion of the original image. The camera intrinsic parameters are the inherent parameters of the camera. After the camera is manufactured, the intrinsic parameters of the camera are determined. The camera intrinsic parameters can be obtained from the manufacturer or by calibrating the camera.

[0086] The camera can be calibrated using a linear calibration method, a nonlinear optimization calibration method, a Zhang Zhengyou calibration method, or other common calibration methods. This application does not limit the calibration method, as long as the camera intrinsic parameters can be obtained. After obtaining the camera intrinsic parameters, the deformation of the captured original image caused by radial distortion and tangential distortion of the camera's own lens can be corrected according to the camera intrinsic parameters. The original image can be corrected for distortion using existing distortion correction technology, and the distortion correction algorithm is not limited in this embodiment.

[0087] Spherical projection is to deform an image to obtain the visual effect of projecting a flat image onto a spherical surface. It refers to correcting an image using a spherical perspective projection model and is a commonly used image processing method.

[0088] In this step, distortion correction and spherical projection are performed on all regions of the original image. For example, distortion correction and spherical projection can be performed on all pixel points in the original image. In this way, there is no need to distinguish between the foreground object and the background in the original image, which speeds up the image correction. Further preferably,

[0089] In the above embodiment, when there is a foreground object in the original image and the deformation degree of the foreground object is greater than a predetermined threshold, distortion correction and spherical projection are performed on the original image to avoid deformation of the foreground object due to the distortion correction, so that the correction effect of the foreground object in the result image is good, and the imaging is beautiful and natural. In addition, since the processing method of distortion correction and spherical projection has a small amount of calculation, the calculation requirements of the computing platform are low, and the result image can be previewed in real time.

[0090] For example, the image distortion correction method is applied to Figure 3 Taking the electronic device 300 as an example, the original image captured by the camera 301 is used to obtain a result image by using the image distortion correction method of this embodiment, and the result image can be displayed in real time on the display screen 302. According to the distortion correction method of the present application, the process of correcting the original image to obtain the result image only takes a few milliseconds, so the real-time preview of the result image will not be delayed, thereby improving the user experience.

[0091] refer to Figure 5 In one embodiment, the image distortion correction method according to the present application includes the following steps S520-S560.

[0092] S520: Acquire an original image captured by a camera.

[0093] The step S520 is the same as the above step S420 and will not be described again.

[0094] S530: Determine whether the original image includes a foreground object.

[0095] Taking the foreground object as a portrait as an example, the face detection technology is used on the original image to detect whether the original image includes a face. The face detection technology is, for example, Adaboost+haar detection, deep model detection, etc. If it is detected that the original image includes a face, it is determined that the original image includes a portrait; otherwise, it is determined that the original image does not include a portrait.

[0096] In other embodiments, the foreground object may be other target objects, such as animals, food, etc., which may be detected using corresponding neural network recognition techniques. It should be understood that the original image may include one or more foreground objects, or may not include a foreground object.

[0097] When it is determined that the original image includes a foreground object, the process proceeds to S540; otherwise, the process proceeds to S545.

[0098] S540: Calculate the deformation degree of the foreground object.

[0099] In one embodiment, calculating the deformation degree of the foreground object may include:

[0100] Acquire a foreground object frame in the original image, a position parameter of the foreground object frame, and a size parameter of the foreground object frame; and

[0101] The degree of deformation of the foreground object frame is calculated based on the position parameter of the foreground object frame and the size parameter of the foreground object frame.

[0102] Taking the foreground object as a portrait as an example, the foreground object bounding box may be a face bounding box. Exemplarily, the face bounding box may be obtained by a deep learning-based method. After obtaining the foreground object bounding box, the coordinates of the pixel points of the foreground object bounding box may be obtained, thereby obtaining the position parameters of the foreground object bounding box and the size parameters of the foreground object bounding box. It should be understood that when the original image includes multiple foreground objects, multiple foreground object bounding boxes corresponding to the multiple foreground objects are obtained respectively.

[0103] The coordinates of a pixel point refer to the coordinate values ​​of each pixel point in the image. For example, the coordinates of the pixel point at the upper left corner of the image can be set to (0,0), the coordinates of the pixel point adjacent to the right side of the pixel point at the upper left corner can be set to (1,0), the coordinates of the pixel point adjacent to the lower side of the pixel point at the upper left corner can be set to (0,1), and so on. It should be understood that the coordinates of the pixel points can also be set according to other rules, for example, the coordinates of the center point of the image can be set to (0,0), etc.

[0104] In a preferred embodiment, reference Figure 6 , the position parameters of the foreground object frame 602 include: the distance l1 between the foreground object frame 602 and the center point C of the original image 601 in the original image 601. For example, the distance between the point A at the upper left corner of the foreground object frame 602 and the center point C of the original image 601 can be obtained as the above distance l1. The distance can be determined by calculating the distance between the coordinates of the pixel point of point A and the coordinates of the pixel point of point C. It should be understood that the distance between other points in the foreground object frame 602 and the center point C of the original image 601 can also be obtained as the above distance l1.

[0105] The size parameters of the foreground object frame 602 include: the width w of the foreground object frame 602 and the height h of the foreground object frame 602. It should be understood that the above size parameters can also be determined by the coordinates of the pixels of the foreground object frame 602. For example, the height h of the foreground object frame 602 is obtained by subtracting the minimum value of the ordinate from the maximum value of the ordinate in the coordinates of the pixels of the foreground object frame 602; the width w of the foreground object frame 602 is obtained by subtracting the minimum value of the ordinate from the maximum value of the ordinate in the coordinates of the pixels of the foreground object frame 602.

[0106] In one embodiment, the deformation degree of the foreground object is calculated based on the following formula:

[0107] S=w1×l1+w2×l2.

[0108] Among them, S represents the deformation degree of the foreground object; l1 represents the distance between the foreground object border in the original image and the center point of the original image; l2 represents the larger value of the width of the foreground object border and the height of the foreground object border; w1 is the first weight value; w2 is the second weight value.

[0109] w1 and w2 are related to the influence of l1 and l2 on the deformation degree. It should be understood that the values ​​of w1 and w2 are associated with the values ​​of the predetermined thresholds and can be set according to actual conditions. In a preferred embodiment, w2 can be greater than w1. Figure 6 As shown, the size of the original image is the same as that of the result image. It should be understood that the coordinates of the center point of the original image are the same as those of the center point of the result image.

[0110] When it is detected in step S530 that the original image includes multiple foreground objects, the above formula may be applied to the foreground object frames corresponding to the multiple foreground objects respectively to calculate the deformation degrees of the multiple foreground objects respectively.

[0111] S545: Perform distortion correction on the original image to obtain a result image.

[0112] When the original image does not include a foreground image, since the distortion correction process will not cause serious deformation of the content of the original image, only the distortion correction can be performed on the original image to obtain a result image, thereby saving time for image correction processing.

[0113] S550: Determine whether the deformation degree is greater than a predetermined threshold.

[0114] As can be seen from the above steps, when multiple foreground objects are detected in step S530, the deformation degrees of the multiple foreground objects are respectively calculated in step S540. In this case, the foreground object with the largest deformation degree among the multiple foreground objects is obtained, and it is determined whether the deformation degree of the foreground object with the largest deformation degree is greater than a predetermined threshold.

[0115] If it is determined that the deformation degree is greater than the predetermined threshold, the process continues to step S560; otherwise, the process continues to step S565.

[0116] S560: Perform distortion correction and spherical projection on the original image to obtain a result image.

[0117] This step is similar to step S460 in the above embodiment and will not be described in detail here.

[0118] S565: Perform distortion correction on the original image to obtain a result image.

[0119] When the deformation degree of the foreground object does not exceed a predetermined threshold, since the distortion correction process will not cause serious deformation of the foreground object, only the distortion correction can be performed on the original image to obtain the result image, thereby saving the time for image correction processing.

[0120] For example, refer to Figure 1 , the closer the area is to the center point of the original image, the less obvious the image distortion is, and the closer the area is to the center point of the original image, the more serious the image distortion is. Therefore, if the foreground object is near the center point of the original image, there may be no distortion, or the degree of distortion is negligible. In this case, the distortion correction of the original image will cause little or no deformation to the foreground object.

[0121] refer to Figure 7In one embodiment, step S460 or step S560 specifically includes the following steps S720 and S740.

[0122] S720: Calculate the correspondence between the pixels of the result image and the pixels of the original image based on the spherical projection transformation formula and the distortion correction transformation formula.

[0123] See also Figure 8 ,(u i ,v i ) represents the coordinates of the pixel in the result image, u i is the horizontal axis, v i is the vertical axis. (u i ”,v i ”) represents the coordinates of the pixel in the original image, u i " is the horizontal axis, v i " is the vertical axis.

[0124] Perform distortion correction on the original image. The coordinates of the pixel points in the original image (u i ”,v i ”) is transformed into the coordinates of the pixel points after the distortion correction is performed on the original image (u i ',v i '); After the original image is distorted, the coordinates of the pixel points after distortion correction (u i ',v i ') is transformed into the coordinates of the pixel points in the result image through spherical projection (u i ,v i ). (u i ,v i ) and (u i ',v i ') corresponds to the spherical projection transformation, (u i ',v i ') and (u i ”,v i ”) corresponds to the distortion correction transformation, so (u i ,v i ) and (u i ”,v i ”) corresponds to. Figure 8 It should be understood that the pixel points after the distortion correction is performed on the original image are the pixel points before the spherical projection is performed on the result image.

[0125] In short, the pixel point (u i ,v i ) is transformed into the pixel point (u) in the original image through the distortion correction transformation and spherical projection transformation i ”,v i”).(u i ,v i ) represents the pixel value of the pixel in the result image and (u i ”,v i ”) corresponds to the pixel value of the pixel represented in the original image. Each pixel in the result image is mapped to a pixel in the original image.

[0126] After calculating the correspondence between the pixels of the result image and the pixels of the original image, the pixel values ​​of the pixels of the original image can be obtained. However, the coordinates of the pixels in the result image calculated by the spherical projection transformation and the distortion correction transformation corresponding to the coordinates of the pixels in the original image are usually not integers, that is, u i ” and v i " is usually not an integer. Therefore, the "pixel point of the original image" calculated according to the present application may not be a standard pixel in the image, and can be considered as a point in the original image. At this time, the pixel value of the pixel point of the original image whose coordinates are not integers can be obtained by using an interpolation algorithm (such as a bilinear interpolation algorithm, a bicubic interpolation algorithm, and a nearest neighbor interpolation algorithm). Taking the bilinear interpolation algorithm as an example, if the coordinates of the corresponding pixel point in the original image calculated by the spherical projection transformation and the distortion correction transformation are (1.1, 2.3), then the four pixel points with integer coordinate values ​​of (1, 2), (2, 2), (2, 3) and (1, 3) in the original image are used for bilinear interpolation calculation to obtain the pixel value of the pixel point in the original image with coordinates of (1.1, 2.3). Calculating pixel values ​​by interpolation algorithms is a common technique in image processing, and the specific calculation method will not be repeated here. It should be understood that various interpolation algorithms can be used to calculate pixel values, and the present application does not limit it.

[0127] In some embodiments, all pixel points in the result image are traversed, and the spherical projection transformation formula and the distortion correction transformation formula are applied to the coordinates of all pixel points in the result image to calculate the coordinates of the corresponding pixel points in the original image.

[0128] In other embodiments, preferably, the spherical projection transformation and the distortion correction transformation may be applied only to the coordinates of some pixel points in the result image. In this case, the result image may be divided into a plurality of rectangular blocks according to certain width intervals and height intervals, and the spherical projection transformation and the distortion correction transformation may be applied to the vertices of the plurality of rectangular blocks in the result image to calculate the coordinates of the corresponding pixel points in the original image. For the vertices of the rectangular blocks, this process is similar to the above embodiment and will not be described in detail here.

[0129] For other pixels in the result image (not vertex pixels), the coordinates of the pixels in the four original images mapped by the coordinates of the four vertices closest to the pixel are used to calculate the coordinates of the pixel in the original image corresponding to this pixel using a bilinear interpolation algorithm.

[0130] like Fig. 9 As shown, in this example, the result image 900 is divided into four rectangular blocks. For the vertices A1, B1, C1, D1, E1, F1, G1, H1 and I1 of the four rectangular blocks, spherical projection and distortion correction transformation are applied to calculate the pixel points A1', B1', C1', D1', E1', F1', G1', H1' and I1' of the original image 900' corresponding to these points, and obtain the coordinates of the pixel points of the original image 900' corresponding to these points. For the remaining pixel points, such as point K, the coordinates of the points A1', B1', D1' and E1' in the original image are used to calculate the coordinates of the corresponding pixel point K' of the original image 900' by using a bilinear interpolation algorithm.

[0131] In this way, by applying the spherical projection transformation formula and the distortion correction transformation formula to some pixel points and applying the bilinear interpolation algorithm to the remaining pixel points, the corresponding relationship between all pixel points in the result image and the pixel points in the original image is obtained, that is, the coordinates of the pixel points of the original image corresponding to all pixel points in the result image are obtained, and then the pixel values ​​of the pixel points of the original image are obtained using the interpolation algorithm. In this embodiment, there is no need to apply the spherical projection and distortion correction transformation formula to the coordinates of all pixel points in the result image, which further reduces the amount of calculation.

[0132] S740: Assign the pixel values ​​of the pixels of the original image to the pixels of the result image corresponding to the pixels of the original image to obtain the pixel values ​​of the pixels in the result image.

[0133] In this step, distortion correction and spherical projection are performed on the original image to obtain a result image. In actual processing, it is usually an inverse calculation. That is, for each pixel point in the result image, the corresponding pixel point of the original image is obtained through the spherical projection transformation formula and the distortion correction transformation formula, and the pixel value of the pixel point of the original image is assigned to the pixel point of the result image corresponding to the pixel point of the original image, so as to obtain the pixel value of each pixel point in the result image, thereby obtaining a result image with pixel values. In other words, when the inverse calculation is not performed through the spherical projection transformation formula and the distortion correction transformation formula, the pixel points in the result image do not have pixel values; by assigning pixel values ​​to the pixel points in the result image through the inverse calculation, a result image with pixel values ​​is obtained.

[0134] For example, for the pixel point (u0, v0) of the result image, the coordinates of the corresponding pixel point in the original image are calculated by the distortion correction transformation formula and the spherical projection transformation formula to be (u0", v0"); the pixel value (also called color value) of the pixel point with coordinates (u0", v0") in the original image is obtained, and then the pixel value is assigned to the pixel point (u0, v0) of the result image, so that the pixel value corresponding to the pixel point (u0, v0) of the result image is the same as the pixel value corresponding to the pixel point (u0", v0") of the original image.

[0135] In one embodiment, the spherical projection transformation formula is:

[0136]

[0137] Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r1 represents the distance from the pixel point of the result image to the center point of the result image, and r2 represents the distance from the pixel point of the distortion-corrected image to the center point of the result image; the pixel point of the result image (u i , v i ), the pixel point of the result image corresponds to the pixel point after distortion correction is performed on the original image (u i ',v i ') and the center points of the resulting image are on the same straight line.

[0138] In one embodiment, the distortion correction transformation is:

[0139]

[0140] Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y is the vertical offset of the image origin relative to the optical center imaging point; k1 is the first radial distortion coefficient of the camera, k2 is the second radial distortion coefficient of the camera, k3 is the third radial distortion coefficient of the camera, k4 is the fourth radial distortion coefficient of the camera, k5 is the fifth radial distortion coefficient of the camera, k6 is the sixth radial distortion coefficient of the camera, p1 is the first tangential distortion coefficient of the camera, and p2 is the second tangential distortion coefficient of the camera. Wherein, f x 、f y 、c x and c y are the intrinsic parameters of the camera, k1, k2, k3, k4, k5, k6, p1 and p2 are the distortion coefficients of the camera, which are the intrinsic parameters of the camera and are obtained by calibrating the camera.

[0141] Reference again Figure 6 According to the image correction method of the above embodiment, when there is a foreground object (such as a portrait) in the original image 601 and the deformation degree of the foreground object is greater than a predetermined threshold, the original image is subjected to distortion correction and spherical projection to obtain a result image 603. Figure 6 It can be seen that if only the distortion correction is performed on the original image 601, the portrait will be stretched and deformed; by using the correction method combining spherical projection with distortion correction, the spherical projection can compensate for the deformation of the foreground object caused by the distortion correction, and avoid the deformation of the foreground object due to the distortion correction, so that the correction effect of the foreground object in the resulting image is good, and the imaging is beautiful and natural. The image correction method according to the present application is particularly suitable for correcting ultra-wide-angle images including portraits. In ultra-wide-angle images, when the foreground object is a portrait, the user is more concerned about whether the portrait is deformed. Using the image correction method according to the present application, it is possible to avoid deformation of the portrait in the corrected image due to stretching.

[0142] In addition, since the distortion correction and spherical projection processing methods have a small amount of calculation, the calculation requirements of the computing platform are low, and the result image can be previewed in real time. Figure 3 The electronic device 300 shown. The electronic device 300 can display the corrected result image on the display screen 302 in real time for the user to view. For example, the original image taken by the camera 301 can be acquired at predetermined intervals (e.g., 1 millisecond), and the original image can be corrected using the distortion correction method according to the present application to obtain the result image. At the same time, in view of the frequent switching of the appearance / disappearance of faces in actual scenes, since the original image is acquired and corrected once at predetermined intervals, it is only necessary to determine whether the current original image has a portrait deformation greater than a predetermined degree during actual processing. During screen preview, a smooth transition between processing with and without portrait deformation can be achieved, thereby improving the user experience.

[0143] The image distortion correction method for ultra-wide-angle images proposed in this application can achieve rapid distortion correction of ultra-wide-angle images with low computational complexity and obtain good correction effect.

[0144] refer to Fig.10 On the other hand, the present application provides an image correction device 900, which includes: an image acquisition module 920, configured to acquire an original image taken by a camera; a deformation calculation module 940, configured to calculate the deformation degree of the foreground object when the original image includes a foreground object; and a correction calculation module 960, configured to perform distortion correction and spherical projection on the original image to obtain a result image when the deformation degree of the foreground object is greater than a predetermined threshold.

[0145] In one embodiment, the correction calculation module 960 is further configured to: when the original image does not include a foreground object, perform the distortion correction on the original image to obtain a result image; or when the deformation degree of the foreground object calculated by the deformation calculation module is not greater than the predetermined threshold, perform the distortion correction on the original image to obtain a result image.

[0146] In one embodiment, the deformation calculation module 940 is further configured to: obtain the foreground object border in the original image and the position parameters of the foreground object border and the size parameters of the foreground object border; and calculate the deformation degree of the foreground object based on the position parameters of the foreground object border and the size parameters of the foreground object border.

[0147] In one embodiment, the position parameters of the foreground object frame include: the distance between the foreground object frame in the original image and the center point of the original image; the size parameters of the foreground object frame include: the width of the foreground object frame and the height of the foreground object frame;

[0148] The deformation calculation module 940 is further configured to calculate the deformation degree of the foreground object frame based on the following formula:

[0149] S=w1×l1+w2×l2

[0150] Among them, S represents the degree of deformation; l1 represents the distance between the foreground object border in the original image and the center point of the original image; l2 represents the larger value between the width of the foreground object border and the height of the foreground object border; w1 is the first weight value; w2 is the second weight value.

[0151] In one embodiment, the correction calculation module 960 includes: a mapping calculation unit 962, configured to calculate the correspondence between the pixel points of the result image and the pixel points of the original image based on the spherical projection transformation and the distortion correction transformation; and a pixel assignment unit 964, configured to assign the pixel values ​​of the pixel points of the original image to the pixel points of the result image corresponding to the pixel points of the original image, so as to obtain the pixel values ​​of the pixel points in the result image.

[0152] In one embodiment, the mapping calculation unit 962 is further configured to: calculate the coordinates (u i ,v i ) corresponds to the coordinates of the pixel point after distortion correction is performed on the original image (u i ',v i'), the pixel points of the result image, the corresponding pixel points after the distortion correction is performed on the original image, and the center point of the result image are on the same straight line; based on the distortion correction transformation formula, the coordinates (u i ',v i ') corresponds to the coordinates of the pixel point of the original image (u i ”,v i ”);

[0153] The spherical projection transformation formula is:

[0154]

[0155] Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r1 represents the distance from the pixel point of the result image to the center point of the result image, and r2 represents the distance from the pixel point of the distortion-corrected image to the center point of the result image;

[0156] The distortion correction transformation is:

[0157]

[0158] Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y is the longitudinal offset of the image origin relative to the optical center imaging point; k1 is the first radial distortion coefficient of the camera, k2 is the second radial distortion coefficient of the camera, k3 is the third radial distortion coefficient of the camera, k4 is the fourth radial distortion coefficient of the camera, k5 is the fifth radial distortion coefficient of the camera, k6 is the sixth radial distortion coefficient of the camera, p1 is the first tangential distortion coefficient of the camera, and p2 is the second tangential distortion coefficient of the camera.

[0159] The image correction device of the present application corresponds one-to-one to the image correction method of the present application. The technical features and beneficial effects described in the embodiment of the above-mentioned image correction method are all applicable to the embodiment of the image correction device, and this is hereby declared.

[0160] For the specific definition of the image distortion correction device, please refer to the definition of the image distortion correction method above, which will not be repeated here. Each module in the above-mentioned image distortion correction device can be implemented in whole or in part by software, hardware and a combination thereof. 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 operations corresponding to the above modules.

[0161] According to another aspect of the present application, an electronic device is provided. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.12 As shown. The electronic device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores a step system and a computer program. The internal memory provides an environment for the operation of the step system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an image distortion correction method is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.

[0162] Those skilled in the art will understand that Fig.12 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0163] In one embodiment, an electronic 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.

[0164] 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.

[0165] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods 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 memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0166] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described 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 specification.

[0167] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for image distortion correction, It is characterized in that include: Get the original image taken by the camera; When the original image includes a foreground object, calculating the deformation degree of the foreground object; as well as When the deformation degree of the foreground object is greater than a predetermined threshold, performing distortion correction and spherical projection on the original image to obtain a result image; Wherein, when the deformation degree of the foreground object is greater than a predetermined threshold, performing distortion correction and spherical projection on the original image to obtain a result image includes: Based on the spherical projection transformation formula and the distortion correction transformation formula, calculating the correspondence between the pixel points of the result image and the pixel points of the original image; and Assigning the pixel values ​​of the pixels of the original image to the pixels of the result image corresponding to the pixels of the original image to obtain the pixel values ​​of the pixels in the result image; Among them, based on the spherical projection transformation formula and the distortion correction transformation formula, the corresponding relationship between the pixel points of the calculated result image and the pixel points of the original image includes: Based on the spherical projection transformation formula, the coordinates of the pixel points of the resulting image are calculated (u i ,v i ) corresponds to the coordinates of the pixel point after distortion correction is performed on the original image (u i ',v i '), the pixel points of the result image, the corresponding pixel points after distortion correction is performed on the original image, and the center point of the result image are on the same straight line; Based on the distortion correction transformation formula, the coordinates of the pixel points after the distortion correction of the original image are calculated (u i ',v i ') corresponds to the coordinates of the pixel point of the original image (u i ”,v i ”); The spherical projection transformation formula is: Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r 1 Represents the distance from the pixel of the result image to the center point of the result image, r 2 Represents the distance from the pixel of the distortion-corrected image to the center point of the result image; The distortion correction transformation is: Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y k is the vertical offset of the image origin relative to the optical center imaging point; 1 is the first radial distortion coefficient of the camera, k 2 is the second radial distortion coefficient of the camera, k 3 is the third radial distortion coefficient of the camera, k 4 is the fourth radial distortion coefficient of the camera, k 5 is the fifth radial distortion coefficient of the camera, k 6 is the sixth radial distortion coefficient of the camera, p 1 is the first tangential distortion coefficient of the camera, p 2 is the second tangential distortion coefficient of the camera.

2. The method according to claim 1, It is characterized in that The method further comprises: When the original image does not include a foreground object, performing the distortion correction on the original image to obtain a result image; or When the deformation degree of the foreground object is not greater than the predetermined threshold, the distortion correction is performed on the original image to obtain a result image.

3. The method according to claim 1, It is characterized in that When the original image includes a foreground object, calculating the deformation degree of the foreground object includes: Acquire a foreground object frame in the original image, a position parameter of the foreground object frame, and a size parameter of the foreground object frame; and The degree of deformation of the foreground object frame is calculated based on the position parameter of the foreground object frame and the size parameter of the foreground object frame.

4. The method according to claim 3, It is characterized in that The position parameters of the foreground object frame include: the distance between the foreground object frame and the center point of the original image in the original image; the size parameters of the foreground object frame include: the width of the foreground object frame and the height of the foreground object frame; The deformation degree of the foreground object is calculated based on the following formula S=w 1 ×l 1 +w 2 ×l 2 Among them, S represents the deformation degree of the foreground object; l 1 represents the distance between the foreground object border in the original image and the center point of the original image; l 2 represents the larger value of the width of the foreground object frame and the height of the foreground object frame; w 1 is the first weight value; w 2 is the second weight value.

5. An image correction device, It is characterized in that include: An image acquisition module, configured to acquire an original image taken by a camera; a deformation calculation module, configured to calculate the deformation degree of the foreground object when the original image includes the foreground object; as well as a correction calculation module, configured to perform distortion correction and spherical projection on the original image to obtain a result image when the deformation degree of the foreground object is greater than a predetermined threshold; Wherein, the correction calculation module includes: A mapping calculation unit configured to calculate the correspondence between the pixel points of the result image and the pixel points of the original image based on the spherical projection transformation formula and the distortion correction transformation formula; and a pixel assignment unit configured to assign pixel values ​​of pixels of the original image to pixels of the result image corresponding to the pixels of the original image to obtain the result image; and The mapping calculation unit is further configured as: Based on the spherical projection transformation formula, the coordinates of the pixel points of the resulting image are calculated (u i ,v i ) corresponds to the coordinates of the pixel point after distortion correction is performed on the original image (u i ',v i '), the pixel points of the result image, the corresponding pixel points after distortion correction is performed on the original image, and the center point of the result image are on the same straight line; Based on the distortion correction transformation formula, the coordinates of the pixel points after the distortion correction of the original image are calculated (u i ',v i ') corresponds to the coordinates of the pixel point of the original image (u i ”,v i ”); The spherical projection transformation formula is: Wherein, d represents the smaller value of the width and height of the original image; f represents the focal length of the camera; r 1 Represents the distance from the pixel of the result image to the center point of the result image, r 2 Represents the distance from the pixel of the distortion-corrected image to the center point of the result image; The distortion correction transformation is: Among them, f x is the first focal length of the camera, f y is the second focal length of the camera, c x is the lateral offset of the image origin relative to the optical center imaging point, c y k is the vertical offset of the image origin relative to the optical center imaging point; 1 is the first radial distortion coefficient of the camera, k 2 is the second radial distortion coefficient of the camera, k 3 is the third radial distortion coefficient of the camera, k 4 is the fourth radial distortion coefficient of the camera, k 5 is the fifth radial distortion coefficient of the camera, k 6 is the sixth radial distortion coefficient of the camera, p 1 is the first tangential distortion coefficient of the camera, p 2 is the second tangential distortion coefficient of the camera.

6. The image correction device according to claim 5, It is characterized in that The correction calculation module is also configured as: When the original image does not include a foreground object, performing the distortion correction on the original image to obtain a result image; or When the deformation degree of the foreground object calculated by the deformation calculation module is not greater than the predetermined threshold, the distortion correction is performed on the original image to obtain a result image.

7. The image correction device according to claim 5, It is characterized in that The deformation calculation module is also configured as: Acquire a foreground object frame in the original image, a position parameter of the foreground object frame, and a size parameter of the foreground object frame; as well as The degree of deformation of the foreground object is calculated based on the position parameter of the foreground object frame and the size parameter of the foreground object frame.

8. The image correction device according to claim 7, It is characterized in that The position parameters of the foreground object frame include: the distance between the foreground object frame and the center point of the original image in the original image; the size parameters of the foreground object frame include: the width of the foreground object frame and the height of the foreground object frame; The deformation calculation module is further configured to calculate the deformation degree of the foreground object frame based on the following formula: S=w 1 ×l 1 +w 2 ×l 2 Among them, S represents the degree of deformation; l 1 represents the distance between the foreground object border in the original image and the center point of the original image; l 2 represents the larger value of the width of the foreground object frame and the height of the foreground object frame; w 1 is the first weight value; w 2 is the second weight value.

9. An electronic device, comprising a memory and a processor, wherein the memory is connected to the processor; The memory stores a computer program; When the processor executes the computer program, the image distortion correction method according to any one of claims 1 to 4 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the image distortion correction method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Method for fusing image data of medium-high speed sensor network

    CN101930603A

  • Hardware-based human presence detection

    CN103140858A

  • Large-viewing-angle image distortion correction and processing method

    CN103426149A

  • Display system with optical lens and display screen and image display method thereof

    CN104020565A

  • Method and device for finding distorted region in image

    CN105227948A