Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 3, No. 1, 2022 1 Research on the Characteristics of Light Sources in Machine Vision Qiming Yuan, He Zhang School of mechanical and electrical engineering, Southwest Petroleum University, Sichuan 610000, China Abstract: A machine vision system as eyes, through image taking device will get signal converted into image signal, and then through computer processing, get the useful information for subsequent research. In the machine vision system, the stand or fall of lighting light source directly affects the system input. A good lighting solution can greatly reduce the later image processing of the computing workload, and can also reduce the cost of the system to a certain extent, so for machine vision system, the light source properties research is particularly important. Light source characteristics research mainly around the type of light source, light source, the intensity of the light source, the number of the layout of the light source and the color of the light source study of five aspects. These five factors will directly affect the lighting effect is good or bad, or even to a certain extent determines the success or failure of a complete set of machine vision system. Combine five factors analysis, find a lighting effect is the best plan combination, light source characteristics research of machine vision system is the key. In this paper, it chooses the best lighting scheme for the school logo box, use the control variable method to carry out research, respectively find the best light source type, quantity, intensity, layout and color, and then combine a set of best lighting scheme. In the lighting scheme studied in this paper, the best combination of lighting scheme is to use two red LED bulbs with 7W power to illuminate in the forward lighting position. Keywords: Machine vision, Light source, Characteristic. 1. Introduction In foreign countries, the concept of machine vision technology was first proposed in the 1950s, and it really began to develop in the 1970s. It was not until the end of the 20th century that it gradually developed and matured. In the beginning, the concept of machine vision was discovered and developed during the research process of robotics. In the 1970s, with the emergence of CCD image sensors, CCD cameras gradually became mainstream, which was an important turning point in the development history of machine vision technology. After entering the 1980s, the hardware technology of digital image processing developed rapidly. This has led to the rapid development of machine vision technology. In foreign countries, the application of machine vision technology is mainly concentrated in the semiconductor and electronic industries. Electronic manufacturing, automobiles, pharmaceuticals and packaging machinery occupy the majority of the market share, and 40 to 50% in the semiconductor industry, such as PCB printed circuit boards and single-sided and double-sided. Multilayer circuit boards, electronic packaging equipment and technology, screen printing equipment, SMT surface mount related equipment, production, processing, molding of various electronic components, integrated circuit manufacturing equipment and electronic tooling, etc,and in quality There are also very common applications in all aspects of detection, and its products also occupy a considerable area in the application. In addition, machine vision systems also occupy a place in various industries and fields such as agricultural industry, aerospace, meteorological monitoring, astronomical observation, military security, and scientific research. In China, the current research on machine vision technology and the application of machine vision in industry are still in the nascent stage. It has only appeared for less than forty years, so many related theories and technologies are very immature, and there are quite a few limitations in the image acquisition, that is, the input end of the machine vision system, such as the image acquisition of high-speed moving objects and the difficulty and cost of manufacturing its sensitive components. Therefore, in order to Keeping the cost within an affordable range will make the resolution of the collected images difficult to meet the requirements. Therefore, machine vision technology needs to go through a long journey to mature, and there is still a lot of room for development. In the machine vision system, lighting is a key factor affecting the input of the machine vision system, which directly determines the quality of the input image and the effect of subsequent research. For machine vision systems, if a good lighting scheme or a suitable light source can be selected, it means that the system has succeeded most of the time. Different objects under test have different light sources suitable for illuminating them, so there is no general lighting scheme for machine vision systems. In order to achieve the best lighting effect, the choice of lighting scheme must be analyzed in combination with the target object to be measured. The machine vision system is equivalent to the human eye to the machine. The machine captures the external image through the vision system, and then further processes it, converts the pixel information such as the color and brightness of the image into digital signals, and then processes the converted digital signals separately. so as to analyze the characteristics of the target. The machine vision system can be used in some areas where the environment is more dangerous, or the target object is small and moving at a high speed, and the human vision cannot work normally or meet the requirements. At the same time, because of the computer- assisted calculation, machine vision can directly quantitatively analyze the uptake of the target, which is far more precise and scientific than human eye observation. 2 Because of the above advantages, the machine vision system has a wide range of applications in industrial production and other fields. It can greatly improve the efficiency of production, and to a certain extent, improve the degree of automation of industrial production. To apply machine vision system to actual production, most fields need to choose a set of easy-to-use lighting scheme to provide lighting to improve the clarity of input image. A good lighting scheme will greatly highlight the difference between the object and the background, and get the clearest image input system, so that the workload of processing the image can be greatly reduced. Lighting in machine vision refers to the use of a certain light source and lighting method for lighting, in order to obtain the clearest image. Judging the quality of the lighting scheme depends on whether the lighting effect can do the following: (1) Maximize the contrast between the target part and other parts; (2) Try to eliminate the parts that are not related to the measured target; (3) Improve the image quality Signal-to-noise ratio. A reasonable lighting scheme can improve the resolution of the entire system and simplify the algorithm; however, an unreasonable choice of lighting scheme will cause a lot of unnecessary trouble. Therefore, to a certain extent, it can be said that the choice of lighting scheme will directly affect the success of the system. For each different detection object and detection environment, different lighting methods are required to highlight the characteristic information of the detected object, and sometimes a combination of several methods may be required. The selection of the best lighting method and light source often needs to be determined through a lot of experiments. The research purpose of this paper is to select a reasonable and efficient lighting scheme for specific application examples, so as to highlight the difference between the background and the object to the greatest extent, and obtain the clearest image input system to facilitate subsequent research and processing. 2. Relevant Theories and Overall Plans 2.1. LED The full name of LED is light-emitting diode, which is a kind of semiconductor device. At first, it was mainly used as an indicator light or display panel in the circuit. Later, with the appearance of white LED, it began to be slowly used in the field of lighting. As we all know, LED has the characteristics of energy saving, environmental protection, long life, small size, low heat generation and high luminous efficiency. Therefore, LED gradually eliminated the original incandescent lamp and became the most widely circulated light source on the market. The development prospects of LED lamps are also huge. If nothing else, lighting alone is a huge development direction. With the advent of the global ban on the sale of incandescent lamps, LED has undoubtedly become the best choice for lighting, Therefore, this paper mainly focuses on the research of LED lamps as lighting sources. 2.2. Image Gray Value A grayscale image is a black and white image. Although a black and white image has no color, it can still clearly display the general outline and characteristics of the image, because the grayscale value of each pixel is different. To a certain extent, grayscale can be regarded as brightness, or the depth of color. The more gray levels an image can show, the richer the color expression of the image, and the stronger the color gradation can be. 2.3. Contrast Contrast refers to the ratio of the maximum difference between light and dark areas in an image, and the greater the difference, the greater the contrast. Generally speaking, contrast refers to the clarity of the image in the visual effect. The image with high contrast is relatively clear and bright, and the color is more vivid, while the image with low contrast is relatively blurred, and the whole image looks gray and the color is not good. Too bright, which can cause some details in the image to be uncaptured, which is often referred to as distortion. To determine the clarity of an image, the contrast is undoubtedly a good criterion, so the calculation of the contrast is particularly important for judging the quality of the lighting scheme. 2.4. Overall Plan The essence of the research on the characteristics of light sources in machine vision systems is to use computers to compare massive data to determine the optimal vision to determine the lighting scheme, that is, the type, quantity, color, position of the light source, and the power of the light source affect the lighting effect. The factors are variable, a mathematical model is established, and the control variable method is used to conduct experiments one by one, and then determine the best lighting scheme. According to the current experimental conditions, although it is impossible to carry out a large number of accurate experimental studies, some light sources in daily life can be replaced to study some main influencing factors. Theoretically speaking, the judgment of the lighting effect is directly related to the contrast of the image, but due to the relatively simple experimental equipment, there will be a lot of unavoidable systematic errors and random errors. These irresistible interference will affect the contrast calculation to a certain extent. As a result, it is not so reliable to judge the quality of the lighting scheme based on the image contrast alone. Therefore, in the research of this paper, the edge detection results of the image and the gray-scale contour map, which have relatively intuitive visual effects, are used as the main criteria for judging the quality of the lighting scheme, and the contrast and standard deviation of the image are used as the main criteria. Auxiliary criteria, and finally according to the experimental research results, to determine the relatively optimal lighting scheme. 3. Research on Algorithms 3.1. Contrast As shown in Table 1, assuming that the blue part in the middle is the photo to be calculated, first perform pixel expansion on the edge of the photo, that is, the peripheral white part, so that the peripheral pixels of the photo can also become the central pixels to participate in the calculation, thereby improving the accuracy . The principle of expansion is that the expanded pixel is completely duplicated with the adjacent pixel, so that no new error will be generated. In the calculation, the square of the difference between the surrounding pixels and the center pixel is summed, and then divided by the number of square terms to calculate the 3 contrast, The number of square items is eight pixels in the middle (m-1)×(n-1) rectangle. At the four corners of the photo, namely A11, A1n, Am1 and Amn, due to the expansion of pixels, the surrounding The three extension pixels are the same as themselves, so the number of squared terms in the calculation of these four pixels is five. Similarly, pixels that are on the edge of the photo ,but not in the four corners have seven squared terms. Table 1. Contrast calculation               A11  A12  ……  A1n      A21  A22  ……  A2n      ……  ……  ……  ……      Am1  Am2  ……  Amn                There are generally two types of contrast calculations, the first is to use the center pixel and the four pixels of the upper, lower, left, and right, and the second is to use the center pixel and the surrounding eight pixels to calculate and process. Considering that the latter has more pixels involved in the calculation, the accuracy of the calculation will be higher, so this paper adopts the second method to calculate the contrast. The contrast calculation script and comments are as follows: % Contrast calculation method: Calculate the contrast by calculating the difference between the gray value of the central pixel and the gray values of the surrounding 8 neighboring pixels: function dbd = duibidu(A) ; % defines the function to calculate the contrast of the image. [m,n] = size(A); % Find the number of rows m and the number of columns n of the original image. B = padarray(A,[1 1],'symmetric','both'); % Expand the original image to assist the calculation. Expand the periphery of the entire original image by a circle, so that the pixels at the edge of the image can also participate in the calculation to improve the accuracy. The principle of expansion is that the gray value of the expanded pixel is the same as the edge pixel that needs to be calculated. [M,N] = size(B); % Find the number of rows M and the number of columns N of the expanded image. B = double(B); % Convert the expanded image to a double- precision floating point number. In general, images are stored as uint8 data. When performing data operations on images, if the data is greater than 256, overflow will occur and result will be distorted. However, there will be no overflow during double-precision operation, so convert the uint8 data to double-precision first, and then perform the operation, so that the calculation precision will not be distorted. k=0; % define a value k, the initial value is 0. for i=2:M-1 %M-1=m means from the second row of pixels to the end of the penultimate row of pixels, which means that although the expanded pixel matrix is larger, the calculation is still based on the original image. Pixel specifications are calculated, ignoring extended peripheral pixels. for j=2:N-1 %N-1=n means starting from the second column of pixels to the end of the penultimate column of pixels, for the same reason as above. k = k+(B(i,j)-B(i,j-1))^2+(B(i,j)-B(i-1,j))^2 +(B(i,j) - B(i,j+1))^2+(B(i,j)-B(i+1,j))^2+ (B(i,j)- B(i+1,j+1 ))^2+(B(i,j)-B(i-1,j+1)) ^2+(B(i,j)-B(i+1,j- 1))^2+( B(i,j)-B(i-1,j-1))^2; % The surrounding pixels and the center pixel are sequentially calculated to square the difference. end end dbd = k/(8*(m-2)*(n-2)+7*(2*(m-2)+2*(n-2))+4*5) ;% Find the original image contrast. The comparison is calculated by dividing the sum of the squares of the difference between the surrounding pixels and the center pixel by the number of squared terms. 3.2. Standard Deviation The standard deviation reflects the degree of dispersion between pixel gray values, which can also reflect the clarity of the image to a certain extent. contrast. The formula for calculating the standard deviation is: s ∑ ̅ (1) In MATLAB, the function std2() is used to calculate the standard deviation of the matrix. The specific procedure is as follows: Function BZC=biaozhuncha(A); B=rgb2gray(A);% Convert RGB image A to grayscale image B figure; subplot(121); imshow(A); subplot(122);imshow(B);% show images A, B SA=std2(A); SB=std2(B);% Calculate the standard deviation of the original image A and the grayscale image B. 3.3. Edge Detection and Grayscale Contour Map Edge detection and grayscale contour map can more intuitively reflect the details of the object to be measured in the image. The display of image contour map can be realized by imcontour function. Edge detection is calculated by Gaussian filter. The local maximum gradient is used for edge detection, which is implemented with the 'canny' statement in the edge function. The specific procedures are as follows: function byjc=bianyuanjiance(A); B=rgb2gray(A);% Convert RGB image A to grayscale image B C=imcontour(B);% display the contour contour C of the grayscale image B D=edge(B,'canny');% Perform edge detection on grayscale image B. figure; subplot(131); imshow(A); subplot(132); imshow(B); subplot(133);imshow(D);% Display images A, B, D in the 1*3 image display box figure; imshow(C);% show image C 4. Study on the Characteristics of Light Sources The research on the characteristics of the light source is inseparable from the specific object to be tested. Different light source lighting schemes should be selected for different 4 objects to match it. The specific objects should be studied in detail rather than generalized. This paper mainly uses the school badge box of the 60th anniversary of Southwest Petroleum University as the measured object to conduct in- depth research, in order to maximize the difference between the background and the school badge box, and to clearly present the shape of the school badge box and the "60" and "60" on the box. The words "Southwest Petroleum University" are the best lighting scheme. 4.1. Type of Light Source In the machine vision system, visible light is mainly used for illumination. There are many types of visible light. The more common ones are light from incandescent lamps, halogen lamps, high-frequency fluorescent lamps, LEDs, and xenon lamps. The comparison of these light sources is shown in Table 2: Table 2. Comparison of light source types light source Lifetime/hours Features color brightness Incandescent lamps 1000~2000 high calorific value white, yellowish Bright halogen lamp 5000~7000 high calorific value white, yellowish Very bright High frequency fluorescent lamps 5000~7000 high calorific value white, green Bright LED 60000~100000 high calorific value white, red, green, blue brighter Xenon lamp 2000~3000 low calorific value white Bright The advantages of the LED lights in the table are particularly clear, the lifespan is far longer than other types of lights, the heat generation is less, the brightness is ideal, and a variety of colors can be realized small size, environmental protection and other advantages. There is no doubt that LED is the most ideal lighting source for machine vision systems, and in practical applications, LED lights are indeed the mainstream in the field of machine vision. According to the current experimental conditions, this paper mainly focuses on incandescent lamps and LED lamps. Because the luminous effect of high-power incandescent lamps is similar to that of low-power LEDs, incandescent lamps can be used instead of LED lamps as the light source to study the influence of the layout and quantity of light sources on the lighting effect. However, the color of incandescent lamps is single, generally white and yellowish, and to achieve the lighting effect of LED lamps, the power is relatively large, so when studying the influence of the color of the light source and the power of the light source on the lighting effect, the LED lamp is used for research experiments. 4.2. Layout and Number of Light Sources The layout of the light source is the placement of the light source. There are many layouts of the light source, such as forward lighting, back lighting, bright field lighting, dark field lighting, structured light lighting, strobe lighting, etc. The layout of each light source is different. Corresponding to different functions; the number of light sources is related to the cost of the system. If the lighting effect is sufficient, the number is undoubtedly as small as possible, but sometimes the number of light sources is too small to meet the system requirements. In this case, it is necessary to appropriately increase the number of light sources. Prioritize whether the lighting effect meets the system input requirements. The choice of the light source layout scheme and the choice of the number of light sources are both important factors that affect the clarity of the input image. Under the current experimental conditions, this paper mainly takes the incandescent lamp as an example to carry out research on the three light source layout schemes of forward lighting, back lighting and dark field lighting, and each scheme uses one and two light sources respectively. Forward lighting is that the light source and the camera are placed on the same side of the object to be measured, and the light emitted by the light source is directly reflected into the camera, which is also one of the most common lighting methods. The light of the dark field illumination light source shines on the object but the reflected light is not reflected into the camera, that is, the light source is placed on the side of the object for illumination. The principle of back lighting is that the light source and the camera are on both sides of the object to be measured, the light source is placed on the back side, the camera takes pictures from the front, and the light from the light source directly illuminates the camera. Through experiments, three light source layout schemes are used and one and two light sources are used to illuminate them respectively, and the obtained pictures are put into Matlab for image edge detection and grayscale contour plots, and the obtained pictures are calculated. Standard deviation and contrast ratio, the optimal lighting scheme obtained by comparison is to use two LED lamps for forward lighting. 4.3. The Intensity and Color of The Light Source The intensity of the light source, that is, the power of the light source and the color of the light source, are also key factors that directly affect the lighting effect. The use of a light source with appropriate power and appropriate color can improve the clarity of the obtained image. According to the current experimental conditions, this paper will use an LED bulb as the light source for lighting. The lighting layout adopts the optimal forward lighting studied above. The power of the light source is 5w, 6w, 7w and 13w, and the color of the light source is good. The research mainly focuses on white, red and blue. Through experiments, three light source colors are used to illuminate them with light sources with power of 5w, 6w, 7w and 13w respectively, and the obtained pictures are put into Matlab for image edge detection and grayscale contour map, and calculate The standard deviation and contrast of the obtained pictures are compared, and the optimal lighting scheme is selected as the use of 7w red LED lighting. 5. Experimental Research Conclusions The purpose of this paper is to select an optimal lighting 5 scheme for the school badge box, so that the machine vision system can obtain the shape and surface details of the school badge box. The lighting scheme includes the type, color, intensity, quantity, and placement of the light sources. The selection of light source types has been mentioned above. As a popular lighting source, LEDs overwhelm other types of light sources in all aspects of their performance. Therefore, choosing LEDs as lighting sources is undoubtedly the best choice. The choice of the number of light sources is limited by the experimental conditions. The main research compares the lighting effects of one light source and two light sources. According to the experimental results, the lighting effect of two light sources is better than that of one light source alone. The placement position of the light source is the layout of the light source. This paper mainly studies forward lighting, dark field lighting and back lighting. According to the above research, among the three light source layouts, the best lighting effect is undoubtedly the forward lighting, which can clearly capture the shape and surface features of the measured object. Darkfield lighting has a poor ability to capture the shape of an object. Backward illumination can clearly capture the shape of the object, but the detection of surface details of the object is worse than that of forward illumination, and it is more suitable for simply detecting the shape of the object or studying objects with a certain degree of transparency. The choice of light source color, this paper mainly studies white, red and blue. Theoretically, because the color of the object in this study is blue and the background is white, blue light on the background will turn the background blue, resulting in a reduction in the color difference between the background and the measured target. Therefore, the lighting effect will be poor, and the color of the light source that produces the best lighting effect should be one of white and red. The actual research results are roughly consistent with the theory. Based on the analysis of the experimental research results, among the three colors, the red light source is the best lighting source. The red light source has been determined as the best illumination light source above, so the influence of different light source powers on the lighting effect under the illumination of the red light source is directly compared. Comparing the lighting effects of 5w, 6w, 7w and 13w, the situation of edge detection and grayscale contour map is similar, and it is difficult for the naked eye to tell which one is clearer, but in terms of contrast, the contrast under the 7w power light source is the largest, so Among the four powers studied, the best light intensity is when the power of the lighting source is 7w. To sum up, when the object observed by the machine vision system is the school badge box, among the lighting schemes that have been studied, the best lighting scheme combination is to use two red LED bulbs with a power of 7w in the forward lighting position for lighting. The lighting effect diagram is shown in Figure 1: Figure 1. Lighting effect 6. Summary The study of light source characteristics is particularly important for the input of the machine vision system. According to the current research, only a relatively good lighting scheme can be determined, but a lot of research is needed to make a more accurate choice. In addition, this paper mainly uses edge detection and the visual effect of gray contour map to subjectively judge the quality of the lighting effect. The calculation of contrast is not accurate enough. This method is not scientific enough, so further research on the algorithm of image contrast is needed. References [1] Jin Weiguo, Zhou Li. Research on light source characteristics of machine vision system using MATLAB [J]. Special equipment for electronic industry, 2012,41 (02): 40-47. [2] Xu Lei. Development status and Prospect of machine vision technology [J]. Equipment management and maintenance, 2016 (09): 7-9. [3] Chen Ying. Research on development status and application dynamics of machine vision technology [J]. Wireless Internet technology, 2018, 15 (19): 147-148. [4] Yin Zhongxin, Wang Quanliang. Lighting optimization design in machine vision system [J]. Microcomputer information, 2010,26 (07): 129-131. [5] Hou yuanshao. Selection of light source in machine vision system [J]. Journal of Luoyang Normal University, 2014,33 (08): 45-49. [6] Wang Wenjie. LED light source and optical characteristic detection [C]. Jiangsu metrology and testing academic papers (2011): Jiangsu metrology and testing society, 2011:177-182. [7] Shang Huichao, Yang Rui, Duan Mengzhen, Duan Xiaowei, Zhang Hongbin. Key technology analysis of machine vision lighting system [J]. Journal of Zhongyuan Institute of technology, 2016,27 (03): 16-21. [8] Bi Mingde, Sun Zhigang, Li Yesong. Fabric defect detection system based on machine vision [J]. Instrument technology and sensor, 2012 (12): 37-39 + 125. 6 [9] Li Yunfeng, Han Xixi, Li Shengyang. Dimension parameter measurement of stamping parts based on machine vision [J]. Tool technology, 2015,49 (11): 95-98. [10] Fu Lihong. Research and development of lighting source database based on machine vision [J]. Technological innovation and application, 2019 (26): 18-19. [11] Liu Qing, Zhang Jinhua, Huang Junqin. Detection and classification of steel ball surface defects based on machine vision [J]. Bearing, 2013 (10): 44-48. [12] Wang Tianyi, Wang Xin, Cao Xingqiang, Zeng Jian, Jia Zhenzhen, Li Xiao, Yao ermin. Optimization of light source for inner packaging defect detection based on machine vision [J]. Packaging engineering, 2019,40 (17): 174-181. [13] Hua Zhengyang. Research on thermal imaging image recognition system based on vision technology [J]. Communication world, 2019,26 (12): 12-13. [14] Zhou Zitian. 3D object surface information recognition and detection system based on vision technology [J]. Communication world, 2019,26 (12): 18-19. [15] Ye Jiaying, Deng Fei, Wang Peixin, Zhao Daxu, Wang Yuzong, Shou Guozhong. Pearl color feature extraction and recognition based on machine vision [J]. Jiangsu Agricultural Sciences, 2019,47 (20): 226-230 + 240.