CN113870189A - Industrial product circular detection method and device - Google Patents

Industrial product circular detection method and device Download PDF

Info

Publication number
CN113870189A
CN113870189A CN202111025672.4A CN202111025672A CN113870189A CN 113870189 A CN113870189 A CN 113870189A CN 202111025672 A CN202111025672 A CN 202111025672A CN 113870189 A CN113870189 A CN 113870189A
Authority
CN
China
Prior art keywords
circle
pixel
region
standard
edge
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
Application number
CN202111025672.4A
Other languages
Chinese (zh)
Inventor
李炯城
曾沂粲
黄伟如
赵仕嘉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Planning and Designing Institute of Telecommunications Co Ltd
Original Assignee
Guangdong Planning and Designing Institute of Telecommunications Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Guangdong Planning and Designing Institute of Telecommunications Co Ltd filed Critical Guangdong Planning and Designing Institute of Telecommunications Co Ltd
Priority to CN202111025672.4A priority Critical patent/CN113870189A/en
Publication of CN113870189A publication Critical patent/CN113870189A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0004Industrial image inspection
    • G06T7/0006Industrial image inspection using a design-rule based approach
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • G06T7/62Analysis of geometric attributes of area, perimeter, diameter or volume
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • G06T7/66Analysis of geometric attributes of image moments or centre of gravity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/90Determination of colour characteristics

Abstract

The invention discloses a method and a device for detecting the roundness of an industrial product, wherein the method comprises the following steps: collecting an industrial product to be detected in a shooting area to obtain an image to be detected; performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected; determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame; traversing pixel points in the region of interest, and screening a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest; and performing circle detection on the region of interest based on the edge pixel points, all target pixel points and the Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle. Therefore, the calculation amount of the Hough transform algorithm can be reduced, the detection efficiency is improved, and the requirement for rapidly detecting industrial products in industrial production is met.

Description

