Based on arcuation face, the polishing metal flaw real-time detection method of machine vision
Technical field
The present invention relates to a kind of detection method, especially a kind of arcuation face, polishing metal flaw real-time detection method based on machine vision, belong to the technical field that arcuation face, polishing metal is detected.
Background technology
In the industrial production, along with improving constantly of industrial technology level, also improve the quality requirements of product, tradition mainly depends on artificial visually examine to the monitoring of workpiece quality thereupon.Due to the impact of the subjective factor of examinate person, be easy to occur flase drop and the situation such as undetected, and artificial visually examine also efficient low, accuracy rate is low and standardization degree inadequate, profile and the state of mind of testing result and supervisory personnel are closely related, stability and Reliability comparotive poor, in addition, detection Data classification can not be sent into computing machine in real time and carry out automatic quality control.The difficult problem that artificial visually examine's workload is large, efficiency is low in order to solve, loss is high, enterprise is badly in need of introducing a kind of Automatic Measurement Technique, with alternative manual operation, can realize again the strict control to product quality while reducing human cost.So, introduce the application of machine vision in workpiece quality monitoring.Replace traditional human eye to monitor product quality by machine vision, improve the quality of production efficiency and product.
At present, many scholars are also had both at home and abroad in the Defect Detection of research polishing arcuation metal surface, this kind of columniform metal works of such as bearing outside surface.Also there is following problem in the detection of this type of workpiece: (1), because the reflectivity of polishing arcuation surface of the work is high, the reflection angle of the reflected light that camera receives is different, so be difficult to obtain uniform illumination, and the image that breadth is wide; (2) the gradation of image skewness collected, effective coverage is narrow.During as adopted axis light as light source, effective coverage is narrow, detects a bearing need at least 60 images through experimental analysis.For solving the problem of uneven illumination, extraction background image can be adopted, then according to background image, image is strengthened, obtaining the image of uniform gray level.But when workpiece has large defect time, the extraction of background image will there will be error.
Summary of the invention
The object of the invention is to overcome the deficiencies in the prior art, provide a kind of arcuation face, polishing metal flaw real-time detection method based on machine vision, it is easy to operate, and accuracy of detection is high, detects adaptability good, reliable and stable.
According to technical scheme provided by the invention, a kind of arcuation face, polishing metal flaw real-time detection method based on machine vision, arcuation face, described polishing metal flaw real-time detection method comprises the steps:
Under step 1, off-line case, obtain first sample image of N opening and closing lattice workpiece under normal work illumination and M opening and closing lattice workpiece low light according under the second sample image, the first sample image is opened to N and carries out medium filtering respectively and obtain image sequence I
n, n=1,2 ..., N, opens the second sample image to M and carries out medium filtering acquisition image sequence I respectively
m, m=1,2 ..., M, to image sequence I
n, image sequence I
mimage g (x, y), h (x, y) is obtained after carrying out data fusion respectively;
Step 2, statistics fused image g (x, y), h (x, y) corresponding gray-scale value and number of pixels corresponding to gray-scale value in, obtain image g (x respectively, y), h (x, y) histogram, the linear relation that the gray-scale value corresponding according to the corresponding larger crest value of histogram is set up between image background I (x, the y) gray-scale value corresponding with crest value larger in histogram is
I(x,y)=a(x,y)*(Z
max-Z
h)+h(x,y)
Wherein, Z
maxrepresent the gray-scale value that in histogram, larger crest value is corresponding, a (x, y) is slope matrix;
Step 3, from above-mentioned first sample image, the second sample image an all optional sample image, and set up the histogram of selected first sample image, the second sample image, obtain the gray-scale value that larger crest value in selected first sample image, the second sample image histogram is corresponding, according to the linear relation of described gray-scale value and step 2, obtain the reflecting component of selected first sample image, the second sample image respectively;
Step 4, obtain the reflecting component of selected first sample image, the second sample image according to step 3, the corresponding relation formula set up between the qualified workpiece reflecting component standard deviation gray-scale value corresponding with crest value larger in histogram is
Wherein, σ (Z
max) represent the reflecting component standard deviation of qualified workpiece, Z
max_nrepresent the gray-scale value that in selected first sample image histogram, maximum crest value is corresponding, Z
max_0represent the gray-scale value that in selected second sample image histogram, maximum crest value is corresponding, σ
nfor the standard deviation of selected first sample image, σ
0for the standard deviation of selected second sample image;
Step 5, the detected image of online arcuation face, Real-time Obtaining polishing metal workpiece under work illumination, carry out medium filtering to described detected image, set up the histogram of detected image; The gray-scale value corresponding according to crest value larger in histogram and above-mentioned steps obtain the reflecting component of detected image; Gaussian filtering is carried out to the reflecting component obtaining detected image, obtains the second reflecting component, and calculate the second standard deviation of the second reflecting component, and calculate first standard deviation of detected image at the qualified workpiece image of corresponding grey scale level according to step 4;
Step 6, compare the first standard deviation and the second standard deviation, to choose segmentation threshold, by segmentation threshold, Threshold segmentation is carried out to the second reflecting component, obtain corresponding bianry image;
Step 7, scan above-mentioned bianry image, and mark connected region different in bianry image, statistics connected region area, compares connected region area with default judgment threshold, judges the flaw in arcuation face, polishing metal.
Described step 1 comprises the steps:
Step 1.1, in off-line case, gathers first sample image of N opening and closing lattice workpiece under work illumination, is then reduced to required intensity of illumination, gathers second sample image of M opening and closing lattice workpiece under Low light intensity;
Step 1.2, the first sample image, the second sample image are carried out to medium filtering and obtain image sequence I respectively
n, I
m; Wherein, n=1,2 ..., N, m=1,2 ... M;
Step 1.3, basis
by image sequence I
ncarry out data fusion, wherein, (x, y) represents the location of pixels in image sequence;
Step 1.4, basis
by image sequence I
mcarry out data fusion.
Described step 2 comprises the steps:
Step 2.1, gradation of image get 0 ~ 255, statistical picture g (x, y) number of pixels of corresponding grey scale value, then divided by image g (x, y) total number of pixels, obtain histogram p (z) of image g (x, y), and obtain the gray-scale value Z reaching larger crest value
g;
Step 2.2, according to step 2.1, obtain histogram q (z) of image h (x, y), and obtain the gray-scale value Z reaching larger peak value
h;
Step 2.3, set up the linear gradient matrix between larger crest value corresponding grey scale value in image background I (x, y) and histogram, obtain
Step 2.4, the linear relationship obtaining in image background I (x, y) and histogram between larger crest value according to step 2.3, for
I(x,y)=a(x,y)*(Z
max-Z
h)+h(x,y),
Wherein, Z
maxrepresent the gray-scale value that in histogram, larger crest value is corresponding.
Described step 3 comprises the steps:
Step 3.1, open the first sample image from above-mentioned N, M opens an all optional sample image the second sample image, the pixel count of corresponding grey scale value in selected first sample image of statistics, the second sample image, to set up the histogram of selected first sample image, the second sample image, obtain the gray-scale value that larger crest value in selected first sample image, the second sample image histogram is corresponding;
Step 3.2, according to step 2 and gray-scale value corresponding to larger crest value, obtain selected first sample image, background component I (x, y) that the second sample image is corresponding respectively;
Step 3.3, basis
ask for the reflecting component of selected first sample image, the second sample image, wherein, k is constant, and f (x, y) is selected first sample image or the second sample image.
Described step 4 comprises the steps:
The average μ of the reflecting component of step 4.1, selected first sample image of calculating, obtains
Wherein, n*m represents the size of reflecting component image;
Step 4.2, calculate the standard deviation sigma of selected first sample image reflecting component according to step 4.1
n, obtain
Step 4.3, calculate the standard deviation sigma of selected second sample image reflecting component according to step 4.1, step 4.2
0;
Step 4.4, set up the gray-scale value Z of larger crest value in qualified workpiece reflecting component standard deviation and histogram
maxcorresponding relation formula, obtains,
Wherein, σ (Z
max) represent the reflecting component standard deviation of qualified workpiece, Z
max_nrepresent the gray-scale value that in selected first sample image histogram, maximum crest value is corresponding, Z
max_0represent the gray-scale value that in selected second sample image histogram, maximum crest value is corresponding.
Described step 5 comprises the steps:
Step 5.1, under work illumination condition, gather workpiece sensing image t (x, y), and medium filtering is carried out to detected image t (x, y);
Step 5.2, set up medium filtering after, the histogram of detected image, according to the histogram of detected image, obtains the gray-scale value Z that larger crest value in histogram is corresponding
t;
Step 5.3, according to gray-scale value Z
tand step 2, obtain the background component I of detected image
t(x, y);
Step 5.4, according to step 5.3 and step 3, obtain the reflecting component r of detected image
t(x, y);
Step 5.5, to reflecting component r
t(x, y) carries out gaussian filtering, generates the second reflecting component R (x, y);
Step 5.6, according to gray-scale value Z
tand step 4.4 obtains the first standard deviation sigma (Z of detected image
t);
Step 5.7, calculate second standard deviation sigma of the second reflecting component R (x, y) according to step 4.1 and step 4.2
t.
Described step 6 comprises the steps:
Step 6.1, compare the first standard deviation sigma (Z
t) and the second standard deviation sigma
trelation, obtain
Step 6.2, setting segmentation upper threshold value T
1, lower threshold value T
2, obtain
Wherein, λ is adjustment factor;
Step 6.3, utilize upper threshold value T
1, lower threshold value T
2threshold segmentation is carried out to the second background component R (x, y), obtains bianry image b (x, y), obtain
Wherein, 0 is background area, and 1 is pending region.
Described step 7 comprises the steps:
Step 7.1, scanning bianry image b (x, y), and the different connected regions in bianry image b (x, y) are marked;
In step 7.2, respectively statistics bianry image b (x, y), the area of different connected region, arranges required judgment threshold S; When the interior connected region area of bianry image b (x, y) is greater than judgment threshold S, then corresponding connected region is defect areas; When in bianry image b (x, y), connected region area is less than judgment threshold S, then corresponding connected region is normal region.
In described step 5.5, the convolution mask of gaussian filtering is
Described adjustment factor λ is 3 ~ 4.
Advantage of the present invention: the first Luminance Distribution situation of study analysis measured workpiece under this duty under off-line state, and the statistical nature of qualified workpiece; Then, during on-line checkingi, effectively can extract the reflecting component of measured workpiece, and by the operation such as filtering, Threshold segmentation, workpiece is carried out in real time, Defect Detection accurately, easy to operate, accuracy of detection is high, detects adaptability good, reliable and stable.
Accompanying drawing explanation
Fig. 1 is that the present invention is for gathering the structural representation of image.
Fig. 2 is process flow diagram of the present invention.
Description of reference numerals: 100-industrial camera, 110-bracing frame, 120-measured workpiece, 130-diffusing plane light, 140-base and 150-hanger bracket.
Embodiment
Below in conjunction with concrete drawings and Examples, the invention will be further described.
The object of the invention is real-time detection arcuation face, polishing metal being carried out to flaw, due to arcuation face, polishing metal smooth surface, diffuse reflectance is low, and surface becomes arcuation, the light intensity that the face of different spatial is radiated differs, so be difficult to the image obtaining wide cut brightness uniformity.According to this problem, propose and a kind ofly detect arcuation face, polishing metal in real time based on off-line learning knowledge and the method for on-line real-time measuremen flaw can be carried out.
As shown in Figure 1, when gathering image, the present invention includes base 140, described base 140 is provided with the bracing frame 110 of vertically distribution, can support metal arcuation face by bracing frame 110; Base 140 is also provided with hanger bracket 150, industrial camera 100 can be hung by hanger bracket 150; Be provided with diffusing plane light 130 directly over bracing frame 110, irradiate tested metal arcuation face by diffusing plane light 130, so that required image can be gathered by industrial camera 100.Adopt X-Sight SV4-30m industrial camera 100 to gather cylindrical workpiece arcuation side surface image in the embodiment of the present invention, industrial camera 100 sampling unit is 1/3 inch of CMOS, and resolution is 640*480(pixel).Because the reflectivity on arcuation surface, polishing metal is high, detection faces is not on a space plane, and the mode of employing direct irradiation, coaxial illumination all can only obtain very narrow effective coverage.The mode that have employed blue diffusing plane LED light source and tested surface vertical irradiation is thrown light on; Because wavelength is shorter, the scattering on surface is better, so have selected the blue-light source of wavelength at 470nm.
As shown in Figure 2: the present invention comprises the steps: arcuation face, polishing metal flaw real-time detection method
Under step 1, off-line case, obtain first sample image of N opening and closing lattice workpiece under normal work illumination and M opening and closing lattice workpiece low light according under the second sample image, the first sample image is opened to N and carries out medium filtering respectively and obtain image sequence I
n, n=1,2 ..., N, opens the second sample image to M and carries out medium filtering acquisition image sequence I respectively
m, m=1,2 ..., M, to image sequence I
n, image sequence I
mimage g (x, y), h (x, y) is obtained after carrying out data fusion respectively;
Off-line case refers to the image first being gathered qualified workpiece by industrial camera, by obtaining required conclusion to mass data analysis, for on-line checkingi, the effect one of sample image is analysis background component, as foundation during on-line checkingi extraction reflecting component; Two is extract feature, uses when Threshold segmentation, decision-making as during detection.Obtain that N opens the first sample image, to open the second sample image be to carry out data fusion to sample image to M, thus obtain more reliable background component, wherein N can equal M.The scope of low light photograph preferably at average gray in value about 20, the chances are about 40 for the average gray value of normal illumination.
Step 1 comprises following concrete steps:
Step 1.1, in off-line case, gathers first sample image of N opening and closing lattice workpiece under work illumination, is then reduced to required intensity of illumination, gathers second sample image of M opening and closing lattice workpiece under Low light intensity;
Step 1.2, the first sample image, the second sample image are carried out to medium filtering and obtain image sequence I respectively
n, I
m; Wherein, n=1,2 ..., N, m=1,2 ... M;
During medium filtering, the gray-scale value of each pixel is set to the intermediate value of all pixel gray-scale values in this some neighborhood window, default window adopts the neighborhood window of 25*25, sample image size according to gathering can adjust accordingly, medium filtering is conventional filtering mode, known by the art personnel, no longer describe in detail herein;
Step 1.3, basis
by image sequence I
ncarry out data fusion, wherein, (x, y) represents the location of pixels in image sequence;
Step 1.4, basis
by image sequence I
mcarry out data fusion.
Step 2, statistics fused image g (x, y), h (x, y) corresponding gray-scale value and number of pixels corresponding to gray-scale value in, obtain image g (x respectively, y), h (x, y) histogram, the linear relation that the gray-scale value corresponding according to the corresponding larger crest value of histogram is set up between image background I (x, the y) gray-scale value corresponding with crest value larger in histogram is
I(x,y)=a(x,y)*(Z
max-Z
h)+h(x,y)
Wherein, Z
maxrepresent the gray-scale value that in histogram, larger crest value is corresponding, a (x, y) is slope matrix;
Described step 2 comprises the steps:
Step 2.1, gradation of image get 0 ~ 255, statistical picture g (x, y) number of pixels of corresponding grey scale value, then divided by image g (x, y) total number of pixels, obtain histogram p (z) of image g (x, y), and obtain the gray-scale value Z reaching larger crest value
g;
Setting up histogram is the technological means that the art is commonly used, and histogrammic horizontal ordinate is image intensity value, and ordinate is the number of pixels of certain gray-scale value and the ratio of the total number of phases number of image, no longer describes in detail herein; Z is image intensity value;
Step 2.2, according to step 2.1, obtain histogram q (z) of image h (x, y), and obtain the gray-scale value Z reaching larger peak value
h;
Step 2.3, set up the linear gradient matrix between larger crest value corresponding grey scale value in image background I (x, y) and histogram, obtain
Step 2.4, the linear relationship obtaining in image background I (x, y) and histogram between larger crest value according to step 2.3, for
I(x,y)=a(x,y)*(Z
max-Z
h)+h(x,y),
Wherein, Z
maxrepresent the gray-scale value that in histogram, larger crest value is corresponding.
Step 3, from above-mentioned first sample image, the second sample image an all optional sample image, and set up the histogram of selected first sample image, the second sample image, obtain the gray-scale value that larger crest value in selected first sample image, the second sample image histogram is corresponding, according to the linear relation of described gray-scale value and step 2, obtain the reflecting component of selected first sample image, the second sample image respectively;
Described step 3 comprises the steps:
Step 3.1, open the first sample image from above-mentioned N, M opens an all optional sample image the second sample image, the pixel count of corresponding grey scale value in selected first sample image of statistics, the second sample image, to set up the histogram of selected first sample image, the second sample image, obtain the gray-scale value that larger crest value in selected first sample image, the second sample image histogram is corresponding;
Step 3.2, according to step 2 and gray-scale value corresponding to larger crest value, obtain selected first sample image, background component I (x, y) that the second sample image is corresponding respectively;
Step 3.3, basis
ask for the reflecting component of selected first sample image, the second sample image, wherein, k is constant, and f (x, y) is selected first sample image or the second sample image; K is the constant depending on reflecting component, and in order to make the average of reflecting component about 0.5, general k gets 0.5.
Step 4, obtain the reflecting component of selected first sample image, the second sample image according to step 3, the corresponding relation formula set up between the qualified workpiece reflecting component standard deviation gray-scale value corresponding with crest value larger in histogram is
Wherein, σ (Z
max) represent the reflecting component standard deviation of qualified workpiece, Z
max_nrepresent the gray-scale value that in selected first sample image histogram, maximum crest value is corresponding, Z
max_0represent the gray-scale value that in selected second sample image histogram, maximum crest value is corresponding, σ
nfor the standard deviation of selected first sample image, σ
0for the standard deviation of selected second sample image;
Described step 4 comprises the steps:
The average μ of the reflecting component of step 4.1, selected first sample image of calculating, obtains
Wherein, n*m represents the size of reflecting component image;
Step 4.2, calculate the standard deviation sigma of selected first sample image reflecting component according to step 4.1
n, obtain
Step 4.3, calculate the standard deviation sigma of selected second sample image reflecting component according to step 4.1, step 4.2
0;
Step 4.4, set up the gray-scale value Z of larger crest value in qualified workpiece reflecting component standard deviation and histogram
maxcorresponding relation formula, obtains,
Wherein, σ (Z
max) represent the reflecting component standard deviation of qualified workpiece, Z
max_nrepresent the gray-scale value that in selected first sample image histogram, maximum crest value is corresponding, Z
max_0represent the gray-scale value that in selected second sample image histogram, maximum crest value is corresponding.
Step 5, the detected image of online arcuation face, Real-time Obtaining polishing metal workpiece under work illumination, carry out medium filtering to described detected image, set up the histogram of detected image; The gray-scale value corresponding according to crest value larger in histogram and above-mentioned steps obtain the reflecting component of detected image; Gaussian filtering is carried out to the reflecting component obtaining detected image, obtains the second reflecting component, and calculate the second standard deviation of the second reflecting component, and calculate first standard deviation of detected image at the qualified workpiece image of corresponding grey scale level according to step 4;
After on-line checkingi refers to and obtains detected image, judge whether metal arcuation face exists flaw by carrying out detection analysis to detected image; On-line checkingi needs the conclusion and the data that utilize offline inspection, when the technological means that on-line checkingi uses is consistent with offline inspection, and can with reference to computing formula during above-mentioned offline inspection and method.
Described step 5 comprises the steps:
Step 5.1, under work illumination condition, gather workpiece sensing image t (x, y), and medium filtering is carried out to detected image t (x, y);
Step 5.2, set up medium filtering after, the histogram of detected image, according to the histogram of detected image, obtains the gray-scale value Z that larger crest value in histogram is corresponding
t;
Step 5.3, according to gray-scale value Z
tand step 2, obtain the background component I of detected image
t(x, y);
Step 5.4, according to step 5.3 and step 3, obtain the reflecting component r of detected image
t(x, y);
Step 5.5, to reflecting component r
t(x, y) carries out gaussian filtering denoising, generates the second reflecting component R (x, y), and wherein the convolution mask of gaussian filtering is
Step 5.6, according to gray-scale value Z
tand step 4.4 obtains the first standard deviation sigma (Z of detected image
t);
Step 5.7, calculate second standard deviation sigma of the second reflecting component R (x, y) according to step 4.1 and step 4.2
t.
Step 6, compare the first standard deviation and the second standard deviation, to choose segmentation threshold, by segmentation threshold, Threshold segmentation is carried out to the second reflecting component, obtain corresponding bianry image;
Described step 6 comprises the steps:
Step 6.1, compare the first standard deviation sigma (Z
t) and the second standard deviation sigma
trelation, obtain
Step 6.2, setting segmentation upper threshold value T
1, lower threshold value T
2, obtain
Wherein, λ is adjustment factor; Described adjustment factor λ is 3 ~ 4.
Step 6.3, utilize upper threshold value T
1, lower threshold value T
2threshold segmentation is carried out to the second background component R (x, y), obtains bianry image b (x, y), obtain
Wherein, 0 is background area, and 1 is pending region.
Step 7, scan above-mentioned bianry image, and mark connected region different in bianry image, statistics connected region area, compares connected region area with default judgment threshold, judges the flaw in arcuation face, polishing metal.
Described step 7 comprises the steps:
Step 7.1, scanning bianry image b (x, y), and the different connected regions in bianry image b (x, y) are marked;
Recursion method can be adopted in the embodiment of the present invention to carry out zone marker;
In step 7.2, respectively statistics bianry image b (x, y), the area of different connected region, arranges required judgment threshold S; When the interior connected region area of bianry image b (x, y) is greater than judgment threshold S, then corresponding connected region is defect areas; When in bianry image b (x, y), connected region area is less than judgment threshold S, then corresponding connected region is normal region.By judging whether the interior connected region of bianry image b (x, y) is that defect areas judges whether metal arcuation face exists flaw, due to the processing request of medal polish face and different industries, judgment threshold S can relative set.
The present invention is the Luminance Distribution situation of study analysis measured workpiece under this duty under off-line state first, and the statistical nature of qualified workpiece; Then, during on-line checkingi, effectively can extract the reflecting component of measured workpiece, and by the operation such as filtering, Threshold segmentation, workpiece is carried out in real time, Defect Detection accurately.