Background
With the rapid development of computer technology, camera technology and digital image processing technology, machine vision technology is also changing day by day, playing an irreplaceable role in modern manufacturing industry. In modern society, machine vision technology has found widespread use in various industries, such as construction, cosmetics, metal working, electronics manufacturing, packaging, automotive manufacturing, pharmaceuticals, and the like. For example, in the medical field, the most typical application is magnetic resonance imaging, which can display an image of the inside of a human body using a certain medical instrument. In the field of movie and television, 3D movies that we often see are an important branch of machine vision — virtual reality. In industrial production, machine vision can realize the detection to product defect automatically, has greatly reduced manpower and materials, has improved production efficiency. In the field of unmanned driving, the machine vision technology can detect surrounding complex conditions, so that an automobile can make correct judgment. Machine vision techniques are used in the field of recognition, such as face recognition and speech recognition in cell phones. In popular terms, machine vision is to replace human eyes with certain machine equipment, so that a series of behaviors which can be finished by only people, such as observation, measurement, understanding, judgment and the like, are realized.
The traditional product defect detection mainly relies on a manual detection method, and the detection method has obvious defects. First, since the detection is performed by human eyes, the detection accuracy is inevitably low, and the detection quality is not guaranteed. Secondly, the detection method consumes a large amount of manpower and material resources, causes resource waste, and is an extremely low-efficiency product detection method. Compared with the traditional detection method, the machine vision detection method greatly improves the quality of the detected product, improves the production efficiency, saves manpower and material resources, is very accurate, and can accurately identify some very small defects. The process of machine vision is actually similar to the human eye. First, an image is captured by a machine vision product, i.e., an image capture device. Then the image is sent to a processing unit, a series of processing is carried out on the image, the measurement of size, the detection of edges, the judgment of shapes and the like are carried out according to the information of pixel distribution, brightness, color and the like, and finally the corresponding equipment action is controlled according to the detection result, so that the non-contact detection is realized. Therefore, there is a significant and necessary need for the study of machine vision.
Disclosure of Invention
The invention provides a product defect detection method based on Labview, aiming at the problems of low precision, waste of a large amount of manpower and material resources, time consumption and low efficiency when a traditional manual detection method is used.
The method of the invention utilizes Labview to create a set of machine vision detection system, the system communicates Labview and PLC, when detecting that the product reaches the corresponding position, the system sends corresponding signals to the computer, and after sending the signals to the Labview system, the system automatically takes pictures of the product, and compares the obtained pictures with the template image to obtain the similarity of the products, if the similarity reaches the set value of the user, the product is qualified, otherwise the product is unqualified.
A product defect detection method based on Labview comprises the following steps:
and (1) configuring the PLC, adding a sending data block and a receiving data block in the PLC, and writing a sending data program and a receiving data program of the PLC through STEP 7. And then programming by using the Labview, establishing a TCP connection, and compiling a data receiving program and a data sending program of the Labview, thereby realizing the data communication between the Labview and the PLC. STEP 7 is the plc programming software of siemens,
and (2) carrying out hardware configuration of the machine vision system, wherein the hardware configuration comprises a camera, a light source and output equipment.
The camera is an industrial camera based on a CCD, and the light source comprises a coaxial light source, a zero-angle light source and a strip-shaped light source which are selected according to actual conditions. The output equipment adopts a liquid crystal display screen and is used for displaying an output result and a user operation interface.
And (3) compiling a Labview program, wherein the Labview program comprises a video image real-time acquisition module, an image display module, an image acquisition module, a template manufacturing module, an image matching module and a system front panel module. The user can set the parameters in the front panel.
The video image real-time acquisition module is connected with the camera and generally has a while loop, and when the condition is true, the content in the while loop is repeatedly executed, so that the real-time acquisition of the image is realized and the image is displayed in the front panel. The image display module reads the data of the template image and displays the read image on the front panel. The image acquisition module is used for automatically acquiring a frame of image of the workpiece from the video image acquired by the video image real-time acquisition module when the workpiece reaches the designated position so as to perform subsequent image comparison operation, and the real-time acquired image displayed on the front panel is frozen into the image acquired by the image acquisition module. The template making module is used for selecting a frame of image from the real-time image displayed on the front panel by a user and selecting an interested area in the image to make the image into a template image. The image matching module firstly reads a template image, selects an interested region of an acquired picture, then converts the acquired picture into a gray picture, and finally performs template matching by using a gray pyramid method. The system front panel module comprises a user operation interface and a display interface, the user operation interface is provided with five buttons according to system functions, namely, acquiring pictures, making templates, matching images, displaying on/off in real time and quitting, and a user performs corresponding operation through the user operation interface; the display interface is divided into two parts of template image display and result display, wherein the template image display is used for displaying the loaded template image, and the result display is used for displaying the detection result and the matching degree of the picture.
And (4) debugging the system to achieve an ideal product defect detection effect.
The user sets the similarity according to the self requirement, the higher the set value is, the higher the matching precision is, and the maximum value set by the similarity is 1000, namely complete matching is realized.
The PLC adopts Siemens S7-1200 PLC.
The invention has the following beneficial effects:
the method of the invention can realize the full-automatic detection of the product defects, and thoroughly changes the prior manual detection method. On one hand, the system can greatly reduce manpower and material resources, reduce resource waste and greatly reduce engineering cost. On the other hand, the system can effectively improve the quality of products, reduce the defective rate, prevent the environment from being damaged by discarding defective products, is favorable for the sustainable development of economy, and has certain popularization and use values. The invention can automatically compare parts with standard parts, thereby detecting which products are qualified and which products are unqualified, realizing complete automatic detection, greatly reducing manpower and material resources, reducing defective rate, reducing environmental pollution and having certain sustainable development potential.
Detailed Description
The present invention will be described in further detail below with reference to the accompanying drawings and examples.
According to the method for automatically detecting the product defects, the PLC is used for carrying out TCP connection on the Labview, so that wireless communication is realized. The main part is the programming of a Labview program and mainly comprises six modules, namely a video image real-time acquisition module, an image display module, an image acquisition module, a template manufacturing module, an image matching module and a system front panel module. When the product reaches the designated position, the product can be automatically photographed and sampled, and the photographed and sampled image is compared with the original template image after image processing, so that whether the product is qualified or not is determined, and the implementation flow is shown in fig. 1. The method comprises the following steps:
FIG. 1 is a flowchart illustrating a method for detecting defects in a product according to the present invention.
And (1) configuring a PLC (programmable logic controller) and writing a program for receiving and sending data. And adding a sending data block for storing data sent by the PLC to the LabVIEW. Click on chunk/add new chunk, select data chunk in open dialog, enter name PlcSendData, type select global DB. Note that instead of transmitting large amounts of data at once, the PLC variables can be used directly, sending one data at a time, without creating a block of data. Then, the data block PlcSendData is opened, data is added, the name of the data block is ArySendData, the data type is selected to be Array of Byte, namely Byte Array, and the Array length is set to be 10. And adding a receiving data block for storing the data sent by the LabVIEW to the PLC. The data block name is PlcRecvData, and the data type is Array of Byte. Writing a data sending program, opening a Main program, adding an instruction communication/open user communication/TSEND _ C to a program segment 1, and calling the data block name of an option by default; configuring the communication parameters of TSEND _ C, selecting TSEND _ C and right key attributes, switching to a configuration page, and selecting connection parameter attributes. The buddy option is unspecified and the connection data is selected to be new and the system will automatically create a connection data, such as PLC _1_ Send _ DB, and enter the IP address of the buddy, such as 192.168.0.12. The connection is established actively by the partner and the ports of the PLC are reserved for default 2000. The connection type is TCP, the connection ID adopts a default value, and the input and the output of TSEND _ C are configured. TSEND _ C performs a transmission operation when it detects the rising edge of parameter REQ, so every time data is transmitted, it generates a pulse on REQ, and calls system Clock _10Hz (10 times per second) to periodically transmit data for simplicity. The parameter DATA is DATA to be transmitted, and calls the DATA block PlcSendData. The transmit LEN is set to 0 when the parameter DATA employs pure symbol addressing, and is set to the length of the actual transmit DATA when the parameter DATA employs absolute addressing. The communication state parameter donebuty is connected as required. Writing a data receiving program, adding command communication/open user communication/TRCV _ C to the program segment 2, and adopting default for calling the data block name of the option. And configuring communication parameters of TRCV _ C. And selecting TRCV _ C and right key attributes, switching to a configuration page, and selecting connection parameter attributes. Configuring the input and output of TRCV _ C. TRCV _ C initiates reception when detecting that the parameter EN _ R is 1. The parameter DATA is the DATA reception area, calling the DATA block PlcRecvData. The receive LEN is set to 0 when the parameter DATA employs pure symbol addressing, and is set to the length of the actual transmitted DATA when the parameter employs absolute addressing. To determine whether the PLC correctly received the data sent by the LabVIEW, the test can be performed by the following two methods: a. setting the data sending area as a data block which is the same as the data receiving area, namely PlcRecvData, and enabling the PLC to send the received data back to Labview; b. the addition of the MOVE instruction accomplishes this function in a data movement method.
And (2) carrying out hardware configuration of the machine vision system. The illumination source is an important part of the machine vision system, and has an important influence on the acquisition and subsequent processing of images, so that a good illumination source is carefully selected. Of the numerous light sources, three are widely used in machine vision systems, namely, coaxial light sources, zero angle light sources, and bar light sources. The three light sources have advantages and disadvantages, and different light sources need to be selected independently according to actual conditions: coaxial light sources have more uniform illumination than conventional light sources and are therefore particularly useful for detecting high reflectivity objects such as glass; the greatest advantage of the zero-angle light source is that the edge of the object is highlighted, and therefore the zero-angle light source is mainly used for detecting the damage condition of the metal edge. However, the zero-angle light source has a high requirement on the heat dissipation of the light source and generates shadows, so the zero-angle light source needs to be selected according to actual conditions; the bar light source is by the LED granule of hi-lite high density an array that the board was covered up to the electricity closely regular arrangement, and comparatively firm alloy material can be chooseed for use to bar light source shell usually to guarantee extension lamps and lanterns life, bar light source utilizes inside several heat dissipation grooves to ensure the bright stability of illumination simultaneously. Cameras are largely classified into conventional cameras and digital cameras. Conventional camera negatives have a photosensitizer which reacts chemically upon exposure to light when a photograph is taken, i.e., the shutter of the camera is opened, thereby forming an image. The digital camera converts the image into a digital signal, and can utilize the strong computing power of a computer to perform complex operation on a large amount of acquired data. Industrial cameras are mostly used in industrial production, compared with traditional digital cameras, the industrial cameras have high image stability, high transmission capability and high anti-interference capability, and most of industrial cameras on the market are cameras based on CCD or CMOS chips. The CCD is the most common image sensor for machine vision at present, integrates photoelectric conversion, charge storage, charge transfer and signal reading, and is a typical solid imaging device. The outstanding feature of a CCD is that it uses charge as a signal, unlike other devices that use current or voltage as a signal. The CCD forms a charge packet through photoelectric conversion, and then transfers and amplifies an output image signal under the action of a driving pulse. The present embodiment employs a CCD-based industrial camera.
And (3) compiling a Labview program.
1. The video image real-time acquisition module: and right clicking at the Session In wiring position to create an input control, and selecting a proper camera from the input control, wherein the cameras are cameras with different models. And calling IMAQdx OpenCamera.vi to open the camera In the program diagram, wherein the Camera.vi comprises Session In wiring, and creating a data buffer area by using IMAQ Create.vi on the program diagram for storing the acquired image data. And calling IMAQdx Grab.vi in a program diagram to acquire images from the industrial camera in real time, putting the images acquired in real time into a data buffer area which is created previously, and displaying the images acquired in real time on a front panel. The real-time acquisition program is generally a while loop, and the content in the while loop is repeatedly executed when the condition is true, so that the real-time acquisition of the image is realized. The condition structure is nested in while loop, when the condition is true, namely the real-time display is opened, the real-time collected image is displayed in the front panel. When the condition is false, namely the real-time display is closed, the condition structure is empty, and the picture in the front panel is a frame of image acquired at the moment of closing.
2. An image display module: firstly, an Image buffer area is created by using an Image Create control and is used for storing template Image information. The template image information is a pixel matrix of the template image and is obtained after the template image is read through the image display module. Inputting a file path of the template Image to an Image terminal of an IMAQ ReadFile VI; and then an Image Display control is placed on the front panel, the Image Display control is connected to an Image Out terminal of the IMAQ ReadFileVI on the program panel, and the template Image read by the Image Display module is displayed on the front panel.
3. An image acquisition module: the image comparison module is used for automatically acquiring a frame of image of the workpiece from the video image acquired by the video image real-time acquisition module when the workpiece reaches the designated position so as to perform subsequent image comparison operation, and when the image acquisition module acquires the image, the image acquired in real time displayed on the front panel is frozen into the image acquired by the image acquisition module. Creating a relative path using the formatted date/time string control and the connection string control; obtaining a base path by utilizing the split path and the created path, and obtaining a final file path through the base path and the name; the acquired image and File path are input into an IMAQWrite File 2 VI. The image format collected by the image collecting module comprises BMP, JPEG and PNG.
4. A template manufacturing module: creating a file input path by using the formatted date/time string control, the connection string control and the creation path; selecting a frame of image from a real-time image displayed on a front panel by a user through an IMAQ Extract control in combination with a calling node, selecting an interested area in the image and making the image into a template image, wherein the template image is a gray image; the processed template image is written into a template image folder (ImageTemplate) using IMAQ Write File 2VI, and the format of storage may be selected.
5. An image matching module: firstly, reading a template image from a memory by using an IMAQ Readfile function; selecting an interested area of an image acquired by an image acquisition module through IMAQ Extract, and converting the image acquired by the image acquisition module into a gray image through IMAQExtract Single Colorplane VI; inputting the processed collected Image into an Image In port of an IMAQ Find Pattern 4VI, inputting the Template Image into a Template port only, and performing Template matching by using a gray pyramid method; when the matching result is true, namely the matching degree meets the setting of a user, displaying 'found' in the output result; when the matching result is false, i.e., the degree of matching does not satisfy the user's set value, "none" will be displayed in the output result.
6. The system front panel is arranged: the system front panel is based on an output device (namely a liquid crystal display screen), and the front panel is set as a user operation interface and a display interface according to the functions of the system; the user operation interface is provided with five buttons according to the functions of the system, namely, acquiring pictures, template making, image matching, real-time display opening/closing and quitting, and the real-time acquired images are displayed in the middle of the user operation interface in a window mode, so that a user can observe the condition of a product at any time and perform corresponding operation. Below the real-time acquired image, the initialization parameters of the system are the template path, the camera name, and the similarity setting. The display interface comprises template image display and result display, the template image display is used for displaying the loaded template image, the template image is changed by directly changing the template path, and the result display is used for displaying the detection result and the matching degree of the image.
And (4) debugging the system. First, a Template Image is selected from a Template path folder (Image Template), and if there is no Template Image, the Template Image is collected and created on-line, and the created Template Image is stored in a Template Image folder (Image Template). If the template changes during the inspection process, the template path can be changed directly without stopping the operation of the system. The corresponding industrial camera is then selected, with cam0 by default. The user sets the similarity according to the self requirement, the higher the set value is, the higher the matching precision is, and the maximum value set by the similarity is 1000, namely complete matching is realized. The set value of the similarity can also be changed in real time according to the requirement in the detection process. After the initialization parameters before operation are set, the program can be operated by clicking the operation button at the upper left corner of the software. After the program runs, inquiring whether a user opens the camera or not, and acquiring a video image by opening the camera; if the real-time display is selected to be opened, the image acquired in real time can be displayed in the window, and if the real-time display is selected to be closed, a frame of image acquired at the moment of closing can be displayed in the window. When the product to be detected reaches the designated position, the PLC sends a corresponding signal to the Labview, and after the Lavbview receives the corresponding signal, the image acquisition program is called to acquire the image of the product to be detected. The image matching module automatically compares and collects the image of the product to be detected with the template image and outputs a corresponding result, thereby realizing the automatic detection of the product defects.
FIG. 2 is a diagram of the hardware components of the present invention.