Numerical control production workpiece detection system based on Internet of Things

Through the Internet of Things-based CNC production workpiece detection system, edge detection and light compensation technology are used to solve the detection accuracy problem caused by uneven light, and the clear presentation of workpiece characteristics and defects is achieved, and the accuracy and reliability of detection are improved.

CN120298337APending Publication Date: 2025-07-11TIANJIN PENGPENG BABA TECH DEV CO LTD
View PDF 12 Cites 0 Cited by

Patent Information

Application Number
CN202510355332.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

Traditional CNC production workpiece detection methods are difficult to ensure the accuracy and consistency of the detection in an unstable environment of lighting conditions, especially the significant differences in light intensity and angles of different shapes on large and complex workpieces, resulting in serious decline in image quality and difficult to clearly present subtle features and defects of workpieces.

Method used

The CNC production workpiece detection system based on the Internet of Things is adopted, including an image acquisition module, an image processing module and an early warning module. The image processing module removes background interference, performs light compensation and isolated pixel removal through edge detection, area division, light compensation, and sub-region classification to form a clear workpiece image.

Benefits of technology

It improves the accuracy and reliability of workpiece inspection, can clearly present workpiece characteristics and defects under uneven lighting conditions, reduce misjudgment, and improve production efficiency and product quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120298337A_ABST
    Figure CN120298337A_ABST
Patent Text Reader

Abstract

The invention discloses a numerical control production workpiece detection system based on the Internet of Things. The system comprises an image acquisition module which is composed of camera equipment installed on numerical control production equipment; relates to the technical field of numerical control production, and comprises the following steps: acquiring a workpiece production diagram through camera equipment, removing the background of a workpiece to obtain a first workpiece diagram containing workpiece information, dividing the first workpiece diagram into a plurality of sub-regions with different shapes through connection points, and performing preliminary illumination compensation on each sub-region to obtain a first workpiece diagram; the problem of image quality caused by non-uniform illumination can be effectively improved, a plurality of sub-regions are divided into edge sub-regions and central sub-regions, binarization processing is performed on the edge sub-regions, isolated pixel removal operation is performed on the central sub-regions, and finally, the image quality is improved. The processed edge sub-region and the center sub-region are spliced and combined again according to the original division positions to obtain the second workpiece image, and finally workpiece defect detection is performed according to the image of the second workpiece image, so that the accuracy of defect detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of numerical control production technology, and particularly to a numerical control production workpiece detection system based on the Internet of Things. Background Art

[0002] The quality inspection of die-cast alloy workpieces is a key link in modern manufacturing, especially in the fields of aviation, automobiles, precision machinery, etc. Traditional inspection methods rely on manual experience and simple optical instruments, which are not only inefficient but also difficult to ensure the consistency and accuracy of inspections. To solve this problem, a series of inspection methods based on computer vision technology have emerged. These methods usually use high-resolution CCD cameras to capture images of the workpiece surface, and then analyze the characteristics of the workpiece surface through image processing technology to achieve automatic defect recognition.

[0003] Publication No. CN118130477B discloses a method and system for detecting defects in die-cast alloy workpieces based on visual recognition. By pre-acquiring the three-dimensional modeling data of the workpiece and combining it with a lighting simulation model, simulation results of reflective surfaces, low-light surfaces, and light and dark mixed surfaces are generated under multi-angle light source illumination, reducing the risk of misjudgment caused by poor lighting conditions during the actual inspection process.

[0004] Publication No. CN116930195B discloses an intelligent CAM system and a surface defect detection method and device for hardware processing. By emitting strip-shaped light onto the hardware workpiece and taking the first workpiece image of the hardware workpiece, and then controlling the hardware workpiece to rotate a certain angle and taking another image, and so on, multiple first workpiece images are obtained. Then, the first average image of the multiple first workpiece images is calculated, and each first workpiece image is compared with the first average image one by one to determine the maximum difference image. After removing the maximum difference image, the second average image of the remaining images is calculated, and the maximum difference image is compared with the second average image to determine whether there are surface defects on the hardware workpiece. Thus, through the comparison of the images of the hardware workpiece itself, the detection of surface defects is achieved.

[0005] However, the above applications still have the following problems: In CN118130477B and CN116930195B, it is usually difficult to maintain stable lighting conditions in the numerical control production environment. The changes in natural light, the aging of equipment light sources, and the occlusion and reflection of light by the shape of the workpiece itself will all cause uneven lighting on the workpiece surface. Although CN118130477B partially realizes the lighting problem, it only uses a simple global lighting compensation method and cannot perform refined processing on the lighting differences in different regions. For example, on large and complex workpieces, the lighting intensity and angle differences in different shaped parts are significant, and global compensation cannot effectively solve these local lighting problems, resulting in a serious decline in image quality. The fine features and defects of the workpiece are difficult to clearly present under uneven lighting, greatly reducing the accuracy and reliability of detection. Summary of the Invention

[0006] To solve the technical problem of reduced defect detection accuracy caused by uneven lighting in the background art, the present invention proposes an Internet of Things-based numerical control production workpiece detection system.

[0007] An Internet of Things-based numerical control production workpiece detection system proposed by the present invention includes:

[0008] Image acquisition module: Composed of a camera device installed on the numerical control production equipment, responsible for taking real-time pictures of the workpiece during production and obtaining the workpiece production diagram;

[0009] Image processing module: Used to perform lighting compensation on the workpiece production diagram;

[0010] The image processing module includes:

