Injection product defect detection method based on machine vision
Through the machine vision inspection method of dynamic matching of light source parameters and multi-dimensional feature fusion, the problems of light source adaptability and feature extraction in injection molded product defect detection are solved, efficient and accurate defect identification and quantification are achieved, and the reliability and adaptability of detection are improved.
Patent Information
- Application Number
- CN202511223027.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-09-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing machine vision inspection methods have problems in defect detection of injection molded products, such as poor light source adaptability, single feature extraction, weak model generalization ability, and low defect quantification and positioning accuracy, making it difficult to achieve efficient and accurate defect identification and quantification.
By collecting material information of injection molded products in real time, dynamically matching light source parameters, combining two-dimensional edge and texture features with three-dimensional depth features, and using deep learning models to identify and quantify defects, including multi-perspective image stitching and three-dimensional model reconstruction, multi-dimensional feature fusion is achieved.
It has improved its adaptability to different materials and defect types, significantly reduced missed and false positive rates, and can accurately identify and quantify the type, quantity, and size of defects, thereby improving the reliability and accuracy of detection results.
Smart Images

Figure CN120726049A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of machine vision, and in particular relates to a method for detecting defects in injection molded products based on machine vision. Background Art
[0002] Injection molded products are widely used in the automotive, electronics, and medical device industries due to their high molding efficiency, low manufacturing costs, and flexible structural design. However, during the injection molding process, factors such as raw material properties, mold precision, and process parameters (such as temperature, pressure, and dwell time) can easily lead to surface defects such as cracks, dents, flash, bubbles, and color variations. These defects not only affect the product's appearance but can also reduce its mechanical properties and safety. Therefore, efficient and accurate defect detection for injection molded products is crucial for ensuring product quality. Traditional defect detection for injection molded products mainly relies on manual visual inspection, which has the following limitations: First, the detection efficiency is low and it is difficult to adapt to the rhythm requirements of high-speed production lines; second, the detection standards are greatly influenced by human experience and are highly subjective, making it easy to miss or misjudge; third, long-term repetitive operations can easily lead to worker fatigue, further reducing detection stability; fourth, it is impossible to accurately quantify parameters such as the size and location of defects, making it difficult to support the optimization and improvement of production processes. To overcome the shortcomings of manual inspection, automated inspection technology has gradually been applied to the quality inspection of injection molded products. Among them, machine vision inspection technology has become a research hotspot due to its non-contact, high efficiency, and quantifiable characteristics. Existing machine vision inspection methods generally include image acquisition, preprocessing, feature extraction, and defect recognition. However, in practical applications, there are still many technical bottlenecks: Poor light source adaptability: Injection molded products made of different materials have differentiated spectral reflectance characteristics. Fixed light source parameters make it difficult to ensure the clarity and contrast of images of various products, resulting in insufficient ability to capture low-contrast defects (such as fine scratches and slight color differences). Single feature extraction: Most methods rely solely on surface features such as edges and textures of two-dimensional images to judge defects, ignoring the three-dimensional information of defects. It is difficult to distinguish defects that are similar in plane but have significant differences in three-dimensional features, and the detection accuracy is limited.
[0003] Weak model generalization: Traditional machine learning algorithms (such as support vector machines and decision trees) rely heavily on feature engineering. When faced with complex and diverse defect types (such as mixed defects of cracks and flash), classification performance is easily affected by the rationality of feature design. Furthermore, existing deep learning models often use single-modal feature inputs, making it difficult to effectively integrate the complementary information of two-dimensional and three-dimensional features, resulting in insufficient adaptability to new types of defects. Low defect quantification and positioning accuracy: Existing methods often calculate defect size based on pixel conversion of two-dimensional images, lacking spatial correlation with three-dimensional models, making it difficult to accurately obtain the actual physical size of the defect (such as volume and surface area). Furthermore, defect location often relies on image coordinates, which are not precisely aligned with the product's three-dimensional coordinate system, hindering targeted optimization of subsequent mold repairs, process adjustments, and other steps. Therefore, there is an urgent need to improve the existing inspection methods for injection molded products in order to provide a machine vision inspection method that can adaptively match light source parameters, integrate multi-dimensional features, and achieve accurate identification and quantification of defects, thereby improving the quality inspection level of injection molded products. Summary of the Invention
[0004] The purpose of the present invention is to provide a method for defect detection of injection molded products based on machine vision, which is used to improve the existing detection method for injection molded products, so as to provide a machine vision detection method that can adaptively match light source parameters, integrate multi-dimensional features, and realize accurate identification and quantification of defects, thereby improving the quality inspection level of injection molded products.
[0005] In order to solve the above technical problems, the technical solutions adopted by the present invention are as follows: A method for detecting defects in injection molded products based on machine vision comprises the following steps: S1: Real-time acquisition of material information of the injection molded product to be inspected, dynamic matching of light source parameters according to the corresponding spectral reflectance characteristics of the material information, and adjustment of the light source of the image acquisition module based on the light source parameters; S2: The image acquisition module after light source adjustment acquires images of the injection molded product to be inspected and pre-processes the acquired image data; S3: Extract edge features from the image using an edge detection algorithm, extract texture features from the image using a texture feature extraction algorithm, construct a 3D model of the product by stitching multiple viewpoint images, and extract 3D features from the 3D model; S4: Input the extracted multi-dimensional features into the constructed deep learning model, and use the deep learning model to determine whether the injection molded product to be inspected has defects. If so, execute step S5; S5: Obtain the category of defects existing in the injection molded product to be inspected, and calculate the number and size of the defects; S6: Generate a defect detection report for the injection molded product to be inspected based on the defect category, defect quantity, and defect size.
[0006] Preferably, the specific process of step S1 is as follows: S11: Collect standard samples of various injection molding product materials, establish a material-spectral feature mapping library, store the reflectance data and characteristic wavelength range of different materials in the wavelength range of 380-1050nm, and pre-calibrate the optimal light source parameter combination including wavelength and intensity for each material as the initial reference value for dynamic adjustment; S12: Conduct non-contact spectral detection to obtain the reflectance spectrum curve of the area to be detected in real time; simultaneously collect the texture characteristics of the product surface, and extract the visual feature parameters of the material through the image preprocessing module to assist in the rapid identification of the material type; S13: Compare the real-time collected spectral curve with the preset material-spectral feature mapping library, and use the dynamic time warping algorithm to calculate the similarity of the spectral curve to determine the material type of the product to be tested; S14: Analyze the spectral reflectance characteristics of the material: identify the characteristic wavelength range and the trend of reflectivity changing with wavelength; S15: Based on the spectral characteristics of the material, the wavelength with a reflectivity of ≥70% within the characteristic wavelength range is preferentially selected as the main wavelength of the light source. The light source intensity is adjusted based on the product surface brightness feedback; S16: The spectrum analysis module converts the matched light source parameters into a control signal and sends it to the tunable light source drive circuit. The tunable light source drive circuit controls the working state of the laser light source: continuous wavelength adjustment within the range of 380-1050nm is achieved through the wavelength switching module to adjust the light source intensity.
[0007] Preferably, the specific process of preprocessing the collected image data in step S2 is as follows: S21: Convert the collected image data into a 3-channel RGB format and perform geometric correction on the image. By identifying the product edge or positioning mark, the image tilt caused by the shooting angle deviation is corrected. S22: converting the color image into a grayscale image using an improved weighted average method, normalizing the grayscale image, and compressing the pixel values to the interval [0, 255]; S23: Detect edge areas and flat areas in the image, distinguish high-detail areas and background areas where defects may exist, and perform filtering processing; S24: Separate the illumination component and the reflection component of the image, suppress low-frequency illumination changes through logarithmic transformation and Fourier transform, enhance high-frequency defect features, and perform local brightness compensation on the corrected image.
[0008] Preferably, the specific process of step S3 is as follows: S31: Using the improved Canny algorithm, initial edges are extracted through dynamic threshold calculation, retaining the edge contours of subtle defects such as cracks and burrs, and morphological processing is performed on the initial edges. Straight and curved edges are detected through Hough transform, broken defect edges are connected, and valid edges with a length of ≥5 pixels are selected as boundary features of the defect candidate area. S32: Using edge features as boundaries, the image is divided into several regions of interest (ROIs). Within each ROI, the gray-level co-occurrence matrix features (GLCM) in four specified directions are calculated to extract four core features: energy, entropy, contrast, and correlation. The circular LBP operator is used to extract local pattern features of the texture. The distribution frequency of different patterns is statistically analyzed through histograms to capture texture variations caused by surface scratches and depressions. S33: The SIFT algorithm is used to extract feature points from each view image. The FLANN matcher is used to match feature points across views. Based on the matched feature point pairs, the PNP algorithm is used to calculate the extrinsic parameters of each camera. The spatial pose relationship between multiple views is established. A patch-based multi-view stereo matching algorithm is used to generate a dense point cloud of the product surface. The dense point cloud is then reconstructed using Poisson curves to generate a 3D model. S34: Perform ICP registration on the 3D model and a standard 3D model without defects, calculate the spatial deviation between the models, and calculate the depth deviation value of each vertex on the registered model. When the absolute value of the deviation exceeds a preset threshold, it is marked as a suspected defect area; S35: Depth feature: Calculate the maximum depth, average depth, and depth gradient of the defect area; Volume feature: Calculate the volume of the defect area through three-dimensional grid integration; Surface area feature: Calculate the actual surface area of the defect area in three-dimensional space.
[0009] Preferably, the process of determining whether there is a defect in step S4 is as follows: S41: Input the pre-processed multi-dimensional features, calculate the defect probability through the forward propagation of the deep learning model, and output the defect probability value P. When P ≥ 0.85, it is determined to be a suspected defective product. The process of calculating the defect probability is as follows: S42: Dynamically weighted fusion of multi-dimensional features is achieved through the attention mechanism, and the similarity matrix of two-dimensional features and three-dimensional features is calculated; attention weights are obtained through Softmax normalization, and the fused features = original two-dimensional features + original three-dimensional features; S43: Map the 128-dimensional fusion features to 32-dimensional features, activate them through ReLU, map the 32-dimensional features to 1-dimensional features, and output the logit value. The logit value is the logarithmic probability, which is the original value of the model output layer before passing through the activation function. It is an intermediate variable used to calculate the final probability. The logit value is converted into the probability P of a defect. The formula is: P=1 / (1+e −logit), when P>85%, it is determined that there is a defect.
[0010] Preferably, the specific process of obtaining the category of defects existing in the injection molded product to be inspected and calculating the size of the defects in step S5 is as follows: S51: The probability of each category of defects is output through the fully connected layer of the parallel branch of the model. The calculation formula is: Pi=e logit (i) / (e logit(1) +e logit(2) +···e logit(N) ), where Pi is the probability of the i-th type of defect, N is the number of defect categories, and logit(N) is the logit value of the N-th type of defect; S52: Defect categories with defect probabilities greater than 85% are selected as defect categories of the injection molded products to be inspected, and the number of defects in each category is counted; S53: Obtain pixel equivalents through camera calibration, segment the preprocessed image based on the semantic segmentation model U-Net++, output a binary mask of the defect area, and obtain a mask image. Use the cv2.findContours algorithm to extract the contours of the mask image, calculate the minimum bounding rectangle of each defect area, filter out noise areas with an area of less than 5×5 pixels, and retain valid defect candidate boxes; align the point cloud of the injection molded product to be inspected with the standard defect-free point cloud through point cloud registration, and select a subset of point clouds with depth deviation exceeding a preset threshold as the 3D defect area; S54: Calculation of defect two-dimensional dimensions: including defect area, defect length and width, and defect perimeter; S55: Calculation of three-dimensional defect dimensions: including defect depth and defect volume.
[0011] Preferably, the defect two-dimensional size calculation process in step S54 is as follows: The defect area is calculated by counting the total number of pixels in the defect area and multiplying it by the actual area of a single pixel. The specific formula is S = number of pixels in the defect area × k², where k is the pixel equivalent. For linear defects, the defect outline is fitted with a minimum circumscribed rectangle, with the long side of the rectangle as the length and the short side as the width. The length and width of the linear defect are calculated using L = number of pixels on the long side of the circumscribed rectangle × k and W = number of pixels on the short side of the circumscribed rectangle × k. The pixel perimeter is obtained using the arc length function of the contour and converted to actual length: C = pixel perimeter × k.
[0012] Preferably, the process of calculating the three-dimensional size of the defect in step S55 is as follows: S551: Defect depth: Calculate the depth difference between each point in the defect area and the corresponding point of the standard model, take the average value as the defect depth, and align the actual point cloud (P) with the standard defect-free point cloud (P0) through the ICP algorithm to obtain the corresponding point pair (p i , p0i ), pᵢ∈P,p 0i ∈P0, calculate the depth deviation: h i =|p i ·z- p 0i z|, z is the height axis of the three-dimensional coordinate system; average depth of the defect: H avg =mean(hᵢ); S552: Defect volume: For concave / convex defects, the defect point cloud is divided into tiny cube grids with a side length of Δ=0.01mm, and the sum of all grid volumes is calculated: V=Σ(Δ 2 ×H avg ), H avg is the average depth within the grid, and the defect volume is obtained.
[0013] The beneficial effects of the present invention include: The machine vision-based defect detection method for injection molded products provided by this invention first dynamically matches light source parameters and adjusts the light source according to the spectral reflectance characteristics of different materials. This ensures that the captured image is clear and the contrast between the defect area and the background is high, laying a good foundation for subsequent feature extraction. Simultaneously, it integrates two-dimensional edge and texture features with three-dimensional depth, volume, and surface area features to characterize defects in multiple dimensions, significantly reducing the rates of missed and false positives. In particular, it significantly improves the accuracy of identifying subtle defects, making detection results more reliable. Secondly, it enhances the adaptability to different materials and defect types: by establishing a material-spectral feature mapping library and optimizing it through incremental learning, it can quickly and accurately identify the material of the product to be inspected, and then dynamically adjust the light source parameters to meet the inspection needs of various common injection molding materials such as PP, PE, ABS, and PC.
[0014] Finally, defect information can be accurately quantified to provide data support for quality analysis: it can not only identify the type and quantity of defects, but also accurately calculate the two-dimensional dimensions (area, length, width, perimeter) and three-dimensional dimensions (depth, volume) of the defects, realizing the quantification of defect information. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 Schematic diagram of the process of the present invention for detecting defects in injection molded products based on machine vision.
[0016] Figure 2 This is a circuit diagram of the tunable light source drive of the present invention. DETAILED DESCRIPTION
[0017] The following is combined with Figure 1~Figure 2 The present invention is described in further detail: Example 1 See attached Figure 1As shown, a method for detecting defects in injection molded products based on machine vision, a method for detecting defects in injection molded products based on machine vision, comprising the following steps: S1: Real-time collection of material information of the injection molded product to be inspected, dynamic matching of light source parameters according to the corresponding spectral reflectance characteristics of the material information, and adjustment of the light source of the image acquisition module based on the light source parameters. The specific process is as follows: S11: Collect standard samples of various injection molding product materials such as PP, PE, ABS, and PC, obtain their basic spectral reflectance characteristic curves through an infrared spectrometer or a Raman spectrometer, establish a material-spectral feature mapping library, and store the reflectance data and characteristic wavelength ranges of different materials in the wavelength range of 380-1050nm. For example, ABS material has a characteristic reflection peak at 600-700nm; for each material, pre-calibrate the optimal light source parameter combination including wavelength and intensity as the initial reference value for dynamic adjustment.
[0018] S12: The micro-spectral sensor integrated in the image acquisition module performs non-contact spectral detection on the product surface, and obtains the reflective spectrum curve of the area to be detected in real time. The texture features of the product surface, including roughness and color saturation, are simultaneously collected, and the visual feature parameters of the material are extracted through the image preprocessing module to assist in the rapid identification of the material type.
[0019] S13: Compare the real-time collected spectral curve with the preset material-spectral feature mapping library, and use the dynamic time warping (DTW) algorithm to calculate the similarity of the spectral curves. When the similarity is ≥95%, the material type of the product to be tested is determined.
[0020] S14: Analyze the spectral reflectance characteristics of the material: identify characteristic wavelength ranges (such as high reflectance bands, absorption bands), and reflectance variation trends with wavelength (such as linear growth, band jumps), providing a basis for adjusting light source parameters.
[0021] S15: Based on the spectral characteristics of the material, a wavelength with a reflectivity of ≥70% within the characteristic wavelength range is preferentially selected as the main wavelength of the light source to ensure that the reflection difference between defective areas (such as scratches and dents) and normal areas is maximized. Based on the product surface brightness feedback (the average grayscale value monitored in real time by the image acquisition module), a PID closed-loop control algorithm is used to adjust the light source intensity: when the average grayscale value is lower than the preset threshold (such as 50), the intensity is linearly increased; when the grayscale value is higher than the threshold (such as 200), the intensity is stepped down until the grayscale value stabilizes in the range of 80-150.
[0022] S16: The spectrum analysis module converts the matched light source parameters (wavelength, intensity) into a control signal and sends it to the tunable light source driver circuit. The tunable light source driver circuit controls the working state of the laser light source: continuous wavelength adjustment within the range of 380-1050nm is achieved through the wavelength switching module, and the light source intensity is adjusted through pulse width modulation (PWM) technology. During the adjustment process, the image acquisition device synchronously captures the test image and verifies the light source effect in real time through the edge clarity evaluation function (such as the Tenengrad gradient operator). If the edge clarity score is less than 80 points, repeat steps 4-5 for secondary adjustment.
[0023] Once the light source parameters stabilize (grayscale standard deviation of three consecutive frames <5), the formal image acquisition process is triggered to ensure that the captured images meet the clarity and contrast requirements for defect detection (contrast between the defect area and the background ≥30%). The adjusted light source parameters are associated with the material type and stored, and the dynamic adjustment record in the material-spectral feature mapping library is updated. Subsequent matching accuracy is optimized through an incremental learning algorithm, and the matching accuracy of similar materials is improved by ≥0.5% after each adjustment.
[0024] In another embodiment of this embodiment, see Figure 2 As shown, the tunable light source driving circuit includes first to fifth resistors, first to third capacitors, and an operational amplifier. The first capacitor and the first resistor are both connected to the light source driving associated signal input terminal, the second resistor is connected in series with the first capacitor and then connected to the second capacitor and the third capacitor, the other end of the first resistor is also connected to the second capacitor and the third capacitor, the fourth resistor is connected to the second voltage input terminal, the fourth resistor is grounded through the fifth resistor, the fourth resistor is connected to the inverting input terminal of the operational amplifier through the external tuning input terminal, and the non-inverting input terminal of the operational amplifier is connected to the reference voltage terminal.
[0025] In this circuit, the operational amplifier (OPA) serves as the core of error detection and amplification, comparing the input signal with a reference value and outputting a control signal. The reference voltage (VREF) serves as the anchor point for the tuning target. Ve is the external tuning input, accepting a variable voltage and serving as the entry point for the tuning operation. V0 is the light source driver-related signal, reflecting the light source's actual operating status.
[0026] 1. Initial State: The system is stable at its initial operating point. Assuming the circuit is operating stably, the voltage at the VFB node equals VREF, the reference value at the op amp's non-inverting terminal. At this point, the error is zero. The op amp's output, COMP, is stable. The light source operates with its initial parameters. If Ve is fixed, the system maintains this state. When the light source needs to be adjusted, Ve is adjusted, and tuning begins. A change in Ve disrupts the original equilibrium. Ve is added to the VFB node through R4. The VFB voltage changes. An increase in Ve causes VFB to increase. At this point, VFB ≠ VREF. The op amp detects an error signal, and the tuning process begins. Error Amplification: The op amp outputs a control signal, COMP. The core function of an op amp is to compare and amplify the error. The op amp's non-inverting terminal is connected to VREF (a fixed reference), and its inverting terminal is connected to the actual signal, VFB, containing the error. The error signal (VFB - VREF) is amplified by the op amp. The output, COMP, changes. An increase in VFB adjusts the COMP voltage. The specific direction depends on the op amp type; generally, an inverting input causes the output to change in the opposite direction. Feedback Correction: VFB is adjusted through the RC network to stabilize the new operating point. The COMP output acts inversely on the VFB node through the feedback network formed by C2 / R3 and C1 / R2. If VFB exceeds VREF due to an increase in Ve, the op amp output COMP is adjusted, which is fed back through C2 / R3 and C1 / R2, lowering the VFB voltage and bringing VFB closer to VREF. If VFB falls below VREF due to a decrease in Ve, the op amp output COMP is reversed, raising VFB again towards VREF. During this process, C1 / C2 act as high-frequency compensation capacitors, suppressing signal noise, compensating for phase shift, preventing circuit self-oscillation, and ensuring a stable tuning process. A new steady-state is established: The light source parameters stabilize at the tuned state. When VFB approaches VREF again after feedback correction, the op amp error signal approaches 0, the COMP output stabilizes, the feedback network reaches a new equilibrium with the input signal, and the system enters a new steady-state, indicating that the light source emits light at a different wavelength. At this point, the light source driving parameters have been adjusted as Ve changes, and due to the existence of feedback, the new parameters will be stably maintained, achieving stable operation after tuning.
[0027] S2: The image acquisition module after light source adjustment acquires images of the injection molded product to be inspected and preprocesses the acquired image data. The specific preprocessing process is as follows: Example 2 Based on Example 1, the specific process of step S2 is as follows: S21: uniformly converting the collected image data into a 3-channel RGB format, adjusting the resolution to a preset size (e.g., 1280×960 pixels) to ensure consistency in subsequent processing, and performing geometric correction on the image to correct image tilt caused by shooting angle deviation by identifying product edges or positioning marks; S22: Convert the color image to a grayscale image using an improved weighted averaging method using the formula: Gray = 0.35 × R + 0.45 × G + 0.2 × B (weights are optimized based on the common color characteristics of injection molded products). The grayscale difference between defective areas and normal areas is retained. The grayscale image is normalized, compressing pixel values to the range [0, 255] to eliminate overall brightness deviations caused by light intensity fluctuations. S23: The Laplacian operator is used to detect edge and flat areas in the image, distinguishing between high-detail areas and background areas where defects may exist. A 5×5 Gaussian filter (standard deviation σ = 1.2) is applied to flat areas to remove random noise. A bilateral filter (spatial standard deviation = 10, grayscale standard deviation = 20) is applied to edge areas to reduce noise while preserving defect edge details. To address the salt and pepper noise common in injection molded products, a median filter (3×3 kernel) is additionally introduced for secondary cleanup to ensure a noise removal rate of ≥ 90%. S24: A homomorphic filtering algorithm is used to separate the illumination and reflection components of the image. Logarithmic and Fourier transforms are used to suppress low-frequency illumination variations and enhance high-frequency defect features. Local brightness compensation is performed on the corrected image: the image is divided into 16×16 subregions, the average grayscale value of each subregion is calculated, and dynamic gain adjustment (gain range 0.5-2.0) is used to make the brightness of each region consistent (grayscale difference between regions ≤ 15).
[0028] S3: Extract edge features from the image using an edge detection algorithm, extract texture features from the image using a texture feature extraction algorithm, construct a 3D model of the product by stitching multiple viewpoint images, and extract 3D features from the 3D model; S31: An improved Canny algorithm is used to extract initial edges through dynamic threshold calculation (high threshold = 0.3 × maximum gradient, low threshold = 0.1 × maximum gradient). The edge contours of subtle defects such as cracks and burrs are retained. Morphological processing (erosion-dilation of 3 × 3 structural elements) is performed on the initial edges to remove isolated noise points. Straight and curved edges are detected through Hough transform, and broken defect edges (such as microcracks) are connected. Edge parameters such as length, curvature, and orientation angle are calculated. Valid edges with a length of 5 pixels or more are selected as boundary features of candidate defect areas. S32: Using edge features as boundaries, the image is divided into several regions of interest (ROIs), including normal areas and suspected defect areas. Within each ROI, the gray-level co-occurrence matrix features (GLCM) are calculated in four directions (0°, 45°, 90°, and 135°). Four core features, energy (reflecting texture uniformity), entropy (reflecting complexity), contrast (reflecting clarity), and correlation (reflecting local gray-level correlation), are extracted. The distance parameter is set to 1-3 pixels. Local binary pattern (LBP) features: A circular LBP operator (radius 3 pixels, 8 sampling points) is used to extract local texture patterns. The distribution frequency of different patterns is statistically analyzed through histograms to capture texture variations caused by surface scratches, dents, etc. S33: The SIFT algorithm is used to extract feature points from each view image (≥500 per image). Cross-view feature point matching is performed using the FLANN matcher. Mismatched points are removed using the RANSAC algorithm. Based on the matched feature point pairs, the PNP algorithm is used to calculate the extrinsic parameters (rotation matrix and translation vector) of each camera view. The spatial pose relationship between the multiple views is established. A patch-based multi-view stereo matching (PMVS) algorithm is used to generate a dense point cloud of the product surface (point cloud density ≥100 points / mm²). The point cloud coordinate accuracy is controlled to ±0.01mm. The dense point cloud is reconstructed using Poisson curves to generate a textured 3D mesh model. Bilateral filtering is used to smooth the model surface (preserving the concave and convex features of the defect area) and remove pseudo-defects caused by point cloud noise. S34: Perform ICP (Iterative Closest Point) registration on the reconstructed 3D model and the defect-free standard 3D model with an alignment accuracy of ≤0.02mm. Calculate the spatial deviation between the models. On the registered model, calculate the depth deviation value (actual depth - standard depth) of each vertex. When the absolute value of the deviation exceeds a preset threshold (e.g., 0.05mm), it is marked as a suspected defect area. S35: Depth feature: Calculates the maximum depth, average depth, and depth gradient of the defect area (reflecting the steepness of the defect); Volume feature: Calculates the volume of the defect area through three-dimensional grid integration (applicable to concave and convex defects); Surface area feature: Calculates the actual surface area of the defect area in three-dimensional space (different from the two-dimensional projection area).
[0029] The 3D depth features are cross-validated with the 2D edge / texture features. If the overlap rate between the 2D defect area and the 3D depth anomaly area is ≥80%, it is confirmed as a real defect.
[0030] S4: Input the extracted multi-dimensional features into the constructed deep learning model, and use the deep learning model to determine whether the injection molded product to be inspected has defects. If so, execute step S5.
[0031] The process of determining whether there is a defect in step S4 is as follows: Input the preprocessed multi-dimensional features, calculate the defect probability through the forward propagation of the deep learning model, and output the defect probability value P. When P ≥ 0.85, it is determined to be a suspected defective product. The process of calculating the defect probability is as follows: The attention mechanism is used to dynamically weight the fusion of two-dimensional features (including edge features and texture features) and three-dimensional features (including depth features, volume features, and surface area features). This highlights features that contribute significantly to defect recognition and calculates the similarity matrix between two-dimensional features (128 dimensions) and three-dimensional features (128 dimensions). Softmax normalization is used to obtain attention weights (the weight of two-dimensional features on three-dimensional features, α, and the weight of three-dimensional features on two-dimensional features, β). Fusion feature = α × 2D feature + β × 3D feature, the fusion feature is 128-dimensional (shape: [1, 128]); Introducing residual connection: fusion feature = original 2D feature + original 3D feature to avoid feature information loss; Fully connected layer 1: maps the 128-dimensional fusion features to 32-dimensional features and activates them through ReLU; Fully connected layer 2: maps 32-dimensional features to 1-dimensional features and outputs logit values. Logit values are the original values of the model output layer before passing through the activation function and are intermediate variables used to calculate the final probability. Convert the logit value to the probability P of a defect (range 0-1), formula: P=1 / (1+e −logit ), when P>85%, it is determined that there is a defect; for example, when logit=2.197, P=0.9 (indicating a 90% probability of being determined to be defective).
[0032] S5: Obtain the category of defects existing in the injection molded product to be inspected, and calculate the number and size of the defects.
[0033] The specific process of step S5 for obtaining the category of defects in the injection molded product to be inspected and calculating the size of the defects is as follows: S51: The probability of each category of defects is output through the fully connected layer of the parallel branch of the model. The calculation formula is: Pi=e logit (i) / (e logit(1) +e logit(2) +···e logit(N) ), where Pi is the probability of the i-th type of defect, N is the number of defect categories, and logit(N) is the logit value of the N-th type of defect; S52: Defect categories with defect probabilities greater than 85% are selected as defect categories of the injection molded products to be inspected, and the number of defects in each category is counted; S53: Obtain pixel equivalent through camera calibration, that is, the actual length corresponding to 1 pixel, in units of mm / pixel; Pixel-level segmentation: Segment the preprocessed image based on the semantic segmentation model U-Net++, output a binary mask of the defect area (defect area pixel value = 1, background = 0), and obtain a mask image; Candidate frame generation: Use the cv2.findContours algorithm to extract the contours of the mask image, calculate the minimum bounding rectangle of each defect area, filter out noise areas with an area of less than 5×5 pixels, and retain valid defect candidate frames; 3D region association: The actual product point cloud is aligned with the standard defect-free point cloud through point cloud registration (ICP algorithm), and a subset of point clouds with depth deviation exceeding a preset threshold (such as 0.05mm) is selected as the 3D defect area. S54: Calculation of defect two-dimensional dimensions: including defect area, defect length and width, and defect perimeter; S55: Calculation of three-dimensional defect dimensions: including defect depth and defect volume.
[0034] The process of calculating the two-dimensional size of the defect in step S54 is as follows: The defect area is calculated by counting the total number of pixels in the defect area and multiplying it by the actual area of a single pixel. The specific formula is S = number of pixels in the defect area × k², where k is the pixel equivalent. For linear defects, the defect contour is fitted with a minimum enclosing rectangle, with the long side of the rectangle as the length and the short side as the width. The length and width of the linear defect are calculated using L = number of pixels on the long side of the enclosing rectangle × k and W = number of pixels on the short side of the enclosing rectangle × k. The pixel perimeter is obtained using the contour arc length function cv2.arcLength and then converted to actual length: C = pixel perimeter × k.
[0035] The process of calculating the three-dimensional size of the defect in step S55 is as follows: S551: Defect depth: Calculate the depth difference (Z-axis deviation) between each point in the defect area and the corresponding point of the standard model, and take the average value as the defect depth (Use the ICP algorithm to align the actual point cloud (P) with the standard defect-free point cloud (P0) to obtain the corresponding point pair (p i , p 0i ), pᵢ∈P,p 0i ∈P0, calculate the depth deviation: h i =|p i ·z- p 0i z|, z is the height axis of the three-dimensional coordinate system; average depth of the defect: H avg =mean(hᵢ); S552: Defect volume: For concave / convex defects, the defect point cloud is divided into tiny cube grids with a side length of Δ=0.01mm, and the sum of all grid volumes is calculated: V=Σ(Δ 2 ×H avg ), H avg is the average depth within the grid, and the defect volume is obtained.
[0036] S6: Generate a defect detection report for the injection molded product to be inspected based on the defect category, defect quantity, and defect size.
[0037] In summary, the method for defect detection of injection molded products based on machine vision provided by the present invention dynamically matches light source parameters and adjusts the light source according to the spectral reflectance characteristics of different materials to ensure that the collected image is clear and the contrast between the defect area and the background is high, laying a good foundation for subsequent feature extraction. At the same time, by integrating two-dimensional edge and texture features with three-dimensional depth, volume, and surface area features, defects are portrayed in multiple dimensions, which greatly reduces the missed judgment and misjudgment rates, especially the recognition accuracy of subtle defects is significantly improved, making the detection results more reliable. Enhanced adaptability to different materials and defect types: By establishing a material-spectral feature mapping library and optimizing through incremental learning, it can quickly and accurately identify the material of the product to be detected, and then dynamically adjust the light source parameters to adapt to the detection needs of various common injection molding materials such as PP, PE, ABS, PC, etc. Accurately quantify defect information to provide data support for quality analysis, not only can it identify the type and quantity of defects, but it can also accurately calculate the two-dimensional and three-dimensional sizes of defects), realizing accurate quantification of defect information.
Claims
1. A method for detecting defects in injection molded products based on machine vision, characterized in that: The following steps are involved: S1: Real-time acquisition of material information of the injection molded product to be inspected, dynamic matching of light source parameters according to the corresponding spectral reflectance characteristics of the material information, and adjustment of the light source of the image acquisition module based on the light source parameters; S2: The image acquisition module after light source adjustment acquires images of the injection molded product to be inspected and pre-processes the acquired image data; S3: Extract edge features from the image using an edge detection algorithm, extract texture features from the image using a texture feature extraction algorithm, construct a 3D model of the product by stitching multiple viewpoint images, and extract 3D features from the 3D model; S4: Input the extracted multi-dimensional features into the constructed deep learning model, and use the deep learning model to determine whether the injection molded product to be inspected has defects. If so, execute step S5; S5: Obtain the category of defects existing in the injection molded product to be inspected, and calculate the number and size of the defects; S6: Generate a defect detection report for the injection molded product to be inspected based on the defect category, defect quantity, and defect size.
2. The method for detecting defects in injection molded products based on machine vision according to claim 1, characterized in that: The specific process of step S1 is as follows: S11: Collect standard samples of various injection molding product materials, establish a material-spectral feature mapping library, store the reflectance data and characteristic wavelength range of different materials in the wavelength range of 380-1050nm, and pre-calibrate the optimal light source parameter combination including wavelength and intensity for each material as the initial reference value for dynamic adjustment; S12: Conduct non-contact spectral detection to obtain the reflectance spectrum curve of the area to be detected in real time; simultaneously collect the texture characteristics of the product surface, and extract the visual feature parameters of the material through the image preprocessing module to assist in the rapid identification of the material type; S13: Compare the real-time collected spectral curve with the preset material-spectral feature mapping library, and use the dynamic time warping algorithm to calculate the similarity of the spectral curve to determine the material type of the product to be tested; S14: Analyze the spectral reflectance characteristics of the material: identify the characteristic wavelength range and the trend of reflectivity changing with wavelength; S15: Based on the spectral characteristics of the material, the wavelength with a reflectivity of ≥70% within the characteristic wavelength range is preferentially selected as the main wavelength of the light source. The light source intensity is adjusted based on the product surface brightness feedback; S16: The spectrum analysis module converts the matched light source parameters into a control signal and sends it to the tunable light source drive circuit. The tunable light source drive circuit controls the working state of the laser light source: continuous wavelength adjustment within the range of 380-1050nm is achieved through the wavelength switching module to adjust the light source intensity.
3. The method for detecting defects in injection molded products based on machine vision according to claim 1, characterized in that: The specific process of preprocessing the collected image data in step S2 is as follows: S21: Convert the collected image data into a 3-channel RGB format and perform geometric correction on the image. By identifying the product edge or positioning mark, the image tilt caused by the shooting angle deviation is corrected. S22: converting the color image into a grayscale image using an improved weighted average method, normalizing the grayscale image, and compressing the pixel values to the interval [0, 255]; S23: Detect edge areas and flat areas in the image, distinguish high-detail areas and background areas where defects may exist, and perform filtering processing; S24: Separate the illumination component and the reflection component of the image, suppress low-frequency illumination changes through logarithmic transformation and Fourier transform, enhance high-frequency defect features, and perform local brightness compensation on the corrected image.
4. The method for detecting defects in injection molded products based on machine vision according to claim 1, wherein: The specific process of step S3 is as follows: S31: Using the improved Canny algorithm, the initial edge is extracted through dynamic threshold calculation, the edge contours of subtle defects such as cracks and burrs are retained, and the initial edge is morphologically processed. The straight / curved edges are detected through Hough transform, the broken defect edges are connected, and valid edges with a length of ≥5 pixels are selected as the boundary features of the defect candidate area. S32: Using edge features as boundaries, the image is divided into several regions of interest (ROIs). Within each ROI, the gray-level co-occurrence matrix features (GLCM) in four specified directions are calculated to extract four core features: energy, entropy, contrast, and correlation. The circular LBP operator is used to extract local pattern features of the texture. The distribution frequency of different patterns is statistically analyzed through histograms to capture texture variations caused by surface scratches and depressions. S33: The SIFT algorithm is used to extract feature points from each view image. The FLANN matcher is used to match feature points across views. Based on the matched feature point pairs, the PNP algorithm is used to calculate the extrinsic parameters of each camera. The spatial pose relationship between multiple views is established. A patch-based multi-view stereo matching algorithm is used to generate a dense point cloud of the product surface. The dense point cloud is then reconstructed using Poisson curves to generate a 3D model. S34: Perform ICP registration on the 3D model and a standard 3D model without defects, calculate the spatial deviation between the models, and calculate the depth deviation value of each vertex on the registered model. When the absolute value of the deviation exceeds a preset threshold, it is marked as a suspected defect area; S35: Depth feature: Calculate the maximum depth, average depth, and depth gradient of the defect area; Volume feature: Calculate the volume of the defect area through 3D grid integration; Surface Area Feature: Calculates the actual surface area of the defect region in three-dimensional space.
5. The method for detecting defects in injection molded products based on machine vision according to claim 1, wherein: The process of determining whether there is a defect in step S4 is as follows: S41: Input the pre-processed multi-dimensional features, calculate the defect probability through the forward propagation of the deep learning model, and output the defect probability value P. When P ≥ 0.85, it is determined to be a suspected defective product. The process of calculating the defect probability is as follows: S42: Dynamically weighted fusion of multi-dimensional features is achieved through the attention mechanism, and the similarity matrix of two-dimensional features and three-dimensional features is calculated; attention weights are obtained through Softmax normalization, and the fused features = original two-dimensional features + original three-dimensional features; S43: Map the 128-dimensional fusion features to 32-dimensional features, activate them through ReLU, map the 32-dimensional features to 1-dimensional features, and output the logit value. The logit value is the logarithmic probability, which is the original value of the model output layer before passing through the activation function. It is an intermediate variable used to calculate the final probability. The logit value is converted into the probability P of a defect. The formula is: P=1 / (1+e −logit ), when P>85%, it is determined that there is a defect.
6. The method for detecting defects in injection molded products based on machine vision according to claim 5, characterized in that: The specific process of step S5 for obtaining the category of defects in the injection molded product to be inspected and calculating the size of the defects is as follows: S51: The probability of each category of defects is output through the fully connected layer of the parallel branch of the model. The calculation formula is: Pi=e logit(i) / (e logit(1) +e logit(2) +···e logit(N) ), where Pi is the probability of the i-th type of defect, N is the number of defect categories, and logit(N) is the logit value of the N-th type of defect; S52: Defect categories with defect probabilities greater than 85% are selected as defect categories of the injection molded products to be inspected, and the number of defects in each category is counted; S53: Obtain pixel equivalents through camera calibration, segment the preprocessed image based on the semantic segmentation model U-Net++, output a binary mask of the defect area, and obtain a mask image. Use the cv2.findContours algorithm to extract the contours of the mask image, calculate the minimum bounding rectangle of each defect area, filter out noise areas with an area of less than 5×5 pixels, and retain valid defect candidate boxes; align the point cloud of the injection molded product to be inspected with the standard defect-free point cloud through point cloud registration, and select a subset of point clouds with depth deviation exceeding a preset threshold as the 3D defect area; S54: Calculation of defect two-dimensional dimensions: including defect area, defect length and width, and defect perimeter; S55: Calculation of three-dimensional defect dimensions: including defect depth and defect volume.
7. The method for detecting defects in injection molded products based on machine vision according to claim 6, characterized in that: The process of calculating the two-dimensional size of the defect in step S54 is as follows: The defect area is calculated by counting the total number of pixels in the defect area and multiplying it by the actual area of a single pixel. The specific formula is S = number of pixels in the defect area × k², where k is the pixel equivalent. For linear defects, the defect outline is fitted with a minimum circumscribed rectangle, with the long side of the rectangle as the length and the short side as the width. The length and width of the linear defect are calculated using L = number of pixels on the long side of the circumscribed rectangle × k and W = number of pixels on the short side of the circumscribed rectangle × k. The pixel perimeter is obtained using the arc length function of the contour and converted to actual length: C = pixel perimeter × k.
8. The method for detecting defects in injection molded products based on machine vision according to claim 6, characterized in that: The process of calculating the three-dimensional size of the defect in step S55 is as follows: S551: Defect depth: Calculate the depth difference between each point in the defect area and the corresponding point of the standard model, take the average value as the defect depth, and align the actual point cloud (P) with the standard defect-free point cloud (P0) through the ICP algorithm to obtain the corresponding point pair (p i , p 0i ), pᵢ∈P,p 0i ∈P0, calculate the depth deviation: h i =|p i ·z- p 0i z|, z is the height axis of the three-dimensional coordinate system; average depth of the defect: H avg =mean(hᵢ); S552: Defect volume: For concave / convex defects, the defect point cloud is divided into tiny cube grids with a side length of Δ=0.01mm, and the sum of all grid volumes is calculated: V=Σ(Δ 2 ×H avg ), H avg is the average depth within the grid, and the defect volume is obtained.
Citation Information
Patent Citations
Flexible circuit board defect detection method and system
CN118644483A
Product detection method and system based on machine vision
CN119323659A
Keyboard key defect detection method and system based on machine vision
CN120253841A
Vehicle surface defect identification method and system based on artificial intelligence
CN120411910A
Method and system for automatically identifying wafer internal defect image of 3D stacked chip
CN120471901A
Cited By
Filter element filterability test method and system based on visual inspection
CN120908197A
Injection product overflow trimming energy consumption optimization data processing method
CN121010059A
Injection mold surface defect detection method based on visual inspection
CN121049290A
Online defect detection method and system for TPMS (Tire Pressure Monitor System) gradient structural member
CN121053122A
Injection molding part quality detection method and system based on machine vision
CN121053144A
