PLC vision detection linkage control method and system based on AI image recognition
By adjusting camera exposure parameters in real time and extracting illumination-invariant features, combined with neural network feature fusion, the problem of missed and false detections caused by illumination changes on high-speed production lines has been solved, achieving efficient defect detection and real-time collaborative control of the production line.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGCHENG IND TECHNOLOGY (SUZHOU) CO LTD
- Filing Date
- 2025-10-24
- Publication Date
- 2026-05-12
AI Technical Summary
Traditional visual inspection algorithms suffer from missed and false detections due to changes in lighting conditions on high-speed production lines, and lack a real-time coordination mechanism with PLCs, which affects product quality and production efficiency.
By evaluating the brightness and contrast of industrial product images in real time, the camera exposure parameters are automatically adjusted, illumination-invariant features are extracted and combined with enhanced image feature vectors under different lighting conditions, and feature fusion is performed using a pre-trained neural network. Finally, the defect detection model is input to output the defect confidence and location.
It achieves adaptive correction under illumination conditions and stable extraction of illumination-invariant features, improving the accuracy and real-time performance of defect detection in industrial products, and ensuring product qualification rate and production efficiency.
Smart Images

Figure CN121258962B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial visual inspection technology, and more specifically, to a PLC visual inspection linkage control method and system based on AI image recognition. Background Technology
[0002] In current high-speed discrete manufacturing scenarios, illuminance, light source angle, and shadow distribution change continuously with the production cycle. Traditional vision algorithms based on fixed thresholds or single preprocessing are difficult to continuously output reliable judgments within the constraints of PLC cycle scanning, resulting in alternating missed detections and false detections, which affects product qualification rate and production efficiency.
[0003] A Chinese patent with authorization announcement number CN119205777B provides an automatic detection method and system for surface defects on flexible touchscreens, comprising: S1: compensating for the illumination of the surface image of the flexible touchscreen using the Retinex method and converting it to the HSV color space to obtain the converted image; S2: calculating a directional feature map based on the converted image; S3: constructing a Gaussian mixture model based on the directional feature map and clustering the features using the expectation-maximization algorithm to obtain an initial defect region; S4: optimizing the initial defect region using morphological processing to obtain an optimized defect region; S5: stitching the converted image and the optimized defect region together to obtain an input image, and performing defect detection on the input image based on a deep learning multi-scale feature fusion network.
[0004] While Retinex can balance global brightness to some extent, its parameters need to be manually set according to the ambient lighting. When the angle of the light source or local shadows change drastically, the compensation result is prone to over-enhancement or loss of detail, leading to inaccurate HSV threshold determination. In addition, this patent uses serial CPU operation, and the overall inference delay cannot be synchronized with the 4ms-level scan cycle of the PLC, nor does it provide an interface solution for coordination with real-time control logic.
[0005] A Chinese patent application with publication number CN116030002A provides an image defect classification method and system based on high dynamic range technology. The method includes: capturing modal field images of the film to be inspected while it is in motion using an industrial camera; extracting bright field images and dark field images from the modal field images; stitching the bright field images into a bright field group image and stitching the dark field images into a dark field group image; identifying bright field defect regions in the bright field group image; detecting defects in the bright field group image according to the bright field defect regions and preset defect detection rules to obtain defect detection regions; and finally classifying defects in the dark field group image according to the defect detection regions and preset defect classification rules to obtain defect classification results.
[0006] This method can expand the image grayscale range and alleviate local overexposure or underexposure. However, its multi-exposure frames require mechanical shutter switching or switching of light source modes, and the sampling window often exceeds 30ms, making it unsuitable for high-speed production lines with a resolution of 120ppm or higher. Furthermore, the system directly classifies HDR results after inputting them into a traditional convolutional network without performing deep feature level fusion on different exposure views, resulting in limited ability to distinguish complex texture defects. Similarly, this solution lacks a real-time data write-back mechanism for PLCs, making it difficult to build closed-loop rejection control.
[0007] A comprehensive comparison reveals that patent CN119205777B focuses on single-frame global compensation, making it difficult to handle local dynamic shadows; patent CN116030002A focuses on hardware multi-exposure, resulting in long sampling periods and an inability to deeply fuse features. Both rely on fixed thresholds or static network weights, lacking adaptive correction strategies for online production, and failing to consider the collaborative implementation of illumination-invariant feature embedding, consistency regularization training, and OPC UA / PLC edge inference. Therefore, existing technologies fail to effectively address the instability issues caused by illumination changes in industrial vision inspection systems, especially in high-speed production lines where missed and false detections due to illumination fluctuations remain uncontrolled. Existing solutions primarily rely on hardware improvements, but cannot fully adapt to complex dynamic lighting environments and lack a close collaborative mechanism with real-time control systems such as PLCs, leading to unstable defect recognition accuracy during production and impacting product quality and production efficiency.
[0008] In view of this, the present invention proposes a PLC vision inspection linkage control method and system based on AI image recognition to solve the above problems. Summary of the Invention
[0009] To overcome the aforementioned shortcomings of the prior art and achieve the above objectives, the present invention provides the following technical solution: a PLC vision detection and linkage control method based on AI image recognition, comprising:
[0010] Based on the evaluation results of the real-time brightness and contrast of the image of the industrial product to be inspected, the camera's exposure parameters are automatically adjusted to obtain a corrected image of the industrial product.
[0011] Extract illumination-invariant features from calibrated industrial product images to generate illumination-invariant feature vectors;
[0012] The original image of the same industrial product to be detected and the corresponding illumination-invariant feature vector are input into the pre-trained feature optimization model, and the optimized illumination-invariant feature vector is output.
[0013] Industrial product images taken under different exposure conditions are input into a pre-trained neural network model and fused to obtain a shared feature vector;
[0014] The optimized illumination-invariant feature vector and shared feature vector are input into the pre-trained defect detection model, which outputs the confidence level and location of the detected defects.
[0015] Furthermore, the shared feature vector is a vector obtained by fusing intermediate features in the output layer after extracting intermediate features from the hidden layers of the neural network model; the intermediate features are features extracted from the hidden layers of the neural network model, which include edge shape information, texture continuity information and corner feature information common to images with different exposures.
[0016] Among them, edge shape information is a pixel feature that reflects the changes in the outer edge and contour of the same industrial product to be detected through gradient magnitude and direction; texture continuity information is a pixel feature that describes the gray-scale distribution pattern of adjacent pixels through local binary mode to characterize the direction of fine surface texture; and corner feature information is a pixel feature that identifies the position of geometric intersection point by corner response value and reflects the gray-scale changes of its neighborhood.
[0017] Furthermore, methods for automatically adjusting the camera's exposure parameters include:
[0018] The image of the industrial product to be inspected is converted from the RGB color space to the grayscale color space to obtain a grayscale image;
[0019] The brightness evaluation value is obtained by averaging the gray values of all pixels in the grayscale image.
[0020] The contrast evaluation value is obtained based on the standard deviation of the gray values of all pixels in the grayscale image;
[0021] The brightness error is obtained by subtracting the brightness assessment value from the preset target brightness value.
[0022] The contrast error is obtained by subtracting the contrast evaluation value from the preset target contrast value.
[0023] The exposure time parameter and gain parameter are obtained by calculating the product of the preset linear scaling factor, the brightness error and the contrast error respectively, which are the exposure adjustment parameters.
[0024] By applying exposure adjustment parameters to camera exposure control, a corrected image of the industrial product is obtained.
[0025] Furthermore, methods for generating illumination-invariant eigenvectors include:
[0026] The images of the industrial products to be inspected are preprocessed by denoising and normalization to obtain preprocessed images;
[0027] Perform gradient calculations on the preprocessed image to obtain a gradient map;
[0028] Local binary pattern calculation is performed on the preprocessed image to obtain a texture feature map;
[0029] Harris corner detection is performed on the preprocessed image to obtain corner feature maps;
[0030] By concatenating each pixel value of the gradient map, texture feature map, and corner feature map in a fixed order, an illumination-invariant feature vector is obtained.
[0031] Furthermore, methods for obtaining gradient maps include:
[0032] The Sobel operator is used to perform a convolution operation on the preprocessed image to calculate the horizontal and vertical gradients of the preprocessed image.
[0033] The gradient magnitude and direction of the preprocessed image are obtained by combining the horizontal and vertical gradients, forming a gradient map.
[0034] Furthermore, methods for obtaining texture feature maps include:
[0035] The preprocessed image is divided into FG×FG blocks, and the pixel values in each block are compared with adjacent pixels to generate binary values.
[0036] Calculate the binary value of each small block to generate a texture feature map.
[0037] Furthermore, methods for obtaining corner feature maps include:
[0038] The Harris corner detection algorithm is used to calculate the corner response value of each pixel in the preprocessed image;
[0039] Pixels with response values greater than a set response threshold are selected as corner points to form a corner feature map.
[0040] Furthermore, the training methods for the feature optimization model include:
[0041] Construct a neural network model, including an input layer, hidden layers, and an output layer;
[0042] Multiple sets of industrial product images taken under different lighting conditions were collected to obtain a training dataset including different exposure conditions. The training dataset was then divided into a training set, a validation set, and a test set.
[0043] Each image in the training set is denoised and normalized to obtain a preprocessed image, and the corresponding illumination-invariant feature vector is obtained.
[0044] Based on different lighting conditions, each training image is enhanced to obtain an enhanced image, and lighting-invariant features are extracted from each enhanced image to generate an enhanced lighting-invariant feature vector.
[0045] The illumination-invariant feature vectors of the original image and the enhanced image are used as inputs to the neural network model for forward propagation;
[0046] A loss function is calculated based on the difference between the output of the neural network model and the true label; the goal of the loss function is to minimize the similarity error of the feature vectors between the augmented images.
[0047] The backpropagation algorithm is used to update the weight parameters of the neural network model based on the calculated loss value.
[0048] The training process is evaluated using a validation set, and the hyperparameters of the neural network are adjusted accordingly.
[0049] After multiple rounds of training and optimization, a well-trained feature optimization model is obtained.
[0050] Furthermore, training methods for neural network models include:
[0051] Collect multiple sets of industrial product images taken under different exposure conditions, and divide each set of images into a training set, a validation set, and a test set;
[0052] Construct the neural network model architecture and determine the structure and parameters of the input layer, hidden layer, and output layer of the neural network model;
[0053] The neural network model is forward propagated using the training set images, and the initial loss value between the neural network model output and the true label is calculated.
[0054] The weight parameters of the neural network model are updated based on the initial loss value using the backpropagation algorithm.
[0055] During training, the performance of the neural network model is evaluated periodically using validation set images, and the model's hyperparameters are adjusted based on the evaluation results.
[0056] Repeat the steps of forward propagation, back propagation, updating weight parameters, and evaluating performance until the performance of the neural network model on the validation set reaches the preset convergence condition.
[0057] The trained neural network model is tested using test set images to obtain the trained neural network model.
[0058] The PLC vision inspection and linkage control system based on AI image recognition includes:
[0059] The illumination correction module automatically adjusts the camera's exposure parameters based on the real-time brightness and contrast evaluation results of the industrial product image to be inspected, and obtains a corrected industrial product image.
[0060] The feature extraction module is used to extract illumination-invariant features from the corrected industrial product images and generate illumination-invariant feature vectors.
[0061] The feature optimization module is used to input the original image of the same industrial product image to be detected and the corresponding illumination-invariant feature vector into the pre-trained feature optimization model, and output the optimized illumination-invariant feature vector.
[0062] The feature fusion module is used to input industrial product images taken under different exposure conditions into a pre-trained neural network model for fusion to obtain a shared feature vector;
[0063] The defect detection module is used to input the optimized illumination-invariant feature vector and shared feature vector into the pre-trained defect detection model, and output the confidence score and defect location of the detected defects.
[0064] Compared with existing technologies, the technical effects and advantages of the PLC vision inspection linkage control method and system based on AI image recognition in this invention are as follows:
[0065] This invention automatically adjusts camera exposure parameters by real-time evaluation of the brightness and contrast of industrial product images, extracts illumination-invariant features, and combines enhanced image feature vectors under different lighting conditions. Images with different exposures are input into a pre-trained neural network and fused to obtain a shared feature vector. Finally, this vector is input into a defect detection model to output defect confidence and location. This scheme achieves adaptive correction of lighting conditions, stable extraction of illumination-invariant features, and deep fusion of multi-exposure features. Furthermore, through linkage control with a PLC, it ensures that the entire inspection process is completed within the PLC scanning cycle.
[0066] It effectively solves the problem of missed and false detections caused by changes in lighting in traditional vision algorithms during high-speed production. It avoids the shortcomings of existing technologies, such as reliance on manual parameters for lighting compensation, high processing latency, and insufficient coordination with PLC. It improves the accuracy and real-time performance of defect detection in industrial products, and ensures product qualification rate and production efficiency. Attached Figure Description
[0067] Figure 1 This is a schematic diagram of a PLC vision inspection and linkage control system based on AI image recognition, according to an embodiment of the present invention.
[0068] Figure 2 This is a flowchart of the PLC vision detection linkage control method based on AI image recognition according to an embodiment of the present invention;
[0069] Figure 3 This is a flowchart of a method for obtaining illumination-invariant feature vectors according to an embodiment of the present invention;
[0070] Figure 4 This is a flowchart of a method for automatically adjusting the exposure parameters of a camera according to an embodiment of the present invention;
[0071] Figure 5 This is a schematic diagram of the optimized illumination-invariant feature vector method according to an embodiment of the present invention. Detailed Implementation
[0072] The technical solutions of the embodiments of the present invention will be described in detail, clearly, and completely below with reference to the accompanying drawings. It should be particularly noted that the specific embodiments described below are only for better illustrating and explaining the technical solutions of the present invention, and are intended to enable those skilled in the art to better understand and implement the present invention, and should not be construed as limiting the scope of protection of the present invention. Without departing from the spirit and substance of the present invention, those skilled in the art can modify, adjust, or make equivalent substitutions based on the content disclosed in the present invention, and these should all be considered within the scope of protection of the present invention.
[0073] Example 1
[0074] Please see Figure 1 As shown, this embodiment discloses a PLC vision inspection linkage control system based on AI image recognition, including a feature extraction module, a feature optimization module, a feature fusion module, a defect detection module, and an illumination correction module. Each module is connected via wired and / or wireless means to achieve data transmission.
[0075] The illumination correction module automatically adjusts the camera's exposure parameters based on the real-time brightness and contrast evaluation results of the industrial product image to be inspected, thereby acquiring a corrected industrial product image.
[0076] Please see Figure 4 As shown, methods for automatically adjusting camera exposure parameters include:
[0077] The image of the industrial product to be inspected is converted from the RGB color space to the grayscale color space to obtain a grayscale image.
[0078] The brightness evaluation value is obtained by averaging the grayscale values of all pixels in the grayscale image.
[0079] The contrast evaluation value is obtained based on the standard deviation of the gray levels of all pixels in the grayscale image.
[0080] The brightness error is obtained by subtracting the brightness assessment value from the preset target brightness value.
[0081] The contrast error is obtained by subtracting the contrast evaluation value from the preset target contrast value.
[0082] The exposure time parameter and gain parameter are obtained by calculating the product of the preset linear scaling factor, the brightness error, and the contrast error, respectively. Thus, the exposure adjustment parameter is obtained.
[0083] By applying exposure adjustment parameters to camera exposure control, a corrected image of the industrial product is obtained.
[0084] Methods for setting the linear scaling factor include:
[0085] First, under typical lighting conditions, multiple sets of representative industrial product image samples were collected, and the changes in brightness and contrast evaluation values of each sample image under different exposure time and gain parameters were recorded. Then, based on the changes between brightness error and actual exposure time adjustment, and between contrast error and gain parameter adjustment, a one-to-one correspondence between brightness error and exposure time parameters, and between contrast error and gain parameters, was established using a linear fitting method. The proportional coefficients corresponding to brightness and contrast were then determined.
[0086] The linear scaling factor can be fine-tuned according to the actual detection scenario to ensure that the image brightness and contrast meet the defect detection requirements while avoiding a decrease in feature extraction effect due to overexposure or underexposure. For example, in a certain application scenario, every 10 increase in brightness error can extend the exposure time by 1ms, at which point the linear scaling factor is 0.1; every 4 increase in contrast error can increase the gain by 1dB, and the corresponding scaling factor is 0.25. The final scaling factor can be used as a fixed parameter in actual deployment, or it can be obtained through experience adjustment during the on-site calibration phase.
[0087] The methods for setting the target brightness and target contrast values include:
[0088] Under typical lighting conditions, multiple sets of representative industrial product image samples were collected. For each set of sample images, images were captured under different exposure time and gain parameters, and the brightness and contrast evaluation values of each sample image were recorded under the corresponding exposure conditions. These recorded data were analyzed to observe the variation patterns of the brightness and contrast evaluation values under different exposure conditions. Based on the actual requirements of industrial product defect detection for image brightness and contrast, the brightness and contrast ranges that can ensure image quality meets defect detection requirements were determined. Representative brightness values within this range were selected as preset target brightness values, and corresponding contrast values were selected as preset target contrast values. In actual deployment, the determined preset target brightness and contrast values can be used as fixed parameters, or they can be fine-tuned empirically during the on-site calibration phase to ensure that image brightness and contrast meet defect detection requirements while avoiding a decrease in feature extraction effectiveness due to overexposure or underexposure.
[0089] Through the above steps, illumination correction not only improves image quality but also ensures consistency in subsequent feature extraction and defect detection. Especially in complex dynamic lighting environments, illumination correction eliminates the interference of illumination changes on the feature extraction process, enabling subsequent illumination-invariant feature extraction and defect detection to proceed stably under different lighting conditions, thus improving overall detection accuracy.
[0090] The feature extraction module is used to extract illumination-invariant features from the image of the industrial product to be detected and generate illumination-invariant feature vectors.
[0091] Please see Figure 3 As shown, methods for generating illumination-invariant eigenvectors include:
[0092] The images of industrial products to be inspected are preprocessed by denoising and normalization to obtain preprocessed images.
[0093] Gradient operations are performed on the preprocessed image to obtain a gradient map.
[0094] Local binary pattern calculation is performed on the preprocessed image to obtain the texture feature map.
[0095] Harris corner detection is performed on the preprocessed image to obtain corner feature maps.
[0096] By concatenating each pixel value of the gradient map, texture feature map, and corner feature map in a fixed order, an illumination-invariant feature vector is obtained.
[0097] Methods for obtaining gradient maps include:
[0098] The Sobel operator is used to perform a convolution operation on the preprocessed image to calculate the horizontal and vertical gradients of the preprocessed image.
[0099] The gradient magnitude and direction of the preprocessed image are obtained by combining the horizontal and vertical gradients, forming a gradient map.
[0100] Methods for obtaining texture feature maps include:
[0101] The preprocessed image is divided into FG×FG blocks, and the pixel values within each block are compared with adjacent pixels to generate binary values.
[0102] Calculate the binary value of each small block to generate a local binary pattern map, i.e., a texture feature map.
[0103] Methods for obtaining corner feature maps include:
[0104] The Harris corner detection algorithm is used to calculate the corner response value of each pixel in the preprocessed image.
[0105] Pixels with response values greater than a set response threshold are selected as corner points to form a corner feature map.
[0106] For example, in this embodiment, the image of the industrial product to be detected is first preprocessed by denoising and normalization to ensure that the image has consistency and stability in subsequent processing. Taking a flexible touch screen surface image to be detected as an example, the image is first denoised using a Gaussian filter to remove noise from the image, and the pixel values of the image are normalized to make their value range uniform and standardized to [0,1], thus obtaining a preprocessed image.
[0107] Next, gradient calculations are performed on the preprocessed image to generate a gradient map. Specifically, the Sobel operator is used to convolve the preprocessed image, calculating the gradients in the horizontal and vertical directions. By combining the gradient magnitudes in the horizontal and vertical directions, the gradient magnitude and direction of each pixel are calculated, forming a complete gradient map. This gradient map reflects the changes in edges and contours in the image and is crucial for subsequent defect detection.
[0108] Based on this, local binary pattern calculation is further performed on the preprocessed image to obtain a texture feature map. First, the preprocessed image is divided into several FG×FG blocks. In this embodiment, FG is set to 8, meaning the image is divided into multiple 8×8 sub-blocks. The pixel values within each sub-block are compared with adjacent pixels to generate binary values. Specifically, the grayscale values of each pixel are compared with those of its neighboring pixels, and the corresponding binary value is generated based on the comparison results. Then, the binary values of all pixels within each block are calculated, ultimately yielding a local binary pattern map, i.e., a texture feature map. The texture feature map can describe the local texture structure of an image, helping to identify surface defects and other detailed information.
[0109] Furthermore, Harris corner detection is performed on the preprocessed image to obtain a corner feature map. The Harris corner detection algorithm is used to calculate the corner response value for each pixel. The corner response value reflects the degree of change in the area surrounding each point in the image, effectively identifying key points in the image. In this embodiment, a threshold for the response value is set, and pixels with response values greater than this threshold are selected as corners, ultimately forming the corner feature map. The corner feature map provides regions with high variation in the image, which is particularly important for defect detection, as defective regions are often accompanied by significant corner variations.
[0110] Finally, the pixel values from the gradient map, texture feature map, and corner feature map are concatenated in a fixed order to obtain a long vector. This long vector is the illumination-invariant feature vector of the industrial product image to be inspected. This method fuses multiple feature information from the image to obtain a robust feature representation independent of illumination changes, facilitating subsequent defect detection and analysis.
[0111] When performing Harris corner detection, setting a threshold for the response value is crucial for selecting the most representative corners from the image. This threshold depends on the actual features of the image and the desired corner sensitivity. The threshold can be determined experimentally, specifically by selecting an appropriate range of response values based on the distribution characteristics of corners and the noise level in the image. A higher response value indicates a stronger salience of the corner in the image, suggesting more significant local variation.
[0112] In the feature vector generation process, the gradient map, texture feature map, and corner feature map are concatenated in a fixed order. This order is typically determined based on the importance of each feature in image processing and its contribution to defect identification. Generally, the gradient map provides edge information, the texture feature map displays local details, and the corner feature map emphasizes significant changes in the image. This fixed concatenation ensures that the features are combined in an orderly and consistent manner, resulting in a final feature vector that comprehensively and effectively represents various important information in the image. The advantages of this approach are that the fixed order guarantees high consistency and repeatability in the feature extraction process, contributing to the stability and accuracy of subsequent machine learning or deep learning model processing. Furthermore, the fixed order maintains consistent dimensionality during feature fusion, facilitating further processing and optimization in various algorithms and improving the overall system performance.
[0113] The feature optimization module is used to input the original image of the same industrial product image to be detected and the corresponding illumination-invariant feature vector into the pre-trained feature optimization model, and output the optimized illumination-invariant feature vector.
[0114] Training methods for feature optimization models include:
[0115] Build a neural network model, including an input layer, hidden layers, and an output layer.
[0116] Multiple sets of industrial product images taken under different lighting conditions were collected to obtain a training dataset including different exposure conditions. The training dataset was then divided into a training set, a validation set, and a test set.
[0117] Each image in the training set is denoised and normalized to obtain a preprocessed image, and the corresponding illumination-invariant feature vector is obtained.
[0118] Based on different lighting conditions, each training image is enhanced to obtain an enhanced image, and lighting-invariant features are extracted from each enhanced image to generate an enhanced lighting-invariant feature vector.
[0119] The illumination-invariant feature vectors of the original and enhanced images are used as inputs to the neural network model for forward propagation.
[0120] A loss function is calculated based on the difference between the output of the neural network model and the true label; the goal of the loss function is to minimize the similarity error of the feature vectors between the augmented images.
[0121] The backpropagation algorithm is used to update the weight parameters of the neural network model based on the calculated loss value.
[0122] The training process is evaluated using a validation set, and the hyperparameters of the neural network are adjusted.
[0123] After multiple rounds of training and optimization, a well-trained feature optimization model is obtained.
[0124] Please see Figure 5 As shown, each training image is enhanced under different lighting conditions to obtain an enhanced image. By simulating different lighting environments, the diversity of the processed images is enhanced. Taking a certain image to be detected as an example, the original image is first acquired, which was taken under standard indoor lighting conditions. Next, the image is enhanced under lighting conditions using the following methods.
[0125] First, the brightness values of the image are adjusted to simulate changes under strong and low light conditions. For example, increasing the brightness value of the original image by 50% simulates a strong light scenario, making the bright areas of the image brighter and the details in the shadows more prominent. Conversely, decreasing the image brightness value by 50% simulates the effect in a low-light environment, making the image darker overall, and the details in the shadow areas may become difficult to discern.
[0126] Secondly, by increasing or decreasing the image contrast, high-contrast and low-contrast lighting variations can be simulated. For example, increasing the image contrast makes the difference between bright and dark areas more obvious, enhancing the image's depth and making it suitable for scenes in strong lighting environments. Then, reducing the image contrast by 50% simulates a low-contrast environment. In this case, the brightness difference in the image is smaller, and the overall effect is softer, making it suitable for detection under cloudy or diffused lighting conditions.
[0127] Next, by simulating light source conditions at different angles, the direction of illumination is changed, thus adjusting the changes in the shadow area of the image. For example, if the light source in the original image comes from directly above, the shadow will appear at the bottom of the image. By rotating the direction of the light source, the effects of light sources at different angles can be simulated. For example, if the light source is rotated to a side position, the shadow will extend from one side of the image to the other, and the change in the shadow area may affect the visibility of surface defects.
[0128] Finally, by adjusting the color temperature of the image, we can simulate the effects of image conditions under cool and warm light. For example, adjusting the color temperature to a warm tone simulates the effect under incandescent light, giving the image a warm yellow hue. Conversely, adjusting the color temperature to a cool tone simulates the effect under fluorescent or daylight lighting, resulting in a cool blue hue. Details in the image may appear differently under different color temperatures.
[0129] By enhancing the image processing, images under various lighting conditions can be obtained, which can effectively expand the diversity of the original image. This allows the subsequent defect detection model to be trained and optimized under different lighting conditions, thereby improving the accuracy and stability of the detection.
[0130] The feature fusion module is used to input industrial product images taken under different exposure conditions into a pre-trained neural network model for fusion to obtain a shared feature vector.
[0131] Training methods for neural network models include:
[0132] Collect multiple sets of industrial product images taken under different exposure conditions, and divide each set of images into a training set, a validation set, and a test set;
[0133] Construct the neural network model architecture and determine the structure and parameters of the input layer, hidden layer, and output layer;
[0134] The neural network model is forward propagated using the training set images, and the initial loss value between the neural network model output and the true label is calculated.
[0135] The weight parameters of the neural network model are updated based on the initial loss value using the backpropagation algorithm.
[0136] During training, the performance of the neural network model is evaluated periodically using validation set images, and the model's hyperparameters are adjusted based on the evaluation results.
[0137] Repeat the steps of forward propagation, back propagation, updating weight parameters, and evaluating performance until the performance of the neural network model on the validation set reaches the preset convergence condition.
[0138] The trained neural network model is tested using test set images to obtain the trained neural network model.
[0139] In this embodiment, multiple sets of images of industrial products taken under different exposure conditions are first collected. For example, the industrial product to be inspected is a certain type of automobile part, and images were taken under four different exposure conditions, including overexposure, normal exposure, underexposure, and standard exposure. Each set of images has the same scene and content, but due to the different exposure intensities, the brightness and detail of the images vary. The collected image data is divided into training, validation, and test sets, with 70% of the images in each set used as the training set, 15% as the validation set, and 15% as the test set, for subsequent neural network training, evaluation, and testing.
[0140] Next, the neural network model architecture is constructed. In this embodiment, the neural network is a convolutional neural network, whose input layer receives multiple images of industrial products taken under different exposure conditions. The hidden layers of the network include multiple convolutional layers and pooling layers, responsible for extracting features from the images under different exposure conditions. After multiple convolutional operations, the output layer of the network generates a shared feature vector, which represents the shared features of the input image under various exposure conditions.
[0141] During the training of the neural network model, forward propagation is first performed using training set images. Each input image is processed sequentially through multiple convolutional and pooling layers to extract different features from the image. Finally, a fully connected layer maps these different features to a shared feature vector. This shared feature vector is the output of the neural network; it reflects the common features of the input images and can be consistently represented under different lighting and exposure conditions.
[0142] After each forward propagation, the loss value between the shared feature vector output by the neural network and the true label is calculated. The loss function uses mean squared error to measure the difference between the shared feature vector output by the network and the expected ideal feature vector.
[0143] Then, using the backpropagation algorithm, the gradients of the parameters of each layer are calculated based on the loss value, and the weights of the neural network are updated. During backpropagation, the network calculates gradients layer by layer and adjusts the weights to minimize the loss function. The updated weights are used in the next round of training, and through continuous iterative optimization, the network's ability to extract features from the input image and generate shared feature vectors is gradually improved.
[0144] During training, the performance of the neural network model is periodically evaluated using validation set images. The validation set is used to monitor the model's performance on unseen data to prevent overfitting. When the model's performance on the validation set no longer improves significantly, such as when the accuracy stabilizes or the loss function converges, the model can be considered to have reached convergence. Based on the evaluation results of the validation set, if the model's performance is unsatisfactory, parameters such as the network's learning rate, the number of convolutional layers, and the pooling layer configuration can be adjusted to further optimize the model.
[0145] After training, the neural network is evaluated using test set images. The test set images are unseen data for the network and are used to verify the generalization ability of the trained model in real-world applications. The model's performance is assessed by calculating metrics such as prediction error on the test set and consistency of shared feature vectors.
[0146] Ultimately, the trained neural network model can accept industrial product images under different exposure conditions as input and output a stable and consistent shared feature vector. This shared feature vector can effectively represent the common features of the input images, ensuring accuracy and consistency regardless of the lighting and exposure conditions, thus improving the performance and reliability of subsequent defect detection tasks.
[0147] The neural network model takes images of industrial products taken under different exposure conditions as input and outputs a shared feature vector representing the common features of the image under various lighting and exposure conditions. Different exposure conditions of the input image affect its brightness, contrast, and detail representation. Therefore, the task of the neural network model is to learn the variations under different exposure conditions and extract stable, defect-useful features under all these conditions.
[0148] When the exposure conditions of an input image change, such as becoming overexposed or underexposed, the image's detail and contrast change significantly. Overexposed images lose detail in bright areas and become more blurry in dark areas; while underexposed images become darker overall, with lost or unclear details. Changes in exposure conditions affect the performance of traditional image processing methods, but neural network models, through their deep convolutional operations, can extract features from input images that are unaffected by changes in lighting. Through optimization, the network can adapt to different exposure conditions, extracting the same high-level features when processing images with different exposures. Therefore, the model's output shared feature vector maintains consistency and accuracy under different lighting conditions.
[0149] In this embodiment, the PLC controller sends exposure time parameters and multi-channel gain parameter configurations to the selected multi-gain output industrial camera in one go during the production line scanning cycle. Multiple lenses of the camera generate multiple output image streams in parallel during single-frame acquisition. The PLC controller receives these multiple output image streams through the PLC interface and transmits them to the feature fusion module. The feature fusion module does not require multiple triggers; the camera can acquire industrial product image sequences under different gain conditions in parallel with a single trigger signal. These images are directly input into a pre-trained neural network model for fusion, generating a shared feature vector. This achieves full-process linkage between the illumination-invariant feature extraction and defect detection modules, enabling parallel image acquisition and processing within the same PLC scanning cycle.
[0150] For example, in a set of images of car parts taken simultaneously at 0.8EV, 0EV, and +0.8EV, the fusion network branches first extract the convolutional features of each frame, and then perform a weighted Hadamard product on the feature channels at the same spatial coordinates in the fusion layer and compress them using ReLU. In the final 512-dimensional shared vector, the amplitudes of the 126th and 137th dimensions are almost constant across all exposures, corresponding to the outer arc edge of the valve body contour; the 272nd to 280th dimensions are significantly higher on scratched workpieces than on defect-free workpieces, and when mapped to the input space, they fall on the fine texture band at the root of the thread, indicating that these dimensions capture consistent texture continuity across exposures; the 399th and 402nd dimensions only appear simultaneously at two intersecting edges above the valve body and are not sensitive to the direction of illumination. Grad-CAM back projection confirms that they focus on the corner response of the intersection point.
[0151] Although the brightness levels of the same industrial product vary in three frames—strong light, normal light, and weak light—the curves of its outer edges, the direction of its fine surface texture, and the positions of its corner points remain consistent. Therefore, after multi-branch encoding, the fusion network retains only the edge shape information, texture continuity information, and corner feature information common to all three frames at the fusion layer, compressing all grayscale differences, local glare, and shadow details caused by lighting. This approach makes the shared feature vector inherently "insensitive" to exposure changes, while completely preserving the geometric skeleton, fine texture, and key corners essential for subsequent defect localization, avoiding... It avoids the feature shift that may still occur under strong exposure drift in traditional single-frame illumination-invariant features, and also avoids the false detection problem caused by the weakening of details in simple pixel averaging or histogram equalization schemes. Therefore, in defect detection networks, if shared feature vectors are lacking, the defect detection model will either face the instability of judgment caused by illumination perturbation, or the reduction of localization accuracy due to the lack of texture and corner information. No other single feature can simultaneously meet the two requirements of "cross-exposure consistency" and "discrimination power that preserves details". Therefore, shared feature vectors are irreplaceable in solving the missed detections and false detections caused by dynamic fluctuations in illumination.
[0152] The defect detection module is used to input the optimized illumination-invariant feature vector and shared feature vector into the pre-trained defect detection model, and output the confidence score and defect location of the detected defects.
[0153] Training methods for defect detection models include:
[0154] Obtain a large dataset of industrial product images labeled with defects, where each image contains the category of the defect and its location in the image.
[0155] Illumination-invariant features are extracted from the images to be detected in the image dataset, and the same image is enhanced under different illumination conditions to obtain optimized illumination-invariant feature vectors.
[0156] Images of industrial products taken under different lighting conditions are input into a pre-trained neural network model to extract shared feature vectors.
[0157] The optimized illumination-invariant feature vector and shared feature vector are used as inputs to construct a defect detection model.
[0158] The defect detection model was trained using an image dataset with defect labels. A regression loss function was used to predict the defect location, and a classification loss function was used to predict the confidence level of the defect.
[0159] During training, the parameters of the defect detection model are optimized by minimizing a weighted combination of regression loss and classification loss.
[0160] During training, the model's performance is evaluated using a validation set, and the weighting coefficients in the loss function are adjusted accordingly.
[0161] After multiple iterations and optimizations, the final defect detection model was obtained.
[0162] For example, taking the surface of a certain automobile part as an example, the specific implementation process of each step in training the defect detection model is described in detail below:
[0163] First, a large dataset of industrial product images with defect labels was acquired. The collected image dataset included surface images of automotive parts, each image manually labeled with information such as the location of the defect (e.g., the coordinates of the bounding box) and the defect category (e.g., scratches, dents, cracks). For example, an image of an automotive part might contain a long, narrow scratch, while another image might contain a small dent. The labeled data provides detailed descriptions of the location and type of each defect, offering target information for subsequent training.
[0164] Next, illumination-invariant features are extracted from the images to be detected in the image dataset. For each image, its illumination-invariant feature vector is extracted. Specifically, the images are first preprocessed, including denoising and normalization. Then, using gradient calculation, local binary pattern recognition, and Harris corner detection methods, the illumination-invariant features of the image are extracted, generating the corresponding feature vector. These feature vectors can represent the structural features of the image without being affected by changes in illumination.
[0165] The same image is enhanced under different lighting conditions to obtain an optimized illumination-invariant feature vector. For example, for a given image, different lighting conditions are simulated, such as adjusting the image's brightness, contrast, light source direction, and color temperature, to obtain multiple enhanced images. Illumination-invariant features are re-extracted from each enhanced image, resulting in a new illumination-invariant feature vector. The optimized illumination-invariant feature vector reflects the key information of the image while eliminating unstable factors caused by changes in lighting.
[0166] In this embodiment, a convolutional neural network is used as a pre-trained model, which has been trained on similar industrial product images. Each image under different lighting conditions is input into this pre-trained model, and the model outputs a shared feature vector representing the global features of the image. The captured features maintain consistency across lighting conditions.
[0167] The input to the defect detection model consists of two parts: an optimized illumination-invariant feature vector and a shared feature vector extracted from a pre-trained neural network. By fusing these two feature vectors, a new deep learning model is constructed that can utilize both illumination-invariant and shared features simultaneously for more accurate defect detection.
[0168] A defect detection model is trained using a pre-collected and labeled dataset of images with defect labels. During training, two loss functions are employed: a regression loss function to predict defect location and a classification loss function to predict defect confidence. For example, for a given image, the model needs to predict the coordinates of the defect's bounding box (representing the regression task) and predict the presence and confidence of the defect (representing the classification task). The regression loss function can use L2 loss, and the classification loss function can use cross-entropy loss.
[0169] During training, the parameters of the defect detection model are optimized by minimizing a weighted combination of regression and classification losses. The loss function is a weighted combination of regression and classification losses, and the optimization objective is to minimize the weighted sum of these two losses. By minimizing this combined loss, the model can simultaneously optimize the prediction accuracy of defect location and the accuracy of defect confidence.
[0170] During training, the model's performance is evaluated using a validation set, and the weighting coefficients in the loss function are adjusted accordingly. After each training epoch, the model is evaluated using images from the validation set, and the regression error and classification accuracy on the validation set are calculated. If poor performance is found on a particular task, such as low regression accuracy for defect locations or low accuracy for defect confidence, the weighting coefficients of the regression and classification losses can be adjusted to improve the overall performance of the model. For example, the weight of the regression loss can be increased to make the model's prediction of defect locations more accurate.
[0171] After multiple iterations and optimizations, the final defect detection model was obtained. As training progressed, the model continuously optimized, and the regression error and classification accuracy gradually converged. Training was stopped when the model's accuracy on the validation set reached the expected target, resulting in the final defect detection model.
[0172] During the training phase, the defect detection model first concatenates or element-wise multiplies the optimized illumination-invariant feature vector with the shared feature vector along the feature dimension to obtain a unified high-dimensional semantic representation. This representation is then passed through a set of fully connected layers or lightweight convolutional-BN-ReLU blocks to complete the high-dimensional mapping, forming a fused feature tensor that carries both local texture and corner details as well as global shape cues across exposures. Two parallel branches then branch off from this tensor: the localization branch directly outputs the center coordinates, width and height offsets, or four vertex coordinates of each candidate box through a regression head; the classification branch provides the confidence score for each candidate box to be "defective" or "non-defective" through a Sigmoid or Softmax head. During training, the localization branch calculates a Smooth-L1 or IoU loss to approximate manually labeled boxes, while the classification branch calculates a cross-entropy loss to approximate true defect labels. Both branches, weighted by hyperparticipation, jointly update the network weights in reverse. Because the fused feature tensor preserves the texture and corners that are invariant to the lighting, avoids the shape drift caused by shadows and glare, and at the same time includes the multi-exposure consistent shape skeleton in the shared feature vector, only one forward propagation is needed during inference to complete the determination of whether there is a defect and the regression of the location of the defect in the fused feature space. The output confidence reflects the class probability, and the output position parameters can be directly restored to image coordinates.
[0173] In this approach, if the fused feature tensor is already a one-dimensional vector, a fully connected layer is used for a linear transformation from one dimension to one dimension. However, when it's necessary to preserve or further mine the spatial or channel structure of the mapped multi-dimensional features, a lightweight convolution-batch normalization-activation block is preferred because it reduces the number of parameters while maintaining local correlations and introduces non-linearity to enrich feature representation. For the classification branch, in binary scenarios where only "defective / non-defective" needs to be determined for each candidate box, a single-output unit binary classification head, equivalent to a Sigmoid structure, is used. In scenarios requiring differentiation between multiple defect types, a multi-class classification head, equivalent to a Softmax structure, is used. In the localization branch, when focusing on the absolute error between the regression output and the labeled box coordinates, a regression loss based on coordinate differences is used, such as center coordinate deviation or width / height deviation. When focusing more on the overlap quality between the predicted and labeled boxes, i.e., whether there is sufficient overlapping area in the image, a loss based on the overlap between the predicted and ground truth boxes is introduced. During training, the two regression losses can be weighted proportionally according to the specific task to balance coordinate accuracy and overlap quality.
[0174] For example, the system simultaneously acquires three exposure images at 1ms, 6ms, and 18ms. First, a feature optimization model converts each frame into its own illumination-invariant feature vector, and then consistency minimization yields an optimized vector with a dimension of 768. Simultaneously, the three images are fed in parallel into a multi-exposure fusion network. The network extracts intermediate features in the branch encoder and compresses them into a shared feature vector of length 512 in a self-attention fusion layer. At the inference end, these two vectors are concatenated by channel to form a 1280-dimensional fusion vector, which is then fed into the backbone MLP of the defect detection model. The backbone first maps the fusion vector into a high-dimensional semantic tensor through two layers of 1024-unit fully connected BatchNorm-ReLU blocks, and then feeds it into two parallel output heads: the localization head outputs the normalized bounding box (cx, cy, w, h) offset using four linear nodes, and the classification head outputs the confidence score that the box belongs to the "crack defect" using a sigmoid node. During the training phase, the Smooth-L1 regression loss and the binary cross-entropy loss are calculated for each positive candidate box, and the two are added together with a weight of 0.6:0.4. Backpropagation enables the network to learn to capture both the crack and narrow texture from the illumination-invariant feature vector and the contour skeleton from the shared feature vector that is consistent across exposures in the fusion vector.
[0175] Through the above steps, the resulting defect detection model can accept industrial product images under different lighting conditions, accurately identify and locate defects in the images, and output the confidence level and location of the defects. This model can be effectively applied in real-world production environments, processing images under different lighting and exposure conditions, and improving the efficiency and accuracy of defect detection for industrial products.
[0176] Using optimized illumination-invariant feature vectors and shared feature vectors as input, the defect detection model outputs the confidence level and location of detected defects. The optimized illumination-invariant feature vectors, by removing interference caused by illumination variations, stably capture key image content such as shape, texture, and structure. Even under different lighting conditions, these feature vectors remain stable; therefore, the defect detection model can detect the same defects under various lighting environments, including strong light, weak light, and shadows, ensuring consistent detection results.
[0177] Shared feature vectors help defect detection models extract global information from images, understand the overall layout and structure of the image, and effectively capture the spatial relationships of defects. The output of the defect detection model includes the confidence score and location of the defect. The defect confidence score is the probability value that the model believes there is a defect in a certain region of the image. The higher the confidence score, the greater the likelihood that the defect detection model believes there is a defect in that region. The defect location is represented by a bounding box, usually the coordinates of the top left and bottom right corners of the rectangle, or the coordinates of the center point of the box and the width and height of the box.
[0178] Changes in input significantly impact output. Changes in illumination-invariant feature vectors, particularly alterations in lighting conditions such as excessively strong light or shadow, can lead to feature vector instability, affecting the defect detection model's predictions of defect location and confidence. If illumination-invariant features fail to effectively handle lighting changes, the defect detection model may be affected by these changes, resulting in prediction errors. Changes in shared feature vectors also affect the performance of the defect detection model, especially when the input image exhibits significant lighting variations or poor image quality (e.g., overexposure or underexposure). In such cases, the shared feature vectors may fail to extract crucial global features, leading to inaccurate predictions of defect confidence and location, and potentially even preventing accurate defect localization. When the overall quality of the input image is poor, or when image content is occluded, blurred, or distorted, the feature extraction and fusion processes may be affected, ultimately decreasing the accuracy of defect location and confidence. Therefore, the stability of optimized illumination-invariant feature vectors and shared feature vectors is crucial for the performance of the defect detection model.
[0179] Example 2
[0180] This embodiment provides a PLC vision inspection and linkage control system based on AI image recognition, which also includes:
[0181] In this embodiment, the PLC controller first sends an acquisition command to the camera during the production line scanning cycle to acquire an image of the industrial product to be inspected and transmits the image to the illumination correction module via the PLC interface. The illumination correction module converts the image from the RGB color space to a grayscale image, calculates the mean of the grayscale values of all pixels in the grayscale image to obtain a brightness evaluation value, and calculates a contrast evaluation value based on the standard deviation of the grayscale values of all pixels in the grayscale image. Then, the brightness evaluation value is subtracted from the preset target brightness value to obtain the brightness error, and the contrast evaluation value is subtracted from the preset target contrast value to obtain the contrast error. The brightness error and contrast error are multiplied by the corresponding scaling factors to calculate the exposure time parameter and gain parameter, forming the exposure adjustment parameter. This exposure adjustment parameter is sent to the camera exposure control register via the PLC interface. After the PLC confirms that the parameter is effective, it returns a status signal, and then the PLC triggers the subsequent illumination-invariant feature extraction module and defect detection module to work, ensuring that the entire image acquisition, illumination correction, feature extraction, and defect judgment process is completed within one scanning cycle.
[0182] Example 3
[0183] Please see Figure 2 As shown, this embodiment provides a PLC vision inspection and linkage control method based on AI image recognition, including:
[0184] Based on the evaluation results of the real-time brightness and contrast of the image of the industrial product to be inspected, the camera's exposure parameters are automatically adjusted to obtain a corrected image of the industrial product.
[0185] Extract illumination-invariant features from calibrated industrial product images to generate illumination-invariant feature vectors;
[0186] The original image of the same industrial product to be detected and the corresponding illumination-invariant feature vector are input into the pre-trained feature optimization model, and the optimized illumination-invariant feature vector is output.
[0187] Industrial product images taken under different exposure conditions are input into a pre-trained neural network model and fused to obtain a shared feature vector;
[0188] The optimized illumination-invariant feature vector and shared feature vector are input into the pre-trained defect detection model, which outputs the detected defects, their confidence scores, and defect locations.
[0189] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
[0190] In conclusion, the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A PLC vision inspection and linkage control method based on AI image recognition, characterized in that, include: Based on the evaluation results of the real-time brightness and contrast of the image of the industrial product to be inspected, the camera's exposure parameters are automatically adjusted to obtain a corrected image of the industrial product. Extract illumination-invariant features from calibrated industrial product images to generate illumination-invariant feature vectors; The original image of the same industrial product to be detected and the corresponding illumination-invariant feature vector are input into the pre-trained feature optimization model, and the optimized illumination-invariant feature vector is output. Training methods for feature optimization models include: Construct a neural network model, including an input layer, hidden layers, and an output layer; Multiple sets of industrial product images taken under different lighting conditions were collected to obtain a training dataset including different exposure conditions. The training dataset was then divided into a training set, a validation set, and a test set. Each image in the training set is denoised and normalized to obtain a preprocessed image, and the corresponding illumination-invariant feature vector is obtained. Based on different lighting conditions, each training image is enhanced to obtain an enhanced image, and lighting-invariant features are extracted from each enhanced image to generate an enhanced lighting-invariant feature vector. The illumination-invariant feature vectors of the original image and the enhanced image are used as inputs to the neural network model for forward propagation; A loss function is calculated based on the difference between the output of the neural network model and the true label; the goal of the loss function is to minimize the similarity error of the feature vectors between the augmented images. The backpropagation algorithm is used to update the weight parameters of the neural network model based on the calculated loss value. The training process is evaluated using a validation set, and the hyperparameters of the neural network are adjusted accordingly. After multiple rounds of training and optimization, a well-trained feature optimization model is obtained; Industrial product images captured under different exposure conditions are input into a pre-trained neural network model and fused to obtain a shared feature vector. The shared feature vector is a vector obtained by fusing intermediate features extracted from the hidden layers of the neural network model and then fusing the intermediate features at the output layer. The intermediate features are extracted from the hidden layers of the neural network model and contain edge shape information, texture continuity information, and corner feature information common to images with different exposures. The optimized illumination-invariant feature vector and shared feature vector are input into the pre-trained defect detection model, which outputs the confidence level and location of the detected defects.
2. The PLC visual inspection and linkage control method based on AI image recognition according to claim 1, characterized in that: Edge shape information is a pixel feature that reflects the changes in the outer edge and contour of the same industrial product to be detected through gradient magnitude and direction. Texture continuity information is a pixel feature that describes the gray-scale distribution pattern of adjacent pixels through local binary mode to characterize the direction of fine surface texture. Corner feature information is a pixel feature that identifies the position of geometric intersection point by corner response value and reflects the gray-scale changes of its neighborhood.
3. The PLC vision inspection and linkage control method based on AI image recognition according to claim 1, characterized in that, Methods for automatically adjusting camera exposure parameters include: The image of the industrial product to be inspected is converted from the RGB color space to the grayscale color space to obtain a grayscale image; The brightness evaluation value is obtained by averaging the gray values of all pixels in the grayscale image. The contrast evaluation value is obtained based on the standard deviation of the gray values of all pixels in the grayscale image; The brightness error is obtained by subtracting the brightness assessment value from the preset target brightness value. The contrast error is obtained by subtracting the contrast evaluation value from the preset target contrast value. The exposure time parameter and gain parameter are obtained by calculating the product of the preset linear scaling factor, the brightness error and the contrast error respectively, which are the exposure adjustment parameters. By applying exposure adjustment parameters to camera exposure control, a corrected image of the industrial product is obtained.
4. The PLC visual inspection and linkage control method based on AI image recognition according to claim 1, characterized in that, Methods for generating illumination-invariant eigenvectors include: The images of the industrial products to be inspected are preprocessed by denoising and normalization to obtain preprocessed images; Perform gradient calculations on the preprocessed image to obtain a gradient map; Local binary pattern calculation is performed on the preprocessed image to obtain a texture feature map; Harris corner detection is performed on the preprocessed image to obtain corner feature maps; By concatenating each pixel value of the gradient map, texture feature map, and corner feature map in a fixed order, an illumination-invariant feature vector is obtained.
5. The PLC visual inspection and linkage control method based on AI image recognition according to claim 4, characterized in that, Methods for obtaining gradient maps include: The Sobel operator is used to perform a convolution operation on the preprocessed image to calculate the horizontal and vertical gradients of the preprocessed image. The gradient magnitude and direction of the preprocessed image are obtained by combining the horizontal and vertical gradients, forming a gradient map.
6. The PLC visual inspection and linkage control method based on AI image recognition according to claim 4, characterized in that, Methods for obtaining texture feature maps include: The preprocessed image is divided into multiple small blocks, and the pixel values within each small block are compared with adjacent pixels to generate binary values. Calculate the binary value of each small block to generate a texture feature map.
7. The PLC visual inspection and linkage control method based on AI image recognition according to claim 4, characterized in that, Methods for obtaining corner feature maps include: The Harris corner detection algorithm is used to calculate the corner response value of each pixel in the preprocessed image; Pixels with response values greater than a set response threshold are selected as corner points to form a corner feature map.
8. The PLC vision inspection and linkage control method based on AI image recognition according to claim 1, characterized in that, Training methods for neural network models include: Collect multiple sets of industrial product images taken under different exposure conditions, and divide each set of images into a training set, a validation set, and a test set; Construct the neural network model architecture and determine the structure and parameters of the input layer, hidden layer, and output layer of the neural network model; The neural network model is forward propagated using the training set images, and the initial loss value between the neural network model output and the true label is calculated. The weight parameters of the neural network model are updated based on the initial loss value using the backpropagation algorithm. During training, the performance of the neural network model is evaluated periodically using validation set images, and the model's hyperparameters are adjusted based on the evaluation results. Repeat the steps of forward propagation, back propagation, updating weight parameters, and evaluating performance until the performance of the neural network model on the validation set reaches the preset convergence condition. The trained neural network model is tested using test set images to obtain the trained neural network model.
9. A PLC vision inspection and linkage control system based on AI image recognition, used to implement the PLC vision inspection and linkage control method based on AI image recognition as described in any one of claims 1-8, characterized in that, include: The illumination correction module automatically adjusts the camera's exposure parameters based on the real-time brightness and contrast evaluation results of the industrial product image to be inspected, and obtains a corrected industrial product image. The feature extraction module is used to extract illumination-invariant features from the corrected industrial product images and generate illumination-invariant feature vectors. The feature optimization module is used to input the original image of the same industrial product image to be detected and the corresponding illumination-invariant feature vector into the pre-trained feature optimization model, and output the optimized illumination-invariant feature vector. Training methods for feature optimization models include: Construct a neural network model, including an input layer, hidden layers, and an output layer; Multiple sets of industrial product images taken under different lighting conditions were collected to obtain a training dataset including different exposure conditions. The training dataset was then divided into a training set, a validation set, and a test set. Each image in the training set is denoised and normalized to obtain a preprocessed image, and the corresponding illumination-invariant feature vector is obtained. Based on different lighting conditions, each training image is enhanced to obtain an enhanced image, and lighting-invariant features are extracted from each enhanced image to generate an enhanced lighting-invariant feature vector. The illumination-invariant feature vectors of the original image and the enhanced image are used as inputs to the neural network model for forward propagation; A loss function is calculated based on the difference between the output of the neural network model and the true label; the goal of the loss function is to minimize the similarity error of the feature vectors between the augmented images. The backpropagation algorithm is used to update the weight parameters of the neural network model based on the calculated loss value. The training process is evaluated using a validation set, and the hyperparameters of the neural network are adjusted accordingly. After multiple rounds of training and optimization, a well-trained feature optimization model is obtained; The feature fusion module is used to input industrial product images captured under different exposure conditions into a pre-trained neural network model for fusion to obtain a shared feature vector. The shared feature vector is a vector obtained by fusing intermediate features extracted from the hidden layers of the neural network model and then fusing the intermediate features at the output layer. The intermediate features are extracted from the hidden layers of the neural network model and contain edge shape information, texture continuity information, and corner feature information common to images with different exposures. The defect detection module is used to input the optimized illumination-invariant feature vector and shared feature vector into the pre-trained defect detection model, and output the confidence score and defect location of the detected defects.