[0011] Background removal unit: Based on the edge detection algorithm, analyze the workpiece production diagram, remove the background part, and obtain the first workpiece diagram containing workpiece information;

[0012] Region division unit: Identify different shapes on the first workpiece diagram in the background removal unit, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points;

[0013] Lighting compensation unit: Perform preliminary lighting compensation on each sub-region in the first workpiece diagram in the region division unit;

[0014] Sub-region classification unit: Based on the edge detection algorithm, perform edge detection on the first workpiece diagram that has undergone preliminary lighting compensation by the lighting compensation unit to obtain the edge line of the workpiece;

[0015] At the same time, for each sub-region, through the contour tracking algorithm, record the coordinates of each boundary pixel in sequence along the boundary of the sub-region to form a boundary line;

[0016] If there is an overlapping part between the boundary line of the sub-region and the edge line, mark the sub-region as an edge sub-region; if there is no overlapping part between the boundary line of the sub-region and the edge line, mark the sub-region as a central sub-region;

[0017] Sub-region recombination unit: For the edge sub-regions in the sub-region classification unit, set a dynamic gray value threshold for binaryzation processing; for the central sub-regions in the sub-region classification unit, remove isolated pixels with abnormal gray values; finally, recombine and splice the processed edge sub-regions and central sub-regions according to the original division positions to obtain the second workpiece diagram;

[0018] Early warning module: Detect workpiece defects through the second workpiece diagram. If a defect is detected, the system issues an alarm.

[0019] Preferably, in the background removal unit, based on the edge detection method, remove the background of the image data to obtain the first workpiece diagram, as follows:

[0020] The edge detection algorithm uses the Canny edge detection algorithm. When using the Canny edge detection algorithm, first perform noise reduction processing on the image data, then determine the edge pixels by calculating the gradient magnitude and direction of the image, then use non-maximum suppression to remove non-edge pixel points, and finally determine strong edges and weak edges through double-threshold detection, connect the weak edges to form a complete workpiece edge contour. After that, through the contour information, retain the first workpiece diagram by filling the inside of the contour and remove the background.

[0021] Preferably, in the region division unit, identify different shapes on the first workpiece diagram, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points, as follows:

[0022] For a certain first workpiece diagram, use the Hough transform method to identify different shapes on the first workpiece diagram. After identifying each shape, extract the contour of each shape. For the contours of adjacent shapes, use geometric calculation methods to solve their intersection points as the connection points;

[0023] Use the obtained connection points as the starting points for segmentation. Starting from the connection points, along the shape boundary, use the depth-first search or breadth-first search algorithm to mark the boundary pixels belonging to the same shape as the same category, so as to divide the first workpiece diagram into multiple sub-regions of different shapes.

[0024] Preferably, in the light compensation unit, during the preliminary light compensation, in the first workpiece diagram, for a certain sub-region i, calculate the average gray value of the sub-region i According to the preset standard average gray value Perform light compensation, and the compensation formula is:

[0025]

[0026] Among them, I i is the pixel value of the original area, and I' i is the pixel value after compensation.

[0027] Preferably, in the sub-region recombination unit, for the edge sub-regions in the sub-region classification unit, a dynamic gray value threshold is set for binarization processing. The specific steps are as follows:

[0028] Step 1: Statistically analyze the image gray histogram:

[0029] For the edge sub-region, traverse all the pixels in the entire edge sub-region image, count the frequency of each gray level, and construct a gray histogram;

[0030] Assume the gray level range is 0 - M, and create an array histogram with a length of M + 1 to record the number of pixels for each gray level;

[0031] Step 2: Calculate the total number of pixels and the probability of each gray level:

[0032] Add up all the elements in the gray histogram array to obtain the total number of pixels N of the image, that is

[0033] For each gray level i, calculate its probability P i in the image, and the calculation formula is

[0034] Step 3: Traverse all possible thresholds to calculate the between-class variance:

[0035] Start from the minimum gray level 0 and end at the maximum value M, and sequentially use each gray level as the candidate threshold T for calculation;

[0036] For each candidate threshold T, divide the pixels in the image into two categories. Pixels with gray values less than or equal to T are classified into the first gray value category, and pixels with gray values greater than T are classified into the second gray value category;

[0037] Assume that the probability w0 of the first gray value category is the sum of the probabilities of all pixels with gray values less than or equal to T;

[0038] Assume that the probability w1 of the second gray value category is the sum of the probabilities of all pixels with gray values greater than T, and w1 = 1 - w0;

[0039] Calculate the average gray value μ0 of the first gray value category, calculate the average gray value μ1 of the second gray value category, and calculate the average gray value μ of the entire image;

[0040] Calculate the between-class variance σ 2 σ2 = w0×(μ0 - μ) 2 + w1×(μ1 - μ) 2 ;

[0041] Step 4. Determine the threshold that maximizes the between-class variance:

[0042] Within the grayscale range of 0 - M, after traversing all thresholds, compare the between-class variance σ 2 value obtained each time, and record the threshold T 2 corresponding to the maximum between-class variance σ max , and set T max as the threshold for distinguishing the first grayscale value classification and the second grayscale value classification in the edge sub-region image;

[0043] According to the determined threshold T max , perform binarization processing on the pixels in the edge sub-region, set the pixels with grayscale values greater than T max to 255, and set the pixels with grayscale values less than or equal to T max to 0.

[0044] Preferably, in the sub-region recombination unit, for the central sub-region, remove the isolated pixels with abnormal grayscale values in the central sub-region as follows:

