Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 5, No. 3, 2023 186 Research on Defect Detection of The Liquid Bag of Bag Infusion Sets Based on Machine Vision Qian Zhang, Kang Liu and Bo Huang* College of Mechanical Engineering, Sichuan University of Science and Engineering, Yibin, 644000, China * Corresponding author Abstract: Intravenous infusion often uses bag infusion devices for clinic treatment, and the liquid bag assembly is an essential component of the bag infusion device. This paper adopts a machine vision system to inspect the assembly quality of the pipeline and dosing interface of liquid bag assembly. We conduct in-depth research on the lighting method, image pre-processing, and defect detection algorithm of a vision system for two defects of pipeline missing and dosing interface missing. Moreover, we do a lighting experiment to detect transparent liquid bag assembly defects. Proposes an adaptive gamma correction library based on power function derivative calculation, and combines the cumulative histogram for adaptive gamma correction, which amplifies the image edge information, combined with the binarization of the OTSU, solves the image segmentation problem in this. Proposes an adaptive ROI region selection method and virtual linear scanning method to achieve the detection of two kinds of defects. The results show that the recognition rate of missing defects of the pipeline on the liquid bag assembly in the machine vision system reaches 100%. Keywords: Machine vision, Liquid bag, Light experiment, Gamma correction. 1. Introduction Thanks to the rapid development of faster GPU computer hardware in the past few years, machine vision has proliferated, further expanding its application areas outside the manufacturing, security, and medical fields [1]. For example, machine vision is used in the electronic circuit industry for PCB inspection. For example, machine vision is used in the electronic circuit industry for PCB defect detection [2]. Machine vision technology is used in the detection of tool defects in industrial machine tools [3]. Machine vision technology is also used in the pharmaceutical industry to ensure that patients receive the specified quality of drug treatment [4]. The pharmaceutical industry, for example, has a wide range of applications for machine vision technology to ensure that patients receive the specified quality of medication. Also, machine vision has been studied to detect defects in liquid pharmaceutical containers [5]. The bagged infusion set described in this paper is a medical device for the clinical delivery of medication to the human body. Its quality will indirectly affect the quality of the medication reaching the human body. Intravenous infusion has become a very important means of modern clinical treatment. Infusion sets are widely used in hospitals to deliver fluids, such as blood, drugs, or liquid nutrients, to patients [6]. Therefore, the quality of drugs and medical devices related to intravenous infusion is crucial to the safety of patients' lives. The application of machine vision in the quality inspection related to intravenous infusion and medical devices mainly focuses on detecting impurities in the drug solution and the surface quality of the drug packaging. For example, Akira et al. used a special illumination method and appropriate imaging optics to detect foreign objects in plastic bottles of pharmaceutical fluids as black or bright spots in diffuse background illumination, based on which a machine vision-based real-time image processing method for foreign objects in plastic bottles of pharmaceutical fluids was realized [7]. Li et al. used a mechanical method to make a motion difference between the foreign body in the I.V. solution and the background, using an optical imaging system to obtain the target motion sequence image. Finally, the machine vision processing algorithm completes the foreign body detection of large infusion solution products [8]. Ji et al. used an improved PCNN to segment the different images of foreign objects in the injection solution. They judged the presence of foreign objects in the injection solution based on the continuity and smoothness of the foreign object trajectory. Finally, They developed an intelligent foreign object detection machine for the injection solution [9]. Finally, an intelligent foreign body detection machine for injection fluid was developed. Zhou et al. used the method of quadratic difference and energy accumulation to obtain the possible small targets of motion in pharmaceutical injections. Also, they proposed a support vector machine-based bubble and visible foreign body classification algorithm to detect the tiny visible foreign bodies within the injectable solution based on the above two aspects [10]. Wang et al. make the foreign body detection machine strictly follow the improved "rotation, sudden braking, video tracking" process to reduce the effect of bubbles, and then apply the improved PCNN Tsallis Entropy to segment the difference images, and finally determine the presence of foreign bodies in the injection solution based on the continuity and smoothness of their traces. Finally, we can determine whether there is a foreign body in the injection based on the continuity and smoothness of the traces [11]. Yao designed a reflection illumination method with lateral illumination to increase the contrast between the ampoule and the foreign body in it and investigated a two-stage frame difference method with the sub-pixel alignment of image sequences to extract small target traces under the auxiliary background interference to detect the foreign body in the ampoule solution effectively [12]. Yang et al. Yang Shuang et al. proposed a probabilistic threshold segmentation and Kalman filter prediction method for online detection and tracking of visible foreign objects in ampoule solution, which meets the requirements of online 187 detection in terms of speed and accuracy [13]. Ge et al. applied supervised learning and used features such as area of impurities, average gray value, geometric invariant moment, and wavelet packet energy spectrum to generate feature vectors to effectively classify foreign particles in injection solution in ampoules [14]. The above studies are all related to intravenous infusion. Many of the above studies are about detecting foreign body defects related to pharmaceutical solutions in intravenous infusions. There is no study specifically for detecting defects in medical devices related to intravenous infusions. Pouch infusion devices are often introduced when large-volume solutions must be dispensed for infusion, and the dose accuracy could be higher. The human eye often detects the assembly defects of the bag components generated during the production process. In this paper, we take the liquid bag assembly on the bag infuser as the research object, study the detection methods of missing defects of the liquid bag lanyard and missing defects of the dosing interface on the liquid bag assembly, and introduce the machine vision technology to the detection of defects of the liquid bag assembly initially. 2. Liquid Bag Component Defect and Defect Detection Study The bag assembly of a bag infuser consists of a bag of fluid and associated piping and a dosing interface. The liquid bag assembly is derived from the different application scenarios of bag infusion devices, including the liquid bag assembly for single-insert bag infusion devices and the liquid bag assembly for double-insert bag infusion devices. The structural difference mainly lies in the different lengths of the catheter, as shown in the red box area of Figure 1. The detection content studied in this paper mainly includes two defects: 1. liquid bag lanyard and related piping are missing, later called defect one; 1. dosing interface is missing, later called defect two, two kinds of liquid bag defects as shown in Figure 2. The defect detection method is necessary to detect both defects of these two types of liquid bag components. Figure 1. Local view of two liquid bag assemblies Figure 2. Comparative diagram of two kinds of defects 2.1. Light experiment Machine vision systems, light sources, and lighting solutions are often the basis for machine vision systems to obtain high-quality images, which is the key to the success of machine vision inspection systems. In defect detection, a good lighting system can maximize the image's contrast [15]. Backlighting is often used in machine vision systems to inspect transparent objects such as disposable bagged infusion sets [16]. Backlighting is often used for transparent objects such as disposable bags in machine vision systems. In the process of image acquisition under the backlight, we found that the quality of the acquired image varies depending on the angle of the backlight and the intensity of the backlight illumination because the object to be measured is transparent and soft. So to find a suitable backlighting angle, this paper first conducted a lighting experiment. 2.1.1. Experimental design The experiment simulates the external light environment during the liquid bag assembly. Figure 3 shows the illuminated experimental platform. The light source is a white backlight with a luminous surface size of 200x200mm, and the panel is frosted. This experiment aims to find a better illumination angle to distinguish the liquid bag image from the background. According to the illumination scheme of this paper, the background part of the acquired image is mainly the luminous surface of the light source, ideally in the same color. Based on this, this experiment introduces the 4-domain and 8-domain contrast to express the contrast between the object and the 188 background image. The contrast formula of an M × N image is like Eq. 1 and Eq. 2. Where d ( , )i s t represents the difference between the pixel (s,t) and its adjacent i pixel, and the solving process of d ( , )i s t is shown in figure 4. Figure 3. The experiment platform Figure 4. The process of solving d ( , )i s t            1 1 2 2 2 2 2 4 6 8 2 2 4 , , , , 4 2 2 M N s t d s t d s t d s t d s t D M N            (1)      1 1 8 2 2 2 1 8 , 8 2 2 M N i s t i d s t D M N         (2) The irradiation angle mentioned above is the acute angle between the Normal direction of the backlight source and the loading table. In the experiment, the OpenCV library is used to process the image, and the contrast of the image with light source brightness from 𝑙 to 𝑙 and illumination angle from 30°to 90° is obtained. The light source controller reading replaces the luminance value, the luminance value step size is 1, and the irradiation angle step size is 5°. The luminance 𝑙 is the minimum luminance value that the camera can capture the object to be measured when the irradiation angle is 90°, and 𝑙 is the maximum luminance value that the camera can capture the object to be measured when the irradiation angle is 30° 2.1.2. Analysis of experimental results According to the preliminary image acquisition experiments, the image collected in the light intensity is weak due to the large size of the parts to be inspected, coupled with the lens distortion and backlighting. The image edge quality will be very poor, and the texture of the backlight source itself will bring interference. It can not form a good background, which is not conducive to later image processing, so the current high-contrast images can not be used. As shown in Figure 5, the two images of Four-neighborhood and eight- neighborhood contrast sizes are comparable. However, the image quality of the right figure is significantly higher than the left figure, more conducive to separating the artifact image and the background image. Analyzing and comparing the image contrast with the left figure for the same light angle with different light intensity, the higher contrast in the left figure is that the pixels in the red box improve the image contrast but reduce the image quality. Intuitively, high-contrast low-quality images are more difficult to process than high-contrast, high-quality images. The experimental data related to this part of high-contrast low-quality images are discarded in this experiment. The final L(s‐1,t‐1) L(s,t‐1) L(s+1,t‐1) L(s‐1,t) L(s,t) L(s+1,t) L(s‐1,t+1) L(s,t+1) L(s+1,t+1) 𝑑 𝑑 𝑑 𝑑𝑑𝑑 𝑑𝑑 𝑑 Solve 𝑑 Example: 𝑑 =L(s,t)‐L(s‐1,t‐1) 189 four- neighborhood and eight- neighborhood contrast maps with irradiation angles from 30° to 90° and light source controller reading between 10 and 30 are shown in Fig. 6. And maximum contrast corresponding to angle and light source size is shown in Fig 7. The image contrast of the transparent liquid bag assembly is affected by both light intensity and backlight angle. When the contrast data of high-contrast low- quality images are excluded, the maximum contrast is easily found at low angles with low light intensity. At a certain angle, the contrast increases and decreases first as the light angle increases. We expect the maximum contrast to be 45, but the final result is inconsistent with our expectations. As the experiment has been able to guide the formulation of this defect detection scheme, this paper has not done any further research. Figure 5. Two high contrast images Figure 6. Image contrast of different angles and light intensities 190 Figure 7. Maximum contrast corresponding to Angle and light source size As in Figure 7(a), image contrast decreases with increasing light intensity. A small backlight angle gives better image contrast, but the size of the long side of the light source size needs to be satisfied Eq. 3. 𝐿 𝑙 (3)    Where L is the long side of the light source, l is the long side of the object to be detected, and 𝑙 is a constant. As in Figure 7(b), the backlight angle of 50° is the final choice of backlight angle, light intensity selected backlight angle of 50° maximum contrast when the corresponding light intensity. 2.2. Digital image pre-processing The key to detecting two defects in the liquid bag assembly is to extract the outer contours of the liquid bag assembly while excluding the contours of the internal areas of the liquid bag assembly as much as possible. The image is first binarized to facilitate contour detection, then contour detection is performed. In this paper, the image binarization is performed on the grayscale image of the liquid bag assembly using the OTSU [17]. From the above, although the best hardware combination is selected according to the system detection requirements, the final acquired image is not good enough due to the backlight illumination and the fact that the detection target is transparent, mainly because the grayscale value near the liquid bag contour is very close to the background grayscale value. As shown in the red box in Fig. 8, the binarization of the OTSU fails to distinguish the liquid bag from the background, and some of the contour information needs to be recovered. Figure 8. Binarization of the original picture 2.2.1. Adaptive Gamma Correction During digital image processing, gamma correction can be achieved by using two variation parameters, \gamma and c, to control the image's overall brightness. The formula for gamma correction is Eq. 4. 191 s cr                           (4)   γ is the normalized grayscale value of the input image; s is the grayscale value after gamma correction; c is the grayscale scaling coefficient. As shown in figure 9 (a), the grayscale value of the over-dark area in the image is enhanced when the value of γ is 0,1 , and the grayscale value of the over-bright area is darkened when the value is 1, ∞ . When γ = 1, the image remains unchanged. No matter what the value of γ is in 0,1 ∪ 1, ∞ , some of the gray values normalized to 0,1 will be compressed, and some of them will be enlarged. As shown in figure 9 (b), the correction curve corresponding to brown γ 2, pink is the function's derivative function, and the r-value corresponding to 1 is the scaling demarcation point. The grayscale values in the range of 0,0.5 are compressed, and the grayscale values in the range of 0.5,1 are stretched. Due to the backlight illumination method and the main part of the liquid bag assembly being presented as transparent, the overall image of the liquid bag assembly is bright. As shown in Figure 10, by analyzing a set of original images and the original images with their latex caps removed (shown in the red box in Figure 10) and comparing them with their respective grayscale histograms, we can learn from them that the opacity of the latex caps causes the first wave in the original histogram. Assuming that the grayscale range of the latex cap is in [L1, L2], when we lengthen the grayscale range [L2,255] and compress the grayscale range [0,L2], we can lengthen the grayscale range containing edge information. The missing part of compression will not remove the edge information, so it is convenient for us to use OTSU. Figure 9. Explanation of the principle of gamma correction Figure 10. The original image and its gray histogram. (a) the original image with different acquisition condition. (b) the grayscale histogram of a. (c) the original image of removing the two links of adding medicine. (c) the original image of removing the two links of adding medicine. (d) the grayscale histogram of c. (c) the original image of removing the two links of adding medicine. (d) the grayscale histogram of c. This paper needs to be able to stretch the range of grayscale values containing useful edge information and eliminate other useless edge information or interference as much as possible. Considering the characteristics of gamma correction and the overall brightness of the module's image, a γ value greater than one can be used to lengthen the gray value range of the bright area. However, unlike the opaque rigid workpiece, all the pipes and liquid bags of the assembly are obtained through 192 the extrusion process, and the parts are soft and elastic. So it cannot always keep the shape it had when it was first produced, do not like a rigid body. In the assembly process, different deformations occur due to different forces on each station, which may show different states in the light transmission process. So for different products and parts of the same product pipeline, the gray value of the profile and the gray background difference are not consistent. Therefore, if only a fixed γ value is used for gamma correction, it is impossible to distinguish all products or different pipeline profiles of the same product. As shown in figure 11, if the γ value is too small, the gray edge range is not extended enough, and the γ value is too large, which will magnify the interference information caused by lens halo, thus affecting image segmentation. Figure 11. Comparison of different gamma correction degrees. (a) the original image with different acquisition condition. (b) gamma correction of a when γ (c) gamma Correction of a Graph when γ is too large. Since the gamma correction does not change 0 and 255 grayscale, we do not count these two levels of grayscale values when counting the grayscale histogram. Combined with the previous section, we only need to be able to find the scaling cut-off point in Figure 9 to complete the stretching of the corresponding range of the image. Here we introduce the parameter of the ratio of the cumulative histogram to the total number of pixels as the adaptive selection of the cut-off point parameter, and the cumulative histogram is calculated as shown in Eq. 5 and 6. 𝑆 𝑟 ∑ 𝐻 𝑖 (5) 𝑃 𝑟 (6) Where H(i) is the number of pixels with gray level i, and P(r) is the scale parameter used to determine. When we use the grayscale value corresponding to the scale at 0.17 as the scaling cut-off point in Figure 9, it is just enough to meet the needs of the previous stretching and compression ranges. The selected cut-off point is the grayscale value marked in red in Figure 12. Figure 12. Grayscale histogram and cumulative histogram 193 When we normalize the grayscale 0,255 to 0,1 , we take 0.01 as the step size, and we can divide 0,1 into 100 points. On this basis, we magnify 0,1 into a collection of 101points 𝐴 0; 1; … ; 100 , we order 𝛾𝐴 1 , from which the elements in the 𝛾 set all correspond to the elements in An one by one, and we take 𝐴 corresponding to the point 𝛾 greater than 50 as a Gammavaluelibrary. Take the element in 𝐴 minus 50 as the index value, and finally get Tab 1 Gamma value library Table 1. Gamma value library 𝛾 indexes 𝛾 𝛾 𝑖𝑛𝑑𝑒𝑥𝑒𝑠 𝛾 𝛾 𝑖𝑛𝑑𝑒𝑥𝑒𝑠 𝛾 γ indexes 𝛾 0 2 13 4 26 9.01 39 30.26 1 2.11 14 4.23 27 9.69 40 34.65 2 2.22 15 4.48 28 10.44 41 40.16 3 2.34 16 4.75 29 11.28 42 47.23 4 2.46 17 5.04 30 12.21 43 56.62 5 2.6 18 5.35 31 13.27 44 69.56 6 2.74 19 5.68 32 14.46 45 88.37 7 2.88 20 6.04 33 15.82 46 117.83 8 3.04 21 6.44 34 17.38 47 169.52 9 3.21 22 6.86 35 19.17 48 279.89 10 3.39 23 7.33 36 21.27 49 644.63 11 3.58 24 7.84 37 23.75 12 3.78 25 8.4 38 26.7 When we get the grayscale value of the demarcation point, divide it according to the above steps to get the gamma index value for adaptive gamma correction. Finally, select the corresponding gamma value for gamma correction. The specific steps of the algorithm are as follows. (1) The histogram of the grayscale image is calculated to obtain the number of each grayscale value in the image at 256 levels, where the number of each grayscale level is denoted by n i is expressed. (2) Starting from a gray value of 0, the number of each gray level is accumulated and compared with the image pixel value to the adaptive accuracy 𝜃 ratio, and when the gray level L When the gray level satisfies the equation (7), the accumulation of is stopped. In this paper, the adaptive accuracy is taken under the light intensity is certain, and the light angle is used as described in the previous section. 𝜃 6 . ∑ 𝑛 𝑖 且 ∑ 𝑛 𝑖 (7)  (3) Calculate the gamma correction in the γof the index value j, calculated as in equation (8). L is the grayscale value calculated in step 4. 𝑗 100 50 (8)  (4) Determine whether the index value is out of the range of the γ value library, and take the maximum value when it is greater than 49; that is γ 49 otherwise, take γ Υ j . Figure 13 shows the block diagram of the adaptive gamma correction procedure. Start calculating the histogram 1 0 0 ( ) ( ) L i L i MN n i MN n i          1L L  100 256 L i   50 0i   [ -50]i  End N Y Y N 49  Figure 13. Adaptive gamma transformation 2.2.2. Contour extraction The edge information in an image is crucial in digital images, and the edge is the place in a digital image where the grayscale transformation is intense [18]. Edge detection algorithms are grayscale histogram-based and gradient-based edge detection. Among them, gradient-based Sobel, Laplacian, and Canny edge detection operators are widely used and have their advantages and disadvantages. We finally chose the Canny edge detection operator for edge detection through experimental comparison [19]. As the liquid bag has a certain grain, the edge information in the image containing only edge information after edge detection is more, which will cause interference to the later pipeline recognition, so it needs to screen out some edge information. The contour information can be considered a series of edge collections, and the required contour, i.e., the 194 corresponding edge information, can be filtered out by judging the geometric features of these different collections. Literature [20]. Two algorithms are introduced to achieve contour extraction. The source code of the fine contours function in OpenCV is a borrowed implementation of the algorithm from this literature. This paper uses the fine contour function of OpenCV for contour extraction. In this paper, we use the area and aspect ratio of the extracted contours to filter the contours. The experiments can filter out all the interfering contours and keep useful contour information. Finally, all the retained contour information is combined to form a new total contour image. In order to better identify the number of pipelines at a later stage, the pipeline contour needs to be processed into a single- pixel contour. The total contour image after contour filtering cannot be guaranteed to be a single-pixel contour map, so the contour needs to be refined. The classical ZS refinement algorithm eliminates the boundary points one by one after several iterations [21]. However, the ZS algorithm has limitations in processing the slant position and cannot remove the redundant pixels on the slant position. Literature [22]. The problem of the ZS algorithm's two-pixel slash refinement distortion and slash redundancy is solved by establishing an elimination template and a retention template. Its proposed improved ZS refinement algorithm is experimentally verified to be applicable in the system. 2.3. Adaptive ROI selection After assembly, only the bag body part of the liquid bag assembly was clamped at the unloading station. In contrast, the rest of the piping and dosing interface parts were not clamped and would swing with mechanical vibration. Image acquisition will not be conducive if the pipeline and dosing interface is clamped. Therefore, in the existing automatic production line, the pipeline swing and dosing interface swing caused by the vibration of machine operation will affect the image acquisition, and the result will not ensure that different liquid bag pipelines are kept in the same shape and position, so the ROI area cannot be specified directly from the original image. The pre-processed image can be used to obtain a contoured image of the liquid bag assembly that has a contour and is well connected. By identifying the coordinates of the external rectangles of each contour, we can determine the pipeline's location and then select the image containing only the pipeline and the dosing interface based on the coordinates of the rectangles, i.e., the ROI area of the pipeline. Since there are two types of liquid bag components, the long tube swing of single-inserted liquid bag components will prevent the direct detection of the missing defects of the dosing interface through the ROI area of the pipeline, so it is necessary to locate the area of the dosing interface on the ROI area of the pipeline again, i.e., the ROI area of the dosing interface. Because the dosing interface is an injection-molded part, it does not present a peaceful state, the pipeline connecting the bag body and the dosing interface is short, and the swing amplitude during assembly and processing is taught to be small, the dosing interface ROI area can be directly divided by directly dividing the area on the pipeline ROI area. As in Figure 14, the red line box is the selected outline for positioning, and then the green ROI area of the pipeline is determined by the height of the red line box and the image's width as a reference. Finally, the bottom right point of the outline image in the ROI area is used as the reference, and the ROI of the dosing interface is directly selected, as shown in the blue line box. Figure 14. Adaptive ROI 2.4. Defect detection strategy and verification Through the above image processing, the contour map of the ROI region of the line containing only the combination of liquid bag line, dosing interface, and latex cap and the contour map of ROI region of the dosing interface can be obtained, and the lines in the contour map are single-pixel linked. In this paper, the strategy to detect whether the pipeline and dosing interface are missing is to count the number of contours, i.e., two contour lines for one pipeline. In the algorithm expression, one virtual straight line is drawn in the specified area in the ROI region. The number of intersection points generated by counting the virtual straight line and the contour can determine the number of pipelines. The number of pipelines can be compared with the theoretical value to determine whether there is a defect in the liquid bag assembly. The virtual straight line method can be used for two ROI regions successively to separate defect one and defect two naturally. As in Figure 15(a), a line is drawn in the last line of the ROI contour map of the pipeline by shifting up a few lines, and the number of intersection points between the line and the contour map is 8, which means there is no defect in the pipeline. As in Fig. 15(b), the first row of the ROI of the dosing interface, where the pixel with 255 gray value appears for the first time, is shifted upward by a few lines, and the number of the intersection of the line and the contour map is 8, which means the dosing interface exists. It should be noted that defect one must be detected before defect two is detected, and defect two must be detected only when there is no defect one. Because when there is a detection for defect one, on the one hand, it can be determined that the test piece has a defect and needs to be sorted out; on the other hand, the detection of defect 2 needs “Datum Point” in figure 15 (b) for offset and marking detection, and in the case of have defect one, the correct “Datum Point” will not be obtained. The absence of the right point, "Datum Point", will lead to the wrong virtual straight line, which may lead to the wrong judgment. No matter the result, the judgment for any defect in the part to be tested is not helpful, so this paper will terminate the judgment of defect 2 when judging the existence of defect one for a while. 195 Figure 15. Virtual line method 3. Results The above algorithm is processed by calling the OpenCV library through the Visual Studio platform; The algorithm can be roughly divided into image pre-processing and defect classification detection. Figure 16 shows the overall program block diagram as described in this paper. Start Image acquisition Binarization Adaptive gamma correction Morphological operation and contour extraction Adaptive ROI region demarcation Detection of defects by virtual straight line method Detection of defects by virtual straight line method End Mark defect one Mark defect two Mark No defect YES NO YES NO Figure 16. Overall block diagram Two defect detection methods for the liquid bag assembly were tested on an experimental laboratory platform. Prepare 100 liquid bags of no defect, 100 liquid bags of defect one, and 100 liquid bags of defect two. Then mix these three kinds of liquid bags. Lastly, put them on the testing platform for testing. The process diagrams of the defect-free image, the defect-one image, and the defect-two image during the processing of the methods described in this paper are shown in Figure 17. And the test results of the laboratory experimental platform are shown in Table 2. The correct recognition rate of non-defective liquid bag components is ninety-seven percent; The correct recognition rate of defect 1 is 100%; The correct recognition rate of defect 2 is 98%. The 3% error recognition rate of non-defective liquid bag assembly and the 2% error rate of defective two-liquid bag assembly are all identified as defect one. The reason is that the deformation of the liquid bag assembly is too large during image acquisition, which leads to the outline at the intersection of the dosing interface and lanyard being too small, so the correct outline is screened out during outline screening, which further leads to the reduction of intersection points between virtual straight line and outline, and the system mistakenly identifies it as defect one. Because the system will stop the defect detection task when defect one is detected, the 2% error rate of defect two is that the liquid bag is wrongly identified as defect one, thus terminating the identification of defect two in advance. The most fundamental reason is that the outline of the intersection between the dosing interface and the lanyard is too small due to deformation. Table 2. Defect detection result Detection Quantity Identify as defect-free Identify as defect one Identify as defect two Recognition rate No defect 100 97 3 0 97% Defect one 100 0 100 0 100% Defect two 100 0 2 98 98% 196 Figure 17. The method of this paper deals with the process diagram. (a) original image. (b) original grayscale image. (c) gamma corrected image. (d) binary image before gamma correction. (d) binary image before gamma correction. (e) binary image after gamma correction. (f) adaptive ROI. (g) virtual line image. (A) defect-free image. (C) deficiency of two links in addition of medicine 4. Conclusion In this paper, a study based on machine vision detection of assembly defects on the liquid bag assembly of a bag infuser is conducted. In the research process, illumination experiments were designed and completed based on the structural characteristics of the liquid bag assembly to seek the best contrast of the acquired images. Suitable backlight angles and light intensities were selected. The illumination experiments also provide a reference for machine vision defect detection of transparent materials. For the low contrast of the transparent object imaging, in the digital image processing process can not be well separated from the background of the parts to be measured, the proposed gamma correction library based on the power function derivative production and combined with the image histogram information to achieve adaptive gamma correction algorithm, to solve the environmental reasons, the target to be inspected itself transparent characteristics bring high brightness and low contrast, and thus the problem of difficult contour extraction. The adaptive gamma correction also provides a new direction for other high-brightness low-contrast processing. Finally, based on the preliminary image pre-processing, a set of defect detection algorithms for liquid bag components is designed. Through laboratory testing, it is verified that the recognition rate of the whole algorithm system reaches 100% and 96% for two types of defects in liquid bag components, respectively. It verifies the possibility of applying machine vision to defect detection for bag infuser liquid bags and supports the research of defect detection for bag infuser liquid bag-based machine vision. Acknowledgment The authors gratefully acknowledge the financial support from Artificial Intelligence Key Laboratory of Sichuan Province (2020RYY01). References [1] Smith, M. L.; Smith, L. N.; Hansen, M. F., The quiet revolution in machine vision - a state-of-the-art survey paper, including historical review, perspectives, and future directions. Computers in Industry 2021, 130. [2] Liu, Z.; Qu, B., Machine vision based online detection of PCB defect. Microprocessors and Microsystems 2021, 82. 197 [3] Zhang, T.; Zhang, C.; Wang, Y.; Zou, X.; Hu, T., A vision- based fusion method for defect detection of milling cutter spiral cutting edge. Measurement 2021, 177. [4] Galata, D. L.; Meszaros, L. A.; Kallai-Szabo, N.; Szabo, E.; Pataki, H.; Marosi, G.; Nagy, Z. K., Applications of machine vision in pharmaceutical technology: A review. Eur J Pharm Sci 2021, 159, 105717. [5] Ma, L.; Wu, X.; Li, Z., High-Precision Medicine Bottles Vision Online Inspection System and Classification Based on Multifeatures and Ensemble Learning via Independence Test. IEEE Transactions on Instrumentation and Measurement 2021, 70, 1-12. [6] Garosi, E.; Mazloumi, A.; Kalantari, R.; Vahedi, Z.; Shirzhiyan, Z., Design and ergonomic assessment of an infusion set connector tool used in nursing work. Appl Ergon 2019, 75, 91- 98. [7] Ishii, A.; Mizuta, T.; Todo, S. In Detection of foreign substances mixed in a plastic bottle of medicinal solution using real-time video image processing, Pattern Recognition, 1998. Proceedings. Fourteenth International Conference on, 1998. [8] Li, Y. G.; Wang, Y. N.; Wang, W., Intelligent transfusion liquor inspector based on machine-vision. Opto-Electronic Engineering 2006, 33 (11), 69-74. [9] Ge, J.; Wang, Y.; Zhou, B.; Zhang, H., Intelligent foreign particle inspection machine for injection liquid examination based on modified pulse-coupled neural networks. Sensors (Basel) 2009, 9 (5), 3386-404. [10] Zhou, B. W., A Machine-Vision-Based Intelligent Inspection System for Pharmaceutical Injections. Robot 2009. [11] Wang, Y.; Ge, J.; Zhang, H.; Zhou, B., Intelligent injection liquid particle inspection machine based on two-dimensional Tsallis Entropy with modified pulse-coupled neural networks. Engineering Applications of Artificial Intelligence 2011, 24 (4), 625-637. [12] Yao, Q.; Wang, B. In Study of on-line inspection technique for foreign substance in Ampoule, International Conference on Artificial Intelligence, 2011. [13] Yang, S.; Wang, Y., On line detection and tracking method of foreign substances in ampoules in high-speed pharmaceutical lines. Chinese Journal of entific Instrument 2011, 32 (3), 488- 494. [14] Ge, J.; Xie, S.; Wang, Y.; Liu, J.; Zhang, H.; Zhou, B.; Weng, F.; Ru, C.; Zhou, C.; Tan, M.; Sun, Y., A System for Automated Detection of Ampoule Injection Impurities. IEEE Transactions on Automation Science and Engineering 2017, 14 (2), 1119- 1128. [15] Ren, Z.; Fang, F.; Yan, N.; Wu, Y., State of the Art in Defect Detection Based on Machine Vision. International Journal of Precision Engineering and Manufacturing-Green Technology 2021, 9 (2), 661-691. [16] Eshkevari, M.; Jahangoshai Rezaee, M.; Zarinbal, M.; Izadbakhsh, H., Automatic dimensional defect detection for glass vials based on machine vision: A heuristic segmentation method. Journal of Manufacturing Processes 2021, 68, 973-989. [17] Ostu, N.; Nobuyuki, O.; Otsu, N., A thresholding selection method from gray level histogram. 1979. [18] Gonzalez;, R. C.; Woods, R. E., Digital Image Processing. 4nd ed. ed.; Pearson: Britain, 2017; p 854. [19] Jing, J.; Liu, S.; Wang, G.; Zhang, W.; Sun, C., Recent advances on image edge detection: A comprehensive review. Neurocomputing 2022, 503, 259-271. [20] Suzuki, S.; Be, K., Topological structural analysis of digitized binary images by border following. Computer Vision Graphics & Image Processing 1985, 30 (1), 32-46. [21] Zhang, T. Y.; Suen, C. Y., A fast parallel algorithm for thinning digital patterns. Comm Acm 1984, 27 (3), 236-239. [22] Han, J.; Song, L., An Improved Thinning Algorithm for Character Image. Journal of Computer-Aided Design & Computer Graphics 2013.