Summary of the invention
The purpose of the present invention is overcoming the above-mentioned deficiency of existing method, a kind of workpiece, defect based on machine vision is proposed
Detection method, this method may be implemented to greatly improve workpiece configurations defect and surface defect measurement accuracy.For this purpose, of the invention
It adopts the following technical scheme that:
Step 1: the image of flange plate type workpiece in acquisition reality;
Step 2: camera being demarcated using Zhang Shi standardization, the parameter and pose of camera are obtained, according to calibration result
Obtain the calibrated error of measuring system;
Step 3: image filtering being carried out to workpiece image, extracts area-of-interest;
Step 4: the detection of workpiece pixel edge is completed using Canny operator first, then using based on Gray Moment
The sub-pixel edge of method extraction workpiece image;
Step 5: the mass center of concentric holes and via hole on workpiece being obtained using the method for circle fitting, according to the think of of least square method
Think, the edge for approaching workpiece outer profile and each via hole is gone to circle;
Step 6: using the defect inspection method based on edge pixel distance, the sub-pix calculated in workpiece actual profile is sat
Distance of the punctuate to fitting circle radial direction;
Step 7: surface defect being split using the PixelNet convolutional neural networks based on pixel stratified sampling, is obtained
To scratch and corrosion region.
Compared with prior art, the beneficial effects of the present invention are:
For the low problem of workpiece configurations defect and surface defects detection difficulty and detection efficiency, the invention proposes be based on
The defect inspection method of machine vision detects the appearance defect of workpiece by Edge Distance method, in conjunction with pixel stratified sampling
PixelNet convolutional neural networks are split detection to Surface Flaw.
Compared to traditional detection method, the present invention has many advantages, such as that non-contact, precision is high, adaptability is good, by worker from numerous
It is freed in superfluous detection work, greatly improves detection efficiency.The present invention is directed to workpiece outer profile damaged area shape
The problem of its segmentation is with identification is influenced with size, the appearance defect detection method based on edge of work distance is proposed, to difference
The workpiece of damaged degree has carried out test experience, and the recognition accuracy of outer profile breakage workpiece demonstrates the algorithm up to 100%
Validity.In addition, aiming at the problem that workpiece surface texture complex effects workpiece surface scratch and corrosion are divided, using based on pixel
The PixelNet convolutional neural networks of stratified sampling are split surface defect, the experimental results showed that the method for the present invention can be right
Surface Flaw is effectively divided, the average friendship of segmentation result and ratio is up to 92.3%, therefore, method proposed by the invention
It may be implemented to workpiece scratch, corrosion, effective detection of outer profile breakage workpiece, and detection accuracy is high.
Specific embodiment
The embodiment of the present invention is described in further detail with reference to the accompanying drawing.
Overall framework flow diagram of the invention is as shown in Figure 1.Firstly, acquisition flange disk workpiece image, using
Family name's standardization demarcates camera, and then carries out distortion correction to workpiece image;Then it uses using Gaussian filter to figure
As being smoothed, convolution operation is carried out using 5 × 5 Gaussian kernels that standard deviation is 1, extracts area-of-interest;It is respectively adopted
Canny algorithm, Sobel algorithm, Roberts algorithm and Prewitt algorithm carry out pixel edge detection to image, more various
Algorithm detection as a result, the best Canny algorithm of selective extraction effect;Using the Sub-pixel Edge Detection based on Gray Moment
Extract the sub-pixel edge of workpiece image;Finally, the mass center of concentric holes and via hole above workpiece is obtained using the method for circle fitting,
According to the thought of least square method, the edge for approaching workpiece outer profile and each hole is gone to circle;Workpiece is calculated by Edge Distance
Appearance defect;Surface defect is split using the PixelNet convolutional neural networks based on pixel stratified sampling, is obtained
The corrosion of workpiece surface and scratch.
1. experimental subjects
Visual field size of the invention is 120mm × 90mm, and selected industrial camera resolution ratio is 1280 × 960, can be calculated
The corresponding actual physics distance of each pixel is about 0.09375mm.It is tested using flange plate type workpiece, workpiece configurations are damaged
Degree arc length size μ as corresponding to damage location is indicated, tests μ≤1mm respectively, tri- kinds of 2mm and μ >=2mm of μ < of 1mm <
The workpiece of different size, Surface Flaw include corrosion and scratch.
2. pixel edge detects
Canny algorithm, Sobel algorithm, Roberts algorithm, Prewitt algorithm is respectively adopted, Pixel-level side is carried out to image
Edge detection.Though by Sobel and Roberts edge detection algorithm it can be seen from the extraction result of four kinds of edge detection operators in Fig. 3
The edge of workpiece single pixel can be so obtained, but sweep is poor, there are jagged edges, are unfavorable for the accurate of sub-pixel edge
It extracts.For Prewitt operator edge extracting result there are false edge, detection effect is poor.Canny edge detection algorithm is to workpiece
Edge extracting is more accurate, while edge-smoothing degree is higher, and the present invention need to measure workpiece size, to edge positioning
Required precision is higher, therefore the present invention selects Canny algorithm to the edge extracting of workpiece progress Pixel-level.The visual field size of system
For 120mm × 90mm, selected industrial camera resolution ratio is 1280 × 960, can calculate the corresponding actual physics of each pixel away from
From about 0.09375mm.There may be the error of 1 pixel between two o'clock in actual measurement, since target of the present invention is examined
It surveys precision and is less than 0.1mm, pixel edge is affected to detection accuracy, is unable to satisfy high-precision measurement request.
3. sub-pixel edge extracts
The pixel edge known to 2 is affected to workpiece sensing precision, is unable to satisfy the measurement request of this system.Guarantee
In the case that visual field is constant, improving measurement accuracy most straightforward approach can be used the industrial camera of higher resolution to reduce pixel
Equivalent, but data volume can be made to increase simultaneously, it is unfavorable for real-time detection.And sub-pixel edge detection can reach 1/n pixel, be equivalent to
Measurement accuracy is improved n times.The measurement demand of higher precision can be completed in the case where guaranteeing camera and the constant visual field.Therefore
The present invention uses Canny algorithm to complete the detection of workpiece pixel edge first, is then examined again using the edge based on Gray Moment
Survey method.Workpiece is detected based on the sub-pixel edge of Gray Moment, sub-pixel edge extracts result as shown in figure 4, using ash
When spending moments method extraction workpiece subpixel coordinates, arithmetic accuracy is higher, while sub-pixel edge is smooth, is more suitable for workpiece Asia picture
The positioning at plain edge.
4. the defect inspection method based on Edge Distance
The common appearance defect of workpiece is caused mainly due to the incompleteness of edge of work part, on the image show as workpiece
Actual edge profile and fitting circle between there are the deviations of certain distance.As shown in figure 5, wherein red edge is the reality of workpiece
Border profile, yellow edge are the workpiece profile that fitting obtains.If the collection of sub-pix point is combined into A in workpiece actual profilei(Xi, Yi),
I ∈ (1,2,3 ... N), it is known that the center of circle of workpiece fitting circle is O (m, n), by center of circle O (m, n) and AiDetermining linear equation can table
It is shown as:Abbreviation obtains: (Xi-m)y+(n-Yi)x-nXi+mYi=0, if the radius of workpiece fitting circle is R,Two coordinate points are calculated, wherein with point AiIt is apart from the smallest point
Coordinate points in fitting circle, are denoted as Bi(Pi, Qi).Then sub-pix point A in workpiece actual edgeiAlong fitting circle radial direction to quasi-
Close the distance d of profileiIt can pass throughIt finds out.Workpiece is at intact unbroken position, actual wheel
Sub-pix point A on exterior featureiWith the radial direction distance d of fitting circleiMuch smaller than the distance of workpiece breakage position.Distance threshold τ is set,
Work as diThe sub-pix point A in workpiece actual profile at this time is recorded when > τiThat is workpiece breakage position, thus according to threshold tau is met
Coordinate points AiNumber { 0, n } can determine that whether current workpiece is damaged workpiece.
In practical application, it is contemplated that sub-pix point number more (N > 2000) influences the operation speed of algorithm on workpiece profile
Degree, the present invention is to sub-pix point set AiIt is sampled in 360 ° relative to workpiece mass center, i.e., by Ai360 parts of equal parts are carried out,
A coordinate points ξ is taken out at random in per sub-pix space of points ξ oncei,Constitute new work
Part contour pixel point set A 'j, thenThen pass through the pixel collection A ' after samplingjInto
Row diCalculating, compared to directly by former ensemble space AiIt is calculated, operation times are greatly decreased, while sub-pix point set A 'j
Largely remain former set AiFeature, that is, workpiece profile information, and the differentiation of workpiece breakage situation not will cause
It influences, Fig. 6 is the partial enlarged view of workpiece breakage position, A 'jFor the coordinate set after workpiece profile sub-pix point sampling, BiFor
Coordinate set in fitting circle corresponding with damage location sub-pix point.Green line segment is then distance of the damage location to fitting circle
di.For the robustness for verifying the algorithm, the present invention carries out test experience to the workpiece under different damaged degree, to 100 differences
The workpiece of damaged degree is detected, and the recognition accuracy of algorithm is 100% under different damaged degree.
5. the PixelNet convolutional neural networks based on pixel stratified sampling are split surface defect
The present invention is acquired 3000 altogether by vision system and tested with scratch with the flange workpiece for corroding defect.It adopts
Region of interesting extraction is carried out to workpiece with traditional image partition method, by workpiece and background separation.By PS software with hand
The mode of work mark completes the mark to scratch on workpiece and corrosion.Meanwhile in order to which facilitating for supervised learning training will be on workpiece
Scratch be indicated from corrosion with different characteristic values, so that mark figure is converted to index map, the wherein color mark of background
Be denoted as (0,0,0), characteristic value 0, the color mark of scratch is (255,0,0), characteristic value 1, the color mark of corrosion be (0,
0,255), characteristic value 2.
Select 2400 pictures as training set from data set, 300 collect as verifying, and 300 are used as test set pair
PixelNet network is trained and tests.The training of parted pattern of the present invention uses depth under 7 operating system of Windows
The Matlab development interface of learning framework Caffe.In hardware environment, processor is Intel Xeon E5-2625, and video card is
NVIDIA GTX1080Ti, video memory size are 11G.Training process is using 24 figures as an iteration step-length, wherein initial learning rate
It is set as 0.01, as the increase of exercise wheel number finally decays to 0.0001, the number of iterations is 100,000 times.Standard in training process
True rate variation is with penalty values variation as shown in Fig. 7 (a) and Fig. 7 (b).Segmentation result such as Fig. 8 and Fig. 9 institute to corrosion with scratch
Show.By Fig. 7 (a) and Fig. 7 (b), the defect based on PixelNet convolutional neural networks that the present invention uses can be intuitively seen
Dividing method can complete the accurate segmentation to Surface Flaw.It can accomplish have simultaneously for the different scratch of depth degree
Effect is extracted, algorithm robustness with higher.Further to evaluate the method for the present invention to the segmentation performance of workpiece, defect, the present invention
The standard evaluation index MIoU of selection semantic segmentation evaluates test result.The model generated using training is on test set
It is tested, acquiring MIoU is 93.2%, accuracy rate with higher, can satisfy industry to the detection demand of workpiece, defect.
By judging that the Pixel Information of workpiece segmentation result can determine that workpieces are other, i.e. output result contains red pixel
Can be identified as have the workpiece of scratch defects, containing blue pixel then for exist corrosion workpiece.Theoretically qualified workpiece
Output result there was only black pixel value, but the case where will appear erroneous segmentation in practical cutting procedure, so that qualified work
Part can also have less red or blue pixel value.Setting area threshold alpha is then determined as defect work when dividing defect and being greater than α
Otherwise part is qualified workpiece, α value of the present invention is 10 pixels.According to actually detected requirement, the value of α can be finely tuned.
Workpiece, defect detection method proposed by the present invention based on machine vision, achievable shape different damaged degree and table
The workpiece sensing of face existing defects, while differentiating that accuracy height, strong robustness can meet the needs of industrial detection.
The foregoing is merely of the invention preferably to apply example, is not intended to limit the scope of the present invention, it should be understood that this
Invention is not limited to existing scheme as described herein, and the purpose of these implementations description is to help those skilled in the art
The member practice present invention.Any those of skill in the art are easy to carry out without departing from the spirit and scope of the present invention
Further improve and perfect, therefore the present invention is only limited by the content and range of the claims in the present invention, is intended to contain
Covering all includes alternative and equivalent program in the spirit and scope of the invention being defined by the appended claims.