[0045] For the central sub-region, traverse all pixels in the entire central sub-region image and count the grayscale values of each pixel;

[0046] Set a pixel range of Y×Y, the central pixel within the pixel range Y×Y is the target pixel, calculate the mean X and standard deviation R of the pixel grayscale values within the pixel range Y×Y. If the grayscale value of the target pixel is greater than X + kR or less than X - kR, then adjust the grayscale value of the target pixel to the mean X.

[0047] Preferably, the value range of Y is 3 - 9, and the value range of k is 2 - 3.

[0048] A numerical control production workpiece detection method based on the Internet of Things includes the following steps:

[0049] S1. Shoot the workpiece during production through a camera device to obtain a workpiece production diagram;

[0050] S2. For the workpiece production diagram of a certain workpiece, remove the background of the workpiece production diagram based on the edge detection algorithm to obtain the first workpiece diagram;

[0051] S3. Identify different shapes on the first workpiece diagram, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points;

[0052] S4. Perform preliminary light compensation on each sub-region in the first workpiece diagram respectively;

[0053] S5. Edge detection is performed on the first workpiece image based on an edge detection algorithm to obtain the edge line of the workpiece. For multiple sub-regions with different shapes in the first workpiece image, through a contour tracking algorithm, the coordinates of each boundary pixel are sequentially recorded along the boundary of the sub-region to form a boundary line.

[0054] If there is an overlapping part between the boundary line of the sub-region and the edge line, then mark this sub-region as an edge sub-region.

[0055] If there is no overlapping part between the boundary line of the sub-region and the edge line, then mark this sub-region as a central sub-region.

[0056] S6. For the edge sub-region, a dynamic gray value threshold is set, and according to the dynamic gray value threshold, binary processing is performed on the pixels in the edge sub-region; for the central sub-region, the isolated pixels with abnormal gray values in the central sub-region are removed; then the edge sub-region and the central sub-region are re-spliced and combined according to the original division positions to obtain the second workpiece image.

[0057] S7. Workpiece defect detection is performed according to the second workpiece image.

[0058] In the present invention, the proposed numerical control production workpiece detection system based on the Internet of Things has the following beneficial technical effects:

[0059] 1. The setting of the image processing module, the workpiece production image is collected by a camera device, and then the background of the workpiece is removed to obtain the first workpiece image containing workpiece information, reducing the influence of background interference on the detection result and improving the detection accuracy. Then, the first workpiece image is divided into multiple sub-regions with different shapes through connection points, and preliminary light compensation is performed on each sub-region, which can effectively improve the image quality problem caused by uneven illumination. By dividing the multiple sub-regions into edge sub-regions and central sub-regions, binary processing of the edge sub-regions and the operation of removing isolated pixels in the central sub-regions are performed. Finally, the processed edge sub-regions and central sub-regions are re-spliced and combined according to the original division positions to obtain the second workpiece image, and finally workpiece defect detection is performed based on the image of the second workpiece image, improving the accuracy and reliability of defect detection.

[0060] 2. The light compensation unit performs preliminary light compensation on each sub-region in the first workpiece image according to the average gray value of each sub-region and the preset standard average gray value. Thus, the average gray value of each sub-region tends to the standard average gray value, preliminarily improving the uneven illumination condition. This can effectively reduce the degradation of image quality caused by uneven illumination. Especially in the case of relatively complex illumination changes, the workpiece features in each region can be more accurately extracted and detected.

[0061] 3. Through the processing of the sub-region recombination unit on the second workpiece image, whether it is the binarization of the edge sub-region or the removal of isolated pixels with abnormal gray values in the central sub-region, the information of the workpiece itself is further highlighted. For the edge sub-region, the binarization processing makes the edge contour clearer, effectively reducing the cases of edge blurring or confusion with the residual background. For the central sub-region, after removing the abnormal pixels, the internal structure is more pure, and the internal details of the workpiece such as textures and holes can be presented more accurately, making the entire workpiece more prominent in the image and facilitating subsequent defect detection;

[0062] During the sub-region recombination process, the edge sub-region can better adapt to the complexity of edge lighting through the binarization processing with a dynamic gray value threshold. For example, in the highlight reflection or shadow part that may appear at the edge, the binarization can determine the threshold according to the principle of the maximum between-class variance, enabling the edge details to be better presented under different lighting conditions. For the central sub-region, the operation of removing abnormal pixels also improves the lighting effect because these abnormal pixels may be generated due to local over-illumination or under-illumination. After removal, the lighting in the central region becomes more uniform, thus optimizing the lighting environment of the internal details and making the details more clearly visible;

[0063] The second workpiece image provides more favorable conditions for defect detection. The clear edge contour and pure central region make defects easier to be discovered. Whether it is the damage or dimensional deviation at the edge, or the damage to the internal structure or texture abnormality in the central region, these defects can be presented in a clearer form in the second workpiece image, thereby improving the accuracy and reliability of defect detection and helping to timely discover quality problems in the production process.

[0064] 4. The sub-region classification unit divides the sub-regions into edge sub-regions and central sub-regions based on the edge detection algorithm and the contour tracking algorithm. The sub-region recombination unit aims at the edge sub-region. By statistically analyzing the gray histogram, calculating the probability, and traversing the threshold to calculate the between-class variance, it determines the threshold that maximizes the between-class variance, and then performs binarization processing. This processing method can highlight the edge features and details of the edge sub-region, facilitating the detection of edge defects and the accuracy of the contour, and is beneficial to ensuring the assembly accuracy of the workpiece. For the central sub-region, the sub-region recombination unit removes isolated pixels with abnormal gray values by setting the pixel range, calculating the mean and standard deviation. This processing method can remove abnormal pixels generated in the central sub-region due to noise or other factors, improve the quality of the central region image, and help accurately detect the integrity and functionality of the internal structure of the workpiece, such as detecting internal holes and texture uniformity.

