A computer vision-based real-time detection method and system for surface defects of injection molded parts
Patent Information
- Application Number
- CN202611307000.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-10-27
AI Technical Summary
通过采用沿垂直于横梁延伸方向的多条像素采样线提取灰度剖面,并基于一阶灰度变化特征和二阶灰度变化特征识别满足局部灰度下凹、两侧边缘斜率方向相反且凹陷宽度处于预设宽度范围的候选凹陷点,克服了传统单点灰度阈值或边缘检测难以区分真实熔接线与表面纹理干扰的技术问题,实现了熔接线缺陷候选区域的初步精准定位;通过沿横梁延伸方向对候选凹陷点进行连续性关联形成熔接线缺陷候选,并依据亮度特征、边缘锐度特征和方向特征对候选进行干扰筛选,剔除高光干扰和飞边干扰,克服了注塑件表面高光反射、飞边等干扰因素导致误检率高的技术问题,实现了真实熔接线缺陷与干扰因素的有效区分。
Smart Images

Figure CN122989696A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and in particular to a real-time detection method and system for surface defects of injection molded parts based on computer vision. Background Technology
[0002] In the injection molding production of automotive heat exchanger shells, the crossbeam (approximately 3mm wide) is a critical component ensuring structural strength. Due to the multi-gate process, when two streams of molten plastic converge at the center of the crossbeam, temperature decay easily leads to weld line defects on the surface. Visually, this defect is not an obvious break or hole, but rather appears as a small, linear indentation approximately 1-2mm wide with gently sloping edges. Because its grayscale value is extremely close to that of a normal shell surface, the contrast is very low, and it is often masked by the high-gloss reflections and burrs on the crossbeam surface, making it difficult for conventional algorithms to effectively extract its subtle edge slope anomaly. This defect reduces the local mechanical strength of the crossbeam, posing a potential threat to the support safety of the heat exchanger.
[0003] Currently, manual visual inspection is insufficient to meet the real-time inspection requirements of production line cycles. In recent years, machine vision technology has been gradually applied to this field and has achieved certain results. However, when dealing with such low-contrast, easily affected, and minute weld line defects, existing methods still have certain limitations in terms of accurate feature extraction and robustness against interference. Summary of the Invention
[0004] This invention provides a real-time detection method and system for surface defects of injection molded parts based on computer vision. By extracting grayscale profiles along the width direction of the crossbeam and performing first- and second-order grayscale change feature analysis, reliable detection of weak depressions in low-contrast weld line defects is achieved. Furthermore, by using three-dimensional interference screening based on brightness, edge sharpness, and directional features, interference from high-gloss reflection and burrs is effectively eliminated, thereby improving the real-time detection accuracy of weld line defects on the surface of injection molded parts.
[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows: Firstly, a real-time detection method for surface defects of injection molded parts based on computer vision, the method comprising: As the injection molded part moves along the production line, a surface image of the surface to be inspected, including the crossbeam, is acquired in real time; the surface image is positioned according to a preset positioning reference to determine the crossbeam detection area corresponding to the crossbeam. Preprocessing is performed on the beam detection area to obtain a reflection suppression image; In the reflection-suppressed image, grayscale value sequences are extracted from multiple pixel sampling lines perpendicular to the extension direction of the beam to obtain multiple grayscale profiles; wherein, the multiple pixel sampling lines are set at intervals along the extension direction of the beam. Baseline correction is performed on each grayscale profile to obtain the baseline-corrected profile; Based on the first-order and second-order gray-scale change characteristics of the baseline correction profile, candidate depression points that meet the requirements of local gray-scale depression, opposite slope directions of the two sides, and depression width within a preset width range are identified. Candidate depression points are continuously correlated along the extension direction of the crossbeam to obtain candidate weld line defects; Based on the brightness, edge sharpness, and orientation characteristics of the weld line defect candidates, interference screening is performed on the weld line defect candidates to obtain the retained weld line defect candidates. Extract defect features from the retained weld line defect candidates, and determine whether there are weld line defects on the beam surface based on the defect features; when a weld line defect is determined to exist, output the defect detection results in real time.
[0006] Secondly, a real-time surface defect detection system for injection molded parts based on computer vision includes: The acquisition module is used to acquire surface images of the surface to be inspected, including the crossbeam, in real time as the injection molded part moves with the production line; and to locate the surface image according to the preset positioning reference to determine the crossbeam detection area corresponding to the crossbeam. The processing module is used to preprocess the crossbeam detection area to obtain a reflection suppression image. In the reflection suppression image, gray value sequences are extracted from multiple pixel sampling lines perpendicular to the extension direction of the crossbeam to obtain multiple gray-scale profiles. The multiple pixel sampling lines are set at intervals along the extension direction of the crossbeam. The correction module is used to perform baseline correction on each grayscale profile to obtain a baseline correction profile. Based on the first-order grayscale change characteristics and second-order grayscale change characteristics of the baseline correction profile, candidate depression points that meet the requirements of local grayscale depression, opposite slope directions of the two sides, and depression width within a preset width range are identified. The filtering module is used to continuously correlate candidate depression points along the extension direction of the crossbeam to obtain candidate weld line defects; based on the brightness characteristics, edge sharpness characteristics and direction characteristics of the candidate weld line defects, interference filtering is performed on the candidate weld line defects to obtain the retained candidate weld line defects. The extraction module is used to extract defect features from the retained weld line defect candidates and determine whether there are weld line defects on the beam surface based on the defect features; when a weld line defect is determined to exist, the defect detection result is output in real time.
[0007] The above-described solution of the present invention has at least the following beneficial effects: By extracting grayscale profiles using multiple pixel sampling lines perpendicular to the beam's extension direction, and identifying candidate depression points that meet the criteria of local grayscale depression, opposite slope directions on both sides of the edge, and depression width within a preset range based on first-order and second-order grayscale change features, this overcomes the technical problem of traditional single-point grayscale thresholding or edge detection failing to distinguish between real weld lines and surface texture interference, achieving preliminary accurate localization of weld line defect candidate areas. Furthermore, by continuously associating candidate depression points along the beam's extension direction to form weld line defect candidates, and by filtering candidates based on brightness, edge sharpness, and direction features to eliminate high-gloss interference and flash interference, this overcomes the technical problem of high false detection rates caused by interference factors such as high-gloss reflection and flash on the injection molded part surface, effectively distinguishing between real weld line defects and interference factors. Attached Figure Description
[0008] Figure 1 This is a schematic flowchart of a real-time detection method for surface defects of injection molded parts based on computer vision, provided by an embodiment of the present invention.
[0009] Figure 2 This is a schematic diagram of a real-time detection system for surface defects of injection molded parts based on computer vision, provided by an embodiment of the present invention.
[0010] Figure 3 This is a schematic diagram of the process of filtering fusion line defect candidates based on the brightness characteristics, edge sharpness characteristics, and direction characteristics of the fusion line defect candidates to obtain the retained fusion line defect candidates, according to an embodiment of the present invention. Detailed Implementation
[0011] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0012] like Figure 1 and Figure 3 As shown, embodiments of the present invention propose a real-time detection method for surface defects of injection molded parts based on computer vision.
[0013] In this embodiment, step 1 involves acquiring a surface image of the surface to be inspected, including the crossbeam, in real time as the injection molded part moves along the production line; positioning the surface image according to a preset positioning reference to determine the crossbeam detection area corresponding to the crossbeam, specifically including: Step 11, set up the image acquisition environment, the specific operations are as follows.
[0014] An industrial camera and light source are installed at the inspection station of the injection molding production line. The industrial camera is fixed above the production line, with its lens pointing vertically downwards at the surface of the injection molding part to be inspected. The imaging plane of the camera covers the area where the beam is located. The light source is a ring-shaped light-emitting diode light source, which is coaxially installed around the camera lens to illuminate the surface to be inspected with uniform front light, reducing the difference in unidirectional high light reflection caused by the curvature of the beam surface.
[0015] The camera is connected to the image processing industrial computer via a gigabit Ethernet interface. The industrial computer is also connected to the encoder signal line of the production line. The encoder is a rotation angle sensor installed on the drive shaft of the production line conveyor belt, which is used to convert the displacement of the conveyor belt into pulse signals. Each pulse corresponds to a preset displacement increment of the conveyor belt.
[0016] When the injection molded part moves to the inspection station with the production line conveyor belt, the encoder sends a trigger pulse signal. After receiving the trigger pulse signal, the industrial control computer controls the camera to perform an exposure and acquire a surface image of the surface to be inspected, which includes the crossbeam. The surface image is a digital image obtained by the camera imaging sensor after photoelectric conversion of the light reflected from the product surface. The brightness value of each pixel in the image reflects the surface reflection intensity at the corresponding position of the pixel.
[0017] Step 12: Determine the preset positioning reference. The specific operation is as follows.
[0018] The preset positioning reference refers to the reference feature used in the surface image for spatial positioning of the beam detection area. In this embodiment, the positioning bosses symmetrically distributed on both sides of the beam are used as the preset positioning reference. The positioning bosses are two raised structures with clear geometric shapes that have been determined in the mold design stage on the injection molded part. They are symmetrically distributed on both sides of the beam and appear as two closed contour areas with obvious grayscale differences in the surface image. A closed contour refers to a closed curve in the image formed by continuous edge pixels, and the pixel area inside the contour has obvious grayscale differences from the outer background area.
[0019] The process involves acquiring a pre-stored positioning boss template image. This template image is a sub-image of the positioning boss area cropped from the surface image of a qualified injection molded part sample under the same lighting conditions and shooting distance. A sub-image refers to a portion of the image cropped from the entire image within a preset rectangular range. The positioning boss template image is then matched with the current surface image. Template matching involves sliding the template image pixel-by-pixel across the current surface image and calculating the similarity between the template image and the covered area in the current surface image at each sliding position. The position with the highest similarity is the matching position of the positioning boss.
[0020] The similarity calculation employs a normalized cross-correlation method. First, the average grayscale value of the template image is calculated: the grayscale values of all pixels in the template image are summed, and then divided by the total number of pixels in the template image; the quotient is the template's average grayscale value. For each pixel in the template image, the template's average grayscale value is subtracted from its grayscale value to obtain the template's mean-free pixel value. Next, the average grayscale value of the covered area in the current surface image is calculated: the grayscale values of all pixels in the covered area are summed, and then divided by the total number of pixels in the covered area; the quotient is the covered area's average grayscale value. For each pixel in the covered area, the covered area's average grayscale value is subtracted from its grayscale value to obtain the covered area's mean-free pixel value.
[0021] The numerator is calculated by multiplying the mean-calculated pixel value of the template at the corresponding position by the mean-calculated pixel value of the covered area, and summing the results. The corresponding position refers to two pixel locations in the template image and the covered area that are at the same row and column offsets. The first denominator is calculated by multiplying the mean-calculated pixel values of all pixels in the template image by themselves, summing the results, and taking the square root. The second denominator is calculated by multiplying the mean-calculated pixel values of all pixels in the covered area by themselves, summing the results, and taking the square root. The numerator is then divided by the product of the first and second denominators; the quotient is the normalized cross-correlation similarity value at that sliding position. A similarity value closer to 1 indicates a greater similarity between the template and the covered area.
[0022] Search for matching positions of the two positioning protrusions in the surface image. The matching position of the left positioning protrusion is the first positioning point, and the matching position of the right positioning protrusion is the second positioning point. Obtain the image coordinates of the first positioning point and the image coordinates of the second positioning point. The image coordinates refer to the position of the pixel in the surface image, which consists of two values: row number and column number. The row number indicates which row the pixel is in and the column number indicates which column the pixel is in.
[0023] Step 13: Determine the crossbeam detection area. The specific operation is as follows.
[0024] Based on the image coordinates of the first and second positioning points, the boundary of the beam detection area is calculated. The arithmetic mean of the column numbers of the first and second positioning points is taken, i.e., the sum of the two is divided by 2, to obtain the beam center column number. The beam center column number determines the center position of the beam along the width direction in the surface image.
[0025] Using the center column number of the beam as a reference, the left boundary column number of the beam detection area is obtained by shifting left by a first preset offset pixel number, and the right boundary column number of the beam detection area is obtained by shifting right by a second preset offset pixel number. The values of the first and second preset offset pixel numbers are determined based on the pixel width of the beam in the image. The pixel width of the beam in the image is the actual physical width of the beam divided by the physical size corresponding to a single pixel. The physical size corresponding to a single pixel is determined by the camera's pixel size and the lens magnification.
[0026] Take the smaller of the row number of the first positioning point and the row number of the second positioning point, and offset it upward by a third preset offset pixel number to obtain the upper boundary row number of the beam detection area. Take the larger of the two, and offset it downward by a fourth preset offset pixel number to obtain the lower boundary row number of the beam detection area. The left offset pixel number is half the width of the beam in the image along the width direction. The right offset pixel number is the same as the left offset pixel number. The height offset pixel number and the height offset pixel number are both between 5 and 20 pixels to ensure that the beam detection area completely covers the beam along the row direction and leaves transition areas on the top and bottom sides.
[0027] The rectangular area bounded by the upper boundary row number, lower boundary row number, left boundary column number, and right boundary column number is the beam detection area. This beam detection area is cropped from the surface image and used for subsequent processing steps.
[0028] Step 2 involves preprocessing the beam detection area to obtain a reflection suppression image, specifically including: Step 21: Perform grayscale processing on the crossbeam detection area. The specific operation is as follows.
[0029] The beam detection area is derived from a surface image, which is typically a color image. Each pixel in the color image is represented by the brightness values of three color channels: red, green, and blue. Grayscale conversion refers to the process of converting the three-channel color information in a color image into single-channel grayscale information. In this embodiment, grayscale conversion uses a weighted average method: For each pixel in the beam detection area, the red, green, and blue channel component values are obtained. The red channel component value is multiplied by a preset red weight, the green channel component value by a preset green weight, and the blue channel component value by a preset blue weight. The preset red weight ranges from 0.2 to 0.4, the preset green weight ranges from 0.4 to 0.7, and the preset blue weight ranges from 0.1 to 0.2. The sum of the three preset weights is 1. The sum of the three products is the grayscale value of the pixel. This calculation is performed on all pixels one by one to obtain the grayscale image corresponding to the beam detection area.
[0030] The grayscale value ranges from 0 to 255, where 0 represents pure black, 255 represents pure white, and intermediate values represent different shades of gray.
[0031] Step 22: Identify the high-reflectivity areas. The specific steps are as follows.
[0032] Specular reflection refers to the abnormal brightness area formed in a local area on the surface of a molded part beam due to the specular reflection effect. The surface of the molded part beam usually has a smooth arc-shaped contour. When the incident angle of the light source just meets the specular reflection condition, the reflected light is concentrated into the camera lens, forming a small but extremely bright white spot in the image, i.e., the highlight area. Specular reflection refers to the reflection phenomenon where the reflection angle is equal to the incident angle after the light shines on a smooth surface, and the reflected light is concentrated in one direction.
[0033] The process of identifying highlight regions is as follows: In a grayscale image, the brightness of each pixel is determined. The grayscale value of the current pixel is compared with a preset brightness threshold. The preset brightness threshold is the grayscale threshold that determines whether a pixel belongs to a highlight region. The preset brightness threshold is determined as follows: In the grayscale histogram of the grayscale image, scan from the highest grayscale value of 255 towards lower grayscale values, find the grayscale value corresponding to the first trough position, and take a preset margin upwards from this grayscale value as the preset brightness threshold. If there is no trough in the grayscale histogram, then all pixels in the grayscale image are arranged in descending order of grayscale value, and the grayscale values in the first 1% to 3% of the arranged pixels are taken as the base brightness threshold. A preset margin is then taken upwards from this base brightness threshold as the preset brightness threshold. The margin range is 5 to 15 grayscale levels. A grayscale histogram is a statistical graph that counts the frequency of each grayscale value in an image. It is constructed by traversing all pixels in the image, counting the number of pixels corresponding to each grayscale value, and plotting the grayscale value on the horizontal axis and the number of pixels on the vertical axis. In a grayscale histogram, a trough refers to the location with the fewest grayscale values within a local area.
[0034] If the grayscale value is greater than a preset brightness threshold, the pixel is marked as a highlight pixel; if the grayscale value is not greater than the preset brightness threshold, the pixel is marked as a normal pixel. This comparison operation is performed on all pixels in the grayscale image one by one. A connected set of highlight pixels is defined as a highlight region. Connectivity means that a highlight pixel has a continuous adjacency relationship with its four adjacent highlight pixels in the above, below, left, and right directions.
[0035] Step 23: Perform grayscale correction on the highlight areas. The specific operation is as follows.
[0036] Grayscale correction refers to interpolating and filling pixels in the highlight area using the grayscale information of surrounding normal pixels to suppress the interference of highlight reflection on subsequent defect detection.
[0037] For each highlight region, obtain the boundary pixels of that region. A boundary pixel is a pixel in the highlight region that has at least one adjacent normal pixel. For each pixel to be corrected within the highlight region, search for normal pixels layer by layer outward from that pixel. The search method is as follows: starting from the center position of the pixel to be corrected, search outward along a pixel ring at a distance of 1 pixel. A pixel ring is a square ring formed by all pixels at a specified pixel distance from the center pixel. If a normal pixel exists in this ring, stop the search, and record the grayscale values of these normal pixels and their Euclidean distances from the center position. Euclidean distance is the straight-line distance between two pixels. In a 2D image, it is calculated by subtracting the row numbers of the two pixels and multiplying by itself, then subtracting the column numbers of the two pixels and multiplying by itself, adding the two squares and taking the square root. If no normal pixel exists in this ring, continue searching outward along a pixel ring at a distance of 2 pixels until at least one normal pixel is found.
[0038] The grayscale values of all found normal pixels are used as the interpolation source. For each normal pixel, the reciprocal of the Euclidean distance from that normal pixel to the center of the pixel to be corrected is calculated and used as the weight of that normal pixel. The closer the normal pixel is, the smaller its Euclidean distance, the larger its reciprocal, and the higher its weight, thus contributing more to the grayscale value of the pixel to be corrected. The grayscale values of all normal pixels are multiplied by their respective weights, summed, and then divided by the sum of all weights. The quotient is the corrected grayscale value of the pixel to be corrected. The original grayscale value of the pixel is replaced with the corrected grayscale value.
[0039] The above search and interpolation operations are performed one by one on all pixels to be corrected within a highlight region to complete the grayscale correction of that highlight region. After performing grayscale correction on all highlight regions in the grayscale image, a highlight-suppressed grayscale image is obtained.
[0040] Step 24, smoothing filtering process, the specific operation is as follows.
[0041] Smoothing filtering refers to the operation of averaging the neighborhood of an image to reduce the impact of random noise on subsequent grayscale profile extraction. In this embodiment, median filtering is used: for each pixel in the image, a filter window of a preset size is selected, centered on that pixel and including the pixel and its surrounding neighboring pixels. The filter window is a square pixel sub-region centered on the current pixel, and the preset size is the side length of the filter window in pixels, ranging from 3 to 5 pixels.
[0042] Arrange the gray values of all pixels within the filtering window in ascending order, and take the gray value at the middle position of the arrangement as the median of the window. Replace the original gray value of the center pixel of the filtering window with this median. For each pixel in the specular suppression grayscale image, take a filtering window centered on that pixel, sort and take the median, and replace the original value. After traversing all pixels, the reflection suppression image is obtained.
[0043] Step 3: In the reflection-suppressed image, extract grayscale value sequences along multiple pixel sampling lines perpendicular to the extension direction of the beam to obtain multiple grayscale profiles; wherein, the multiple pixel sampling lines are spaced apart along the extension direction of the beam, specifically including: Step 31: Determine the direction of beam extension.
[0044] The beam extension direction refers to the direction in which the beam extends along its length in the reflection suppression image. In the beam detection area, the beam extension direction is perpendicular to the line connecting the first and second positioning points. This is because the two positioning bosses are symmetrically distributed on both sides of the beam, and the line connecting the two positioning points crosses the beam along its width, i.e., perpendicular to the beam extension direction.
[0045] The specific process for determining the direction of beam extension is as follows.
[0046] Obtain the image coordinates of the first and second positioning points. Image coordinates consist of row and column numbers. Subtract the row number of the first positioning point from the row number of the second positioning point to obtain the row difference. Subtract the column number of the first positioning point from the column number of the second positioning point to obtain the column difference. The row and column differences together form a line vector connecting the two positioning points, with the direction of this line vector pointing from the first positioning point to the second positioning point.
[0047] The connecting vector is perpendicular to the beam's extension direction. Rotate this vector 90 degrees clockwise around its starting point. If the rotated direction is opposite to the actual beam's extension direction in the image, take the opposite direction; this is the beam's extension direction. The specific method for rotating 90 degrees is: replace the row component of the connecting vector with the column difference, and replace the column component with the opposite of the row difference (i.e., add a negative sign before the row difference). The two rotated components constitute the beam's extension direction vector.
[0048] The direction vector is normalized to a unit direction vector of length 1. The normalization process involves squaring the row direction component and the column direction component, adding the two squares, and taking the square root to obtain the magnitude of the direction vector. Dividing the row direction component by the magnitude yields the row component of the unit direction vector. Dividing the column direction component by the magnitude yields the column component of the unit direction vector. These two components constitute the unit direction vector along the beam's extension direction.
[0049] A pixel sampling line refers to a single row or column of pixel lines that runs perpendicular to the direction of beam extension and through the beam's detection area along its width. The pixels along each pixel sampling line constitute a one-dimensional pixel sequence.
[0050] Step 32: Determine the positions of multiple pixel sampling lines.
[0051] Within the crossbeam detection area, multiple pixel sampling lines are defined perpendicular to the crossbeam's extension direction. These pixel sampling lines are spaced apart along the crossbeam's extension direction, meaning there is a preset pixel distance between adjacent pixel sampling lines along the crossbeam's extension direction. The preset pixel distance is between 1 and 5 pixels, determined based on a balance between detection accuracy requirements and real-time performance: a smaller pixel distance results in denser sampling lines and higher detection accuracy for weld line defects along the crossbeam's extension direction, but also increases the computational load.
[0052] The specific process for determining the position of each pixel sampling line is as follows.
[0053] Within the beam detection area, the starting end of the beam's extension direction is determined. The starting end is the end position in the beam detection area near the first positioning point along the beam's extension direction. Taking this starting end as the origin, a sampling position is determined every preset pixel distance along the beam's extension direction. The number of sampling positions is equal to the total pixel length of the beam detection area along the beam's extension direction divided by the preset pixel distance and then rounded down.
[0054] At each sampling location, a straight line segment perpendicular to the beam's extension direction is constructed. This is done by: using the sampling location as the center point, obtaining the unit direction vector of the beam's extension direction; rotating this unit direction vector 90 degrees, replacing the row component of the direction vector with the column component of the unit direction vector, and then replacing the column component with the negative of the row component of the unit direction vector, thus obtaining the direction of the pixel sampling line. Extending along this direction from one boundary of the beam detection area to the other, the resulting pixel path constitutes a pixel sampling line.
[0055] When the pixel sampling line is not along the row or column direction of the image, digital differential analysis (DDA) is used to determine the pixel sequence traversed by the pixel sampling line. The principle of DDA is as follows: the larger of the two components along the pixel sampling line direction is used as the principal step axis, and the smaller one as the minor step axis. Starting from the initial pixel, each pixel is stepped once along the principal step axis, while simultaneously accumulating the step amount along the minor step axis according to the ratio of the two components. Each time the accumulation reaches one pixel, a new step is performed. After each step, the position of the current pixel is recorded, resulting in the complete pixel sequence traversed by the pixel sampling line.
[0056] The above construction operation is performed on all sampling positions one by one to obtain multiple pixel sampling lines spaced apart along the extension direction of the beam.
[0057] Step 33: Read the grayscale value sequence on each pixel sampling line.
[0058] For each pixel sampling line, obtain the grayscale values of all pixels that the sampling line passes through in the reflection-suppressed image. Starting from one end of the pixel sampling line, sequentially read the grayscale values of each pixel that the line passes through.
[0059] If the pixel sampling line happens to be aligned with the row or column direction of the image (i.e., the pixel sampling line is aligned with the pixel grid), then the grayscale value of each pixel in the aligned direction is read directly.
[0060] If the pixel sampling line does not follow the row or column direction, the digital differential analysis method has determined the pixel sequence through which the pixel sampling line passes. For each pixel in this pixel sequence, the gray value of that pixel in the reflection-suppressed image is directly read. Since the pixel sampling line may not pass through the center of the pixel, when a more accurate gray value is needed, bilinear interpolation can be used to calculate the gray value of the pixel sampling line at a certain sub-pixel position. The specific method of bilinear interpolation is as follows: obtain the gray values of the four nearest integer pixels around the sub-pixel position, determine the integer pixel with the smallest row number and the smallest column number as the top-left pixel, the integer pixel with the smallest row number and the largest column number as the top-right pixel, the integer pixel with the largest row number and the smallest column number as the bottom-left pixel, and the integer pixel with the largest row number and the largest column number as the bottom-right pixel. Calculate the row offset and column offset from the sub-pixel position to the top-left pixel. The row offset is the difference between the row number of the sub-pixel position and the row number of the top-left pixel, and the column offset is the difference between the column number of the sub-pixel position and the column number of the top-left pixel. First, perform two linear interpolations along the row direction. Subtract the gray value of the top-left pixel from the gray value of the top-right pixel, multiply by the row offset, and add the gray value of the top-left pixel to obtain the first row interpolation result. Subtract the gray value of the bottom-left pixel from the gray value of the bottom-right pixel, multiply by the row offset, and add the gray value of the bottom-left pixel to obtain the second row interpolation result. Then, perform one more linear interpolation along the column direction. Subtract the first row interpolation result from the second row interpolation result, multiply by the column offset, and add the first row interpolation result to obtain the interpolated gray value at that subpixel position.
[0061] The gray values at all sampling positions along the pixel sampling line are arranged sequentially in spatial order along the direction of the pixel sampling line to obtain a gray value sequence. Each element in this gray value sequence is a gray value, and the order of the elements reflects the gray value change from one edge of the beam to the other along the direction of the pixel sampling line.
[0062] A grayscale value sequence is an ordered set of values formed by arranging the grayscale values at each position on a pixel sampling line in spatial order. The above reading operation is performed on each of all pixel sampling lines to obtain the grayscale value sequence corresponding to each pixel sampling line.
[0063] Step 34: Determine the grayscale value sequence as a grayscale profile.
[0064] The grayscale value sequence corresponding to each pixel sampling line is defined as a grayscale profile. A grayscale profile is a curve showing the change of grayscale value with pixel position along a pixel sampling line perpendicular to the extension direction of the beam. The grayscale profile reflects the grayscale distribution pattern of the beam surface on a cross-section along the width direction. The grayscale profile of a normal beam surface shows a sharp drop in grayscale at both edges and a relatively uniform grayscale in the flat middle area. However, at locations with weld line defects, the grayscale profile shows a local grayscale depression at the defect location, i.e., a local valley shape where the grayscale value first decreases and then increases.
[0065] The grayscale value sequences corresponding to all pixel sampling lines are determined as grayscale profiles, resulting in multiple grayscale profiles. The number of grayscale profiles is equal to the number of pixel sampling lines. These multiple grayscale profiles are used as the output of step 3.
[0066] Step 4: Perform baseline correction on each grayscale profile to obtain a baseline-corrected profile, specifically including: Step 41: Fit the grayscale profile to obtain the baseline.
[0067] The baseline refers to the reference curve in the grayscale profile that reflects the overall trend of grayscale variation on the normal surface of the beam. Due to the curved contour of the beam surface, under uniform illumination, its grayscale profile exhibits an overall trend of higher grayscale values in the central area and gradually decreasing grayscale values in the two edge areas. This overall trend constitutes the background component of the grayscale profile, while the local grayscale depressions caused by weld line defects are abnormal components superimposed on this background. By separating the background grayscale trend of the normal surface from the grayscale profile and retaining only the local grayscale abnormal components superimposed on the background, the grayscale depression characteristics of the weld line defects are highlighted.
[0068] For each grayscale profile, a baseline fitting operation is performed. Fitting refers to the mathematical operation of finding a smooth curve that best represents the overall trend of grayscale variation based on all grayscale values in the grayscale profile. In this embodiment, the baseline fitting adopts the polynomial curve fitting method, which approximates the background variation trend in the grayscale profile by constructing a polynomial curve.
[0069] The specific process of polynomial curve fitting is as follows.
[0070] Obtain the position number and grayscale value of each pixel along the pixel sampling line direction in the grayscale profile. The position numbers start from 1 and are consecutively numbered 1, 2, 3... until the total number of pixels in the grayscale profile. Use the position number of each pixel as the independent variable and the grayscale value of that pixel as the dependent variable to form a set of two-dimensional data points. A two-dimensional data point refers to a data pair consisting of a pair of independent and dependent variable values; in this embodiment, it is the pairing of position number and grayscale value.
[0071] A polynomial of a preset order is selected as the functional form of the fitted curve. A polynomial is a mathematical expression consisting of a weighted sum of several terms: for an nth-order polynomial, it contains n+1 undetermined coefficients. Each term is formed by multiplying the coefficient by the corresponding power of the independent variable value. The 0th-order term is a constant term (coefficient multiplied by 1), the 1st-order term is the coefficient multiplied by the independent variable value, the 2nd-order term is the coefficient multiplied by the square of the independent variable value, and so on up to the nth-order term. The preset order n determines the smoothness of the fitted curve; the lower the order, the smoother the curve and the better it reflects the overall trend; the higher the order, the closer the curve is to the data points, but it may also include defects and depressions in the baseline. In this embodiment, the preset order is between 3rd and 5th order.
[0072] The goal of fitting is to determine a set of polynomial coefficient values such that the sum of the squares of the differences between the calculated grayscale values and the corresponding actual grayscale values at each indexed position of the polynomial curve is minimized. This goal can be achieved by solving a system of normal equations. The system of normal equations is constructed as follows: For each undetermined coefficient in the polynomial, a normal equation is constructed. Taking a 3rd-order polynomial as an example, there are 4 undetermined coefficients (constant term coefficient, first-order term coefficient, second-order term coefficient, and third-order term coefficient), requiring the construction of 4 normal equations. The left side of the first normal equation is: the constant term coefficient multiplied by the sum of all position numbers raised to the power of 0 (i.e., the total number of pixels), plus the first term coefficient multiplied by the sum of all position numbers raised to the power of 1, plus the second term coefficient multiplied by the sum of all position numbers raised to the power of 2, plus the third term coefficient multiplied by the sum of all position numbers raised to the power of 3. The right side of the first normal equation is: the sum of the gray values at each position number multiplied by the zero power of that position number (i.e., each gray value itself). The left side of the second normal equation has a sum of position numbers corresponding to each coefficient raised to the power of 1, which is one order higher than the first equation. The right side is the sum of gray values multiplied by the corresponding position number raised to the power of 1. This process is repeated to construct all normal equations.
[0073] Solve the constructed normal equation system to obtain the values of the coefficients of each polynomial. The normal equation system is a linear system of equations, which can be solved using elimination. The specific steps of elimination are as follows: Arrange the equations in the system sequentially. Starting with the first equation, divide each term of the first equation by the coefficient of the first unknown, making the coefficient of the first unknown equal to 1. Then, subtract the product of the first equation and the coefficient of the first unknown from the second equation to eliminate the first unknown in the second equation. Repeat this operation for subsequent equations to eliminate the first unknown in each equation. After eliminating the first unknown, repeat the above elimination process for the sub-equations formed by the second to the last equations, successively eliminating the second and third unknowns, until the last equation contains only the last unknown. Starting from the last unknown, substitute backwards, substituting the already obtained values of the unknowns into the previous equation to solve for the previous unknown, until all unknowns have been solved. The obtained values of each unknown are the values of the coefficients of each polynomial.
[0074] Substituting the obtained polynomial coefficients into the polynomial expression yields a smooth polynomial baseline curve. This baseline curve reflects the expected grayscale distribution trend of the normal surface of the beam at this grayscale profile location.
[0075] The quality of the fit is evaluated using the fitting residuals. The fitting residuals are calculated as follows: subtract the baseline gray value at the same position number in the baseline curve from the actual gray value at each location in the gray-scale profile. The residuals are then multiplied by themselves, summed, and divided by the total number of pixel locations in the gray-scale profile. The quotient is the fitting residual. If the fitting residual is greater than a preset fitting residual threshold and the current polynomial order is less than 5, the polynomial order is increased by 1, and the normal equation system is re-constructed and solved. If the current polynomial order has reached 5 and the fitting residual is still greater than the preset fitting residual threshold, the baseline obtained by fitting the current 5th-order polynomial is used as the final baseline. The preset fitting residual threshold ranges from the square of 1 to 5 gray-level values. A gray-level value refers to the smallest unit of change in gray value, i.e., the difference between two adjacent gray-level values is 1.
[0076] Step 42: Calculate the grayscale difference sequence.
[0077] For each pixel location in the grayscale profile, obtain the actual grayscale value at that location. Simultaneously, obtain the baseline grayscale value at the same location number in the baseline curve obtained in step 41. Substitute the location number into the solved polynomial expression, calculate the product and sum of the terms of the polynomial, and the result is the baseline grayscale value at that location.
[0078] The grayscale difference at a pixel location is obtained by subtracting the baseline grayscale value from the actual grayscale value.
[0079] A negative grayscale difference value indicates that the actual grayscale value is lower than the baseline grayscale value, meaning there is a grayscale depression at that location, and the actual surface height is lower than the normal surface. The larger the absolute value of the negative value, the deeper the depression, and the higher the probability that the location is a weld line defect. A positive grayscale difference value indicates that the actual grayscale value is higher than the baseline grayscale value, and the location is a normal surface or may still have residual highlight areas with abnormal brightness. The closer the grayscale difference value is to zero, the closer the actual grayscale value is to the baseline grayscale value, and the height at that location is basically the same as the normal surface.
[0080] The gray-level differences of all pixel positions in the gray-level profile are arranged sequentially along the pixel sampling line direction, i.e., in ascending order of position number, to obtain a gray-level difference sequence. The length of the gray-level difference sequence is the same as the length of the original gray-level profile, and the value at each position in the sequence is the gray-level deviation of the corresponding position in the original gray-level profile relative to the baseline.
[0081] Step 43: Determine the grayscale difference sequence as the baseline correction profile.
[0082] The grayscale difference sequence was determined as the baseline correction profile corresponding to the grayscale profile. The baseline correction profile underwent background removal, eliminating the overall grayscale gradient trend caused by the curved surface of the beam, retaining only the grayscale deviation at each pixel location relative to the normal surface. In the baseline correction profile, the grayscale deviation of the normal surface approaches zero, while the grayscale deviation at the weld line defect location exhibits a significant negative value depression.
[0083] Perform the baseline fitting and difference calculation operations from step 41 to step 43 on each grayscale profile to obtain the baseline correction profile corresponding to each grayscale profile. Each baseline correction profile is a numerical sequence of the same length as the original grayscale profile. The position and depth information of the negative value depression in the sequence completely preserves the grayscale abnormality characteristics of the weld line defect on the cross section. These baseline correction profiles are used as the output of step 4.
[0084] Step 5: Based on the first-order and second-order gray-level change characteristics of the baseline correction profile, identify candidate depression points that meet the following criteria: local gray-level concavity, opposite slope directions on both sides, and depression width within a preset width range. Specifically, this includes: Step 51: Perform first-order difference processing on the baseline correction profile to obtain a first-order grayscale change sequence.
[0085] First-order differencing refers to the operation of calculating the numerical change between two adjacent positions in a sequence. First-order differencing is performed for each baseline correction profile.
[0086] Obtain the sequence of gray-level difference values for all pixel positions in the baseline correction profile, arranged sequentially. Each position in this sequence corresponds to a gray-level difference value. Starting from the first position in the sequence, subtract the gray-level difference of the first position from the gray-level difference of the second position to obtain the first first-order difference value. Subtract the gray-level difference of the second position from the gray-level difference of the third position to obtain the second first-order difference value. Subtract the gray-level difference of the third position from the gray-level difference of the fourth position to obtain the third first-order difference value. Continue in this manner until the gray-level difference of the second-to-last position is subtracted from the gray-level difference of the last position to obtain the last first-order difference value.
[0087] All first-order difference values are arranged sequentially according to their corresponding positions to obtain the first-order grayscale variation sequence of the baseline correction profile. The length of the first-order grayscale variation sequence is one element less than that of the original baseline correction profile.
[0088] The physical meaning of the first-order difference value is the rate and direction of change of grayscale along the pixel sampling line at that location. A positive first-order difference value indicates that the grayscale is increasing along the pixel sampling line, with the grayscale difference changing from negative to zero or positive. A negative first-order difference value indicates that the grayscale is decreasing along the pixel sampling line, with the grayscale difference changing from zero or positive to negative. The larger the absolute value of the first-order difference value, the more drastic the change in grayscale at that location. At the edge of a weld line defect, the grayscale difference drops sharply from the normal level to a negative value, corresponding to a large negative first-order difference value. At the recovery location of the defect, the grayscale difference rises from a negative value back to the normal level, corresponding to a large positive first-order difference value.
[0089] The first-order difference processing described above is performed on each of the baseline correction profiles to obtain the first-order grayscale change sequence corresponding to each baseline correction profile.
[0090] Step 52: Perform second-order difference processing on the baseline correction profile to obtain a second-order grayscale change sequence.
[0091] Second-order difference processing refers to performing a difference operation again on the first-order gray-level change sequence that has already undergone first-order difference processing. For each baseline correction profile, second-order difference processing is performed on the basis of the first-order gray-level change sequence.
[0092] Obtain the first-order grayscale variation sequence. Starting from the first position of the first-order grayscale variation sequence, subtract the first first-order difference value from the second first-order difference value to obtain the first second-order difference value. Subtract the second first-order difference value from the third first-order difference value to obtain the second second-order difference value. Continue in this manner until the last first-order difference value is subtracted from the second-to-last first-order difference value to obtain the last second-order difference value.
[0093] All second-order difference values are arranged sequentially according to their corresponding positions to obtain the second-order gray-level change sequence of the baseline correction profile. The length of the second-order gray-level change sequence is 1 element less than that of the first-order gray-level change sequence and 2 elements less than that of the original baseline correction profile.
[0094] The physical meaning of the second-order difference value is the rate of change of the grayscale change rate itself, reflecting the bending direction and degree of the grayscale profile at that position. A positive second-order difference value indicates that the grayscale change rate is increasing and the grayscale profile at that position is convex. A negative second-order difference value indicates that the grayscale change rate is decreasing and the grayscale profile at that position is concave. In the concave bottom region of the weld line defect, at the turning point where the grayscale changes from decreasing to increasing, the second-order difference value changes from negative to positive. That is, the bottom of the concave corresponds to the turning point from negative to positive in the second-order difference sequence.
[0095] The above second-order difference processing is performed on each of the baseline correction profiles to obtain the second-order grayscale change sequence corresponding to each baseline correction profile.
[0096] Step 53: Determine two edge points with opposite gray-level change directions based on the first-order gray-level change sequence.
[0097] An edge point refers to the boundary in the baseline correction profile where the gray level either begins to move from the normal level into the recessed area or returns to the normal level from the recessed area. In the recessed section of a weld line defect, there are two edge points: the entry edge point and the exit edge point. The first-order difference values at the two edge points have opposite signs: the first-order difference at the entry edge point is negative, and the first-order difference at the exit edge point is positive.
[0098] For each first-order grayscale change sequence of the baseline correction profile, perform the following edge point detection operation.
[0099] In a first-order grayscale variation sequence, find the first-order difference value with the largest absolute value and denote it as the reference peak. Obtain preset positive change thresholds and preset negative change thresholds. The preset positive change threshold is determined by multiplying the reference peak by a preset positive scaling factor; the product is the preset positive change threshold. The preset negative change threshold is determined by multiplying the absolute value of the reference peak by a preset negative scaling factor and taking the opposite value; the result is the preset negative change threshold. The values of both the preset positive and preset negative scaling factors range from 0.3 to 0.5.
[0100] In a first-order grayscale variation sequence, each first-order difference value is scanned sequentially from the beginning to the end of the sequence. When a first-order difference value is found to be less than a preset negative change threshold, i.e., the first-order difference value is a significantly negative value, this position is marked as the first change position. The first change position corresponds to the edge point entering the concave region, where the grayscale level drops sharply.
[0101] The scanning continues, and when a first-order difference value is found that is greater than a preset positive change threshold (i.e., the first-order difference value is a significantly positive value), this position is marked as the second change position. The second change position corresponds to the edge point leaving the concave region, where the grayscale level rises sharply.
[0102] The first and second change positions are defined as two edge points with opposite grayscale change directions. The first change position (negative change) is the entry edge of the depression, and the second change position (positive change) is the exit edge of the depression. The two edge points are set at intervals along the pixel sampling line direction and are located on both sides of the same grayscale depression.
[0103] If multiple pairs of first and second change positions satisfying the above conditions are found in a first-order grayscale change sequence, each pair is determined as two corresponding edge points. There should be no other first or second change position between the first and second change positions in each pair. That is, the pairing is matched according to the nearest negative and positive changes along the direction of the pixel sampling line.
[0104] Step 54: Determine the local gray-level concave region based on the second-order gray-level change sequence between the two edge points.
[0105] For each pair of paired edge points, obtain the position numbers of these two edge points in the first-order grayscale change sequence. Map the positions in the first-order difference sequence to the pixel positions in the original baseline correction profile. The first-order difference value at any position in the first-order grayscale change sequence corresponds to the grayscale change between that position and the next adjacent position in the original baseline correction profile. The pixel position corresponding to the first change position in the original baseline correction profile is the first change position number plus 1, and the pixel position corresponding to the second change position is the second change position number plus 1.
[0106] The segment between two edge points in the original baseline correction profile is the candidate concave segment. For the pixel positions within the candidate concave segment, the second-order difference value of the corresponding position in the second-order gray-level change sequence is obtained.
[0107] Check whether the second-order grayscale variation features within the candidate concave region exhibit a local concave shape. The method for determining a local concave shape is as follows: within the second-order grayscale variation sequence corresponding to the candidate concave region, scan each second-order difference value sequentially from the beginning to the end. When the second-order difference value at a certain position is less than 0 and the second-order difference value at the next position is greater than 0, that is, the second-order difference value changes from negative to positive at that position, this position is the turning point from negative to positive. The existence of the turning point indicates that the curvature direction of the grayscale profile within this region has changed from concave to convex, meaning that there is indeed a bottom of a local grayscale concavity within this region.
[0108] If a candidate concave segment contains a turning point from negative to positive, then the candidate concave segment is determined as a local gray-level concave interval. If a candidate concave segment does not contain a turning point from negative to positive, then the segment does not constitute a local gray-level concave interval.
[0109] Step 55: Calculate the width of the depression in the local grayscale depression area.
[0110] For each local gray-level recessed region, calculate its recess width. The recess width refers to the pixel span of the local gray-level recessed region along the pixel sampling line direction.
[0111] The starting boundary position is defined as the location at one end of the local gray-level concavity interval along the pixel sampling line direction of the two edge points. The ending boundary position is defined as the location at the other end of the local gray-level concavity interval along the pixel sampling line direction of the two edge points. The starting boundary position is the pixel position corresponding to the first change position in the original baseline correction profile, and the first change position number is incremented by 1. The ending boundary position is the pixel position corresponding to the second change position in the original baseline correction profile, and the second change position number is incremented by 1.
[0112] The number of consecutive pixels between the starting and ending boundary positions is counted. Starting from the pixel corresponding to the starting boundary position, the count is performed sequentially along the pixel sampling line until the pixel corresponding to the ending boundary position is reached. The count of these consecutive pixels is determined as the concavity width of this local grayscale depression. The unit of concavity width is the number of pixels.
[0113] Step 56: Determine the local grayscale depression range where the depression width is within the preset width range as candidate depression points.
[0114] Obtain the preset width range. The preset width range is a range of one pixel. The lower and upper limits are determined by dividing the physical width range of the weld line defect in the background technology (approximately 1mm to 2mm) by the physical size corresponding to a single pixel. This results in the pixel width range corresponding to the physical width in the image, which is then used as the preset width range.
[0115] The width of the depression is compared with a preset width range. If the width of the depression is not less than the lower limit of the preset width range and not greater than the upper limit of the preset width range, the pixel position corresponding to the local grayscale depression is determined as a candidate depression point. A candidate depression point indicates that a grayscale depression with a width feature that matches the expected weld line defect is detected at a position along the beam width direction on the pixel sampling line.
[0116] Simultaneously record the location information of the candidate indentation point: the number of the pixel sampling line where the candidate indentation point is located, and the start and end boundary positions of the candidate indentation point on the pixel sampling line.
[0117] If the width of the depression is less than the lower limit of the preset width range, the depression is too narrow and may be caused by image noise or minor surface textures, and will not be considered a candidate depression point. If the width of the depression is greater than the upper limit of the preset width range, the depression is too wide and may be caused by wide and gentle arc-shaped undulations on the surface of the beam or large areas of residual highlights, and will not be considered a candidate depression point.
[0118] For each baseline correction profile, perform the edge point detection, concave interval determination, width calculation and candidate concave point screening operations from step 53 to step 56 one by one, summarize all the candidate concave points identified in all baseline correction profiles, obtain the candidate concave point set, and use the candidate concave point set as the output of step 5.
[0119] Step 6: Perform continuity correlation on the candidate depression points along the extension direction of the crossbeam to obtain candidate weld line defects, specifically including: Step 61: Determine the pixel position of each candidate indentation point on the corresponding pixel sampling line.
[0120] For each candidate indentation point in the candidate indentation point set, its location information is extracted. The location information of each candidate indentation point includes: the number of the pixel sampling line where the candidate indentation point is located, and the start boundary position and end boundary position of the candidate indentation point on the pixel sampling line.
[0121] Calculate the center pixel position of the candidate indentation point on the pixel sampling line. The center pixel position is calculated as follows: add the start boundary position and the end boundary position, divide by 2, and round the quotient to the nearest integer. This quotient is the center pixel position of the candidate indentation point. The center pixel position represents the representative position of the candidate indentation point along the width direction of the beam on the corresponding pixel sampling line.
[0122] Simultaneously, based on the pixel sampling line number where the candidate indentation point is located and the predetermined preset pixel distance, the position coordinates of the candidate indentation point along the extension direction of the beam are calculated. The pixel sampling line number is multiplied by the preset pixel distance, and the resulting product is the position coordinates of the candidate indentation point along the extension direction of the beam from the starting end.
[0123] Perform the above pixel position extraction and calculation operations on all candidate indentation points one by one to obtain the two-dimensional position coordinates of each candidate indentation point within the crossbeam detection area. The coordinates along the width direction of the crossbeam are the center pixel positions, and the coordinates along the extension direction of the crossbeam are the product of the pixel sampling line number and the preset pixel distance.
[0124] Step 62: Perform continuity correlation on the candidate depression points along the extension direction of the beam.
[0125] A weld line defect is a linear indentation of a certain length that extends along the beam's direction, formed when two streams of molten plastic converge at the middle of the beam. A candidate indentation detected on a single pixel sampling line only indicates the possible presence of a weld line defect at that cross-sectional location. To determine whether a continuous weld line defect exists, it is necessary to correlate candidate indentation points located close to each other on adjacent pixel sampling lines along the beam's direction.
[0126] Along the extension direction of the beam, that is, in the direction of pixel sampling line numbering from small to large, the candidate depression points are continuously correlated with each pixel sampling line.
[0127] Obtain the preset positional deviation threshold. The preset positional deviation threshold is the upper limit of the allowable positional deviation along the beam width direction for determining whether two candidate depressions on two adjacent pixel sampling lines belong to the same weld line defect. It is determined by dividing the maximum possible spatial offset of the weld line defect in the beam width direction by the physical size corresponding to a single pixel to obtain the pixel-level deviation limit. The value of the preset positional deviation threshold ranges from 2 to 5 pixels.
[0128] Starting from the first pixel sampling line, obtain the center pixel position for each candidate indentation point on that pixel sampling line. On the second pixel sampling line, search all candidate indentation points. Check if there exists a candidate indentation point whose absolute value of the difference between its center pixel position and the center pixel position of the current candidate indentation point on the first pixel sampling line is less than a preset position deviation threshold.
[0129] If candidate depressions that meet the above conditions exist, the current candidate depression on the first pixel sampling line and the matching candidate depression on the second pixel sampling line are associated as the same set of associated depressions. Association means marking candidate depressions that are close in position on different pixel sampling lines as part of the same weld line defect.
[0130] If there are multiple candidate depressions that meet the conditions on the second pixel sampling line, the one with the smallest absolute value of the difference between the center pixel position and the center pixel position of the current candidate depression on the first pixel sampling line is selected for association.
[0131] If there is no candidate depression point that meets the conditions on the second pixel sampling line, the associated chain of the candidate depression point is interrupted at the current pixel sampling line. The interruption indicates the termination of the weld line defect candidate along the extension direction.
[0132] Continue from the second pixel sampling line to the third and fourth pixel sampling lines, repeating the above association operation. Each time, find a candidate concave point on the current pixel sampling line whose absolute value of the difference between the center pixel position of the candidate concave point associated with the previous pixel sampling line and the candidate concave point is less than the preset position deviation threshold, and add it to the current associated concave point group.
[0133] For each candidate depression point on a pixel sampling line, if it fails to establish a connection with any candidate depression point on the previous pixel sampling line, a new group of associated depression points is started from that candidate depression point, and the association search continues to the next pixel sampling line.
[0134] Step 63: Identify the continuous trajectory as a candidate for weld line defect.
[0135] After completing the association operation of all pixel sampling lines, several sets of associated depression points are obtained. Each set of associated depression points is an ordered set of candidate depression points. The candidate depression points in the set are arranged sequentially along the extension direction of the beam, and the positional deviation between two adjacent candidate depression points along the width direction of the beam is within a preset positional deviation threshold.
[0136] For each group of associated indentations, check its continuous length along the beam's extension direction. The continuous length is calculated as follows: Obtain the pixel sampling line number of the foremost candidate indentation point along the beam's extension direction in the group of associated indentations, denoted as the starting sampling line number; obtain the pixel sampling line number of the last candidate indentation point in the group of associated indentations, denoted as the ending sampling line number. Subtract the starting sampling line number from the ending sampling line number, add 1, and multiply by a preset pixel distance. The resulting product is the continuous length of the group of associated indentations along the beam's extension direction.
[0137] Obtain a preset minimum continuous length threshold. This threshold is the minimum pixel span along the extension direction required to determine whether a group of associated indentations constitutes a meaningful weld line defect candidate. If the continuous length of the associated indentation group is less than the preset minimum continuous length threshold, the group of indentations may be formed by random noise occurring near each other on different pixel sampling lines, and does not constitute a meaningful defect. The preset minimum continuous length threshold ranges from 5 to 20 pixels, and the specific value is determined based on the minimum extension length of the weld line defect in the actual product and the physical size corresponding to a single pixel.
[0138] If the continuous length of the group of associated depressions is not less than a preset minimum continuous length threshold, then the continuous trajectory formed by connecting the group of associated depressions sequentially along the extension direction of the beam is determined as a candidate weld line defect. The continuous trajectory refers to the spatial curve formed by connecting the center pixel position of each candidate depression point in the group of associated depressions along the extension direction of the beam, using the center pixel position of the pixel sampling line as a node.
[0139] Each weld line defect candidate within the beam detection area is described by the following information: the start and end positions of the weld line defect candidate along the beam extension direction, and the sequence of center pixel positions of the weld line defect candidate on each pixel sampling line.
[0140] All associated indentation points that meet the continuous length requirement are identified as candidates for weld line defects, resulting in a candidate set of weld line defects. This set is then used as the output of step 6.
[0141] Step 7: Based on the brightness characteristics, edge sharpness characteristics, and direction characteristics of the weld line defect candidates, interference screening is performed on the weld line defect candidates to obtain the retained weld line defect candidates, specifically including: Step 71: Determine the candidate region corresponding to each weld line defect candidate.
[0142] For each candidate weld line defect in the candidate set, determine its corresponding candidate region in the reflection suppression image. The candidate region is a rectangular sub-region of the reflection suppression image that contains the pixel sampling line where each associated indentation point of the weld line defect candidate is located and its neighboring pixels.
[0143] Obtain the start and end boundary positions of the candidate fusion line defect on each pixel sampling line. Along the beam width direction, take the minimum value from all start boundary positions as the left boundary of the candidate region, and take the maximum value from all end boundary positions as the right boundary of the candidate region. Along the beam extension direction, offset the pixel position corresponding to the start sampling line number of the candidate fusion line defect upwards by a preset number of neighboring pixels to form the upper boundary of the candidate region, and offset the pixel position corresponding to the end sampling line number downwards by a preset number of neighboring pixels to form the lower boundary of the candidate region. The preset number of neighboring pixels ranges from 3 to 5 pixels.
[0144] The rectangular region bounded by the upper, lower, left, and right boundaries is the candidate region corresponding to the candidate fusion line defect. The candidate region is cropped from the reflection suppression image to obtain a candidate region sub-image. This process is repeated for all candidate fusion line defects to obtain each candidate region sub-image.
[0145] Step 72: Calculate the average brightness of the candidate region to obtain the brightness features.
[0146] For each candidate region sub-image, obtain the grayscale values of all pixels in the candidate region sub-image. Sum the grayscale values of all pixels one by one to obtain the total grayscale value. Divide the total grayscale value by the total number of pixels in the candidate region sub-image, i.e., the pixel width multiplied by the pixel height of the candidate region; the quotient is the average brightness of the candidate region, which is used as the brightness feature of the fusion line defect candidate. Perform the above calculation on all fusion line defect candidates one by one to obtain the brightness feature of each fusion line defect candidate.
[0147] Step 73: Calculate the gradient intensity of the candidate region edge to obtain the edge sharpness feature.
[0148] For each pixel in each candidate region sub-image, calculate the gradient value of that pixel along the width direction of the beam and the gradient value along the extension direction of the beam.
[0149] The gradient value along the width of the beam is calculated as follows: obtain the gray values of the pixels to the right and to the left of the pixel. Subtract the gray value of the pixel to the right from the gray value of the pixel to the gray value of the pixel to the left, and divide the difference by 2 to obtain the gradient value of the pixel along the width of the beam.
[0150] The gradient value along the beam's extension direction is calculated as follows: Obtain the grayscale values of the pixels below and above the current pixel. Subtract the grayscale value of the pixels above from the grayscale value of the pixels below, and divide the difference by 2 to obtain the gradient value of the current pixel along the beam's extension direction.
[0151] For a pixel located on the boundary of the candidate region, if it lacks a neighboring pixel on one side, the gray value of the pixel itself is used to replace the gray value of the missing neighboring pixel for calculation.
[0152] Multiply the gradient value of the pixel along the width of the beam by itself, and multiply the gradient value of the pixel along the extension direction of the beam by itself. Add the two squared values together and take the square root. The resulting value is the gradient intensity of the pixel. Perform the above gradient intensity calculation on all pixels in the candidate region sub-image one by one to obtain the gradient intensity value of each pixel.
[0153] The arithmetic mean of the gradient intensity values of the top percentage of pixels with the largest gradient intensity values in the candidate region sub-image is taken. The sum of these selected gradient intensity values is then divided by the number of selected pixels to obtain the edge sharpness feature of the candidate region. The preset percentage ranges from 5% to 10%. This calculation is performed on all candidate weld line defects one by one to obtain the edge sharpness feature of each candidate weld line defect.
[0154] Step 74: Determine the directional angle between the extension direction of the candidate region and the extension direction of the beam to obtain the directional features.
[0155] For each candidate weld line defect, the center pixel position of the candidate weld line defect on each pixel sampling line and the position coordinates of each pixel sampling line along the extension direction of the beam are obtained. The position coordinates of each pixel sampling line along the extension direction of the beam are used as independent variables, and the center pixel position of the corresponding candidate depression point is used as the dependent variable, forming a set of two-dimensional data points.
[0156] The principle of linear fitting and polynomial curve fitting for this set of two-dimensional data points is the same, except that the order of the polynomial is set to 1. Linear fitting is performed by constructing a system of normal equations and solving them by elimination to obtain the slope of the fitted line. The slope reflects the offset along the width of the beam when the candidate line moves forward a unit distance along the beam's extension direction.
[0157] Calculate the directional angle between the extension direction of the candidate weld line defect and the extension direction of the crossbeam. Since the pixel sampling lines are spaced apart along the extension direction of the crossbeam, and the center pixel position represents the position of the candidate depression point along the width direction perpendicular to the extension direction of the crossbeam, in a two-dimensional coordinate system constructed with the position coordinates along the extension direction of the crossbeam as the first coordinate and the center pixel position as the second coordinate, the direction corresponding to the second coordinate of the extension direction of the crossbeam remains unchanged. The slope of the fitted straight line represents the offset along the width direction of the crossbeam for each unit distance the candidate weld line defect advances along the extension direction of the crossbeam. The absolute value of this slope is the tangent of the directional angle. Convert the absolute value of the slope into an angle value using an arctangent operation.
[0158] Before performing the series expansion, first determine if the absolute value of the slope is greater than 1. If it is greater than 1, calculate the reciprocal of the absolute value of the slope, perform the following series expansion on the reciprocal to obtain the intermediate angle value, and subtract the intermediate angle value from half of pi to obtain the final angle value. If it is not greater than 1, directly perform the following series expansion on the absolute value of the slope, and the arctangent operation maps the slope value to the corresponding angle value. The calculation method is as follows: using the series expansion formula of the arctangent function, iterate term by term with the slope value as the independent variable. The calculation process is as follows: take the slope value as the first term. Divide the slope value by 3 to the power of 3 to obtain the second term and subtract it from the first term. Divide the slope value by 5 to the power of 5 to obtain the third term and add it to the previous result. Divide the slope value by 7 to the power of 7 to obtain the fourth term and subtract it from the previous result. And so on, alternating between subtraction and addition, with the power increasing by 2 each time. Stop iterating when the absolute value of the current term is less than the preset series truncation threshold. The preset level cutoff threshold is set to the fourth decimal place. The final accumulated result is used as the output angle value of the arctangent calculation. The obtained angle value is the angle between the extension direction of the weld line defect candidate and the extension direction of the crossbeam.
[0159] The smaller the directional angle, the closer the candidate's extension direction is to the beam's extension direction, and the more likely the candidate is a genuine weld line defect. The larger the directional angle, the greater the deviation, and the more likely it is interference from burrs or flash. Perform the above calculations on all weld line defect candidates one by one to obtain the directional characteristics of each candidate.
[0160] Step 75: Identify candidate specular interference and candidate fly-edge interference.
[0161] Obtain the preset interference brightness threshold, preset sharpness threshold, and preset angle threshold.
[0162] The preset interference brightness threshold is determined as follows: the average gray value of the normal beam surface in the reflection suppression image is used as the reference brightness, and the reference brightness is multiplied by a preset brightness coefficient. The product is the preset interference brightness threshold. The preset brightness coefficient ranges from 1.3 to 1.8.
[0163] The preset sharpness threshold is determined as follows: Collect statistical values of edge sharpness from known weld line defect samples, and take the 10th percentile of these statistical values as the preset sharpness threshold. If known weld line defect samples are lacking in the initial stage of system deployment, the preset sharpness threshold is initially set to 30% to 50% of the maximum gradient intensity of all pixels in the candidate region. After obtaining known weld line defect samples, it is updated based on the sample statistical values. The preset angle threshold ranges from 10°. 0 Up to 20 0 .
[0164] For each candidate fusion line defect, if the candidate's brightness characteristic is greater than a preset interference brightness threshold and its edge sharpness characteristic is less than a preset sharpness threshold, then the candidate is identified as a specular interference candidate. If the candidate's edge sharpness characteristic is greater than a preset sharpness threshold and its directional angle is greater than a preset angle threshold, then the candidate is identified as a burr interference candidate. This process is repeated for all candidate fusion lines defect, and the results are summarized to obtain a specular interference candidate set and a burr interference candidate set.
[0165] Step 76: Eliminate candidates for specular interference and burr interference to obtain the remaining candidates for weld line defects.
[0166] From the candidate set of fusion line defects, remove all candidates from the candidate set of specular interference, and then remove all candidates from the candidate set of flash interference. The remaining candidates after this process are the retained fusion line defect candidates, which are the output of step 7.
[0167] Step 8: Extract defect features from the retained weld line defect candidates, and determine whether weld line defects exist on the beam surface based on the defect features; when a weld line defect is determined to exist, output the defect detection results in real time, specifically including: Step 81: Extract the defect features of the retained weld line defect candidates.
[0168] For each retained weld line defect candidate, the defect length feature, defect depth feature, and defect consistency feature are extracted. The defect length feature is directly taken from the continuous length of the weld line defect candidate along the extension direction of the crossbeam. The larger the defect length, the more severe the weakening of the crossbeam's mechanical strength.
[0169] The method for extracting the defect depth feature is as follows: For the candidate depression points corresponding to the weld line defect candidate on each pixel sampling line, obtain the local gray-level depression intervals corresponding to each candidate depression point. Within the local gray-level depression interval, find the position with the lowest gray-level difference, i.e., the position with the largest absolute negative value. The absolute value of the gray-level difference at this position is the depth value at that pixel sampling line. The largest depth value among all depth values of the weld line defect candidate on each pixel sampling line is taken as the defect depth feature.
[0170] The method for extracting the defect consistency feature is as follows: Obtain the depth value sequence of the weld line defect candidate on each pixel sampling line, add the depth values together and divide by the number of depth values to obtain the average depth value. For each depth value, subtract the average depth value from the depth value, multiply by itself, add all the squares together, divide by the number of depth values, and take the square root. The resulting value is the standard deviation of the depth, which is used as the defect consistency feature. The smaller the standard deviation, the more uniform the indentation depth of the candidate on each cross section. Perform the above extraction operation on all retained weld line defect candidates one by one.
[0171] Step 82: Determine whether there are weld line defects on the surface of the beam based on the defect characteristics.
[0172] Get the preset length threshold, preset depth threshold, and preset consistency threshold.
[0173] The preset length threshold is determined by dividing the minimum extension length of the weld line defect that may affect the mechanical strength in the actual product by the physical size corresponding to a single pixel, thus obtaining the lower limit of the length at the pixel level. The preset length threshold ranges from 10 to 30 pixels.
[0174] The preset depth threshold is determined as follows: the standard deviation of the statistical distribution of grayscale differences on the normal beam surface in the baseline correction profile is multiplied by a preset factor, and the resulting product is the preset depth threshold. The preset factor ranges from 2 to 3. The preset depth threshold ranges from 3 to 8 grayscale levels.
[0175] The preset consistency threshold is the upper limit of the standard deviation of the depth used to determine whether the depth of the candidate depression is stable along the extension direction, and the value range is 2 to 5 gray level values.
[0176] For each retained candidate weld line defect, if its defect length is not less than a preset length threshold, its defect depth is not less than a preset depth threshold, and its defect consistency is not greater than a preset consistency threshold, then the corresponding beam surface location is determined to have a weld line defect. Simultaneously, the starting and ending boundary positions, defect length, and maximum defect depth of the defect in the beam detection area are recorded. If any one of these conditions is not met, the candidate is determined not to constitute a weld line defect. This triple-judgment process is performed on all retained weld line defect candidates one by one.
[0177] Step 83: When a weld line defect is detected, the defect detection result is output in real time.
[0178] If at least one weld line defect is determined to exist, the number of candidate defects is taken as the total number of defects. Defects are arranged in descending order of length, and the starting boundary position, ending boundary position, defect length, and maximum depth of each defect are output sequentially.
[0179] The defect detection results are sent to the production line control system through the data communication interface of the industrial control computer. The production line control system performs corresponding operations based on the detection results, such as marking and sorting injection molded parts with weld line defects, triggering audible and visual alarms, or recording them to the production quality database.
[0180] If step 82 determines that there are no defects in the fusion lines, then a normal test result is output.
[0181] After completing the detection of this frame image, the industrial control computer continues to wait for the next trigger pulse signal from the encoder and repeats steps 1 to 8 to perform real-time detection on each injection molded part that subsequently arrives on the production line.
[0182] like Figure 2 As shown, embodiments of the present invention also provide a real-time detection system for surface defects of injection molded parts based on computer vision, comprising: The acquisition module is used to acquire surface images of the surface to be inspected, including the crossbeam, in real time as the injection molded part moves with the production line; and to locate the surface image according to the preset positioning reference to determine the crossbeam detection area corresponding to the crossbeam. The processing module is used to preprocess the crossbeam detection area to obtain a reflection suppression image. In the reflection suppression image, gray value sequences are extracted along multiple pixel sampling lines perpendicular to the extension direction of the crossbeam to obtain multiple gray-scale profiles. The multiple pixel sampling lines are set at intervals along the extension direction of the crossbeam. The correction module is used to perform baseline correction on each grayscale profile to obtain a baseline correction profile. Based on the first-order grayscale change characteristics and second-order grayscale change characteristics of the baseline correction profile, candidate depression points that meet the requirements of local grayscale depression, opposite slope directions of the two sides, and depression width within a preset width range are identified. The filtering module is used to continuously correlate candidate depression points along the extension direction of the crossbeam to obtain candidate weld line defects; based on the brightness characteristics, edge sharpness characteristics and direction characteristics of the candidate weld line defects, interference filtering is performed on the candidate weld line defects to obtain the retained candidate weld line defects. The extraction module is used to extract defect features from the retained weld line defect candidates and determine whether there are weld line defects on the beam surface based on the defect features; when a weld line defect is determined to exist, the defect detection result is output in real time.
[0183] It should be noted that this system is a system corresponding to the above method. All implementation methods in the above method embodiments are applicable to this embodiment and can achieve the same technical effect.
[0184] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A real-time detection method for surface defects in injection molded parts based on computer vision, characterized in that, The method includes: As the injection molded part moves along the production line, a surface image of the surface to be inspected, including the crossbeam, is acquired in real time; the surface image is positioned according to a preset positioning reference to determine the crossbeam detection area corresponding to the crossbeam. Preprocessing is performed on the beam detection area to obtain a reflection suppression image; In the reflection-suppressed image, grayscale value sequences are extracted along multiple pixel sampling lines perpendicular to the extension direction of the beam to obtain multiple grayscale profiles; wherein, the multiple pixel sampling lines are set at intervals along the extension direction of the beam. Baseline correction is performed on each grayscale profile to obtain the baseline-corrected profile; Based on the first-order and second-order gray-scale change characteristics of the baseline correction profile, candidate depression points that meet the requirements of local gray-scale depression, opposite slope directions of the two sides, and depression width within a preset width range are identified. Candidate depression points are continuously correlated along the extension direction of the crossbeam to obtain candidate weld line defects; Based on the brightness, edge sharpness, and orientation characteristics of the weld line defect candidates, interference screening is performed on the weld line defect candidates to obtain the retained weld line defect candidates. Extract defect features from the retained weld line defect candidates, and determine whether there are weld line defects on the beam surface based on the defect features; when a weld line defect is determined to exist, output the defect detection results in real time.
2. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 1, characterized in that, The beam detection area is preprocessed to obtain a reflection suppression image, including: The detection area of the beam is converted to grayscale to obtain a grayscale image; In a grayscale image, pixel regions with grayscale values greater than a preset brightness threshold are defined as highlight regions; Perform grayscale correction on pixels in the highlight area to suppress highlight reflection; The beam detection area after grayscale correction is smoothed and filtered to obtain a reflection-suppressed image.
3. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 2, characterized in that, In the reflection-suppressed image, grayscale value sequences are extracted along multiple pixel sampling lines perpendicular to the direction of beam extension, resulting in multiple grayscale profiles, including: In the reflection suppression image, determine the beam extension direction corresponding to the beam detection area; Based on the direction of beam extension, multiple pixel sampling lines perpendicular to the direction of beam extension are determined within the beam detection area; Read the pixel grayscale value on each pixel sampling line to obtain the grayscale value sequence corresponding to each pixel sampling line; The gray value sequence corresponding to each pixel sampling line is determined as multiple gray-level profiles.
4. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 3, characterized in that, Baseline correction is performed on each grayscale profile to obtain baseline-corrected profiles, including: Each grayscale profile is fitted to obtain the baseline corresponding to each grayscale profile. Calculate the grayscale difference sequence between each grayscale profile and the corresponding baseline; Each grayscale difference sequence is determined as the corresponding baseline correction profile.
5. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 4, characterized in that, Based on the first-order and second-order gray-level variation characteristics of the baseline correction profile, candidate depression points are identified that satisfy the following conditions: local gray-level concavity, opposite slope directions on both sides of the edge, and depression width within a preset width range. These include: A first-order difference processing is performed on each baseline correction profile to obtain a first-order grayscale change sequence; A second-order difference processing is performed on each baseline correction profile to obtain a second-order grayscale change sequence; Based on the first-order gray-level change sequence, determine two edge points with opposite gray-level change directions; The local gray-level concavity region is determined based on the second-order gray-level change sequence between two edge points; Calculate the width of the depression in the local gray-level recessed area; The pixel positions corresponding to the local grayscale depression range where the depression width is within the preset width range are determined as candidate depression points.
6. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 5, characterized in that, Based on the first-order grayscale change sequence, determine two edge points with opposite grayscale change directions, including: In a first-order grayscale change sequence, determine the first change position where the grayscale change value is greater than a preset positive change threshold; In a first-order grayscale change sequence, determine the second change position where the grayscale change value is less than a preset negative change threshold; The first and second change positions, which are set at intervals along the pixel sampling line and located on both sides of the same grayscale depression, are defined as two edge points.
7. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 6, characterized in that, Calculate the width of the depression in the local gray-level recessed area, including: The starting boundary position is determined by the position of one end of the local gray-level concave region along the pixel sampling line direction of the two edge points. The position of the two edge points located at the other end of the local gray-level concave region along the pixel sampling line direction is determined as the end boundary position; Count the number of consecutive pixels between the start and end boundary positions; The number of consecutive pixels is defined as the indentation width.
8. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 7, characterized in that, By performing continuous correlation of candidate depression points along the extension direction of the crossbeam, candidate weld line defects are obtained, including: Determine the pixel position of each candidate indentation point on the corresponding pixel sampling line; Along the extension direction of the beam, candidate depression points located on different pixel sampling lines and whose pixel position deviation is less than a preset position deviation threshold are identified as associated depression points. The continuous trajectory formed by the associated indentations along the extension direction of the beam is identified as a candidate for weld line defects.
9. The real-time detection method for surface defects of injection molded parts based on computer vision according to claim 8, characterized in that, Based on the brightness, edge sharpness, and orientation characteristics of the weld line defect candidates, interference screening is performed to obtain the retained weld line defect candidates, including: Determine the candidate region corresponding to each weld line defect candidate; Calculate the average brightness of the candidate region to obtain the brightness characteristics; Calculate the gradient intensity of the candidate region edge to obtain the edge sharpness feature; Determine the directional angle between the extension direction of the candidate region and the extension direction of the crossbeam to obtain the directional features; Candidate weld line defects with brightness characteristics greater than a preset interference brightness threshold and edge sharpness characteristics less than a preset sharpness threshold are identified as specular interference candidates. Candidate weld line defects with edge sharpness features greater than a preset sharpness threshold and direction angle greater than a preset angle threshold are identified as flash interference candidates. After eliminating candidates for specular interference and flash interference, the remaining candidates for weld line defects are obtained.
10. A computer vision-based real-time surface defect detection system for injection molded parts, the system implementing the method as described in any one of claims 1 to 9, characterized in that, include: The acquisition module is used to acquire surface images of the surface to be inspected, including the crossbeam, in real time as the injection molded part moves with the production line. The surface image is located according to the preset positioning reference to determine the beam detection area corresponding to the beam; The processing module is used to preprocess the crossbeam detection area to obtain a reflection suppression image. In the reflection suppression image, gray value sequences are extracted along multiple pixel sampling lines perpendicular to the extension direction of the crossbeam to obtain multiple gray-scale profiles. The multiple pixel sampling lines are set at intervals along the extension direction of the crossbeam. The correction module is used to perform baseline correction on each grayscale profile to obtain a baseline correction profile. Based on the first-order grayscale change characteristics and second-order grayscale change characteristics of the baseline correction profile, candidate depression points that meet the requirements of local grayscale depression, opposite slope directions of the two sides, and depression width within a preset width range are identified. The filtering module is used to continuously correlate candidate depression points along the extension direction of the crossbeam to obtain candidate weld line defects; based on the brightness characteristics, edge sharpness characteristics and direction characteristics of the candidate weld line defects, interference filtering is performed on the candidate weld line defects to obtain the retained candidate weld line defects. The extraction module is used to extract defect features from the retained weld line defect candidates and determine whether there are weld line defects on the beam surface based on the defect features; when a weld line defect is determined to exist, the defect detection result is output in real time.