A general machine vision detection algorithm, device and equipment
By automatically traversing and training algorithms in the computer vision algorithm library, the problem of lack of automatic adaptation capabilities and unstable detection results in the prior art is solved, and more efficient and accurate image detection is achieved.
Patent Information
- Application Number
- CN202510406165.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The existing machine vision algorithm library lacks unified standards and automatic adaptability, making it difficult to deal with complex and changeable detection scenarios, and the stability of the detection results is affected by individual differences in operators.
By collecting and annotating multiple sample images and detection images, the training set is constructed and each image detection algorithm in the computer vision algorithm library is traversed, and the algorithm that is most suitable for a specific detection task is automatically trained and filtered out, and the best detection algorithm is determined.
It improves the accuracy and versatility of the detection, reduces the impact of human factors on the detection results, and enhances the stability of the detection quality.
Smart Images

Figure CN119919743B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image detection, and particularly to a general machine vision detection algorithm, device and equipment. Background Art
[0002] In the fields of industrial production and logistics, machine vision has demonstrated significant value. In industrial production, it can monitor product quality in real time, accurately detect defects, and effectively improve production efficiency and product quality; in the logistics field, it can achieve automatic sorting and identification of goods, optimizing the logistics process. 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 are obvious deficiencies in the current computer vision algorithm library. On the one hand, the application scopes of the algorithms are extremely broad and intersect with each other, making it difficult to clarify the best applicable scenarios of each algorithm during actual application; on the other hand, there is a lack of unified standards or specifications, which cannot provide effective guidance for users to select the most applicable algorithm. This series of problems has led to an urgent need for a general machine vision detection algorithm that can cross different scenarios and detection objects in actual operation to meet the requirements of various industries for efficient and accurate image detection.
[0003] In the prior art, a general machine vision detection algorithm provided by the publication number CN115100150A includes the following steps: S1, data annotation; S2, pre-selection of a deep learning model; S3, rough extraction of a detection area; S4, fine extraction of the detection area; S5, fitting of the detection area; S6, defect detection; S7, defect screening; S8, data integration. This method summarizes and classifies the commonly used traditional algorithms and deep learning algorithms in machine vision projects into various modules, uses these modules as the respective modules of the detection system, and adds a recommendation mechanism. Artificial selection is made according to the experimental effects for different application scenarios to form a detection system that meets the requirements. Moreover, the entire module is implemented using an open-source library or self-developed, without using a commercial library; this not only reduces the work difficulty and complexity, lowers the technical level requirements for personnel, but also shortens the development cycle and reduces the 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 existing technology depends on manual selection according to experimental effects for different application scenarios, lacking the ability of algorithm automatic adaptation, and it is difficult to cope with complex, changeable and large-scale scenarios. When detecting new images, it is only based on a fixed process, and does not fully utilize the characteristics of the new images themselves and the matching degree with the existing algorithm library to optimize the detection, resulting in limited detection accuracy and generality. Moreover, there are differences in the project experience and knowledge reserves of different operators. Even with the assistance of the intelligent parameter setting function, due to the subjectivity of intuitive feelings, different people have different focuses and sensitivities in observing images, and their understandings and judgments of the same image will also be different. This problem of inconsistent detection results caused by individual differences of operators affects the stability of detection quality.
[0005] The above information disclosed in the background art section is only used to strengthen the understanding of the background of the present disclosure. Therefore, it may include information that does not constitute the prior art known to those 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 proposed in the above background art.
[0007] To achieve the above purpose, the present invention provides the following technical solutions:
[0008] A general machine vision detection algorithm, the specific steps include:
[0009] S1: Collect a variety of sample images and detection images and perform annotation. The annotation content includes image categories and defect types. Perform edge detection on the sample images and detection images to obtain the contours of the defects, and extract defect features on the contours of the defects. The defect features include the first defect position and the first defect area;
[0010] S2: Use the sample images as input features, and the corresponding annotation content and defect features as output labels to construct a training set. Use the annotation content and defect features corresponding to the detection images 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 algorithms;
[0011] S3: Input the detection images into each trained image detection algorithm, compare the annotation content output by each image detection algorithm with the standard reference data, calculate the coincidence degree according to the differences in image categories and defect types, sort the coincidence degrees from high to low, and determine the image detection algorithm with the highest coincidence degree as the best detection algorithm;
[0012] S4: Compare the defect features corresponding to the optimal detection algorithm with the defect features in the standard reference data to obtain the distance between the two first defect positions and the relative error value of the two first defect areas. Compare the distance between the two first defect positions and the relative error value of the two first defect areas with their preset thresholds respectively to determine whether the optimal detection algorithm is a general machine vision detection algorithm.
[0013] Further, perform edge detection on the sample image to obtain the contour of the defect in the sample image. The specific process is as follows:
[0014] Convert the sample image into a grayscale image. For an RGB image, through the formula:
[0015] ;
[0016] where is the grayscale value of the pixel, , , are the pixel values of the red channel, green channel, and blue channel;
[0017] Use the Sobel operator to calculate the gradients in the horizontal and vertical directions:
[0018] ;
[0019] ;
[0020] where is the gradient in the horizontal direction, is the gradient in the vertical direction, is the sample image, represents the convolution operation,
[0021] The gradient magnitude and direction are respectively:
[0022] ;
[0023] ;
[0024] where is the gradient magnitude, is the gradient direction;
[0025] Compare the gradient magnitude with two thresholds to identify the edge pixels in the sample image. The specific process is as follows:
[0026] When , the pixel is marked as a strong edge pixel;
[0027] When , the pixel is marked as a weak edge pixel;
[0028] When , the pixel is marked as a non-edge pixel;
[0029] wherein, is the high threshold, is the low threshold;
[0030] Starting from the strong edge pixels, the weak edge pixels connected to them are also marked as edge pixels by using connectivity analysis, and a complete and continuous edge image is obtained. Based on the edge image, the contour of the defect is extracted, and the closed curve composed of continuous edge pixels in the image is found by using the contour extraction algorithm, which is the contour of the defect of the sample image;
[0031] The method for edge detection of the detection image to obtain the contour of the defect of the detection image is the same as the method for edge detection of the sample image to obtain the contour of the defect of the sample image.
[0032] Furthermore, features are extracted on the contour of the defect, including the first defect position and the first defect area. The centroid coordinates are calculated as the first defect position, and the centroid coordinates are calculated by the following formula:
[0033] ;
[0034] ;
[0035] wherein, are the horizontal and vertical coordinates of the centroid, that is, the coordinates of the first defect position of the sample image are , is the horizontal and vertical coordinates of the th pixel on the contour, is the index of the pixel on the contour, is the total number of pixels on the contour;
[0036] The first defect area of the sample image is equal to the number of pixels inside the defect contour multiplied by the area of a single pixel, and the formula is as follows:
[0037] ;
[0038] wherein, is the first defect area of the sample image, is the number of pixels inside the defect contour, is the number of pixels per unit length in the horizontal direction, is the number of pixels per unit length in the vertical direction;
[0039] 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.
[0040] Furthermore, the specific process of step S3 is as follows:
[0041] The specific process of step S3 is as follows:
[0042] There are image detection algorithms in the computer vision algorithm library, labeled as , is the th algorithm in the algorithm library, is the index of the algorithm in the algorithm library, is the total number of algorithms in the algorithm library;
[0043] For the th algorithm , the set of applicable image categories is denoted as , is the set of applicable image categories for algorithm , is the number of image categories applicable to the th algorithm , and the set of defect types is denoted as , is the set of defect types applicable to the th algorithm , is the number of defect types applicable to the th algorithm ;
[0044] The set of image categories of the standard reference data is , is the number of image categories of the standard reference data, and the set of defect types is , is the number of defect types existing in the standard reference data;
[0045] Calculate the image category overlap degree between the th algorithm and the standard reference data, according to the following formula:
[0046] ;
[0047] Among them, is the image category overlap degree between the th algorithm and the standard reference data;
[0048] Calculate the defect type overlap degree between the th algorithm and the standard reference data, according to the following formula:
[0049] ;
[0050] Among them, is the coincidence degree of the defect type of the th algorithm and the standard reference data;
[0051] Perform a linear weighted calculation on the coincidence degree of the defect type of the th algorithm and the standard reference data, and obtain the comprehensive coincidence degree of the th algorithm and the standard reference data. The formula is as follows:
[0052] ;
[0053] Among them, is the comprehensive coincidence degree of the th algorithm and the standard reference data. The comprehensive coincidence degree comprehensively evaluates the coincidence degree of the th algorithm and the standard reference data from two levels: the coincidence degree of the defect type and the coincidence degree of the defect type;
[0054] is the weight coefficient of the image category coincidence degree of the th algorithm and the standard reference data, is the weight coefficient of the defect type coincidence degree of the th algorithm and the standard reference data. On the basis of , let ;
[0055] After calculating the comprehensive coincidence degrees of all algorithms, sort them in descending order to obtain the algorithm with the highest coincidence degree. The algorithm with the highest coincidence degree, that is, , is determined as the best detection algorithm.
[0056] Furthermore, calculate the distance between two first defect positions. The formula is as follows:
[0057] ;
[0058] Among them, is the distance between two first defect positions, , are the horizontal and vertical coordinates of the first defect position corresponding to the best detection algorithm, , are the horizontal and vertical coordinates of the first defect position in the standard reference data;
[0059] Calculate the relative error value of the two first defect areas according to the following formula:
[0060] ;
[0061] Wherein, 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.
[0062] Furthermore, compare the distance between the two first defect positions and the relative error value of the two first defect areas with their preset thresholds respectively to preliminarily determine whether the optimal detection algorithm is a general machine vision detection algorithm. The specific process is as follows:
[0063] 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 optimal detection algorithm is a general machine vision detection algorithm;
[0064] 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. It is determined that the optimal detection algorithm is not a general machine vision detection algorithm;
[0065] When , It indicates 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. It is determined that the optimal detection algorithm is not a general machine vision detection algorithm;
[0066] When , It indicates 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. It is determined that the optimal detection algorithm is not a general machine vision detection algorithm;
[0067] Wherein, is the threshold of the distance, is the threshold of the relative error value of the area.
[0068] Further, on the basis of preliminarily determining that the best detection algorithm is the general machine vision detection algorithm, the above detection and comparison processes are performed using multiple different new images. If the algorithm can meet the error ranges of position and area on 90% of the images, then the algorithm is considered to be general, and finally, the algorithm is confirmed as the general machine vision detection algorithm; conversely, if the error greater than the threshold appears on 50% of the images, it is finally confirmed that the algorithm is not the general machine vision detection algorithm.
[0069] To achieve the above object, the present invention also provides the following technical solutions:
[0070] A general machine vision detection device, which is used to execute any one of the above general machine vision detection algorithms, includes:
[0071] A labeling and feature extraction module, which is used to collect a variety of sample images and detection images and perform labeling. The labeling content includes image categories and defect types, perform edge detection on the sample images and detection images, obtain the contours of the defects, and extract defect features on the contours of the defects. The defect features include the first defect position and the first defect area;
[0072] A training set construction module, which is used to use the sample images as input features, the corresponding labeling content and defect features as output labels to construct a training set, use the labeling content and defect features corresponding to the detection images 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;
[0073] A coincidence degree calculation module, which is used to input the detection images into each trained image detection algorithm, compare the labeling content output by each image detection algorithm with the standard reference data, calculate the coincidence degree according to the differences in image categories and defect types, sort the coincidence degrees from high to low, and determine the image detection algorithm with the highest coincidence degree as the best detection algorithm;
[0074] A comparison module, which 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, compare the distance between the two first defect positions and the relative error value of the two first defect areas with their preset thresholds respectively, and judge whether the best detection algorithm is the general machine vision detection algorithm.
[0075] A device for storing a computer program, where the computer program, when executed by a processor, implements any one of the above general machine vision detection algorithms.
[0076] Compared with the prior art, the beneficial effects of the present invention are:
[0077] The present invention abandons the way in the prior art that relies on manual selection of algorithm modules according to experimental effects for different application scenarios. 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 most suitable for a specific detection task, greatly enhancing the automatic adaptation ability of the algorithm. This way can effectively cope with complex, changeable and large-scale scenarios, no longer being limited to a fixed process, but training and screening algorithms according to sample data in different scenarios, improving the accuracy and generality of detection.
[0078] When detecting a new image, this solution does not solely rely on a fixed detection process, but fully exploits the features of the new image itself. By constructing a training set and standard reference data, it deeply matches the features of the new image with the algorithms in the existing algorithm library. During the process of training and screening algorithms, the algorithm can learn the relationship between the features of the new image and the annotations, thereby automatically optimizing the detection process according to the characteristics of the new image, improving the accuracy of detection and the adaptability to different images.
[0079] Through an automated algorithm training, screening and evaluation process, the interference of human factors on the detection results is reduced. The operator only needs to collect data and start the detection program according to the established process, and the subsequent algorithm selection, training and determination are all automatically completed by the system, avoiding the problem of inconsistent detection results caused by individual differences of operators, and effectively improving the stability of the detection quality. Brief Description of the Drawings
[0080] Figure 1 It is a schematic diagram of the overall method flow of the present invention;
[0081] Figure 2 It is a block diagram of the module composition of the present invention. Detailed Embodiment
[0082] To make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below in conjunction with specific embodiments.
[0083] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention shall have the ordinary meanings understood by those with ordinary skills in the field to which the present invention pertains. The "first", "second" and similar terms used in the present invention do not denote any order, quantity or importance, but are only used to distinguish different components. The terms such as "comprising" or "including" mean that the elements or objects appearing before this word cover the elements or objects listed after this word and their equivalents, without excluding other elements or objects. The terms such as "connected" or "coupled" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The terms such as "upper", "lower", "left" and "right" are only used to represent relative position relationships. When the absolute position of the object being described changes, the relative position relationship may also change accordingly.
[0084] Embodiment 1:
[0085] Please refer to Figure 1 , the present invention provides a technical solution:
[0086] A general machine vision detection algorithm, the specific steps include:
[0087] S1: Collect a variety of sample images and detection images and perform annotation. The annotation content includes image categories and defect types. Perform edge detection on the sample images and detection images to obtain the contours of the defects, and extract defect features on the contours of the defects. The defect features include the first defect position and the first defect area;
[0088] Among them, the first defect position refers to the position where the defect is the largest. Similarly, the first defect area refers to the area where the defect is the largest. Therefore, in the subsequent calculations, both the first defect position and the first defect area refer to the position and area where the defect is the largest.
[0089] Based on the above embodiment, adjust the sizes of the sample images and detection images to 224×224.
[0090] Based on the above embodiment, the sample images include images of mechanical parts, plastic products, and textiles.
[0091] Based on the above embodiment, the computer vision algorithm library includes Scale-Invariant Feature Transform (SIFT) algorithm, Speeded-Up Robust Features (SURF) algorithm, Oriented FAST and Rotated BRIEF (ORB) feature extraction algorithm, You Only Look Once (YOLO) object detection algorithm, Faster Region-based Convolutional Neural Network (Faster R-CNN) object detection algorithm, Sobel edge detection algorithm, and Canny edge detection algorithm.
[0092] Based on the above embodiment, the annotation content of the mechanical parts includes:
[0093] Image category: Classify according to the type of mechanical parts, such as gears, bolts, shafts;
[0094] Defect types: Include cracks, wear, deformation, surface scratches, holes.
[0095] The labeling content of plastic products includes:
[0096] Image category: Classify according to the use or shape of plastic products, such as plastic containers, plastic toys, plastic pipes;
[0097] Defect types: Commonly include bubbles, flash, deformation, color difference, rupture.
[0098] The labeling content of textiles includes:
[0099] Image category: Classify according to the material, use or style of textiles, such as cotton T-shirts, wool scarves, silk dresses;
[0100] Defect types: Include stains, damage, skipped stitches, pulled threads, color difference.
[0101] Based on the above embodiments, label the collected sample images and detection images. The specific process is as follows:
[0102] Collect images of various mechanical parts, plastic products or textiles, including normal and defective samples;
[0103] Use professional image annotation tools, such as VGG Image Annotator, to annotate the sample images and detection images;
[0104] 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, and repeat this step for all images to complete the annotation of the image category;
[0105] If there is no defect in the image, label it as "no defect";
[0106] For relatively subtle defects, such as skipped stitches on textiles and surface scratches on mechanical parts, use a point annotation tool to mark the key points at the defect location and describe the defect type and location in detail in the annotation;
[0107] For obvious defects, such as cracks on mechanical parts, bubbles on plastic products, and stains on textiles, use the rectangle or polygon tool in the annotation tool to frame the defect area and indicate the defect type beside it.
[0108] Based on the above embodiments, perform edge detection on the sample images to obtain the contours of the defects. The specific process is as follows:
[0109] Convert the color sample image into a grayscale image. For an RGB image, use the formula:
[0110] ;
[0111] where is the grayscale value of the pixel, , , are the pixel values of the red channel, green channel, and blue channel respectively;
[0112] Calculate the gradients in the horizontal and vertical directions using the Sobel operator:
[0113] ;
[0114] ;
[0115] where is the gradient in the horizontal direction, is the gradient in the vertical direction, is the sample image, represents the convolution operation,
[0116] The gradient magnitude and direction are respectively:
[0117] ;
[0118] ;
[0119] where is the gradient magnitude, is the gradient direction;
[0120] Set two thresholds. By comparing the gradient magnitude with the two thresholds, identify the edge pixels in the sample image. The specific process is as follows:
[0121] When , the pixel is marked as a strong edge pixel;
[0122] When , the pixel is marked as a weak edge pixel;
[0123] When , the pixel is marked as a non-edge pixel;
[0124] where is the high threshold, is the low threshold;
[0125] Starting from the strong edge pixels, using connectivity analysis to mark the weak edge pixels connected to them as edge pixels as well, so as to obtain a more complete and continuous edge image. Among them, connectivity analysis is a prior art and will not be elaborated here;
[0126] Extract the contour of the defect based on the edge image. 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;
[0127] The method of performing edge detection on the detection image to obtain the contour of the defect in the detection image is the same as the method of performing edge detection on the sample image to obtain the contour of the defect in the sample image.
[0128] Among them, the specific steps of the contour extraction algorithm for extracting the contour of the defect are as follows:
[0129] Perform binarization processing on the input edge image to ensure that there are only foreground (edge pixels) and background in the image;
[0130] Starting from the boundary of the image, find the first unvisited edge pixel as the starting point;
[0131] Start tracking adjacent edge pixels in a predetermined direction (such as clockwise), and record the pixel coordinates passed by;
[0132] Continue tracking until returning to the starting point to form a closed contour;
[0133] Repeat the above steps until all edge pixels have been visited, so as to extract the contour of the defect;
[0134] Extract features on the contour of the defect, including the first defect position and the first defect area. Calculate its centroid coordinates as the first defect position. The centroid coordinates are calculated by the following formula:
[0135] ;
[0136] ;
[0137] Among them, are the horizontal and vertical coordinates of the centroid, that is, the coordinates of the first defect position in the sample image are , is the horizontal and vertical coordinates of the th pixel on the contour, is the index of the pixel on the contour, is the total number of pixels on the contour;
[0138] The first defect area of the sample image is equal to the number of pixels inside the defect contour multiplied by the area of a single pixel. The formula is as follows:
[0139] ;
[0140] Among them, is the first defect area of the sample image, is the number of pixels inside the defect contour, is the number of pixels per unit length in the horizontal direction, is the number of pixels per unit length in the vertical direction.
[0141] The method for obtaining the first defect position and the first defect area of the detection image is the same as that of the sample image.
[0142] S2: Using the sample image as the input feature, the corresponding annotation content and defect features as the output labels, construct a training set, and use the corresponding annotation content and defect features of the detection image as the 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;
[0143] Based on the above embodiments, the image detection algorithm is composed of a deep learning network based on a multi-layer perceptron. The deep neural network of the multi-layer perceptron includes an input layer, a first hidden layer, a second hidden layer, a third hidden layer, and an output layer. The first hidden layer, the second hidden layer, and the third hidden layer all have at least two neurons and all use ReLU (Rectified Linear Unit), that is, the rectified linear unit, as the activation function;
[0144] In the image detection algorithm, the input features of the deep learning network of the multi-layer perceptron include: the sample image, 1 feature.
[0145] The structure of the deep learning network of the multi-layer perceptron is:
[0146] Input layer: Receive the input of 1 feature;
[0147] First hidden layer: Has 128 neurons and uses ReLU as the activation function;
[0148] Second hidden layer: Has 64 neurons and also uses the ReLU activation function;
[0149] Third hidden layer: Has 32 neurons and uses the ReLU activation function;
[0150] Output layer: Has 1 neuron, corresponding annotation content and defect features.
[0151] The process of training the image detection algorithm is as follows:
[0152] Using the sample image as the input quantity, and the corresponding annotation content and defect features as the output labels for training, using the mean squared error as the loss function, when the mean squared error is within the range, the training of the image detection algorithm is completed.
[0153] S3: Input the detection image into each trained image detection algorithm, compare the annotation content output by each image detection algorithm with the standard reference data, calculate the coincidence degree according to the differences in the image category and defect type, sort the coincidence degrees from high to low, and determine the image detection algorithm with the highest coincidence degree as the best detection algorithm. There may be more than 2 best detection algorithms with equal coincidence degrees. If there are more than 2 best detection algorithms, determine according to the previous usage frequency, and select the algorithm with a higher usage frequency as the best detection algorithm.
[0154] Based on the above embodiments, the specific process of step S3 is as follows:
[0155] There are image detection algorithms in the computer vision algorithm library, marked as , is the th algorithm in the algorithm library, is the index of the algorithm in the algorithm library, is the total number of algorithms in the algorithm library;
[0156] For the th algorithm , the set of image categories applicable to it is denoted as , is the set of image categories applicable to algorithm , is the th algorithm The number of image categories applicable to it, and the set of defect types is denoted as , is the th algorithm The set of defect types applicable to it, is the th algorithm The number of defect types applicable to it;
[0157] The set of image categories of the standard reference data is , is the number of image categories of the standard reference data, and the set of defect types is , is the number of defect types existing in the standard reference data;
[0158] Calculate the th algorithm The coincidence degree of the image category with the standard reference data is based on the following formula:
[0159] ;
[0160] where, is the coincidence degree of the th algorithm with the image category of the standard reference data;
[0161] Calculate the coincidence degree of the th algorithm with the defect type of the standard reference data. The formula is as follows:
[0162] ;
[0163] where, is the coincidence degree of the th algorithm with the defect type of the standard reference data;
[0164] Perform a linear weighted calculation on the coincidence degree of the th algorithm with the defect type of the standard reference data and the defect type coincidence degree to obtain the comprehensive coincidence degree of the th algorithm with the standard reference data. The formula is as follows:
[0165] ;
[0166] where, is the comprehensive coincidence degree of the th algorithm with the standard reference data. The comprehensive coincidence degree comprehensively evaluates the coincidence degree of the th algorithm with the standard reference data from two aspects: the defect type coincidence degree and the defect type coincidence degree. The larger the comprehensive coincidence degree, the higher the coincidence degree;
[0167] is the weight coefficient of the th algorithm with the image category coincidence degree of the standard reference data, is the weight coefficient of the th algorithm with the defect type coincidence degree of the standard reference data;
[0168] In a general image quality detection scenario, it is necessary to accurately judge the category to which the image belongs and accurately identify the defect type therein. Neither can be lacking. At this time, 、 Setting them to the same value can enable the comprehensive coincidence degree to evenly reflect the matching degree of the algorithm in terms of both image categories and defect types.
[0169] Therefore, based on , let .
[0170] After calculating the comprehensive coincidence degrees of all algorithms, sort them in descending order, obtain the algorithm with the highest coincidence degree, and the algorithm with the highest coincidence degree, that is, , is determined as the best detection algorithm.
[0171] S4: Compare the defect features corresponding to the best detection algorithm with the defect features in the standard reference data, obtain the distance between two first defect positions and the relative error value of two first defect areas, compare the distance between two first defect positions and the relative error value of two first defect areas with their preset thresholds respectively, and determine whether the best detection algorithm is a general machine vision detection algorithm.
[0172] Based on the above embodiments, the formula for calculating the distance between two first defect positions is as follows:
[0173] ;
[0174] Where is the distance between two first defect positions, , are the horizontal and vertical coordinates of the first defect position corresponding to the best detection algorithm, , are the horizontal and vertical coordinates of the first defect position in the standard reference data;
[0175] The formula for calculating the relative error value of two first defect areas is as follows:
[0176] ;
[0177] Where is the relative error value of two first defect areas, is the first defect area corresponding to the best detection algorithm, is the first defect area in the standard reference data;
[0178] Compare the distance between two first defect positions and the relative error value of two first defect areas with their preset thresholds respectively, and preliminarily determine whether the best detection algorithm is a general machine vision detection algorithm. The specific process is as follows:
[0179] 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, it is preliminarily determined that the best detection algorithm is the general machine vision detection algorithm;
[0180] When , When it indicates that the distance between the two first defect positions is within the threshold range, but the relative error value of the two first defect areas exceeds the threshold range, it is determined that the best detection algorithm is not the general machine vision detection algorithm;
[0181] When , When it indicates that the distance between the two first defect positions exceeds the threshold range, but the relative error value of the two first defect areas is within the threshold range, it is determined that the best detection algorithm is not the general machine vision detection algorithm;
[0182] When , When it indicates that the distance between the two first defect positions exceeds the threshold range, and the relative error value of the two first defect areas also exceeds the threshold range, it is determined that the best detection algorithm is not the general machine vision detection algorithm;
[0183] Among them, is the threshold of the distance, is the threshold of the relative error value of the area. According to the data records of previous similar detection tasks, analyze the distribution of defect positions and areas in these data, as well as the performance of different algorithms on these data, to determine the appropriate threshold. For example, observe the fluctuation range of defect positions and the error range of area measurement in previous data, and set the threshold at the boundary that can reasonably distinguish normal fluctuations and true anomalies.
[0184] On the basis of the above embodiments, on the basis of preliminarily determining that the best detection algorithm is the general machine vision detection algorithm, use multiple different new images 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 it is considered that the algorithm has universality, and finally confirm that the algorithm is the general machine vision detection algorithm; otherwise, if the error greater than the threshold appears on 50% of the images, finally confirm that the algorithm is not the general machine vision detection algorithm.
[0185] Please refer to Figure 2 , the present invention also provides a technical solution:
[0186] A general machine vision detection device, the device is used to execute any one of the above-mentioned general machine vision detection algorithms, including:
[0187] The annotation and feature extraction module is used to collect various sample images and detection images for annotation. The annotation content includes image categories and defect types. Edge detection is performed on the sample images and detection images to obtain the contours of the defects, and defect features are extracted on the contours of the defects. The defect features include the first defect position and the first defect area;
[0188] The training set construction module is used to construct a training set with the 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 images are used as standard reference data. Each image detection algorithm in the computer vision algorithm library is traversed, and the training set is used for the training of the image detection algorithms;
[0189] The coincidence degree calculation module is used to input the detection images into each trained image detection algorithm, compare the annotation content output by each image detection algorithm with the standard reference data, calculate the coincidence degree according to the differences in image categories and defect types, sort the coincidence degrees from high to low, and determine the image detection algorithm with the highest coincidence degree as the best detection algorithm;
[0190] The 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, compare the distance between the two first defect positions and the relative error value of the two first defect areas with their preset thresholds respectively, and determine whether the best detection algorithm is a general machine vision detection algorithm.
[0191] A device for storing a computer program, which when executed by a processor implements a general machine vision detection algorithm as described in any one of the above.
[0192] The above formulas are all dimensionless and take their numerical values for calculation. The formulas are obtained by collecting a large amount of data for software simulation to get a formula closest to the real situation. The preset parameters in the formulas are set by those skilled in the art according to the actual situation.
[0193] The above embodiments can be implemented in whole or in part by software, hardware, firmware, or any other combination. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by computer software and electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software methods depends on the specific application and design constraints of the technical solution.
[0194] The unit described as a separation component may or may not be physically separated. The component displayed as a unit may or may not be a physical unit, and it may be located in one place or distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0195] As described above, the above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered within 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
Universal detection algorithm for machine vision
CN115100150A
Machine vision-based workpiece defect detection method
CN109900711A
Evaluation method, evaluation apparatus, and non-transitory computer-readable storage medium
US20240273357A1