[0065] The additional aspects and advantages of the present invention will be partly given in the following description, partly will become obvious from the following description, or will be understood through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 is the principle block diagram of the system of the present invention;

[0067] Figure 2 is the flowchart of the method of the present invention. Detailed implementation manners

[0068] The embodiments of the present invention will be described in detail below. Examples of the embodiments are shown in the accompanying drawings, where the same or similar symbols represent the same or similar elements or elements with the same or similar functions throughout. The embodiments described below by referring to the accompanying drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation to the present invention.

[0069] Such as Figure 1 shown, an IoT-based numerical control production workpiece detection system includes:

[0070] Image acquisition module: Composed of a camera device installed on the numerical control production equipment, responsible for taking real-time pictures of the workpiece during production to obtain the workpiece production diagram;

[0071] The image acquisition module can, through the camera device installed on the numerical control production equipment, take real-time pictures of the workpiece during production to obtain the workpiece production diagram. This real-time acquisition function ensures that the detection system can timely obtain the workpiece images during the production process, provides first-hand information for subsequent detection and analysis, helps to timely discover problems during the production process, avoid producing a large number of unqualified products, and thus improve production efficiency and product quality.

[0072] Image processing module: Used to perform light compensation on the workpiece production diagram;

[0073] The image processing module includes:

[0074] Background removal unit: Based on the edge detection algorithm, analyze the workpiece production diagram, remove the background part, and obtain the first workpiece diagram containing workpiece information; This module can effectively separate the workpiece from the background and provide a clear image basis for subsequent processing;

[0075] In the background removal unit, the background of the picture data is removed based on the edge detection method to obtain the first workpiece diagram, as follows:

[0076] Since there are usually obvious gray-scale changes between the edges of the workpiece and the background, the edge detection algorithm can find these edge pixels, then use the edge pixels to outline the contour of the workpiece, and then extract the workpiece from the background according to the contour information.

[0077] The edge detection algorithm uses the Canny edge detection algorithm, which is a widely used edge detection algorithm in the fields of image processing and computer vision. When using the Canny edge detection algorithm, first, the image data is denoised. Then, the edge pixels are determined by calculating the gradient magnitude and direction of the image. Next, non-maximum suppression is used to remove non-edge pixel points. Finally, strong edges and weak edges are determined through double-threshold detection, and the weak edges are connected to form the complete edge contour of the workpiece. After that, based on the contour information, the first workpiece image is retained by filling the interior of the contour, and the background is removed.

[0078] The background removal unit uses the Canny edge detection algorithm. Through steps such as denoising, calculating the gradient magnitude and direction, non-maximum suppression, and double-threshold detection, the edge contour of the workpiece is determined. On this basis, by filling the interior of the contour to retain the workpiece image and remove the background, the workpiece can be effectively separated, providing a pure workpiece image for subsequent image processing, reducing the influence of background interference on the detection result, and improving the accuracy of detection.

[0079] Region division unit: Identify different shapes on the first workpiece image in the background removal unit, determine the connection points between the shapes, and divide the first workpiece image into multiple sub-regions of different shapes through the connection points; this helps to perform targeted processing on different parts of the workpiece and improve the accuracy of detection.

[0080] In the region division unit, different shapes on the first workpiece image are identified, the connection points between the shapes are determined, and the first workpiece image is divided into multiple sub-regions of different shapes through the connection points, as follows:

[0081] For a certain first workpiece image, the Hough transform method is used to identify different shapes on the first workpiece image. After each shape is identified, the contour of each shape is extracted. For the contours of adjacent shapes, geometric calculation methods are used to solve their intersection points, which are used as the connection points;

[0082] Taking the obtained connection points as the starting points of segmentation, starting from the connection points, along the shape boundary, using the depth-first search or breadth-first search algorithm, the boundary pixels belonging to the same shape are marked as the same category, thereby dividing the first workpiece image into multiple sub-regions of different shapes.

[0083] The region division unit uses the Hough transform method to identify different shapes on the workpiece image, determines the connection points between the shapes through geometric calculations, and then divides the workpiece image into multiple sub-regions of different shapes with the help of the depth-first search or breadth-first search algorithm. This fine region division method can perform targeted processing on sub-regions of different shapes, improving the accuracy and flexibility of image processing, and helping to more accurately analyze the characteristics and quality status of each part of the workpiece.

[0084] Light compensation unit: Perform preliminary light compensation on each sub-region in the first workpiece image of the region division unit to reduce the impact of uneven illumination on the detection results. By adjusting the pixel gray values within the sub-region, the overall brightness of the image becomes more uniform, facilitating subsequent image processing.

[0085] In the light compensation unit, during preliminary light compensation, in the first workpiece image, for a certain sub-region i, where i represents any sub-region in the first workpiece image, calculate the average gray value of sub-region i According to the preset standard average gray value Perform light compensation, and the compensation formula is

[0086] where I i is the pixel value of the original region, and I′ i is the pixel value after compensation;

[0087] The compensation method is to multiply the gray value of each pixel within the sub-region by the ratio of the standard average gray value to the average gray value of this region, so that the average gray values of each sub-region tend to the standard average gray value, initially improving the uneven illumination condition.

