Method and system for circle detection based on ZYNQ Hough transform
Through the Hough transformation method based on ZYNQ, combined with image preprocessing and ordered Hough circle detection algorithm, problems such as slow circle detection speed and large hardware platform in the existing technology are solved, and fast and accurate circle detection is achieved, reducing system power consumption and cost.
Patent Information
- Application Number
- CN202210830960.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-15
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2042-07-15
AI Technical Summary
The existing circular detection system has slow detection speed in industrial manufacturing, which is difficult to meet real-time requirements, and software-based systems have problems such as large hardware platform, high power consumption and high cost.
Using ZYNQ-based Hough transformation method, the image preprocessing, gradient amplitude calculation, edge contour extraction and ordered Hough circle detection algorithm are used to achieve fast and accurate circle detection, and the detection efficiency is improved through Vivado HLS hardware acceleration.
It improves detection speed and accuracy, reduces system power consumption and cost, realizes fast and accurate detection of ring-shaped workpieces, and meets the real-time needs of industrial applications.
Smart Images

Figure CN115115605B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method and system for realizing circle detection based on ZYNQ Hough transform, and belongs to the technical field of digital image processing. Background Art
[0002] At present, in the field of mechanical processing and other related industrial manufacturing, various parts have various specifications and huge quantities. Their appearance may be affected by various factors such as material wear, corrosion, cutting deviation, etc., which in turn cause deviations and affect the performance of the workpiece. In actual measurement, there are a large number of simple workpieces that need to be quickly detected, which can be mainly divided into two categories: straight line detection and circle detection. Among them, the detection speed of annular workpieces is slow due to the circle detection problem, which has yet to be solved. Rapidly and accurately detecting circles and their parameters is an important research topic in computer vision and pattern recognition, and it also has broad application prospects in the fields of machine vision automatic measurement systems and intelligent detection.
[0003] In traditional applications, circle detection systems are usually designed and implemented based on simulation software of serial processors, such as Matlab and OpenCV. With the in-depth development of image processing technology, the processed image information is becoming more and more complex, and the circle detection system based on software programs is difficult to meet the real-time requirements of industrial applications. Serial processing has a slow operation speed, and instructions can only be executed one by one in sequence; for fields such as image processing involving large amounts of data, the serial processing method greatly prolongs the clock cycle, which is not conducive to real-time image processing; and because the general hardware platform of serial processors is PC, the device is large and not easy to carry.
[0004] In the existing technology, the video processing solution using a single architecture is difficult to meet the needs of image processing; the expansion solution using multiple chips has the disadvantages of complex system structure, difficult development and maintenance, high power consumption, and high cost. ZYNQ is an expandable processing platform based on Xilinx All Programmable. It perfectly integrates the processing system (PS) based on the high-performance ARM Cortex-A9 processor and the Xilinx 28nm programmable logic (PL) in a single chip, providing users with top-level flexibility, configurability and performance. Compared with other independent ARM processors or Xilinx FPGA on a single board, the ZYNQ architecture has the advantages of overall performance improvement, overall power consumption reduction, design cost reduction, and enhanced design flexibility. Summary of the invention
[0005] In view of the shortcomings of the prior art, the present invention provides a method and system for circle detection based on ZYNQ Hough transform. In order to have a basic understanding of the content of the present invention, a brief summary is given below.
[0006] The technical solutions adopted are:
[0007] In a first aspect, a method for circle detection using Hough transform is provided, comprising:
[0008] Obtain an image to be processed that contains a circle;
[0009] Perform filtering preprocessing on the image to be processed to obtain a filtered image;
[0010] Calculate the gradient amplitude of the filtered image in each direction to obtain the amplitude image in each direction;
[0011] Perform gradient amplitude combination on the amplitude images in each direction to obtain the maximum amplitude image;
[0012] Extract edge contours from the maximum amplitude image to obtain single-pixel edge contours;
[0013] Perform edge connection on the single-pixel edge contour to obtain a complete edge contour image;
[0014] The ordered Hough circle detection algorithm is used to detect the characteristic parameters of the circle in the edge contour image to obtain the circle detection data.
[0015] In some embodiments, filtering preprocessing includes:
[0016] According to different types of image noise to be processed, one or more of mean filtering, Gaussian filtering and median filtering are selected for filtering.
[0017] In some embodiments, the gradient magnitudes in various directions of the filtered image are calculated using different SOBEL templates.
[0018] In some embodiments, a non-maximum suppression method is used to extract edge contours from the maximum amplitude image.
[0019] In some embodiments, an eight-neighborhood contour tracing algorithm is used to perform edge connection on single-pixel edge contours.
[0020] In some embodiments, detecting characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm includes:
[0021] Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas;
[0022] Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates;
[0023] Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction;
[0024] Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained;
[0025] Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ;
[0026] Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
[0027] Furthermore, according to the set proportionality coefficient, the minimum number of points T allowed for the candidate radius r to form a circle is calculated. m ,include:
[0028] T m =λ×2πr
[0029] Among them, λ is the set proportional coefficient.
[0030] In a second aspect, the present invention provides a device for circle detection using Hough transform, comprising:
[0031] An image acquisition unit, configured to acquire an image to be processed containing a circle;
[0032] A filtering unit is configured to perform filtering preprocessing on the image to be processed to obtain a filtered image;
[0033] A gradient amplitude calculation unit is configured to calculate the gradient amplitude of the filtered image in each direction to obtain an amplitude image in each direction;
[0034] A gradient amplitude combination unit is configured to perform gradient amplitude combination on the amplitude images in each direction to obtain a maximum amplitude image;
[0035] An edge contour extraction unit is configured to extract edge contours from the maximum amplitude image to obtain a single-pixel edge contour;
[0036] An edge contour connection unit is configured to perform edge connection on single-pixel edge contours to obtain a complete edge contour image;
[0037] The Hough circle detection unit is configured to detect characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm to obtain circle detection data.
[0038] In some embodiments, the Hough circle detection unit is configured to detect characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm, including:
[0039] Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas;
[0040] Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates;
[0041] Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction;
[0042] Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained;
[0043] Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ;
[0044] Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
[0045] In a third aspect, the present invention provides a system for implementing circle detection using Hough transform, including the device for implementing circle detection using Hough transform described in the third aspect.
[0046] In some embodiments, the system further comprises:
[0047] The data acquisition module, including a CMOS image sensor, is connected to the ZYNQ module via an LVDS interface and is configured to acquire images and send them to the ZYNQ module.
[0048] The ZYNQ module includes a device for implementing circle detection by using the Hough transform, and sends the processed edge contour image and circle detection data to a host computer;
[0049] The host computer, which is software implemented on a PC using MFC, uses the GigE Vision protocol to communicate with the ZYNQ module to receive and display edge contour images and circle detection data.
[0050] In some embodiments, the ZYNQ module includes a PS unit and a PL unit, and the two units are connected via an AXI bus; an Ethernet card is used to realize communication between the ZYNQ module and the host computer, and is the carrier of the GigE Vision protocol; and a DDR3 memory is used to store images.
[0051] Optionally, the ZYNQ module also includes:
[0052] The Ethernet card is the carrier for implementing the GigE Vision protocol and is used for communication between the ZYNQ module and the PC host computer.
[0053] LVDS interface, used to connect ZYNQ module and image sensor module;
[0054] DDR memory, connected to the ZYNQ module, is used to store images.
[0055] Optionally, the PS unit comprises:
[0056] ARM Cortex-A9 processor is used to transplant embedded Linux system and design corresponding embedded software. Embedded software includes system software and application software.
[0057] The system software, i.e. the driver, is developed based on the Linux video framework V4L2 and needs to implement the unified interface specified therein;
[0058] The application software adopts a modular development approach based on multi-threading technology, which is divided into data acquisition module, parameter configuration module, communication module and system management module. The communication module realizes communication between the camera and the host computer through the industrial camera standard GigE Vision protocol.
[0059] Optionally, the PS unit further comprises:
[0060] DDR memory controller, used for caching the received image into DDR memory;
[0061] TF card, used to start the embedded Linux system;
[0062] PS_AXI bus interface, used for information exchange with PL unit;
[0063] Universal peripheral interface, used to connect external hardware devices.
[0064] Optionally, the PL unit comprises:
[0065] VDMA soft IP core, used to read the image in the DDR memory and send the image to the PL unit through the AXI protocol;
[0066] RXIF logic interface, used to convert the LVDS data output by the sensor into serial and parallel data, decode the format, and control the timing and synchronization;
[0067] SPI module controls the operation of CMOS sensor through SPI bus.
[0068] Beneficial effects: Compared with the prior art, the technical solution of the present invention has the following advantages:
[0069] The invention discloses a method and system for realizing circle detection based on ZYNQ Hough transform. When preprocessing collected image data, the method sets a reasonable filtering mode for noise generated in different environments, improves image quality, and enhances the anti-interference ability of the system to environmental noise. After gradient amplitude calculation, gradient amplitude combination, edge contour extraction and connection, an ordered Hough circle detection algorithm is used for detection, and the detection is fast and accurate. The invention utilizes Vivado HLS to realize hardware acceleration of the Hough circle detection algorithm. A large amount of invalid data accumulation will lead to waste of resources, so an improved ordered Hough circle detection method is used to improve detection efficiency and resource utilization.
[0070] The invention provides a circle detection system based on ZYNQ Hough transform, which is an integrated visual detection system integrating image acquisition, image processing and data transmission. GigE Vision is a Gigabit network protocol, which has not only high transmission rate but also long transmission distance. The ZYNQ module belongs to the FPGA+ARM architecture, that is, it realizes the functions of FPGA+ARM in the size of the original FPGA, which not only maintains the advantages of the original FPGA high-speed parallelism, but also adds the advantages of ARM high-speed computing, while keeping the volume unchanged, making rational use of software and hardware resources, reducing the product development cycle, and meeting the needs of high integration. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 It is a structural schematic diagram of a circle detection system implemented by a ZYNQ-based Hough transform according to an embodiment of the present invention;
[0072] Figure 2 is a schematic diagram of an embedded system software framework shown in an embodiment of the present invention;
[0073] Figure 3 is a schematic diagram of a V4L2 overall framework shown in an embodiment of the present invention;
[0074] Figure 4 is a schematic diagram of camera parameter setting and data acquisition shown in an embodiment of the present invention;
[0075] Figure 5 It is a schematic diagram of a processing flow of a video processing IP core shown in an embodiment of the present invention.
[0076] Figure 6 It is a schematic diagram of a system detection effect shown in an embodiment of the present invention. DETAILED DESCRIPTION
[0077] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and specific methods.
[0078] In the description of the present invention, "several" means more than one, "many" means more than two, "greater than", "less than", "exceed", etc. are understood to exclude the number itself, and "above", "below", "within", etc. are understood to include the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0079] In the description of the present invention, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0080] Example 1
[0081] In a first aspect, a method for circle detection using Hough transform is provided, comprising:
[0082] Obtain an image to be processed that contains a circle;
[0083] Perform filtering preprocessing on the image to be processed to obtain a filtered image;
[0084] Calculate the gradient amplitude of the filtered image in each direction to obtain the amplitude image in each direction;
[0085] Perform gradient amplitude combination on the amplitude images in each direction to obtain the maximum amplitude image;
[0086] Extract edge contours from the maximum amplitude image to obtain single-pixel edge contours;
[0087] Perform edge connection on the single-pixel edge contour to obtain a complete edge contour image;
[0088] The ordered Hough circle detection algorithm is used to detect the characteristic parameters of the circle in the edge contour image to obtain the circle detection data.
[0089] In some embodiments, detecting characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm includes:
[0090] Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas;
[0091] Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates;
[0092] Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction;
[0093] Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained;
[0094] Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ;
[0095] Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
[0096] Furthermore, according to the set proportionality coefficient, the minimum number of points T allowed for the candidate radius r to form a circle is calculated. m ,include:
[0097] T m =λ×2πr
[0098] Among them, λ is the set proportional coefficient.
[0099] In some embodiments, a method for circle detection using Hough transform includes:
[0100] Step 1: Receive the image to be processed.
[0101] Step 2: Image filtering: This is used to filter the received image to obtain a filtered image.
[0102] Since the collected images may contain noise, filtering is required. Different filtering methods are selected according to the different types of noise. Not all filtering algorithms are suitable for implementation in HLS. This example implements three different filtering algorithms to target different noise situations.
[0103] Mean filtering. Mean filtering is a typical linear filtering algorithm, which actually uses a template for convolution operation. Mean filtering is relatively simple, fast in calculation, and has a good effect on Gaussian noise denoising. Since it uses the same weights for filtering, when the area to be processed is contaminated by impulse noise, its filtering effect will be very poor. In addition, it cannot protect the image details well while eliminating noise, making the image blurred. The operation expression of this filtering algorithm is as follows:
[0104] Gaussian filter. Gaussian filter is also a linear filter that can effectively eliminate Gaussian noise and smooth images. This filter takes a weighted average of the entire image, that is, each pixel is a weighted average of itself and the surrounding pixels. The basic principle of Gaussian filter is similar to that of mean filter, but the coefficient of the window template it uses is different from that of mean filter. The template coefficient of mean filter is 1, while the template coefficient of Gaussian filter is obtained by discretizing the two-dimensional Gaussian function.
[0105] The following is a two-dimensional Gaussian function: Among them, σ is the standard deviation, which determines the width of the Gaussian function. If the standard deviation is small, the filtering effect is not obvious; if the standard deviation is large, the filtered image is blurry. The Gaussian template actually simulates the characteristics of the Gaussian function, which is symmetrical and the value center decreases continuously around. Therefore, Gaussian filtering is very effective in suppressing Gaussian noise, and its filtering effect has a smaller degree of blurring for the mean filtered image.
[0106] Median filtering. Median filtering is a typical nonlinear filtering technology. Its basic idea is to replace the gray value of a certain pixel in the image with the median value of each pixel in the neighborhood of the pixel. Since it is difficult for median filtering to select noise components, it has almost no effect on the filter output and can also preserve the edge information of the image well.
[0107] The median filter definition is as follows: In the above formula, f(x,y) represents the input pixel grayscale value, and g(x,y) represents the output pixel grayscale value. Since this filter does not depend on the value in the neighborhood that is very different from the current pixel value, it is very effective for adverse factors such as pulse interference and salt and pepper noise.
[0108] Step 3: Gradient amplitude calculation: It is used to calculate the gradient amplitude in each direction of the image, so as to obtain the amplitude image in different directions.
[0109] Since the classic SOBEL operator only has 3x3 neighborhood templates in the horizontal and vertical directions, the directions that can be represented are too few, and the direction of the template only represents the direction of grayscale change, rather than the reverse direction of the actual edge of the image. Therefore, 8 directional templates are defined based on the Sobel operator, numbered 0-7, so that the direction represented by the template is the actual edge direction of the image. Using these 8 templates can not only easily obtain edge points through some algorithms, but also facilitate the subsequent calculation of the sub-pixel coordinates of the edge. When calculating the gradient amplitude, the 8 directional templates are used to perform convolution operations on the detection image. The pixel value of the position where the template slides over is multiplied by the corresponding value in the template, and finally all are added to obtain 8 gradient images. The direction of the template is the angle with the X-axis, which is 0°, 45°, 90°, 135°, 180°, 225°, 270°, 315° and other 8 directions.
[0110] Step 4: Gradient amplitude combination. It is used to combine the amplitude images in different directions to obtain the maximum amplitude image.
[0111] The purpose of gradient amplitude combination is to obtain a rough edge image, which lays a good foundation for further obtaining edge contours and sub-pixel coordinate extraction. The 8 direction templates in the previous step can detect the edges in the specified direction. Here, the 8 edge images are combined into a complete edge image. The gradient direction points to the direction with the largest gradient amplitude. Now there are 8 amplitude images. As long as the largest amplitude is compared, its direction can be obtained. The parts with the largest amplitude in each direction are combined together to obtain the maximum amplitude image. While obtaining the maximum amplitude image, its gradient direction must be recorded, and the gradient direction of the corresponding pixel point is stored in another image, which is called an angle image. When actually recording, the numbers of each direction can be recorded to facilitate the search operation. After obtaining the maximum amplitude image and the corresponding angle image, the next step of obtaining the edge contour can be performed.
[0112] Optionally, four templates can be used when performing the convolution operation to obtain the gradient amplitude, which can reduce the amount of calculation. The defined 8 directional templates can be grouped in pairs, 0° and 180°, 90° and 270°, 45° and 225°, 135° and 315°, and the two directional templates in each group are exactly opposite. Therefore, in actual operation, only four templates need to be convolved, and the remaining four templates can be used to invert the previously convolved gradient image.
[0113] Step 5, obtaining edge contours. This is used to extract edge contours from the maximum amplitude image and obtain a single-pixel edge contour image.
[0114] The purpose of this step is to extract the edge contour of a single pixel on the rough edge image obtained previously. Only by extracting a relatively accurate single pixel edge contour can the accuracy of the measurement be ensured. On the amplitude image, the edge is the point with the largest amplitude. Although the previous step has found the point with the largest amplitude, this "edge" is relatively coarse and is not a real edge. It is only the place with a relatively large amplitude in the 8 gradient images. The brightest point in the amplitude image is the edge. In order to find the accurate edge, the contour is extracted using the non-maximum suppression method. It is necessary to compare the amplitudes of the two points on the left and right of the center point in a 3x3 neighborhood according to the direction of the gradient. It may also be to compare the two points in the diagonal direction or the up and down direction. This also depends on the location of the pixel point and the corresponding gradient direction to determine the object of comparison. The gradient direction amplitude usually increases from small to large and then decreases. We only need to determine whether the middle is greater than the amplitude on both sides. If the middle is greater than both sides at the same time, it is an edge point, otherwise it is not an edge point.
[0115] Step 6: Edge connection: This is used to repair broken edges and obtain a complete edge profile.
[0116] The purpose of this step is to repair the broken edge contour. The single-pixel edge contour extracted in the above step has a few breaks, making the obtained contour discontinuous. In response to this situation, an edge connection algorithm based on eight-neighborhood detection is used to effectively solve the problem of broken edge contours. First, the edge contour image is traversed, and eight-neighborhood detection is performed on each non-zero pixel point. The eight-neighborhood with only one foreground point is called an endpoint; secondly, for all endpoints, the sixteen points on the outer layer are searched. If there is a foreground point, the point between the endpoint and the foreground point is also changed to a foreground point; finally, the edge connection result shows that this method can connect adjacent foreground points while ensuring the correctness of edge information.
[0117] Step 7: Hough circle detection: Parameters used to detect circles in the contour image.
[0118] The purpose of this step is to use the edge contour image to detect the characteristic parameters of the circle. The present invention uses an ordered Hough circle detection algorithm for detection. Hough Transform is a feature extraction technology in image processing. This process obtains a set that conforms to the specific shape as the Hough Transform result by calculating the local maximum of the cumulative result in a parameter space. The Hough Transform maps the points on the source image to the parameter space for accumulation through the duality of points and lines, and converts the problem of detecting a given curve in the original image into the problem of finding the peak in the parameter space. Since global features are used, it is less affected by noise and boundary discontinuities and has strong robustness.
[0119] Standard Hough transform circle detection is one of the most traditional detection algorithms, and its biggest advantage is that it is insensitive to noise. However, since the circle has three free parameters, they need to be accumulated in three-dimensional space, making this approach impractical due to excessive computational complexity. In order to overcome these shortcomings, some scholars have proposed randomized Hough transform (RHT), which randomly selects three non-collinear points in the image space and maps them into a point in the parameter space. When RHT is used to process simple images, it shows quite excellent performance, but when processing complex images, the algorithm performance is reduced due to the introduction of a large number of invalid sampling and accumulation by random sampling. The present invention uses Vivado HLS to implement hardware acceleration of the Hough circle detection algorithm. A large amount of invalid data accumulation will lead to a waste of resources, so an improved ordered Hough circle detection method is adopted to improve detection efficiency and resource utilization.
[0120] The standard equation of a circle is x 2 +y 2+2ax+2by+c=0, the formula contains three parameters, which are calculated in two steps: the first step is to calculate the center of the circle, and the second step is to calculate the radius of the circle. Use the edge contour image obtained in the previous step to scan it line by line. Let h i is the horizontal scan line of the i-th row in the digital image, l i ,m i h i Two intersection points with the circle, n i for l i and m i The midpoint of their satisfaction l i +m i =2×n i (abscissa value). Since the circle is symmetrical about its center, the abscissa of the center must be on the straight line x = a. And a = n i =n i+1 =n i+2 …=n i+k (horizontal coordinate value). Therefore, we can scan each row to find such symmetrical points, and use Hough transform in one-dimensional space to accumulate the counts of the points. The parameter coordinate corresponding to the maximum count is the value of a. Similarly, we can scan each column to find such symmetrical points, and use Hough transform in one-dimensional space to accumulate the counts of the points. The parameter coordinate corresponding to the maximum count is the value of b. In this way, the center of the circle (a, b) can be calculated. Using the coordinates of the center of the circle, substitute the edge pixel point into equation (xa) 2 +(yb) 2 =r 2 , calculate a candidate radius r, and use Hough transform in one-dimensional space to accumulate the number of candidate radii r. See if the count value A(r) of r is greater than the minimum number of points T allowed to form a circle m =λ×2πr (λ is the proportionality coefficient) to determine the true circle, and r is the radius of the circle.
[0121] Step 8, sending data, is used to send the processed edge contour image and Hough circle detection data.
[0122] The MFC host computer is used to display the test results, such as Figure 6 The figure shows the display effect of the host computer of the present invention. Taking the circular workpiece as the detection object, the output original image and the output contour image are respectively displayed.
[0123] Example 2
[0124] In a second aspect, this embodiment provides a device for circle detection using Hough transform, including:
[0125] An image acquisition unit, configured to acquire an image to be processed containing a circle;
[0126] A filtering unit is configured to perform filtering preprocessing on the image to be processed to obtain a filtered image;
[0127] A gradient amplitude calculation unit is configured to calculate the gradient amplitude of the filtered image in each direction to obtain an amplitude image in each direction;
[0128] A gradient amplitude combination unit is configured to perform gradient amplitude combination on the amplitude images in each direction to obtain a maximum amplitude image;
[0129] An edge contour extraction unit is configured to extract edge contours from the maximum amplitude image to obtain a single-pixel edge contour;
[0130] An edge contour connection unit is configured to perform edge connection on single-pixel edge contours to obtain a complete edge contour image;
[0131] The Hough circle detection unit is configured to detect characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm to obtain circle detection data.
[0132] In some embodiments, the Hough circle detection unit is configured to detect characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm, including:
[0133] Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas;
[0134] Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates;
[0135] Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction;
[0136] Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained;
[0137] Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ;
[0138] Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
[0139] Example 2
[0140] In a third aspect, a system for circle detection using Hough transform is provided, including the device for circle detection using Hough transform described in the third aspect.
[0141] In some embodiments, the system further comprises:
[0142] The data acquisition module, including a CMOS image sensor, is connected to the ZYNQ module via an LVDS interface and is configured to acquire images and send them to the ZYNQ module.
[0143] The ZYNQ module includes a device for implementing circle detection by using the Hough transform, and sends the processed edge contour image and circle detection data to a host computer;
[0144] The host computer, which is software implemented on a PC using MFC, uses the GigE Vision protocol to communicate with the ZYNQ module to receive and display edge contour images and circle detection data.
[0145] In some embodiments, the ZYNQ module includes a PS unit and a PL unit, and the two units are connected via an AXI bus; an Ethernet card is used to realize communication between the ZYNQ module and the host computer, and is the carrier of the GigE Vision protocol; and a DDR3 memory is used to store images.
[0146] Optionally, the ZYNQ module also includes:
[0147] The Ethernet card is the carrier for implementing the GigE Vision protocol and is used for communication between the ZYNQ module and the PC host computer.
[0148] LVDS interface, used to connect ZYNQ module and image sensor module;
[0149] DDR memory, connected to the ZYNQ module, is used to store images.
[0150] Optionally, the PS unit comprises:
[0151] ARM Cortex-A9 processor is used to transplant embedded Linux system and design corresponding embedded software. Embedded software includes system software and application software.
[0152] The system software, i.e. the driver, is developed based on the Linux video framework V4L2 and needs to implement the unified interface specified therein;
[0153] The application software adopts a modular development approach based on multi-threading technology, which is divided into data acquisition module, parameter configuration module, communication module and system management module. The communication module realizes communication between the camera and the host computer through the industrial camera standard GigE Vision protocol.
[0154] The present invention provides a system for circle detection based on Hough transform of ZYNQ to achieve real-time Hough circle detection and meet the increasing demand for miniaturized and integrated embedded applications. The system has a simple overall structure and a short development cycle. The system includes a sensor, a ZYNQ module and an MFC host computer. The sensor is the image acquisition front end of the entire system, and transmits the image to the ZYNQ module for further processing; the ZYNQ module performs filtering, edge detection, contour extraction, edge connection, Hough circle detection and other processing on the acquired image, and sends the processed image and data to the host computer through the GigE Vision protocol. The system can control the camera and receive camera data with only one ZYNQ chip, realize real-time processing of camera image data and Hough circle detection, and display the processed image on the host computer, meeting the demand for high integration.
[0155] The following will be combined Figure 1 The overall structure of the ZYNQ-based Hough circle detection system provided by the present invention is described in detail. Figure 1 The system specifically includes:
[0156] CMOS sensor for capturing images and sending them to the ZYNQ module.
[0157] Specifically, the PS connects to the SPI module through the AXI_Lite bus and controls the CMOS sensor through the SPI bus. The data captured by the CMOS sensor is stored in the DDR3 memory through the LVDS interface, the RXIF module, the channel switching logic, and the VDMA module.
[0158] The ZYNQ module is used to control the sensor parameters, pre-process the received images and perform Hough circle detection, and send the processed images and data to the host computer.
[0159] ZYNQ belongs to the FPGA+ARM architecture, which means that the functions of FPGA+ARM are realized in the original size of FPGA, that is, the advantages of the original FPGA high-speed parallelism are maintained, and the advantages of ARM high-speed computing are added, while keeping the size unchanged, rationally utilizing software and hardware resources, and shortening the product R&D cycle.
[0160] Furthermore, the ZYNQ module includes a PS unit and a PL unit, and the PS unit and the PL unit are connected via an AXI bus.
[0161] Optionally, the PS unit comprises:
[0162] DDR memory controller is used to control DDR3 memory. DDR3 memory is connected to ZYNQ module. When ZYNQ module receives video data, DDR memory controller stores the image into the address specified by DDR memory.
[0163] It also includes an EMAC controller for controlling Ethernet and uses GigE Vision to communicate with the host computer.
[0164] It also includes a PS_AXI bus interface for information exchange with the PL unit.
[0165] It also includes an ARM Cortex-A9 processing unit for porting the embedded Linux system, setting the camera's control parameters and communicating with the PL part.
[0166] Embedded systems have the characteristics of low power consumption, high reliability, and easy development. They can more easily realize high-speed processing and real-time display of image acquisition systems and improve system performance. It is a Linux-based operating system that can be modified according to needs and ported to the embedded development platform for running. It is a software system that can complete multiple functions such as multi-threaded tasks, storage system read and write control, and interrupt task processing.
[0167] The embedded system built by the present invention adopts the startup mode of TF card startup. After the program is updated, the burning of the program is no longer needed. It is only necessary to replace the corresponding file in the TF card, and the development process is more efficient. The Ethernet interface related parameters, static IP address, gateway address and subnet mask on the board are set so that the Ethernet interface IP address on the board and the IP address of the PC host computer are in the same network segment, and the connection between the development board and the host computer is completed. Then a cross-compilation environment is built to directly generate a code that can be run on the ZYNQ platform. Then the embedded software is transplanted to complete the relevant driver design, camera parameter setting, video data acquisition, and transmission.
[0168] In order to make the system work normally, embedded software needs to be designed. Figure 2The following is the system software architecture diagram. The software aspect includes two aspects: system software, namely driver development, and application software development. The device driver is developed based on the Linux video framework V4L2, and it is necessary to implement the unified interface specified therein. The virtual device is used as v4l2_device, the Sensor and RXIF devices are used as v4l2_subbdev, and VDMA is used as video_device to implement the interface of unified operation. The application is developed in a modular way based on multi-threading technology, and is divided into data acquisition module, parameter configuration module, communication module and system management module. The communication module realizes the communication between the camera and the PC host computer through the industrial camera standard GigE Vision protocol.
[0169] V4L2 framework, V4L2 is a video framework designed specifically for Linux, such as Figure 3 As shown in the figure, the framework constructs the code required by all drivers and encapsulates it into modules, which simplifies the reconstruction of the common code of device drivers. There are three core device structures in the framework: video_device, v4l2_devive, and v4l2_subdev. For the V4L2 framework, the device file generated by the video capture device is / dev / videoX, and the value of X is 0 to 63, that is, the device number of the video device is 0 to 63. In the application layer, the video device file is opened through the open function, and then the image capture-related APIs are called in sequence to open the image data stream channel. The prototypes of these API functions are uniformly defined, that is, as long as the driver layer uses the framework, the application can work almost without modification during porting.
[0170] Furthermore, data collection is implemented at the application layer by calling a series of interfaces of V4L2. The specific flow chart is as follows: Figure 4 As shown. The application first needs to use the open function to open the file in a read-write and non-blocking manner. Then query whether the device has the video input function. After confirming that the device has the video input function, set the video frame format, and then apply for a frame buffer for saving data according to the set frame format and the number of buffer frames to be applied for. Since the memory buffer needs to be operated in the application space, the mmap function is used to map it to the application space, and then the data stream channel is opened and the data collected in the buffer queue is operated through paired input and output operations. Since the two channels use the same VDMA, the current channel needs to be closed when switching channels, and then the frame format parameters and buffer size are reset, and the data stream is reopened.
[0171] Optionally, the PS unit further comprises:
[0172] DDR memory controller, used for caching the received image into DDR memory;
[0173] TF card, used to start the embedded Linux system;
[0174] PS_AXI bus interface, used for information exchange with PL unit;
[0175] Universal peripheral interface, used to connect external hardware devices.
[0176] Optionally, the PL unit comprises:
[0177] In this module, the VDMA soft IP core is used to read the image in the DDR memory and send the image to the PL unit through the AXI protocol; in this module, the soft IP core VDMA provided by Xilinx is used. This IP provides high-bandwidth direct data access between the memory or AXI4-Stream peripherals, and is based on the AXI protocol. It is a key IP for realizing high-speed communication between the PL end and DDR3. VDMA accesses the device initialization, status and management registers through the AXI4-Lite interface, interacts with the memory through the AXI4Memory Map bus, and realizes the reading and writing of peripherals through the AXI4-Stream interface. As the core device of the system, VDMA is registered as video_device in the driver to generate the device node for application operation. At the same time, the Sensor and RXIF devices are included in its management, and a set of operation interfaces based on the V4L2 framework is realized.
[0178] The RXIF logic interface is used to convert the LVDS data output by the sensor into serial-to-parallel data, decode the format, and control the timing and synchronization; since the image sensor of the present invention adopts the LVDS interface, the output LVDS high-speed serial signal includes two channels, the synchronization signal and the pixel data, and a series of operations such as serial-to-parallel conversion, data alignment, and timing synchronization are required for the signal. The RXIF logic interface is responsible for converting the image pixel values generated by the CMOS into an image format that can be processed by the software. It is encapsulated into an IP core in the PL part of the SoC, and its conversion rate directly affects the subsequent work. Therefore, the logic interface plays a vital role in the entire system.
[0179] SPI module controls the operation of CMOS sensor through SPI bus.
[0180] The ZYNQ-based Hough circle detection system provided by the present invention can realize the FPGA+ARM architecture with only one ZYNQ chip, realize the control of industrial cameras and receive camera data, realize real-time image data processing, edge detection, sub-pixel coordinate calculation, and send the processed target data to the PC host computer, which not only maintains the advantages of the original FPGA high-speed parallelism, but also adds the advantages of ARM high-speed computing, while keeping the volume unchanged, reasonably utilizing software and hardware resources, reducing the product development cycle, and meeting the needs of high integration. The acquired workpiece edge feature contour and Hough circle detection data can also provide data for further feature size measurement and calculation.
[0181] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0182] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0183] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0184] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0185] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for circle detection using Hough transform, characterized in that: include: Obtain an image to be processed that contains a circle; Perform filtering preprocessing on the image to be processed to obtain a filtered image; Calculate the gradient amplitude of the filtered image in each direction to obtain the amplitude image in each direction; Perform gradient amplitude combination on the amplitude images in each direction to obtain the maximum amplitude image; Extract edge contours from the maximum amplitude image to obtain single-pixel edge contours; Perform edge connection on the single-pixel edge contour to obtain a complete edge contour image; The ordered Hough circle detection algorithm is used to detect the characteristic parameters of the circle in the edge contour image to obtain the circle detection data, which specifically includes: Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas; Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates; Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction; Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained; Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ; Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
2. The method for circle detection using Hough transform according to claim 1, characterized in that: Filter preprocessing, including: According to different types of image noise to be processed, one or more of mean filtering, Gaussian filtering and median filtering are selected for filtering.
3. The method for circle detection using Hough transform according to claim 1, characterized in that: The gradient amplitude in each direction of the filtered image is calculated using different SOBEL templates.
4. The method for circle detection using Hough transform according to claim 1, characterized in that: The non-maximum suppression method is used to extract edge contours from the maximum amplitude image.
5. The method for circle detection using Hough transform according to claim 1, characterized in that: An eight-neighborhood contour tracing algorithm is used to edge connect single-pixel edge contours.
6. The method for circle detection using Hough transform according to claim 1, characterized in that: According to the set proportionality coefficient, the minimum number of points T allowed for the candidate radius r to form a circle is calculated. m ,include: T m =λ×2πr Among them, λ is the set proportional coefficient.
7. A device for circle detection using Hough transform, characterized in that: include: An image acquisition unit, configured to acquire an image to be processed containing a circle; A filtering unit is configured to perform filtering preprocessing on the image to be processed to obtain a filtered image; A gradient amplitude calculation unit is configured to calculate the gradient amplitude of the filtered image in each direction to obtain an amplitude image in each direction; A gradient amplitude combination unit is configured to perform gradient amplitude combination on the amplitude images in each direction to obtain a maximum amplitude image; An edge contour extraction unit is configured to extract edge contours from the maximum amplitude image to obtain a single-pixel edge contour; An edge contour connection unit is configured to perform edge connection on single-pixel edge contours to obtain a complete edge contour image; The Hough circle detection unit is configured to detect characteristic parameters of a circle in an edge contour image using an ordered Hough circle detection algorithm to obtain circle detection data; the Hough circle detection unit is specifically used to: Step 1: traverse the edge contour image horizontally, calculate the midpoint abscissa of each row of contour pixel points in pairs, use the accumulator to select the midpoint abscissas of several rows with higher voting results from the midpoint abscissas of all rows, and calculate the midpoint position in the X direction based on the statistics of these midpoint abscissas; Step 2: traverse the edge contour image vertically, calculate the midpoint ordinate of each column of contour pixel points in pairs, use the accumulator to select the midpoint ordinates with higher voting results from the midpoint ordinates of all columns, and calculate the midpoint position in the Y direction based on these midpoint ordinates; Step 3, determining the coordinates of the center of the circle according to the midpoint position in the X direction and the midpoint position in the Y direction; Step 4: Based on the coordinates of the circle center, the contour pixels are traversed point by point to calculate the distance from the circle center to each contour pixel, and the distances from the circle center to the contour pixels with higher voting results are selected by using an accumulator, and this distance is used as the candidate radius r, and the count value A(r) of the contour pixel of the candidate radius r is obtained; Step 5: Calculate the minimum number of points T allowed for a circle with a candidate radius r according to the set proportionality coefficient. m ; Step 6: The minimum number of points T allowed for the candidate radius r to form a circle m Compared with the count value A(r), in response to the count value A(r) being greater than T m , determine the candidate radius r as the circle radius, and the circle formed by the center coordinates and the circle radius r is the true circle.
8. A system for circle detection using Hough transform, characterized in that: A device for realizing circle detection by using the Hough transform as claimed in claim 7.
9. The system for circle detection using Hough transform according to claim 8, characterized in that: Also includes: The data acquisition module, including a CMOS image sensor, is connected to the ZYNQ module via an LVDS interface and is configured to acquire images and send them to the ZYNQ module. The ZYNQ module includes a device for implementing circle detection by using the Hough transform, and sends the processed edge contour image and circle detection data to a host computer; The host computer communicates with the ZYNQ module using the GigE Vision protocol to receive and display edge contour images and circle detection data.
10. The system for circle detection using Hough transform according to claim 9, characterized in that: The ZYNQ module includes a PS unit and a PL unit, and the two units are connected via an AXI bus; The Ethernet card is used to realize the communication between the ZYNQ module and the host computer, and it is the carrier of the GigE Vision protocol; DDR3 memory is used to store images.
