Disclosure of Invention
In order to solve the problem that the accuracy of the detection result of the defect of the oil-way copper sleeve of the automobile engine is poor, the invention aims to provide a computer vision-based method for detecting the defect of the oil-way copper sleeve of the automobile engine.
The invention provides a computer vision-based method for detecting defects of a copper bush of an oil way of an automobile engine, which comprises the following steps of:
acquiring a surface image of an oil way copper sleeve of an automobile engine to be detected, and preprocessing the surface image to obtain a preprocessed surface image;
determining a relevant area of each pixel point in the preprocessed surface image according to the preprocessed surface image, and determining an abnormal degree index value of each pixel point according to the gray value of each pixel point in the relevant area of each pixel point;
acquiring the gray gradient amplitude of each pixel point in the preprocessed surface image, and determining the probability that each pixel point is a defect edge pixel point according to the abnormal degree index value and the gray gradient amplitude of each pixel point and the neighborhood pixel points in the preprocessed surface image;
determining each defect edge pixel point in the preprocessed surface image according to the probability that each pixel point is a defect edge pixel point;
determining each defect edge connected domain in the preprocessed surface image according to each defect edge pixel point in the preprocessed surface image and the probability that the defect edge pixel point is the defect edge pixel point, and further determining each defect area in the preprocessed surface image;
and determining the defect degree evaluation value of the oil way copper sleeve of the automobile engine to be detected according to the area and the number corresponding to each defect region in the preprocessed surface image of the oil way copper sleeve of the automobile engine to be detected.
Further, a formula for calculating the probability that each pixel is a defect edge pixel is as follows:
wherein,
for the probability that each pixel is a defect edge pixel,
for the index value of the degree of abnormality of each pixel point,
for the gray scale gradient magnitude of each pixel point,
the abnormal degree index value of the k-th neighborhood pixel point of each pixel point,
for the k-th neighborhood image of each pixel pointThe gray scale gradient magnitude of the pixel point,
in order to be a hyper-parameter,
as a hyperbolic tangent function.
Further, a calculation formula of the abnormal degree index value of each pixel point is as follows:
wherein,
for the index value of the degree of abnormality of each pixel point,
for the first in the relevant area of each pixel
jThe gray value of each pixel point is calculated,
for the mean value of the gray levels of the individual pixels in the relevant area of each pixel,
the number of pixel points in the relevant area for each pixel point.
Further, the step of determining each defect edge connected domain in the preprocessed surface image includes a step of determining and traversing a plurality of defect edge connected domains in sequence, and each step of determining and traversing a defect edge connected domain includes:
judging whether a defect edge pixel point of a defect edge connected domain which is not determined exists in the current surface image;
if the defect edge pixel points of the undetermined defect edge connected domain exist, determining the positions of the growing seed points in the current surface image according to the probability that each defect edge pixel point in the undetermined defect edge connected domain corresponds to the defect edge pixel point;
judging whether defect edge pixel points exist in a preset neighborhood corresponding to the growth seed point, if so, merging the growth seed point and the defect edge pixel points in the preset neighborhood into a defect edge communication domain, further judging whether defect edge pixel points exist in the preset neighborhood corresponding to each defect edge pixel point in the defect edge communication domain, and continuously repeating the steps until no defect edge pixel points exist in the preset neighborhood corresponding to the defect edge pixel points.
Further, a calculation formula of the evaluation value of the defect degree of the copper sleeve of the oil way of the automobile engine to be detected is as follows:
wherein,
the defect degree evaluation value of the copper sleeve of the oil way of the automobile engine to be detected,
for the second in the surface image of the pretreated automobile engine oil way copper sleeve to be detected
xThe area of each defect area, n is the number of the defect areas in the surface image of the oil way copper sleeve of the automobile engine to be detected after pretreatment,
the total area of the surface image of the pre-processed automobile engine oil way copper sleeve to be detected is obtained.
Further, the step of determining each defect edge pixel point in the preprocessed surface image includes:
if the probability that a certain pixel point in the preprocessed surface image is a defect edge pixel point is not less than the preset defect probability value, the pixel point is a defect edge pixel point, otherwise, the pixel point is not a defect edge pixel point.
Further, the step of determining the relevant region of each pixel point in the preprocessed surface image includes:
constructing a sliding window according to the preprocessed surface image, and enabling the sliding window to slide on the preprocessed surface image, so as to obtain a sliding window area of each pixel point in the preprocessed surface image;
and determining the relevant area of each pixel point according to the sliding window area of each pixel point in the preprocessed surface image.
Further, the relevant region of each pixel point refers to a sliding window region that does not contain each pixel point.
Further, the step of determining each defect region in the preprocessed surface image comprises:
and clustering the defect edge connected domains according to the defect edge connected domains in the preprocessed surface image, and taking the minimum external matrix of the defect edge connected domains of the same type as the defect region in the preprocessed surface image.
The invention has the following beneficial effects:
according to the method, the relevant area of each pixel point is determined by acquiring the surface image of the preprocessed automobile engine oil way copper sleeve to be detected. Determining an abnormal degree index value of each pixel point according to the gray value of each pixel point in the relevant region of each pixel point, then determining the probability that each pixel point is a defect edge pixel point according to the abnormal degree index value and the gray gradient amplitude value of each pixel point and the adjacent pixel points, and further determining each defect edge pixel point in the preprocessed surface image, thereby determining each defect region in the preprocessed surface image. And finally, the defect degree evaluation value of the oil way copper sleeve of the automobile engine to be detected is determined according to the area and the number corresponding to each defect area.
According to the method, the probability that each pixel point in the surface image of the to-be-detected automobile engine oil way copper sleeve is a defect edge pixel point is determined, the defect edge pixel points in the surface image are determined, pixel points with abnormal pixel gray levels caused by illumination influence in the surface image of the to-be-detected automobile engine oil way copper sleeve are eliminated, the accuracy of the area and the number corresponding to each defect area in the pre-processed surface image is ensured, the defect degree evaluation value of the to-be-detected automobile engine oil way copper sleeve is enabled to be more standard, and the accuracy of oil way copper sleeve defect detection is effectively improved. In addition, the invention can enable the automobile engine oil way copper sleeve to be detected to be more suitable for complex illumination environment, enhances the robustness of defect detection and enables the defect detection result to be more accurate.
Detailed Description
To further explain the technical means and effects of the present invention adopted to achieve the predetermined objects, the following detailed description of the embodiments, structures, features and effects of the technical solutions according to the present invention will be given with reference to the accompanying drawings and preferred embodiments. In the following description, different references to "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
The embodiment provides a computer vision-based method for detecting defects of an oil way copper bush of an automobile engine, which has the application scenes that: in the production process of the automobile engine oil way copper sleeve, the defect of the automobile engine oil way copper sleeve caused by abnormal process control or transport error needs to be detected, as shown in figure 1, the method comprises the following steps:
(1) the method comprises the steps of obtaining a surface image of an oil way copper sleeve of the automobile engine to be detected, and preprocessing the surface image to obtain a preprocessed surface image.
In this embodiment, the industrial camera is used for collecting the surface image of the copper sleeve of the oil passage of the automobile engine to be detected, and in order to reduce the subsequent calculation amount, the surface image is preprocessed in the implementation, and the preprocessing step includes: inputting the surface image of the oil-way copper sleeve of the automobile engine to be detected into a constructed and trained oil-way copper sleeve recognition network to obtain a binary image of the surface image of the oil-way copper sleeve of the automobile engine to be detected, then processing the binary image of the surface image of the oil-way copper sleeve of the automobile engine to be detected by adopting Gaussian filtering to eliminate the influence of Gaussian noise on the binary image of the surface image of the oil-way copper sleeve of the automobile engine to be detected, carrying out gray processing on the binary image, and finally obtaining the surface image of the oil-way copper sleeve of the automobile engine to be detected after preprocessing. The process of gaussian filtering and denoising is prior art and is not within the scope of the present invention, and will not be elaborated herein.
The process for acquiring the surface image of the oil way copper sleeve of the automobile engine to be detected comprises the following steps: firstly, placing an automobile engine oil way copper sleeve to be detected on a rotatable workbench, then arranging a camera light source, wherein the camera light source adopts an OPT machine vision light source to realize light source compensation on the surface of the automobile engine oil way copper sleeve to be detected, the camera light source is positioned obliquely above the automobile engine oil way copper sleeve to be detected, and finally, acquiring a surface image of the automobile engine oil way copper sleeve to be detected by utilizing an industrial camera through the rotatable workbench, wherein the industrial camera is positioned right above the automobile engine oil way copper sleeve to be detected.
It should be noted that, when the surface image to be detected is preprocessed, a pre-constructed and trained oil circuit copper bush identification network is used, and training the oil circuit copper bush identification network requires a large number of training data sets, the training data sets are surface images of a large number of automobile engine oil circuit copper bushes with various styles, and the process of acquiring the training data sets of the oil circuit copper bush identification network is consistent with the process of acquiring the surface images of the automobile engine oil circuit copper bushes to be detected, so the process of acquiring the surface images of the automobile engine oil circuit copper bushes to be detected can be referred to by the training data sets of the oil circuit copper bush identification network. When the oil way copper sleeve identification network is trained, the label corresponding to the data set is a single-channel semantic label, the background pixel point in the surface image is marked as 0, the pixel point of the automobile engine oil way copper sleeve in the surface image is marked as 1, and the loss function used in the training process is a cross entropy loss function. The process of constructing and training the oil circuit copper bush recognition network is the prior art and is not within the protection scope of the invention, and the detailed description is not provided herein.
(2) And determining a relevant area of each pixel point in the preprocessed surface image according to the preprocessed surface image, and determining an abnormal degree index value of each pixel point according to the gray value of each pixel point in the relevant area of each pixel point.
Firstly, it should be noted that, in the production process of the oil-way copper sleeve of the automobile engine, the casting blank is subjected to various stresses, and the stresses cause the casting blank to generate thermal strain, tensile strain, phase change strain and the like. When the casting blank can not bear stress strain, a crack is generated, after the crack is contacted with air, oxidation reaction is generated and cuprous oxide is generated, the cuprous oxide on the surface of the copper sleeve of the oil way of the automobile engine and the copper inside the copper sleeve have color difference, at the moment, various pixel gray level differences can be presented in the collected surface image of the copper sleeve of the oil way of the automobile engine, the gray level differences are caused by cracks or scratches of products in the production process, and the gray level changes of the pixel gray level of a crack area or a scratch area in the surface image of the copper sleeve of the oil way of the automobile engine and the pixel gray level of a normal area are cliff type.
In addition, because the automobile engine oil way copper sleeve in the embodiment is of a tubular smooth metal structure, the automobile engine oil way copper sleeve is easy to reflect light under the influence of illumination, so that a local highlight phenomenon exists in the automobile engine oil way copper sleeve, and the closer the automobile engine oil way copper sleeve is to the industrial camera, the larger the gray value of a partial area in a surface image of the automobile engine oil way copper sleeve is. Although the highlight area in the surface image of the copper sleeve of the oil way of the automobile engine has larger gray scale difference with other areas in the surface image, the gray scale change in the surface image of the copper sleeve of the oil way of the automobile engine caused by illumination is a gradual change process.
In order to determine whether the abnormal change of the pixel gray scale in the surface image of the oil copper sleeve of the automobile engine to be detected after preprocessing is a cliff type or a gradual change type, that is, in order to distinguish a defect caused by a crack in the surface image of the oil copper sleeve of the automobile engine and a pseudo defect caused by illumination, the embodiment needs to calculate the abnormal degree index value of each pixel point in the surface image, and the steps include:
(2-1) determining a relevant area of each pixel point in the preprocessed surface image according to the preprocessed surface image, wherein the method comprises the following steps:
(2-1-1) constructing a sliding window according to the preprocessed surface image, and enabling the sliding window to slide on the preprocessed surface image, so that a sliding window area of each pixel point in the preprocessed surface image is obtained.
In the embodiment, a sliding window is constructed according to the preprocessed surface image of the oil way copper sleeve of the automobile engine to be detected, and the size of the sliding window is n
n, sliding the sliding window on the preprocessed surface image to obtain each corresponding sliding area when the sliding window slides, and taking each pixel point as a central pixelAnd taking the sliding area of the point as the sliding window area of each pixel point in the preprocessed surface image.
(2-1-2) determining a relevant area of each pixel point according to the sliding window area of each pixel point in the preprocessed surface image.
In this embodiment, according to the sliding window region of each pixel point in the preprocessed surface image, the sliding window region that does not include each pixel point itself is used as the relevant region of each pixel point, that is, the sliding window region that does not include the center pixel point is used as the relevant region of the center pixel point.
It should be noted that, in the present embodiment, the central pixel point is not considered to reduce interference caused by calculation of the relevant area when the central pixel point is a noise point, which effectively improves accuracy of subsequently determined abnormal degree index values of each pixel point.
(2-2) determining an abnormal degree index value of each pixel point according to the gray value of each pixel point in the relevant area of each pixel point, wherein the calculation formula is as follows:
wherein,
the index value of the abnormal degree of each pixel point,
for the first in the relevant area of each pixel
jThe gray value of each pixel point is calculated,
for the mean value of the gray levels of the individual pixels in the relevant area of each pixel,
the number of pixel points in the relevant area for each pixel point.
It should be noted that, if the grayscale fluctuation of each pixel point in the relevant region of a certain pixel point is larger, that is, the grayscale variance of each pixel point in the relevant region of a certain pixel point is larger, the abnormal degree index value of the pixel point is larger, and then the pixel point is more likely to be the pixel point in the defect region caused by the crack.
(3) And obtaining the gray gradient amplitude of each pixel point in the preprocessed surface image, and determining the probability that each pixel point is a defect edge pixel point according to the abnormal degree index value and the gray gradient amplitude of each pixel point and the adjacent pixel points in the preprocessed surface image.
Firstly, it should be noted that the distinguishing features of the defect region caused by the crack and the pseudo-defect region caused by the illumination further include the gray gradient change of the edge pixel points, in order to amplify the difference between the defect caused by the crack and the pseudo-defect caused by the illumination, the embodiment further analyzes the relationship between the gray gradient of each pixel point in the surface image of the oil path copper sleeve of the automobile engine and the gray gradient of the pixel points in the neighborhood thereof, thereby determining the probability that each pixel point is the defect edge pixel point, and the steps include:
and (3-1) obtaining the gray gradient amplitude of each pixel point in the surface image of the oil way copper sleeve of the preprocessed automobile engine.
In the embodiment, the sobel operator is used for calculating each pixel point in the surface image of the preprocessed copper sleeve of the oil way of the automobile engine
Direction and
a gradient of gray scale in the direction, i.e.
And
then the gray scale gradient amplitude of each pixel point is
And finally, obtaining the gray gradient amplitude corresponding to the gray gradient of each pixel point in the surface image of the pretreated automobile engine oil way copper sleeve. The sobel operator is prior art and is not within the scope of the present invention, and will not be described in detail herein.
And (3-2) determining the probability that each pixel point is a defect edge pixel point according to the abnormal degree index value and the gray gradient amplitude of each pixel point and the neighborhood pixel points in the preprocessed surface image.
In this embodiment, the probability that each pixel point is a defect edge pixel point is determined by combining the abnormal degree index value and the gray gradient amplitude value of each pixel point and the neighborhood pixel points in the surface image of the pretreated automobile engine oil path copper bush determined in the step (2-2) and the step (3-1), and the calculation formula is as follows:
wherein,
for the probability that each pixel is a defect edge pixel,
for the index value of the degree of abnormality of each pixel point,
for the gray scale gradient magnitude of each pixel point,
the abnormal degree index value of the k-th neighborhood pixel point of each pixel point,
for the gray scale gradient amplitude of the k-th neighborhood pixel of each pixel,
in order to be a super-parameter,
,
is a hyperbolic tangent function.
It should be noted that, for a certain pixel point in the preprocessed surface image of the oil-way copper sleeve of the automobile engine to be detected, if the gray gradient amplitude of the pixel point is larger, the abnormal degree is higher, and the difference between the pixel point and the pixel point in the neighborhood is more obvious, the probability that the pixel point is a defect edge pixel point is higher.
(4) And determining each defect edge pixel point in the preprocessed surface image according to the probability that each pixel point is a defect edge pixel point.
In this embodiment, according to the probability that each pixel in step (3) is a defect edge pixel, each pixel in the surface image of the to-be-detected automobile engine oil way copper sleeve after the pretreatment is screened, and each pixel after the screening is labeled, and the pixel after the labeling is used as a defect edge pixel, the screening step includes:
if the probability P that a certain pixel point in the preprocessed surface image of the automobile engine oil way copper sleeve to be detected is a defect edge pixel point is not smaller than the preset defect probability value, the pixel point is the defect edge pixel point, the preset defect probability value is set to be 0.7 in the embodiment, and if the probability P that a certain pixel point in the preprocessed surface image of the automobile engine oil way copper sleeve to be detected is the defect edge pixel point is smaller than the preset defect probability value, the pixel point is not the defect edge pixel point.
It should be noted that if the probability that a certain pixel point in the preprocessed surface image of the oil-way copper sleeve of the automobile engine to be detected is a defect edge pixel point is higher, the more likely the pixel point is the defect edge pixel point.
(5) And determining each defect edge connected domain in the preprocessed surface image according to each defect edge pixel point in the preprocessed surface image and the probability that the defect edge pixel point is the defect edge pixel point, and further determining each defect area in the preprocessed surface image.
(5-1) determining each defect edge connected domain in the preprocessed surface image according to each defect edge pixel point in the preprocessed surface image and the probability that the defect edge pixel point is the defect edge pixel point, wherein the method comprises the following steps:
and judging whether the current surface image has defect edge pixel points of the undetermined defect edge connected domain, if so, determining the positions of the growing seed points in the current surface image according to the probability that each defect edge pixel point in the undetermined defect edge connected domain corresponds to the defect edge pixel point. Judging whether defect edge pixel points exist in a preset neighborhood corresponding to the growth seed point, if so, merging the growth seed point and the defect edge pixel points in the preset neighborhood into a defect edge communication domain, further judging whether defect edge pixel points exist in the preset neighborhood corresponding to each defect edge pixel point in the defect edge communication domain, and continuously repeating the steps until no defect edge pixel points exist in the preset neighborhood corresponding to the defect edge pixel points.
In this embodiment, the step of determining each defect edge connected domain in the surface image of the oil-way copper sleeve of the pre-processed automobile engine to be detected comprises:
(5-1-1) firstly, judging whether defect edge pixel points of a defect edge communicating region which is not determined exist in a surface image of an oil way copper sleeve of an automobile engine to be detected after current pretreatment, if the defect edge pixel points of the defect edge communicating region which is not determined exist in the current surface image, selecting the defect edge pixel point with the maximum P as a growth seed point, and when a plurality of defect edge pixel points with the maximum P exist in the surface image, randomly selecting any one of the defect edge pixel points as the growth seed point, wherein P is the probability that each pixel point is a defect edge pixel point.
(5-1-2) then, searching in the preset neighborhood range of the growing seed point, setting the preset neighborhood range of the implementation as eight neighborhoods, detecting whether defect edge pixel points exist in the eight neighborhoods of the growing seed point, if so, reserving the defect edge pixel points in the eight neighborhoods of the growing seed point, combining the reserved defect edge pixel points and the growing seed point into a defect edge communication domain, taking each defect edge pixel point in the defect edge communication domain as a new growing seed point, searching again in the eight neighborhoods of each new growing seed point, detecting whether defect edge pixel points exist in the eight neighborhoods of each new growing seed point, if so, reserving the defect edge pixel points in the eight neighborhoods of each new growing seed point, and combining the reserved defect edge pixel points and each new growing seed point into a defect edge pixel point And (4) continuously repeating the steps until defect edge pixel points do not exist in the eight neighborhoods of the growing seed points, and obtaining one defect edge connected domain of the current surface image at the moment.
(5-1-3) after obtaining one of the defect edge connected domains of the current surface image, judging whether defect edge pixels of the undetermined defect edge connected domain exist in the surface image of the to-be-detected automobile engine oil way copper sleeve after current pretreatment, if defect edge pixels of the undetermined defect edge connected domain still exist in the current surface image, repeating the steps (5-1-1) to (5-1-3), and continuously iterating the steps until defect edge pixel points of the undetermined defect edge connected domain do not exist in the surface image of the to-be-detected automobile engine oil way copper sleeve after current pretreatment.
Therefore, the defect edge communication domain in the surface image of the oil way copper sleeve of the automobile engine to be detected after pretreatment is obtained.
And (5-2) determining each defect area in the preprocessed surface image according to each defect edge connected domain in the preprocessed surface image.
Firstly, it should be noted that, since each defect edge connected domain in the step (5-1) may not be a complete defect region, each defect edge connected domain needs to be clustered to obtain each defect region, so that the accuracy of the subsequently determined evaluation value of the defect degree of the oil-way copper sleeve of the automobile engine to be detected is improved, and the accuracy of the defect detection result of the oil-way copper sleeve of the automobile engine is enhanced.
In this embodiment, according to each defect edge connected domain in the preprocessed surface image of the oil copper sleeve of the automobile engine to be detected, and based on the euclidean distance between each defect edge connected domain, each defect edge connected domain is clustered by using a K-M clustering algorithm, and the minimum external matrix of each defect edge connected domain of the same type is used as a defect region in the preprocessed surface image, that is, each defect region includes a plurality of defect edge connected domains of the same type. The K-M clustering algorithm is prior art and is not within the scope of the present invention, and will not be described in detail herein.
(6) Determining the defect degree evaluation value of the automobile engine oil way copper sleeve to be detected according to the area and the number corresponding to each defect region in the preprocessed surface image of the automobile engine oil way copper sleeve to be detected, wherein the calculation formula is as follows:
wherein,
the defect degree evaluation value of the copper sleeve of the oil way of the automobile engine to be detected,
for the second in the surface image of the pretreated automobile engine oil way copper sleeve to be detected
xThe area of each defect area, n is the number of the defect areas in the surface image of the oil way copper sleeve of the automobile engine to be detected after pretreatment,
the total area of the surface image of the pre-processed automobile engine oil way copper sleeve to be detected is obtained.
It should be noted that the larger the area of each defect region in the surface image of the to-be-detected automobile engine oil way copper bush is, the larger the number of each defect region is, the larger the defect degree evaluation value of the to-be-detected automobile engine oil way copper bush is, that is, the worse the quality of the to-be-detected automobile engine oil way copper bush is.
The implementer can carry out quality classification according to the actual detection condition of the automobile engine oil circuit copper bush to be detected, for example:
if the defect degree evaluation value H of the automobile engine oil way copper sleeve to be detected is smaller than or equal to the first defect degree evaluation threshold, the quality of the automobile engine oil way copper sleeve to be detected is good, if the defect degree evaluation value H of the automobile engine oil way copper sleeve to be detected is larger than the first defect degree evaluation threshold and smaller than the second defect degree evaluation threshold, the quality of the automobile engine oil way copper sleeve to be detected is general, and if the defect degree evaluation value H of the automobile engine oil way copper sleeve to be detected is larger than the second defect degree evaluation threshold, the quality of the automobile engine oil way copper sleeve to be detected is poor.
The invention mainly aims to reduce the influence of false defects caused by illumination on the defect detection of the oil-way copper sleeve of the automobile engine to be detected and eliminate interference factors in the defect detection process of the oil-way copper sleeve of the automobile engine as much as possible, thereby effectively improving the accuracy and the detection efficiency of the defect detection of the oil-way copper sleeve of the automobile engine.
It should be noted that: the precedence order of the above embodiments of the present invention is only for description, and does not represent the merits of the embodiments. And specific embodiments thereof have been described above. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.