[0088] This can effectively reduce the degradation of image quality caused by uneven illumination. Especially in the case of relatively complex illumination changes, the workpiece features in each region can be more accurately extracted and detected.

[0089] Sub-region classification unit: Based on the edge detection algorithm, perform edge detection on the first workpiece image that has undergone preliminary light compensation by the light compensation unit to obtain the edge line of the workpiece;

[0090] At the same time, for each sub-region, through the contour tracking algorithm, record the coordinates of each boundary pixel in sequence along the boundary of the sub-region to form a boundary line; this module can accurately define the edge of the workpiece and the boundary of the sub-region, providing a basis for subsequent sub-region classification;

[0091] If there is an overlapping part between the boundary line of the sub-region and the edge line, mark this sub-region as an edge sub-region; if there is no overlapping part between the boundary line of the sub-region and the edge line, mark this sub-region as a central sub-region;

[0092] Sub-region recombination unit: For the edge sub-regions in the sub-region classification unit, set a dynamic gray value threshold for binary processing; for the central sub-regions in the sub-region classification unit, remove the isolated pixels with abnormal gray values; finally, splice and combine the processed edge sub-regions and central sub-regions according to the original division positions to obtain the second workpiece image;

[0093] In the sub-region recombination unit, for the edge sub-regions in the sub-region classification unit, a dynamic grayscale value threshold is set for binarization processing. The specific steps are as follows:

[0094] Step 1: Statistically analyze the image grayscale histogram:

[0095] For the edge sub-region, traverse all pixels in the entire edge sub-region image, count the frequency of each grayscale level, and construct a grayscale histogram;

[0096] Assume the grayscale level range is 0 - M, and create an array histogram with a length of M + 1 to record the number of pixels for each grayscale level; for example, histogram[5] represents the number of pixels with a grayscale value of 5;

[0097] Step 2: Calculate the total number of pixels and the probability of each grayscale level:

[0098] Add up all elements in the grayscale histogram array to obtain the total number of pixels N in the image, that is

[0099] For each grayscale level i, calculate its probability P i , and the calculation formula is

[0100] Step 3: Traverse all possible thresholds for between-class variance calculation:

[0101] Start from the minimum grayscale level 0 and end at the maximum value M, and successively use each grayscale level as the candidate threshold T for calculation;

[0102] For each candidate threshold T, divide the pixels in the image into two categories. Pixels with a grayscale value less than or equal to T are classified into the first grayscale value category, and pixels with a grayscale value greater than T are classified into the second grayscale value category;

[0103] Assume the probability w0 of the first grayscale value category is the sum of the probabilities of all pixels with a grayscale value less than or equal to T;

[0104] Assume the probability w1 of the second grayscale value category is the sum of the probabilities of all pixels with a grayscale value greater than T, and w1 = 1 - w0;

[0105] Calculate the average grayscale value μ0 of the first grayscale value category, calculate the average grayscale value μ1 of the second grayscale value category, and calculate the average grayscale value μ of the entire image;

[0106] Calculate the between-class variance σ 2 , σ 2 = w0×(μ0 - μ) 2 + w1×(μ1 - μ ) 2;

[0107] Step 4: Determine the threshold that maximizes the between-class variance:

[0108] Within the grayscale range of 0 - M, after traversing all thresholds, compare the between-class variance σ 2 calculated each time, and record the threshold T 2 corresponding to the maximum between-class variance σ max , and set T max as the threshold for distinguishing the first grayscale value classification and the second grayscale value classification in the edge sub-region image;

[0109] According to the determined threshold T max , perform binarization on the pixels within the edge sub-region, setting the pixels with grayscale values greater than T max to 255 and the pixels with grayscale values less than or equal to T max to 0;

[0110] Through the above method, find the threshold that maximizes the between-class variance, and then use this threshold to perform binarization on the image to better separate target objects such as workpieces and reduce the impact of light interference on the image quality.

[0111] Through such binarization processing, further separate the workpiece part, reduce misjudgment caused by uneven illumination, and make the details and contours of the workpiece more clearly presented.

[0112] The edges and some fine textures of the workpiece that were originally blurred due to uneven illumination are clearly shown after binarization, successfully removing the remaining light interference part, improving the image quality, and facilitating more accurate feature extraction, shape recognition and other detection operations on the workpiece in the follow-up.

[0113] By combining the region-based light compensation and the adaptive threshold algorithm in this way, it is possible to more effectively cope with the problem of light interference and improve the accuracy and reliability of workpiece detection based on machine vision.

[0114] In the sub-region recombination unit, for the central sub-region, remove the isolated pixels with abnormal grayscale values within the central sub-region as follows:

[0115] For the central sub-region, traverse all pixels in the entire central sub-region image and count the grayscale values of each pixel;

[0116] Set a pixel range of Y×Y, the central pixel within the pixel range Y×Y is the target pixel, calculate the mean X and standard deviation R of the pixel grayscale values within the pixel range Y×Y. If the grayscale value of the target pixel is greater than X + kR or less than X - kR, then adjust the grayscale value of the target pixel to the mean X;

[0117] This can effectively remove small light interference points and make the detailed parts of the image clearer.

[0118] In an optional embodiment, the value range of Y is 3 - 9, and the value range of k is 2 - 3;

[0119] It is used to remove isolated pixels with abnormal gray values generated by factors such as light interference in the central sub-region and optimize the image details.

