CN-121999290-A - Automatic detection method for appearance defects of plastic tray based on machine vision
Abstract
The invention relates to the technical field of machine vision and image processing, and discloses an automatic detection method for appearance defects of a plastic tray based on machine vision. The method comprises the steps of collecting a tray surface image in real time in a plastic tray conveying process, constructing a gray image matrix, filtering under different smooth scales to obtain a smooth image, generating local binary codes by using a neighborhood comparison center and neighborhood gray scales in a fixed direction, establishing a square window at a position far away from a boundary, summing squares of the codes to obtain a local texture energy map, calculating difference values according to pixels and counting average values and standard deviations among the energy maps in different scales to construct a global threshold, screening defect areas according to eight neighborhood regions and areas after binary segmentation of the difference map, marking the pixels of the defect areas, outputting geometric positions and statistical information, thereby weakening the influence of tray movement and illumination change, taking noise suppression and texture retention into account, reducing sensitivity of traditional edge and fixed threshold methods, and realizing automatic defect detection and quantification.
Inventors
- LI ZHIJUN
Assignees
- 江苏一仟亿环保科技有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260128
Claims (9)
- 1. The automatic detection method for the appearance defects of the plastic tray based on machine vision is characterized by comprising the following steps of: collecting images of the upper surface of the tray in the plastic tray conveying process, and constructing a gray image matrix according to the row index and the column index; Performing two-dimensional smoothing filtering on the gray image matrix under at least two different smoothing scales to obtain a smooth image corresponding to each smoothing scale; in each smooth image, establishing a neighborhood sampling structure with fixed direction distribution for each pixel, and generating a local binary coded image formed by a plurality of binary bits according to the comparison result of the gray level of the neighborhood pixel and the gray level of the central pixel; Under each smooth scale, selecting pixels at positions far from the boundaries of the smooth images as centers to establish square local windows, reading local binary coding values in each square local window, and performing square summation to obtain corresponding local texture energy so as to form a corresponding local texture energy image; calculating energy difference for each pixel position among the smooth scale local texture energy images to obtain a scale energy difference response map, and obtaining an average value and a standard deviation of the scale energy difference; Constructing a global threshold based on the average value and the standard deviation of the scale energy difference, executing threshold segmentation on the scale energy difference response graph, and generating a binary response graph of suspected defect response; in the binary response chart, extracting a connected region according to an eight-neighborhood connected rule, and screening according to an area condition to obtain a defect connected region; marking corresponding pixels in the defect connected region, obtaining geometric position parameters of the defect connected region, constructing a defect result image, and deriving statistical information of the defect connected region to the defect connected region.
- 2. The automatic detection method for appearance defects of plastic trays based on machine vision according to claim 1, wherein the steps of collecting images of the upper surface of the tray during the plastic tray conveying process and constructing a gray image matrix according to row indexes and column indexes comprise: Establishing a two-dimensional rectangular coordinate system on a tray detection image plane, setting a coordinate origin at the pixel position at the upper left corner of the image, enabling the horizontal axis direction to be consistent with the increasing direction of the image column index, enabling the vertical axis direction to be consistent with the increasing direction of the image row index, and setting the total line number and the total column number of the tray detection image to be not less than 7; a shooting device vertically oriented to the surface of the tray is arranged at the top of a production line for conveying plastic trays, a frame of complete image is captured when each tray passes through a shooting area, the captured frame image is organized into an original image matrix according to row indexes and column indexes, and gray scale values or color values of each pixel position are recorded; When the original image is a color image, the gray values of the red channel, the green channel and the blue channel of each pixel are subjected to equal weight arithmetic average operation to generate corresponding gray values to form a gray image matrix, and when the original image is a single-channel gray image, the numerical value of each pixel in the original image matrix is directly used as the gray value to form the gray image matrix.
- 3. The automatic detection method of appearance defects of a plastic tray based on machine vision according to claim 2, wherein the performing two-dimensional smoothing filtering on the gray image matrix under at least two different smoothing scales to obtain a smoothed image corresponding to each smoothing scale specifically comprises: selecting a first smooth scale and a second smooth scale on the gray image matrix, wherein the size of the first smooth scale is set to be 1 pixel, and the size of the second smooth scale is set to be 2 pixels; For each smooth scale, constructing a Gaussian smooth template according to the values of a two-dimensional Gaussian function in the row direction and the column direction, and reserving template coefficients in a range that the absolute values of the row offset and the column offset are not more than three times that of each smooth scale to form the Gaussian smooth template with a limited size; Establishing a mirror image mapping rule for a row index of the gray image matrix, symmetrically reflecting according to the first row index when the row index is smaller than the first row index, maintaining the original row index when the row index is between the first row index and the last row index, and symmetrically reflecting according to the last row index when the row index is larger than the last row index; and under each smooth scale, acquiring a pixel gray value in a convolution window according to a mirror image mapping rule, performing item-by-item multiplication on template coefficients of all positions in a Gaussian smooth template and gray values of corresponding positions, summing in the convolution window, and performing two-dimensional discrete convolution operation pixel by pixel on the whole gray image matrix to respectively obtain a smooth image under a first smooth scale and a smooth image under a second smooth scale.
- 4. The automatic detection method of plastic tray appearance defects based on machine vision according to claim 3, wherein in each smooth image, a neighborhood sampling structure with fixed directional distribution is established for each pixel, and a local binary coded image composed of a plurality of binary bits is generated according to the comparison result of the neighborhood pixel gray level and the center pixel gray level, specifically comprising: In each smooth image, establishing a circular neighborhood with the center of the current pixel for each pixel, and dividing the circular neighborhood into eight sampling directions with equal angular intervals along the horizontal direction, the vertical direction and two diagonal directions; Setting the neighborhood sampling radius to be twice of each smooth scale for each smooth scale, calculating the row index and the column index of the neighborhood sampling point in each sampling direction according to the neighborhood sampling radius and the sampling direction angle, and taking the nearest integer as the neighborhood sampling point position for the calculated row index and column index; when the line index or the column index of the neighborhood sampling point exceeds the effective range of the smooth image, acquiring the pixel gray value symmetrical to the line index of the neighborhood sampling point in the smooth image according to the mirror image mapping rule; For each central pixel, respectively comparing the gray values of the neighborhood sampling points with the gray values of the central pixel in eight preset sampling directions, recording binary values 1 in the corresponding direction positions when the gray values of the neighborhood sampling points are larger than or equal to the gray values of the central pixel, and recording binary values 0 in the corresponding direction positions when the gray values of the neighborhood sampling points are smaller than the gray values of the central pixel; According to a fixed direction sequence, binary values recorded in eight sampling directions are sequentially arranged from the lowest bit to the highest bit, a local binary code consisting of eight binary bits is generated, the generated local binary code is endowed to a corresponding center pixel position, and a local binary code image is formed under a first smooth scale and a second smooth scale respectively.
- 5. The automatic detection method of appearance defect of plastic tray based on machine vision according to claim 4, wherein under each smooth scale, selecting pixels at positions far from the border of the smooth image as the center to establish square local windows, reading local binary code values in each square local window and performing square summation to obtain corresponding local texture energy, and forming a corresponding local texture energy image, specifically comprising: Setting the side length of a square local window as 7 pixels, and taking the pixels with row indexes larger than or equal to 4 and smaller than or equal to 3 of the total row number of the local binary coded image and the pixels with column indexes larger than or equal to 4 and smaller than or equal to 3 of the total column number of the local binary coded image in the local binary coded image under the corresponding smooth scale as effective central pixels for local texture energy calculation; For each effective central pixel, a square local window with side length of 7 pixels and geometric center at the central pixel position is established in the local binary coded image, and the square local window covers row and column pixel indexes within a distance range of 3 pixels around the central pixel; and in each square local window, reading local binary coding values of all pixel positions in the window, carrying out square operation on each local binary coding value, summing in the window, taking the summation result as local texture energy of the central pixel position under the current smooth scale, and respectively forming local texture energy images under the first smooth scale and the second smooth scale.
- 6. The automatic detection method of appearance defects of a plastic tray based on machine vision according to claim 5, wherein the calculating energy differences for each pixel position between the smooth-scale local texture energy images to obtain a scale energy difference response map, and obtaining an average value and a standard deviation of the scale energy differences specifically comprises: For an effective center pixel, calculating the absolute value of the difference value of the local texture energy of two scales at the same pixel position in a local texture energy image of a first smooth scale and a second smooth scale, and forming a scale energy difference response graph in the pixel position range of a gray image matrix; Counting the difference response values of all effective pixel positions in the scale energy difference response map, and calculating the arithmetic average value of the difference response values to obtain the average value of scale energy differences in the pixel position range of the gray image matrix; And subtracting the average value of the scale energy difference from the difference response value of each pixel position in the effective pixel range of the scale energy difference response graph to obtain a difference response deviation value, calculating the arithmetic average value of the squares of all the difference response deviation values, and then squaring to obtain the standard deviation of the scale energy difference, and simultaneously, reserving the average value of the scale energy difference and the standard deviation of the scale energy difference as statistical features constructed by the subsequent threshold.
- 7. The automatic detection method of plastic tray appearance defects based on machine vision according to claim 6, wherein the constructing a global threshold based on the average value and standard deviation of the scale energy difference, performing threshold segmentation on the scale energy difference response map, and generating a binary response map of suspected defect response, comprises: the average value of the scale energy difference and the standard deviation of the scale energy difference obtained by the scale energy difference response calculation are utilized to carry out addition operation on the two statistical features, so that the global threshold value adopted by the binarization processing of the scale energy difference response graph is obtained; Comparing the difference response value of each effective pixel position with a global threshold value aiming at each effective pixel position in the scale energy difference response graph, writing a pixel value 1 in a position corresponding to the binary response graph when the difference response value is larger than or equal to the global threshold value, and writing a pixel value 0 in a position corresponding to the binary response graph when the difference response value is smaller than the global threshold value; and finishing binary response map generation in the pixel position range of the gray image matrix.
- 8. The automatic detection method for appearance defects of a plastic tray based on machine vision according to claim 7, wherein in the binary response chart, the connected regions are extracted according to eight-neighborhood connected rules, and the defect connected regions are obtained by screening according to area conditions, specifically comprising: In the binary response graph, all pixel positions with pixel values of 1 are formed into a foreground pixel index set, and each element in the foreground pixel index set corresponds to a suspected defect response pixel; In the foreground pixel index set, defining adjacent pixel relation according to eight neighborhood communication rule, and defining two pixels as eight adjacent pixels when the absolute value of index difference of the two pixels in the row direction or the column direction is not more than 1 and is not 0 at the same time; In the foreground pixel index set, dividing the foreground pixels into a plurality of mutually non-overlapping communication areas according to the reachable path relation between eight adjacent pixels, distributing unique area numbers to each communication area, and classifying the foreground pixels belonging to the same communication area into corresponding area numbers; And counting the number of foreground pixels contained in each connected region, taking the number of foreground pixels in the connected region as the pixel area of the connected region, setting the minimum area threshold of the defective connected region as 10 pixels, marking the connected region as a defective connected region when the pixel area of the connected region is greater than or equal to 10 pixels, and marking the connected region as a non-defective connected region when the pixel area of the connected region is less than 10 pixels.
- 9. The automatic detection method of appearance defects of a plastic tray based on machine vision according to claim 8, wherein the marking of the corresponding pixels in the defect connected areas, obtaining geometric position parameters of the defect connected areas, constructing a defect result image, and deriving statistical information of the defect connected areas to the defect connected areas, comprises: establishing a pixel position corresponding relation between a gray image matrix and a defect connected region which is divided by a connected relation of a binary response graph and obtained by screening according to an area threshold value, writing a preset high gray value 255 into a position corresponding to a defect result image for the pixel position belonging to the defect connected region, and writing a gray value into a position corresponding to the defect result image in the gray image matrix for the pixel position not belonging to the defect connected region to generate a defect result image; Traversing all pixel positions in each defect communication area aiming at each defect communication area, acquiring a minimum row index value and a maximum row index value in a pixel row index, acquiring a minimum column index value and a maximum column index value in a pixel column index, combining the minimum row index and the minimum column index into a pixel coordinate of the left upper corner of the minimum circumscribed rectangle, and combining the maximum row index and the maximum column index into a pixel coordinate of the right lower corner of the minimum circumscribed rectangle; For each defect communication area, the area number, the pixel area, the pixel coordinates of the upper left corner of the minimum bounding rectangle and the pixel coordinates of the lower right corner of the minimum bounding rectangle are derived and output together with the defect result image.
Description
Automatic detection method for appearance defects of plastic tray based on machine vision Technical Field The invention relates to the technical field of machine vision and image processing, in particular to an automatic detection method for appearance defects of a plastic tray based on machine vision. Background At present, plastic trays are used in a large number in the scenes of logistics, storage and the like, and the surfaces of the plastic trays are easy to generate tiny appearance defects such as cracks, scratches, falling blocks, indentations and the like in the long-term turnover process. The existing production line still generally adopts a manual visual detection mode, relies on experience of operators to judge, has the problems of low detection efficiency, high omission rate caused by fatigue, inconsistent judgment standards among different people and the like, and is difficult to adapt to the consistency quality requirements of high-speed production lines and mass products. With the development of machine vision technology, some manufacturers introduce automatic detection systems based on two-dimensional images. The conventional scheme mainly adopts the processing flows of fixed threshold segmentation, global contrast enhancement, edge detection, morphological filtering and the like to extract and threshold judgment on the gray level change of the surface of the plastic tray. However, the overall texture of the surface of the plastic tray is usually flat, the defect gray scale contrast is low, the scale is various, and uneven illumination, surface stains and injection molding textures can introduce large-area gray scale fluctuation. Under the background, the algorithm based on a single gray threshold or a simple gradient response is difficult to distinguish normal slight texture fluctuation from real cracks or scratches, and false detection and omission are easy to generate. Part of methods try to judge by adopting single-scale texture features (such as local binary pattern LBP, gray level co-occurrence matrix and the like), but generally count texture distribution on a single scale, multi-scale comparison cannot be performed specially for a scene with 'whole smoothness but local tiny structure damage', and stable response to cracks and tiny scratches with different sizes and directions is difficult to maintain. In another class of techniques, existing schemes introduce machine-learning or deep-learning based classification and segmentation models that perform end-to-end training through large scale labeling samples to automatically learn defect features. Although the method can obtain better effects in partial scenes, the method has the problems of high acquisition and labeling cost of training samples, complex model structure, high consumption of reasoning calculation resources and engineering realization that retraining or parameter adjustment is required when the field environment is changed (such as camera position, background material and pallet batch change), and has high application threshold for high-speed pipeline scenes of plastic pallets with high beat requirements and limited deployment environment. In addition, the internal features of the deep learning model are difficult to directly relate to the field process indexes, the interpretability of the defect response is weak, and the quality engineering personnel are not beneficial to adjusting the process or judging rules according to the response features. Therefore, the scheme aims to provide an automatic detection method for appearance defects of the plastic tray based on machine vision, and the tiny gray level change of the surface of the tray is quantized by combining multi-scale image smooth filtering with local binary texture analysis, so that the defect areas can be rapidly and accurately positioned and marked under the condition of no complex manual parameter adjustment. The method comprises the steps of firstly collecting tray images on a pipeline in real time, converting color images into gray image matrixes, then generating multi-scale smooth images through selecting two Gaussian filters with different smooth scales, guaranteeing that noise can be restrained and fine texture information can be reserved, generating local binary codes based on gray level comparison between central pixels and neighborhood pixels in each scale image, performing square summation on coded values in each fixed direction to obtain local texture energy, constructing a global threshold value through cross-scale energy difference calculation, generating a binary response image, finally extracting and screening connected areas through eight neighborhood connected rules, marking defect connected blocks, and outputting defect result images and statistical information. Disclosure of Invention The invention provides an automatic detection method for appearance defects of a plastic tray based on machine vision, which facilitates solving the problems ment