FPGA-based camera image distortion correction method
By performing block readback and quadratic fitting curve coefficient calculation on the FPGA hardware, the problems of storage resource occupation and latency in large distortion and high resolution image distortion correction are solved, thereby improving the resource utilization and processing efficiency of the FPGA.
Patent Information
- Application Number
- CN202411211266.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-21
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-08-21
AI Technical Summary
When implementing image distortion correction in FPGA hardware, especially for images with large distortion and high resolution, there are issues such as the problem of back-mapping occupying a large amount of storage resources on the FPGA chip, and the problem of low latency and bandwidth utilization when using external memory such as DDR or SDRAM as image cache.
An FPGA-based camera image distortion correction method is adopted. The distorted image is read back to local storage in blocks. The block regions are determined by using preset quadratic fitting curve coefficients and FPGA local line cache capacity. The pixel values are calculated according to the correction coordinates to generate the corrected image.
This reduces the demand for FPGA local storage resources, improves FPGA resource utilization, avoids latency issues, increases processing speed, and reduces DDR bandwidth usage, thus ensuring processing efficiency.
Smart Images

Figure CN119090784B_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent filed on August 21, 2023, with application number 2023110518355 and invention title "A Camera Image Distortion Correction Method Based on FPGA". Technical Field
[0002] This invention relates to the field of image processing, and more particularly to a camera image distortion correction method based on FPGA. Background Technology
[0003] Cameras are crucial sensors in computer vision, but images captured by cameras inevitably suffer from distortions such as barrel and pincushion distortion. The direct cause of these distortions is the difference in magnification between the edges and center of the lens, an inherent characteristic of optical lenses. This distortion results in only the central region of the image remaining straight, while other parts become curved, with the distortion increasing further away from the image center. Therefore, it is essential to eliminate the adverse effects of image distortion before performing image detection / recognition.
[0004] Most existing image distortion correction techniques employ either backward mapping or forward mapping. Backward mapping maps the integer coordinates of the corrected image onto the distorted image, interpolating the new pixels using the pixels surrounding the mapped point. This backward mapping process requires caching a certain amount of image data. The size of the cached image is directly proportional to the degree of image distortion and image resolution. Furthermore, as camera resolution increases and image distortion intensifies, the demand for hardware storage resources in the camera also increases.
[0005] Taking FPGA chips as an example, since general devices also require a certain amount of storage resources during other logic designs / processing, it is impossible to use most of the storage resources for image caching. Even if other logic occupies relatively few storage resources, using a large amount of storage resources in the FPGA chip for image caching would result in resource waste and increase the difficulty of placement and routing. Therefore, most design solutions use external SDRAM (Synchronous Dynamic Random Access Memory) or DDR (Double Data Rate Synchronous Dynamic Random Access Memory) for image caching. However, since external memory requires real-time access during image distortion correction, this introduces latency issues caused by frequent bus access and DDR bandwidth occupation issues, which in turn leads to a decrease in the FPGA chip's processing frame rate and a decrease in the processing speed of the SOC that shares the DDR with it.
[0006] Therefore, how to solve the problem of the back-mapping method occupying a large amount of storage resources of the FPGA chip when implementing image distortion correction in FPGA hardware, especially for large distortion and high resolution images, and the problem of low latency and bandwidth utilization caused by using external memory such as DDR or SDRAM as image cache are issues that urgently need to be addressed by those skilled in the art. Summary of the Invention
[0007] The technical problems to be solved by this application are: how to solve the problem that the backward mapping method occupies a lot of storage resources of the FPGA chip when implementing image distortion correction in FPGA hardware, especially for large distortion and high resolution images, and the problem of low latency and low bandwidth utilization when using external memory such as DDR or SDRAM as image cache.
[0008] To address the aforementioned technical problems, this application proposes a camera image distortion correction method based on FPGA, the correction method comprising:
[0009] Step 1: Buffer the received original distorted image and read the preset quadratic fitting curve coefficients. Read the preset quadratic fitting coefficients corresponding to the correction coordinates from the coefficient buffer in DDR to the FPGA local.
[0010] Step 2: Determine the block region by coordinate calculation based on the preset quadratic fitting curve coefficients and the preset FPGA local row cache capacity.
[0011] Any set of preset quadratic fitting curve coefficients corresponds to a row of pixels in the corrected image. Step 2 specifically includes:
[0012] Step 2.1: Based on any set of preset quadratic fitting curve coefficients, construct the corresponding correction coordinate calculation equation;
[0013] Step 2.2: Based on the calibration coordinate calculation equation and the preset FPGA local line cache capacity, determine the first starting point and the maximum block position of the first block region corresponding to each set of preset quadratic fitting curve coefficients in turn by coordinate calculation.
[0014] Step 2.3: Select the minimum value of the column coordinates in each maximum block position, and take the corresponding maximum block position as the first end point of the first block region. Determine the first block region based on the first start point and the first end point.
[0015] Step 2.4: Based on the first termination point and the corresponding correction coordinate calculation equation, determine the second starting point of the second block region. Repeat step 2.2 to determine each block region of the original distorted image in sequence.
[0016] The first starting point is determined by the constant term coefficient in the preset quadratic fitting curve coefficients;
[0017] Step 3: Based on the segmented regions, determine the readback regions in the original distorted image row by row;
[0018] Step 4: Based on the readback area, read back the original distorted image from DDR and cache it locally. Read back the original distorted image and record it as the readback image. Read the pixel values of the pixels around the correction coordinates in the readback image. The correction coordinates are determined by the preset quadratic fitting curve coefficients.
[0019] Step 5: Based on the pixel values of the pixels surrounding the correction coordinates in the readback image, the pixel values of the four pixels to be read corresponding to the correction coordinates are read from the readback image. Interpolation is used to determine the pixel values of the points to be corrected, and a correction image is generated based on the pixel values of the points to be corrected.
[0020] In any of the above technical solutions, step 2.2 further includes: rounding up the first starting point;
[0021] Based on the preset FPGA local row buffer capacity, the row coordinates of the first starting point after rounding are moved up or down; based on the moved row coordinates, the corresponding column coordinates are calculated using the corresponding correction coordinate calculation equation; the calculated column coordinates are rounded up, and the maximum block position is determined based on the moved row coordinates and the rounded column coordinates.
[0022] In any of the above technical solutions, the row coordinate of the rounded first starting point is moved up or down according to the preset FPGA local row buffer capacity, specifically including:
[0023] Based on the calibration coordinate calculation equation, a preset number of calibration coordinates are obtained after the first starting point; the row coordinate movement direction is determined based on the row coordinate change trend of the preset number of calibration coordinates; and the row coordinates of the first starting point are moved and rounded based on the preset FPGA local row cache capacity and the row coordinate movement direction.
[0024] In any of the above technical solutions, step 2.4, determining the second starting point of the second segmented region based on the first termination point and the corresponding correction coordinate calculation equation, specifically includes:
[0025] Using coordinate calculation, based on the correction coordinate calculation equation, it is determined whether the column coordinate of the first termination point corresponds to the column coordinate of the correction coordinate. If so, the pixel point corresponding to the correction coordinate is taken as the second starting point of the second block region. If not, the pixel point corresponding to the last correction coordinate contained in the first block region is taken as the second starting point of the second block region.
[0026] In any of the above technical solutions, step 2.2 further includes: counting the number of correction coordinates contained between the first starting point and the maximum block position in the first block area; determining whether the number is less than or equal to the preset local coordinate cache capacity; if yes, proceeding to step 2.3; if no, selecting the last correction coordinate to update the maximum block position according to the preset local coordinate cache capacity, and proceeding to step 2.3.
[0027] In any of the above technical solutions, the preset quadratic fitting curve coefficients include x-axis fitting coefficients and y-axis fitting coefficients. The x-axis fitting coefficients are determined by fitting the horizontal coordinates of the corresponding corrected coordinates in the original distorted image, and the y-axis fitting coefficients are determined by fitting the vertical coordinates of the corresponding corrected coordinates in the original distorted image.
[0028] The formula for calculating the equation for corrected coordinates is as follows:
[0029]
[0030] In the formula, Fx(z) is the calculated row coordinate of the z-th point to be corrected in the original distorted image corresponding to the corrected coordinates; ax, bx, and cx are the quadratic, linear, and constant coefficients of the x-axis fitting coefficients, respectively; Fy(z) is the column coordinate of the z-th point to be corrected in the original distorted image corresponding to the corrected coordinates; ay, by, and cy are the quadratic, linear, and constant coefficients of the y-axis fitting coefficients, respectively; z is the number of the point to be corrected, z = 0, 1, 2, ..., n, where n is the set number of points to be corrected.
[0031] In any of the above technical solutions, step 4, reading the pixel values of the pixels surrounding the correction coordinates in the readback image, specifically includes: rounding down the correction coordinates of the current point to be corrected in the readback image; determining the pixel at its upper left corner as the first pixel to be read based on the rounded correction coordinates, and selecting the other three coordinate points adjacent to the first pixel to be read as the second to fourth pixels to be read, starting from the first pixel to be read and proceeding clockwise; and reading the pixel values of the four pixels to be read from the readback image.
[0032] Compared with the prior art, the beneficial effects of this application are as follows:
[0033] 1. The FPGA-based camera image distortion correction method provided in this application introduces a method of reading back distorted images from hardware storage in blocks and caching them locally. Based on preset quadratic fitting curve coefficients and preset FPGA local row cache capacity, the area of the distorted image that needs to be read back is determined by coordinate calculation. Based on the read-back area, the pixel values of the pixels around the correction coordinates in the read-back image are read, and the pixel values of the points to be corrected are determined, thereby generating a corrected image. By reading back distorted images from hardware storage in blocks and caching them locally on the FPGA, each block of image only needs to cache a few rows, which solves the problem of the need for a large amount of local storage resources on the FPGA. Even under the requirements of large distortion and high resolution, the local storage resources occupied by the distortion correction function on the FPGA are minimized, thereby improving the utilization rate of FPGA resources.
[0034] 2. The FPGA-based camera image distortion correction method provided in this application, based on the hardware storage cache of the whole frame image, reads back part of the image to the FPGA local storage and uses it for correction calculation, thereby avoiding the latency problem caused by directly operating the memory itself. Moreover, the whole process uses a pipelined processing method, which greatly improves the processing speed and the distortion correction processing frame rate is greatly improved.
[0035] 3. The FPGA-based camera image distortion correction method provided in this application addresses the problem of traditional solutions where direct DDR operation requires accessing DDR once or multiple times for each point processed, resulting in a large amount of readback data, frequent bus operations consuming significant DDR bandwidth, and consequently slowing down the operating system's processing speed. In this application, the readback of distorted images is processed in blocks, with each block containing at most the number of locally cached image data lines. Generally, only the line difference between the current line and the previous line within the current block needs to be read back, greatly reducing the DDR bandwidth usage for distortion correction and ensuring DDR efficiency.
[0036] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the preferred embodiments of this application are described in detail below with reference to the accompanying drawings.
[0037] The above and other objects, advantages and features of this application will become more apparent to those skilled in the art from the following detailed description of specific embodiments in conjunction with the accompanying drawings. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In all drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn to scale.
[0039] Figure 1 This is a flowchart of the FPGA-based camera image distortion correction method in this application;
[0040] Figure 2 This is a schematic diagram showing the composition of the correction coordinates and the quadratic fitting coefficients in the embodiments of this application;
[0041] Figure 3 This is a schematic diagram of the process of segmenting a distorted image into blocks in an embodiment of this application;
[0042] Figure 4 This is another schematic diagram illustrating the process of segmenting a distorted image into blocks in an embodiment of this application;
[0043] Figure 5 This is a schematic diagram illustrating the process of determining the readback position in an embodiment of this application;
[0044] Figure 6 This is a schematic diagram of block division and caching of distorted images in an embodiment of this application;
[0045] Figure 7 This is a schematic diagram of the bilinear interpolation principle in the embodiments of this application. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. In the following description, specific details such as specific configurations and components are provided merely to help fully understand the embodiments of this application. Therefore, those skilled in the art should understand that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. In addition, for clarity and brevity, descriptions of known functions and structures are omitted in the embodiments.
[0047] It should be understood that the phrase "an embodiment" or "this embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "an embodiment" or "this embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.
[0048] Furthermore, reference numerals and / or letters may be repeated in different examples within this application. Such repetition is for the purpose of simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or settings discussed.
[0049] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, B exists alone, and A and B exist simultaneously. The term " / and" in this article describes another type of relationship between related objects, indicating that two relationships can exist. For example, A / and B can mean: A exists alone, and A and B exist alone. In addition, the character " / " in this article generally indicates that the related objects before and after it are in an "or" relationship.
[0050] In this article, the term "at least one" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, "at least one of A and B" can mean: A exists alone, A and B exist simultaneously, or B exists alone.
[0051] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion.
[0052] Example 1
[0053] Existing image distortion correction methods employ back-mapping, which maps the integer coordinates of the corrected image onto the distorted image, interpolating the corresponding new pixels using the pixels surrounding the mapped points. However, back-mapping requires buffering a certain amount of image data. The size of the buffered image is directly proportional to the degree of distortion and image resolution. As camera resolution and distortion increase, the demand for hardware storage resources in the camera also grows. Therefore, for images with large distortion and high resolution, back-mapping consumes significant FPGA storage resources. Furthermore, using external hardware memory for image buffering introduces substantial latency and low bandwidth utilization.
[0054] To address this, this embodiment provides a camera image distortion correction method based on FPGA. This method introduces the idea of reading back the distorted image from hardware storage in blocks and caching it locally. This solves the problem of large local storage resource consumption of FPGA during image distortion correction. Even under the conditions of large distortion and high resolution, it can effectively reduce the local storage resource consumption of FPGA during distortion correction and improve the utilization rate of FPGA resources.
[0055] Combined with appendix Figure 1 As shown, the correction method in this embodiment includes: Step 1, performing frame buffering on the received original distorted image and reading preset quadratic fitting curve coefficients; Step 2, determining the block region by coordinate calculation based on the preset quadratic fitting curve coefficients and the preset FPGA local row buffer capacity; Step 3, determining the readback region in the original distorted image row by row based on the block region; Step 4, reading back the original distorted image based on the readback region, recording it as the readback image, and reading the pixel values of the pixels around the correction coordinates in the readback image, wherein the correction coordinates are determined by the preset quadratic fitting curve coefficients; Step 5, determining the pixel value of the point to be corrected based on the pixel value of the pixel around the correction coordinates in the readback image, and generating a corrected image based on the pixel value of the point to be corrected.
[0056] Those skilled in the art will understand that, for a camera, the coordinate correspondence between pixels in the corrected image and the original distorted image before and after correction depends on the camera's intrinsic distortion parameters obtained through camera calibration, calculated based on the pinhole camera mathematical model and the camera distortion mathematical model. Therefore, once the aforementioned camera parameters are determined, the coordinates of each pixel in the corrected image mapped to the distorted image are fixed.
[0057] In this embodiment, the image captured by the camera is denoted as the original distorted image, the image generated after distortion correction is denoted as the corrected image, the pixels in the corrected image are denoted as points to be corrected, the corresponding coordinates are denoted as the coordinates of the points to be corrected, and the coordinates of the points to be corrected mapped to the coordinates in the original distorted image are denoted as the corrected coordinates.
[0058] Considering that directly using correction coordinates during distortion correction would significantly increase the memory size required to store them in DDR and the bandwidth needed to read them back from DDR, this embodiment uses two quadratic curves fitted to the x-axis and y-axis coordinates of several correction coordinates, denoted as preset quadratic fitting curves. Only the coefficients of these preset quadratic fitting curves (preset quadratic fitting curve coefficients) are stored in DDR. During distortion correction, these coefficients are read from DDR to the FPGA, and then the correction coordinates are obtained through inverse fitting operations.
[0059] like Figure 2 As will be understood by those skilled in the art, the position coordinates of each point are 8 bytes, including 4 bytes each for the horizontal and vertical coordinates. Each horizontal and vertical coordinate contains a 2-byte integer part and a 2-byte decimal part. Each quadratic fitting curve requires 3 coefficients, each coefficient being 4 bytes. This embodiment can be configured to use 64 correction point coordinates to fit two preset quadratic fitting curves to the horizontal and vertical coordinates. Calculated using 64 correction point coordinates as a unit, directly using the coordinates requires 512 bytes, while using the quadratic fitting scheme only requires 24 bytes. In this example, the scheme of reading preset quadratic fitting curve coefficients proposed in this embodiment reduces DDR memory and bandwidth usage by approximately 95% compared to the traditional scheme of directly using correction coordinates.
[0060] It should be noted that any set of preset quadratic fitting curve coefficients corresponds to the coordinates of a row of pixels in the corrected image.
[0061] Specifically, when the resolution of the corrected image is 1920*1080, each row of pixels is divided into 30 segments from left to right in groups of 64. Each segment of pixels can be fitted with a quadratic fitting curve, corresponding to a quadratic fitting curve coefficient. Each group of pixels (points to be corrected) is sequentially labeled as 0-63.
[0062] Therefore, every 30 segments of quadratic fitting curve coefficients can form a set of preset quadratic fitting curve coefficients, corresponding to a row of pixels in the corrected image. Thus, a total of 30*1080 segments and 1080 sets of preset quadratic fitting curve coefficients can be obtained.
[0063] After obtaining the preset quadratic fitting curve coefficients by reading back, the labels of the points to be corrected are sequentially substituted into the coordinates. The corresponding corrected coordinates in the original distorted image can then be obtained through coordinate calculation. Subsequently, a block-based approach can be adopted. Based on the preset FPGA local row buffer capacity, such as 8 rows, the first corrected coordinate corresponding to each set of preset quadratic fitting curve coefficients is taken as the starting point of the block region. After moving 8 rows, the last corrected coordinate of the corresponding row is taken as the ending point of the current block region. The corrected coordinates corresponding to this ending point are then taken as the starting point of the next block region. The above process is repeated until all the block regions corresponding to all sets of preset quadratic fitting curve coefficients are determined.
[0064] Subsequently, when correcting each frame of the original distorted image, the image's segmented regions remain unchanged. Based on the determined segmented regions, the readback region in the original distorted image corresponding to the corrected image is determined row by row. First, the column coordinates of the corrected coordinates in the original distorted image are compared with the segmented regions to determine the segment in which it belongs, obtaining the column start position and column number of the image to be read back. Then, the smallest row coordinate in the original distorted image among all the corrected coordinates in each segmented region of the current row needs to be found as the row start position of the readback region. Finally, the number of rows to be moved down or up by the preset FPGA local row buffer capacity is determined, i.e., moving down or up by 8 rows, thus determining the region of the original distorted image that needs to be read back, i.e., the readback region.
[0065] When correcting the next row, the above process is repeated. The resulting readback area is compared to the readback area of the previous corrected row. Only a few rows have changed, or none have changed. Only the row numbers of the changed image sections need to be updated to meet the correction requirements of the current row. For example, if the current readback area has only changed by two rows compared to the previous corrected row, only those two changed rows need to be read.
[0066] Therefore, after segmentation, the image that each correction row needs to read back is at most the locally set row cache capacity. The amount of image data that needs to be read back after the entire frame correction is completed does not exceed the size of one frame. Compared with the traditional DDR solution, which requires at least 4 frames of image data to be read back, the DDR bandwidth usage is reduced by more than 75%.
[0067] Furthermore, based on the identified readback area, the original distorted image can be read back, and then pixel value calculations (such as interpolation) can be performed based on the pixel values of the pixels around the correction coordinates to calculate the corresponding pixel values to be corrected, generating the final corrected image to be output, thus completing the image distortion correction.
[0068] In some embodiments, a method for determining block regions as described in Embodiment 1 above is shown. Step 2 specifically includes: Step 201, constructing a corresponding correction coordinate calculation equation based on any set of preset quadratic fitting curve coefficients; Step 202, calculating each correction coordinate in the original distorted image sequentially using coordinate calculation based on the correction coordinate calculation equation; Step 203, determining the first starting point and maximum block position of the first block region corresponding to each set of preset quadratic fitting curve coefficients sequentially according to the order of the correction coordinates, based on the preset FPGA local line cache capacity; Step 204, selecting each maximum block position. The minimum value of the column coordinates is used as the first end point of the first block region, and the first block region is determined according to the first start point and the first end point. Step 205: According to the first end point and the correction coordinates, the second start point of the second block region is determined. Step 203 is repeated to determine each block region of the original distorted image in sequence. Wherein, the first start point is the first correction coordinate corresponding to the preset quadratic fitting curve coefficient, the second start point is the first correction coordinate to the right of the first end point in the correction coordinates, or the second start point is the correction coordinate that is the same as the column coordinate of the first end point in the correction coordinates.
[0069] Specifically, by reading back the pre-set quadratic fitting curve coefficients, the corresponding curve and the corresponding correction coordinate calculation equation can be fitted. Then, by using coordinate calculation, all the correction coordinates used for pixel correction in the original distorted image can be calculated.
[0070] First, the first calibration coordinate corresponding to the coefficients of each set of preset quadratic fitting curves is taken as the first starting point. According to the preset FPGA local row cache capacity (e.g., 8 rows), in the order of calibration coordinates, when the difference between the selected calibration coordinate and the row coordinate of the first starting point reaches 8, the calibration coordinate is the maximum block position corresponding to the first starting point.
[0071] Then, to ensure that the limited read-back images meet the requirements for correcting the maximum distortion, the original distorted image is divided into several regions (blocks) with the same number of columns in the horizontal direction. The positions of the corresponding regions in each row of the original distorted image are standardized to reduce the number of parameters at the block positions. The minimum value of the column coordinates among the maximum block positions corresponding to each set of preset quadratic fitting curve coefficients is selected, and the corresponding coordinate point is used as the first termination point. The first block region can be determined based on the first starting point and the first termination point.
[0072] Finally, after determining the first block region, the last correction coordinate contained in this region may be located on the boundary of the region (the correction coordinate is the same as the minimum value of the column coordinate in the maximum block position) or it may be located to the right of the boundary of the region. Therefore, the first correction coordinate to the right of the first termination point, or the correction coordinate that is the same as the column coordinate of the first termination point, is selected as the second starting point of the second block region (the next block region). Step 203 is repeated to determine the maximum block position corresponding to each second starting point. The above process is repeated to determine each block region of the original distorted image in turn.
[0073] Then, the corrected image is determined line by line to correspond to the readback region in the original distorted image.
[0074] In some embodiments, step 203 specifically includes: selecting the first correction coordinate corresponding to each set of preset quadratic fitting curve coefficients and recording it as the first starting point of the first block region; calculating the row difference between the row coordinates of each correction coordinate after the first starting point and the row coordinate of the first correction coordinate in sequence according to the order of the correction coordinates; when the row difference is greater than the preset FPGA local row cache capacity, selecting the previous correction coordinate and recording it as the maximum block position of the first block region.
[0075] To ensure that the limited readback images meet the requirements for correcting the maximum distortion, the distorted image is horizontally divided into several regions with the same number of columns. Furthermore, to reduce the number of parameters for each block location, the idea of determining the maximum block location is introduced to unify the position of each row of block regions. In some embodiments, another method for determining the block region as described in Embodiment 1 above is also shown. This step 2 includes: Step 2.1, constructing the corresponding correction coordinate calculation equation based on any set of preset quadratic fitting curve coefficients; Step 2.2, calculating the correction coordinates based on the correction coordinate calculation equation and the preset FPGA local row buffer capacity. Step 2.3: Select the minimum value of the column coordinates in each maximum block position and take the corresponding maximum block position as the first termination point of the first block region. Determine the first block region based on the first starting point and the first termination point. Step 2.4: Determine the second starting point of the second block region based on the first termination point and the corresponding correction coordinate calculation equation. Repeat step 2.2 to determine each block region of the original distorted image in turn. The first starting point is determined by the constant term coefficient in the preset quadratic fitting curve coefficients.
[0076] Specifically, such as Figure 3 and Figure 4As shown, taking barrel distortion as an example, the horizontal midline of the original distorted image divides the distorted image into upper and lower parts. The first correction coordinate corresponding to the coefficients of each set of preset quadratic fitting curves is used as the first starting point (such as point A). The first starting point includes row coordinates and column coordinates.
[0077] For the upper part of the image, based on the preset FPGA local row buffer capacity (e.g., 8 rows), the row coordinate of the first starting point is moved upwards by 8 rows (i.e., the coordinate value is reduced by 8), while the column coordinate remains unchanged. This allows us to determine the intersection point of the 8th row after the upward movement with the curve corresponding to the coefficient of the quadratic fitting curve in that row. This intersection point is the maximum block position. For the lower part of the image, the coordinates are moved downwards by 8 rows, and the rest of the process is the same.
[0078] It should be noted that for pincushion distortion, the upper part of the image moves downwards, and the lower part of the image moves upwards.
[0079] Then, determine the first starting point and the maximum block position of the next set of preset quadratic fitting curve coefficients, until the maximum block position of all sets of preset quadratic fitting curve coefficients is determined.
[0080] To ensure the consistency of the block size and reduce the bandwidth occupied by DDR during image readback, the minimum value of the column coordinates among the above maximum block positions is selected as the column coordinate of the first termination point. The row coordinates after moving 8 rows are used as the row coordinates of the first termination point. The first termination point (such as point B) of the first block region corresponding to all the preset quadratic fitting curve coefficients is obtained, and thus the first block region is obtained.
[0081] Then, based on the column coordinates of the first termination point and the corresponding correction coordinates, calculate the intersection point (such as point C) of the first block region and the quadratic fitting curve corresponding to the preset quadratic fitting curve coefficients. Use this intersection point as the second starting point of the second block region. Repeat the above process to determine each block region of the original distorted image.
[0082] In some embodiments, considering that the correction coordinates mapped to the original distorted image are not continuous and may be decimals, the left boundary of a block region may be the same as the column coordinate of a certain correction coordinate. In this case, the pixel corresponding to the correction coordinate is located on the left boundary of the block region. The left boundary of the block region may also be located between the pixels corresponding to two correction coordinates. Therefore, in order to ensure the accuracy of the starting point of the next block region and to obtain accurate pixel values in subsequent pixel correction operations, step 2.4 above further includes: using coordinate calculation, according to the correction coordinate calculation equation, determining whether the column coordinate of the first termination point corresponds to the column coordinate of the correction coordinate. If yes, it indicates that the pixel corresponding to the correction coordinate is located on the left boundary of the block region, and therefore the pixel is used as the second starting point of the second block region. If no, it indicates that the left boundary of the block region is located between the pixels corresponding to two correction coordinates. In this case, the pixel corresponding to the last correction coordinate contained in the first block region (the previous block region) is used as the second starting point of the second block region to ensure that the next block region can contain all the pixels required for the corresponding correction coordinate correction, and to ensure that accurate pixel values can be obtained in subsequent pixel correction operations.
[0083] In some embodiments, the preset quadratic fitting curve coefficients include x-axis fitting coefficients and y-axis fitting coefficients. The x-axis fitting coefficients are determined by fitting the horizontal coordinate of the corresponding corrected coordinate in the original distorted image, and the y-axis fitting coefficients are determined by fitting the vertical coordinate of the corresponding corrected coordinate in the original distorted image. The calculation formula for the corrected coordinate calculation equation is as follows:
[0084]
[0085] In the formula, F x (z) is the row coordinate of the z-th point to be corrected, corresponding to the correction coordinate in the original distorted image, a x b x c x These are the quadratic term coefficient, linear term coefficient, and constant term coefficient in the x-axis fitting coefficients, respectively, F y (z) is the column coordinate of the z-th point to be corrected, corresponding to the correction coordinates in the original distorted image, a y b y c y These are the quadratic term coefficient, linear term coefficient, and constant term coefficient in the y-axis fitting coefficients, respectively. z is the number of the point to be corrected, z = 0, 1, 2, ..., n, where n is the set number of points to be corrected.
[0086] In some embodiments, step 2.2 further includes: rounding the first starting point upwards; moving the row coordinates of the rounded first starting point up or down by M rows according to the preset FPGA local row cache capacity; calculating the corresponding column coordinates using the corresponding correction coordinate calculation equation based on the moved row coordinates; rounding the calculated column coordinates upwards; and determining the maximum block position based on the moved row coordinates and the rounded column coordinates.
[0087] In some embodiments, the row coordinates of the rounded first starting point are shifted up or down by M rows according to the preset FPGA local row buffer capacity. Specifically, this includes: when the distortion type of the original distorted image is determined to be barrel distortion, determining whether the row coordinates of the rounded first starting point are less than or equal to 1 / 2 of the number of rows in the original distorted image; if yes, shifting the row coordinates of the rounded first starting point up by M rows according to the preset FPGA local row buffer capacity; if no, shifting the row coordinates of the rounded first starting point down by M rows according to the preset FPGA local row buffer capacity. When the distortion type of the original distorted image is determined to be pincushion distortion, determining whether the row coordinates of the rounded first starting point are less than or equal to 1 / 2 of the number of rows in the original distorted image; if yes, shifting the row coordinates of the rounded first starting point down by M rows according to the preset FPGA local row buffer capacity; if no, shifting the row coordinates of the rounded first starting point up by M rows according to the preset FPGA local row buffer capacity.
[0088] In some embodiments, the row coordinates of the rounded first starting point are moved up or down according to the preset FPGA local row cache capacity. Specifically, this includes: obtaining a preset number of correction coordinates after the first starting point according to the correction coordinate calculation equation, wherein the preset number can be manually set; determining the row coordinate movement direction according to the row coordinate change trend of the preset number of correction coordinates, that is, when the row coordinates show a decreasing trend, it indicates that the corresponding quadratic fitting curve bends upward, and the row coordinate movement direction should be upward; when the row coordinates show an increasing trend, it indicates that the corresponding quadratic fitting curve bends downward, and the row coordinate movement direction should be downward; and moving the row coordinates of the rounded first starting point according to the preset FPGA local row cache capacity and the row coordinate movement direction.
[0089] In some embodiments, the method for determining the maximum block position can also be as follows: The values of the row coordinates in the adjacent correction coordinates after the first starting point are counted sequentially. When the row difference reaches the preset FPGA local row buffer capacity, the corresponding position is the maximum block position. For example, assuming the local row buffer capacity is M rows, the coordinates of each point in the distorted image on the curve can be calculated. A starting point is determined, and this starting point is taken as the first coordinate point on the curve. The row difference between the first and second coordinate points is calculated to see if it is greater than or equal to M. If not, the row difference between the first and third coordinate points is calculated until the row difference between the last coordinate point and the first coordinate point on the curve is greater than or equal to M. At this point, the last coordinate point is taken as the final maximum block position.
[0090] In some embodiments, step 2.2 above further includes: counting the number of correction coordinates contained between the first starting point and the maximum block position in the first block region; determining whether the counted number is less than or equal to the preset local coordinate cache capacity N; if yes, proceeding to step 2.3; if no, according to the preset local coordinate cache capacity N, starting from the first starting point, selecting the last correction coordinate among the N correction coordinates to update the maximum block position, and proceeding to step 2.3.
[0091] In this embodiment, the distorted image is read back in blocks. The amount of image data in each block is at most the number of locally cached rows. Generally, it is only necessary to read back the data amount of the row difference between the current row and the previous row in the current block, which greatly reduces the bandwidth occupied by the hardware memory to implement the distortion correction function and ensures the efficiency of memory use.
[0092] In some embodiments, step 4, reading the pixel values of pixels surrounding the correction coordinates in the readback image, specifically includes: rounding down the correction coordinates in the readback image corresponding to the current point to be corrected; determining the pixel at its upper left corner as the first pixel to be read based on the rounded correction coordinates, and selecting the remaining three coordinate points adjacent to the first pixel to be read as the second to fourth pixels to be read, starting from the first pixel to be read and proceeding clockwise; and reading the pixel values of the four pixels to be read from the readback image.
[0093] In some embodiments, step 5, determining the pixel value of the point to be corrected based on the pixel values of the pixels surrounding the correction coordinates in the readback image, specifically includes: determining the pixel value of the point to be corrected using interpolation based on the pixel values of the four pixels corresponding to the correction coordinates read from the readback image. The interpolation principle is as follows: Figure 7 As shown. The formula for calculating the pixel value of the point to be corrected is as follows:
[0094] X = X lu *(1-a)*(1-b)+Xru *a*(1-b)+X ld *(1-a)*b+X rd *a*b
[0095] In the formula, X is the pixel value of the point to be corrected. lu X ru X ld X rd These are the pixel values of the four pixels to be read, and a and b are the decimal parts of the column coordinate and row coordinate in the calibration coordinate, respectively.
[0096] The FPGA-based camera image distortion correction method proposed in this embodiment only requires caching a few lines regardless of the degree of image distortion, and the FPGA local storage resources used are relatively fixed and limited. Compared with the caching scheme before block partitioning, which required caching as many lines as the distortion was large, this method can greatly alleviate the pressure on FPGA storage resources when dealing with high resolution and high distortion.
[0097] Example 2
[0098] Based on Embodiment 1, this embodiment takes barrel distortion as an example to specifically illustrate a camera image distortion correction method based on FPGA. The correction method includes the following steps:
[0099] Step 100: Frame buffering of the received raw distorted image; Step 1 is to receive the raw distorted image and then write the raw distorted image into the reserved frame buffer area in DDR through the high-speed data bus interface.
[0100] In the implementation of step 1, the FPGA includes two modules: one is the image_cache module, which is used to receive images, cache the length of a burst transmission, and complete the Axi data transmission control; the other is the axi_datamover module, which is used to handle the data interaction with the Axi high-speed data interface.
[0101] Step 200: Read the preset quadratic fitting curve coefficients; the main function of this step is to read the preset quadratic fitting coefficients corresponding to the correction coordinates from the coefficient buffer in DDR to the FPGA. In implementation, the FPGA includes two modules: one is the fit_coef_read module, which controls the alternating issuance of commands to read the fitting coefficients of the left and right plots in DDR; the other is the axi_datamover module, which handles data interaction with the Axi high-speed data interface.
[0102] In this embodiment, a backward mapping approach is used. The correspondence between pixel coordinates before and after correction relies on the camera's intrinsic distortion parameters obtained from camera calibration. These parameters are calculated based on the pinhole camera mathematical model and the camera distortion mathematical model; the calculation process is not detailed here. Therefore, once the aforementioned camera parameters are determined, the coordinates of each pixel in the corrected image mapped to the original distorted image are fixed.
[0103] The coordinates of pixels in the corrected image are mapped to the coordinates in the original distorted image to form the corrected coordinates. However, considering that directly using the corrected coordinates during the correction process would significantly increase the memory size required to store them in DDR and the bandwidth needed to read them back from DDR with increasing resolution, this implementation uses two quadratic curves fitted to the x-axis and y-axis coordinates of several points to be corrected. Only the coefficients of these quadratic curves are stored in DDR. After reading these coefficients back to the FPGA, the corrected coordinates are obtained through inverse fitting operations. These corrected coordinates are determined by the coefficients of the quadratic curves.
[0104] During the quadratic fitting and inverse fitting operations, image distortion causes the line connecting each row of pixels in the corrected image to the original distorted image to approximate a curve. Therefore, the order of magnitude of the error generated by the quadratic fitting and inverse fitting operations can be 10^6. -4 -10 -5 This ensures that the calculation of the pixel value (grayscale value) at the correction point has only a small loss of precision during the correction process, without affecting the integer part of the calculated pixel value.
[0105] like Figure 2 As shown, the position coordinates of each point to be corrected are 8 bytes, including 4 bytes each for the x and y coordinates. Each x and y coordinate contains a 2-byte integer part and a 2-byte decimal part. Each quadratic fitting curve requires 3 coefficients, each coefficient being 4 bytes. Two quadratic curves are fitted using 64 points to be corrected. Calculated using the coordinates of 64 points, directly using the coordinates would require 512 bytes, while using the quadratic fitting scheme would only require 24 bytes.
[0106] Step 300: Calculate the coordinates of the point to be corrected in the original distorted image; specifically, cache the correction coordinate fitting coefficients read in step 2 locally, and parse the quadratic coefficients, linear coefficients, constant coefficients, etc. of each set of horizontal and vertical coordinates according to the protocol; through discrete fitting inverse operation, the coordinates of several points to be corrected can be obtained from each set of coefficients; among them, the coordinates of the point to be corrected include its integer coordinates and decimal coordinates in the original distorted image.
[0107] Assuming each curve read back and parsed from DDR is obtained by fitting 64 points to be corrected, then the coordinates of these 64 points can also be calculated in reverse for each quadratic fitted curve. For any set of 64 points to be corrected, the corresponding calculation formula is as follows:
[0108] F x (z)=a x *z 2 +b x *z+c x
[0109] F y (z)=a y *z 2 +b y *z+c y
[0110] In the above formula, F x (z) is the row coordinate of the z-th point to be corrected, corresponding to the correction coordinate in the original distorted image, a x b x c x These are the quadratic term coefficient, linear term coefficient, and constant term coefficient in the x-axis fitting coefficients, respectively, F y (z) is the column coordinate of the z-th point to be corrected, corresponding to the correction coordinates in the original distorted image, a y b y c y These are the quadratic, linear, and constant terms in the y-axis fitting coefficients, respectively. z represents the number of the point to be corrected, z = 0, 1, 2, ..., n, where n is the set number of points to be corrected. Therefore, the coordinates of the point to be corrected in the original distorted image, calculated in reverse, are (F... x (z),F y (z)).
[0111] Step 400: Based on the preset quadratic fitting curve coefficients and the preset FPGA local line buffer capacity, the readback area is determined through coordinate calculation. Step 400 is to determine the location information of the original distorted image needed to complete the current line correction by reading it back from the DDR frame buffer.
[0112] This embodiment takes barrel distortion as an example. First, the entire original distorted image is divided into several blocks, as shown in the attached figure. Figure 3 , 4 As shown, for an original distorted image to be corrected for barrel distortion, the process of dividing it into blocks includes the following steps:
[0113] Step 410: Taking the coordinates of the first point to be corrected corresponding to the quadratic fitting curve coefficients in each row in the original distorted image as the starting point, and based on the preset FPGA local row cache capacity (e.g., 8 rows) and FPGA local coordinate cache capacity (e.g., 100 coordinate points), determine the maximum block position of the first point to be corrected corresponding to the quadratic fitting curve coefficients in each row in turn, which is the column coordinate.
[0114] In this embodiment, the horizontal midline of the original distorted image divides the original distorted image into upper and lower parts;
[0115] For the upper part of the image, after determining the coordinates of the first point to be corrected in the original distorted image, it is used as the first starting point. According to the preset FPGA local row buffer capacity, it is moved up 8 rows (or down 8 rows for pincushion distortion), that is, the row coordinate value is reduced by 8 and the column coordinate value remains unchanged. At this time, combined with the corresponding quadratic fitting curve coefficient, the intersection point of the 8th row after the upward movement and the curve corresponding to the quadratic fitting curve coefficient of that row can be determined.
[0116] It should be noted that since the coordinates of the point to be corrected in the original distorted image may be decimals, the first starting point is rounded up before determining the starting point. The rounded first starting point is then moved. This ensures that the data below the point can be obtained during the readback, which can be used as the basis for interpolation.
[0117] Since the coordinates of the point to be corrected in the original distorted image have been calculated in step 300, the number of points to be corrected between the intersection point and the first starting point can be counted. If the number is less than or equal to the set FPGA local coordinate cache capacity, the column coordinates corresponding to the intersection point are determined to be the maximum block position corresponding to the current starting point of the set of quadratic fitting curve coefficients.
[0118] If the number is greater than the set FPGA local coordinate cache capacity, then starting from this starting point, select FPGA local coordinate cache capacity number of points to be corrected, and use the column coordinate of the correction coordinate corresponding to the last selected point to be corrected as the maximum block position corresponding to the current starting point of the set of quadratic fitting curve coefficients.
[0119] For the lower part of the image, move down 8 rows and repeat the above process.
[0120] Then repeat the above process for the quadratic fitting curve coefficients of the next row until the maximum block position corresponding to the quadratic fitting curve coefficients of all rows is determined.
[0121] Step 420: Select the minimum value among the largest block positions as the first vertical block boundary of the coefficients of each row of quadratic fitting curves.
[0122] Step 430: Calculate the correction coordinates of the last point to be corrected for the quadratic fitting curve coefficients of each row corresponding to the current vertical block boundary, and determine whether the coordinates are on the vertical block boundary. If they are, use the coordinates as the starting position and repeat step 410 to determine the next maximum block position for each row. If they are not, use the next point to be corrected in the current row as the starting position and repeat step 410 to determine the next maximum block position for each row.
[0123] Repeat steps 410-430 until the original barrel-shaped distorted image is divided into blocks. After block division, the leftmost column coordinates (col1, col2, ..., col...) of each block will be obtained. n ) and column numbers (col_num1, col_num2, ..., col_num) n-1 Write to the FPGA local cache, such as Figure 5 As shown.
[0124] The above process is implemented in the FPGA using three modules: a column_block module to store the results of the block partitioning algorithm; a column_point module to preprocess and delay the coordinates obtained in step 3; and a readback_position module. This module first compares the column coordinates of the point to be corrected in the original distorted image with the block position to determine the block it belongs to, and obtains the starting position and column number of the column to be read back. Then, it finds the minimum row coordinate of all the points to be corrected in each block in the current row in the original distorted image, which is used as the starting position of the row to be read back, thereby determining the area of the original distorted image that needs to be read back.
[0125] like Figure 5 As shown, for Figure 5 The curve ① is corrected, and the portion of the original distorted image that needs to be read back within the first block is the solid-line bounding box area. The leftmost column coordinates col1, col2, etc., and the column numbers col_num1, col_num2, etc. of the block have been obtained through the above block division process and cached in the FPGA local RAM.
[0126] By traversing all points of curve ① in the first block, we can obtain the minimum row position of this part of the curve in the original distorted image, i.e., row1, which can be used as the starting position of the row to be read back; then, combined with the column number col_num1, we can determine the number of columns to be read back at this time.
[0127] The number of rows read is determined by the FPGA's local row cache capacity (e.g., 8 rows), meaning it moves down 8 rows from row1.
[0128] In summary, we can determine the region of the original distorted image that needs to be read back in the current block for the current correction row. Similarly, the region of the original distorted image that needs to be read back for the second block is the area within the dashed box.
[0129] Step 500: Read back the original distorted image from DDR and cache it locally. The original distorted image read back is denoted as the read-back image.
[0130] The FPGA implementation of this process includes three modules: an image_readback module, which further determines the position obtained in step 400; if the current block needs to update the original distorted image, it issues an AXI command to retrieve the corresponding part of the original distorted image from DDR; otherwise, it does not need to initiate a readback operation; an axi_datamover module, which handles data interaction with the AXI high-speed data interface; and a line_buffer module, which stores the original distorted image retrieved from DDR.
[0131] To minimize DDR bandwidth usage and improve utilization when reading back the original distorted image, the entire original distorted image is first divided into several blocks, such as... Figure 6 As shown. Assume the distribution curve of the row to be corrected in the distortion map is as follows: Figure 6 As shown in curve ①, the blocks in this implementation will divide curve ① into several parts. For each part of the curve, it is only necessary to retrieve the corresponding few rows of original distorted images from DDR to complete the correction processing of the current row and output the first row of corrected pixels of the corrected image.
[0132] like Figure 6 The middle curve ② is the next line distribution curve to be corrected after curve ①. It will also be divided into several parts by the divided block. Based on the row1 corresponding to the curve, the starting position of the smallest row is determined. Similarly, it moves down 8 rows to determine the original distorted image area that needs to be read back in the current block.
[0133] By comparing the original distorted image regions that need to be read back for curves ① and ②, it is found that only a few rows of the original distorted images that need to be retrieved from DDR have changed or have not changed. Only the changed parts of the image need to be updated to meet the correction processing requirements of the corresponding rows to be corrected for curve ②.
[0134] The above process can be determined by comparing the values of row.
[0135] Similarly, after segmentation, the image data that needs to be read back for each correction row is at most the locally set row buffer capacity. The amount of image data that needs to be read back to complete the correction of the entire frame does not exceed the size of one frame. Compared with the traditional DDR solution, which requires reading back at least 4 frames of image data, this application reduces the DDR bandwidth usage by more than 75%. This solves the problem that in the traditional solution, when directly operating DDR, it is necessary to access DDR once or multiple times for each point being processed, resulting in a large amount of data read back. Frequent bus operations will consume a lot of DDR bandwidth, which may lead to a decrease in the operating system's processing speed.
[0136] In some embodiments, the following should also be noted when dividing blocks:
[0137] 1) The maximum line difference between all points to be corrected in the same block and the original distorted image in each correction line does not exceed the FPGA local line buffer capacity, thus controlling the storage resources occupied by the original distorted image buffer;
[0138] 2) If there are points to be corrected in the previous block at the boundary of the division, when reading back the image of the next block, it is necessary to read back the right side image required for the boundary point correction of the previous block to ensure the correctness of the correction.
[0139] 3) The maximum number of points to be corrected contained in each block shall not exceed the FPGA local coordinate cache capacity, thereby controlling the storage resources occupied by the coordinate cache.
[0140] Step 600: Read the pixel values of the pixels surrounding the correction coordinates in the readback image;
[0141] In this embodiment, step 600 needs to read the pixel values of the points around the coordinates from the line_buffer in step 500 based on the position of the point to be corrected in the original distorted image obtained in step 300.
[0142] When determining the surrounding pixels, the correction coordinates of the current point to be corrected are rounded down. Based on the rounded correction coordinates, the pixel in the upper left corner is determined as the first pixel to be read. Starting from the first pixel to be read, the other three coordinate points adjacent to the first pixel to be read are selected in a clockwise direction as the second to fourth pixels to be read. Then, the pixel values of the four pixels to be read are read from the image read back in step 500.
[0143] Step 700: Determine the pixel value of the point to be corrected based on the pixel values of the pixels surrounding the correction coordinates in the readback image, and generate a corrected image based on the pixel values of the point to be corrected. Specifically, this includes: determining the pixel value of the point to be corrected using interpolation based on the pixel values of the four pixels corresponding to the correction coordinates read from the readback image. The interpolation principle is as follows... Figure 7As shown. The formula for calculating the pixel value of the point to be corrected is as follows:
[0144] X = X lu *(1-a)*(1-b)+X ru *a*(1-b)+X ld *(1-a)*b+X rd *a*b
[0145] In the formula, X is the pixel value of the point to be corrected. lu X ru X ld X rd These are the pixel values of the four pixels to be read, and a and b are the decimal parts of the column coordinate and row coordinate in the calibration coordinate, respectively.
[0146] In this embodiment, to minimize the use of local FPGA storage resources when reading back the original distorted image from the FPGA local cache, a block-based caching scheme is proposed. The entire original distorted image is first divided into several blocks. The original distorted image retrieved from DDR is mapped to the corresponding block and stored according to the relative position of the rows. Regardless of the degree of image distortion, only a few rows need to be cached, significantly reducing the DDR bandwidth usage for distortion correction and ensuring DDR efficiency. Compared to the previous caching scheme where the number of rows needed to be cached depends on the degree of distortion, this scheme greatly alleviates the pressure on FPGA storage resources, especially at high resolutions and with high distortion levels.
[0147] The above description is merely a preferred embodiment of this application and does not limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any changes, modifications, substitutions, integrations, and parameter alterations to these embodiments within the spirit and principles of this application, achieved through conventional substitutions or by realizing the same function without departing from the principles and spirit of this application, fall within the scope of protection of this application.
Claims
1. A camera image distortion correction method based on FPGA, characterized in that, The correction method includes: Step 1: Buffer the received original distorted image and read the preset quadratic fitting curve coefficients. Read the preset quadratic fitting coefficients corresponding to the correction coordinates from the coefficient buffer in DDR to the FPGA local. Step 2: Determine the block region by coordinate calculation based on the preset quadratic fitting curve coefficients and the preset FPGA local row cache capacity. Any set of the preset quadratic fitting curve coefficients corresponds to a row of pixels in the corrected image. Step 2 specifically includes: Step 2.1: Construct the corresponding correction coordinate calculation equation based on any set of preset quadratic fitting curve coefficients; Step 2.2: Based on the correction coordinate calculation equation and the preset FPGA local line cache capacity, determine the first starting point and the maximum block position of the first block region corresponding to each set of preset quadratic fitting curve coefficients in turn by coordinate calculation. Step 2.3: Select the minimum value of the column coordinates in each of the maximum block positions, and take the corresponding maximum block position as the first end point of the first block region. Determine the first block region based on the first start point and the first end point. Step 2.4: Based on the first termination point and the corresponding correction coordinate calculation equation, determine the second starting point of the second block region, and repeat step 2.2 to determine each block region of the original distorted image in sequence; The first starting point is determined by the constant term coefficient in the preset quadratic fitting curve coefficients; Step 3: Based on the segmented regions, determine the readback regions in the original distorted image line by line; Step 4: Based on the readback area, read back the original distorted image from DDR and cache it locally. Read back the original distorted image and record it as the readback image. Read the pixel values of the pixels around the correction coordinates in the readback image. The correction coordinates are determined by the preset quadratic fitting curve coefficients. Step 5: Based on the pixel values of the pixels surrounding the correction coordinates in the readback image, the pixel values of the four pixels to be read corresponding to the correction coordinates read from the readback image are used to determine the pixel values of the points to be corrected by interpolation, and a correction image is generated based on the pixel values of the points to be corrected.
2. The FPGA-based camera image distortion correction method according to claim 1, characterized in that, Step 2.2 further includes: rounding the first starting point upwards; Based on the preset FPGA local row cache capacity, the row coordinates of the first starting point after rounding are moved up or down; based on the moved row coordinates, the corresponding column coordinates are calculated using the corresponding correction coordinate calculation equation; the calculated column coordinates are rounded up, and the maximum block position is determined based on the moved row coordinates and the rounded column coordinates.
3. The FPGA-based camera image distortion correction method according to claim 2, characterized in that, The step of moving the rounded row coordinate of the first starting point up or down according to the preset FPGA local row cache capacity specifically includes: According to the correction coordinate calculation equation, a preset number of correction coordinates are obtained after the first starting point; the row coordinate movement direction is determined according to the row coordinate change trend of the preset number of correction coordinates; the row coordinates of the first starting point are moved and rounded according to the preset FPGA local row cache capacity and the row coordinate movement direction.
4. The FPGA-based camera image distortion correction method according to claim 1, characterized in that, Step 2.4, which involves determining the second starting point of the second segmented region based on the first termination point and the corresponding correction coordinate calculation equation, specifically includes: Using coordinate calculation, based on the correction coordinate calculation equation, it is determined whether the column coordinate of the first termination point corresponds to the column coordinate of the correction coordinate. If yes, the pixel point corresponding to the correction coordinate is taken as the second starting point of the second block region. If no, the pixel point corresponding to the last correction coordinate contained in the first block region is taken as the second starting point of the second block region.
5. The FPGA-based camera image distortion correction method according to claim 2, characterized in that, Step 2.2 further includes: counting the number of correction coordinates contained between the first starting point and the maximum block position in the first block region; determining whether the number is less than or equal to the preset local coordinate cache capacity; if yes, proceeding to step 2.3; if no, according to the preset local coordinate cache capacity, selecting the last correction coordinate to update the maximum block position, and proceeding to step 2.
3.
6. The FPGA-based camera image distortion correction method according to any one of claims 1 to 5, characterized in that, The preset quadratic fitting curve coefficients include x-axis fitting coefficients and y-axis fitting coefficients. The x-axis fitting coefficient is determined by fitting the horizontal coordinate of the corresponding corrected coordinate in the original distorted image, and the y-axis fitting coefficient is determined by fitting the vertical coordinate of the corresponding corrected coordinate in the original distorted image. The calculation formula for the corrected coordinate calculation equation is as follows: In the formula, F x (z) is the calculated row coordinate of the z-th point to be corrected, corresponding to the corrected coordinates in the original distorted image. x b x c x These are the quadratic, linear, and constant coefficients in the x-axis fitting coefficients, respectively. Fy(z) is the column coordinate of the z-th point to be corrected corresponding to the corrected coordinates in the original distorted image. y b y c y These are the quadratic term coefficient, linear term coefficient, and constant term coefficient in the y-axis fitting coefficients, respectively, and z is the number of the point to be corrected, z = 0, 1, 2, ..., n, where n is the set number of the points to be corrected.
7. The FPGA-based camera image distortion correction method according to any one of claims 1 to 5, characterized in that, In step 4, reading the pixel values of the pixels surrounding the correction coordinates in the readback image specifically includes: rounding down the correction coordinates of the current point to be corrected in the readback image; determining the pixel at its upper left corner as the first pixel to be read based on the rounded correction coordinates, and selecting the other three coordinate points adjacent to the first pixel to be read as the second to fourth pixels to be read, starting from the first pixel to be read and proceeding clockwise; and reading the pixel values of the four pixels to be read from the readback image.
Citation Information
Patent Citations
FPGA-based binocular camera distortion correction system and method, and terminal device
CN112529795A
Distortion image correction method and device
CN115272124A
