Automatic Spring Detection System Based on Machine Vision
2026-04-06 06:01:34··#1
Introduction Spring surface quality inspection is a crucial step in spring manufacturing. During inspection, various testing methods are used to determine the spring's performance, quantifying its quality and providing accurate assessment criteria for enterprise quality management and tracking. Finished spring inspection mainly includes appearance inspection, dimensional inspection, and load testing. Here, we primarily focus on appearance and dimensional inspection (including spring length, wire diameter, wire spacing, and effective coil count). Existing domestic spring inspection methods generally rely on manual visual inspection using tools such as vernier calipers. This method is not only inefficient but also prone to errors. Some companies import advanced equipment for automated spring inspection, which significantly increases production costs and makes equipment maintenance difficult. Therefore, developing an automated spring inspection system based on machine vision is of great significance. This system is primarily developed using NI's LabVIEW graphical programming environment, featuring a simple and user-friendly interface for easy operation by inspection personnel. For springs of the same specification, the system compares all spring data with corresponding standard values to classify the springs. Experimental results show that compared to traditional manual inspection methods, this method offers faster inspection speed, higher accuracy, and stronger reliability. I. Hardware Composition of the Spring Inspection Platform 1.1 Components of the Inspection System The hardware composition of the automatic spring inspection system is shown in Figure 1. The spring is horizontally placed on a white rotating shaft, driven by a stepper motor. The PLC, in addition to sending pulses to drive the motor rotation, also uses these pulses as external trigger signals to the image acquisition card to ensure proportional image acquisition. The camera uses a Basler L101k-2k linear scan camera from Basler, Germany, in conjunction with a PCI-1428 image acquisition card from NI to complete image acquisition. The acquired spring unfolded diagram is shown in Figure 1. After the camera acquires a frame of the spring unfolded diagram, it is sent to the computer for processing via the image acquisition card. The computer mainly performs hardware configuration and initialization, image processing, data analysis, and storage functions. After obtaining the key parameters of the spring surface defects and dimensions through image processing, the computer compares them with the corresponding spring standard library information to identify unqualified springs. Figure 1 Schematic diagram of automatic spring detection system 1.2 Cooperation between line scan camera and acquisition card The imaging principle of line scan camera is different from that of area scan camera. It only acquires one line of image at a time. Only when there is relative motion between the lens and the object being photographed can a complete two-dimensional image be acquired. In Figure 2, the vertical direction is the direction of the line scan sensor, and its resolution is determined by the line scan CCD; the horizontal direction is the scanning direction of the camera, and its resolution is determined by the minimum step distance of the stepper motor. If the motor speed is too high, the image will be compressed, as shown in Figure 2(b); if the speed is too low, the image will be stretched, as shown in Figure 2(c). Figure 2 Corresponding imaging effect when the motion speed is different In order to obtain an image of equal scale, the camera is set to work in external edge trigger mode, as shown in Figure 3. In this mode, the line scan rate of the camera is completely determined by the frequency of the external signal. The relationship between the two is: line scan rate = 1 / external signal frequency. NI's PCI-1428 image acquisition card provides four pairs of external trigger ports (from Trig_(0) to Trig_(3), respectively, with the input signal type being TTL level), supporting the external synchronous imaging mode of the line scan camera. By connecting the pulses emitted by the PLC to any external trigger port of the PCI-1428 data acquisition card, the correspondence between motor speed and line scan rate is achieved. MAX (Measurement & Automation Explorer) is software developed by NI to facilitate users in setting and testing various hardware. In MAX, the basic parameters of the data acquisition card can be configured as needed, such as image acquisition mode, image size, and trigger signal type. Figure 3 External Edge Trigger Mode (ExSync, Edged-controlled Mode) II. Key Modules of Spring Detection The software part of the automatic spring detection system is developed using NI's LabVIEW graphical programming language. LabVIEW's intuitive icon operation, efficient multi-threaded parallel processing, and convenient modularity greatly shorten the program development cycle, resulting in high program execution efficiency and strong scalability, facilitating error checking and modification at any time. The flow of the spring detection part is shown in Figure 4. The program mainly consists of several functional modules: spring standard library update, image acquisition, image processing, and data analysis and processing modules. Figure 4 Image Processing Main Program Flow 2.1 Spring Standard Library In this system, the specifications of springs are distinguished by their outer diameter. The spring standard library contains two types of information: calibration information for springs of different specifications and their corresponding standard dimensions. Once the camera position is fixed, the actual size represented by a unit pixel in the X-direction of the image remains constant, while the actual size ΔLi in the Y-direction is proportional to the spring's outer diameter. Therefore, we need to know ΔLi in advance to obtain the actual size value of the spring. Since the standard library cannot possibly contain information for all spring specifications, the system also includes an expansion function for the standard library, allowing inspectors to add information at any time. Figure 5 shows the section on adding calibration library information. 2.2 Image Acquisition For external triggering of linear array images, IMAQ provides two basic triggering modes: Variable Height Acquisition (VHA) and Trigger Each Line (TEL). This paper adopts a combination of these two acquisition methods. Because the outer diameter of the spring under test is variable, the VHA acquisition mode can adapt to image acquisition at variable heights, while the Trigger Each Line mode ensures that the camera's line scan rate is synchronized with the motor speed. Figure 6 Image Acquisition Sub-VI Before starting acquisition, the following steps should be taken: (1) Initialize the acquisition card using the IMAQ Init function; (2) Configure the buffer units using the IMAQ Configure List function. Each unit should be allocated space separately within the For loop; (3) Set the trigger type to Trigger Each Line. Note that before using VHA mode, the maximum height of the image should be preset in MAX (this value is set to 1000 in this application). The camera will automatically stop acquiring images after acquiring 1000 lines. 2.3 Image Processing For the field of machine vision, NI provides the automatic detection vision generator NI Vision Builder AI and Vision Assistant software to assist in image processing. In their interactive menu-driven environment, users can easily develop machine vision applications without programming. In addition, Vision Builder and Assistant can automatically generate LabVIEW or C code, which greatly simplifies programming and also provides the possibility for the expansion of the development platform. For detecting surface defects on springs, we are only interested in the information of the spring lines' surface. Therefore, we can use Image Mask to mask the background, gaps between spring lines, and other parts. The Image Mask function has two masking methods: one is to directly select the Region of Interest (ROI) on the image (which can be a rectangle, ellipse, etc.); the other is to import an existing mask image. Based on the image characteristics, we choose the second method here. To obtain the ROI region of the spring lines, we first binarize the original grayscale image of the spring using the intraclass variance method, then fill the surface defect area of the spring using the Fill Holes function to obtain a lossless binary image of the spring. Finally, we erode the entire image to obtain the required mask file. As shown in Figure 7, if we do not erode the image at the end, the edges of the spring lines will remain, which is meaningless for our surface defect analysis. After obtaining the mask image of the spring outline, we import this file into the Image Mask function to obtain a grayscale image containing only surface defects. Figure 7: Comparison of un-erodeted and erodeted mask images. Particle filtering and analysis: The remaining ROI is binarized using the thresholding method to obtain a binary image containing surface defects and noise. After corrosion and expansion, the Particle Filter function is used to filter out suspicious microparticles, thus obtaining an image of the spring surface defect. The Particle Analysis function is used to obtain the area of the particles, and the actual area of the surface defect is calculated using calibration information. The Particle Analysis function provides results for nearly a hundred particle parameters, including the number of particles, perimeter, orientation, etc. 2.4 Accessing the Database Using the SQL Toolkit The LabVIEW SQL Toolkit (also known as the LabVIEW Database Connectivity Toolset) is an add-on toolkit for database access. It integrates a series of advanced function modules that encapsulate most database operations and some advanced database access functions, supporting local or remote ODBC databases. This toolkit can access the database through UDL files or by directly accessing the database file, facilitating the publication and application of standalone files. The library is divided into general VIs and advanced VIs. When dealing with general database problems, the general VIs can be used to quickly implement basic functions such as database querying and storage. Advanced functions, such as parameterized queries and calling stored procedures, can be implemented using the advanced VIs. Overall, the detection system can be integrated with the LabVIEW SQL Toolkit for database operations, improving the rapid prototyping of programming. 2.5 Data Analysis and Test Results Figure 8 shows the main interface of the automatic spring detection system. The main program primarily implements the functions of spring detection, historical data query, and standard library update. To facilitate operation by inspection personnel, the interface design is kept as simple as possible. To test the stability and accuracy of the algorithm, we used a group of 10 springs with surface defects for detection, and the results are shown in Figure 9. The results show that the detection accuracy of the spring dimensions fully meets the requirements, with deviations generally within ±0.2mm, and the accuracy rate for repeated detection of the same spring is 100%. Figure 8 Main interface of the detection program Figure 9 Test results of sample defective springs III. Conclusion Introducing machine vision into the spring quality inspection process, compared with the original manual inspection system, has the following advantages: ● High detection accuracy. The required error for manual spring inspection is within ±0.5mm, while the size of the dimensions detected by vision can achieve a detection error within ±0.1mm; ● Fast detection speed. Manually inspecting a spring takes approximately 3 seconds, while this system takes only 1 second. However, manual inspection is susceptible to emotional fluctuations and eye fatigue, making it difficult to maintain consistent inspection results. Visual inspection, on the other hand, offers stable performance, achieving 100% accuracy in repeated inspections of the same spring, and can operate continuously for 24 hours. While machine vision is increasingly widely used in industry, its application in spring inspection, combined with line scanning systems, is currently unexplored in China. Due to my limited experience, the development of this system encountered numerous challenges, requiring significant effort and time in everything from solution selection and hardware system setup to image processing algorithm research. Ultimately, choosing LabVIEW as the development platform proved to be a wise decision. Its ease of learning, powerful functionality, rich example libraries, and comprehensive network support allowed the development team to focus on algorithm design rather than spending excessive time on programming. Machine vision is a highly versatile technology; while the underlying technologies are consistent, significant differences in application are a key characteristic of various machine vision systems. Therefore, the development of this system offers valuable insights for the application of machine vision in other fields.