CN117611619A - Linear fitting method, linear fitting system, electronic equipment and storage medium - Google Patents
Linear fitting method, linear fitting system, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN117611619A CN117611619A CN202311667602.8A CN202311667602A CN117611619A CN 117611619 A CN117611619 A CN 117611619A CN 202311667602 A CN202311667602 A CN 202311667602A CN 117611619 A CN117611619 A CN 117611619A
- Authority
- CN
- China
- Prior art keywords
- fitting
- straight line
- parameter interface
- edge
- image
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 54
- 230000007547 defect Effects 0.000 claims abstract description 60
- 238000012216 screening Methods 0.000 claims abstract description 17
- 238000000605 extraction Methods 0.000 claims description 11
- 238000004590 computer program Methods 0.000 claims description 10
- 230000002950 deficient Effects 0.000 claims description 8
- 238000001914 filtration Methods 0.000 abstract description 28
- 238000004364 calculation method Methods 0.000 abstract description 21
- 238000012545 processing Methods 0.000 abstract description 15
- 230000002159 abnormal effect Effects 0.000 abstract description 2
- 238000009499 grossing Methods 0.000 description 6
- 238000001514 detection method Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 5
- 238000004422 calculation algorithm Methods 0.000 description 4
- 238000007796 conventional method Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/181—Segmentation; Edge detection involving edge growing; involving edge linking
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
Landscapes
- Engineering & Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Image Analysis (AREA)
- Image Processing (AREA)
Abstract
The invention provides a straight line fitting method, a straight line fitting system, electronic equipment and a storage medium. The method comprises the steps of obtaining an image of an object to be detected; extracting the image edge along the horizontal or vertical direction, and obtaining a plurality of edge point coordinates; and setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information. The method aims at improving the robustness of edge fitting and resisting noise interference by adding simple edge point filtering measures, namely setting a parameter interface. According to the straight line fitting method, any iterative computation is not adopted, abnormal point filtering with different degrees is realized through controlling the parameter interface, and not only is the defect judging result and defect position information of the image edge in the parameter interface obtained, but also the fitting result and position information of the correct position in the parameter interface can be obtained; the method has the advantages of simple calculation, small calculated amount, low hardware resource consumption, suitability for parallel running of the FPGA and high processing efficiency.
Description
Technical Field
The present invention relates to the field of image processing, and in particular, to a line fitting method, a line fitting system, an electronic device, and a storage medium.
Background
The straight lines present on the image generally correspond to the boundaries of the actual object. Straight line fitting is one of the most frequently used techniques in image processing detection applications. In industrial applications, high-efficiency stable linear features are often used to measure dimensional information of an object to detect whether the object features meet process requirements, thereby detecting defects such as protrusions, depressions, or discontinuities at the linear edge. Or by detecting the accurate position of a specific straight line in the image, the method is used for establishing a coordinate system or accurately positioning a target object and the like. Most of the straight line detection algorithms only output straight line coordinate information, and no information prompt or judgment condition about whether defects exist in the straight line boundary itself exists.
Most of the conventional image-based straight line detection methods are based on least square or ransac methods, the least square fitting anti-interference capability is weak, and the ransac methods need iterative computation and are not suitable for hardware implementation.
Based on the above technical problems, chinese patent CN 116894958A provides an image edge fitting method, an electronic device and a storage medium. The user sets a line segment close to the edge of the object in the image to determine an image edge processing area, and generates an interested area according to the line segment set by the user, so that interference of an unnecessary area can be eliminated; by filtering the edge points for multiple times, the influence of the interference points is eliminated, so that the edge fitting algorithm only needs to process meaningful data, and the edge fitting efficiency and quality can be further improved. The accuracy of the fitting result of the application greatly depends on the quality of edge points, and on the other hand, the technical means of multiple times of filtering are adopted, so that the consumption of hardware resources of operation is increased.
Chinese patent CN 112085759a discloses a straight line fitting method and apparatus based on big data. The method acquires all non-repeated random data point coordinates in the image at one time, acquires a final fitting result through repeated iteration, and is complex in calculation and different from the technical means of the patent.
Chinese patent CN 116309660a provides a straight line detecting method, apparatus, device and storage medium. The method mainly comprises the following steps: according to target position information of a region to be detected in the image to be detected, determining angle information corresponding to a detection path of the region to be detected, wherein the target position information comprises a target starting point of the region to be detected; according to the angle information and the target starting point, calculating a first edge point of the target edge in the region to be detected; scanning the region to be detected according to the scanning direction of the region to be detected and the first edge point to obtain a second edge point of the target edge; calculating sub-pixel edge points corresponding to the target edge according to the complex judgment direction and the second edge points; and performing linear fitting on the sub-pixel edge points to obtain a linear detection result corresponding to the target edge. The problem of fitting sub-pixel edge points is solved by the patent, and is different from the problem solved by the scheme.
Disclosure of Invention
The invention provides a straight line fitting method, a straight line fitting system, electronic equipment and a storage medium, which can at least solve one of the technical problems.
In order to achieve the above purpose, the present invention proposes the following technical solutions:
a method of straight line fitting comprising:
acquiring an image of an object to be measured;
extracting the image edge along the horizontal or vertical direction, and obtaining a plurality of edge point coordinates;
and setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information.
Further, the method further comprises the step of setting an expected fitting straight line for evaluating the fitting result, wherein the expected fitting straight line is a straight line perpendicular to the x axis or the y axis.
Further, the setting parameter interface screens coordinates of edge points involved in fitting to obtain fitting results and position information, including: setting a first parameter interface, fitting edge point coordinates of the first parameter interface, obtaining a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface.
Further, the determining the defect result of the image edge of the first parameter interface includes: the first fitting straight line is taken as a starting end, the size of an included angle between the first fitting straight line and an expected fitting straight line is compared in the clockwise direction, and if the included angle is within an included angle threshold range, the image edge of the first parameter interface is defect-free; otherwise, judging that the image edge of the first parameter interface is defective.
Further, the setting parameter interface screens coordinates of edge points involved in fitting to obtain fitting results and position information, including: setting a second parameter interface, fitting edge point coordinates of the second parameter interface, and obtaining second fitting straight lines and position information of image edges of the second parameter interface.
Further, with the expected fitting line as a standard, setting a threshold requirement of the normal position fitting line, wherein the second fitting line meets the threshold requirement of the normal position fitting line.
A line fitting system, comprising:
the acquisition unit acquires an image of an object to be detected;
the extraction unit is used for extracting the edges of the image along the horizontal or vertical direction and obtaining a plurality of edge point coordinates;
the fitting unit is used for setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information; setting an expected fitting straight line for evaluating the fitting result, wherein the expected fitting straight line is a straight line perpendicular to an x axis or a y axis;
the parameter interfaces comprise a first parameter interface and a second parameter interface;
setting a first parameter interface, fitting edge point coordinates in the first parameter interface to obtain a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface;
setting a second parameter interface, fitting edge point coordinates in the second parameter interface, and obtaining a second fitting straight line and position information of an image edge of the second parameter interface; and setting a threshold requirement of a normal position fitting straight line by taking the expected fitting straight line as a standard, wherein the second fitting straight line meets the threshold requirement of the normal position fitting straight line.
Further, the determining the defect result of the image edge of the first parameter interface includes: the first fitting straight line is taken as a starting end, the size of an included angle between the first fitting straight line and an expected fitting straight line is compared in the clockwise direction, and if the included angle is within an included angle threshold range, the image edge of the first parameter interface is defect-free; otherwise, judging that the image edge of the first parameter interface is defective.
The invention also proposes an electronic device comprising a memory in which a computer program is stored and a processor arranged to run the computer program to perform the above-mentioned line fitting method.
The invention further proposes a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a line fitting method as described above.
The beneficial effects of the invention are as follows: the method aims at improving the robustness of edge fitting and resisting noise interference by adding simple edge point filtering measures, namely setting a parameter interface. According to the straight line fitting method, any iterative computation is not adopted, abnormal point filtering with different degrees is realized through controlling the parameter interface, and not only is the defect judging result and defect position information of the image edge in the parameter interface obtained, but also the fitting result and position information of the correct position in the parameter interface can be obtained; the method has the advantages of simple calculation, small calculated amount, low hardware resource consumption, suitability for parallel running of the FPGA and high processing efficiency.
Drawings
FIG. 1 is a flow diagram of a straight line fitting method;
FIG. 2 is an image of an object to be measured;
FIG. 3 is a schematic diagram of a first parameter interface;
fig. 4 is a schematic diagram of a second parameter interface.
Description of the embodiments
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention.
As shown in fig. 1, the present invention proposes a straight line fitting method, including:
an image of the object to be measured is acquired as shown in fig. 2.
And extracting the image edge along the horizontal or vertical direction, and obtaining a plurality of edge point coordinates. The method comprises the following steps:
in order to ensure the optimal calculated amount of the straight line fitting method in the application, the data processing efficiency is improved. In this embodiment, the obtained image of the object to be measured contains an image edge to be fitted in a straight line, and after the image is subjected to simple position adjustment, at least one image edge distributed along the vertical or horizontal direction can be obtained.
Meanwhile, the application relates to a straight line fitting method, which aims to ensure the accuracy and reliability of a calculation result. Thus, the type of image edge in this application is non-curvilinear.
At least one region of interest ROI (region of interest) is extracted from the image with any one of the image edges distributed in the vertical or horizontal direction as a data processing object, and the ROI includes any one of the image edges distributed in the vertical or horizontal direction, or a partial region of the image edge.
In this embodiment, the (image) edge regions are distributed in the vertical direction, and the ROI is an edge sub-region in the vertical direction. Preferably, the edge regions may also be distributed in the horizontal direction, and the ROI is an edge sub-region in the horizontal direction.
In the current ROI, a plurality of blocks with the same shape and size are equidistantly arranged along the vertical direction, any block is taken as a sub-region, and a plurality of sub-regions are obtained by dividing. The block shape is not limited in this embodiment, and may be set to a rectangular shape, a fan shape, or other shapes according to actual requirements. Preferably, the calculation of any sub-region is facilitated, and in this embodiment, rectangular blocks are set.
Image processing is carried out on any subarea, and the method comprises the following steps:
performing row-column operation on the image data in the subareas to obtain a one-dimensional vector; wherein the row-column operation is a column average operation or a row average operation; and smoothing the one-dimensional vector by adopting Gaussian filtering to filter out tiny noise points, so that the image of the currently processed subarea is clearer and more reliable, and gradient calculation is facilitated. Preferably, the sub-area image can be simply smoothed by adopting small-size mean filtering or median filtering according to actual conditions.
And carrying out gradient calculation on the sub-region image subjected to the smoothing treatment to obtain the position and the size of a gradient extreme value, and outputting calculated coordinates (x, y) of the edge points according to preset gradient screening conditions. Preferably, the edge point coordinates are also obtained using the second derivative.
The processing of image data in the above-described sub-areas is only illustrated as an example. Preferably, filtering and denoising can be performed on the image to realize smoothing treatment; performing row-column operation to obtain a one-dimensional vector; and gradient calculation or second derivative is adopted for the one-dimensional vector to obtain the calculation coordinates of the edge points. Or the first derivative or the second derivative is adopted to obtain edge points of the subareas; performing row-column operation to obtain a one-dimensional vector; and finally, filtering and denoising.
And sequentially processing the image data in the subareas to obtain the calculated coordinates of the edge points of the subareas.
Based on fitting conditions, the calculated coordinates of a plurality of edge points are screened, and a plurality of edge point coordinates are obtained and used for straight line fitting.
In general, in order to meet the requirement of subsequent straight line fitting, the actual edge information closer to the object to be measured is obtained, and the obtained calculated coordinates of the edge points are subjected to condition screening to obtain the coordinates of the edge points. The specific screening conditions are optionally set by the user.
The image edge extraction process described above is a conventional method, and is merely illustrative. The invention does not limit the specific extraction process of the image edge, and can extract the image edge by other modes or algorithms to obtain a plurality of edge point coordinates for straight line fitting.
And setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information.
Based on the image edge extraction process, among the obtained edge points, the maximum value of the x coordinates of the edge point is x_max, the minimum value of the x coordinates of the edge point is x_min, and the mean value of the x coordinates of the edge point is x_mean, x_mean= (x1+x2+x3+.+ xn)/n.
Meanwhile, in order to ensure the accuracy and reliability of the calculation result of the method, some edge points exist in normal positions in the plurality of edge points obtained by extracting the image edge, that is, the x coordinates of the part of edge points are the same, or the x coordinates do not exceed a first x coordinate threshold range, and the first x coordinate threshold range is formulated according to practical conditions. At this time, x_mean is closer to the x coordinate range of the partial edge point at the normal position. The number of the edge points of the part is at least not less than half of the total number of the edge points obtained by extracting the image edge, and the specific number ratio can be adjusted according to practical conditions.
An expected fit line is set for evaluating the fit result, the expected fit line being a line perpendicular to the x-axis or the y-axis.
In this embodiment, in the width range of the ROI, an expected fitting straight line is set, which is perpendicular to the x-axis, and the slope does not exist; the straight line is used for evaluating the fitting result of the fitting straight line of the parameter interface, so that the defect judging result of the image edge in the parameter interface is obtained. In the width range of the ROI, the coordinate position of the expected fitting straight line can be dynamically transformed, so that the expected fitting straight line exists in any parameter interface, and the fitting result of the parameter interface can be evaluated; or in the range of the ROI width, setting a plurality of expected fitting straight lines with different coordinate positions.
Preferably, if the processed image edge is in the horizontal direction and the ROI is also in the horizontal direction, the expected fit line is set, perpendicular to the y-axis, with a slope of 0.
In this embodiment, a parameter interface x_range is set, and the coordinates of the edge points involved in the fitting are screened out by selecting the range of the x coordinates of the edge points involved in the fitting.
In this embodiment, in the parameter interface, the edge points at the normal position are most of the edge points; the edge points at the normal position have the following commonalities: the x coordinates are the same, or the x coordinates do not exceed a second x coordinate threshold range, and the second x coordinate threshold range is formulated according to actual conditions. Wherein, the number of most edge points is at least not less than half of the number of edge points in the parameter interface, and the specific number can be adjusted according to practical situations.
To further improve the quality of the line fitting, in this embodiment, the number of most edge points is set to be not less than 90% of the number of edge points in the parameter interface.
According to the setting of the parameter interface, the fitting result and the position information of the parameter interface can be obtained, and the method concretely comprises the following steps:
setting a first parameter interface, fitting edge point coordinates of the first parameter interface, obtaining a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface.
Determining a defect result of an image edge of the first parameter interface, comprising: comparing the slope of the first fitting straight line with the slope of the expected fitting straight line, and judging that the image edge of the first parameter interface is defect-free if the difference value of the slope of the first fitting straight line and the slope of the expected fitting straight line meets a first threshold value condition; and otherwise, judging that the image edge of the first parameter interface is defective.
As shown in fig. 3, the selection range of the x coordinate in the first parameter interface is large, so that noise points exist in the fitting point. The first fitting straight line y=kx+b is fitted with the edge point coordinates within the current x_range 1. And comparing the first fitting straight line with the expected fitting straight line, and judging a defect result of the image edge of the first parameter interface. According to the defect judging result, a user can set whether to output the fitting result of the image edge of the first parameter interface or not.
Because the expected fitting straight line is a straight line perpendicular to the x axis, the first fitting straight line is taken as a starting end, and the size of an included angle between the first fitting straight line and the expected fitting straight line is judged along the clockwise direction, so that the defect result of the image edge of the first parameter interface is determined. If the included angle is within the included angle threshold range, the image edge of the first parameter interface is free of defects; otherwise, judging that the image edge of the first parameter interface is defective.
Preferably, the defect type can be further judged according to the included angle. If the included angle is smaller than 90 degrees, the defect is a type I defect; if the included angle is larger than 90 degrees, the defect is a type II defect.
Similarly, the included angle between the first fitting straight line and the expected fitting straight line can be simply calculated, and the included angle is used as a judgment basis. The slope of the first fitting straight line is used as the judging basis of the defect type: if the slope is 0 or the slope is within the slope threshold, the image edge of the first parameter interface is defect free. If the slope of the first fitting straight line is positive, the defect is a type I defect, and if the slope of the first fitting straight line is negative, the defect is a type II defect.
Setting a second parameter interface, fitting edge point coordinates of the second parameter interface, and obtaining second fitting straight lines and position information of image edges of the second parameter interface. And setting a threshold requirement of a normal position fitting straight line by taking the expected fitting straight line as a standard, wherein the second fitting straight line meets the threshold requirement of the normal position fitting straight line.
The threshold requirement of the normal position fitting straight line comprises the included angle between the second fitting straight line and the expected fitting straight line or the slope of the normal position fitting straight line; the specific value of the relevant threshold is set according to the actual application situation.
In order to simplify the calculation process of filtering noise points, this embodiment proposes a simplified calculation description of filtering noise, which is specifically as follows: based on the characteristic of the x coordinate range of the edge point of which the x_mean is closer to the normal position in the extracted image edge; and the parameter interface x_range is set by taking x_mean as a central point for filtering noise points, namely, the edge points participating in fitting are reserved as [ x_mean-x_range/2, x_mean+x_range/2] in a plurality of edge points acquired in the image edge extraction, so that the screening and calculating processes of a plurality of edge points are simplified, and the hardware implementation is facilitated.
As shown in fig. 4, the selection range of the x coordinate in the second parameter interface is small, that is, the x_rang2 is small, and noise points are filtered. And fitting edge point coordinates of the second parameter interface to obtain a second fitting straight line and position information of an image edge of the second parameter interface.
Because the setting range of x_rang2 is smaller, the number of edge points in the normal position is high in the selected edge points in the range, namely most (more than 90% of the total number of the edge points selected in the range) of the edge points are in the normal position, so that the second fitting straight line takes the expected fitting straight line as a standard, and the threshold requirement of the fitting straight line in the normal position is met.
The noise filtering can also refer to the position of the actual boundary of the object to be detected or the edge schematic diagram of the template image; in the selection range of x_rang2, most edge points are positioned at normal positions, so that the second fitting straight line meets the threshold requirement of the fitting straight line at the normal positions, and normal position information can be obtained.
Or the x-coordinate filtering range is reduced from x_rang1 to x_rang2 by taking the defect judging result of x_rang1 as a reference.
In this embodiment, the x_range may be used only once, and the defect result or the fitting result of the normal position may be output. Or x_range can be used in combination, and x_range1 is set first so as to judge the defect result of x_range 1; based on the defect result, reducing the x coordinate filtering range from x_rang1 to x_rang2, fitting the edge point coordinates in the x_rang2, and thus obtaining a straight line fitting result and position information of a normal position; meanwhile, defect position information can be obtained by back-pushing according to the linear fitting result and the position information of the normal position obtained by the x_rang2.
Based on the same inventive concept, the invention also provides a straight line fitting system, which comprises:
and the acquisition unit acquires an image of the object to be detected.
And the extraction unit is used for extracting the image edge along the horizontal or vertical direction and obtaining a plurality of edge point coordinates.
In order to ensure the optimal calculated amount of the straight line fitting method in the application, the data processing efficiency is improved. In this embodiment, the obtained image of the object to be measured contains an image edge to be fitted in a straight line, and after the image is subjected to simple position adjustment, at least one image edge distributed along the vertical or horizontal direction can be obtained.
In order to ensure the accuracy and reliability of the calculation result, the type of the image edge is non-curve in the application.
At least one region of interest ROI (region of interest) is extracted from the image with any one of the image edges distributed in the vertical or horizontal direction as a data processing object, and the ROI includes any one of the image edges distributed in the vertical or horizontal direction, or a partial region of the image edge.
In this embodiment, the (image) edge regions are distributed in the vertical direction, and the ROI is an edge sub-region in the vertical direction. Preferably, the edge regions may also be distributed in the horizontal direction, and the ROI is an edge sub-region in the horizontal direction.
In the current ROI, a plurality of blocks with the same shape and size are equidistantly arranged along the vertical direction, any block is taken as a sub-region, and a plurality of sub-regions are obtained by dividing. The block shape is not limited in this embodiment, and may be set to a rectangular shape, a fan shape, or other shapes according to actual requirements. Preferably, the calculation of any sub-region is facilitated, and in this embodiment, rectangular blocks are set.
Image processing is carried out on any subarea, and the method comprises the following steps:
performing row-column operation on the image data in the subareas to obtain a one-dimensional vector; wherein the row-column operation is a column average operation or a row average operation; and smoothing the one-dimensional vector by adopting Gaussian filtering to filter out tiny noise points, so that the image of the currently processed subarea is clearer and more reliable, and gradient calculation is facilitated. Preferably, the sub-area image can be simply smoothed by adopting small-size mean filtering or median filtering according to actual conditions.
And carrying out gradient calculation on the sub-region image subjected to the smoothing treatment to obtain the position and the size of a gradient extreme value, and outputting calculated coordinates (x, y) of the edge points according to preset gradient screening conditions. Preferably, the edge point coordinates are also obtained using the second derivative.
The processing of image data in the above-described sub-areas is only illustrated as an example. Preferably, filtering and denoising can be performed on the image to realize smoothing treatment; performing row-column operation to obtain a one-dimensional vector; and gradient calculation or second derivative is adopted for the one-dimensional vector to obtain the calculation coordinates of the edge points. Or the first derivative or the second derivative is adopted to obtain edge points of the subareas; performing row-column operation to obtain a one-dimensional vector; and finally, filtering and denoising.
And sequentially processing the image data in the subareas to obtain the calculated coordinates of the edge points of the subareas.
Based on fitting conditions, the calculated coordinates of a plurality of edge points are screened, and a plurality of edge point coordinates are obtained and used for straight line fitting.
In general, in order to meet the requirement of subsequent straight line fitting, the actual edge information closer to the object to be measured is obtained, and the obtained calculated coordinates of the edge points are subjected to condition screening to obtain the coordinates of the edge points. The specific screening conditions are optionally set by the user.
The image edge extraction process described above is a conventional method, and is merely illustrative. The invention does not limit the specific extraction process of the image edge, and can extract the image edge by other modes or algorithms to obtain a plurality of edge point coordinates for straight line fitting.
The system is also provided with a fitting unit. The fitting unit is used for setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information; wherein, an expected fitting straight line is set for evaluating the fitting result, and the expected fitting straight line is a straight line perpendicular to the x axis or the y axis.
Based on the image edge extraction process, among the obtained edge points, the maximum value of the x coordinates of the edge point is x_max, the minimum value of the x coordinates of the edge point is x_min, and the mean value of the x coordinates of the edge point is x_mean, x_mean= (x1+x2+x3+.+ xn)/n.
Meanwhile, in order to ensure the accuracy and reliability of the calculation result of the method, some edge points exist in normal positions in the plurality of edge points obtained by extracting the image edge, that is, the x coordinates of the part of edge points are the same, or the x coordinates do not exceed a first x coordinate threshold range, and the first x coordinate threshold range is formulated according to practical conditions. At this time, x_mean is closer to the x coordinate range of the partial edge point at the normal position. The number of the edge points of the part is at least not less than half of the total number of the edge points obtained by extracting the image edge, and the specific number ratio can be adjusted according to practical conditions.
An expected fit line is set for evaluating the fit result, the expected fit line being a line perpendicular to the x-axis or the y-axis.
In this embodiment, in the width range of the ROI, an expected fitting straight line is set, which is perpendicular to the x-axis, and the slope does not exist; the straight line is used for evaluating the fitting result of the fitting straight line of the parameter interface, so that the defect judging result of the image edge in the parameter interface is obtained. In the width range of the ROI, the coordinate position of the expected fitting straight line can be dynamically transformed, so that the expected fitting straight line exists in any parameter interface, and the fitting result of the parameter interface can be evaluated; or in the range of the ROI width, setting a plurality of expected fitting straight lines with different coordinate positions.
Preferably, if the processed image edge is in the horizontal direction and the ROI is also in the horizontal direction, the expected fit line is set, perpendicular to the y-axis, with a slope of 0.
In this embodiment, a parameter interface x_range is set, and the coordinates of the edge points involved in the fitting are screened out by selecting the range of the x coordinates of the edge points involved in the fitting.
In this embodiment, in the parameter interface, the edge points at the normal position are most of the edge points; the edge points at the normal position have the following commonalities: the x coordinates are the same, or the x coordinates do not exceed a second x coordinate threshold range, and the second x coordinate threshold range is formulated according to actual conditions. Wherein, the number of most edge points is at least not less than half of the number of edge points in the parameter interface, and the specific number can be adjusted according to practical situations.
In order to further improve the quality of the line fitting, in this embodiment, the number of most edge points is set to be 90% of the number of edge points in the parameter interface.
According to the setting of the parameter interface, the fitting result and the position information of the parameter interface can be obtained, and the method concretely comprises the following steps:
the parameter interfaces include a first parameter interface and a second parameter interface.
Setting a first parameter interface, fitting edge point coordinates in the first parameter interface to obtain a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface.
Determining a defect result of an image edge of the first parameter interface, comprising: comparing the slope of the first fitting straight line with the slope of the expected fitting straight line, and judging that the image edge of the first parameter interface is defect-free if the difference value of the slope of the first fitting straight line and the slope of the expected fitting straight line meets a first threshold value condition; and otherwise, judging that the image edge of the first parameter interface is defective.
As shown in fig. 3, the selection range of the x coordinate in the first parameter interface is large, so that noise points exist in the fitting point. The first fitting straight line y=kx+b is fitted with the edge point coordinates within the current x_range 1. And comparing the first fitting straight line with the expected fitting straight line, and judging a defect result of the image edge of the first parameter interface. According to the defect judging result, a user can set whether to output the fitting result of the image edge of the first parameter interface or not.
Because the expected fitting straight line is a straight line perpendicular to the x axis, the first fitting straight line is taken as a starting end, and the size of an included angle between the first fitting straight line and the expected fitting straight line is judged along the clockwise direction, so that the defect result of the image edge of the first parameter interface is determined. If the included angle is within the included angle threshold range, the image edge of the first parameter interface is free of defects; otherwise, judging that the image edge of the first parameter interface is defective.
Preferably, the defect type can be further judged according to the included angle. If the included angle is smaller than 90 degrees, the defect is a type I defect; if the included angle is larger than 90 degrees, the defect is a type II defect.
Similarly, the included angle between the first fitting straight line and the expected fitting straight line can be simply calculated, and the included angle is used as a judgment basis. The slope of the first fitting straight line is used as the judging basis of the defect type: if the slope is 0 or the slope is within the slope threshold, the image edge of the first parameter interface is defect free. If the slope of the first fitting straight line is positive, the defect is a type I defect, and if the slope of the first fitting straight line is negative, the defect is a type II defect.
Setting a second parameter interface, fitting edge point coordinates in the second parameter interface, and obtaining a second fitting straight line and position information of an image edge of the second parameter interface; and setting a threshold requirement of a normal position fitting straight line by taking the expected fitting straight line as a standard, wherein the second fitting straight line meets the threshold requirement of the normal position fitting straight line.
The threshold requirement of the normal position fitting straight line comprises the included angle between the second fitting straight line and the expected fitting straight line or the slope of the normal position fitting straight line; the specific value of the relevant threshold is set according to the actual application situation.
In order to simplify the calculation process of filtering noise points, this embodiment proposes a simplified calculation description of filtering noise, which is specifically as follows: based on the characteristic of the x coordinate range of the edge point of which the x_mean is closer to the normal position in the extracted image edge; and referring to the method taking x_mean as a central point, filtering noise points, setting a parameter interface x_range, namely, reserving the edge points participating in fitting as [ x_mean-x_range, x_mean+x_range ] among a plurality of edge points acquired in the image edge extraction, simplifying screening and calculating processes of a plurality of edge points, and facilitating hardware implementation.
As shown in fig. 4, the selection range of the x coordinate in the second parameter interface is small, that is, the x_rang2 is small, and noise points are filtered. And fitting edge point coordinates of the second parameter interface to obtain a second fitting straight line and position information of an image edge of the second parameter interface.
Because the setting range of x_rang2 is smaller, the number of edge points in the normal position is high in the selected edge points in the range, namely most (more than 90% of the total number of the edge points selected in the range) of the edge points are in the normal position, so that the second fitting straight line takes the expected fitting straight line as a standard, and the threshold requirement of the fitting straight line in the normal position is met.
The noise filtering can also refer to the position of the actual boundary of the object to be detected or the edge schematic diagram of the template image; in the selection range of x_rang2, most edge points are positioned at normal positions, so that the second fitting straight line meets the threshold requirement of the fitting straight line at the normal positions, and normal position information can be obtained.
Or the x-coordinate filtering range is reduced from x_rang1 to x_rang2 by taking the defect judging result of x_rang1 as a reference.
In this embodiment, the x_range may be used only once, and the defect result or the fitting result of the normal position may be output. Or x_range can be used in combination, and x_range1 is set first so as to judge the defect result of x_range 1; based on the defect result, reducing the x coordinate filtering range from x_rang1 to x_rang2, fitting the edge point coordinates in the x_rang2, and thus obtaining a straight line fitting result and position information of a normal position; meanwhile, defect position information can be obtained by back-pushing according to the linear fitting result and the position information of the normal position obtained by the x_rang2.
The invention also proposes an electronic device comprising a memory in which a computer program is stored and a processor arranged to run the computer program to perform the above-mentioned line fitting method.
The invention also proposes a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a line fitting method as described above.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (10)
1. A method of straight line fitting comprising:
acquiring an image of an object to be measured;
extracting the image edge along the horizontal or vertical direction, and obtaining a plurality of edge point coordinates;
and setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information.
2. The line fitting method according to claim 1, further comprising setting an expected fitting line for evaluating the fitting result, the expected fitting line being a line perpendicular to the x-axis or the y-axis.
3. The method of straight line fitting according to claim 2, wherein the setting parameter interface, screening coordinates of edge points involved in fitting, obtaining fitting results and position information, includes: setting a first parameter interface, fitting edge point coordinates of the first parameter interface, obtaining a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface.
4. A line fitting method as claimed in claim 3, wherein said determining a defect result of an image edge of the first parameter interface comprises: the first fitting straight line is taken as a starting end, the size of an included angle between the first fitting straight line and an expected fitting straight line is compared in the clockwise direction, and if the included angle is within an included angle threshold range, the image edge of the first parameter interface is defect-free; otherwise, judging that the image edge of the first parameter interface is defective.
5. The method of straight line fitting according to claim 2, wherein the setting parameter interface, screening coordinates of edge points involved in fitting, obtaining fitting results and position information, includes: setting a second parameter interface, fitting edge point coordinates of the second parameter interface, and obtaining second fitting straight lines and position information of image edges of the second parameter interface.
6. The line fitting method according to claim 5, wherein a threshold requirement of a normal position fitting line is set with an expected fitting line as a standard, and the second fitting line satisfies the threshold requirement of the normal position fitting line.
7. A line fitting system, comprising:
the acquisition unit acquires an image of an object to be detected;
the extraction unit is used for extracting the edges of the image along the horizontal or vertical direction and obtaining a plurality of edge point coordinates;
the fitting unit is used for setting a parameter interface, screening edge point coordinates involved in fitting, and obtaining fitting results and position information; setting an expected fitting straight line for evaluating the fitting result, wherein the expected fitting straight line is a straight line perpendicular to an x axis or a y axis;
the parameter interfaces comprise a first parameter interface and a second parameter interface;
setting a first parameter interface, fitting edge point coordinates in the first parameter interface to obtain a first fitting straight line, comparing the first fitting straight line with an expected fitting straight line, and judging a defect result of an image edge of the first parameter interface;
setting a second parameter interface, fitting edge point coordinates in the second parameter interface, and obtaining a second fitting straight line and position information of an image edge of the second parameter interface; and setting a threshold requirement of a normal position fitting straight line by taking the expected fitting straight line as a standard, wherein the second fitting straight line meets the threshold requirement of the normal position fitting straight line.
8. The line fitting system of claim 7, wherein said determining a defect result for an image edge of the first parameter interface comprises: the first fitting straight line is taken as a starting end, the size of an included angle between the first fitting straight line and an expected fitting straight line is compared in the clockwise direction, and if the included angle is within an included angle threshold range, the image edge of the first parameter interface is defect-free; otherwise, judging that the image edge of the first parameter interface is defective.
9. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to run the computer program to perform the line fitting method of any of claims 1-6.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the line fitting method according to any of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311667602.8A CN117611619A (en) | 2023-12-07 | 2023-12-07 | Linear fitting method, linear fitting system, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311667602.8A CN117611619A (en) | 2023-12-07 | 2023-12-07 | Linear fitting method, linear fitting system, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117611619A true CN117611619A (en) | 2024-02-27 |
Family
ID=89949750
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311667602.8A Pending CN117611619A (en) | 2023-12-07 | 2023-12-07 | Linear fitting method, linear fitting system, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117611619A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118229574A (en) * | 2024-05-21 | 2024-06-21 | 济宁景泽信息科技有限公司 | Digital enhancement method for water supply and drainage design drawing |
-
2023
- 2023-12-07 CN CN202311667602.8A patent/CN117611619A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118229574A (en) * | 2024-05-21 | 2024-06-21 | 济宁景泽信息科技有限公司 | Digital enhancement method for water supply and drainage design drawing |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109410230B (en) | Improved Canny image edge detection method capable of resisting noise | |
CN109242853B (en) | PCB defect intelligent detection method based on image processing | |
CN117611619A (en) | Linear fitting method, linear fitting system, electronic equipment and storage medium | |
CN113340909B (en) | Glue line defect detection method based on machine vision | |
CN116416268B (en) | Method and device for detecting edge position of lithium battery pole piece based on recursion dichotomy | |
CN106651801A (en) | Method and system for removing noises during light spot locating | |
CN115222736B (en) | Steel pipe production quality detection method based on Hough space | |
CN110688871A (en) | Edge detection method based on bar code identification | |
CN114820631A (en) | Fabric defect detection method capable of resisting texture interference | |
CN111275659A (en) | Weld image processing method and device, terminal device and storage medium | |
CN115439523A (en) | Method and equipment for detecting pin size of semiconductor device and storage medium | |
CN116468687A (en) | Scratch defect detection method and device, storage medium and electronic equipment | |
CN111221996A (en) | Instrument screen visual detection method and system | |
CN112365448A (en) | Fabric defect detection method in warp knitting process | |
CN114841943A (en) | Part detection method, device, equipment and storage medium | |
CN111414912B (en) | Method, device and equipment for identifying characteristic points of butt-joint type welding seam and storage medium | |
CN114913112A (en) | Method, device and equipment for detecting double edges of wafer | |
CN115908404B (en) | Image stripe interference detection method and device, electronic equipment and medium | |
CN115861315B (en) | Defect detection method and device | |
CN110310239B (en) | Image processing method for eliminating illumination influence based on characteristic value fitting | |
CN112884694A (en) | Defect detection method, device, equipment and medium for flat display panel | |
CN114693543B (en) | Image noise reduction method and device, image processing chip and image acquisition equipment | |
CN111681229B (en) | Deep learning model training method, wearable clothes flaw identification method and wearable clothes flaw identification device | |
CN113744200B (en) | Camera dirt detection method, device and equipment | |
CN115588109A (en) | Image template matching method, device, equipment and application |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |