Image correction method, device and electronic device
By selecting the target line from the edge image and determining the target distortion correction model, correcting the images captured by the camera, the image distortion problem caused by lens distortion is solved, and an efficient image correction effect is achieved.
Patent Information
- Application Number
- CN202111300615.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-04
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2041-11-04
AI Technical Summary
The images captured by the camera are distorted due to lens distortion, and the prior art is difficult to effectively correct.
By selecting the target line from the edge image, the target distortion correction model is determined and the original image is corrected using this model. The width of the image and the specified abscissa value are considered during the correction process to reduce the loss of the field of view angle.
Adaptive correction of image distortion caused by lens distortion is achieved, reducing the loss of image field angle and ensuring the clarity and accuracy of the image.
Smart Images

Figure CN114187188B_ABST
Abstract
Description
Technical Field
[0001] This application relates to image processing technology, and particularly to an image correction method, apparatus, and electronic device. Background Art
[0002] Due to manufacturing precision of lenses in a camera and deviations in assembly processes, etc., distortion will be introduced, which will in turn cause distortion in the images captured by the camera. For example, the distortion here is the distortion distributed along the radius direction of the lens (which can be called radial distortion), and the reason for its generation is that light bends more at places far from the center of the lens than at places close to the center. Figure 1 Barrel distortion in radial distortion is illustrated by way of example. Another example is that the distortion here is the distortion generated due to the lens itself not being parallel to the camera sensor plane (imaging plane) or the image plane (which can be called tangential distortion), and the reason for its generation is mostly due to installation deviation when the lens is adhered to the lens module. Summary of the Invention
[0003] Embodiments of this application provide an image correction method, apparatus, and electronic device to correct images captured during lens distortion.
[0004] Embodiments of this application provide an image correction method, which includes:
[0005] Select a target line from the obtained edge image; wherein, the number of pixel points belonging to the target line in the edge image is greater than a set number, and the edge image is obtained by performing edge detection on the original image;
[0006] Determine a target distortion correction model based on the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line;
[0007] Use the target distortion correction model to correct the original coordinate information of each pixel point in the pixel coordinate system in the original image to obtain the target correction coordinate information corresponding to each pixel point;
[0008] Use the width of the original image and the specified abscissa value in the original image to correct the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image; wherein, the closer the abscissa value in the target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
[0009] Embodiments of this application provide an image correction apparatus, which includes:
[0010] A selection unit, configured to select a target line from the obtained edge image; wherein, the number of pixel points belonging to the target line in the edge image is greater than a set number, and the edge image is obtained by performing edge detection on the original image;
[0011] A target unit, configured to determine a target distortion correction model according to the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line;
[0012] A correction unit, configured to correct the original coordinate information of each pixel point in the pixel coordinate system of the original image by using the target distortion correction model to obtain the target correction coordinate information corresponding to each pixel point; and,
[0013] correct the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image by using the width of the original image and the specified abscissa value in the original image; wherein, the closer the abscissa value in the target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
[0014] An embodiment of the present application further provides an electronic device. The electronic device includes: a processor and a machine-readable storage medium;
[0015] The machine-readable storage medium stores machine-executable instructions that can be executed by the processor;
[0016] The processor is configured to execute the machine-executable instructions to implement the steps of the method disclosed above.
[0017] It can be seen from the above technical solutions that in the embodiment of the present application, by selecting a target line from the edge image and determining a target distortion correction model according to the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line, and correcting the original image by using the target distortion correction model, so as to implement the correction of the image taken when the lens is distorted, and an adaptive distortion correction method is realized.
[0018] Further, in this embodiment, the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image is further corrected by using the width of the original image and the specified abscissa value in the original image, which further reduces the loss of the image field of view as much as possible on the premise of ensuring that the image distortion meets the requirements. Description of the Drawings
[0019] The drawings here are incorporated into the specification and constitute a part of this specification, showing the embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure.
[0020] Figure 1 Schematic diagram of radial distortion provided by an embodiment of the present application;
[0021] Figure 2 Flowchart of the method provided by an embodiment of the present application;
[0022] Figures 3a to 3d Schematic diagrams before and after field of view angle correction provided by an embodiment of the present application;
[0023] Figure 4 Flowchart of the implementation of step 201 provided by an embodiment of the present application;
[0024] Figure 5 Schematic diagram of the pixel coordinate system and the representation in the Hough space provided by an embodiment of the present application;
[0025] Figure 6 Flowchart of the determination of the target line provided by an embodiment of the present application;
[0026] Figures 7a to 7d Schematic diagrams before and after the correction of the distorted image provided by an embodiment of the present application;
[0027] Figures 8a to 8d Another schematic diagram of the distorted image before and after correction provided by an embodiment of the present application;
[0028] Figure 9 Structure diagram of the device provided by an embodiment of the present application;
[0029] Figure 10 Structure diagram of the electronic device provided by an embodiment of the present application. Detailed implementation manners
[0030] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0031] The terms used in the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. The singular forms "a", "the", and "said" used in the present application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0032] To enable those skilled in the art to better understand the technical solutions provided by the embodiments of the present application and make the above-mentioned objects, features, and advantages of the embodiments of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0033] See Figure 2 , Figure 2 which is a flowchart of the method provided by the embodiment of the present application. As an embodiment, this process can be applied to front-end devices such as cameras, video cameras, and other image acquisition devices with image acquisition functions. As another embodiment, this process can also be applied to back-end devices such as platforms, servers, etc. This embodiment does not specifically limit the devices to which the method provided by the embodiment of the present application is applied.
[0034] As Figure 2 shown, this process may include the following steps:
[0035] Step 201, select a target line from the obtained edge image.
[0036] Here, the edge image is obtained by performing edge detection on the original image. Optionally, to ensure the image correction effect, the original image here can be an image with a relatively rich straight-line scene in the captured image, such as a zebra crossing image, a building image, etc.
[0037] In this embodiment, there are various optional edge detection (gradient) operators when performing edge detection on the original image, such as ordinary first-order difference operators, Robert operators (cross differences), Sobel operators, Canny operators, etc. Taking the selection of the Canny operator as the edge detection algorithm to perform edge detection on the original image as an example, first, the Gaussian filter can be used to filter the original image to smooth the image and filter out noise. Then, calculate the gradient intensity and direction of each pixel point in the filtered image. Based on the calculated gradient intensity and direction of each pixel point, first use the non-maximum suppression algorithm to eliminate the stray responses brought by edge detection, and then use double-threshold detection to determine the real and potential edges. Finally, suppress the isolated weak edges to finally complete the edge detection and obtain the edge image.
[0038] After obtaining the edge image, as described in step 201, a target line can be selected from the edge image. Optionally, as an embodiment, the selected target line may satisfy the following conditions: the number of pixel points belonging to the target line in the edge image is greater than a set number, and the set number can be set according to actual needs. Preferably, in an example, the selected target line may be a line in the edge image where the number of pixel points belonging to the target line is greater than the set number, and the target line is a line with the most pixel points in the edge image (that is, the number of pixel points belonging to the target line in the edge image is greater than the number of pixel points on any other line in the edge image).
[0039] Step 202: Determine the target distortion correction model based on the original coordinate information of the pixel points belonging to the target line in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line.
[0040] Optionally, in this embodiment, a straight line equation can be fitted based on the original coordinate information of the pixel points belonging to the target line in the pixel coordinate system. Then, for each pixel point, if the abscissa value of the pixel point is used as a reference, the abscissa value of the pixel point is substituted into the straight line equation to obtain the corresponding theoretical ordinate value, and the abscissa value of the pixel point and the above-mentioned theoretical ordinate value are used as the theoretical coordinate information of the pixel point. Similarly, if the ordinate value of the pixel point is used as a reference, the ordinate value of the pixel point is substituted into the straight line equation to obtain the corresponding theoretical abscissa value, and the theoretical abscissa value of the pixel point and the ordinate value in the original coordinate information of the pixel point are used as the theoretical coordinate information of the pixel point. Finally, the theoretical coordinate information of each pixel point belonging to the above target line will be obtained.
[0041] After that, as described in step 202, the target distortion correction model can be determined based on the original coordinate information of the pixel points belonging to the target line in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line. Optionally, as an embodiment, in the process of determining the target distortion correction model in step 202, the target distortion correction model can be calculated first based on the original coordinate information of the pixel points belonging to the target line in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line as shown in Formula 1:
[0042] L(r) = 1 + k1r 2 + k2r 4 (Formula 1)
[0043] where L(r) is the target distortion correction model, k1 and k2 are the first two-order distortion parameters of the target distortion model, and r is the pixel point to be corrected and the specified point (x c , yc ) distance. Optionally, for the original image before and after correction, its height and width do not change. Correspondingly, the change in the original coordinate information of the pixel point at the center (referred to as the central pixel point) before and after correction is also small. Based on this, as an embodiment, the specified pixel point (x c , y c ) can be the original coordinate information of the central pixel point in the original image.
[0044] It should be noted that the embodiments of the present invention do not specifically limit the method for determining the target distortion correction model. As long as the original coordinate information of the pixel points belonging to the target line in the above-mentioned edge image in the pixel coordinate system and the theoretical coordinate information of the pixel point calculated based on the straight line equation corresponding to the target line are obtained, then naturally the existing model determination method can be referred to, and based on the original coordinate information of the pixel points belonging to the target line in the pixel coordinate system and the theoretical coordinate information of the pixel point calculated based on the straight line equation corresponding to the target line, the target distortion correction model is determined.
[0045] Step 203: Use the target distortion correction model to correct the original coordinate information of each pixel point in the original image in the pixel coordinate system to obtain the target correction coordinate information corresponding to each pixel point.
[0046] As an embodiment, optionally, the above formula 1 can be converted into the following formula 2:
[0047]
[0048] Based on this, for each pixel point in the original image, determine the distance r between the pixel point and the above central pixel point based on the original coordinate information of the pixel point in the pixel coordinate system, then substitute it into formula 1 to obtain L(r), and then substitute the obtained L(r) into the above formula 2 to finally obtain the target correction coordinate information corresponding to the pixel point. It should be noted that the above formula 1 and formula 2 are only examples of correction and are not used for limitation.
[0049] Step 204: Use the width of the original image and the specified abscissa value in the original image to correct the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image.
[0050] This step 204 is a field of view angle correction to expand the horizontal field of view angle of the original image. Optionally, as an embodiment, this step 204 can correct the abscissa value in the target correction coordinate information corresponding to each pixel point through the following formula 3:
[0051]
[0052] In Formula 3, x` is the abscissa value after correction in the target correction coordinate information, x is the abscissa value before correction in the target correction coordinate information, C x is the specified abscissa value, and s x is the set correction coefficient.
[0053] Optionally, as described above, the original coordinate information of the specified pixel point (x c , y c ) doesn't differ much before and after correction. Based on this, the specified abscissa value C x can be the abscissa value x c of the above-specified pixel point.
[0054] Additionally, optionally, the correction coefficient s x here can be set according to the actual situation, for example, as a value in the interval (0.95, 1).
[0055] In this embodiment, the closer the abscissa value in the above target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
[0056] It should be noted that using Formula 3 to correct the abscissa value in the target correction coordinate information corresponding to other pixel points in the original image is just an example and not for limitation.
[0057] Taking the abscissa value of the central pixel point in the original image as the specified abscissa value as an example, based on the above formula, when the abscissa value x to be corrected in the target correction coordinate information satisfies the following condition: 0 <= x <= C x , specifically as Figure 3a shown, then finally, the correction of each abscissa value in [0, C x to be corrected is as Figure 3b shown.
[0058] Taking another example, when the abscissa value x to be corrected in the target correction coordinate information satisfies the following condition: C x <= x <= width, specifically as Figure 3c shown, then finally, the correction of each abscissa value in [C x , width] to be corrected is as Figure 3d shown
[0059] Through Figures 3a to 3dIt can be seen that in this embodiment, when the abscissa value x to be corrected in the target correction coordinate information is closer to the above-specified abscissa value (taking the abscissa value of the central pixel point as an example), the correction amplitude of the abscissa value x is smaller and closer to 1. On the contrary, when the abscissa value x to be corrected in the target correction coordinate information is closer to the left and right sides of the original image (far from the above-specified abscissa value), the correction amplitude of the abscissa value x is larger and closer to sigma.
[0060] So far, the Figure 2 shown process is completed.
[0061] Through the Figure 2 shown process,
[0062] In this embodiment, by selecting a target line from the edge image, based on the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line, a target distortion correction model is determined. The original image is corrected by this target distortion correction model to realize the correction of the image taken when the lens is distorted, and an adaptive distortion correction method is realized.
[0063] Furthermore, in this embodiment, the width of the original image and the specified abscissa value in the original image are further used to correct the abscissa values in the target correction coordinate information corresponding to other pixel points in the original image, which further reduces the loss of the image field of view as much as possible on the premise of ensuring that the image distortion meets the requirements.
[0064] Next, an example of selecting a target line from the obtained edge image in step 201 above is described.
[0065] Refer to Figure 4 , Figure 4 which is the implementation flowchart of step 201 provided by the embodiment of the present application. Optionally, this implementation process can be realized by an improved Hough transform method to detect the distorted straight lines and curved straight lines in the image.
[0066] As Figure 4 shown, this process may include the following steps:
[0067] Step 401, map each pixel point in the edge image from the pixel coordinate system to the Hough space in the polar coordinate system, and obtain the mapped pixel points in the Hough space that have a mapping relationship with each pixel point in the edge image.
[0068] Optionally, in this embodiment, by specifying a coordinate conversion method (for the conversion between the pixel coordinate system and the Hough space in the polar coordinate system), each pixel point in the edge image can be mapped from the pixel coordinate system to the Hough space in the polar coordinate system, and mapping pixel points in the Hough space that have a mapping relationship with each pixel point in the edge image are obtained. For example, each pixel point in the edge image is mapped from the pixel coordinate system to the Hough space in the polar coordinate system through the following formula 4:
[0069] ρ = xcos(θ) + ysin(θ) (Formula 4)
[0070] In Formula 4, [x, y] represents the coordinates of the pixel point in the edge image in the pixel coordinate system, and [ρ, θ] represents the coordinate values of the mapping pixel point in the polar coordinate system. Optionally, the value range of ρ is [0, r_max], where r_max is the length of the image diagonal in the edge image. The value range of θ is [0, 180].
[0071] Step 402, statistically determine at least one target mapping pixel point in the Hough space; wherein, the number of pixel points in the edge image mapped by the target mapping pixel points in the Hough space is greater than the number of pixel points in the edge image mapped by the non-target mapping pixel points in the Hough space.
[0072] Optionally, in this embodiment, a polar coordinate point coordinate information table with a size of r_max * 180 can be made in advance. Then, for each pixel point in the edge image, determine the polar coordinate point (i.e., the mapping pixel point) in the table to which the pixel point is mapped. When there is no mapping quantity mark for this polar coordinate point (i.e., the mapping pixel point), set a mapping quantity mark for this polar coordinate point and set the mapping quantity mark to a first value. When there is a mapping quantity mark for this polar coordinate point (i.e., the mapping pixel point), increase the mapping quantity mark of this polar coordinate point by the first value on the basis of the current value. And so on. Then, sort the polar coordinate points (i.e., the mapping pixel points) in descending order according to the values of the mapping quantity marks, and the first n polar coordinate points (i.e., the mapping pixel points) in the sequence are the above-mentioned target mapping pixel points.
[0073] Step 403, find the corresponding initial lines in the edge image according to each target mapping pixel point, and determine the target lines according to the determined initial lines.
[0074] In this embodiment, a straight line in the pixel coordinate system corresponds to a point in the Hough space. Similarly, a point in the Hough space corresponds to a straight line in the pixel coordinate system. Specifically, as Figure 5 shown. Based on this, this embodiment can determine the initial lines corresponding to each target mapping pixel point in the Hough space in the edge image according to the representation method as Figure 5 shown.
[0075] After that, determine the above-mentioned target line according to each determined initial line. For example, select the one with the most pixels or the longest one from all the initial lines as the target line; or, the target line can be determined with reference to the Figure 6 method.
[0076] Refer to Figure 6 , Figure 6 which is the flowchart for determining the target line provided by the embodiment of the present application. As Figure 6 shown, this process may include the following steps:
[0077] Step 601: Determine all the initial lines as the current lines; select the longest reference line from all the current lines, and determine the reference distortion correction model according to the original coordinate information of the pixels belonging to the reference line in the pixel coordinate system in the edge image and the theoretical coordinate information of this pixel calculated based on the straight line equation corresponding to the reference line.
[0078] Optionally, in this embodiment, the method for determining the reference distortion correction model is similar to the method for determining the target distortion correction model in step 202 above, and will not be elaborated here.
[0079] Step 602: For each pixel in the edge image, correct the original coordinate information of this pixel in the pixel coordinate system according to the reference distortion correction model to obtain the reference correction coordinate information corresponding to this pixel, and determine whether this pixel is a candidate pixel according to the original coordinate information of this pixel in the edge image and the reference correction coordinate information after this pixel is corrected.
[0080] Optionally, in this embodiment, the method for correcting the original coordinate information of this pixel in the pixel coordinate system according to the reference distortion correction model is similar to the correction method in step 203 above, and will not be elaborated here.
[0081] As an embodiment, in this step 602, determining whether this pixel is a candidate pixel according to the original coordinate information of this pixel in the edge image and the reference correction coordinate information after this pixel is corrected may include:
[0082] For each pixel, calculate the Euclidean distance between the original coordinate information of this pixel in the edge image and the reference correction coordinate information after this pixel is corrected;
[0083] When the Euclidean distance is less than the first set distance threshold, determine that this pixel is a candidate pixel, otherwise, determine that this pixel is not a candidate pixel. Optionally, the first set distance threshold here can be set according to actual needs. For example, it can be set to the size of 8 pixels.
[0084] Step 603: Determine the target pixel points belonging to each current line from all the determined candidate pixel points, perform fitting processing based on the current line and the determined target pixel points belonging to the current line to obtain the fitting line corresponding to the current line, and when there is a current iteration count, increase the recorded iteration count by a first value, otherwise, set the iteration count to the first value; when the current value of the iteration count is less than the set value, determine all the fitting lines as the current lines, and return to the step of selecting the longest reference line from all the current lines, otherwise, select the longest one from all the fitting lines as the target line.
[0085] Optionally, in this embodiment, determining the target pixel points belonging to each current line from all the determined candidate pixel points may include:
[0086] Perform the following step a for each current line:
[0087] Step a: For each candidate pixel point, determine whether the direction difference between the current line and the candidate pixel point after both are mapped to the Hough space is less than the set direction threshold. When the direction difference is less than or equal to the set direction threshold, if the distance from the candidate pixel point to the current line is less than or equal to the second set distance threshold, determine that the candidate pixel point is a target pixel point belonging to the current line. When the direction difference is greater than the set direction threshold, or when the direction difference is less than the set direction threshold but the distance from the candidate pixel point to the current line is greater than the second set distance threshold, determine that the candidate pixel point does not belong to the target pixel points of the current line. Optionally, the second set distance threshold can be set according to actual needs, such as the size of 3 pixel points. In this embodiment, the distance from the candidate pixel point to the current line can be calculated according to the following formula 5 for example:
[0088]
[0089] In formula 5, d i is the Euclidean distance from the candidate edge point to the current line (the i-th (1 <= i <= n) straight line). v i represents the calculated distance from the candidate pixel point to the current line.
[0090] Thus, the Figure 6 shown process is completed.
[0091] Through the above Figure 5 、 Figure 6 shown process, the embodiment of the present application provides improved line detection. Through this improved line detection, even for an image with relatively severe distortion, continuous lines can be detected.
[0092] The method provided by the embodiment of the present application has been described above.
[0093] By the above method provided by the embodiments of the present application, when a distorted image as shown in Figure 7a is captured at a field of view angle of 125 degrees, an edge image as shown in Figure 7b can be obtained by performing edge detection on the distorted image. Then, line detection is performed on the edge image shown in 7b through the process as shown in Figures 4 to 6 to obtain a line as shown in Figure 7c . Based on the line shown in Figure 7c , a target distortion correction model is determined, and the distorted image as shown in Figure 7a is corrected by using the target distortion correction model. The corrected image is as shown in Figure 7d . Through comparison, it can be found that the distortion correction effect is as shown in Table 1:
[0094] Table 1
[0095] Field of view Geometric distortion Before correction 125 -39.7% After correction 114 (field of view loss 8.8%) -9.7%
[0096] Similarly, by the above method provided by the embodiments of the present application, when a distorted image as shown in Figure 8a is captured at a field of view angle of 128 degrees, an edge image as shown in Figure 8b can be obtained by performing edge detection on the distorted image. Then, line detection is performed on the edge image shown in 8b through the process as shown in Figures 4 to 6 to obtain a line as shown in Figure 8c . Based on the line shown in Figure 8c , a target distortion correction model is determined, and the distorted image as shown in Figure 8a is corrected by using the target distortion correction model. The corrected image is as shown in Figure 8d . Through comparison, it can be found that the distortion correction effect is as shown in Table 2:
[0097] Table 2
[0098] Field of view Geometric distortion Before correction 128 -42.9% After correction 117 (field of view loss 8.6%) -11.2%
[0099] The method provided by the embodiments of the present application has been described above. Next, the device provided by the embodiments of the present application will be described:
[0100] Referring to Figure 9 , Figure 9 is the structural diagram of the device provided by the embodiments of the present application. The device includes:
[0101] A selection unit, configured to select a target line from the obtained edge images; wherein, the number of pixel points belonging to the target line in the edge image is greater than a set number, and the edge image is obtained by performing edge detection on the original image;
[0102] A target unit, configured to determine a target distortion correction model according to the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight-line equation corresponding to the target line;
[0103] A correction unit, configured to correct the original coordinate information of each pixel point in the pixel coordinate system in the original image by using the target distortion correction model to obtain the target correction coordinate information corresponding to each pixel point; and,
[0104] correct the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image by using the width of the original image and the specified abscissa value in the original image; wherein, the closer the abscissa value in the target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
[0105] Optionally, the selection unit selecting a target line from the obtained edge images includes:
[0106] Mapping each pixel point in the edge image from the pixel coordinate system to the Hough space in the polar coordinate system to obtain the mapped pixel points in the Hough space that have a mapping relationship with each pixel point in the edge image;
[0107] Counting at least one target mapped pixel point in the Hough space; wherein, the number of pixel points in the edge image mapped by the target mapped pixel points in the Hough space is greater than the number of pixel points in the edge image mapped by the non-target mapped pixel points in the Hough space;
[0108] Finding the corresponding initial line according to each target mapped pixel point in the edge image, and determining the target line according to the determined initial lines.
[0109] Optionally, the selection unit determining the target line according to the determined initial lines includes:
[0110] Selecting the longest one from all the initial lines as the target line; or,
[0111] Determining all the initial lines as the current lines; selecting a reference line with the most pixel points from all the current lines, and determining a reference distortion correction model according to the original coordinate information of the pixel points belonging to the reference line in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight-line equation corresponding to the reference line;
[0112] For each pixel point in the edge image, correct the original coordinate information of the pixel point in the pixel coordinate system according to the reference distortion correction model to obtain the reference correction coordinate information corresponding to the pixel point, and determine whether the pixel point is a candidate pixel point according to the original coordinate information of the pixel point in the edge image and the reference correction coordinate information after the pixel point is corrected;
[0113] Determine the target pixel points belonging to each current line from all the determined candidate pixel points, perform fitting processing according to the current line and the determined target pixel points belonging to the current line to obtain the fitting line corresponding to the current line, and when there is a current iteration count, increase the recorded iteration count by a first value, otherwise, set the iteration count to the first value; when the current value of the iteration count is less than the set value, determine all the fitting lines as the current lines, and return to the step of selecting the longest reference line from all the current lines, otherwise, select the longest one from all the fitting lines as the target line.
[0114] Optionally, the selection unit determines whether the pixel point is a candidate pixel point according to the original coordinate information of the pixel point in the edge image and the reference correction coordinate information after the pixel point is corrected, including:
[0115] For each pixel point, calculate the Euclidean distance between the original coordinate information of the pixel point in the edge image and the reference correction coordinate information after the pixel point is corrected;
[0116] When the Euclidean distance is less than the first set distance threshold, determine that the pixel point is a candidate pixel point, otherwise, determine that the pixel point is not a candidate pixel point.
[0117] Optionally, the selection unit determines the target pixel points belonging to each current line from all the determined candidate pixel points, including:
[0118] Perform the following steps for each current line:
[0119] For each candidate pixel point, determine whether the direction difference between the current line and the candidate pixel point after both are mapped to the Hough space is less than the set direction threshold. When the direction difference is less than or equal to the set direction threshold, if the distance from the candidate pixel point to the current line is less than or equal to the second set distance threshold, determine that the candidate pixel point is a target pixel point belonging to the current line. When the direction difference is greater than the set direction threshold, or when the direction difference is less than the set direction threshold but the distance from the candidate pixel point to the current line is greater than the second set distance threshold, determine that the candidate pixel point does not belong to the target pixel points of the current line.
[0120] Optionally, the correction unit corrects the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image by using the width of the original image and the specified abscissa value in the original image, including:
[0121] The abscissa value in the target correction coordinate information corresponding to each pixel point is corrected by the following formula:
[0122]
[0123] where x` is the corrected abscissa value in the target correction coordinate information, x is the abscissa value before correction in the target correction coordinate information, C x is the specified abscissa value, and s x is the set correction coefficient.
[0124] So far, the structural description of the Figure 9 shown device is completed.
[0125] The embodiment of the present application also provides Figure 9 the hardware structure of the shown device. Refer to Figure 10 , Figure 10 which is the structural diagram of the electronic device provided by the embodiment of the present application. As Figure 10 shown, the hardware structure may include: a processor and a machine-readable storage medium, and the machine-readable storage medium stores machine-executable instructions that can be executed by the processor; the processor is used to execute the machine-executable instructions to implement the method disclosed in the above examples of the present application.
[0126] Based on the same application concept as the above method, the embodiment of the present application also provides a machine-readable storage medium, on which a number of computer instructions are stored, and when the computer instructions are executed by a processor, the method disclosed in the above examples of the present application can be implemented.
[0127] Exemplarily, the above machine-readable storage medium can be any electronic, magnetic, optical or other physical storage device, which can contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium can be: RAM (Random Access Memory, random access memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), solid state drive, any type of storage disk (such as optical disk, dvd, etc.), or similar storage media, or a combination thereof.
[0128] The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, and the specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver device, a game console, a tablet computer, a wearable device, or a combination of any several of these devices.
[0129] For the convenience of description, when describing the above devices, they are described as various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in one or more software and / or hardware.
[0130] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0131] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0132] Moreover, these computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing devices to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0133] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are executed on the computer or other programmable apparatus to generate a computer-implemented process, thereby providing instructions for implementing the process Figure 1 in one process or multiple processes and / or blocks Figure 1 the steps of the functions specified in one block or multiple blocks.
[0134] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. An image correction method, characterized in that, The method includes: Selecting a target line from the obtained edge image; wherein, the number of pixel points belonging to the target line in the edge image is greater than a set number, and the edge image is obtained by performing edge detection on the original image; the target line is determined based on an initial line found in the edge image according to each target mapped pixel point; the target mapped pixel point is statistically obtained from each pixel point in the edge image after mapping from the pixel coordinate system to the Hough space in the polar coordinate system; the target line is the longest one among all the initial lines, or the target line is determined based on line detection; the line detection can also detect continuous target lines when applied to an edge image with severe distortion; Determining a target distortion correction model based on the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line; Correcting the original coordinate information of each pixel point in the pixel coordinate system in the original image by using the target distortion correction model to obtain the corresponding target correction coordinate information of each pixel point; Correcting the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image by using the width of the original image and the specified abscissa value in the original image; wherein, the closer the abscissa value in the target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
2. The method according to claim 1, wherein The selecting a target line from the obtained edge image includes: Mapping each pixel point in the edge image from the pixel coordinate system to the Hough space in the polar coordinate system to obtain mapped pixel points in the Hough space that have a mapping relationship with each pixel point in the edge image; Statistically obtaining at least one target mapped pixel point in the Hough space; wherein, the number of pixel points in the edge image mapped by the target mapped pixel point in the Hough space is greater than the number of pixel points in the edge image mapped by the non-target mapped pixel point in the Hough space; Finding the corresponding initial line in the edge image according to each target mapped pixel point, and determining the target line according to the determined initial lines; 3. The method according to claim 2, characterized in that, The determining the target line according to the determined initial lines includes: Selecting the longest one from all the initial lines as the target line; or, Determining all the initial lines as the current lines; selecting a reference line with the most pixel points from all the current lines, and determining a reference distortion correction model based on the original coordinate information of the pixel points belonging to the reference line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the reference line; For each pixel point in the edge image, correcting the original coordinate information of the pixel point in the pixel coordinate system by using the reference distortion correction model to obtain the corresponding reference correction coordinate information of the pixel point, and determining whether the pixel point is a candidate pixel point according to the original coordinate information of the pixel point in the edge image and the corrected reference correction coordinate information of the pixel point; Determine the target pixel points belonging to each current line from all the determined candidate pixel points, perform fitting processing based on the current line and the determined target pixel points belonging to the current line to obtain the fitting line corresponding to the current line, and when there is a current iteration count, increase the recorded iteration count by a first value, otherwise, set the iteration count to the first value; when the current value of the iteration count is less than the set value, determine all the fitting lines as the current lines, and return to the step of selecting the longest reference line from all the current lines, otherwise, select the longest one from all the fitting lines as the target line.
4. The method according to claim 3, wherein The determination of whether the pixel point is a candidate pixel point based on the original coordinate information of the pixel point in the edge image and the corrected reference correction coordinate information of the pixel point after correction includes: For each pixel point, calculate the Euclidean distance between the original coordinate information of the pixel point in the edge image and the corrected reference correction coordinate information of the pixel point after correction; When the Euclidean distance is less than the first set distance threshold, determine that the pixel point is a candidate pixel point, otherwise, determine that the pixel point is not a candidate pixel point.
5. The method according to claim 3, characterized in that, The determination of the target pixel points belonging to each current line from all the determined candidate pixel points includes: Execute the following steps for each current line: For each candidate pixel point, determine whether the direction difference between the current line and the candidate pixel point after both are mapped to the Hough space is less than the set direction threshold. When the direction difference is less than or equal to the set direction threshold, if the distance from the candidate pixel point to the current line is less than or equal to the second set distance threshold, determine that the candidate pixel point is a target pixel point belonging to the current line. When the direction difference is greater than the set direction threshold, or when the direction difference is less than the set direction threshold but the distance from the candidate pixel point to the current line is greater than the second set distance threshold, determine that the candidate pixel point does not belong to the target pixel points of the current line.
6. The method according to any one of claims 1 to 5, characterized in that The correction of the abscissa value in the target correction coordinate information corresponding to other pixel points in the original image by using the width of the original image and the specified abscissa value in the original image includes: Correct the abscissa value in the target correction coordinate information corresponding to each pixel point through the following formula: Among them, x` is the abscissa value after correction in the target correction coordinate information, x is the abscissa value before correction in the target correction coordinate information, C x is the specified abscissa value, s x is the set correction coefficient.
7. An image correction device, characterized in that, The device includes: A selection unit for selecting a target line from the obtained edge image; wherein, the number of pixel points belonging to the target line in the edge image is greater than the set number, the edge image is obtained by performing edge detection on the original image; the target line is determined based on the initial line found by each target mapping pixel point in the edge image; the target mapping pixel points are statistically obtained from the pixel coordinate system of each pixel point in the edge image mapped to the Hough space in the polar coordinate system; the target line is the longest one among all the initial lines, or the target line is determined based on line detection; the line detection can also detect continuous target lines when applied to an edge image with severe distortion. A target unit, configured to determine a target distortion correction model according to the original coordinate information of the pixel points belonging to the target line in the edge image in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the target line; A correction unit, configured to correct the original coordinate information of each pixel point in the original image in the pixel coordinate system by using the target distortion correction model to obtain the target correction coordinate information corresponding to each pixel point; and Correct the abscissa value in the target correction coordinate information corresponding to each other pixel point in the original image by using the width of the original image and the specified abscissa value in the original image; wherein, the closer the abscissa value in the target correction coordinate information is to the specified abscissa value, the smaller the correction amplitude.
8. The device according to claim 7, characterized in that, The selection unit selects a target line from the obtained edge images, including: Mapping each pixel point in the edge image from the pixel coordinate system to the Hough space in the polar coordinate system to obtain the mapped pixel points in the Hough space that have a mapping relationship with each pixel point in the edge image; Counting at least one target mapped pixel point in the Hough space; wherein, the number of pixel points in the edge image mapped by the target mapped pixel points in the Hough space is greater than the number of pixel points in the edge image mapped by the non-target mapped pixel points in the Hough space; Searching for the corresponding initial line according to each target mapped pixel point in the edge image, and determining the target line according to the determined initial lines.
9. The device according to claim 8, characterized in that, The selection unit determines the target line according to the determined initial lines, including: Selecting the longest one from all the initial lines as the target line; or Determining all the initial lines as the current lines; selecting a reference line with the most pixel points from all the current lines, and determining a reference distortion correction model according to the original coordinate information of the pixel points belonging to the reference line in the pixel coordinate system and the theoretical coordinate information of the pixel points calculated based on the straight line equation corresponding to the reference line; For each pixel point in the edge image, correcting the original coordinate information of the pixel point in the pixel coordinate system by using the reference distortion correction model to obtain the reference correction coordinate information corresponding to the pixel point, and determining whether the pixel point is a candidate pixel point according to the original coordinate information of the pixel point in the edge image and the reference correction coordinate information after the pixel point is corrected; Determining the target pixel points belonging to each current line from all the determined candidate pixel points, performing fitting processing on the current line and the determined target pixel points belonging to the current line to obtain the fitting line corresponding to the current line, and when there is a current iteration number, increasing the recorded iteration number by a first value, otherwise, setting the iteration number to the first value; when the current value of the iteration number is less than the set value, determining all the fitting lines as the current lines, and returning to the step of selecting the longest reference line from all the current lines, otherwise, selecting the longest one from all the fitting lines as the target line.
10. An electronic device, characterized in that, The electronic device includes: a processor and a machine-readable storage medium; The machine-readable storage medium stores machine-executable instructions that can be executed by the processor; The processor is configured to execute the machine-executable instructions to implement the method steps of any one of claims 1-6.
Citation Information
Patent Citations
Image sensor internal reference calibration method and device, equipment and storage medium
CN113096192A