A mask detection method integrating machine vision and deep learning
By integrating machine vision and deep learning into a mask detection method, the problems of low efficiency and low accuracy of traditional detection methods are solved, achieving efficient and accurate mask detection and character recognition, and improving the robustness and adaptability of the system.
Patent Information
- Application Number
- CN202210394659.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-15
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2042-04-15
AI Technical Summary
Traditional mask testing methods rely on manual inspection, which is inefficient, inaccurate, and has a high rate of missed detections. Furthermore, machine vision-based inspection systems are not robust, struggle to handle harsh lighting conditions and unknown defects, and cannot effectively identify characters on the reverse side.
This invention integrates machine vision and deep learning to detect mask defects and identify characters on the reverse side by adjusting the light source and lens parameters. Templates are then established to improve robustness and accuracy.
It achieves efficient and accurate mask testing, reduces production costs, improves the robustness and accuracy of the testing system, and can handle character recognition under various defects and harsh lighting conditions.
Smart Images

Figure CN114689512B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a mask detection method integrating machine vision and deep learning. Background Art
[0002] Traditional mask inspection is based on manual inspection. Workers cannot work continuously for a long time, and they are prone to fatigue, low efficiency, low accuracy, high missed detection rate, and high labor costs. Bag masks have many types of defects, such as empty bags, two masks in one bag, wrinkled masks, membrane joints, ear straps, mask bags, abnormal coding, wrinkled membranes, roll film displacement, sealed openings, no ear straps, debris and pollution in the bag. The printing position of the characters on the back of the mask is not fixed, and the characters are very small and contain adhesion. It is difficult and slow for human eyes to detect and identify them. Therefore, manual inspection is time-consuming and laborious, and the effect is not good. A high-speed and accurate mask detection and identification method is urgently needed.
[0003] At present, there are only mask inspection systems based on traditional machine vision on the market, but they can detect only a few types of mask defects, and they are not very robust. They cannot detect defects under harsh or uneven lighting. The inspection system parameters are very dependent on the current imaging environment. When the imaging components such as the camera lens light source are slightly changed, the system parameters must be readjusted, which is very troublesome, and the accuracy of this type of inspection system is not high. Moreover, it cannot handle unknown types of defects. When the number of defect types increases, the accuracy may decrease, and additional inspection stations are required. The inspection system based on traditional machine vision is also inaccurate in positioning and identifying characters on the back, and the effect of handling sticky characters or characters under harsh lighting is not good. The accuracy is also not high when the characters are damaged or dirty. . Summary of the invention
[0004] The purpose of the present invention is to provide a mask detection method that integrates machine vision and deep learning to solve the current problems of mask detection accuracy, robustness and intelligence.
[0005] In order to solve the above technical problems, the present invention provides a mask detection method integrating machine vision and deep learning, comprising:
[0006] Step 1: Adjust the conveyor belt speed, light source height brightness, lens field of view and line scan camera parameters to make the image clear and the features obvious;
[0007] Step 2: Place the mask so that the front side of the mask faces upward and the back side faces downward. The upper and lower surface cameras simultaneously capture images of the front and back sides of the mask respectively.
[0008] The upper surface camera first collects several images of masks without defects, and then collects several images of masks with various defects. The two sets of images collected are placed in the OK / NG folder respectively; the lower surface camera collects the reverse side images of the masks without defects and places them in the ocr folder;
[0009] Step 3: Use a deep learning detection and classification algorithm to train the images collected by the upper surface camera;
[0010] For the image captured by the lower surface camera, count the maximum area of the jump range of the 4 lines of characters to be detected, relative to the relative rectangular coordinates of the mask;
[0011] At the same time, the template is established with the 4-line character area of the positive-angle mask;
[0012] Step 4: Unload the material, and the upper and lower surface cameras start to detect respectively;
[0013] The upper surface camera executes the mask defect detection and classification algorithm to classify masks into OK / NG categories, and an alarm is issued for NG masks;
[0014] The lower surface camera performs the algorithm for locating and recognizing characters on the back of the mask;
[0015] Step 5: The lower surface camera executes the production date character recognition algorithm on the back of the mask.
[0016] Optionally, the belt is composed of three sections of belt lines on the same horizontal line, with the same speed and the same width. There are two connections between the three sections of belt lines, and a set of visual systems is installed at each connection:
[0017] The visual system for detecting the upper surface is installed at the connection between the first and second sections of the belt. The upper surface camera is installed above the belt and vertically downward. The light source is installed in a backlight manner, that is, it is installed below the belt and illuminates from bottom to top.
[0018] The visual system for detecting the lower surface is installed at the connection between the second and third sections of the belt. The lower surface camera is installed vertically upward below the belt. The light source is installed in a backlight mode, that is, it is installed above the belt and illuminates from top to bottom.
[0019] Both sets of cameras are line scan cameras, and the line scan direction is along the direction of belt line movement;
[0020] Both sets of light sources are white bar light sources, emitting uniform white light. The brightness of the light source above makes various defects on the surface of the mask clearly visible;
[0021] The lens is a common lens, and the lens matches the camera field of view and the width of the belt line.
[0022] Optionally, the upper surface camera collects images of masks covered with various defects, wherein the types of defects include masks containing roll film joints, abnormal number of masks in a mask bag, abnormal ear straps, continuous packing, abnormal coding, wrinkles on the mask film surface, and roll film displacement;
[0023] The lower surface camera collects the back image of the defect-free mask, collects multiple images of the mask at different positions, angles, light intensity, different positions and angles of the mask in the mask bag, different production dates, and production dates at different positions on the mask, and puts them in the OCR folder.
[0024] Optionally, training the images collected by the upper surface camera using a deep learning detection and classification algorithm includes:
[0025] Several defect-free images and several images containing various defects collected by the upper surface camera are stored in OK and NG folders respectively;
[0026] Perform data augmentation on the collected image data samples, perform certain rotation and translation scaling affine transformation, image brightness adjustment, and uneven lighting processing according to the mask bag, increase the samples in the sample set under various special circumstances, and enhance the robustness of the model;
[0027] According to the constructed data set, the training set, validation set and test set are randomly divided. The training set is used to train the detection and classification model, the validation set is used to evaluate the performance of the detection and classification model, and the test set is used for testing. When the accuracy of the test set can reach more than 99%, the test is passed.
[0028] Optionally, a template is created with a 4-line character area of a positive angle mask including:
[0029] When the incoming mask material is rotated, translated and scaled, firstly, based on threshold segmentation, connected domain screening, and hole filling in hollow areas, the minimum circumscribed rectangle of the mask area is extracted, and then the image is affine transformed to transform the mask into a normal upright mask. Then, based on the relative rectangular area, the initial positioning area of the character area is extracted, and then the image is cropped;
[0030] A template is created to store the 4-line character area of the production date. The template contains the following data: edge features and grayscale information of the 4-line character area, image file of the template, width and height information of the template, the relative rectangular area of the first line of characters relative to the template, and the number of characters;
[0031] Since the position of the mask production date relative to the mask area is not fixed and there is a range of movement, it is necessary to count the 4-line character areas of the production date of a large number of normal masks and calculate the maximum range of the dynamic rectangular area relative to the mask to narrow the character positioning area range and increase the accuracy; the dynamic rectangular area of this mask follows the mask area to rotate, translate and scale, so if the incoming mask is rotated, translated, scaled or tilted, it can also be accurately located.
[0032] Optionally, the upper surface camera performs mask defect detection including:
[0033] (1) First detect the abnormality of the membrane joint. The color of the membrane joint area is different from that of other areas. According to the color space processing, the membrane joint area is extracted. If the membrane joint area is present, the membrane joint is abnormal, and NG is sent and returned directly. Otherwise, enter the next process;
[0034] (2) Determine the area of the minimum circumscribed rectangle and convex hull of the mask area. If the area is less than the given threshold, it is an empty bag. If the area is greater than the given threshold, the bag contains multiple masks or the ear straps exceed the mask area. Send NG and return directly. Otherwise, enter the next process judgment.
[0035] (3) Detect the number of ear straps. Based on the four established rectangular areas, detect the number of ear straps within the four rectangular areas. If the number is less than four, the number of ear straps is abnormal and the function returns NG.
[0036] Optionally, the membrane joint detection method is: the color of the membrane joint area is different from other areas, and the location area of the membrane joint is detected based on the color space processing of the image. The specific implementation is: based on the color image, the color of the membrane joint is yellowish, the mask is blue, and the ear strap is black after backlighting. The three-channel color image is first decomposed into three single-channel images of Red, Green, and Blue, and then the Blue and Red are subtracted to obtain the ImageSub image. First, the original image is segmented by dynamic threshold to obtain the mask area containing the membrane joint, and the background part is eliminated. Then, the black part is obtained by binarization based on the ImageSub image, and then the connected domain is decomposed, and the area with the largest area is taken as the membrane joint area;
[0037] The mask area detection method is as follows: through dynamic threshold segmentation, the mask area that includes the ear strap but does not include the mask pocket is extracted, and the area of the mask's minimum circumscribed rectangle is extracted to determine whether the ear strap exceeds the mask range or the number of masks is abnormal; the area of the mask's minimum circumscribed convex hull is extracted and compared with the area of the minimum circumscribed rectangle; the upper and lower thresholds of the normal area of the mask's minimum circumscribed rectangle and minimum convex hull need to be obtained by collecting a large number of OK and NG pictures for statistical analysis, and the stability and robustness are tested through a large number of images;
[0038] The method for detecting the number of ear straps is as follows: first, based on the regional position of the ear straps in the standard mask, 4 rectangular areas are established. According to the previous detection process, after excluding the abnormal number and color of masks, the remaining images contain an OK mask. Then, based on the relative position of the ear straps relative to a single mask, the following rectangular area is set, a total of 4 rectangles. Within the range of these 4 rectangles, the position of the ear straps is found according to the edge extraction algorithm. If there are 4, it contains two complete ear straps, if there is 1, there is only 1 ear strap, and if it is 0, there is no ear strap.
[0039] Optionally, the upper surface camera performs mask defect detection and classification including: collecting a large number of pictures according to corresponding defects, extracting pictures of the mask area, normalizing them and sending them into a deep learning detection and classification model for classification.
[0040] Optionally, the lower surface camera performs a character positioning algorithm on the back of the mask including:
[0041] Locate the mask location and direction based on threshold segmentation;
[0042] Initial positioning: narrow the limited range of the production date character area according to the relative coordinates of the character area relative to the mask;
[0043] Precise positioning: Based on the template matching algorithm, the 4-line character area of the production date on the back of the mask is located;
[0044] Perform morphological processing on each row to obtain the character area of the first row.
[0045] Optionally, the lower surface camera performs a character recognition algorithm for the production date on the reverse side of the mask:
[0046] Based on OCR character recognition, the final extracted line of character images is segmented, and then individual characters are recognized one by one;
[0047] Based on deep learning, after preprocessing the character image of the entire line, the entire line is recognized and the string is output.
[0048] In the mask detection method integrating machine vision and deep learning provided by the present invention, the imaging effect of the visual system is adjusted; the material is discharged, and a large number of images are collected; the images collected by the upper surface camera are trained with the existing deep learning detection classification algorithm; the four-line character area of the image collected by the lower surface camera is taken to establish a template, and the relevant parameter information is saved; the characters extracted from the lower surface camera picture are trained with traditional OCR and deep learning OCR; the material is discharged, and the upper and lower surface cameras start detection respectively; the upper surface camera executes the mask defect detection classification algorithm, and the masks are divided into OK / NG categories, and the NG mask alarm is triggered, and the lower surface camera executes the mask reverse character positioning and recognition algorithm. The detection method of the present invention has good robustness, high accuracy, high efficiency, and reduces production costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 This is a flow chart of a mask detection method integrating machine vision and deep learning provided by the present invention;
[0050] Figure 2 This is a layout diagram of a mask detection system integrating machine vision and deep learning provided by the present invention;
[0051] Figure 3 This is a diagram showing that the front of the mask is OK and has no defects;
[0052] Figure 4 The NG defect on the front of the mask is a schematic diagram of mask wrinkles;
[0053] Figure 5 The NG defect on the front of the mask is a schematic diagram of the mask containing the membrane joint;
[0054] Figure 6 This is a schematic diagram of the NG defect on the front of the mask being an empty bag;
[0055] Figure 7 The NG defect on the front of the mask is a schematic diagram of multiple masks in the bag;
[0056] Figure 8 The NG defect on the front of the mask is the ear strap extending beyond the range of the mask;
[0057] Fig. 9 The NG defect on the front of the mask is the lack of ear straps;
[0058] Fig.10 The NG defect on the front of the mask is that there is only one ear strap;
[0059] Fig.11 The NG defect on the front of the mask is a schematic diagram of the abnormal mask package connection;
[0060] Fig.12 The NG defect on the front of the mask is a schematic diagram of abnormal film displacement;
[0061] Fig.13 This is a schematic diagram of the detection of the mask front membrane joint area;
[0062] Fig.14 This is a schematic diagram of color space conversion for detecting the mask front membrane joint area;
[0063] Fig.15 This is a schematic diagram of the mask ear strap detection effect;
[0064] Fig.16 This is a global schematic diagram of the reverse side of the mask;
[0065] Fig.17 This is the initial positioning map of the character area on the back of the mask;
[0066] Fig.18 It is the precise positioning map of the character area on the back of the mask;
[0067] Fig.19 This is the first line of character area map finally located on the back of the mask;
[0068] Fig. 20 This is the result of identifying the production date on the back of the mask. DETAILED DESCRIPTION
[0069] The following is a further detailed description of a mask detection method that integrates machine vision and deep learning proposed by the present invention in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become clearer according to the following description and claims. It should be noted that the drawings are all in a very simplified form and are not in precise proportions, and are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention.
[0070] The present invention provides a mask detection method integrating machine vision and deep learning, the process of which is as follows: Figure 1 As shown, the following steps are included:
[0071] Step 1: Adjust the conveyor belt speed, light source height brightness, lens field of view and line scan camera parameters to make the image clear and the features obvious.
[0072] The entire detection system includes two sets of visual systems, which detect the upper surface and lower surface of the mask respectively. Figure 2 As shown;
[0073] The visual system for detecting the upper surface is installed at the junction of the first and second sections of the belt line. The upper surface camera (i.e., camera 1) is installed above the belt line and vertically downward. The lower surface light source (i.e., light source 1) is installed in a backlight manner, that is, it is installed below the belt line and illuminates from bottom to top.
[0074] The visual system for detecting the lower surface is installed at the connection between the second and third sections of the belt line. The lower surface camera (i.e., camera 2) is installed below the belt line and vertically upward. The upper surface light source (i.e., light source 2) is installed in a backlight manner, that is, it is installed above the belt line and illuminates from top to bottom.
[0075] The two sets of cameras are line scanning cameras, and the line scanning direction is along the moving direction of the belt line;
[0076] The two sets of light sources are both white strip light sources that emit uniform white light. The brightness of the light source on the lower surface is appropriate, so that various defects on the upper surface of the mask are clearly visible.
[0077] The lens is a common lens, and the lens matches the camera field of view and the width of the belt line;
[0078] The belt line is composed of three sections of belt lines (i.e., belt line 1, belt line 2, and belt line 3) on the same horizontal line, with the same speed and the same width. There are two connections between the three sections of belt lines, and a set of visual systems is installed at each connection. The movement of objects will not exceed the width range of the belt line;
[0079] Step 2: Place the mask so that the front side of the mask faces upward (i.e., the upper surface) and the back side faces downward (i.e., the lower surface). The upper and lower surface cameras collect images at the same time, and collect the front and back images of the mask respectively; the upper surface camera first collects 2,000 images such as Figure 3 The defect-free masks shown in the figure are collected, and then 2000 masks with various defects are collected. The pictures of various types of defects are as follows Figure 4 to Figure 12 As shown, the types of defects are as follows: the mask contains a roll film joint, the number of masks in the mask bag is abnormal (the bag contains multiple masks or the number of masks is insufficient or even an empty bag), the ear strap is abnormal (pressed ear strap, no ear strap or less ear strap, or the ear strap exceeds the range of the mask), the bag is connected (multiple mask bags are connected together), the coding is abnormal, the mask film surface is wrinkled, and the roll film is displaced. The collected samples try to cover all types of defects. The same sample can be used to collect multiple pictures at different positions, angles, light illumination and darkness on the belt line. Multiple pictures can also be collected at different positions and angles of the same mask in the mask bag. In short, there is only one principle for collecting pictures, which is to cover as many states as possible to enhance the robustness and accuracy of the model. The two groups of pictures with and without defects collected by the upper surface camera are placed in the OK / NG folder respectively. Similarly, the lower surface camera collects pictures of the back of the mask without defects, and collects multiple pictures of the mask at different positions, angles, light levels, positions and angles in the mask bag, different production dates, and production dates at different positions on the mask. Try to cover as many states as possible, especially consider pictures in some undesirable states, such as when characters are stuck or slightly dirty. The more comprehensive the state considered, the higher the detection and recognition accuracy of the algorithm model. The collected pictures are placed in the ocr folder.
[0080] Step 3: Use the existing deep learning detection and classification algorithm to train the images in the OK / NG folder captured by the upper surface camera; for the images captured by the lower surface camera, count the maximum area of the jump range of the 4 lines of characters to be detected, relative to the relative rectangular coordinates of the mask, and at the same time establish a template with the 4 lines of characters of the mask with a relatively positive placement angle. This step is divided into the following four steps:
[0081] 1. The training process of deep learning detection classification model is as follows:
[0082] (1) 1,000 defect-free images and 1,000 images containing various defects collected by the upper surface camera are stored in the OK and NG folders respectively;
[0083] (2) Perform data augmentation on the collected data samples, perform affine transformations such as rotation and translation scaling according to the mask bag, image brightness adjustment, uneven lighting and other image processing, increase the number of samples in the sample set under various special circumstances, and enhance the robustness of the model;
[0084] (3) According to the constructed data set, randomly divide the training set, validation set and test set into 70%, 15% and 15% respectively. Use the training set to train the detection and classification model, use the validation set to judge the performance of the detection and classification model, and use the test set to test. When the accuracy of the test set can reach more than 99%, it passes the test. The model used is the pretrained_dl_classifier_enhanced model in the halcon software. Compared with the pretrained_dl_classifier_compact model, this model has a higher accuracy, but the training time is longer. The pretrained_dl_classifier_enhanced model is a pretrained model, that is, it has been pretrained based on the detection and classification of pictures in a large number of industrial scenes. Subsequent training can be done on the basis of this model, which saves a lot of time. The training is performed on a computer with a GPU graphics card.
[0085] 2. The process of building a character template is as follows:
[0086] When the incoming mask material is rotated, translated and scaled, firstly, based on threshold segmentation, connected domain screening, and hole filling in hollow areas, the minimum circumscribed rectangle of the mask area is extracted, and then the image is affine transformed to transform the mask into a normal upright mask. Then, based on the relative rectangular area counted in step 12, the initial positioning area of the character area can be extracted, and then the image is cropped. The effect diagram is shown in the attached figure. Fig.16 shown.
[0087] A template is created to store the 4-line character area of the production date. The template contains the following data: edge features and grayscale information of the 4-line character area, image file of the template, width and height information of the template, relative rectangular area of the first line of characters relative to the template, and number of characters. Since the position of the mask production date relative to the mask area is not fixed and there is a range of movement, it is necessary to count the 4-line character areas of the production date of a large number of normal masks and calculate the maximum range of the dynamic rectangular area relative to the mask. This can reduce the range of the character positioning area and increase the accuracy. The dynamic rectangular area of this mask follows the mask area to perform rotation, translation, and scaling transformations, and can be accurately located every time the incoming mask is rotated, translated, scaled, or tilted.
[0088] 3. OCR character recognition training:
[0089] Based on the image of a row of character areas extracted, annotation training is performed. A large number of images collected with different lighting uniformity are divided into training set, validation set, and test set at a ratio of 70%, 15%, and 15%. The annotation tool Deep LearniNG Tool in the halcon software is used for character annotation. The training set is used to train the MLP character recognition model, the validation set is used to evaluate the character recognition performance, and the test set is used to test the character recognition performance. If the test set reaches an accuracy rate of more than 99.9%, it meets the requirements.
[0090] 4. The deep learning character recognition training described above is based on the extracted image of the last line of character area, and the annotation training is performed. A large number of images collected at different illumination uniformities are divided into training set, validation set, and test set at a ratio of 70%, 15%, and 15%. The annotation tool Deep LearniNG Tool in the halcon software is used for character annotation. The training set is used to train the deep learning character recognition model, the validation set is used to evaluate the character recognition performance, and the test set is used to test the character recognition performance. The accuracy of the test set reaches more than 99.9%, which meets the requirements. This training method is based on the training of the entire line of characters, that is, the extracted entire line of character images and strings are annotated for training.
[0091] Step 4: Unload the material, and the upper and lower surface cameras start to detect respectively. The upper surface camera detects the upper part of the mask, and the lower surface camera detects the lower part of the mask. According to the flow of the mask on the belt line, the flow corresponds to the upper or lower part of the camera, which will trigger the photoelectric sensor to trigger the camera to take a photo and start detection.
[0092] The current material feeding is done manually. When feeding, the front and back of the mask must not be reversed, and it must not exceed the range of the belt line. It is best to put the material in the middle of the belt line to maintain the consistency of the head and tail directions. The angle should be as small as possible, so that parameters can be set in the software to limit the mask angle search range, so that the detection speed will be faster. The principle of feeding is: when collecting images during deep learning training, try to cover various extreme situations, but in the actual detection later, try to put the material better, the accuracy will be higher and the speed will be faster.
[0093] Step 5: The upper surface camera executes the mask defect detection and classification algorithm to classify the masks into OK / NG categories, and an alarm is triggered for NG masks.
[0094] 1. Defect detection method flow:
[0095] (1) First detect the abnormality of the membrane joint. The color of the membrane joint area is different from that of other areas. According to the color space processing, the membrane joint area is extracted. If the membrane joint area is contained, the membrane joint is abnormal, and NG is sent and returned directly. Otherwise, enter the next process. The detection method of the roll membrane joint is based on the traditional algorithm: Since the color of the membrane joint area is different from that of other areas, based on the color space processing of the image, the location area of the membrane joint is detected in this image. The specific implementation is as follows: Fig.13 The figure shows the detection image of the membrane joint area on the front of the mask. Based on this color image, the membrane joint is yellowish, the mask is blue, and the ear straps are black after backlighting. First, the three-channel color image is decomposed into three single-channel images of Red, Green, and Blue, and then the difference between Blue and Red is obtained to obtain the ImageSub image, as shown in Fig.14 As shown above, the image is the ImageSub image. The features of the membrane joint part in this image are very obvious compared to other parts. First, the mask area (including the membrane joint part) is obtained based on the original image through dynamic threshold segmentation, and the background part is eliminated. Then, the black part can be obtained through binarization based on the ImageSub image, and then the connected domain is decomposed. The area with the largest area is the membrane joint area.
[0096] (2) Determine the area of the minimum circumscribed rectangle and convex hull of the mask area (i.e., including the ear straps but not the mask bag). If the area is less than the given threshold, it is an empty bag. If the area is greater than the given threshold, the bag contains multiple masks or the ear straps exceed the mask area. Send NG and return directly. Otherwise, enter the next process for judgment. The mask area detection method is: extract the mask area (including the ear straps but not the mask bag) through dynamic threshold segmentation, extract the area of the minimum circumscribed rectangle of the mask, which is used to determine whether the ear straps exceed the mask range or the number of masks is abnormal.
[0097] Extract the area of the minimum circumscribed convex hull of the mask and compare it with the area of the minimum circumscribed rectangle. If the difference is too large, it means that the mask has abnormal wrinkles. The upper and lower thresholds of the normal area of the minimum circumscribed rectangle and the minimum convex hull of the mask need to be obtained by collecting a large number of OK and NG pictures for statistical analysis, and after a large number of image tests for stability and robustness. This area threshold is related to the parameter settings of the line scan camera (image width and height), as well as the camera working distance, field of view, etc.
[0098] (3) Detect the number of ear straps based on the four established rectangular areas, such as Fig.15 As shown, the number of ear straps in the four rectangular areas is detected. If the number of ear straps is less than 4, the number of ear straps is abnormal and NG is returned. The ear strap detection method is as follows: first, four rectangular areas must be established based on the regional position of the ear straps in the standard mask, such as Fig.14As shown, according to the previous detection process, after excluding the abnormal number and color of masks, the remaining images all contain an OK mask. Then, based on the relative position of the ear strap relative to a single mask, a following rectangular area is set, a total of 4 rectangles. Within the range of these 4 rectangles, the position of the ear strap is found according to the edge extraction algorithm. If there are 4, it contains two complete ear straps, if there is 1, there is only 1 ear strap, and if there is 0, there is no ear strap;
[0099] 2. Detection and classification method of defective masks based on deep learning: A large number of pictures are collected according to the corresponding defects, and the pictures extracted from the mask area are normalized and sent to the deep learning detection and classification model for classification.
[0100] Step 6: The lower surface camera executes the mask back character positioning algorithm, and the global image of the back of the mask is shown in Fig.16 :
[0101] (1) Locate the mask position area and direction based on threshold segmentation. This step is achieved by dynamic threshold segmentation of the original image, then decomposition of the connected domain, and area screening to extract the largest rectangular area. The mask area image obtained in this step is tilted and angled, and an affine transformation is required to align the current mask area image to the template mask area image, that is, the angle is 0;
[0102] (2) Initial positioning, such as Fig.17 As shown, according to the relative coordinates of the character area relative to the mask, the limited range of the production date character area is reduced. The relative coordinates of this rectangular area are obtained based on previous statistics. Since the production date is not fixed in the mask area, this rectangular area takes the maximum rectangular area of the floating range of the production date position;
[0103] (3) Precise positioning: Based on the template matching algorithm, the 4-line character area of the production date on the back of the mask is located. Fig.18 As shown, the 4-row mask character area is located based on the template built in the previous step, and the attached figure is precisely located. This step can be achieved through the template matching algorithm. The template search angle range is set. The upper and lower limits of this angle can be set according to the incoming material situation. If the incoming material angle accuracy is very poor, the angle search range is set to -180 to 360 degrees. The minimum threshold for detecting masks can be adjusted according to the actual imaging situation. It is currently set to 0.2, and the number of matched pyramid layers is 4. Generate a rectangle of the 4-row character area based on the matched position area and crop the image.
[0104] (4) Perform morphological processing on each row to obtain the character area of the first row. Fig.19As shown in the figure, the image of the extracted 4-line character area is subjected to histogram equalization to make the image brightness balanced globally, and then the image grayscale value is stretched and normalized to 0-255. After a series of image preprocessing operations, threshold segmentation is performed, and the connected domain is extracted and screened to obtain the 4-line character area. The connected domain is then expanded with a coefficient of (10, 1) to obtain the last 4 areas. The character area of the first row can be obtained by sorting them according to the row coordinates.
[0105] Step 7: The lower surface camera executes the character recognition algorithm for the production date on the back of the mask:
[0106] 1. Based on traditional OCR character recognition, for the final extracted line of character images, first do image preprocessing, then segmentation processing, divide it into individual characters, and then recognize each character one by one. There are three small steps in total.
[0107] (1) Image preprocessing: First, grayscale stretching is performed, scale_image_max(ImageReduced, ImageScaleMax), to stretch the image grayscale to 0-255 to facilitate the accuracy of subsequent threshold segmentation; then the image is histogram equalized to prevent segmentation errors caused by uneven image illumination, emphasize(ImageScaleMax,Sharp,7,7,2.0), where the mask size 7*7 is obtained based on experiments and 2 is the strength of equalization; then the image is dynamically thresholded and the black part is taken as the character area.
[0108] (2) The character area extracted in the previous step may have damaged or adhered characters. Morphological processing is required to repair the damage first, and then segment the partially adhered characters. This is the most critical step in OCR technology. First, close the character area, decompose the connected domain, and then intersect with the original area to obtain individual character areas. Then arrange the segmented characters according to column coordinates. The characters obtained in this step are repaired, but there are still a small number of adhered characters that need further segmentation. First, filter by area to filter out relatively small noise areas, and convert the remaining character areas into rectangular areas. Further filter by width and height. First, based on the large number of images extracted Fig.19 As shown, manually segment and count the width and height information of a single character, as well as the number of characters, and calculate the average width and height of the characters. According to a large amount of data statistics, the average width of a single character on the production date of this mask is 13.7 pixels. The width of the rectangular area of a single character is divided by 13.7 and rounded to the number of characters that need to be further subdivided. If the total number of characters is the same as the number of masks, NG is returned directly, otherwise it goes to the next step of character recognition.
[0109] (3) OCR recognition technology, including MLP, CNN, SVM, KNN and other methods. According to the characters of the last line extracted in the previous step, the individual characters after segmentation are extracted and recognized one by one. After experimental verification, the Pharma_0-9_NoRej.omc character library can be used with the highest recognition accuracy. It is necessary to set the NumAlternatives value, which is the number of classes for each character used for internal word correction, and NumCorrections, which is the maximum number of corrected characters. The generated words are scored according to a score between 0.0 (no correction found) and 1.0 (the original word is correct). The way to reduce the score is to add a penalty based on the number of modified characters, and another (secondary) penalty is based on how many high-confidence classes are ignored to match the expression. Num_corr is the number of corrections actually applied, and num_alt is the total number of replacements discarded.
[0110] 2. Based on deep learning, after preprocessing the character image of the entire line, the entire line is recognized and the string is output.
[0111] The deep learning character recognition results are shown in Fig. 20 . OCR technology is based on character-by-character segmentation and recognition, and the effect of handling character adhesion is not ideal, especially for the case of characters of different sizes. It is easy to segment the wrong number of characters, or the segmented character area is incomplete and shifted, etc., resulting in subsequent recognition failure. Based on deep learning, whole-line character recognition has better robustness and accuracy than traditional OCR recognition, can resist uneven lighting and character adhesion, and does not require character segmentation. This method is trained on the whole line and recognized on the whole line.
[0112] First, decompose the original color image into three-channel images of Red, Green, and Blue, decompose3(ImageRGB, Red, Green, Blue), and then convert the three-channel images to the HSV color space, trans_from_rgb (Red, Green, Blue, Hue, Saturation, Intensity, 'hsv'). Use the image of the Intensity channel for character positioning and recognition, as the contrast between the characters and the background of the Intensity channel image is the highest. Then normalize the Intensity image to a size of 100*40 in width and height, because the model requires a compact crop of the input image. This model only targets character recognition and does not include character positioning, which can improve recognition accuracy. apply_deep_ocr (Image, DeepOcrHandle, 'recognition', DeepOcrResult). DeepOcrResult directly contains the recognition result of the current input image, because the previous character training was based on the entire image, and all recognitions were also for the entire image. System requirements: cuDNN and cuBLAS are required if running on a GPU (see GetDeepOcrParam). Alternatively, this operator can also be run on the CPU.
[0113] The above description is only a description of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any changes or modifications made by a person skilled in the art in the field of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. A mask detection method integrating machine vision and deep learning, characterized in that: include: Step 1: Adjust the conveyor belt speed, light source height brightness, lens field of view and line scan camera parameters to make the image clear and the features obvious; Step 2: Place the mask so that the front side of the mask faces upward and the back side faces downward. The upper and lower surface cameras simultaneously capture images of the front and back sides of the mask respectively. The upper surface camera first collects several images of masks without defects, and then collects several images of masks with various defects. The two sets of images collected are placed in the OK / NG folder respectively; the lower surface camera collects the reverse side images of the masks without defects and places them in the ocr folder; Step 3: Use a deep learning detection and classification algorithm to train the images collected by the upper surface camera; For the image captured by the lower surface camera, count the maximum area of the jump range of the 4 lines of characters to be detected, relative to the relative rectangular coordinates of the mask; At the same time, the template is established with the 4-line character area of the positive-angle mask; Step 4: Unload the material, and the upper and lower surface cameras start to detect respectively; Step 5: The upper surface camera executes the mask defect detection and classification algorithm to classify the masks into OK / NG categories, and an alarm is triggered for NG masks; Step 6: The lower surface camera executes the character positioning algorithm on the back of the mask; Step 7: The lower surface camera executes the character recognition algorithm of the production date on the back of the mask; The template is created with 4 lines of characters in the positive angle mask area including: When the incoming mask material is rotated, translated and scaled, firstly, based on threshold segmentation, connected domain screening, and hole filling in hollow areas, the minimum circumscribed rectangle of the mask area is extracted, and then the image is affine transformed to transform the mask into a normal upright mask. Then, based on the relative rectangular area, the initial positioning area of the character area is extracted, and then the image is cropped; A template is created to store the 4-line character area of the production date. The template contains the following data: edge features and grayscale information of the 4-line character area, image file of the template, width and height information of the template, the relative rectangular area of the first line of characters relative to the template, and the number of characters; Since the position of the mask production date relative to the mask area is not fixed and has a moving range, it is necessary to count the 4-line character area of the production date of a large number of normal masks and calculate the maximum range of the dynamic rectangular area relative to the mask to narrow the character positioning area range and increase the accuracy; the dynamic rectangular area of this mask follows the mask area to perform rotation, translation and scaling transformations, and if the incoming mask is rotated, translated, scaled and tilted, it can also be accurately positioned; The upper surface camera performs mask defect detection including: (1) First detect the abnormality of the membrane joint. The color of the membrane joint area is different from that of other areas. According to the color space processing, the membrane joint area is extracted. If the membrane joint area is present, the membrane joint is abnormal, and NG is sent and returned directly. Otherwise, enter the next process; (2) Determine the area of the minimum circumscribed rectangle and convex hull of the mask area. If the area is less than the given threshold, it is an empty bag. If the area is greater than the given threshold, the bag contains multiple masks or the ear straps exceed the mask area. Send NG and return directly. Otherwise, enter the next process judgment. (3) Detect the number of ear straps. According to the four established rectangular areas, detect the number of ear straps in the four rectangular areas. If the number is less than 4, the number of ear straps is abnormal and NG is returned. The membrane joint detection method is as follows: the color of the membrane joint area is different from other areas. Based on the color space processing of the image, the location area of the membrane joint is detected. The specific implementation is as follows: based on the color image, the color of the membrane joint is yellowish, the mask is blue, and the ear strap is black after backlighting. The three-channel color image is first decomposed into three single-channel images of Red, Green, and Blue, and then the Blue and Red are subtracted to obtain the ImageSub image. First, the original image is segmented by dynamic threshold to obtain the mask area containing the membrane joint, and the background part is eliminated. Then, the black part is obtained by binarization based on the ImageSub image, and then the connected domain is decomposed, and the area with the largest area is the membrane joint area; The mask area detection method is as follows: through dynamic threshold segmentation, the mask area that includes the ear strap but does not include the mask pocket is extracted, and the area of the mask's minimum circumscribed rectangle is extracted to determine whether the ear strap exceeds the mask range or the number of masks is abnormal; the area of the mask's minimum circumscribed convex hull is extracted and compared with the area of the minimum circumscribed rectangle; the upper and lower thresholds of the normal area of the mask's minimum circumscribed rectangle and minimum convex hull need to be obtained by collecting a large number of OK and NG pictures for statistical analysis, and the stability and robustness are tested through a large number of images; The method for detecting the number of ear straps is as follows: first, based on the regional position of the ear straps in the standard mask, 4 rectangular areas are established. According to the previous detection process, after excluding the abnormal number and color of masks, the remaining images contain an OK mask. Then, based on the relative position of the ear straps relative to a single mask, the following rectangular area is set, a total of 4 rectangles. Within the range of these 4 rectangles, the position of the ear straps is found according to the edge extraction algorithm. If there are 4, it contains two complete ear straps, if there is 1, there is only 1 ear strap, and if it is 0, there is no ear strap.
2. The mask detection method integrating machine vision and deep learning as claimed in claim 1, characterized in that: The belt is composed of three sections of belt lines on the same horizontal line, with the same speed and the same width. There are two connections between the three sections of belt lines, and a set of visual systems is installed at each connection: The visual system for detecting the upper surface is installed at the connection between the first and second sections of the belt. The upper surface camera is installed above the belt and vertically downward. The light source is installed in a backlight manner, that is, it is installed below the belt and illuminates from bottom to top. The visual system for detecting the lower surface is installed at the connection between the second and third sections of the belt. The lower surface camera is installed vertically upward below the belt. The light source is installed in a backlight mode, that is, it is installed above the belt and illuminates from top to bottom. Both sets of cameras are line scan cameras, and the line scan direction is along the direction of belt line movement; Both sets of light sources are white bar light sources, emitting uniform white light. The brightness of the light source above makes various defects on the surface of the mask clearly visible; The lens is a common lens, and the lens matches the camera field of view and the width of the belt line.
3. The mask detection method integrating machine vision and deep learning as claimed in claim 2, characterized in that: The upper surface camera collects images of masks covered with various defects, wherein the defect types include masks containing roll film joints, abnormal number of masks in the mask bag, abnormal ear straps, continuous packing, abnormal coding, wrinkles on the mask film surface, and roll film displacement; The lower surface camera collects the back image of the defect-free mask, collects multiple images of the mask at different positions, angles, light intensity, different positions and angles of the mask in the mask bag, different production dates, and production dates at different positions on the mask, and puts them in the OCR folder.
4. The mask detection method integrating machine vision and deep learning as claimed in claim 3, characterized in that: The images collected by the upper surface camera are trained using a deep learning detection and classification algorithm including: Several defect-free images and several images containing various defects collected by the upper surface camera are stored in OK and NG folders respectively; Perform data augmentation on the collected image data samples, perform certain rotation and translation scaling affine transformation, image brightness adjustment, and uneven lighting processing according to the mask bag, increase the samples in the sample set under various special circumstances, and enhance the robustness of the model; According to the constructed data set, the training set, validation set and test set are randomly divided. The training set is used to train the detection and classification model, the validation set is used to evaluate the performance of the detection and classification model, and the test set is used for testing. When the accuracy of the test set can reach more than 99%, the test is passed.
5. The mask detection method integrating machine vision and deep learning as claimed in claim 4, characterized in that: The upper surface camera performs mask defect detection and classification, including: collecting a large number of pictures according to the corresponding defects, extracting pictures of the mask area, normalizing them and sending them into the deep learning detection and classification model for classification.
6. The mask detection method integrating machine vision and deep learning as claimed in claim 5, characterized in that: The lower surface camera performs the algorithm for locating characters on the back of the mask, including: Locate the mask location and direction based on threshold segmentation; Initial positioning: narrow the limited range of the production date character area according to the relative coordinates of the character area relative to the mask; Precise positioning: Based on the template matching algorithm, the 4-line character area of the production date on the back of the mask is located; Perform morphological processing on each row to obtain the character area of the first row.
7. The mask detection method integrating machine vision and deep learning as claimed in claim 6, characterized in that: The lower surface camera performs the production date character recognition algorithm on the back of the mask: Based on OCR character recognition, the final extracted line of character images is segmented, and then individual characters are recognized one by one; Based on deep learning, after preprocessing the character image of the entire line, the entire line is recognized and the string is output.