[0120] The sub-region classification unit divides the sub-region into an edge sub-region and a central sub-region based on the edge detection algorithm and the contour tracking algorithm. For the edge sub-region, the sub-region recombination unit determines the threshold that maximizes the between-class variance by statistically analyzing the gray histogram, calculating probabilities, and traversing the threshold to calculate the between-class variance, and then performs binarization processing. This processing method can highlight the edge features and details of the edge sub-region, facilitate the detection of edge defects and the accuracy of the contour, and is beneficial to ensuring the assembly accuracy of the workpiece. For the central sub-region, the sub-region recombination unit removes isolated pixels with abnormal gray values by setting the pixel range and calculating the mean and standard deviation. This processing method can remove abnormal pixels generated by noise or other factors in the central sub-region, improve the quality of the central region image, and help accurately detect the integrity and functionality of the internal structure of the workpiece, such as detecting internal holes and texture uniformity.

[0121] Early warning module: Use the second workpiece drawing for workpiece defect detection. Through a preset defect detection algorithm, the preset defect detection algorithm includes the structural similarity index algorithm, the phase consistency algorithm, the histogram matching algorithm, and the feature point matching algorithm, analyze the shape, size, surface quality, etc. of the workpiece to determine whether there are defects in the workpiece. If a defect is detected, the system issues an alarm.

[0122] The second workpiece drawing is equivalent to the first workpiece drawing. Through the processing of the sub-region recombination unit, whether it is the binarization of the edge sub-region or the removal of isolated pixels with abnormal gray values in the central sub-region, the information of the workpiece itself is further highlighted. For the edge sub-region, the binarization processing makes the edge contour clearer and effectively reduces the situation of edge blurring or confusion with the residual background. For the central sub-region, after removing abnormal pixels, the internal structure is more pure, and the internal details of the workpiece, such as textures and holes, can be presented more accurately, making the entire workpiece more prominent in the image and facilitating subsequent defect detection;

[0123] During the sub-region recombination process, the edge sub-regions can better adapt to the complexity of edge lighting through binarization with a dynamic gray value threshold. For example, in areas of high-light reflection or shadow that may appear at the edge, binarization can determine the threshold according to the principle of maximum between-class variance, enabling edge details to be better revealed under different lighting conditions. For the central sub-region, the operation of removing abnormal pixels also improves the lighting effect because these abnormal pixels may be caused by local over-illumination or under-illumination. After removal, the lighting in the central region becomes more uniform, thus optimizing the lighting environment for internal details and making the details more clearly visible;

[0124] The second workpiece image provides more favorable conditions for defect detection. The clear edge contour and pure central region make defects easier to be detected. Whether it is a breakage or size deviation at the edge, or internal structure damage or texture abnormality in the central region, etc., these defects can be presented in a clearer form in the second workpiece image, thereby improving the accuracy and reliability of defect detection and helping to timely discover quality problems in the production process. Through the processing of the sub-region recombination unit, whether it is the binarization of the edge sub-regions or the removal of isolated pixels with abnormal gray values in the central sub-regions, it further highlights the information of the workpiece itself. For the edge sub-regions, the binarization process makes the edge contour clearer, effectively reducing the situation of edge blurring or confusion with the remaining background. For the central sub-regions, after removing abnormal pixels, the internal structure is purer, and internal details of the workpiece such as textures and holes can be presented more accurately, making the entire workpiece more prominent in the image and facilitating subsequent defect detection;

[0125] During the sub-region recombination process, the edge sub-regions can better adapt to the complexity of edge lighting through binarization with a dynamic gray value threshold. For example, in areas of high-light reflection or shadow that may appear at the edge, binarization can determine the threshold according to the principle of maximum between-class variance, enabling edge details to be better revealed under different lighting conditions. For the central sub-region, the operation of removing abnormal pixels also improves the lighting effect because these abnormal pixels may be caused by local over-illumination or under-illumination. After removal, the lighting in the central region becomes more uniform, thus optimizing the lighting environment for internal details and making the details more clearly visible;

[0126] The second workpiece image provides more favorable conditions for defect detection. The clear edge contour and pure central region make defects easier to be detected. Whether it is a breakage or size deviation at the edge, or internal structure damage or texture abnormality in the central region, etc., these defects can be presented in a clearer form in the second workpiece image, thereby improving the accuracy and reliability of defect detection and helping to timely discover quality problems in the production process.

[0127] The warning module detects defects in the processed second workpiece image. Once a defect is detected, the system immediately issues an alarm. This function can quickly respond to quality problems in the production process, reminding operators to take timely measures, such as adjusting the production process, replacing equipment parts, etc., thereby effectively reducing the scrap rate, reducing production costs, and improving the economic efficiency and product competitiveness of the enterprise.

[0128] This system aims to use Internet of Things technology to detect workpieces in the CNC production process in real time to ensure that product quality meets standards. The image processing module is set up to collect the workpiece production image through a camera device. Next, the background of the workpiece is removed to obtain the first workpiece image containing workpiece information. Then, the first workpiece image is divided into multiple sub-regions of different shapes through connection points. Preliminary light compensation is performed on each sub-region, which can effectively improve the image quality problem caused by uneven illumination. By dividing the multiple sub-regions into edge sub-regions and central sub-regions, binary processing is performed on the edge sub-regions and the operation of removing isolated pixels is performed on the central sub-regions. Finally, the processed edge sub-regions and central sub-regions are re-stitched and combined according to the original division positions to obtain the second workpiece image. Finally, workpiece defect detection is carried out based on the image of the second workpiece image, improving the accuracy of defect detection.

