Background
Industrial production tends to be more and more automated and intelligent; for the defect detection of products, if manual detection is adopted, the efficiency is low, the detection omission is easy, and the labor cost is greatly increased, so that the machine detection is basically adopted in the industry to replace the manual detection. In the industry, for surface detection of cylindrical products, a plurality of line cameras with large lenses are generally adopted, a rotating device is used for enabling the cylindrical products to rotate at a constant speed, and the surface images obtained by scanning are synthesized to obtain complete surface images of the cylindrical products, so that the requirement of surface defect detection can be met. However, the adoption of a plurality of linear cameras with large lenses leads to expensive equipment and large occupied plant space due to large volume; complex image synthesis algorithms result in the need for sophisticated processors; both line cameras and sophisticated processors can significantly increase inspection costs.
Disclosure of Invention
In order to solve the above problems, an embodiment of the present invention provides a method for detecting a surface of a cylinder based on a CIS, which can effectively reduce the cost of detecting defects of a cylinder product.
The technical scheme adopted by the invention for solving the problems is as follows:
in a first aspect of the present invention, a CIS-based cylinder surface detection method is provided, including the following steps:
enabling a CIS sensor to acquire a simulation image of the rotating cylinder;
converting the analog image into a digital image;
performing compensation processing on each pixel of the digital image;
performing characteristic analysis and defect detection on the digital image subjected to compensation processing;
wherein the performing compensation processing on each pixel of the digital image comprises:
measuring a base value of the CIS sensor with and without exposure, the base value including an arithmetic mean Va of each pixel of the exposurenThe arithmetic maximum value Vamax per pixel of the exposurenArithmetic mean value Vb of each pixel not exposednAnd the arithmetic maximum value Vbmax of each pixel not exposedn;
According to Gn=(Vamaxn-Vbmaxn)/(Van-Vbn) And OFFSETn=Vamaxn-(Vamaxn-Vbmaxn)/(Van-Vbn)*VanThe gain G of each pixel is calculatednAnd OFFSET OFFSETn;
According to yn=Gn*xn+OFFSETnFor each pixel x of the digital imagenPixel y after compensationn。
Further, the acquiring of the analog image by the CIS sensor to the rotating cylinder is specifically as follows:
adjusting the distance between the CIS sensor and the cylinder;
adjusting the illumination effect on the cylinder and the exposure degree of the CIS sensor;
rotating the cylinder and enabling the CIS sensor to collect analog images of the side surface of the cylinder until the analog images of one circle of the side surface of the cylinder are collected;
the CIS sensor is caused to acquire analog images of the upper and lower surfaces of the cylinder.
Specifically, in the step of adjusting the distance between the CIS sensor and the cylinder, the distance between the CIS sensor and the cylinder is between 1mm and 15 mm.
Further, the performing feature analysis and defect detection on the compensated digital image comprises:
extracting features of the digital image subjected to compensation processing by adopting an HOG algorithm;
classifying the extracted features by adopting an SVM classifier;
and comparing the classified features with the image features of the non-defective cylinder and judging whether defects exist or not.
Further, the CIS sensor includes a photosensitive element, a lens array, and a light source.
In a second aspect of the invention, a CIS-based cylinder surface detection device is provided, comprising a control processor and a memory for communicative connection with the control processor; the memory stores instructions executable by the control processor to enable the control processor to perform a CIS-based cylinder surface detection method according to a first aspect of the present invention.
In a third aspect of the present invention, there is provided a computer-readable storage medium storing computer-executable instructions for causing a computer to perform a CIS-based cylinder surface detection method according to the first aspect of the present invention.
The technical scheme at least has the following beneficial effects: the CIS sensor is used for scanning and imaging the surface of the cylinder, so that the imaging effect is good, the image is free of distortion, and the reduction degree is high; the imaging device of the CIS sensor is low in price and small in size; the image acquired by the CIS sensor is compensated, so that the distortion problem of the image is solved, the image has higher definition and restoration degree, and the subsequent feature analysis and defect detection of the image are more accurate.
Detailed Description
Reference will now be made in detail to the present preferred embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to like elements throughout.
In the description of the present invention, unless otherwise explicitly limited, terms such as arrangement, installation, connection and the like should be understood in a broad sense, and those skilled in the art can reasonably determine the specific meanings of the above terms in the present invention in combination with the specific contents of the technical solutions.
Referring to fig. 1, an embodiment of the present invention provides a CIS-based cylinder surface detection method, including the following steps:
s100, enabling the CIS sensor to acquire a simulation image of the rotating cylinder;
s200, converting the analog image into a digital image;
s300, performing compensation processing on each pixel of the digital image;
s400, performing characteristic analysis and defect detection on the digital image subjected to compensation processing;
referring to fig. 3, step S300 specifically includes:
s310, measuring basic values of the CIS sensor under the conditions of exposure and non-exposure, wherein the basic values comprise the arithmetic mean value Va of each pixel of exposurenThe arithmetic maximum value Vamax per pixel of the exposurenArithmetic mean value Vb of each pixel not exposednAnd the arithmetic maximum value Vbmax of each pixel not exposedn;
S320, according to Gn=(Vamaxn-Vbmaxn)/(Van-Vbn) And OFFSETn=Vamaxn-(Vamaxn-Vbmaxn)/(Van-Vbn)*VanThe gain G of each pixel is calculatednAnd OFFSET OFFSETn;
S330, according to yn=Gn*xn+OFFSETnFor each pixel x of the digital imagenPixel y after compensationn。
In this embodiment, the cis (contact Image sensor) sensor is a sensor generally called a contact Image sensor, and is commonly used in scanners, in which the photosensitive elements 1 are closely arranged and directly collect information of light reflected by a scanned document.
Referring to fig. 5, in particular, the CIS sensor includes a photosensitive element 1, a lens array 2, and a light source 3. When the CIS is operated, light emitted from the light source 3 is directly incident on the surface of the cylinder, and light reflected from the surface of the cylinder is focused by the lens array 2, imaged on the photosensitive element 1, and converted into electric charges to be stored. The light intensities at different positions are different, so that the light intensities received by the pixel units of the photosensitive element 1 at different positions are different. The illumination time, namely the charge accumulation time of each pixel unit is consistent in each reading period, after the charge accumulation time is reached, the analog switches are controlled by the shift register to be sequentially opened, and the electric signals of the pixel units are sequentially output in the form of analog signals, so that the analog image signals of the surface of the cylinder are obtained. Further, the photosensitive element 1 is a MOS device; the light source 3 is in particular an LED light source.
The CIS sensor has a simple structure, so that a scanning surface can be made into a large area; therefore, the CIS sensor is scanned for one circle opposite to the outer side surface of the cylinder, and the collection of the simulation image of the outer side surface of the cylinder can be completed. The CIS sensor sweeps over the upper and lower surfaces of the cylinder to obtain simulated images of the upper and lower surfaces of the cylinder. Meanwhile, the ratio of the simulated image to the actual image obtained by scanning is 1:1, the phenomenon of image distortion is avoided, and the color reality and the image resolution are excellent.
However, in the CIS sensor, in the process of converting an optical signal into an electrical signal, the capacitance is largeErrors are liable to occur, and therefore, compensation processing for an image is required. An analog image obtained by the CIS sensor is subjected to filter preprocessing and then converted into a digital image via an analog-to-digital converter. And inputting the digital image into the FPGA for compensation processing. Gain G according to each pixelnAnd OFFSET OFFSETnThe compensation process is performed for each pixel of the digital image. Finally formed by yn=Gn*xn+OFFSETnFor each pixel x of the digital imagenPixel y after compensationn. In this embodiment, step S300 is implemented in an FPGA, which is model number EP1C3T144C 8N. Of course in other embodiments, the FPGA may take on other models.
In the process of measuring the basic value of the CIS sensor under the conditions of exposure and non-exposure, the arithmetic mean value Va of each pixel of the exposure is measurednThe arithmetic maximum value Vamax per pixel of the exposurenThe method comprises the following steps:
setting the exposure of the CIS sensor, and enabling the CIS sensor to scan pure white paper in a static mode, and ensuring that image pixels are between 240 and 250; obtaining the arithmetic average value Va of each pixel exposed in the time TnAnd the arithmetic average value Vamax of each pixel of the exposuren;
Measuring the arithmetic mean Vb of each pixel not exposednAnd the arithmetic mean value Vbmax of each pixel not exposednThe method comprises the following steps:
closing the exposure effect of the CIS sensor, and enabling the CIS sensor to scan pure white paper in a static mode again, and meanwhile ensuring that image pixels are between 240 and 250; obtaining an arithmetic average value Vb of each pixel which is not exposed in the time TnAnd the arithmetic maximum value Vbmax of each pixel not exposedn。
The digital image obtained after compensation processing overcomes the defects of insufficient definition and partial distortion of the analog image directly obtained by the original CIS sensor, facilitates subsequent feature extraction, and improves the accuracy of defect detection.
Referring to fig. 2, further, the step S100 specifically includes:
s110, adjusting the distance between the CIS sensor and the cylinder;
s120, adjusting the illumination effect on the cylinder and the exposure degree of the CIS sensor;
s130, rotating the cylinder and enabling the CIS sensor to collect the simulation image of the side surface of the cylinder until the simulation image of the circumference of the side surface of the cylinder is collected;
and S140, enabling the CIS sensor to collect simulation images of the upper surface and the lower surface of the cylinder.
Specifically, the distance between the CIS sensor and the cylinder is adjusted to be 1-15 mm, and the CIS sensor is in contact type, so that the distance between the CIS sensor and the cylinder needs to be very close to each other. And the light source 3 of the CID sensor is adjusted to adjust the illumination effect of the cylinder and the exposure degree of the CIS sensor, so that the image overexposure is avoided, and the image definition is prevented from being influenced. The cylindrical product to be measured is placed on the rotating platform, and the rotating motor is connected with the rotating platform and drives the rotating platform to rotate at a constant speed. The CIS sensor collects the analog images of the side surface of the cylinder until the analog images of the circumference of the side surface of the cylinder are collected. In addition, the upper surface and the lower surface of the cylinder are respectively swept by the CIS sensor, so that simulated images of all surfaces of the cylinder can be obtained, and the defect detection of the whole cylinder is facilitated.
Referring to fig. 4, further, the step S400 includes:
s410, extracting features of the digital image subjected to compensation processing by adopting an HOG algorithm;
s420, classifying the extracted features by adopting an SVM classifier;
and S430, comparing the classified features with the image features of the defect-free cylinder and judging whether defects exist or not.
In this embodiment, the Chinese language of the HOG (histogram of Oriented gradient) algorithm is all called the direction gradient histogram algorithm. It constructs features by calculating and counting the histogram of gradient direction of local area of image.
The specific steps of the HOG algorithm are as follows:
graying the digital image subjected to the compensation processing;
normalizing the grayed digital image by a Gamma correction method;
calculating a gradient for each pixel of the normalized digital image;
dividing the digital image into unit areas and counting a gradient histogram of each unit area to obtain the characteristics of the unit areas;
and combining the unit areas into square areas and further obtaining an overall digital image, wherein the characteristics of the square areas are obtained by serially connecting the characteristics of the unit areas, and the characteristics of all the square areas in the digital image are serially connected to obtain the image characteristics of the digital image subjected to compensation processing.
In other embodiments, the HOG algorithm may be replaced by other algorithms commonly used for image feature extraction, such as SIFT algorithm, SURF algorithm, LBP algorithm, and the like.
The SVM classifier is a generalized linear classifier for binary classification of data in a supervised learning mode, and a decision boundary of the SVM classifier is a maximum edge distance hyperplane for solving learning samples. The SVM classifier calculates empirical risks by using a hinge loss function and adds a regularization term in a solution system to optimize structural risks, and the SVM classifier is a classifier with sparsity and robustness. The SVM classifier classifies the extracted image features of the compensated digital image. In other embodiments, the SVM classifier may be replaced by other algorithms commonly used for feature classification, such as Bayesian algorithms, KNN algorithms, and the like.
Finally, comparing the classified characteristics of the cylinder to be detected with the image characteristics of the cylinder without defects, judging whether the defects exist or not, and outputting a judgment result; and automatic cylinder surface detection is realized.
In this embodiment, the FPGA is connected to the DSP. The digital image after FPGA compensation processing enters a DSP; step S400 is processed in a DSP, specifically, the model of the DSP is TMS320F 2810. Of course in other embodiments, the DSP may take other forms.
In another embodiment of the invention, a CIS-based cylinder surface detection device is provided, comprising a control processor and a memory for communicative connection with the control processor; the memory stores instructions executable by the control processor to enable the control processor to perform a CIS-based cylinder surface sensing method as described above. Specifically, the control processor adopts a PLC controller.
In another embodiment of the present invention, there is provided a computer-readable storage medium storing computer-executable instructions for causing a computer to perform a CIS-based cylinder surface detection method as described above.
The above description is only a preferred embodiment of the present invention, and the present invention is not limited to the above embodiment, and the present invention shall fall within the protection scope of the present invention as long as the technical effects of the present invention are achieved by the same means.