Machine vision general detection algorithm, device and equipment
By constructing the training set and traversing each image detection algorithm in the computer vision algorithm library, we automatically find the algorithm that is most suitable for specific detection tasks, solving the problem of insufficient automatic adaptation capabilities of algorithms in the existing technology, improving the accuracy and versatility of detection, and improving the stability of detection quality.
Patent Information
- Application Number
- CN202510406165.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The existing general machine vision detection algorithm lacks automatic adaptability and is difficult to deal with complex and changeable scenarios. The accuracy and universality of detection are limited, and the inconsistent detection results caused by individual differences in operators affect the stability of detection quality.
By acquiring and annotating multiple sample images and detection images, the training set is constructed and traversing each image detection algorithm in the computer vision algorithm library, the training set is used to train the image detection algorithm, automatically find the algorithm that is most suitable for a specific detection task, and calculate the overlap degree based on the differences in image categories and defect types to determine the best detection algorithm.
It greatly enhances the automatic adaptation capability of the algorithm, can effectively deal with complex and changeable scenarios, improve the accuracy and versatility of detection, reduce the interference of human factors on the detection results, and improve the stability of detection quality.
Smart Images

Figure CN119919743A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to a general machine vision detection algorithm, device and equipment. Background Art
[0002] In the field of industrial production and logistics, machine vision has shown significant value. In terms of industrial production, it can monitor product quality in real time, accurately detect defects, and effectively improve production efficiency and product quality; in the field of logistics, it can realize automatic sorting and identification of goods and optimize logistics processes. The realization of these functions depends on a variety of image detection algorithms in the computer vision algorithm library, which are used for image detection of industrial products and goods. However, there is a clear shortage of computer vision algorithm libraries at present. On the one hand, the scope of use of algorithms is extremely broad and cross-cutting, making it difficult to clarify the best application scenarios of each algorithm in actual application; on the other hand, there is a lack of unified standards or specifications, and it is impossible to provide users with effective guidance for selecting the most suitable algorithm. This series of problems has led to an urgent need for a general machine vision detection algorithm that can span different scenarios and detection objects in actual operations to meet the needs of various industries for efficient and accurate image detection.
[0003] In the prior art, a general machine vision detection algorithm provided by publication number CN115100150A includes the following steps: S1, data labeling; S2, deep learning model pre-selection; S3, rough extraction of detection area; S4, fine extraction of detection area; S5, detection area fitting; S6, defect detection; S7, defect screening; S8, data integration. This method summarizes and classifies the traditional algorithms and deep learning algorithms commonly used in machine vision projects into various modules, uses these modules as various modules of the detection system, and adds a recommendation mechanism. The modules are selected manually according to the experimental results for different application scenarios to form a detection system that meets the requirements. The entire module uses an open source library or is developed by itself, and no longer uses a commercial library. It not only reduces the difficulty and complexity of the work, reduces the technical level requirements of personnel, but also shortens the development cycle and reduces labor and time costs.
[0004] However, there are still the following deficiencies. From the above statements, it can be seen that the module composition of the prior art relies on manual selection for different application scenarios based on experimental results, lacks the ability of automatic algorithm adaptation, and is difficult to cope with complex, changeable and large-scale scenes. When detecting new images, it is only based on a fixed process, and does not fully utilize the characteristics of the new image itself and the matching degree with the existing algorithm library to optimize the detection, resulting in limited detection accuracy and versatility. In addition, different operators have different project experience and knowledge reserves. Even with the assistance of intelligent parameter setting functions, due to the subjective nature of intuitive feelings, different people have different observation focuses and sensitivities on images, and their understanding and judgment of the same image will also be different. This problem of inconsistent detection results caused by individual differences among operators affects the stability of detection quality.
[0005] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention
[0006] The purpose of the present invention is to provide a general machine vision detection algorithm, device and equipment to solve the problems raised in the above background technology.
[0007] To achieve the above object, the present invention provides the following technical solutions: A general machine vision detection algorithm, the specific steps include: S1: collecting a variety of sample images and test images and annotating them, wherein the annotated contents include image categories and defect types, performing edge detection on the sample images and the test images, obtaining defect contours, and extracting defect features on the defect contours, wherein the defect features include a first defect position and a first defect area; S2: Use the sample image as input features, the corresponding annotation content and defect features as output labels, build a training set, use the annotation content and defect features corresponding to the detection image as standard reference data, traverse each image detection algorithm in the computer vision algorithm library, and use the training set to train the image detection algorithm; S3: Input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap degree according to the difference in image category and defect type, sort the overlap degrees from high to low, and determine the image inspection algorithm with the highest overlap degree as the best inspection algorithm; S4: Compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
[0008] Furthermore, edge detection is performed on the sample image to obtain the contour of the sample image defect. The specific process is as follows: Convert the sample image to a grayscale image. For RGB images, use the formula: ; in, is the gray value of the pixel, , , are the pixel values of the red channel, green channel, and blue channel; Use the Sobel operator to calculate the horizontal and vertical gradients: ; ; in, is the horizontal gradient, is the vertical gradient, is a sample image, represents the convolution operation, The gradient magnitude and direction are: ; ; in, is the gradient amplitude, is the gradient direction; The gradient amplitude By comparing the two thresholds, edge pixels in the sample image are identified. The specific process is as follows: when , the pixels are marked as strong edge pixels; when , the pixel is marked as a weak edge pixel; when , the pixels are marked as non-edge pixels; in, is the high threshold, is the low threshold; Starting from the strong edge pixels, the weak edge pixels connected to them are also marked as edge pixels using connectivity analysis to obtain a complete and continuous edge image. The contour of the defect is extracted based on the edge image, and the contour extraction algorithm is used to find the closed curve composed of continuous edge pixels in the image, which is the contour of the defect in the sample image. The method of performing edge detection on the detection image and obtaining the contour of the detection image defect is the same as the method of performing edge detection on the sample image and obtaining the contour of the sample image defect.
[0009] Furthermore, features are extracted from the contour of the defect, including the first defect position and the first defect area, and the centroid coordinates thereof are calculated as the first defect position. The centroid coordinates are calculated by the following formula: ; ; in, are the horizontal and vertical coordinates of the centroid, that is, the coordinates of the first defect position of the sample image are , For the outline The horizontal and vertical coordinates of pixels, is the index of the pixel on the contour, is the total number of pixels on the contour; The first defect area of the sample image is equal to the number of pixels inside the defect outline multiplied by the area of a single pixel, and the formula is as follows: ; in, is the first defect area of the sample image, is the number of pixels inside the defect outline, is the number of pixels per unit length in the horizontal direction, is the number of pixels per unit length in the vertical direction; The method for obtaining the first defect position and the first defect area of the detection image is the same as the method for obtaining the first defect position and the first defect area of the sample image.
[0010] Furthermore, the specific process of step S3 is as follows: The specific process of step S3 is as follows: The computer vision algorithm library has image detection algorithms, denoted as , For the algorithm library Algorithms, is the index of the algorithm in the algorithm library, is the total number of algorithms in the algorithm library; For Algorithms , and its applicable image category set is recorded as , For the algorithm The set of applicable image categories, For the Algorithms The number of applicable image categories and the defect type set are recorded as , For the Algorithms The set of applicable defect types, For the Algorithms The number of defect types that apply; The image category set of standard reference data is , is the number of image categories of the standard reference data, and the defect type set is , is the number of defect types present in the standard reference data; Calculate the Algorithms The degree of overlap between image categories and standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap between image categories and standard reference data; Calculate the Algorithms The degree of coincidence of defect types with the standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap of defect types with standard reference data; The first Algorithms The defect type overlap and defect type overlap of the standard reference data are linearly weighted to obtain the Algorithms The comprehensive coincidence with the standard reference data is based on the following formula: ; in, For the Algorithms The comprehensive coincidence with the standard reference data is evaluated from two aspects: defect type coincidence and defect type coincidence. Algorithms The degree of overlap with the standard reference data; For the Algorithms The weight coefficient of the overlap between the image category and the standard reference data, For the Algorithms The weight coefficient of the defect type coincidence with the standard reference data is On the basis of ; After calculating the comprehensive overlap of all algorithms, sort them in descending order to obtain the algorithm with the highest overlap, that is, , determined as the best detection algorithm.
[0011] Furthermore, the distance between the two first defect positions is calculated according to the following formula: ; in, is the distance between the two first defect locations, , are the horizontal and vertical coordinates of the first defect position corresponding to the optimal detection algorithm, , are the horizontal and vertical coordinates of the first defect position in the standard reference data; The relative error value of the two first defect areas is calculated according to the following formula: ; in, is the relative error value of the two first defect areas, is the first defect area corresponding to the optimal detection algorithm, is the first defect area in the standard reference data.
[0012] Furthermore, the distance between the two first defect positions and the relative error values of the two first defect areas are compared with the preset thresholds to preliminarily determine whether the best detection algorithm is a general machine vision detection algorithm. The specific process is as follows: when , When , it indicates that the distance between the two first defect positions and the relative error value of the two first defect areas are within the threshold range, and it is preliminarily determined that the best detection algorithm is the general machine vision detection algorithm; when , When , it indicates that the distance between the two first defect positions is within the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas is within the threshold range, and it is determined that the optimal detection algorithm is not the general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; in, is the distance threshold, is the threshold of the relative error value of the area.
[0013] Furthermore, based on the preliminary judgment that the best detection algorithm is a general detection algorithm for machine vision, multiple different new images are used to perform the above detection and comparison process. If the algorithm can meet the position and area error ranges on 90% of the images, then the algorithm is considered to be universal, and is ultimately confirmed to be a general detection algorithm for machine vision. On the contrary, if errors greater than the threshold appear on 50% of the images, it is ultimately confirmed that the algorithm is not a general detection algorithm for machine vision.
[0014] To achieve the above object, the present invention also provides the following technical solutions: A general machine vision detection device, the device is used to execute any of the general machine vision detection algorithms described above, comprising: A labeling and feature extraction module, which is used to collect and label a variety of sample images and test images, wherein the labeling content includes image category and defect type, perform edge detection on the sample images and test images, obtain the contour of the defect, and extract defect features on the contour of the defect, wherein the defect features include a first defect position and a first defect area; The training set construction module is used to construct a training set using sample images as input features and the corresponding annotation content and defect features as output labels. The annotation content and defect features corresponding to the detection image are used as standard reference data, and each image detection algorithm in the computer vision algorithm library is traversed to train the image detection algorithm using the training set. The overlap calculation module is used to input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap according to the difference in image category and defect type, sort the overlap from high to low, and determine the image inspection algorithm with the highest overlap as the best inspection algorithm; A comparison module is used to compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
[0015] A device for storing a computer program, wherein the computer program, when executed by a processor, implements any of the above-mentioned general machine vision detection algorithms.
[0016] Compared with the prior art, the present invention has the following beneficial effects: The present invention abandons the prior art approach of relying on manual selection of algorithm modules for different application scenarios based on experimental results. By automatically traversing all algorithms in the computer vision algorithm library and training based on a large number of sample images, it can automatically find the algorithm that best suits a specific detection task, greatly enhancing the algorithm's automatic adaptation capability. This approach can effectively cope with complex, changeable and large numbers of scenarios, is no longer limited to fixed processes, but trains and screens algorithms based on sample data in different scenarios, thereby improving detection accuracy and versatility.
[0017] When detecting new images, this solution does not only rely on a fixed detection process, but fully explores the characteristics of the new image itself. By constructing training sets and standard reference data, the characteristics of the new image are deeply matched with the algorithms in the existing algorithm library. In the process of training and screening algorithms, the algorithm can learn the relationship between the new image features and annotations, thereby automatically optimizing the detection process according to the characteristics of the new image, improving the accuracy of detection and adaptability to different images.
[0018] Through automated algorithm training, screening and evaluation processes, the interference of human factors on test results is reduced. Operators only need to collect data and start the test program according to the established process. Subsequent algorithm selection, training and judgment are all completed automatically by the system, avoiding the problem of inconsistent test results caused by individual differences among operators and effectively improving the stability of test quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a schematic diagram of the overall method flow of the present invention; Figure 2 This is a block diagram of the module composition of the present invention. DETAILED DESCRIPTION
[0020] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments.
[0021] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0022] Embodiment 1: See also Figure 1 , the present invention provides a technical solution: A general machine vision detection algorithm, the specific steps include: S1: collecting a variety of sample images and test images and annotating them, wherein the annotated contents include image categories and defect types, performing edge detection on the sample images and the test images, obtaining defect contours, and extracting defect features on the defect contours, wherein the defect features include a first defect position and a first defect area; Among them, the first defect position refers to the position with the largest defect, and similarly, the first defect area refers to the area with the largest defect. Therefore, in the calculations below, the first defect position and the first defect area both refer to the position and area with the largest defect.
[0023] Based on the above embodiment, the sizes of the sample image and the detection image are adjusted to 224×224.
[0024] Based on the above embodiment, the sample images include images of mechanical parts, plastic products, and textiles.
[0025] Based on the above embodiments, the computer vision algorithm library includes a scale-invariant feature transformation algorithm, an accelerated robust feature algorithm, an ORB feature extraction algorithm, a YOLO target detection algorithm, a FasterR-CNN target detection algorithm, a Sobel edge detection algorithm, and a Canny edge detection algorithm.
[0026] Based on the above embodiment, the marking contents of the mechanical parts include: Image categories: Classify according to the type of mechanical parts, such as gears, bolts, shafts; Defect types: including cracks, wear, deformation, surface scratches, and holes.
[0027] The labeling contents of plastic products include: Image categories: plastic products are classified according to their use or shape, such as plastic containers, plastic toys, and plastic pipes; Defect types: Common ones include bubbles, flash, deformation, color difference, and rupture.
[0028] The labeling contents of textiles include: Image categories: Textiles are classified by material, purpose or style, such as cotton T-shirts, wool scarves, and silk dresses; Defect types: including stains, breakage, skipped wires, thread pulling, and color difference.
[0029] On the basis of the above embodiment, the collected sample image and the detection image are labeled, and the specific process is as follows: Collect a variety of images of mechanical parts, plastic products or textiles, including normal and defective samples; Use professional image annotation tools, such as VGG Image Annotator, to annotate sample images and test images; Select the corresponding image category label in the annotation tool for annotation. For example, if the image is a gear, select "Gear" as the image category in the annotation tool. Repeat this step for all images to complete the image category annotation. If there are no defects in the image, it is marked as "no defect"; For relatively minor defects, such as skipped threads on textiles and surface scratches on mechanical parts, it is necessary to use point annotation tools to mark key points at the defect location and explain the defect type and location in detail in the annotations; For obvious defects, such as cracks on mechanical parts, bubbles on plastic products, and stains on textiles, use the rectangular box or polygon tool in the annotation tool to select the defect area and note the defect type next to it.
[0030] On the basis of the above embodiment, edge detection is performed on the sample image to obtain the outline of the defect. The specific process is as follows: Convert the color sample image to a grayscale image. For RGB images, use the formula: ; in, is the gray value of the pixel, , , are the pixel values of the red channel, green channel, and blue channel; Use the Sobel operator to calculate the horizontal and vertical gradients: ; ; in, is the horizontal gradient, is the vertical gradient, is a sample image, represents the convolution operation, The gradient magnitude and direction are: ; ; in, is the gradient amplitude, is the gradient direction; Set two thresholds, by gradient amplitude By comparing the two thresholds, edge pixels in the sample image are identified. The specific process is as follows: when , the pixels are marked as strong edge pixels; when , the pixel is marked as a weak edge pixel; when , the pixels are marked as non-edge pixels; in, is the high threshold, is the low threshold; Starting from the strong edge pixels, the weak edge pixels connected to them are also marked as edge pixels by using connectivity analysis, so as to obtain a more complete and continuous edge image, wherein connectivity analysis is a prior art and will not be described in detail here; Extract the contour of the defect based on the edge image, and use the contour extraction algorithm to find the closed curve composed of continuous edge pixels in the image, which is the contour of the defect in the sample image; The method of performing edge detection on the detection image and obtaining the contour of the detection image defect is the same as the method of performing edge detection on the sample image and obtaining the contour of the sample image defect.
[0031] Among them, the specific steps of the contour extraction algorithm to extract the contour of the defect are as follows: Binarize the input edge image to ensure that there are only foreground (edge pixels) and background in the image; Starting from the boundary of the image, find the first unvisited edge pixel as the starting point; Start tracing adjacent edge pixels in a predetermined direction (e.g., clockwise) and record the coordinates of the pixels passed; Continue tracking until you return to the starting point, forming a closed outline; Repeat the above steps until all edge pixels have been visited, thereby extracting the outline of the defect; Features are extracted from the defect contour, including the first defect position and the first defect area, and the centroid coordinates are calculated as the first defect position. The centroid coordinates are calculated using the following formula: ; ; in, are the horizontal and vertical coordinates of the centroid, that is, the coordinates of the first defect position of the sample image are , For the outline The horizontal and vertical coordinates of pixels, is the index of the pixel on the contour, is the total number of pixels on the contour; The first defect area of the sample image is equal to the number of pixels inside the defect outline multiplied by the area of a single pixel, and the formula is as follows: ; in, is the first defect area of the sample image, is the number of pixels inside the defect outline, is the number of pixels per unit length in the horizontal direction, is the number of pixels per unit length in the vertical direction.
[0032] The method for obtaining the first defect position and the first defect area of the detection image is the same as the method for obtaining the first defect position and the first defect area of the sample image.
[0033] S2: Use the sample image as input features, the corresponding annotation content and defect features as output labels, build a training set, use the annotation content and defect features corresponding to the detection image as standard reference data, traverse each image detection algorithm in the computer vision algorithm library, and use the training set to train the image detection algorithm; On the basis of the above embodiment, the image detection algorithm is composed of a deep learning network based on a multilayer perceptron, and the deep neural network of the multilayer perceptron includes an input layer, a first hidden layer, a second hidden layer, a third hidden layer and an output layer, and the first hidden layer, the second hidden layer and the third hidden layer each have at least two neurons, and all use ReLU (Rectified Linear Unit), that is, rectified linear unit, as an activation function; In the image detection algorithm, the input features of the deep learning network of the multilayer perceptron include: sample image, 1 feature.
[0034] The structure of the deep learning network of multi-layer perceptron is: Input layer: receives input of 1 feature; The first hidden layer has 128 neurons and uses ReLU as the activation function. The second hidden layer has 64 neurons and also uses the ReLU activation function. The third hidden layer has 32 neurons and uses the ReLU activation function. Output layer: has 1 neuron, corresponding to the annotation content and defect features.
[0035] The process of training an image detection algorithm is as follows: The sample image is used as the input, and the corresponding annotation content and defect features are used as the output label for training. The mean square error is used as the loss function. When the mean square error is When the image is within the range, the training of the image detection algorithm is completed.
[0036] S3: Input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap according to the difference in image category and defect type, sort the overlap from high to low, and determine the image inspection algorithm with the highest overlap as the best inspection algorithm. There may be more than two best inspection algorithms with equal overlap. If there are more than two best inspection algorithms, the one with higher frequency of use will be selected as the best inspection algorithm based on its previous usage frequency.
[0037] Based on the above embodiment, the specific process of step S3 is as follows: The computer vision algorithm library has image detection algorithms, denoted as , For the algorithm library Algorithms, is the index of the algorithm in the algorithm library, is the total number of algorithms in the algorithm library; For Algorithms , and its applicable image category set is recorded as , For the algorithm The set of applicable image categories, For the Algorithms The number of applicable image categories and the defect type set are recorded as , For the Algorithms The set of applicable defect types, For the Algorithms The number of defect types that apply; The image category set of standard reference data is , is the number of image categories of the standard reference data, and the defect type set is , is the number of defect types present in the standard reference data; Calculate the Algorithms The degree of overlap between image categories and standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap between image categories and standard reference data; Calculate the Algorithms The degree of coincidence of defect types with the standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap of defect types with standard reference data; The first Algorithms The defect type overlap and defect type overlap of the standard reference data are linearly weighted to obtain the Algorithms The comprehensive coincidence with the standard reference data is based on the following formula: ; in, For the Algorithms The comprehensive coincidence with the standard reference data is evaluated from two aspects: defect type coincidence and defect type coincidence. Algorithms The degree of overlap with the standard reference data, and the greater the comprehensive overlap, the higher the overlap; For the Algorithms The weight coefficient of the overlap between the image category and the standard reference data, For the Algorithms The weight coefficient of the defect type coincidence with the standard reference data; In general image quality inspection scenarios, it is necessary to accurately determine the category to which the image belongs and to accurately identify the defect type. , Setting them to the same value allows the comprehensive overlap to evenly reflect the matching degree of the algorithm in terms of image category and defect type.
[0038] Therefore, in On the basis of .
[0039] After calculating the comprehensive overlap of all algorithms, sort them in descending order to obtain the algorithm with the highest overlap, that is, , determined as the best detection algorithm.
[0040] S4: Compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
[0041] Based on the above embodiment, the distance between the two first defect positions is calculated according to the following formula: ; in, is the distance between the two first defect locations, , are the horizontal and vertical coordinates of the first defect position corresponding to the optimal detection algorithm, , are the horizontal and vertical coordinates of the first defect position in the standard reference data; The relative error value of the two first defect areas is calculated according to the following formula: ; in, is the relative error value of the two first defect areas, is the first defect area corresponding to the optimal detection algorithm, is the first defect area in the standard reference data; The distance between the two first defect positions and the relative error values of the two first defect areas are compared with the preset thresholds to preliminarily determine whether the best detection algorithm is a general machine vision detection algorithm. The specific process is as follows: when , When , it indicates that the distance between the two first defect positions and the relative error value of the two first defect areas are within the threshold range, and it is preliminarily determined that the best detection algorithm is the general machine vision detection algorithm; when , When , it indicates that the distance between the two first defect positions is within the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas is within the threshold range, and it is determined that the optimal detection algorithm is not the general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; in, is the distance threshold, The threshold of the relative error value of the area is determined by analyzing the distribution of defect locations and areas in the data records of similar inspection tasks in the past, as well as the performance of different algorithms on these data. For example, by observing the fluctuation range of defect locations and the error range of area measurement in previous data, the threshold is set at a level that can reasonably distinguish normal fluctuations from true anomalies.
[0042] On the basis of the above embodiment, and based on the preliminary judgment that the best detection algorithm is a general detection algorithm for machine vision, multiple different new images are used to perform the above detection and comparison process. If the algorithm can meet the error range of position and area on 90% of the images, then the algorithm is considered to be universal, and finally confirmed to be a general detection algorithm for machine vision; conversely, if errors greater than the threshold appear on 50% of the images, it is finally confirmed that the algorithm is not a general detection algorithm for machine vision.
[0043] See also Figure 2 , the present invention also provides a technical solution: A general machine vision detection device, the device is used to execute any of the general machine vision detection algorithms described above, comprising: A labeling and feature extraction module, which is used to collect and label a variety of sample images and test images, wherein the labeling content includes image category and defect type, perform edge detection on the sample images and test images, obtain the contour of the defect, and extract defect features on the contour of the defect, wherein the defect features include a first defect position and a first defect area; The training set construction module is used to construct a training set using sample images as input features and the corresponding annotation content and defect features as output labels. The annotation content and defect features corresponding to the detection image are used as standard reference data, and each image detection algorithm in the computer vision algorithm library is traversed to train the image detection algorithm using the training set. The overlap calculation module is used to input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap according to the difference in image category and defect type, sort the overlap from high to low, and determine the image inspection algorithm with the highest overlap as the best inspection algorithm; A comparison module is used to compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
[0044] A device for storing a computer program, wherein the computer program, when executed by a processor, implements any of the above-mentioned general machine vision detection algorithms.
[0045] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0046] The above embodiments may be implemented in whole or in part by software, hardware, firmware or any other combination thereof. When implemented using software, the above embodiments may be implemented in whole or in part in the form of a computer program product. Those skilled in the art may appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by computer software, electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed by hardware or software depends on the specific application and design constraints of the technical solution.
[0047] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0048] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A general machine vision detection algorithm, characterized by: The specific steps include: S1: collecting a variety of sample images and test images and annotating them, wherein the annotated contents include image categories and defect types, performing edge detection on the sample images and the test images, obtaining defect contours, and extracting defect features on the defect contours, wherein the defect features include a first defect position and a first defect area; S2: Use the sample image as input features, the corresponding annotation content and defect features as output labels, build a training set, use the annotation content and defect features corresponding to the detection image as standard reference data, traverse each image detection algorithm in the computer vision algorithm library, and use the training set to train the image detection algorithm; S3: Input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap degree according to the difference in image category and defect type, sort the overlap degrees from high to low, and determine the image inspection algorithm with the highest overlap degree as the best inspection algorithm; S4: Compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
2. The general machine vision detection algorithm according to claim 1, characterized in that: Perform edge detection on the sample image to obtain the outline of the sample image defect. The specific process is as follows: Convert the sample image to a grayscale image. For RGB images, use the formula: ; in, is the gray value of the pixel, , , are the pixel values of the red channel, green channel, and blue channel; Use the Sobel operator to calculate the horizontal and vertical gradients: ; ; in, is the horizontal gradient, is the vertical gradient, is a sample image, represents the convolution operation, The gradient magnitude and direction are: ; ; in, is the gradient amplitude, is the gradient direction; The gradient amplitude By comparing the two thresholds, edge pixels in the sample image are identified. The specific process is as follows: when , the pixels are marked as strong edge pixels; when , the pixel is marked as a weak edge pixel; when , the pixels are marked as non-edge pixels; in, is the high threshold, is the low threshold; Starting from the strong edge pixels, the weak edge pixels connected to them are also marked as edge pixels using connectivity analysis to obtain a complete and continuous edge image. The contour of the defect is extracted based on the edge image, and the contour extraction algorithm is used to find the closed curve composed of continuous edge pixels in the image, which is the contour of the defect in the sample image. The method of performing edge detection on the detection image and obtaining the contour of the detection image defect is the same as the method of performing edge detection on the sample image and obtaining the contour of the sample image defect.
3. The general machine vision detection algorithm according to claim 2, characterized in that: Features are extracted from the defect contour, including the first defect position and the first defect area, and the centroid coordinates are calculated as the first defect position. The centroid coordinates are calculated using the following formula: ; ; in, are the horizontal and vertical coordinates of the centroid, that is, the coordinates of the first defect position of the sample image are , For the outline The horizontal and vertical coordinates of pixels, is the index of the pixel on the contour, is the total number of pixels on the contour; The first defect area of the sample image is equal to the number of pixels inside the defect outline multiplied by the area of a single pixel, and the formula is as follows: ; in, is the first defect area of the sample image, is the number of pixels inside the defect outline, is the number of pixels per unit length in the horizontal direction, is the number of pixels per unit length in the vertical direction; The method for obtaining the first defect position and the first defect area of the detection image is the same as the method for obtaining the first defect position and the first defect area of the sample image.
4. The general machine vision detection algorithm according to claim 1, characterized in that: The specific process of step S3 is as follows: There is image detection algorithms, denoted as , For the algorithm library Algorithms, is the index of the algorithm in the algorithm library, is the total number of algorithms in the algorithm library; For Algorithms , and its applicable image category set is recorded as , For the algorithm The set of applicable image categories, For the Algorithms The number of applicable image categories and the defect type set are recorded as , For the Algorithms The set of applicable defect types, For the Algorithms The number of defect types that apply; The image category set of standard reference data is , is the number of image categories of the standard reference data, and the defect type set is , is the number of defect types present in the standard reference data; Calculate the Algorithms The degree of overlap between image categories and standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap between image categories and standard reference data; Calculate the Algorithms The degree of coincidence of defect types with the standard reference data is based on the following formula: ; in, For the Algorithms The degree of overlap of defect types with standard reference data; The first Algorithms The defect type overlap and defect type overlap of the standard reference data are linearly weighted to obtain the Algorithms The comprehensive coincidence with the standard reference data is based on the following formula: ; in, For the Algorithms The comprehensive coincidence with the standard reference data is evaluated from two aspects: defect type coincidence and defect type coincidence. Algorithms The degree of overlap with the standard reference data; For the Algorithms The weight coefficient of the overlap between the image category and the standard reference data, For the Algorithms The weight coefficient of the defect type coincidence with the standard reference data is On the basis of ; After calculating the comprehensive overlap of all algorithms, sort them in descending order to obtain the algorithm with the highest overlap, that is, , determined as the best detection algorithm.
5. The general machine vision detection algorithm according to claim 3, characterized in that: The distance between the two first defect locations is calculated according to the following formula: ; in, is the distance between the two first defect locations, , are the horizontal and vertical coordinates of the first defect position corresponding to the optimal detection algorithm, , are the horizontal and vertical coordinates of the first defect position in the standard reference data; The relative error value of the two first defect areas is calculated according to the following formula: ; in, is the relative error value of the two first defect areas, is the first defect area corresponding to the optimal detection algorithm, is the first defect area in the standard reference data.
6. The general machine vision detection algorithm according to claim 5, characterized in that: The distance between the two first defect positions and the relative error values of the two first defect areas are compared with the preset thresholds to preliminarily determine whether the best detection algorithm is a general machine vision detection algorithm. The specific process is as follows: when , When , it indicates that the distance between the two first defect positions and the relative error value of the two first defect areas are within the threshold range, and it is preliminarily determined that the best detection algorithm is the general machine vision detection algorithm; when , When , it indicates that the distance between the two first defect positions is within the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas is within the threshold range, and it is determined that the optimal detection algorithm is not the general machine vision detection algorithm; when , When , it means that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas exceeds the threshold range, and it is determined that the optimal detection algorithm is not a general machine vision detection algorithm; in, is the distance threshold, is the threshold of the relative error value of the area.
7. The general machine vision detection algorithm according to claim 6, characterized in that: Based on the preliminary judgment that the best detection algorithm is a general detection algorithm for machine vision, multiple different new images are used to perform the above detection and comparison process. If the algorithm can meet the error range of position and area on 90% of the images, then the algorithm is considered to be universal and is ultimately confirmed to be a general detection algorithm for machine vision. On the contrary, if errors greater than the threshold appear on 50% of the images, then it is ultimately confirmed that the algorithm is not a general detection algorithm for machine vision.
8. A general machine vision detection device, the device being used to execute a general machine vision detection algorithm according to any one of claims 1 to 7, characterized in that: include: A labeling and feature extraction module, which is used to collect and label a variety of sample images and test images, wherein the labeling content includes image category and defect type, perform edge detection on the sample images and test images, obtain the contour of the defect, and extract defect features on the contour of the defect, wherein the defect features include a first defect position and a first defect area; The training set construction module is used to construct a training set using sample images as input features and the corresponding annotation content and defect features as output labels. The annotation content and defect features corresponding to the detection image are used as standard reference data, and each image detection algorithm in the computer vision algorithm library is traversed to train the image detection algorithm using the training set. The overlap calculation module is used to input the inspection image into each trained image inspection algorithm, compare the annotation content output by each image inspection algorithm with the standard reference data, calculate the overlap according to the difference in image category and defect type, sort the overlap from high to low, and determine the image inspection algorithm with the highest overlap as the best inspection algorithm; A comparison module is used to compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between the two first defect positions and the relative error value of the two first defect areas, and compare the distance between the two first defect positions and the relative error value of the two first defect areas with their pre-set thresholds, respectively, to determine whether the best detection algorithm is a general machine vision detection algorithm.
9. A device, characterized in that: Used to store a computer program, which, when executed by a processor, implements a general machine vision detection algorithm as described in any one of claims 1-7.
Citation Information
Patent Citations
Machine vision-based workpiece defect detection method
CN109900711A
Universal detection algorithm for machine vision
CN115100150A
Product visual image accurate identification and processing integrated platform
CN118982543A
Training method, detection method, device, equipment, storage medium and program product
CN119671968A
Evaluation method, evaluation apparatus, and non-transitory computer-readable storage medium
US20240273357A1