[0129] Such as Figure 2 shown, a method for detecting workpieces in CNC production based on the Internet of Things includes the following steps:

[0130] S1. Shoot the workpiece during production through a camera device to obtain the workpiece production image;

[0131] S2. For the workpiece production image of a certain workpiece, remove the background of the workpiece production image based on the edge detection algorithm to obtain the first workpiece image;

[0132] S3. Identify different shapes on the first workpiece image, determine the connection points between the shapes, and divide the first workpiece image into multiple sub-regions of different shapes through the connection points;

[0133] S4. Perform preliminary light compensation on each sub-region in the first workpiece image respectively;

[0134] S5. Perform edge detection on the first workpiece image based on the edge detection algorithm to obtain the edge line of the workpiece. For multiple sub-regions of different shapes in the first workpiece image, through the contour tracking algorithm, record the coordinates of each boundary pixel in sequence along the boundary of the sub-region to form a boundary line;

[0135] If there is an overlapping part between the boundary line of the sub-region and the edge line, mark the sub-region as an edge sub-region;

[0136] If there is no overlapping part between the boundary line of the sub-region and the edge line, mark the sub-region as a central sub-region;

[0137] The number of central sub-regions can be 0;

[0138] S6. For the edge sub-regions, set a dynamic gray value threshold, and perform binarization processing on the pixels within the edge sub-regions according to the dynamic gray value threshold; for the central sub-regions, remove the isolated pixels with abnormal gray values within the central sub-regions; then splice and combine the edge sub-regions and the central sub-regions according to the original division positions to obtain a second workpiece image;

[0139] S7. Perform workpiece defect detection according to the second workpiece image.

[0140] Meanwhile, the content not described in detail in this specification belongs to the prior art well-known to those skilled in the art.

[0141] In the embodiments provided by the present invention, it should be understood that the disclosed system or method can be implemented in other ways. For example, the above-described invention embodiments are merely illustrative. For example, the division of modules is only a logical function division, and there may be other division methods in actual implementation.

[0142] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules. They can be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0143] In addition, in each embodiment of the present invention, the functional modules can be integrated into one processing module, or each module can exist physically alone, or two or more modules can be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0144] For those skilled in the operation and maintenance field, it is obvious that the present invention is not limited to the details of the above-mentioned exemplary embodiments, and can be implemented in other specific forms without departing from the basic characteristics of the present invention.

[0145] The above is only the preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the technical solution and inventive concept of the present invention, makes equivalent substitutions or changes, and should be covered by the protection scope of the present invention.

Claims

1. An IoT-based numerical control production workpiece detection system, characterized in that, Including: Image acquisition module: Composed of camera devices installed on numerically controlled production equipment, responsible for taking real-time pictures of workpieces during production to obtain workpiece production diagrams; Image processing module: Used to perform light compensation on the workpiece production diagram; The image processing module includes: Background removal unit: Based on the edge detection algorithm, analyze the workpiece production diagram, remove the background part, and obtain the first workpiece diagram containing workpiece information; Region division unit: Identify different shapes on the first workpiece diagram in the background removal unit, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points; Light compensation unit: Perform preliminary light compensation on each sub-region in the first workpiece diagram in the region division unit; Sub-region classification unit: Based on the edge detection algorithm, perform edge detection on the first workpiece diagram that has undergone preliminary light compensation by the light compensation unit to obtain the edge line of the workpiece; At the same time, for each sub-region, through the contour tracking algorithm, record the coordinates of each boundary pixel in sequence along the boundary of the sub-region to form a boundary line; If there is an overlapping part between the boundary line of the sub-region and the edge line, mark this sub-region as an edge sub-region; if there is no overlapping part between the boundary line of the sub-region and the edge line, mark this sub-region as a central sub-region; Sub-region recombination unit: For the edge sub-regions in the sub-region classification unit, set a dynamic gray value threshold for binary processing; for the central sub-regions in the sub-region classification unit, remove the isolated pixels with abnormal gray values; finally, splice and combine the processed edge sub-regions and central sub-regions according to the original division positions to obtain the second workpiece diagram; Early warning module: Perform workpiece defect detection through the second workpiece diagram. If a defect is detected, the system issues an alarm.

2. The IoT-based numerical control production workpiece detection system according to claim 1, wherein, In the background removal unit, the background of the picture data is removed based on the edge detection method to obtain the first workpiece diagram as follows: The edge detection algorithm uses the Canny edge detection algorithm. When using the Canny edge detection algorithm, first perform noise reduction processing on the picture data, then determine the edge pixels by calculating the gradient magnitude and direction of the image, then use non-maximum suppression to remove non-edge pixel points, and finally determine strong edges and weak edges through double-threshold detection, connect the weak edges to form a complete workpiece edge contour. After that, through the contour information, retain the first workpiece diagram by filling the inside of the contour and remove the background.

3. The IoT-based numerical control production workpiece detection system according to claim 2, characterized in that In the region division unit, identify different shapes on the first workpiece diagram, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points as follows: For a certain first workpiece diagram, use the Hough transform method to identify different shapes on the first workpiece diagram. After identifying each shape, extract the contour of each shape. For the contours of adjacent shapes, use geometric calculation methods to solve their intersection points as the connection points; Take the obtained connection points as the starting point of segmentation. Starting from the connection points, along the shape boundary, use the depth-first search or breadth-first search algorithm to mark the boundary pixels belonging to the same shape as the same category, thereby dividing the first workpiece diagram into multiple sub-regions of different shapes.