Industrial product circular detection method and device
Technical Field
The invention relates to the technical field of intelligent detection, in particular to a method and a device for detecting the roundness of an industrial product.
Background
Some industrial products often have strict requirements on the roundness degree of the product appearance, the appearance is required to be round, the edge of the product cannot reach perfect roundness due to the condition of uneven stress in the processing stage in the production process, and the radius of the product may have little change. Before the product is delivered out of the factory, whether the radius of the product is within the allowed range and whether the boundary is circular or not need to be detected.
At present, the industry generally adopts the Hough transform circular detection technology to realize the circular detection of industrial products, but the algorithm has large calculation amount and low detection efficiency, and cannot meet the requirement of rapidly detecting industrial products in the industrial production process.
Therefore, how to improve the detection efficiency is a technical problem to be solved in the field.
Disclosure of Invention
The invention aims to solve the technical problems that the general Hough transform circular detection algorithm is large in calculation amount and low in detection efficiency, and provides the industrial product circular detection method which can be beneficial to reducing the calculation amount and improving the detection efficiency.
In order to solve the technical problem, the invention discloses a method for detecting the roundness of an industrial product in a first aspect, which comprises the following steps:
collecting an industrial product to be detected in a shooting area to obtain an image to be detected;
performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected;
determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame;
traversing the pixel points in the region of interest, and screening out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest;
and performing circle detection on the region of interest based on the edge pixel points, all the target pixel points and the Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle.
As an optional implementation manner, in the first aspect of the present invention, before the screening out a plurality of target pixel points falling into a predetermined target region from all pixel points in the region of interest, the method further includes:
determining a standard rectangular area according to the preset size of the rectangular frame;
starting when a standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the preset step length is one pixel;
and determining the area through which the standard circle slides as a target area.
As an alternative implementation manner, in the first aspect of the present invention, the initial position is a position where the standard circle is tangent to any two adjacent edges of the standard rectangular region;
starting when the standard circle is at the initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the sliding process comprises the following steps:
determining a movement starting position where the standard circle is located, wherein the initially determined movement starting position is the initial position;
starting from the standard circle at the movement starting position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time until the standard circle is tangent to a first target edge of the standard rectangular region, wherein the first preset direction is parallel to any one of all edges of the standard rectangular region, and the first target edge is an edge towards which the first preset direction faces in all edges of the standard rectangular region;
resetting the standard circle at the moving initial position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain a first position of the standard circle, wherein the second preset direction is vertical to the first preset direction;
judging whether the standard circle is tangent to a second target edge of the standard rectangular region when the standard circle is at the first position, wherein the second target edge is an edge of all edges of the standard rectangular region, and the second target edge faces the second preset direction;
if the standard circle is not tangent to the second target edge of the standard rectangular area when the standard circle is located at the first position, updating the moving starting position according to the first position, executing the step of sliding the standard circle according to a rule of sliding the preset step length each time along a first preset direction from the moving starting position, and stopping sliding until the standard circle is tangent to the first target edge of the standard rectangular area, and executing the step of resetting the standard circle at the moving starting position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain the first position of the standard circle;
and if the standard circle is judged to be tangent to the second target edge of the standard rectangular area when the standard circle is at the first position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time from the first position of the standard circle until the standard circle is tangent to the first target edge of the standard rectangular area, and finishing sliding.
As an optional implementation manner, in the first aspect of the present invention, the screening out a plurality of target pixel points falling into a predetermined target region from all pixel points in the region of interest includes:
in the standard rectangular region, marking the pixel values of all pixel points contained in the target region as 1, and marking the pixel values of a plurality of residual pixel points except the pixel points contained in the target region as 0 to obtain a mask image;
determining coordinates of all first pixel points in the region of interest and coordinates of all second pixel points in the mask image, wherein the first pixel point coordinate in the region of interest is the same as the first second pixel point coordinate in the mask image;
for each first pixel point in the region of interest, acquiring a second pixel point with the same coordinate as the first pixel point in the mask image according to the coordinate of the first pixel point, and performing an and operation on the pixel value of the first pixel point and the pixel value of the second pixel point;
if the pixel value of the first pixel point and the pixel value of the second pixel point and the operation result are 0, judging that the first pixel point does not fall into the target area;
and if the pixel value of the first pixel point, the pixel value of the second pixel point and the operation result are not 0, judging that the first pixel point falls into the target area, and determining the first pixel point as a target pixel point.
As an optional implementation manner, in the first aspect of the present invention, all the pixel points in the region of interest are stored in the memory continuously in rows;
the traversing of the pixel points in the region of interest includes:
acquiring a preset pixel pointer p;
enabling the pixel pointer p to point to the memory starting address of the first pixel point in the region of interest, and acquiring the first pixel point in the region of interest;
executing p + +, enabling the pixel pointer p to point to the memory starting address of the next pixel point, and acquiring the next pixel point, wherein the next pixel point is a subsequent pixel point adjacent to the storage position of the first pixel point in the region of interest in the memory;
and repeatedly executing p + +, and obtaining all pixel points in the region of interest.
As an optional implementation manner, in the first aspect of the present invention, after determining the center point and the radius corresponding to the detected circle, the method further includes:
performing least square fitting on edge pixel points of the image to be measured to obtain a fitting result;
and comparing the fitting result with the central point and the radius corresponding to the circle to obtain the perfect circle degree of the industrial product to be detected.
As an optional implementation manner, in the first aspect of the present invention, the performing least square fitting on the edge pixel point of the image to be measured, and obtaining a fitting result includes:
acquiring an edge pixel point coordinate set of the image to be detected;
establishing an overdetermined equation set of a circle to be fitted according to the edge pixel point coordinate set of the image to be fitted;
and solving the overdetermined equation set by using a least square estimation method to obtain a fitting result of the circle to be fitted.
The invention discloses a circular detection device for industrial products in a second aspect, which comprises:
the acquisition module is used for acquiring the industrial product to be detected in the shooting area to obtain an image to be detected;
the edge detection module is used for carrying out edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected;
the determining module is used for determining an interested area in the image to be detected according to the edge pixel point of the image to be detected and the size of a preset rectangular frame;
the traversal module is used for traversing the pixel points in the region of interest and screening out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest;
and the detection module is used for performing circular detection on the image to be detected based on the edge pixel points of the image to be detected, all the target pixel points and the Hough transform algorithm to obtain a circle contained in the image to be detected and a central point and a radius corresponding to the circle.
As an alternative embodiment, in the second aspect of the present invention, the apparatus further comprises: a target area generation module to:
before a plurality of target pixel points falling into a predetermined target area are screened from all pixel points in the area of interest, determining a standard rectangular area according to the size of the preset rectangular frame;
starting when a standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the preset step length is one pixel;
and determining the area through which the standard circle slides as a target area.
As an alternative embodiment, in the second aspect of the present invention, the initial position is a position where the standard circle is tangent to any two adjacent edges of the standard rectangular region;
the target area generating module is configured to slide a standard circle according to a preset step length from the time when the standard circle is at an initial position until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, and a specific implementation manner includes:
determining a movement starting position where the standard circle is located, wherein the initially determined movement starting position is the initial position;
starting from the standard circle at the movement starting position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time until the standard circle is tangent to a first target edge of the standard rectangular region, wherein the first preset direction is parallel to any one of all edges of the standard rectangular region, and the first target edge is an edge towards which the first preset direction faces in all edges of the standard rectangular region;
resetting the standard circle at the moving initial position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain a first position of the standard circle, wherein the second preset direction is vertical to the first preset direction;
judging whether the standard circle is tangent to a second target edge of the standard rectangular region when the standard circle is at the first position, wherein the second target edge is an edge of all edges of the standard rectangular region, and the second target edge faces the second preset direction;
if the standard circle is not tangent to the second target edge of the standard rectangular area when the standard circle is located at the first position, updating the moving starting position according to the first position, executing the step of sliding the standard circle according to a rule of sliding the preset step length each time along a first preset direction from the moving starting position, and stopping sliding until the standard circle is tangent to the first target edge of the standard rectangular area, and executing the step of resetting the standard circle at the moving starting position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain the first position of the standard circle;
and if the standard circle is judged to be tangent to the second target edge of the standard rectangular area when the standard circle is at the first position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time from the first position of the standard circle until the standard circle is tangent to the first target edge of the standard rectangular area, and finishing sliding.
As an optional implementation manner, in the second aspect of the present invention, the traversal module is configured to screen out a plurality of target pixel points that fall into a predetermined target region from all pixel points in the region of interest, where a specific implementation manner includes:
in the standard rectangular region, marking the pixel values of all pixel points contained in the target region as 1, and marking the pixel values of a plurality of residual pixel points except the pixel points contained in the target region as 0 to obtain a mask image;
determining coordinates of all first pixel points in the region of interest and coordinates of all second pixel points in the mask image, wherein the first pixel point coordinate in the region of interest is the same as the first second pixel point coordinate in the mask image;
for each first pixel point in the region of interest, acquiring a second pixel point with the same coordinate as the first pixel point in the mask image according to the coordinate of the first pixel point, and performing an and operation on the pixel value of the first pixel point and the pixel value of the second pixel point;
if the pixel value of the first pixel point and the pixel value of the second pixel point and the operation result are 0, judging that the first pixel point does not fall into the target area;
and if the pixel value of the first pixel point, the pixel value of the second pixel point and the operation result are not 0, judging that the first pixel point falls into the target area, and determining the first pixel point as a target pixel point.
As an optional implementation manner, in the second aspect of the present invention, all the pixel points in the region of interest are stored in the memory continuously in rows;
the traversal module is used for traversing the pixel points in the region of interest, and the specific implementation mode comprises the following steps:
acquiring a preset pixel pointer p;
enabling the pixel pointer p to point to the memory starting address of the first pixel point in the region of interest, and acquiring the first pixel point in the region of interest;
executing p + +, enabling the pixel pointer p to point to the memory starting address of the next pixel point, and acquiring the next pixel point, wherein the next pixel point is a subsequent pixel point adjacent to the storage position of the first pixel point in the region of interest in the memory;
and repeatedly executing p + +, and obtaining all pixel points in the region of interest.
As an alternative embodiment, in the second aspect of the present invention, the apparatus further comprises: a fitting module to:
after determining the central point and the radius corresponding to the detected circle, performing least square fitting on the edge pixel point of the image to be detected to obtain a fitting result;
and comparing the fitting result with the central point and the radius corresponding to the circle to obtain the perfect circle degree of the industrial product to be detected.
As an optional implementation manner, in the second aspect of the present invention, the fitting module is configured to perform least square fitting on an edge pixel point of the image to be measured to obtain a fitting result, and a specific implementation manner includes:
acquiring an edge pixel point coordinate set of the image to be detected;
establishing an overdetermined equation set of a circle to be fitted according to the edge pixel point coordinate set of the image to be fitted;
and solving the overdetermined equation set by using a least square estimation method to obtain a fitting result of the circle to be fitted.
The invention discloses another industrial product circular detection device in a third aspect, which is characterized by comprising:
a memory storing executable program code;
a processor coupled with the memory;
the processor calls the executable program code stored in the memory to execute the industrial product circular detection device method disclosed by the first aspect of the invention.
In a fourth aspect of the present invention, a computer-readable storage medium is disclosed, wherein computer program instructions are stored in the computer-readable storage medium, and when the computer program instructions are called, the computer-readable storage medium is used for executing the industrial product circular detection method disclosed in the first aspect of the present invention.
Compared with the prior art, the embodiment of the invention has the following beneficial effects:
in the embodiment of the invention, the to-be-detected image is obtained by collecting the to-be-detected industrial product in the shooting area; performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected; determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame; traversing the pixel points in the region of interest, and screening out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest; performing circle detection on the region of interest based on the edge pixel points, all the target pixel points and a Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle; the calculation amount of the Hough transform algorithm can be reduced, the detection efficiency is improved, and the requirement for rapidly detecting industrial products in industrial production is met.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic flow chart of a method for detecting a circular shape of an industrial product according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an image to be detected in a circular inspection method for industrial products according to an embodiment of the present disclosure;
FIG. 3(a) is a schematic diagram of a target area in a circular inspection method for industrial products according to an embodiment of the present invention;
FIG. 3(b) is a schematic diagram of a target area in another industrial product circular inspection method disclosed in an embodiment of the present invention;
fig. 4 is a diagram of hough transform-based circle detection as disclosed in an embodiment of the present invention;
FIG. 5 is a schematic flow chart of another industrial product circular inspection method disclosed in embodiments of the present invention;
FIG. 6 is a schematic structural diagram of an industrial product circular detection device according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of another industrial product circular detection device disclosed in the embodiment of the invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first," "second," and the like in the description and claims of the present invention and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, article, or article that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or article.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the invention. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The invention discloses a method and a device for detecting a circular shape of an industrial product, which can reduce the calculated amount of a Hough transform algorithm, improve the detection efficiency and meet the requirement of rapidly detecting the industrial product in industrial production, and are respectively explained in detail below.
Example one
Referring to fig. 1, fig. 1 is a schematic flow chart of a circular inspection method for industrial products according to an embodiment of the present invention. The industrial product circle detection method described in fig. 1 may be applied to devices such as a smart phone, a personal computer, and a server, and the embodiment of the present invention is not limited thereto. As shown in fig. 1, the industrial product circular inspection method may include the operations of:
and S1, collecting the industrial product to be detected in the shooting area to obtain an image to be detected.
In the embodiment of the invention, an electronic device with a camera is used for acquiring images, as shown in fig. 2, a dotted rectangular area in fig. 2 is a preset shooting area, and a circle is an example of an industrial product to be measured. In an alternative embodiment, the robot periodically sends the circular product to the front of the camera for collection, and the image to be measured is obtained.
And S2, performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected.
In the embodiment of the invention, the edge detection algorithm is adopted to carry out edge detection, the boundary of the industrial product to be detected in the image to be detected is separated, and all edge pixel points in the image to be detected are obtained. Optionally, the edge detection algorithm may adopt an edge detection algorithm commonly used in the field, such as a Sobel edge detection algorithm, a Laplacian edge detection algorithm, a Canny edge detection algorithm, and the like, which is not limited in the present invention.
And S3, determining the region of interest in the image to be detected according to the edge pixel points and the preset size of the rectangular frame.
In the embodiment of the invention, the position of the industrial product to be measured in the image to be measured obtained by shooting each time has certain deviation, but does not exceed the rectangle with fixed size, as shown by the solid line rectangle frame in fig. 2. In the embodiment of the invention, the preset rectangular frame size width is determined as W and the height is determined as H. And determining the region of interest where the edge pixel points are located in the image to be detected according to the edge pixel points obtained in the step S2 and a preset rectangular frame with the width W and the height H. Meanwhile, the method for determining the region of interest may adopt various operators and functions commonly used in machine vision software in the field to obtain the region of interest ROI, which is not limited by the present invention.
And S4, traversing the pixel points in the region of interest, and screening a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest.
In the prior art, the pixel is usually randomly located by using a specified (x, y) coordinate, and the conventional calculation for accessing the pixel I [ y ] [ x ] is: the pixel memory start address I + y + the number of bytes occupied by one row of pixels + x the number of bytes occupied by one pixel, that is, the operation amount is large when two additions and two multiplications are performed each time and the pixel point access is performed.
In the embodiment of the present invention, optionally, all the pixel points in the region of interest are stored in the memory continuously in rows. That is, all the pixels in the region of interest are stored continuously in the memory, and the data of all the pixels in the region of interest can be regarded as a one-dimensional array.
In the embodiment of the present invention, further optionally, the operation of traversing the pixel points in the region of interest in step S4 is implemented in the following manner:
and acquiring a preset pixel pointer p.
And pointing the pixel pointer p to the memory starting address of the first pixel point in the region of interest, and acquiring the first pixel point in the region of interest.
And executing p + +, enabling the pixel pointer p to point to the memory starting address of the next pixel point, and acquiring the next pixel point, wherein the next pixel point is a subsequent pixel point adjacent to the storage position of the first pixel point in the region of interest in the memory.
And repeatedly executing p + +, and obtaining all pixel points in the region of interest.
That is, in the embodiment of the present invention, when traversing the pixels, the pixels are accessed in a manner of consciously adjusting to be in front of and behind. Let a pixel pointer p point to the pixel memory start address I at the beginning. Thereafter, only p + + needs to be executed to point to the next adjacent pixel. Only one addition is required to access the next pixel. The amount of calculation is one fourth of the conventional way. If the multiply instruction is considered more time consuming than the add instruction, this step improves performance by a factor of more than 4.
In the embodiment of the present invention, optionally, before a plurality of target pixel points falling into a predetermined target region are screened from all pixel points in the region of interest, the method further includes:
and determining a standard rectangular area according to the preset size of the rectangular frame. For example, the predetermined rectangular frame size width is W and height is H.
Starting when the standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the preset step length is one pixel.
The area through which the standard circle slides is determined as a target area.
In the embodiment of the present invention, further optionally, the initial position is a position where any two adjacent edges of the standard circle and the standard rectangular region are tangent to each other.
Starting when the standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the method specifically comprises the following steps:
and determining the movement starting position of the standard circle, wherein the initially determined movement starting position is the initial position.
Starting from the position where the standard circle is located at the movement starting position, sliding the standard circle according to a rule of sliding the standard circle in a first preset direction for a preset step length each time until the standard circle is tangent to a first target edge of the standard rectangular region, wherein the first preset direction is parallel to any one of all edges of the standard rectangular region, and the first target edge is an edge towards which the first preset direction faces in all edges of the standard rectangular region.
And resetting the standard circle at the moving initial position, and sliding the standard circle once according to a rule of sliding a preset step length along a second preset direction to obtain a first position of the standard circle, wherein the second preset direction is vertical to the first preset direction.
And judging whether the standard circle is tangent to a second target edge of the standard rectangular region when the standard circle is at the first position, wherein the second target edge is an edge towards which a second preset direction faces in all edges of the standard rectangular region.
If the standard circle is not tangent to the second target edge of the standard rectangular area when the standard circle is located at the first position, updating the moving initial position according to the first position, executing the step of starting with the standard circle being located at the moving initial position, sliding the standard circle according to a rule of sliding the preset step length along the first preset direction each time until the standard circle is tangent to the first target edge of the standard rectangular area, and executing the step of resetting the standard circle at the moving initial position, and sliding the standard circle once according to the rule of sliding the preset step length along the second preset direction to obtain the first position of the standard circle.
And if the standard circle is judged to be tangent to the second target edge of the standard rectangular area when the standard circle is at the first position, sliding the standard circle according to a rule of sliding a preset step length along a first preset direction each time from the first position of the standard circle until the standard circle is tangent to the first target edge of the standard rectangular area, and finishing sliding.
For example, let the circle representing the edge of the product be located where the top left corner of a rectangular box at W x H is tangent to the two sides of the rectangular box, as shown in fig. 3 (a). The circle is made to slide one pixel at a time from left to right within the rectangular box of W x H, and when the right boundary of the rectangle is touched, the circle is made to return to the leftmost side, then drops one pixel, and moves from left to right. Continuing, the last circle is located at the lower right corner of the rectangular frame, tangent to the two sides of the rectangular frame, as shown in FIG. 3(b) where the circle is located. In this process, the area swept by the points on the circular edge is the target area. It is clear that points of the non-target region are not detected in the hough circle transform calculation.
In the embodiment of the present invention, optionally, a plurality of target pixel points falling into a predetermined target region are screened from all pixel points in the region of interest, and the method specifically includes the following steps:
in the standard rectangular region, the pixel values of all pixel points included in the target region are marked as 1, and the pixel values of a plurality of remaining pixel points except the pixel points included in the target region are marked as 0, so that a mask image is obtained. In this alternative embodiment, the target area may be obtained by programming in Python, moving the circle inside the rectangle and noting the point where the edge of the circle passes.
And determining the coordinates of all first pixel points in the region of interest and the coordinates of all second pixel points in the mask image, wherein the coordinates of the first pixel points in the region of interest are the same as the coordinates of the first second pixel points in the mask image.
And for each first pixel point in the region of interest, acquiring a second pixel point with the same coordinate as the first pixel point in the mask image according to the coordinate of the first pixel point, and performing AND operation on the pixel value of the first pixel point and the pixel value of the second pixel point.
And if the pixel value of the first pixel point and the pixel value of the second pixel point and the operation result are 0, judging that the first pixel point does not fall into the target area.
And if the pixel value of the first pixel point, the pixel value of the second pixel point and the operation result are not 0, judging that the first pixel point falls into a target area, and determining the first pixel point as a target pixel point.
Therefore, in the optional embodiment, when traversing the rectangle, it is only necessary to see whether the point corresponding to the mask image is 1 to know whether traversing is needed, and the efficiency is further improved.
S5, performing circle detection on the region of interest based on the edge pixel points, all target pixel points and the Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle.
Hough transform is a feature detection algorithm widely used in image analysis, computer vision, and digital image processing. The hough transform is used to identify features in the found object, such as: and (4) a circular shape. The algorithm flow is roughly as follows, given an object, the kind of shape to be distinguished, the algorithm performs voting in the parameter space (parameter space) to determine the shape of the object, which is determined by the local maximum (local maximum) in the accumulation space (accumulator space).
By defining the shape equation to be detected, the detection of the shape can be realized. As in the explicit form, the hough transform is defined by considering the equation of a circle of the following formula (1):
(x-x0)2+(y-y0)2=r2 (1)
the equation defines a point with origin (x)0,y0) As the center of the circle, r is the locus of the point (x, y) of radius. The equation can be visualized in two additional ways: the locus of each point (x, y) in the image, or the point (x) with (x, y) as the center and r as the radius0,y0) The trajectory of (2). Fig. 4 illustrates both definitions based on the circle detection of the hough transform.
In the image containing circles of fig. 4, (a) each edge point defines a set of circles of accumulator space, which are defined by all possible radii, with the coordinates of their edge points as the center of the circle. The accumulator space of fig. 4 (b) gives three circles defined by three edge points having a given radius, each edge point defining a circle with other values as radii. This means that the accumulator space is three-dimensional (with three parameters of interest) and the edge points map to one Voting (Voting) pyramid (a con of votes) of the accumulator space. The three-dimensional accumulation space of fig. 4(c) is such an accumulator. After all the evidence of edge points are collected, the maximum value of the accumulator space corresponds to the parameters of the circle of the original image. Wherein the Voting (Voting) is formed by generating a cone according to the above equation (1).
The above formula (1) can be defined in a parametric form as:
x=x0+rcos(θ)y=y0+rsin(θ) (2)
the advantage of this representation method is that it allows solving parameter problems. Thus, the definition of the hough transform map is:
x0=x-rcos(θ)y0=y-rsin(θ) (3)
these equations define points in accumulator space that depend on the radius r.
The circle with the radius within the designated range can be found out by adopting Hough circle transformation, and the central point and the radius of the circle can be obtained. However, the conventional hough transform process is to traverse all points in the whole rectangular region once. For a preset rectangular frame with W width and H height, detection operation is performed on all pixel points in an area through traditional Hough transformation, the operation amount is very large, and the detection efficiency is very low.
In the embodiment of the invention, the detection points participating in Hough transform are reduced by determining the target area and the target pixel points, so that the speed is increased by more than one time. The following was demonstrated:
for example, a rectangular box of W × H is set to a region of 430 pixels × 400 pixels, and the diameter of the product to be detected is 370.
As shown in fig. 3(a) and 3(b), the midpoints of the sides of the rectangular frame are taken to connect the midpoints of the two sets of opposite sides, so as to obtain a rectangular cross line, and the rectangle is divided into 4 regions of the same size. Two circular diameter lines are taken, the two diameter lines are parallel to the rectangular cross line, and the two circular diameter lines divide the circle into 4 areas with the same size.
Two white regions were recorded as areas S1 and S2, respectively, as shown in fig. 3 (b). It can be seen that the proportion of the gray area in the rectangle is obtained by calculating S1+ S2 and dividing by W H/4.
Let coordinates of point A be (Ax, Ay), and coordinates of point B be (Bx, By).
Figure BDA0003243268000000131
Calculating by definite integral S2:
Figure BDA0003243268000000132
calculating the ratio of the gray area to the rectangular area:
Figure BDA0003243268000000133
and calculating to obtain:
Figure BDA0003243268000000134
finally, we substitute W430, H400, and r 370/2 into the above formula to obtain 0.667. That is, inside the rectangle 430 x 400, a circle of diameter 370 produces a non-gray area to rectangle ratio of more than 66%, so that more than 66% of the dots need not be traversed.
Therefore, according to the embodiment of the invention, by determining the target area and the target pixel point, detection points participating in Hough transform can be reduced, the calculation amount of Hough transform is reduced, and the calculation speed is increased.
In the embodiment of the present invention, optionally, when the accumulator is updated, the value of the accumulator subjected to hough circle transformation is updated every preset number of degrees, where the preset number of degrees is greater than 1, for example, the preset number of degrees is 10 degrees. This way the calculation can be increased by a factor of 10 over the conventional one-degree-per-update speed.
In the embodiment of the invention, optionally, in the general hough circle detection process, the pixel points related to the edge of the circle with the specified radius are calculated by taking each traversed point as the center of the circle. In this alternative embodiment, determining the pixel points involved on the circumference includes the following steps:
and determining a circle with a specified radius by taking a target pixel point as a circle center.
And determining 4 quadrants of the circle by taking the target pixel point as the origin of the coordinate system.
And calculating the coordinates of the point in the first quadrant on the circumference of the circle relative to the target pixel point.
And obtaining coordinates of points in the other three quadrants on the circumference of the circle relative to the target pixel point based on the calculated coordinates of the point in the first quadrant on the circumference of the circle relative to the target pixel point by utilizing the symmetry of the circle.
For each point on the circumference of the circle, determining the coordinate of the point relative to the target pixel point; and obtaining the coordinates of the point in the interested region according to the coordinates of the point relative to the target pixel point and the coordinates of the target pixel point in the interested region, and further determining the pixel point corresponding to the point in the interested region. All the pixel points involved on the circumference of the circle can be determined through the steps.
Therefore, in the optional embodiment, the coordinates of all points on the circumference can be quickly obtained by only calculating the coordinates of the points in one quadrant by using the symmetry of the circle, so that the calculation amount is reduced in the calculation process, and the processing efficiency is improved.
In the embodiment of the invention, optional target pixel point (x) is calculatedi,yj) As the circle center, r is the circle of radius, and when the pixel point involved on the circumference is, the pixel point involved on the circumference (x, y) can be represented by a polar coordinate formula:
x=xi+rcos(α)y=yj+rsin(α) (4)
however, in the actual operation process, it is time-consuming to calculate the trigonometric function, and in this alternative embodiment, the operation amount may be reduced by using the property of the trigonometric function:
determining the X-Y coordinate system of the circle and determining 4 quadrants of the circle;
let a point on the circle in the first quadrant be recorded as point p1Determining the point p1Angle of rotation alpha relative to the X axis1Calculating sin (alpha)1),cos(α1);
Determine the sum point p1A point symmetrical about the Y axis, denoted as point p2Point p of2Is a point on the circumference of the circle in the second quadrant, determines point p2Is alpha2And determining sin (α)2) And cos (. alpha.) (2) In which α is2=(π-α1),sin(α2)=sin(α1),cos(α2)=-cos(α1);
Determine the sum point p2A point symmetrical about the X axis, denoted as point p3Point p of3Is a point on the circumference of the circle in the third quadrant, determines point p3Is alpha3And determining sin (α)3) And cos (. alpha.) (3) In which α is3=(π+α1),sin(α3)=-sin(α1),cos(α2)=-cos(α1);
Determine the sum point p1A point symmetrical about the X axis, denoted as point p4Point p of4Is a point on the circumference of the circle in the fourth quadrant, determines point p4Is alpha4And determining sin (α)4) And cos (. alpha.) (4) In which α is4=(2π-α1),sin(α2)=-sin(α1),cos(α2)=cos(α1)。
Therefore, in the optional embodiment, by using the property of the trigonometric function and the symmetry of the circle, the coordinates of all points on the circumference can be quickly obtained by only calculating the trigonometric function of the points in one quadrant, so that the calculation amount is reduced in the calculation process, and the processing efficiency is improved.
It can be seen that by implementing the industrial product circular detection method described in fig. 1, the industrial product to be detected in the shooting area is collected, and an image to be detected is obtained; performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected; determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame; traversing pixel points in the region of interest, and screening a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest; performing circle detection on the region of interest based on the edge pixel points, all target pixel points and a Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle; the calculation amount of the Hough transform algorithm can be reduced, the detection efficiency is improved, and the requirement for rapidly detecting industrial products in industrial production is met.
Example two
Referring to fig. 5, fig. 5 is a schematic flow chart of another industrial product circle detection method according to an embodiment of the present disclosure. The industrial product circle detection method described in fig. 5 may be applied to devices such as a smart phone, a personal computer, and a server, and the embodiment of the present invention is not limited thereto. As shown in fig. 5, the industrial product circle detection method may include the operations of:
and S51, collecting the industrial product to be detected in the shooting area to obtain an image to be detected.
And S52, performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected.
And S53, determining the region of interest in the image to be detected according to the edge pixel points and the preset size of the rectangular frame.
And S54, traversing the pixel points in the region of interest, and screening a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest.
S55, performing circle detection on the region of interest based on the edge pixel points, all target pixel points and the Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle.
In the embodiment of the present invention, please refer to other specific descriptions of steps S1 to S5 in the first embodiment for other descriptions of steps S51 to S55, which is not repeated herein.
In this embodiment of the present invention, optionally, after step S55, the industrial product circular detection method further includes the following steps:
and S56, performing least square fitting on the edge pixel points of the image to be measured to obtain a fitting result.
And S57, comparing the fitting result with the central point and the radius corresponding to the circle to obtain the perfect circle degree of the industrial product to be measured.
In the embodiment of the present invention, optionally, in step S56, performing least square fitting on the edge pixel point of the image to be measured, and obtaining a fitting result, the method includes:
firstly, acquiring an edge pixel point coordinate set of an image to be detected.
Setting the coordinate set of edge pixel points of the image to be detected as { (x)1,y1),(x2,y2)...(xn,yn)}。
And secondly, establishing an overdetermined equation set of the circle to be fitted according to the edge pixel point coordinate set of the image to be fitted.
To fit a circle: (x-c)1)2+(y-c2)2=r2
The center of the circle is (c)1,c2) Radius r, order c3=r2-c1 2-c2 2
Then, the following steps are obtained: 2xc1+2yc2+c3=x2+y2
Substituting the boundary point number group to obtain an overdetermined equation set:
Figure BDA0003243268000000161
and thirdly, solving the over-determined equation set by using a least square estimation method to obtain a fitting result of the circle to be fitted.
The product of the matrix a with n rows and 3 columns on the left side of the equation in the overdetermined equation set and the vector Z with 3 rows and 1 column on the right side of the equation is referred to as an n-element column vector b, and a × Z is obtained.
The Numpy packet for Python can be used to find:
Import Numpy.linalg as la
lstsq (a, b), i.e. the least squares solution.
res [0] is a 3-element array with the value of the unknown vector z inside.
res [1] [0] is the fitting residual, representing how good the fit is.
It can be seen that by implementing the industrial product circle detection method described in fig. 5, the circle fitted by the edge pixel point is compared with the circle obtained by hough transform detection, so that the perfect circle degree of the industrial product to be detected can be determined.
EXAMPLE III
Referring to fig. 6, fig. 6 is a schematic flow chart of an industrial product circle detection device according to an embodiment of the present invention. The industrial product circle detection device described in fig. 6 may be adapted to a smart phone, a personal computer, a server, and other devices, and the embodiment of the present invention is not limited thereto. As shown in fig. 6, the industrial product circle detecting apparatus may include the following operations:
the acquisition module 601 is configured to acquire an industrial product to be detected in the shooting area to obtain an image to be detected.
In the embodiment of the invention, an electronic device with a camera is used for acquiring images, as shown in fig. 2, a dotted rectangular area in fig. 2 is a preset shooting area, and a circle is an example of an industrial product to be measured. In an alternative embodiment, the robot periodically sends the circular product to the front of the camera for collection, and the image to be measured is obtained.
The edge detection module 602 is configured to perform edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected.
In the embodiment of the invention, the edge detection algorithm is adopted to carry out edge detection, the boundary of the industrial product to be detected in the image to be detected is separated, and all edge pixel points in the image to be detected are obtained. Optionally, the edge detection algorithm may adopt an edge detection algorithm commonly used in the field, such as a Sobel edge detection algorithm, a Laplacian edge detection algorithm, a Canny edge detection algorithm, and the like, which is not limited in the present invention.
The determining module 603 is configured to determine an area of interest in the image to be measured according to the edge pixel point and a preset size of the rectangular frame.
In the embodiment of the invention, the position of the industrial product to be measured in the image to be measured obtained by shooting each time has certain deviation, but does not exceed the rectangle with fixed size, as shown by the solid line rectangle frame in fig. 2. In the embodiment of the invention, the preset rectangular frame size width is determined as W and the height is determined as H. And determining the region of interest where the edge pixel points are located in the image to be detected according to the edge pixel points obtained in the step S2 and a preset rectangular frame with the width W and the height H. Meanwhile, the method for determining the region of interest may adopt various operators and functions commonly used in machine vision software in the field to obtain the region of interest ROI, which is not limited by the present invention.
The traversing module 604 is configured to traverse the pixel points in the region of interest, and screen out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest.
In the prior art, the pixel is usually randomly located by using a specified (x, y) coordinate, and the conventional calculation for accessing the pixel I [ y ] [ x ] is: the pixel memory start address I + y + the number of bytes occupied by one row of pixels + x the number of bytes occupied by one pixel, that is, the operation amount is large when two additions and two multiplications are performed each time and the pixel point access is performed.
In the embodiment of the present invention, optionally, all the pixel points in the region of interest are stored in the memory continuously in rows. That is, all the pixels in the region of interest are stored continuously in the memory, and the data of all the pixels in the region of interest can be regarded as a one-dimensional array.
In the embodiment of the present invention, further optionally, a specific implementation manner of the traversing module 604 for traversing the pixel points in the region of interest includes:
and acquiring a preset pixel pointer p.
And pointing the pixel pointer p to the memory starting address of the first pixel point in the region of interest, and acquiring the first pixel point in the region of interest.
And executing p + +, enabling the pixel pointer p to point to the memory starting address of the next pixel point, and acquiring the next pixel point, wherein the next pixel point is a subsequent pixel point adjacent to the storage position of the first pixel point in the region of interest in the memory.
And repeatedly executing p + +, and obtaining all pixel points in the region of interest.
That is, in the embodiment of the present invention, when traversing the pixels, the pixels are accessed in a manner of consciously adjusting to be in front of and behind. Let a pixel pointer p point to the pixel memory start address I at the beginning. Thereafter, only p + + needs to be executed to point to the next adjacent pixel. Only one addition is required to access the next pixel. The amount of calculation is one fourth of the conventional way. If the multiply instruction is considered more time consuming than the add instruction, this step improves performance by a factor of more than 4.
In this embodiment of the present invention, optionally, before the traversing module 604 selects a plurality of target pixel points falling into a predetermined target region from all pixel points in the region of interest, the apparatus further includes: a target area generation module 600.
And a target area generating module 600, configured to determine a standard rectangular area according to a preset rectangular frame size. For example, the predetermined rectangular frame size width is W and height is H. Starting when the standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the preset step length is one pixel. The area through which the standard circle slides is determined as a target area.
In the embodiment of the present invention, further optionally, the initial position is a position where any two adjacent edges of the standard circle and the standard rectangular region are tangent to each other.
The target area generating module 600 starts sliding the standard circle according to a preset step length when the standard circle is at an initial position until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, and specifically includes the following steps:
and determining the movement starting position of the standard circle, wherein the initially determined movement starting position is the initial position.
Starting from the position where the standard circle is located at the movement starting position, sliding the standard circle according to a rule of sliding the standard circle in a first preset direction for a preset step length each time until the standard circle is tangent to a first target edge of the standard rectangular region, wherein the first preset direction is parallel to any one of all edges of the standard rectangular region, and the first target edge is an edge towards which the first preset direction faces in all edges of the standard rectangular region.
And resetting the standard circle at the moving initial position, and sliding the standard circle once according to a rule of sliding a preset step length along a second preset direction to obtain a first position of the standard circle, wherein the second preset direction is vertical to the first preset direction.
And judging whether the standard circle is tangent to a second target edge of the standard rectangular region when the standard circle is at the first position, wherein the second target edge is an edge towards which a second preset direction faces in all edges of the standard rectangular region.
If the standard circle is not tangent to the second target edge of the standard rectangular area when the standard circle is located at the first position, updating the moving initial position according to the first position, executing the step of starting with the standard circle being located at the moving initial position, sliding the standard circle according to a rule of sliding the preset step length along the first preset direction each time until the standard circle is tangent to the first target edge of the standard rectangular area, and executing the step of resetting the standard circle at the moving initial position, and sliding the standard circle once according to the rule of sliding the preset step length along the second preset direction to obtain the first position of the standard circle.
And if the standard circle is judged to be tangent to the second target edge of the standard rectangular area when the standard circle is at the first position, sliding the standard circle according to a rule of sliding a preset step length along a first preset direction each time from the first position of the standard circle until the standard circle is tangent to the first target edge of the standard rectangular area, and finishing sliding.
For example, let the circle representing the edge of the product be located where the top left corner of a rectangular box at W x H is tangent to the two sides of the rectangular box, as shown in fig. 3 (a). The circle is made to slide one pixel at a time from left to right within the rectangular box of W x H, and when the right boundary of the rectangle is touched, the circle is made to return to the leftmost side, then drops one pixel, and moves from left to right. Continuing, the last circle is located at the lower right corner of the rectangular frame, tangent to the two sides of the rectangular frame, as shown in FIG. 3(b) where the circle is located. In this process, the area swept by the points on the circular edge is the target area. It is clear that points of the non-target region are not detected in the hough circle transform calculation.
In the embodiment of the present invention, optionally, the traversal module 604 screens out a plurality of target pixel points falling into a predetermined target region from all pixel points in the region of interest, which specifically includes the following contents:
in the standard rectangular region, the pixel values of all pixel points included in the target region are marked as 1, and the pixel values of a plurality of remaining pixel points except the pixel points included in the target region are marked as 0, so that a mask image is obtained. In this alternative embodiment, the target area may be obtained by programming in Python, moving the circle inside the rectangle and noting the point where the edge of the circle passes.
And determining the coordinates of all first pixel points in the region of interest and the coordinates of all second pixel points in the mask image, wherein the coordinates of the first pixel points in the region of interest are the same as the coordinates of the first second pixel points in the mask image.
And for each first pixel point in the region of interest, acquiring a second pixel point with the same coordinate as the first pixel point in the mask image according to the coordinate of the first pixel point, and performing AND operation on the pixel value of the first pixel point and the pixel value of the second pixel point.
And if the pixel value of the first pixel point and the pixel value of the second pixel point and the operation result are 0, judging that the first pixel point does not fall into the target area.
And if the pixel value of the first pixel point, the pixel value of the second pixel point and the operation result are not 0, judging that the first pixel point falls into a target area, and determining the first pixel point as a target pixel point.
Therefore, in the optional embodiment, when traversing the rectangle, it is only necessary to see whether the point corresponding to the mask image is 1 to know whether traversing is needed, and the efficiency is further improved.
The detection module 605 is configured to perform circle detection on the region of interest based on the edge pixel points, all target pixel points, and the hough transform algorithm, so as to obtain a circle included in the region of interest, and a central point and a radius corresponding to the circle.
Hough transform is a feature detection algorithm widely used in image analysis, computer vision, and digital image processing. The hough transform is used to identify features in the found object, such as: and (4) a circular shape. The algorithm flow is roughly as follows, given an object, the kind of shape to be distinguished, the algorithm performs voting in the parameter space (parameter space) to determine the shape of the object, which is determined by the local maximum (local maximum) in the accumulation space (accumulator space).
By defining the shape equation to be detected, the detection of the shape can be realized. As in the explicit form, the hough transform is defined by considering the equation of a circle of the following formula (1):
(x-x0)2+(y-y0)2=r2 (1)
the equation defines a point with origin (x)0,y0) As the center of the circle, r is the locus of the point (x, y) of radius. The equation can be visualized in two additional ways: the locus of each point (x, y) in the image, or the point (x) with (x, y) as the center and r as the radius0,y0) The trajectory of (2). Fig. 4 illustrates both definitions based on the circle detection of the hough transform.
In the image containing circles of fig. 4, (a) each edge point defines a set of circles of accumulator space, which are defined by all possible radii, with the coordinates of their edge points as the center of the circle. The accumulator space of fig. 4 (b) gives three circles defined by three edge points having a given radius, each edge point defining a circle with other values as radii. This means that the accumulator space is three-dimensional (with three parameters of interest) and the edge points map to one Voting (Voting) pyramid (a con of votes) of the accumulator space. The three-dimensional accumulation space of fig. 4(c) is such an accumulator. After all the evidence of edge points are collected, the maximum value of the accumulator space corresponds to the parameters of the circle of the original image. Wherein the Voting (Voting) is formed by generating a cone according to the above equation (1).
The above formula (1) can be defined in a parametric form as:
x=x0+rcos(θ)y=y0+rsin(θ) (2)
the advantage of this representation method is that it allows solving parameter problems. Thus, the definition of the hough transform map is:
x0=x-rcos(θ)y0=y-rsin(θ) (3)
these equations define points in accumulator space that depend on the radius r.
The circle with the radius within the designated range can be found out by adopting Hough circle transformation, and the central point and the radius of the circle can be obtained. However, the conventional hough transform process is to traverse all points in the whole rectangular region once. For a preset rectangular frame with W width and H height, detection operation is performed on all pixel points in an area through traditional Hough transformation, the operation amount is very large, and the detection efficiency is very low.
In the embodiment of the invention, the detection points participating in Hough transform are reduced by determining the target area and the target pixel points, so that the speed is increased by more than one time. The following was demonstrated:
for example, a rectangular box of W × H is set to a region of 430 pixels × 400 pixels, and the diameter of the product to be detected is 370.
As shown in fig. 3(a) and 3(b), the midpoints of the sides of the rectangular frame are taken to connect the midpoints of the two sets of opposite sides, so as to obtain a rectangular cross line, and the rectangle is divided into 4 regions of the same size. Two circular diameter lines are taken, the two diameter lines are parallel to the rectangular cross line, and the two circular diameter lines divide the circle into 4 areas with the same size.
Two white regions were recorded as areas S1 and S2, respectively, as shown in fig. 3 (b). It can be seen that the proportion of the gray area in the rectangle is obtained by calculating S1+ S2 and dividing by W H/4.
Let coordinates of point A be (Ax, Ay), and coordinates of point B be (Bx, By).
Figure BDA0003243268000000211
Calculating by definite integral S2:
Figure BDA0003243268000000212
calculating the ratio of the gray area to the rectangular area:
Figure BDA0003243268000000213
and calculating to obtain:
Figure BDA0003243268000000214
finally, we substitute W430, H400, and r 370/2 into the above formula to obtain 0.667. That is, inside the rectangle 430 x 400, a circle of diameter 370 produces a non-gray area to rectangle ratio of more than 66%, so that more than 66% of the dots need not be traversed.
Therefore, according to the embodiment of the invention, by determining the target area and the target pixel point, detection points participating in Hough transform can be reduced, the calculation amount of Hough transform is reduced, and the calculation speed is increased.
In the embodiment of the present invention, optionally, when the accumulator is updated, the value of the accumulator subjected to hough circle transformation is updated every preset number of degrees, where the preset number of degrees is greater than 1, for example, the preset number of degrees is 10 degrees. This way the calculation can be increased by a factor of 10 over the conventional one-degree-per-update speed.
In the embodiment of the invention, optionally, in the general hough circle detection process, the pixel points related to the edge of the circle with the specified radius are calculated by taking each traversed point as the center of the circle. In this alternative embodiment, determining the pixel points involved on the circumference includes the following steps:
and determining a circle with a specified radius by taking a target pixel point as a circle center.
And determining 4 quadrants of the circle by taking the target pixel point as the origin of the coordinate system.
And calculating the coordinates of the point in the first quadrant on the circumference of the circle relative to the target pixel point.
And obtaining coordinates of points in the other three quadrants on the circumference of the circle relative to the target pixel point based on the calculated coordinates of the point in the first quadrant on the circumference of the circle relative to the target pixel point by utilizing the symmetry of the circle.
For each point on the circumference of the circle, determining the coordinate of the point relative to the target pixel point; and obtaining the coordinates of the point in the interested region according to the coordinates of the point relative to the target pixel point and the coordinates of the target pixel point in the interested region, and further determining the pixel point corresponding to the point in the interested region. All the pixel points involved on the circumference of the circle can be determined through the steps.
Therefore, in the optional embodiment, the coordinates of all points on the circumference can be quickly obtained by only calculating the coordinates of the points in one quadrant by using the symmetry of the circle, so that the calculation amount is reduced in the calculation process, and the processing efficiency is improved.
In the embodiment of the invention, optional target pixel point (x) is calculatedi,yj) As the circle center, r is the circle of radius, and when the pixel point involved on the circumference is, the pixel point involved on the circumference (x, y) can be represented by a polar coordinate formula:
x=xi+rcos(α)y=yj+rsin(α) (4)
however, in the actual operation process, it is time-consuming to calculate the trigonometric function, and in this alternative embodiment, the operation amount may be reduced by using the property of the trigonometric function:
determining the X-Y coordinate system of the circle and determining 4 quadrants of the circle;
let a point on the circle in the first quadrant be recorded as point p1Determining the point p1Angle of rotation alpha relative to the X axis1Calculating sin (alpha)1),cos(α1);
Determine the sum point p1A point symmetrical about the Y axis, denoted as point p2Point p of2Is a point on the circumference of the circle in the second quadrant, determines point p2Is alpha2And determining sin (α)2) And cos (. alpha.) (2) In which α is2=(π-α1),sin(α2)=sin(α1),cos(α2)=-cos(α1);
Determine the sum point p2A point symmetrical about the X axis, denoted as point p3Point p of3Is a point on the circumference of the circle in the third quadrant, determines point p3Is alpha3And determining sin (α)3) And cos (. alpha.) (3) In which α is3=(π+α1),sin(α3)=-sin(α1),cos(α2)=-cos(α1);
Determine the sum point p1A point symmetrical about the X axis, denoted as point p4Point p of4Is a point on the circumference of the circle in the fourth quadrant, determines point p4Is alpha4And determining sin (α)4) And cos (. alpha.) (4) In which α is4=(2π-α1),sin(α2)=-sin(α1),cos(α2)=cos(α1)。
Therefore, in the optional embodiment, by using the property of the trigonometric function and the symmetry of the circle, the coordinates of all points on the circumference can be quickly obtained by only calculating the trigonometric function of the points in one quadrant, so that the calculation amount is reduced in the calculation process, and the processing efficiency is improved.
In the embodiment of the present invention, optionally, the industrial product circle detection apparatus according to the embodiment of the present invention further includes: a fitting module 606, the fitting module 606 configured to:
performing least square fitting on edge pixel points of the image to be measured to obtain a fitting result; and comparing the fitting result with the central point and the radius corresponding to the circle to obtain the perfect circle degree of the industrial product to be measured.
In the embodiment of the present invention, further optionally, performing least square fitting on edge pixel points of an image to be measured, and obtaining a fitting result, where the specific implementation manner includes:
firstly, acquiring an edge pixel point coordinate set of an image to be detected.
Setting the coordinate set of edge pixel points of the image to be detected as { (x)1,y1),(x2,y2)...(xn,yn)}。
And secondly, establishing an overdetermined equation set of the circle to be fitted according to the edge pixel point coordinate set of the image to be fitted.
To fit a circle: (x-c)1)2+(y-c2)2=r2
The center of the circle is (c)1,c2) Radius r, order c3=r2-c1 2-c2 2
Then, the following steps are obtained: 2xc1+2yc2+c3=x2+y2
Substituting the boundary point number group to obtain an overdetermined equation set:
Figure BDA0003243268000000231
and thirdly, solving the over-determined equation set by using a least square estimation method to obtain a fitting result of the circle to be fitted.
The product of the matrix a with n rows and 3 columns on the left side of the equation in the overdetermined equation set and the vector Z with 3 rows and 1 column on the right side of the equation is referred to as an n-element column vector b, and a × Z is obtained.
The Numpy packet for Python can be used to find:
Import Numpy.linalg as la
lstsq (a, b), i.e. the least squares solution.
res [0] is a 3-element array with the value of the unknown vector z inside.
res [1] [0] is the fitting residual, representing how good the fit is.
Therefore, in the optional embodiment, the circle fitted by the edge pixel point is compared with the circle obtained by hough transform detection, so that the perfect circle degree of the industrial product to be detected can be determined.
It can be seen that, with the circular industrial product detection device described in fig. 6, the industrial product to be detected in the shooting area is collected, and an image to be detected is obtained; performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected; determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame; traversing pixel points in the region of interest, and screening a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest; performing circle detection on the region of interest based on the edge pixel points, all target pixel points and a Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle; the calculation amount of the Hough transform algorithm can be reduced, the detection efficiency is improved, and the requirement for rapidly detecting industrial products in industrial production is met.
Example four
Referring to fig. 7, fig. 7 is a schematic structural diagram of another industrial product circle detection device disclosed in the embodiment of the present invention. As shown in fig. 7, the industrial product circle detecting apparatus may include:
a memory 701 in which executable program code is stored;
a processor 702 coupled to the memory 701;
the processor 702 calls the executable program code stored in the memory 701 to execute the steps of the industrial product circle detection method described in the first embodiment or the second embodiment of the present invention.
EXAMPLE five
The embodiment of the invention discloses a computer storage medium, which stores computer instructions, and the computer instructions are used for executing the steps in the industrial product circle detection method described in the first embodiment or the second embodiment of the invention when being called.
EXAMPLE six
An embodiment of the invention discloses a computer program product comprising a non-transitory computer readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform the steps of the method for intelligently controlling circulation of a reusable container described in the first or second embodiment.
The above-described embodiments of the apparatus are merely illustrative, and the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above detailed description of the embodiments, those skilled in the art will clearly understand that the embodiments may be implemented by software plus a necessary general hardware platform, and may also be implemented by hardware. Based on such understanding, the above technical solutions may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, where the storage medium includes a Read-Only Memory (ROM), a Random Access Memory (RAM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), a One-time Programmable Read-Only Memory (OTPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Compact Disc-Read-Only Memory (CD-ROM), or other disk memories, CD-ROMs, or other magnetic disks, A tape memory, or any other medium readable by a computer that can be used to carry or store data.
Finally, it should be noted that: the method and apparatus for detecting the circular shape of an industrial product disclosed in the embodiments of the present invention are only preferred embodiments of the present invention, and are only used for illustrating the technical solutions of the present invention, not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those skilled in the art; the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for detecting a circularity of an industrial product, said method comprising:
collecting an industrial product to be detected in a shooting area to obtain an image to be detected;
performing edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected;
determining an interested area in the image to be detected according to the edge pixel point and the size of a preset rectangular frame;
traversing the pixel points in the region of interest, and screening out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest;
and performing circle detection on the region of interest based on the edge pixel points, all the target pixel points and the Hough transform algorithm to obtain a circle contained in the region of interest and a central point and a radius corresponding to the circle.
2. The industrial product circular inspection method of claim 1, wherein before the step of screening out a plurality of target pixels falling within a predetermined target area from all the pixels in the region of interest, the method further comprises:
determining a standard rectangular area according to the preset size of the rectangular frame;
starting when a standard circle is at an initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the preset step length is one pixel;
and determining the area through which the standard circle slides as a target area.
3. The industrial product circular detection method according to claim 2, wherein the initial position is a position where the standard circle is tangent to any two adjacent edges of the standard rectangular region;
starting when the standard circle is at the initial position, sliding the standard circle according to a preset step length until the standard circle is tangent to any two adjacent edges of the standard rectangular area in the sliding process, wherein the sliding process comprises the following steps:
determining a movement starting position where the standard circle is located, wherein the initially determined movement starting position is the initial position;
starting from the standard circle at the movement starting position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time until the standard circle is tangent to a first target edge of the standard rectangular region, wherein the first preset direction is parallel to any one of all edges of the standard rectangular region, and the first target edge is an edge towards which the first preset direction faces in all edges of the standard rectangular region;
resetting the standard circle at the moving initial position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain a first position of the standard circle, wherein the second preset direction is vertical to the first preset direction;
judging whether the standard circle is tangent to a second target edge of the standard rectangular region when the standard circle is at the first position, wherein the second target edge is an edge of all edges of the standard rectangular region, and the second target edge faces the second preset direction;
if the standard circle is not tangent to the second target edge of the standard rectangular area when the standard circle is located at the first position, updating the moving starting position according to the first position, executing the step of sliding the standard circle according to a rule of sliding the preset step length each time along a first preset direction from the moving starting position, and stopping sliding until the standard circle is tangent to the first target edge of the standard rectangular area, and executing the step of resetting the standard circle at the moving starting position, and sliding the standard circle once according to a rule of sliding the preset step length along a second preset direction to obtain the first position of the standard circle;
and if the standard circle is judged to be tangent to the second target edge of the standard rectangular area when the standard circle is at the first position, sliding the standard circle according to a rule of sliding the preset step length along a first preset direction each time from the first position of the standard circle until the standard circle is tangent to the first target edge of the standard rectangular area, and finishing sliding.
4. The industrial product circular detection method according to claim 2, wherein the step of screening out a plurality of target pixel points falling into a predetermined target area from all the pixel points in the region of interest comprises:
in the standard rectangular region, marking the pixel values of all pixel points contained in the target region as 1, and marking the pixel values of a plurality of residual pixel points except the pixel points contained in the target region as 0 to obtain a mask image;
determining coordinates of all first pixel points in the region of interest and coordinates of all second pixel points in the mask image, wherein the first pixel point coordinate in the region of interest is the same as the first second pixel point coordinate in the mask image;
for each first pixel point in the region of interest, acquiring a second pixel point with the same coordinate as the first pixel point in the mask image according to the coordinate of the first pixel point, and performing an and operation on the pixel value of the first pixel point and the pixel value of the second pixel point;
if the pixel value of the first pixel point and the pixel value of the second pixel point and the operation result are 0, judging that the first pixel point does not fall into the target area;
and if the pixel value of the first pixel point, the pixel value of the second pixel point and the operation result are not 0, judging that the first pixel point falls into the target area, and determining the first pixel point as a target pixel point.
5. The industrial product circular detection method according to claim 1, wherein all the pixels in the region of interest are stored in the memory continuously in rows;
the traversing of the pixel points in the region of interest includes:
acquiring a preset pixel pointer p;
enabling the pixel pointer p to point to the memory starting address of the first pixel point in the region of interest, and acquiring the first pixel point in the region of interest;
executing p + +, enabling the pixel pointer p to point to the memory starting address of the next pixel point, and acquiring the next pixel point, wherein the next pixel point is a subsequent pixel point adjacent to the storage position of the first pixel point in the region of interest in the memory;
and repeatedly executing p + +, and obtaining all pixel points in the region of interest.
6. The industrial product circle detection method of claim 1, wherein after determining the center point and radius corresponding to the detected circle, the method further comprises:
performing least square fitting on edge pixel points of the image to be measured to obtain a fitting result;
and comparing the fitting result with the central point and the radius corresponding to the circle to obtain the perfect circle degree of the industrial product to be detected.
7. The industrial product circle detection method according to claim 6, wherein the performing least square fitting on the edge pixel point of the image to be detected and obtaining a fitting result comprises:
acquiring an edge pixel point coordinate set of the image to be detected;
establishing an overdetermined equation set of a circle to be fitted according to the edge pixel point coordinate set of the image to be fitted;
and solving the overdetermined equation set by using a least square estimation method to obtain a fitting result of the circle to be fitted.
8. An industrial product roundness detection apparatus, the apparatus comprising:
the acquisition module is used for acquiring the industrial product to be detected in the shooting area to obtain an image to be detected;
the edge detection module is used for carrying out edge detection on the image to be detected through an edge detection algorithm to obtain edge pixel points of the image to be detected;
the determining module is used for determining an interested area in the image to be detected according to the edge pixel point of the image to be detected and the size of a preset rectangular frame;
the traversal module is used for traversing the pixel points in the region of interest and screening out a plurality of target pixel points falling into a predetermined target region from all the pixel points in the region of interest;
and the detection module is used for performing circular detection on the image to be detected based on the edge pixel points of the image to be detected, all the target pixel points and the Hough transform algorithm to obtain a circle contained in the image to be detected and a central point and a radius corresponding to the circle.
9. An industrial product roundness detection apparatus, the apparatus comprising:
a memory storing executable program code;
a processor coupled with the memory;
the processor invokes the executable program code stored in the memory to perform the industrial article roundness detection apparatus method of any one of claims 1-7.
10. A computer readable storage medium having computer program instructions stored therein, which when invoked, perform the industrial product roundness detection method of any one of claims 1-7.
CN202111025672.4A 2021-09-02 2021-09-02 Industrial product circular detection method and device Pending CN113870189A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111025672.4A CN113870189A (en) 2021-09-02 2021-09-02 Industrial product circular detection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111025672.4A CN113870189A (en) 2021-09-02 2021-09-02 Industrial product circular detection method and device

Publications (1)

Publication Number Publication Date
CN113870189A true CN113870189A (en) 2021-12-31

Family

ID=78989239

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111025672.4A Pending CN113870189A (en) 2021-09-02 2021-09-02 Industrial product circular detection method and device

Country Status (1)

Country Link
CN (1) CN113870189A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117115146A (en) * 2023-10-19 2023-11-24 深圳宝铭微电子有限公司 Method for detecting quality of coating film on surface of silicon carbide semiconductor
CN117152415A (en) * 2023-09-01 2023-12-01 北京奥乘智能技术有限公司 Method, device, equipment and storage medium for detecting marker of medicine package
CN117350984A (en) * 2023-10-23 2024-01-05 保定景欣电气有限公司 Method and device for detecting shoulder-opening and fork-opening of monocrystalline silicon

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117152415A (en) * 2023-09-01 2023-12-01 北京奥乘智能技术有限公司 Method, device, equipment and storage medium for detecting marker of medicine package
CN117152415B (en) * 2023-09-01 2024-04-23 北京奥乘智能技术有限公司 Method, device, equipment and storage medium for detecting marker of medicine package
CN117115146A (en) * 2023-10-19 2023-11-24 深圳宝铭微电子有限公司 Method for detecting quality of coating film on surface of silicon carbide semiconductor
CN117115146B (en) * 2023-10-19 2024-03-19 深圳宝铭微电子有限公司 Method for detecting quality of coating film on surface of silicon carbide semiconductor
CN117350984A (en) * 2023-10-23 2024-01-05 保定景欣电气有限公司 Method and device for detecting shoulder-opening and fork-opening of monocrystalline silicon

Similar Documents

Publication Publication Date Title
CN113870189A (en) Industrial product circular detection method and device
CN110223226B (en) Panoramic image splicing method and system
CN107301402B (en) Method, device, medium and equipment for determining key frame of real scene
CN109977997B (en) Image target detection and segmentation method based on convolutional neural network rapid robustness
CN108986152B (en) Foreign matter detection method and device based on difference image
WO2023065792A1 (en) Image processing method and apparatus, electronic device, and computer-readable storage medium
CN109698944B (en) Projection area correction method, projection apparatus, and computer-readable storage medium
CN111598074A (en) Edge detection method and apparatus, electronic device, and storage medium
CN108257186B (en) Method and device for determining calibration image, camera and storage medium
CN108334879B (en) Region extraction method, system and terminal equipment
CN109509200A (en) Checkerboard angle point detection process, device and computer readable storage medium based on contours extract
CN114331951A (en) Image detection method, image detection device, computer, readable storage medium, and program product
CN111062331A (en) Mosaic detection method and device for image, electronic equipment and storage medium
CN109034058B (en) Method and system for dividing and self-correcting region in image
CN111553927B (en) Checkerboard corner detection method, detection system, computer device and storage medium
CN106663317B (en) Morphological processing method and digital image processing device for digital image
CN110264397B (en) Method and device for extracting effective region of fisheye image
CN115619791B (en) Article display detection method, device, equipment and readable storage medium
CN111047614A (en) Feature extraction-based method for extracting target corner of complex scene image
CN108564571B (en) Image area selection method and terminal equipment
CN115049713A (en) Image registration method, device, equipment and readable storage medium
CN114049380A (en) Target object positioning and tracking method and device, computer equipment and storage medium
CN111260723B (en) Barycenter positioning method of bar and terminal equipment
CN113840135A (en) Color cast detection method, device, equipment and storage medium
CN113470063A (en) Multi-target tracking method, device and medium based on feature set

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