Image keystone correction method and device, and storage medium
Through trapezoidal scene detection and radial offset combined with homography transformation, high-quality corrected images are generated, which solves the problem that the image keystone correction method in the prior art cannot take into account distant details and proximal geometric accuracy, and achieves the improvement of image quality and analysis value.
Patent Information
- Application Number
- CN202510464140.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2045-04-14
AI Technical Summary
The existing image keystone correction methods cannot take into account distant details and proximal geometric accuracy, resulting in a decline in image quality and affecting subsequent processing effects.
The vertex coordinates are determined through trapezoidal scene detection, radial offsets are performed, and the target transformation matrix is constructed, and the corrected image is generated in combination with homography transformation, which enhances distant details and maintains proximity geometric integrity.
The overall quality and analysis value of the image are improved, and the clarity of the distance details is improved while maintaining the geometric structure of the near area remains unchanged.
Smart Images

Figure CN120495141A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision technology, and in particular to a method, device, and storage medium for trapezoidal correction of an image. Background Art
[0002] With the popularization and development of digital camera technology, digital images have been widely used in various fields. However, during the image acquisition process, due to the influence of factors such as the angle and position of the camera equipment, trapezoidal distortion often occurs, which reduces the image quality and affects subsequent image processing. Specifically, due to the perspective effect, the top pixel density of the captured trapezoidal image is low, which may cause key details in the distance to not be clearly presented. Currently, for the pre-processing of the trapezoidal area in the image, the use of fisheye lenses or affine transformation methods can expand the field of view but will destroy the geometric structure of the near area. The use of traditional perspective transformation methods can correct the geometric distortion caused by the shooting angle, but it has limited improvement in the clarity of distant details.
[0003] Therefore, there is an urgent need for an image keystone correction method that can effectively amplify distant details while maintaining the geometric integrity of nearby areas, thereby improving the overall quality and analytical value of the image. Summary of the Invention
[0004] The main purpose of this application is to provide a method, device and storage medium for trapezoidal correction of an image, aiming to solve the technical problem that the existing trapezoidal correction method of an image cannot take into account both distant details and near-end geometric accuracy.
[0005] To achieve the above objectives, the present application proposes a method for image trapezoidal correction, the method comprising:
[0006] Determine the coordinates of the first vertex of the vertices of the trapezoidal area in the image to be processed by trapezoidal scene detection;
[0007] Based on the first vertex coordinates, radially offset the vertices of the trapezoidal area along the central axis of the trapezoidal area, and use the offset positions as the second vertex coordinates corresponding to the target trapezoidal area;
[0008] determining a target transformation matrix between the trapezoidal region and a target trapezoidal region according to the first vertex coordinates and the second vertex coordinates;
[0009] Each pixel point of the trapezoidal area is converted according to the target conversion matrix to generate a corrected target trapezoidal area image.
[0010] In one embodiment, determining the coordinates of first vertices of a trapezoidal region in the image to be processed by trapezoidal scene detection includes:
[0011] Performing edge detection on the image to be processed to obtain an edge binary image, wherein the brightness values of edge pixels in the edge binary image are higher than the brightness values of non-edge pixels;
[0012] Performing line detection on the edge binary image to obtain a set of candidate lines for the trapezoidal region boundary;
[0013] The first vertex coordinates of the vertices of the trapezoidal region are determined by using the set of candidate straight lines for the trapezoidal region boundary.
[0014] In some embodiments, the vertices of the trapezoidal area include an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area. Based on the first vertex coordinates, radially offsetting the vertices of the trapezoidal area along the central axis of the trapezoidal area and using the offset positions as the second vertex coordinates corresponding to the target trapezoidal area includes:
[0015] determining a first depth between an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area, and determining a first adjustment coefficient corresponding to the first depth based on a preset correspondence between depths and adjustment coefficients and the first depth;
[0016] Determine a first radial offset of the upper vertex according to the length of the upper side of the trapezoidal area and the first adjustment coefficient;
[0017] Based on the first radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinates of the lower vertex of the trapezoidal area are determined as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
[0018] In some embodiments, the vertices of the trapezoidal area include an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area. Based on the first vertex coordinates, radially offsetting the vertices of the trapezoidal area along the central axis of the trapezoidal area and using the offset positions as the second vertex coordinates corresponding to the target trapezoidal area includes:
[0019] Obtaining a second adjustment coefficient input by a user, and determining a second radial offset of the upper vertex according to the length of the upper side of the trapezoidal area image and the second adjustment coefficient;
[0020] Based on the second radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinates of the lower vertex of the trapezoidal area are determined as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
[0021] In some embodiments, determining a target transformation matrix between the trapezoidal region and the target trapezoidal region based on the first vertex coordinates and the second vertex coordinates includes:
[0022] Based on the first vertex coordinates of the vertices of the trapezoidal area and the second vertex coordinates of the vertices of the target trapezoidal area, an algorithm for obtaining a perspective transformation matrix is called to obtain the target transformation matrix.
[0023] In some embodiments, converting each pixel point of the trapezoidal area according to the target conversion matrix to generate a corrected target trapezoidal area image includes:
[0024] Traversing each pixel point of the trapezoidal area, and calculating corresponding coordinates of each pixel point in the target trapezoidal area image using the target transformation matrix;
[0025] generating an initial target trapezoidal area image based on corresponding coordinates of each pixel point in the target trapezoidal area image;
[0026] Mask fusion is performed on the initial target trapezoidal region image and the trapezoidal region image to fill blank areas in the initial target trapezoidal region image that are not covered by original pixels, so as to obtain a corrected target trapezoidal region image.
[0027] In some embodiments, after generating the corrected target trapezoidal area image, the method further includes:
[0028] Using a super-resolution algorithm to perform pixel supplementation on the target trapezoidal region image to obtain an enhanced target trapezoidal region image;
[0029] The enhanced target trapezoidal region image replaces the trapezoidal region image in the image to be processed to obtain a processed image.
[0030] In some embodiments, after generating the corrected target trapezoidal area image, the method further includes:
[0031] Target detection is performed on the target trapezoidal area image to obtain a target detection result, where the target detection result is used to indicate the category of the target to be detected and the confidence level of the target to be detected in the target trapezoidal area image.
[0032] In addition, to achieve the above-mentioned purpose, the present application also proposes a trapezoidal correction device for an image, the trapezoidal correction device for an image comprising:
[0033] A trapezoidal scene detection module, configured to determine the coordinates of first vertices of a trapezoidal region in the image to be processed through trapezoidal scene detection;
[0034] a radial offset module, configured to radially offset the vertices of the trapezoidal region along the central axis of the trapezoidal region based on the first vertex coordinates, and use the offset positions as the second vertex coordinates corresponding to the target trapezoidal region;
[0035] a transformation matrix determining module, configured to determine a target transformation matrix between the trapezoidal region and a target trapezoidal region according to the first vertex coordinates and the second vertex coordinates;
[0036] The geometric correction module is used to transform each pixel point of the trapezoidal area according to the target transformation matrix to generate a corrected target trapezoidal area image.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a trapezoidal correction device for an image, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the trapezoidal correction method for an image as described above.
[0038] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the image trapezoidal correction method as described above are implemented.
[0039] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps of the image trapezoidal correction method as described above.
[0040] One or more technical solutions proposed in this application have at least the following technical effects: through trapezoidal scene detection, the four vertex coordinates of the trapezoidal area are extracted, that is, the first vertex coordinates of the vertices of the trapezoidal area in the image to be processed. Based on the first vertex coordinates, the vertices of the trapezoidal area are radially offset from top to bottom as needed along the central axis of the trapezoidal area, so that the top width of the trapezoidal area is increased, and the offset position is used as the second vertex coordinate corresponding to the target trapezoidal area, which specifically amplifies distant details, helps to improve the visibility and clarity of distant features, while minimizing the impact on nearby areas. According to the first vertex coordinates and the second vertex coordinates, the target transformation matrix between the trapezoidal area and the target trapezoidal area is determined, and the target transformation matrix defines how to map from the trapezoidal area to the target trapezoidal area. The target transformation matrix is applied to perform a geometric transformation on each pixel point of the trapezoidal area, and for each pixel point, its corresponding position in the new image (target trapezoidal area image) is calculated by the target transformation matrix to obtain the target trapezoidal area image after geometric correction. The generated target trapezoidal area image has a wider top and clearer distant details. The image trapezoidal correction method proposed in this application can, on the one hand, increase the density of distant pixels and improve the clarity of distant details through radial offset; on the other hand, combine with homography transformation (using the target transformation matrix) to eliminate perspective distortion and local stretching deformation to achieve geometric correction, and solve the technical problem that the image trapezoidal correction method in the existing technology cannot take into account both distant details and near-end geometric accuracy. Combined with radial distortion correction and perspective transformation, a high-quality corrected image (i.e., the target trapezoidal area image) is generated, which not only amplifies distant details but also maintains the geometric integrity of the near area, effectively improving the overall quality and analytical value of the corrected target trapezoidal area image. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0043] Figure 1 A schematic flow chart of a method for image trapezoidal correction provided in an embodiment of the present application;
[0044] Figure 2 A comparison chart of the effects of the image trapezoidal correction method provided in this application;
[0045] Figure 3A comparison chart of the existing fisheye lens processing effects provided for this application;
[0046] Figure 4 A schematic diagram of the module structure of an image trapezoidal correction device provided in an embodiment of the present application;
[0047] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the image trapezoidal correction method in the embodiment of the present application. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] The main solution of the embodiment of the present application is: through trapezoidal scene detection, the first vertex coordinates of the vertices of the trapezoidal area in the image to be processed are determined; based on the first vertex coordinates, the vertices of the trapezoidal area are radially offset along the central axis of the trapezoidal area, and the offset position is used as the second vertex coordinates corresponding to the target trapezoidal area; according to the first vertex coordinates and the second vertex coordinates, the target transformation matrix between the trapezoidal area and the target trapezoidal area is determined; according to the target transformation matrix, each pixel point of the trapezoidal area is transformed to obtain the target trapezoidal area image after geometric correction, and the top of the generated target trapezoidal area image is widened, and the details in the distance are clearer.
[0051] In this embodiment, for ease of description, the following description is made with the image trapezoidal correction system as the execution subject.
[0052] With the popularization and development of digital camera technology, digital images have been widely used in various fields. However, during the image acquisition process, due to the influence of factors such as the angle and position of the camera equipment, the problem of trapezoidal distortion often occurs, which reduces the image quality and affects the subsequent image processing. Specifically, due to the perspective effect, the top pixel density of the captured trapezoidal image is low, which may cause key details in the distance to not be clearly presented. Currently, for the pre-processing of the trapezoidal area in the image, the fisheye lens or affine transformation method can expand the field of view but destroy the geometric structure of the near area. The traditional perspective transformation method can correct the geometric distortion caused by the shooting angle, but the clarity of the distant details is limited. Therefore, there is an urgent need for an image trapezoidal correction method that can effectively magnify distant details while maintaining the geometric integrity of the near area, thereby improving the overall quality and analytical value of the image.
[0053] The present application provides a method for trapezoidal correction of an image. On the one hand, radial offset is used to increase the density of distant pixels and improve the clarity of distant details. On the other hand, the method combines homography transformation (using the target transformation matrix) to eliminate perspective distortion and local stretching deformation to achieve geometric correction. This solves the technical problem that the trapezoidal correction method of images in the prior art cannot take into account both distant details and near-end geometric accuracy. It cleverly combines radial distortion correction and perspective transformation to generate a high-quality corrected image (i.e., the target trapezoidal area image), which not only amplifies distant details but also maintains the geometric integrity of the near area, effectively improving the overall quality and analytical value of the corrected target trapezoidal area image.
[0054] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, mobile phone, etc., or an image keystone correction system capable of implementing the above functions. The following uses the image keystone correction system as an example to illustrate this embodiment and the following embodiments.
[0055] Based on this, the embodiment of the present application provides a method for trapezoidal correction of an image, referring to Figure 1 , Figure 1 FIG. 1 is a flow chart of a first embodiment of a method for image trapezoidal correction according to the present invention.
[0056] In this embodiment, the image trapezoidal correction method includes steps 101 to 104:
[0057] Step 101 : Determine the coordinates of the first vertices of the trapezoidal region in the image to be processed by trapezoidal scene detection.
[0058] Specifically, trapezoidal scene detection is the process of identifying a specific shape of a trapezoidal area from the image to be processed. For example, the image trapezoidal correction method provided in this application provides a comparison chart of the processing effect, refer to Figure 2 In the image on the right, the trapezoidal scene detection can be a railway track with a trapezoidal structure. The first vertex coordinates are the actual coordinates of the four vertices of the trapezoidal area in the image to be processed before any correction or transformation.
[0059] In addition, before performing trapezoidal scene detection on the image to be processed, the image to be processed can be preprocessed. The preprocessing steps may include grayscale processing, denoising, etc. Grayscale processing can convert the color image to be processed into a single-channel grayscale image to reduce computational complexity, and a smoothing filter such as Gaussian blur can be used to remove noise to improve the accuracy of edge detection.
[0060] In some embodiments, computer vision techniques can be used to identify and locate the boundaries of a trapezoidal region in the image to be processed, thereby extracting the coordinates of the four vertices of the trapezoidal region, namely, the first vertex coordinates of the vertices of the trapezoidal region. Determining the boundaries and vertex locations of the trapezoidal region helps ensure that subsequent processing targets only that trapezoidal region, avoiding interference from unrelated areas. The first vertex coordinates of the vertices of the trapezoidal region serve as a key input for subsequent calculations of geometric transformations. Furthermore, determining the precise first vertex coordinates of the vertices of the trapezoidal region helps ensure the accuracy of subsequent transformations, thereby achieving the goal of amplifying distant details while maintaining stable near-field geometry.
[0061] Step 102 : Based on the first vertex coordinates, radially offset the vertices of the trapezoidal region along the central axis of the trapezoidal region, and use the offset positions as the second vertex coordinates corresponding to the target trapezoidal region.
[0062] Specifically, the first vertex coordinates (A, B, C, D) are the actual coordinates of the four vertices of the trapezoidal area in the image to be processed, which are the basis for subsequent transformations. In this application, radial offset is applied along the central axis of the trapezoidal area according to the distance from the top, so that the top width increases, while the bottom area remains almost unchanged. The second vertex coordinates (A', B', C', D') are the new coordinates of the four vertices of the target trapezoidal area after radial offset, which define the corrected target trapezoidal shape.
[0063] In some embodiments, the central axis of the trapezoidal area can be calculated by connecting the midpoints of the two vertices at the top of the trapezoid and the two vertices at the bottom. At the same time, the top expansion ratio (for example, 80%) or the radial offset of the top of the trapezoidal area is determined. The top expansion ratio or the radial offset directly determines the width that needs to be increased at the top. For each vertex, its radial offset along the central axis is determined based on the distance from the vertex to the central axis and the expansion ratio. In this application, the offset of the upper vertex is larger, and the offset of the lower vertex is smaller or zero. The closer the vertex is to the top, the larger the offset; the closer the vertex is to the bottom, the smaller the offset. The calculated offset of each vertex is applied to each vertex to obtain the offset position, which is the second vertex coordinate of the target trapezoidal area. By radially offsetting the vertices of the trapezoidal area along the central axis of the trapezoidal area based on the first vertex coordinates (A, B, C, D), and using the offset positions as the second vertex coordinates (A', B', C', D') corresponding to the target trapezoidal area, the problem that the trapezoidal correction method of the image in the existing technology cannot take into account both distant details and near-end geometric accuracy is effectively solved. By precisely adjusting the vertex positions, the expressiveness of distant details is enhanced while maintaining the geometric integrity of the near area. It is suitable for application scenarios that require high-precision visual analysis.
[0064] Step 103: Determine a target transformation matrix between the trapezoidal region and the target trapezoidal region according to the first vertex coordinates and the second vertex coordinates.
[0065] Specifically, the target transformation matrix is a homography matrix, which can be a 3x3 matrix. In this application, the target transformation matrix can be used to map the trapezoidal area to the target trapezoidal area after radial offset. According to the first vertex coordinates and the second vertex coordinates, the solution equation of the target transformation matrix is constructed. The least squares method or singular value decomposition can be used to solve the equation to obtain the target transformation matrix. Optionally, in OpenCV, the target transformation matrix between the trapezoidal area and the target trapezoidal area can be directly calculated by calling the cv::getPerspectiveTransform function.
[0066] By determining the coordinate correspondence between the first vertex coordinates (A, B, C, D) and the second vertex coordinates (A', B', C', D') of the vertices of the target trapezoidal area, the target transformation matrix is obtained. The target transformation matrix is used to unify the modeling of the geometric deformation of the trapezoidal area (such as top expansion) and the global perspective correction, so as to achieve the pixel density improvement of distant details in the processed image and the lossless preservation of the near-end key geometric structure, solving the problem that the existing technology cannot take into account both distant details and near-end geometric accuracy.
[0067] Step 104 , transforming each pixel point of the trapezoidal area according to the target transformation matrix to generate a corrected target trapezoidal area image.
[0068] Specifically, based on the target transformation matrix, a blank target trapezoidal region image is initialized. Each pixel in the trapezoidal region is traversed and mapped to the corresponding target trapezoidal region using the target transformation matrix. The corresponding coordinates of the pixels in the target trapezoidal region image are calculated. For non-integer coordinates obtained, an interpolation algorithm can be used to determine the color value of the location. During the interpolation process, a weighted average is performed based on the color information of adjacent pixels in the original trapezoidal region to achieve a smooth color transition. Furthermore, the interpolated color value is assigned to the corresponding location in the target trapezoidal region image. This process is repeated until all pixels in the trapezoidal region have been processed, generating a corrected target trapezoidal region image. The generated target trapezoidal region image has an expanded top region, magnifying distant details (the top details of the trapezoidal region) while preserving the geometric structure of the near region as much as possible. By applying the calculated target transformation matrix to geometrically transform each pixel in the trapezoidal region, the trapezoidal region in the processed image is corrected to the target trapezoidal region image. This amplifies distant details while preserving the geometric structure of the near region and eliminating perspective distortion, resulting in a high-quality corrected image.
[0069] Based on the trapezoidal correction method of the image provided by the present application, the four vertex coordinates of the trapezoidal area are extracted through trapezoidal scene detection, that is, the first vertex coordinates of the vertices of the trapezoidal area in the image to be processed. Based on the first vertex coordinates, the vertices of the trapezoidal area are radially offset from top to bottom as required along the central axis of the trapezoidal area, so that the top width of the trapezoidal area is increased, and the offset position is used as the second vertex coordinate corresponding to the target trapezoidal area, which specifically amplifies the distant details, helps to improve the visibility and clarity of distant features, while minimizing the impact on the near area. According to the first vertex coordinates and the second vertex coordinates, the target transformation matrix between the trapezoidal area and the target trapezoidal area is determined, and the target transformation matrix defines how to map from the trapezoidal area to the target trapezoidal area. The target transformation matrix is applied to perform a geometric transformation on each pixel point of the trapezoidal area, and for each pixel point, its corresponding position in the new image (target trapezoidal area image) is calculated by the target transformation matrix to obtain the target trapezoidal area image after geometric correction. The generated target trapezoidal area image has a wider top and clearer distant details. The image trapezoidal correction method proposed in this application, on the one hand, can increase the density of distant pixels and improve the clarity of distant details through radial offset; on the other hand, combined with homography transformation (using the target transformation matrix), it eliminates perspective distortion and local stretching deformation to achieve geometric correction, solving the technical problem that the image trapezoidal correction method in the existing technology cannot take into account both distant details and near-end geometric accuracy. It cleverly combines radial distortion correction and perspective transformation to generate a high-quality corrected image (i.e., the target trapezoidal area image), which not only amplifies distant details but also maintains the geometric integrity of the near area, effectively improving the overall quality and analytical value of the corrected target trapezoidal area image.
[0070] In some embodiments, determining the coordinates of first vertices of a trapezoidal region in the image to be processed by trapezoidal scene detection includes:
[0071] Performing edge detection on the image to be processed to obtain an edge binary image, wherein the brightness value of edge pixels in the edge binary image is higher than the brightness value of non-edge pixels;
[0072] Perform line detection on the edge binary image to obtain a set of candidate lines for the trapezoidal region boundary;
[0073] The first vertex coordinates of the vertices of the trapezoidal region are determined by the set of candidate straight lines for the trapezoidal region boundary.
[0074] As an example, the Canny operator can be used to perform edge detection on the image being processed. Specifically, the process includes converting the image to a grayscale image, applying a filter to remove noise, and calculating the intensity gradient at each pixel. Only local maxima along the gradient are retained, edges are refined, and high and low thresholds are dynamically set to generate a binary edge image, where edge pixels have higher brightness values and non-edge pixels have lower brightness values. A line detection algorithm is then applied to the resulting binary edge image, mapping points in image space to parameter space to effectively detect lines. This results in a set of all detected lines, namely, the set of candidate lines for the trapezoidal region boundary. The line detection algorithm employed can be a Hough transform. The set of candidate lines for the trapezoidal region boundary is then screened to obtain the lines that define the trapezoidal region boundary. The coordinates of the vertices of the trapezoidal region are then calculated based on these lines. Furthermore, unexpected anomalous intersections can be eliminated. For example, the validity of the vertices can be confirmed using pre-set shape constraints (such as the angle range and side length ratio of the trapezoid). Ultimately, the specific coordinates (A, B, C, D) of the four vertices of the trapezoidal region are obtained, namely, the coordinates of the first vertex. Additionally, it allows users to manually adjust vertex positions.
[0075] By performing edge detection on the image to be processed, an edge binary image is obtained, and line detection is performed on the edge binary image to obtain a set of candidate straight lines for the trapezoidal area boundary. The coordinates of the first vertex of the vertices of the trapezoidal area are determined through the set of straight lines, thereby achieving precise positioning of the trapezoidal area from the image. This not only provides the necessary basic data for subsequent geometric correction, but also ensures the accuracy and efficiency of the entire image processing process.
[0076] In some embodiments, the vertices of the trapezoidal region include an upper vertex of the trapezoidal region and a lower vertex of the trapezoidal region. Based on the first vertex coordinates, the vertices of the trapezoidal region are radially offset along the central axis of the trapezoidal region, and the offset positions are used as the second vertex coordinates corresponding to the target trapezoidal region, including:
[0077] Determine a first depth between an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area, and determine a first adjustment coefficient corresponding to the first depth based on a preset correspondence between the depth and the adjustment coefficient and the first depth;
[0078] Determining a first radial offset of the upper vertex according to the length of the upper side of the trapezoidal area and the first adjustment coefficient;
[0079] Based on the first radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinate corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinate of the lower vertex of the trapezoidal area is determined as the second lower vertex coordinate corresponding to the lower vertex of the target trapezoidal area.
[0080] Specifically, the upper vertices of the trapezoidal area are the two vertices at the top of the trapezoidal area, and the lower vertices of the trapezoidal area are the two vertices at the bottom of the trapezoidal area. The first depth is the vertical distance between the upper vertex and the lower vertex of the trapezoidal area, which can represent the perspective depth in the image to be processed. The adjustment coefficient is a proportional factor that dynamically adjusts the offset according to the depth. It increases linearly with the increase of depth and is used to control the offset of the vertex. The greater the depth between the upper vertex of the trapezoidal area and the lower vertex of the trapezoidal area, the greater the adjustment coefficient. The first radial offset is the distance by which the upper vertex is displaced along the central axis of the trapezoidal area. The upper side length is the horizontal distance between the two upper vertices at the top of the trapezoidal area.
[0081] As an example, the vertical distance between the upper vertex (A and B) and the lower vertex (C and D) of the trapezoidal area is calculated, that is, the first depth. The adjustment coefficient corresponding to the first depth is found or calculated using a pre-set mapping relationship to obtain the first adjustment coefficient corresponding to the first depth. The mapping relationship can be designed according to the needs of the specific application scenario. In this application, the adjustment coefficient is positively correlated with the depth. The vertex closer to the top requires a larger offset. The greater the depth, the larger the corresponding adjustment coefficient and the larger the subsequent radial offset. The length of the upper side of the trapezoidal area (the horizontal distance between A and B) can be calculated based on the first upper vertex coordinates of the upper vertex of the trapezoidal area, and the first adjustment coefficient is multiplied by the length of the upper side to obtain the first radial offset of the upper vertex. Further, the position of the central axis of the trapezoidal area is determined. For each upper vertex (A and B), the corresponding first radial offset is moved along the central axis to obtain new vertex coordinates (A' and B'), that is, the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area. At the same time, the coordinates of the lower vertex of the trapezoidal area are used as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
[0082] By calculating the first depth between the upper vertex and the lower vertex of the trapezoidal area, determining the first adjustment coefficient based on the correspondence between the preset depth and the adjustment coefficient, and then calculating the first radial offset of the upper vertex in combination with the upper side length of the trapezoidal area, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area based on the first radial offset of the upper vertex, and keeping the lower vertex almost unchanged, it is possible to effectively magnify distant details and maintain the geometric structure of the near area, thereby solving the problem that the image correction method in the prior art cannot take into account both distant details and near-end geometric accuracy.
[0083] In some embodiments, the vertices of the trapezoidal region include an upper vertex of the trapezoidal region and a lower vertex of the trapezoidal region. Based on the first vertex coordinates, the vertices of the trapezoidal region are radially offset along the central axis of the trapezoidal region, and the offset positions are used as the second vertex coordinates corresponding to the target trapezoidal region, including:
[0084] Obtaining a second adjustment coefficient input by the user, and determining a second radial offset of the upper vertex according to the length of the upper side of the trapezoidal area image and the second adjustment coefficient;
[0085] Based on the second radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinates of the lower vertex of the trapezoidal area are determined as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
[0086] Specifically, the second adjustment coefficient is a parameter entered by the user that controls the offset of the vertex. For example, the second adjustment coefficient can be any value between 50% and 200%, and the specific value is manually and dynamically adjusted based on the application scenario. The second radial offset is the displacement distance of the vertex along the central axis calculated based on the second adjustment coefficient and the length of the upper side of the trapezoidal area.
[0087] As an example, a second adjustment coefficient input by the user is obtained. The second adjustment coefficient allows the user to flexibly adjust the offset degree of the upper vertex according to specific needs, providing a customized method to optimize the image correction result. The length of the upper side of the trapezoidal area is calculated, and the second radial offset of each upper vertex is determined using the formula (i.e., the second radial offset = the length of the upper side of the trapezoidal area image × the second adjustment coefficient). Further, the position of the central axis of the trapezoidal area is calculated, and each upper vertex is radially offset along the central axis based on the second radial offset calculated above. For each upper vertex of the trapezoidal area, the radial offset obtains the corresponding upper vertex of the target trapezoidal area and the second upper vertex coordinates of the upper vertex of the target trapezoidal area. For the lower vertex of the trapezoidal area, the first lower vertex coordinate of the lower vertex of the trapezoidal area is directly determined as the second lower vertex coordinate corresponding to the lower vertex of the target trapezoidal area, ensuring that the geometric structure of the bottom area remains unchanged. By radially offsetting the upper vertex of the trapezoidal area along its axis and making fine adjustments in combination with the second adjustment coefficient input by the user, it is possible to effectively amplify distant details and maintain the geometric structure of the near area, thereby obtaining a target trapezoidal area image that is more in line with user expectations.
[0088] In addition, the first adjustment coefficient is automatically calculated based on the vertical distance between the upper vertex and the lower vertex of the trapezoidal area (i.e., the first depth) and the mapping relationship between its pre-set depth and the adjustment coefficient. It is mainly used to standardize the vertex offset at different depths, so that the vertex closer to the top obtains a larger offset, thereby increasing the top width and improving the visibility of distant details. The second adjustment coefficient is manually input by the user, providing greater flexibility and control accuracy, allowing the user to fine-tune the offset of the top vertex according to the specific image content and correction target. For example, in some cases, the user may want to enlarge the top area more significantly to highlight specific features, or conversely reduce the offset to avoid over-stretching. By introducing the second adjustment coefficient, the user's expected visual effect can be achieved more accurately without affecting the overall correction framework.
[0089] In some embodiments, determining a target transformation matrix between the trapezoidal region and the target trapezoidal region based on the first vertex coordinates and the second vertex coordinates includes:
[0090] Based on the first vertex coordinates of the vertices of the trapezoidal region and the second vertex coordinates of the vertices of the target trapezoidal region, the perspective transformation matrix acquisition algorithm is called to obtain the target transformation matrix.
[0091] Specifically, the above algorithm for obtaining the perspective transformation matrix may be the cv::getPerspectiveTransform function.
[0092] As an example, based on the first vertex coordinates of the vertices of the trapezoidal area and the second vertex coordinates of the vertices of the target trapezoidal area, an algorithm for obtaining the perspective transformation matrix (homography matrix) is called. For example, in image processing libraries such as OpenCV, the cv::getPerspectiveTransform function can be used to obtain the target transformation matrix. The cv::getPerspectiveTransform function accepts two sets of point sets as input parameters. The first set of point sets contains the coordinates of the four vertices of the trapezoidal area, i.e., the first vertex coordinates of the vertices of the trapezoidal area. The second set of point sets contains the coordinates of the four vertices of the target trapezoidal area, i.e., the second vertex coordinates of the vertices of the target trapezoidal area. The cv::getPerspectiveTransform function returns the target transformation matrix, which describes the mapping relationship from the trapezoidal area to the target trapezoidal area. Furthermore, the coordinate mapping error corresponding to the lower vertex of the trapezoidal area can be given a high weight to force the proximal coordinates to be strictly unchanged. Through vertex coordinate mapping and weighted optimization, user-defined deformation requirements (such as top edge expansion) and geometric correction are unified into homography matrix calculation, which not only improves the clarity of distant details but also maintains the geometric structure of nearby areas. This helps to solve the problem that the existing image trapezoidal correction method cannot take into account both distant details and near-end geometric accuracy.
[0093] In some embodiments, converting each pixel point of the trapezoidal region according to the target conversion matrix to generate a corrected target trapezoidal region image includes:
[0094] Traverse each pixel point in the trapezoidal area and calculate the corresponding coordinates of each pixel point in the target trapezoidal area image through the target transformation matrix;
[0095] Generate an initial target trapezoidal area image based on the corresponding coordinates of each pixel point in the target trapezoidal area image;
[0096] The initial target trapezoidal region image and the trapezoidal region image are mask-fused to fill blank areas in the initial target trapezoidal region image that are not covered by original pixels, thereby obtaining a corrected target trapezoidal region image.
[0097] As an example, traverse each pixel point in the trapezoidal area, and use the target transformation matrix to calculate the new position of each pixel point in the target trapezoidal area image, that is, the corresponding coordinates of the pixel point in the target trapezoidal area image. Based on the calculated corresponding coordinates of each pixel point in the target trapezoidal area image, create a new blank image as the target trapezoidal area image, and for each pixel point in the trapezoidal area, assign its color value to the corresponding pixel position in the target trapezoidal area image according to its new coordinates in the target trapezoidal area image. When the corresponding coordinates of the pixel point in the target trapezoidal area image are non-integer, an interpolation method can be used to determine the color value of the position. The interpolation method can include nearest neighbor interpolation, bilinear interpolation, and bicubic interpolation. Specifically, in OpenCV, the cv::warpPerspective function can be called to generate the initial target trapezoidal area image based on the corresponding coordinates of each pixel point in the target trapezoidal area image.
[0098] Furthermore, in the generated initial target trapezoidal region image, there may be some blank areas not covered by the original pixels. The blank areas not covered by the original pixels are usually black or transparent. To improve the overall quality and visual effect of the image, the blank areas not covered by the original pixels need to be filled. This can be done by performing mask fusion on the initial target trapezoidal region image and the original trapezoidal region image to generate a binary mask, marking the blank areas in the initial target trapezoidal region image. The blank areas in the initial target trapezoidal region image are then filled using background copying, smooth transition, and image inpainting algorithms. The filled image is then combined with the trapezoidal region image to obtain a corrected target trapezoidal region image, ensuring the consistency and integrity of the entire image.
[0099] By applying the target transformation matrix, the trapezoidal region is precisely mapped to the target trapezoidal region image. Each pixel is transformed to generate an initial target trapezoidal region image. Mask fusion technology is then used to fill in blank areas, ultimately resulting in a high-quality target trapezoidal region image. This not only improves the clarity of distant details but also maintains the geometric structure of nearby areas, resolving the problem in existing image correction methods that cannot balance distant details with near-end geometric accuracy.
[0100] In some embodiments, reference Figure 3 , Figure 3 This is a comparison chart of the existing fisheye lens processing effects. Figure 3 The image on the left is the image to be processed. The tracks, spikes, and ground gravel in the near distance are clearly visible, while the tracks in the medium and far distances gradually narrow due to the perspective effect, and the details of the background vegetation and trees are blurred. Figure 3 The right side shows the effect of using a traditional fisheye lens. The fisheye lens can provide a wide field of view, but it introduces significant geometric distortion. Figure 3 In the image on the right, the nearside railway track appears curved, while the distant background trees appear curved and distorted, distorting the perception of vegetation density. This not only affects the precise measurement of the track structure but can also lead to misjudgments in subsequent analysis algorithms. Furthermore, distant details remain unclear, making it difficult to meet high-quality detection requirements.
[0101] refer to Figure 2 , Figure 2 This is a comparison chart of the processing effects of the image trapezoidal correction method proposed in this application. Figure 2 The right side shows the image to be processed, which contains the trapezoidal area of the original rail image. The rails in the distance are narrow and blurred due to the perspective effect. Figure 2 The left side is the effect diagram of the trapezoidal correction processing method of the image proposed in this application. The top width is expanded and the texture of the railway track in the distance is clearly visible. Figure 2 This intuitively demonstrates the significant advantages of this application in correcting perspective distortion and enhancing remote details. Figure 3 The inherent defects of fisheye lenses in near-end distortion and pseudo-enhancement are exposed. By precisely adjusting the position of the vertices of the trapezoidal area, especially increasing the top width, the image trapezoidal correction method proposed in this application effectively amplifies distant details. Even tiny cracks or other subtle defects can be clearly captured, improving detection accuracy and reliability. Compared with fisheye lenses, this application can minimize geometric distortion in images, provide more realistic and accurate visual information, focus on maintaining the geometry of the near-field track limits, avoid measurement errors caused by geometric distortion, and ensure the accuracy of important parameters such as track spacing and spike positions.
[0102] In some embodiments, after generating the corrected target trapezoidal area image, the method further includes:
[0103] The super-resolution algorithm is used to supplement the pixels of the target trapezoidal area image to obtain the enhanced target trapezoidal area image;
[0104] The enhanced target trapezoidal region image replaces the trapezoidal region image in the image to be processed to obtain a processed image.
[0105] Specifically, after generating the corrected target trapezoidal region image, a super-resolution algorithm can be used to supplement pixels to further improve image quality and detail. Examples of super-resolution algorithms include Enhanced Super-Resolution Generative Adversarial Networks (ESRGAN) and Super-Resolution Convolutional Neural Networks (SRCNN).
[0106] As an example, a pre-trained super-resolution model can be used to process the target trapezoidal region image, including but not limited to resizing, normalization, and denormalization. Through the above process, an enhanced target trapezoidal region image with higher resolution and richer details is obtained. Furthermore, a corresponding binary mask is created for the enhanced target trapezoidal region image, and the area to be replaced is marked on the mask. The mask is then applied to the image to be processed and the enhanced target trapezoidal region image. Through a pixel-by-pixel comparison, the pixel values in the corresponding positions of the trapezoidal region image in the image to be processed are replaced with the pixel values in the enhanced target trapezoidal region image, ultimately obtaining a complete processed image containing enhanced details.
[0107] Through the above-mentioned super-resolution processing and image replacement, super-resolution enhancement of the target trapezoidal area image is achieved, and the enhanced target trapezoidal area image is seamlessly integrated back into the original image, thereby greatly improving the visual quality of the specific area (trapezoidal area). By applying the super-resolution algorithm, the clarity of the target trapezoidal area image is improved, which is helpful for subsequent image analysis tasks such as object recognition and defect detection. At the same time, the above-mentioned local enhancement can also avoid unnecessary calculations for the entire image, thereby improving processing efficiency. Finally, by accurately fusing the enhanced area and the original image (the image to be processed), the naturalness and consistency of the final result are guaranteed, and a high-quality processed image is obtained, which not only enhances the visual effect of the local area, but also improves the analytical value of the entire image.
[0108] In some embodiments, after generating the corrected target trapezoidal area image, the method further includes:
[0109] Target detection is performed on the target trapezoidal region image to obtain a target detection result, where the target detection result is used to indicate the category of the target to be detected and the confidence level of the target to be detected in the target trapezoidal region image.
[0110] In some embodiments, after generating the corrected target trapezoidal area image, the method further includes:
[0111] Target detection is performed on the target trapezoidal region image to obtain a target detection result, where the target detection result is used to indicate the category of the target to be detected and the confidence level of the target to be detected in the target trapezoidal region image.
[0112] Specifically, after generating the corrected target trapezoidal area image, target detection can be performed on the target trapezoidal area image to identify and classify various targets to be detected in the target trapezoidal area image, and provide category information and confidence score for each target to be detected.
[0113] As an example, you can select a target detection model that is suitable for the current application scenario, perform target detection on the target trapezoidal area image through the target detection model, input the corrected target trapezoidal area image into the target detection model for target detection, convert the target trapezoidal area image into a format suitable for model input, and obtain the detection results through forward propagation, and output the position, category and confidence of each detected target.
[0114] Furthermore, the image trapezoidal correction method proposed in this application can be applied to railway inspection systems. In railway inspection systems, real-time monitoring of the rails and their surroundings is crucial to ensure safe and stable operation. After the corrected target trapezoidal region image (or processed image) is generated, it can be preprocessed, including but not limited to image resizing and color space conversion, to ensure that the data format input to the target detection model meets the requirements. For railway inspection, good preprocessing can effectively improve detection accuracy. A pretrained YOLO model can be selected as the target detector. The preprocessed trapezoidal region image is input into the YOLO model for target detection. A single forward propagation completes all target detection tasks for the entire image, outputting the location, category, and confidence score of each detected target. In a railway environment, the target detector can identify safety hazards such as foreign object intrusion, track cracks, and loose spikes. Based on the results output by the YOLO model, the railway inspection system further analyzes the results, combines the confidence value given by the model with actual railway maintenance standards and empirical knowledge, determines the true safety hazard, and issues corresponding warnings or recommendations. By performing precise target detection on the corrected trapezoidal area image, potential hazards on the track, such as fallen branches, stones, or other foreign objects, can be discovered and located in a timely manner, greatly reducing the risk of serious accidents such as train derailment.
[0115] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the trapezoidal correction method of the image of the present application. More forms of simple transformations based on this technical concept are all within the scope of protection of the present application.
[0116] This application also provides a trapezoidal correction device for an image, please refer to Figure 4 , the image trapezoidal correction device includes:
[0117] The trapezoidal scene detection module 401 is used to determine the coordinates of the first vertices of the trapezoidal region in the image to be processed through trapezoidal scene detection;
[0118] A radial offset module 402 is configured to radially offset the vertices of the trapezoidal region along the central axis of the trapezoidal region based on the first vertex coordinates, and use the offset positions as the second vertex coordinates corresponding to the target trapezoidal region;
[0119] A transformation matrix determination module 403 is configured to determine a target transformation matrix between the trapezoidal region and the target trapezoidal region based on the first vertex coordinates and the second vertex coordinates;
[0120] The geometric correction module 404 is used to transform each pixel point of the trapezoidal area according to the target transformation matrix to generate a corrected target trapezoidal area image.
[0121] The image keystone correction device provided in this application utilizes the image keystone correction method described in the aforementioned embodiment, resolving the technical issue of existing image keystone correction methods being unable to balance distant detail with near-end geometric accuracy. Compared to the prior art, the image keystone correction device provided in this application achieves the same beneficial effects as the image keystone correction method described in the aforementioned embodiment. Other technical features of the image keystone correction device are the same as those disclosed in the aforementioned embodiment and are not further elaborated upon here.
[0122] The present application provides a device for trapezoidal correction of an image, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for trapezoidal correction of an image in the above-mentioned embodiment 1.
[0123] Reference below Figure 5, which shows a schematic structural diagram of an image keystone correction device suitable for implementing the embodiments of the present application. The image keystone correction device in the embodiments of the present application may include, but is not limited to, mobile terminals such as laptop computers, personal digital assistants (PDAs), tablet computers (PADs), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The trapezoidal correction device of the image shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0124] like Figure 5 As shown, the image keystone correction device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the image keystone correction device. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the image keystone correction device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an image keystone correction device with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may alternatively be implemented or have.
[0125] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are performed.
[0126] The image keystone correction device provided in this application utilizes the image keystone correction method described in the aforementioned embodiment, resolving the technical issue of existing image keystone correction methods being unable to balance distant detail with near-end geometric accuracy. Compared to the prior art, the image keystone correction device provided in this application achieves the same beneficial effects as the image keystone correction method described in the aforementioned embodiment. Other technical features of this image keystone correction device are the same as those disclosed in the aforementioned embodiment and are not further elaborated upon here.
[0127] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0128] The above are only specific embodiments of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0129] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, wherein the computer-readable program instructions are used to execute the image trapezoidal correction method in the above-mentioned embodiment.
[0130] The computer-readable storage medium provided in this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared or semiconductor systems, systems or devices, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an optical fiber, a portable compact disk read-only memory (CD-Read Only Memory, CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium can be transmitted using any appropriate medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.
[0131] The computer-readable storage medium may be included in the image keystone correction device; or may exist independently without being assembled into the image keystone correction device.
[0132] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the image trapezoidal correction device, the image trapezoidal correction device enables the following: to determine the first vertex coordinates of the vertices of the trapezoidal area in the image to be processed through trapezoidal scene detection; based on the first vertex coordinates, to radially offset the vertices of the trapezoidal area along the central axis of the trapezoidal area, and to use the offset position as the second vertex coordinate corresponding to the target trapezoidal area; to determine the target transformation matrix between the trapezoidal area and the target trapezoidal area based on the first vertex coordinates and the second vertex coordinates; and to transform each pixel point of the trapezoidal area according to the target transformation matrix to generate a corrected target trapezoidal area image.
[0133] The computer program code for performing the operations of the present application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect via the Internet).
[0134] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can be implemented using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.
[0135] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.
[0136] The computer-readable storage medium provided in this application stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned image keystone correction method. This computer-readable storage medium can address the technical issue of existing image keystone correction methods, which are unable to balance distant detail with near-end geometric accuracy. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the image keystone correction method provided in the aforementioned embodiments, and are not further elaborated here.
[0137] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned image trapezoidal correction method when the computer program is executed by a processor.
[0138] The computer program product provided in this application can address the technical issue of existing image keystone correction methods that are unable to balance distant detail with near-end geometric accuracy. Compared to the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the image keystone correction methods provided in the aforementioned embodiments, and are not further elaborated here.
[0139] The above are only some embodiments of the present application and are not intended to limit the patent scope of the present application. All equivalent structural transformations made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for trapezoidal correction of an image, characterized in that: The trapezoidal correction method comprises: Determine the coordinates of the first vertex of the vertices of the trapezoidal area in the image to be processed by trapezoidal scene detection; Based on the first vertex coordinates, radially offset the vertices of the trapezoidal area along the central axis of the trapezoidal area, and use the offset positions as the second vertex coordinates corresponding to the target trapezoidal area; determining a target transformation matrix between the trapezoidal region and a target trapezoidal region according to the first vertex coordinates and the second vertex coordinates; Each pixel point of the trapezoidal area is converted according to the target conversion matrix to generate a corrected target trapezoidal area image.
2. The image trapezoidal correction method according to claim 1, wherein: The step of determining the coordinates of first vertices of a trapezoidal region in the image to be processed by detecting the trapezoidal scene includes: Performing edge detection on the image to be processed to obtain an edge binary image, wherein the brightness values of edge pixels in the edge binary image are higher than the brightness values of non-edge pixels; Performing line detection on the edge binary image to obtain a set of candidate lines for the trapezoidal region boundary; The first vertex coordinates of the vertices of the trapezoidal region are determined by using the set of candidate straight lines for the trapezoidal region boundary.
3. The image trapezoidal correction method according to claim 1, wherein: The vertices of the trapezoidal area include an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area. Based on the first vertex coordinates, radially offsetting the vertices of the trapezoidal area along the central axis of the trapezoidal area and using the offset positions as the second vertex coordinates corresponding to the target trapezoidal area includes: determining a first depth between an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area, and determining a first adjustment coefficient corresponding to the first depth based on a preset correspondence between depths and adjustment coefficients and the first depth; Determine a first radial offset of the upper vertex according to the length of the upper side of the trapezoidal area and the first adjustment coefficient; Based on the first radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinates of the lower vertex of the trapezoidal area are determined as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
4. The image trapezoidal correction method according to claim 1, wherein: The vertices of the trapezoidal area include an upper vertex of the trapezoidal area and a lower vertex of the trapezoidal area. Based on the first vertex coordinates, radially offsetting the vertices of the trapezoidal area along the central axis of the trapezoidal area and using the offset positions as the second vertex coordinates corresponding to the target trapezoidal area includes: Obtaining a second adjustment coefficient input by a user, and determining a second radial offset of the upper vertex according to the length of the upper side of the trapezoidal area image and the second adjustment coefficient; Based on the second radial offset of the upper vertex, the upper vertex of the trapezoidal area is radially offset along the central axis of the trapezoidal area to obtain the second upper vertex coordinates corresponding to the upper vertex of the target trapezoidal area, and the first lower vertex coordinates of the lower vertex of the trapezoidal area are determined as the second lower vertex coordinates corresponding to the lower vertex of the target trapezoidal area.
5. The image trapezoidal correction method according to claim 1, wherein: The determining of a target transformation matrix between the trapezoidal region and the target trapezoidal region according to the first vertex coordinates and the second vertex coordinates includes: Based on the first vertex coordinates of the vertices of the trapezoidal area and the second vertex coordinates of the vertices of the target trapezoidal area, an algorithm for obtaining a perspective transformation matrix is called to obtain the target transformation matrix.
6. The image trapezoidal correction method according to claim 1, wherein: The step of converting each pixel point of the trapezoidal area according to the target conversion matrix to generate a corrected target trapezoidal area image includes: Traversing each pixel point of the trapezoidal area, and calculating corresponding coordinates of each pixel point in the target trapezoidal area image using the target transformation matrix; generating an initial target trapezoidal area image based on corresponding coordinates of each pixel point in the target trapezoidal area image; Mask fusion is performed on the initial target trapezoidal region image and the trapezoidal region image to fill blank areas in the initial target trapezoidal region image that are not covered by original pixels, so as to obtain a corrected target trapezoidal region image.
7. The image trapezoidal correction method according to claim 1, wherein: After generating the corrected target trapezoidal area image, the method further includes: Using a super-resolution algorithm to perform pixel supplementation on the target trapezoidal region image to obtain an enhanced target trapezoidal region image; The enhanced target trapezoidal region image replaces the trapezoidal region image in the image to be processed to obtain a processed image.
8. The image trapezoidal correction method according to claim 1, wherein: After generating the corrected target trapezoidal area image, the method further includes: Target detection is performed on the target trapezoidal area image to obtain a target detection result, where the target detection result is used to indicate the category of the target to be detected and the confidence level of the target to be detected in the target trapezoidal area image.
9. An image trapezoidal correction device, characterized in that: The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the image keystone correction method according to any one of claims 1 to 8.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the image trapezoidal correction method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Drawing processing system, quick fetching system and data processing method
CN101388109A
Real-time image correction method based on cell phone platform
CN106952231A
Keystone correction method and equipment for projection system
CN108924521A
Calibration method and device based on multiocular vision
CN109341718A
Rapid geometric correction method and system for unmanned aerial vehicle remote sensing images
CN110555813A