4. The IoT-based CNC production workpiece detection system according to claim 1 or 3, characterized in that, In the light compensation unit, during the preliminary light compensation, in the first workpiece image, for a certain sub-region i, calculate the average gray value of the sub-region i According to the preset standard average gray value Perform light compensation, and the compensation formula is: Among them, I i is the pixel value of the original area, and I' i is the pixel value after compensation.

5. The IoT-based numerical control production workpiece detection system according to claim 1, characterized in that, In the sub-region recombination unit, for the edge sub-regions in the sub-region classification unit, set a dynamic grayscale value threshold for binarization. The specific steps are as follows: Step 1: Statistically analyze the image grayscale histogram: For the edge sub-regions, traverse all the pixels in the entire edge sub-region image, count the frequency of each grayscale level, and construct a grayscale histogram; Assume the grayscale level range is 0 - M, and create an array histogram with a length of M + 1 to record the number of pixels for each grayscale level; Step 2: Calculate the total number of pixels and the probability of each grayscale level: Add up all the elements in the grayscale histogram array to obtain the total number of pixels N of the image, that is For each gray level i, calculate the probability P of its occurrence in the image i , and the calculation formula is Step 3: Traverse all possible thresholds for between-class variance calculation: Start from the minimum grayscale level 0 and end at the maximum grayscale level M, and sequentially use each grayscale level as the candidate threshold T for calculation; For each candidate threshold T, divide the pixels in the image into two categories. Pixels with grayscale values less than or equal to T are classified into the first grayscale value category, and pixels with grayscale values greater than T are classified into the second grayscale value category; Assume the probability w0 of the first grayscale value category is the sum of the probabilities of all pixels with grayscale values less than or equal to T; Assume the probability w1 of the second grayscale value category is the sum of the probabilities of all pixels with grayscale values greater than T, and w1 = 1 - w0; Calculate the average grayscale value μ0 of the first grayscale value category, calculate the average grayscale value μ1 of the second grayscale value category, and calculate the average grayscale value μ of the entire image; Calculate the between-class variance σ 2 , σ 2 = w0 × (μ0 - μ) 2 + w1(μ1 - μ) 2 ; Step 4: Determine the threshold that maximizes the between-class variance: Within the gray level range of 0 - M, after traversing all thresholds, compare the between-class variance σ 2 calculated each time, and record the between-class variance σ 2 corresponding to the maximum value, and set the threshold T max at this time. Let T max be the threshold for distinguishing the first gray value classification and the second gray value classification in the edge sub-region image; According to the determined threshold T max , perform binarization processing on the pixels within the edge sub-region, and set the pixels with gray values greater than T max to 255, and set the pixels with gray values less than or equal to T max to 0.

6. The IoT-based numerical control production workpiece detection system according to claim 1 or 5, characterized in that In the sub-region recombination unit, for the central sub-regions, remove the isolated pixels with abnormal grayscale values in the central sub-regions as follows: For the central sub-regions, traverse all the pixels in the entire central sub-region image and count the grayscale value of each pixel; Set a pixel range of Y × Y. The central pixel within the pixel range Y × Y is the target pixel. Calculate the mean X and standard deviation R of the grayscale values of the pixels within the pixel range Y × Y. If the grayscale value of the target pixel is greater than X + kR or less than X - kR, then adjust the grayscale value of the target pixel to the mean X.

7. The IoT-based CNC production workpiece detection system according to claim 6, wherein The value range of Y is 3 - 9, and the value range of k is 2 - 3.

8. The method for detecting numerically controlled production workpieces based on the Internet of Things according to any one of claims 1-7, characterized in that, It includes the following steps: S1. Use a camera device to photograph the workpiece during production to obtain a workpiece production diagram; S2. For the workpiece production diagram of a certain workpiece, based on an edge detection algorithm, remove the background of the workpiece production diagram to obtain a first workpiece diagram; S3. Identify different shapes on the first workpiece diagram, determine the connection points between the shapes, and divide the first workpiece diagram into multiple sub-regions of different shapes through the connection points; S4. Perform preliminary light compensation on each sub-region in the first workpiece diagram respectively; S5. Perform edge detection on the first workpiece diagram based on an edge detection algorithm to obtain the edge line of the workpiece. For the multiple sub-regions of different shapes in the first workpiece diagram, through a contour tracking algorithm, record the coordinates of each boundary pixel in sequence along the boundary of the sub-region to form a boundary line; If there is an overlapping part between the boundary line of the sub-region and the edge line, then mark this sub-region as an edge sub-region; If there is no overlapping part between the boundary line of the sub-region and the edge line, then mark this sub-region as a central sub-region; S6. For the edge sub-region, set a dynamic gray value threshold, and perform binarization processing on the pixels within the edge sub-region according to the dynamic gray value threshold; for the central sub-region, remove the isolated pixels with abnormal gray values within the central sub-region; then splice and combine the edge sub-region and the central sub-region according to the original division positions to obtain a second workpiece image; S7. Perform workpiece defect detection according to the second workpiece image.

Citation Information

Patent Citations

  • Image detection method for automatically detecting straws left in grains

    CN107633503A

  • Hollow cylinder work-piece surface defect detection system and method

    CN108596909A

  • Downhole image processing method based on improved bilateral filtering

    CN110288536A

  • Backlight plate detection method and system based on secondary exposure

    CN110428411A

  • Fluorescent glue defect segmentation method robust to illumination change

    CN110610496A