Disclosure of Invention
In order to improve the efficiency of measuring the size of the bottle mouth and realize the measurement of the sizes of various bottle mouths, the invention provides a bottle mouth size measuring method, computer equipment and a medium.
In a first aspect, the present invention provides a method of measuring the size of a bottle mouth, the method comprising:
acquiring a first image of a target bottle opening;
Determining a plurality of first circle centers in the target bottle opening and first boundary points corresponding to the first circle centers according to the first image;
calculating a first distance between each first circle center and a first boundary point corresponding to each first circle center;
and determining the size information of the target bottle opening according to the first distances.
In consideration of the fact that in the related art, the diameter detection equipment is complex in operation, the detection equipment is poor in universality and is used for measuring only one bottle opening, through the method, a plurality of first circle centers are obtained through the first image of the target bottle opening, the plurality of first circle centers are used as candidate circle centers, size information of the target bottle opening is calculated according to the distance between each candidate circle center and a first boundary point, size information of the bottle opening can be obtained through the shot image, size measurement efficiency is improved, the method is applicable to various circular bottle openings or circular bottle bottoms, and detection universality is improved.
In an alternative embodiment, determining each first boundary point from the first image includes:
Determining a gradient map of the target bottleneck according to the first image;
A plurality of first boundary points satisfying a preset condition are selected in the gradient map.
According to the embodiment, the gradient map of the target bottle opening is obtained according to the first image, the intensity value in the gradient map reflects the high-low frequency information in the image, the high-frequency information in the gradient map represents the edge information in the first image, namely the boundary of the bottle opening, and the point meeting the preset condition is taken as the first boundary point of the bottle opening through the intensity value in the gradient map.
In an alternative embodiment, determining a gradient map of the target finish from the first image includes:
conducting guided filtering on the first image to obtain a second image;
performing weighted least square filtering on the first image to obtain a third image;
carrying out weighted summation on the second image and the third image to obtain a fourth image;
and acquiring a gradient map according to the fourth image.
In view of the fact that the first image may be interfered by external factors to cause unclear edge information in the acquired image, according to the above embodiment, the first image is processed by combining the guided filtering and the weighted least square filtering through linear combination, so that optimal gradient information in the first image is acquired.
In an alternative embodiment, selecting a plurality of first boundary points in the gradient map that satisfy a preset condition includes:
Taking the point which is larger than the preset intensity value in the gradient map as a second boundary point;
Calculating a second distance between each second boundary point and each first circle center;
and taking the second boundary point of which the second distance is within the preset distance range as the first boundary point corresponding to each first circle center.
According to the embodiment, in the gradient map, the larger the intensity value is, the stronger the high-frequency information is represented, the stronger the edge information in the first image is, therefore, the point larger than the preset intensity value is used as the second boundary point in the first image, meanwhile, the second distance is the distance between the first circle center and the second boundary point, that is, the closer the second distance is to the radius of the bottle mouth, the better the closer the second distance is to the radius of the bottle mouth, and the like, the second boundary point with the second distance meeting the preset distance range is screened further by combining with priori knowledge of the radius of the bottle mouth and the like, so that the first boundary point corresponding to each first circle center is obtained more accurately, the detection accuracy of the size information of the target bottle mouth is improved, and meanwhile, the resource consumption and the time consumption caused by always searching the boundary point outwards from the first circle center are avoided by setting the preset distance range.
In an alternative embodiment, the point in the gradient map, which is greater than the preset intensity value, is taken as the second boundary point, which includes:
Constructing a preset number of paths in the gradient map;
and taking the point which is larger than the preset intensity value on each path as a second boundary point.
In an alternative embodiment, constructing a preset number of paths in the gradient map includes:
xupdate=xcenter+(Plength*sinPangle*Plength)
yupdate=ycenter+(Plength*cosPangle*Plength)
Wherein x center、ycenter is the coordinate of the first center, P length is the length of the path, x update、yupdate is the coordinate of the path, and P angle is the angle of the path.
In an alternative embodiment, the size information includes a second center and a first radius, and determining the size information of the target bottle opening according to each first distance includes:
inputting each first distance into a pre-constructed objective function to obtain an objective function value corresponding to each first circle center, wherein the objective function is constructed through the first distance and the first radius;
Selecting a first circle center which minimizes the objective function value as a second circle center of the objective bottle mouth;
The radius that minimizes the objective function is selected as the first radius of the target finish.
In an alternative embodiment, the objective function is expressed as follows:
Wherein, L j is the objective function value corresponding to the first center j, d i is the first distance corresponding to the first boundary point i, R is the first radius, and N is the number of first boundary points corresponding to the first center j.
By the above embodiment, the objective function of the error between the first distance and the first radius is established, and the smaller the objective function value, the closer the first distance and the first radius are represented, that is, the smaller the objective function value, the more accurate the size information of the obtained bottleneck is, so in this embodiment, the first circle center with the minimum objective function value is used as the final circle center of the target bottleneck, and the radius with the minimum objective function value is used as the final radius of the target bottleneck through multiple fitting.
In a second aspect, the present invention also provides a computer device comprising a memory and a processor, the memory and the processor being communicatively connected to each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the steps of the method of measuring the size of a bottleneck in the first aspect or any of the embodiments of the first aspect.
In a third aspect, the present invention also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method of measuring the finish size of the first aspect or any of the embodiments of the first aspect.
Detailed Description
The following description of the embodiments of the present invention will be made apparent and fully in view of the accompanying drawings, in which some, but not all embodiments of the invention are shown. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In addition, the technical features of the different embodiments of the present invention described below may be combined with each other as long as they do not collide with each other.
In order to improve the efficiency of measuring the size of the bottle mouth and realize the measurement of the sizes of various bottle mouths, the invention provides a bottle mouth size measuring method, computer equipment and a medium.
Fig. 1 is a flow chart of a method for measuring finish size according to an exemplary embodiment. As shown in fig. 1, the bottleneck size measuring method includes the following steps S101 to S104.
Step S101: a first image of a target finish is acquired.
In an alternative embodiment, the first image may be captured by a camera to obtain an initial image, and then the first image of the target bottleneck may be obtained by a target detection class algorithm, a target segmentation class algorithm, a conventional vision algorithm, and the like. Fig. 2 is an initial image of a target finish, and fig. 3 is a first image of the target finish.
Step S102: and determining a plurality of first circle centers in the target bottle opening and first boundary points corresponding to the first circle centers according to the first image.
In an alternative embodiment, a plurality of first circle centers are roughly obtained according to the first image, the obtained first circle centers are used as candidate circle centers of the target bottle mouth, and the final circle center of the target bottle mouth is determined from the candidate circle centers.
In an alternative embodiment, the first boundary point refers to a boundary point of the target finish.
In an alternative embodiment, a plurality of candidate boundary points may be determined according to the first image, and then, the first boundary point is obtained by screening the distance between the candidate boundary point and the first center of the circle in combination with a priori knowledge such as the radius of the bottle mouth.
Step S103: and calculating a first distance between each first circle center and a first boundary point corresponding to each first circle center.
Step S104: and determining the size information of the target bottle opening according to the first distances.
In an alternative embodiment, the target bottle opening is a circular bottle opening, and in addition to measuring the size of the circular bottle opening, the method provided in the embodiment of the invention can also measure the circular bottle bottom.
In an alternative embodiment, the size information of the target bottleneck includes a diameter, a radius, a center, etc. of the target bottleneck, which is not particularly limited herein.
In an alternative embodiment, the size information of the target bottle opening can be determined according to each first distance through a least square algorithm.
In consideration of the fact that in the related art, the diameter detection equipment is complex in operation, the detection equipment is poor in universality and is used for measuring only one bottle opening, through the method, a plurality of first circle centers are obtained through the first image of the target bottle opening, the plurality of first circle centers are used as candidate circle centers, size information of the target bottle opening is calculated according to the distance between each candidate circle center and a first boundary point, size information of the bottle opening can be obtained through the shot image, size measurement efficiency is improved, the method is applicable to various circular bottle openings or circular bottle bottoms, and detection universality is improved.
In an example, in the above step S102, each first boundary point is determined by:
Step a1: and determining a gradient map of the target bottle opening according to the first image. The gradient map can be regarded as a two-dimensional discrete function, the gradient map of the image is the derivative of the two-dimensional function, and the image edge can be obtained by carrying out gradient operation on the image.
Step a2: a plurality of first boundary points satisfying a preset condition are selected in the gradient map.
In the embodiment of the invention, a gradient map of a target bottle opening is obtained according to a first image, the intensity value in the gradient map reflects high-low frequency information in the image, the high-frequency information in the gradient map represents edge information in the first image, namely the boundary of the bottle opening, and a point meeting a preset condition is taken as a first boundary point of the bottle opening through the intensity value in the gradient map.
In an example, in the step a1, the gradient map of the target bottle mouth is determined as follows:
First, the first image is guided and filtered to obtain a second image. In the guided filtering, a local linear model is used, in which a point on a function is in a linear relation with a point of a neighboring part of the function, a complex function can be represented by a plurality of local linear functions, and when the value of the point on the function is required, only the values of all the linear functions containing the point need to be calculated and averaged.
And secondly, carrying out weighted least square filtering on the first image to obtain a third image. The weighted least squares filtering is a kind of edge-preserving filtering, the goal of which is to have the filtering result as close as possible to the original image, while being as smooth as possible in the areas of smaller gradient strength, while the edge portions with larger strength values remain as much as possible.
And thirdly, carrying out weighted summation on the second image and the third image to obtain a fourth image.
Finally, a gradient map is acquired from the fourth image.
In the embodiment of the present invention, a calculation formula for obtaining a fourth image by performing weighted summation on the second image and the third image may be expressed as follows:
Youtput=αfguided(Xinput)+βfweighted(Xinput)
Wherein X input represents the first image input; f guided denotes pilot filtering; f weighted denotes weighted least squares filtering; alpha and beta respectively represent the weight of the guided filtering and the weight of the weighted least square filtering, and the alpha and the beta can be adjusted according to different illumination conditions; y output is the fourth image output. Fig. 4 is a gradient map obtained by processing the first image.
In view of the fact that the first image may be interfered by external factors to cause unclear edge information in the acquired image, in the above embodiment, the first image is processed by combining the guided filtering and the weighted least square filtering through linear combination, and then the optimal gradient information in the first image is acquired through an edge extraction operator.
In an example, in the step a2, a plurality of first boundary points satisfying the preset condition are selected by:
Step b1: and taking the point which is larger than the preset intensity value in the gradient map as a second boundary point. The preset intensity value may be set according to actual situations, and is not particularly limited herein.
Step b2: and calculating a second distance between each second boundary point and each first circle center.
Step b3: and taking the second boundary point of which the second distance is within the preset distance range as the first boundary point corresponding to each first circle center. Illustratively, the predetermined distance range may be set based on a priori knowledge of the finish radius, etc., without limitation.
In the embodiment of the invention, in the gradient map, the larger the intensity value is, the stronger the high-frequency information is represented, the stronger the edge information in the first image is, therefore, the point larger than the preset intensity value is used as the second boundary point in the first image, meanwhile, the second distance is the distance between the first circle center and the second boundary point, that is, the closer the second distance should be to the bottle neck radius, the better, and the prior knowledge such as the bottle neck radius is combined, the second boundary point of which the second distance meets the preset distance range is further screened, so that the first boundary point corresponding to each first circle center is obtained more accurately, the detection accuracy of the target bottle neck size information is improved, and meanwhile, the resource consumption and the time consumption caused by always searching the boundary point outwards from the first circle center are avoided by setting the preset distance range.
In an example, in the step b1, the second boundary point is obtained by:
Step c1: a preset number of paths are constructed in the gradient map.
Step c2: and taking the point which is larger than the preset intensity value on each path as a second boundary point.
In an alternative embodiment, in step c1, a preset number of paths may be constructed in the gradient map using uniform sampling. Assuming that the number of paths required is N, knowing that the angle of a complete circle is 360 degrees, the angle of each path is P angle = 360/N. The first circle center is taken as a reference point, a search path is constructed at intervals of the same angle, and the calculation formula of the path coordinates is as follows:
xupdate=xcenter+(Plength*sinPangle*Plength)
yupdate=ycenter+(Plength*cosPangle*Plength)
Wherein x center、ycenter is the coordinate of the first circle center; p length is the length of the paths, which is the number of paths; x update、yupdate is the coordinates of the path; p angle is the angle of the path.
Fig. 5 shows a schematic of 18 paths and fig. 6 shows a schematic of 180 paths. As can be seen from fig. 5 and 6, the more the paths are searched, the denser the number of points is, the higher the final measurement accuracy is, and the length of the paths can be adjusted according to specific accuracy requirements.
In an alternative embodiment, in the step c1, a non-uniform sampling may be used to construct a preset number of paths. The sampling mode is more than two parameters of uniform sampling, namely a maximum value A of a single sampling angle and a maximum sampling frequency Nr in the single sampling angle. A random value Ai is generated each time within the range of a, and within the range of Ai, the number of samples Nri is randomly generated. Compared with uniform sampling, the number of times of one sampling is increased from 1 to Nri, and the calculated amount can be reduced by setting A.
In an alternative embodiment, in the step c2, a point on each path greater than the preset intensity value may be selected sequentially as the second boundary point. According to the path diagram obtained in step c1, the intensity values of the corresponding points in the path are searched point by point, all points larger than the preset intensity value are found and stored in the second boundary point set S { S1, S2, S3..si }, where Si represents the second boundary point set of the path i, as shown in fig. 7. For each second boundary point set, a second distance from each second boundary point to the first circle center (reference point) is calculated, and a plurality of points within a preset distance range are reserved as first boundary points (optimal point sets) by combining prior knowledge of the diameter of the bottle mouth, as shown in fig. 8.
In an alternative embodiment, in step c2, a point on each path greater than the preset intensity value may be used as the second boundary point through neighbor selection. And searching along the path by setting a neighborhood window with a preset size, and taking the point in the neighborhood window meeting the preset intensity value as a second boundary point. Illustratively, a neighborhood window of size [ n, n ] is set. A plurality of points satisfying the preset intensity value appear at the time of the local edge, and these points are taken as second boundary points, as shown in fig. 9. Then, the second distances from all the second boundary points to the first circle center (reference point) are calculated, and the point closest to the prior radius is reserved as the first boundary point. When the position of a certain point is interfered, the first boundary point cannot be acquired in the sequential selection, so that the first boundary point on the path is lost, and the problem can be solved by setting a proper window size in the neighborhood selection.
In an example, the size information includes the second center and the first radius, and in the step S104, the size information of the target bottle opening is determined by:
firstly, inputting each first distance into a pre-constructed objective function to obtain an objective function value corresponding to each first circle center, wherein the objective function is constructed through the first distance and the first radius.
In an alternative embodiment, assuming that the center of the circle is (a, B) and the radius is R, the equation of the circle corresponding to the bottle mouth can be written as:
R2=(x-A)2+(y-B)2=x2-2Ax+A2+y2-2By+B2
The calculation formula of the distance d i between the first circle center and the first boundary point corresponding to the first circle center is as follows:
in an embodiment of the present invention, the objective function is expressed as follows:
Wherein, L j is the objective function value corresponding to the first center j, d i is the first distance corresponding to the first boundary point i, R is the first radius, and N is the number of first boundary points corresponding to the first center j.
Then, a first circle center which minimizes the objective function value is selected as a second circle center of the objective bottle mouth. The radius that minimizes the objective function is selected as the first radius of the target finish. In the embodiment of the invention, the size information of the target bottle mouth can be obtained after multiple fitting.
In the embodiment of the invention, an objective function of an error between the first distance and the first radius is established, and the smaller the objective function value is, the closer the first distance and the first radius are represented, that is, the smaller the objective function value is, the more accurate the obtained size information of the bottleneck is, so in the embodiment, the first circle center with the minimum objective function value is used as the final circle center of the target bottleneck, and the radius with the minimum objective function value is used as the final radius of the target bottleneck through multiple fitting.
Based on the same inventive concept, an embodiment of the present invention further provides a bottle mouth size measuring device, as shown in fig. 10, including:
An obtaining module 1001, configured to obtain a first image of a target bottleneck; the details are described in step S101 in the above embodiments, and are not described herein.
A first determining module 1002, configured to determine, according to the first image, a plurality of first circle centers in the target bottleneck and first boundary points corresponding to the first circle centers; the details refer to the description of step S102 in the above embodiment, and are not repeated here.
A calculating module 1003, configured to calculate a first distance between each first circle center and a first boundary point corresponding to each first circle center; the details are described in step S103 in the above embodiments, and are not described herein.
The second determining module 1004 is configured to determine size information of the target bottleneck according to each first distance. The details are referred to the description of step S104 in the above embodiment, and will not be repeated here.
In an example, the first determination module 1002 includes:
the first determining submodule is used for determining a gradient map of the target bottleneck according to the first image; the details are described in the above embodiments, and are not repeated here.
The first selecting sub-module is used for selecting a plurality of first boundary points meeting preset conditions in the gradient map. The details are described in the above embodiments, and are not repeated here.
In an example, the first determination submodule includes:
The first filtering unit is used for conducting guided filtering on the first image to obtain a second image; the details are described in the above embodiments, and are not repeated here.
The second filtering unit is used for carrying out weighted least square filtering on the first image to obtain a third image; the details are described in the above embodiments, and are not repeated here.
And the weighting unit is used for carrying out weighted summation on the second image and the third image to obtain a fourth image. The details are described in the above embodiments, and are not repeated here.
And the acquisition unit is used for acquiring the gradient map according to the fourth image. The details are described in the above embodiments, and are not repeated here.
In one example, the first selection submodule includes:
the first determining unit is used for taking the point which is larger than the preset intensity value in the gradient map as a second boundary point; the details are described in the above embodiments, and are not repeated here.
The calculating unit is used for calculating a second distance between each second boundary point and each first circle center; the details are described in the above embodiments, and are not repeated here.
And the second determining unit is used for taking a second boundary point with a second distance within a preset distance range as a first boundary point corresponding to each first circle center. The details are described in the above embodiments, and are not repeated here.
In an example, the first determining unit includes:
A construction subunit, configured to construct a preset number of paths in the gradient map; the details are described in the above embodiments, and are not repeated here.
And the determining subunit is used for taking the point which is larger than the preset intensity value on each path as a second boundary point. The details are described in the above embodiments, and are not repeated here.
In one example, in the construction subunit, a preset number of paths are constructed by the following formula:
xupdate=xcenter+(Plength*sinPangle*Plength)
yupdate=ycenter+(Plength*cosPangle*Plength)
Wherein x center、ycenter is the coordinate of the first center, P length is the length of the path, x update and y update are the coordinates of the path, and P angle is the angle of the path. The details are described in the above embodiments, and are not repeated here.
In an example, the size information includes a second center of a circle and a first radius, and the second determining module 1004 includes:
The computing sub-module is used for inputting each first distance into a pre-built objective function to obtain an objective function value corresponding to each first circle center, and the objective function is built through the first distances and the first radius; the details are described in the above embodiments, and are not repeated here.
The second selecting submodule is used for selecting a first circle center which minimizes the objective function value as a second circle center of the objective bottle mouth; the details are described in the above embodiments, and are not repeated here.
And a third selecting sub-module, configured to select a radius that minimizes the objective function as the first radius of the target bottleneck. The details are described in the above embodiments, and are not repeated here.
The specific limitation of the device and the beneficial effects can be seen from the limitation of the bottle mouth size measuring method, and the detailed description is omitted here. The various modules described above may be implemented in whole or in part by software, hardware, or a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
Fig. 11 is a schematic diagram of a hardware structure of a computer device according to an exemplary embodiment. As shown in fig. 11, the device includes one or more processors 1110 and a memory 1120, the memory 1120 including persistent memory, volatile memory and a hard disk, one processor 1110 being illustrated in fig. 11. The apparatus may further include: an input device 1130 and an output device 1140.
The processor 1110, memory 1120, input devices 1130, and output devices 1140 may be connected by a bus or other means, for example in fig. 11.
The processor 1110 may be a central processing unit (Central Processing Unit, CPU). The Processor 1110 may also be other general purpose processors, digital signal processors (DIGITAL SIGNAL processors, DSPs), application SPECIFIC INTEGRATED Circuit (ASICs), field-Programmable gate arrays (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or combinations thereof. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 1120 is used as a non-transitory computer readable storage medium, including persistent memory, volatile memory, and hard disk, and can be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules corresponding to the bottleneck size measurement method in the embodiment of the present application. Processor 1110 executes various functional applications of the server and data processing, i.e., implements any of the bottleneck size measurement methods described above, by running non-transitory software programs, instructions, and modules stored in memory 1120.
Memory 1120 may include a storage program area that may store an operating system, at least one application program required for functionality, and a storage data area; the storage data area may store data or the like used as needed. In addition, memory 1120 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, memory 1120 optionally includes memory provided remotely from processor 1110, which may be connected to the data processing apparatus via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 1130 may receive input numerical or character information and generate signal inputs related to user settings and function control. The output 1140 may comprise a display device such as a display screen.
One or more modules are stored in memory 1120 that, when executed by one or more processors 1110, perform the method illustrated in fig. 1.
The product can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. Technical details which are not described in detail in the present embodiment can be found in the embodiment shown in fig. 1.
The present invention also provides a non-transitory computer storage medium storing computer executable instructions that can perform the method of any of the above-described method embodiments. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a Flash Memory (Flash Memory), a hard disk (HARD DISK DRIVE, abbreviated as HDD), a Solid state disk (Solid-STATE DRIVE, SSD), or the like; the storage medium may also comprise a combination of memories of the kind described above.
It should be noted that in this document, relational terms such as "first" and "second" and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
The foregoing is merely exemplary of embodiments of the present invention to enable those skilled in the art to understand or practice the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.