A method, system and storage medium for automatically detecting a switch gap
Through template matching and grayscale integral projection algorithm, the problem of low accuracy and manual demarcation of reference lines in the notch detection of the switch machine is solved, and high accuracy and automated notch detection is achieved, which is suitable for faults of the switch machine in complex environments. diagnosis.
Patent Information
- Application Number
- CN202010453478.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-25
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-05-25
AI Technical Summary
The existing gap detection methods for switch machine have problems such as low measurement accuracy, high false alarm rate, no on-site adjustment instructions, complex maintenance of monitoring equipment and manual demarcation of reference lines, which cannot meet the railway department's fault maintenance of switch machine equipment Latest requirements.
The template matching algorithm and grayscale integral projection algorithm are used to detect the gap between the switch machine, and the gap size value is calculated through template matching and grayscale integral projection, so as to automatically identify the baseline, reduce manual intervention and improve detection accuracy.
It improves the accuracy and robustness of the detection results, avoids the influence of light changes and noise, automatically recognizes the baseline, reduces labor costs and work efficiency, and meets the accurate detection needs of equipment fault maintenance of switch machine equipment.
Smart Images

Figure CN111754460B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of switch gap detection, and in particular to a switch gap automatic detection method, system and storage medium. Background Art
[0002] In recent years, my country's transportation industry has developed rapidly, a large number of passenger dedicated lines have been built, and the transportation network has become increasingly complex, which has put forward high standards and strict requirements on the safety and reliability of train signal equipment. As an important infrastructure of the traffic signal station interlocking system, turnouts and their conversion equipment are a key step to ensure the safety of train operation, and at the same time, they are the weak link in rail transportation. The switch is the actuator of the turnout control system, which is used to realize the conversion, locking and position detection of the turnout. In the turnout conversion device, the turnout gap is responsible for checking the close fit of the turnout point rail, ensuring that the close fit value of the point rail and the base rail meets the line driving requirements and realizes the safe passage of the train.
[0003] The continuous increase in train speed and the high-density driving sections have caused the impact of train wheels on the turnouts to become greater and greater, resulting in the loosening and displacement of various components of the turnouts. This is manifested in the inability of the inspection column inside the switch machine to fall and the inability of the turnout to lock, which greatly endangers driving safety. In the past, major safety accidents such as derailment, derailment, and rear-end collisions during train operation were often caused by turnout failures. Therefore, timely detection and handling of turnout failures are key steps to ensure the safe operation of trains. In the past, regular manual inspection of turnouts could no longer meet the normal maintenance requirements of switch machine equipment. The reason is that the internal mechanical structure of the switch machine is very complex, which makes manual maintenance difficult; manual inspections face great resistance due to environmental factors such as high temperature and severe oil pollution inside the equipment, and strong vibration of various parts when the train passes through the switch machine equipment. Various factors have led to the inability of manual inspections to achieve the purpose of detection, thereby failing to ensure the normal operation of the switch machine equipment, and the safety hazards cannot be effectively solved.
[0004] In order to ensure the accuracy and real-time detection of switch gaps, it is particularly important to vigorously develop intelligent detection technology for switch gaps. At present, some online detection technologies have been developed in China for switch gap detection. The present invention provides an automatic detection method for switch gaps, which can accurately and intuitively detect the gap value by analyzing real-time pictures, improve work efficiency, and reduce labor.
[0005] At present, there are two main methods for online detection of switch gaps. One is to perform automatic detection directly through gap sensors and mechanical operations. The gap sensor determines whether the detection column falls into the indicating rod. If the detection column falls into the indicating rod, the system alarms through mechanical operations such as compression springs, thereby achieving the purpose of gap monitoring; the other is to perform automatic detection by analyzing the gap image based on image recognition and processing technology, such as using basic edge extraction operators to identify the gap edge, and calculating the distance between the gap edge line and the initial position to achieve the purpose of calculating the gap value.
[0006] The method of directly detecting the switch gap through the gap sensor and mechanical operation has changed the original traditional naked eye detection method. It can directly monitor the sampling, set the alarm value through various processes such as instrument measurement, thereby eliminating the uncertainty of artificially set detection standards, and is not affected by train vibration and the oily and humid environment in the switch machine. The detection accuracy is improved, and the method is low-cost, stable and reliable. However, this method can only monitor qualitatively, and cannot quantitatively detect the size of the gap value, which cannot meet the accuracy requirements of gap detection, and is easily affected by mechanical vibration and wear.
[0007] The commonly used detection methods for switch machine gaps in China are mainly various sensors combined with mechanical operations for detection. They have problems such as low measurement accuracy, high false alarm rate, no on-site adjustment instructions, and complex maintenance of the monitoring equipment to varying degrees, which cannot meet the latest requirements of the railway department for switch machine equipment fault inspection and maintenance. In order to solve the above problems, a gap detection method based on image processing technology has emerged, but there are still some problems.
[0008] The gap detection algorithm used in the real-time online detection of switch machines based on image processing technology is prone to the following two problems: first, due to the weak stability of the algorithm, the target edge will be greatly blurred when the lighting changes, causing errors in the recognition results or even recognition failures; second, the existing gap detection algorithm can only automatically identify the edge line corresponding to the moving end of the gap, while the baseline corresponding to the fixed end of the gap needs to be manually drawn. According to the actual situation on site, there are too many switch machines in each power section. When the system is initially configured, the fixed end of the gap of each switch machine needs to be manually drawn and the baseline calibrated. This is a very tedious task, which consumes a lot of manpower costs and has low work efficiency. Summary of the invention
[0009] The present invention proposes a method, system and storage medium for automatically detecting the gap of a switch machine, and applies the template matching algorithm and the grayscale integral projection algorithm to real-time detection of the gap, which greatly exerts the advantages of the template matching algorithm and the grayscale integral projection method in fault diagnosis of the switch machine. The present invention utilizes advanced image processing technology, improves the existing technical solutions, improves the deficiencies of the existing technology in detecting the gap of the switch machine, and improves the accuracy of the detection results.
[0010] A first aspect of the present invention provides a method for automatically detecting a switch gap, comprising the following steps:
[0011] Collect switch machine gap images;
[0012] Read pre-created template information;
[0013] Perform template matching between the acquired image and the pre-created template;
[0014] Generate matching blocks;
[0015] Perform image preprocessing on the obtained matching blocks;
[0016] Perform grayscale integral projection on the preprocessed matching block and calculate the average grayscale value;
[0017] The gray value mutation points are extracted according to the average gray value to calculate the gap size value.
[0018] Furthermore, before the step of acquiring the switch machine gap image, the step of acquiring a standard image and creating a template is also included.
[0019] Furthermore, the steps of acquiring a standard image and creating a template include:
[0020] An image capable of showing the gap between the fixed end and the moving end of the gap is collected as a standard image;
[0021] Creating three rectangular regions of interest, i.e., rectangular ROI regions, for the standard image, which are respectively recorded as a template region, a reference region, and a region to be detected;
[0022] Gray-scale processing is performed on the standard image to obtain a grayscale image, and corresponding template area grayscale image, reference area grayscale image and to-be-detected area grayscale image are obtained;
[0023] The template area grayscale image, the reference area grayscale image and the to-be-detected area grayscale image are saved as template information, and the template area grayscale image is recorded as template image I m .
[0024] Furthermore, the step of performing template matching between the captured image and the pre-created template includes:
[0025] Read the template image I in the template information m ;
[0026] Grayscale the acquired image to obtain the image I to be matched;
[0027] The image pyramid search strategy is used to search for the image to be matched I and the template image I m The image area with the greatest similarity is used as the template area matching block.
[0028] Furthermore, the similarity r is calculated by the following formula:
[0029]
[0030] Among them, (x, y) represents the coordinates of a pixel point, f n is the template image I m The gray value of each point in (x, y), f is the template image I m The grayscale mean square value of (x,y), I n I is the image to be matched g 'The gray value of each point in (x, y), I is the image to be matched I g '(x,y) grayscale mean square value, N is the total number of pixels in image I'(x,y);
[0031] Set the threshold σ for successful template matching. When r≥σ, the match is considered successful, otherwise continue searching for matches.
[0032] The image I' corresponding to the maximum value of r is selected as the template area matching block.
[0033] Furthermore, the step of generating a matching block includes:
[0034] The translation transformation matrix G is used to perform translation transformation on the grayscale image of the reference area and the grayscale image of the area to be detected, respectively, to obtain a matching block of the reference area and a matching block of the area to be detected;
[0035] Among them, the translation transformation matrix G is:
[0036]
[0037] (x1, y1) and (x2, y2) represent the template image I m The coordinates of the center pixel of the block matching the template area.
[0038] Furthermore, the performing image preprocessing on the obtained matching block includes:
[0039] Perform Gaussian filtering on the matching blocks in the reference area and the matching blocks in the area to be detected to suppress noise in the image and smooth the image;
[0040] Then perform grayscale closing operation on the image to fill the holes that still exist on the edge of the image after Gaussian filtering, and perform a second smoothing process;
[0041] The processed reference area matching block and the to-be-detected area matching block are denoted as T c (x,y) and T d (x,y).
[0042] Furthermore, the step of performing grayscale integral projection on the preprocessed matching block to calculate the average grayscale value includes:
[0043] Calculate T c (x,y) and T d The average grayscale value of pixels in the vertical direction (x,y) is V(y):
[0044]
[0045] Where I(x,y) is the grayscale value of the pixel in the image at (x,y), [x1,x2] is the required area of the image in the horizontal direction, and [y1,y2] is the required area of the image in the vertical direction.
[0046] Furthermore, the step of extracting the gray value mutation point according to the average gray value to calculate the gap size value includes:
[0047] The gray value mutation point is extracted by using the offset subtraction method for the average gray value, and the corresponding gap reference line and the line to be detected are extracted;
[0048] The gap size value is calculated according to the number of pixel points between the gap reference line and the line to be detected.
[0049] Furthermore, the method of offset subtraction includes:
[0050] Construct a one-dimensional array M with n elements, where each element corresponds to the average grayscale value of each column in the vertical direction, and add a zero element at the beginning and end of the array M to form arrays M1 and M2 with n+1 elements.
[0051] Subtract the corresponding elements of arrays M1 and M2 to obtain a one-dimensional difference array with n+1 elements, and normalize the elements of the arrays to obtain a normalized array M3;
[0052] Set the difference ratio threshold A, compare the elements in array M3 with the value of A one by one, select the largest element B in array M3, divide the elements in array M3 by A, and obtain a new normalized array M4;
[0053] Each element in the array M4 is rounded down to obtain the array M5, and the required element can be obtained, that is, the column coordinate values of the baseline and the line to be detected are found.
[0054] A second aspect of the present invention provides a switch machine gap automatic detection system, the system comprising:
[0055] memory and one or more processors;
[0056] The memory is communicatively connected to the one or more processors, and the memory stores instructions that can be executed by the one or more processors. The instructions are executed by the one or more processors so that the one or more processors are used to execute the method as described above.
[0057] A third aspect of the present invention provides a computer-readable storage medium having computer-executable instructions stored thereon, which, when executed by a computing device, can be operated to perform the method as described above.
[0058] In summary, the present invention provides a method for automatically detecting the gap of a switch machine, which accurately and intuitively detects the gap value by analyzing the real-time shot picture or video of the gap of the switch machine. The beneficial technical effects of the present invention are mainly the following two points:
[0059] First, the use of template matching algorithm and grayscale integral projection algorithm for switch gap detection is an intelligent detection method. Practical tests show that the algorithm used in the present invention is very suitable for switch gap detection. Changing the light intensity during image acquisition will not affect the detection results. The noise in the captured image has no effect on the extraction of the gap detection line. Therefore, the algorithm is more robust.
[0060] Second, starting from the algorithm itself, the innovation of this algorithm is that the baseline of the gap detection is automatically identified and does not need to be manually drawn. Combined with the actual situation on site, the present invention solves the problem of manually drawing the baselines of the gap fixed ends of multiple switch machines, and avoids the calibration work that must be done due to the inaccurate manual baseline drawing, which greatly improves the actual work efficiency and the intelligent level of gap detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A schematic diagram of a flow chart of a method for automatically detecting a notch of a switch machine according to an embodiment of the present invention;
[0062] Figure 2 A schematic diagram of a ROI region according to an embodiment of the present invention;
[0063] Figure 3 A schematic diagram of a template matching process according to an embodiment of the present invention;
[0064] Figure 4 It is a schematic diagram of the notch structure of a ZDJ-9 type switch machine according to a specific embodiment of the present invention;
[0065] Figure 5 (a) is a schematic diagram of creating a ROI region according to a specific embodiment of the present invention. Figure 5 (b) is a schematic diagram of the generated template image;
[0066] Figure 6 A schematic diagram of a matching block of a region to be detected according to a specific embodiment of the present invention;
[0067] Figure 7 A schematic diagram of gray value segmentation results according to a specific embodiment of the present invention;
[0068] Figure 8 It is a schematic diagram of the final detection result of a specific embodiment of the present invention;
[0069] Fig. 9 (a)-(f) are schematic diagrams of algorithm performance verification experimental results for different gap values. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, the description of well-known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention.
[0071] The first aspect of the present invention provides a method for automatically detecting a switch gap. Due to the obvious difference in grayscale values of switch gap images, the strong robustness of the grayscale integral projection algorithm, and the high search efficiency of the template matching algorithm, this method is an innovative application in gap detection. The method can automatically detect the switch gap value with high detection accuracy and good stability.
[0072] The algorithm flow chart of automatic detection of switch gap using this method is as follows: Figure 1 As shown, the specific steps are as follows:
[0073] Step 1: Collect images, create ROI areas, and create templates.
[0074] When the switch gap detection system is configured, start the corresponding gap image acquisition and upload it to the indoor host in real time. Collect an image that can show the gap between the fixed end and the mobile end of the gap as a standard image for use when creating a template. Create three rectangular regions of interest, namely rectangular ROI areas, for the standard image, which are respectively recorded as the template area, the reference area, and the area to be detected, to locate the image area of interest and perform template matching, such as Figure 2The position of the ROI region in the image can be determined by the coordinates of the upper left corner and the lower right corner of the three rectangular ROI regions. The standard image is grayed to obtain a grayscale image I g , in grayscale image I g The coordinates of the upper left corner and the lower right corner of the three ROI regions are obtained, and the corresponding template area grayscale image, reference area grayscale image, and to-be-detected area grayscale image are obtained for template matching. The template area grayscale image is referred to as template image I m At this point, the template creation is complete. Since the template information and the matching process are independent of each other during use, the template information needs to be saved and re-read for search and matching during template matching to separate template creation from template matching. A template needs to be created during the first gap detection, and the subsequent gap detection can directly read the template information for template matching.
[0075] Step 2: Read the template, perform template matching on the image to be matched, and obtain the reference area matching block and the detection area matching block.
[0076] The template data is read and the collected original image is grayed to obtain the image to be matched I. The template matching algorithm is used to automatically find the gap area to be detected in the image to be matched so as to extract the gap edge line in a small area, thereby solving the problem that the gap edge line cannot be directly extracted from the image to be matched I or the extraction is difficult, thereby improving the effectiveness and efficiency of detection. Figure 3 This is the template matching flow chart. Read the template image I m , using the image pyramid search strategy to search for the image to be matched I and the template image I m The image area with the greatest similarity. The image pyramid hierarchical search strategy is to accelerate the search from coarse to fine to find image I' at different scales. First, a K-layer pyramid structure is established for the image I to be matched. The bottom layer is the image I to be matched. As the number of layers increases, the resolution of the image decreases. To determine the matching position, the search image and the template image are matched at the top layer of the pyramid, and the normalized correlation coefficient r is calculated. The matching results are mapped to the next layer, and the search for matching continues in the area with a larger r value. This process continues until the matching position is found on the search image and template image with the highest resolution. The hierarchical search using the image pyramid can efficiently complete the search and reduce the amount of calculation because the search area of each layer is very small.
[0077] During the search process, the image I and the current template image I m The image in the same area is denoted as I'. Image I' and template image I m The number of pixels is the same as that of the template image I. mThe area with the greatest similarity needs to use the normalized correlation coefficient r to compare image I' with the template image I m The larger the value of r, the more similar the image I' is to the template image I m The higher the similarity, the better. Considering the equation for calculating the normalized correlation coefficient r is as follows:
[0078]
[0079] Among them, (x, y) represents the coordinates of a pixel point, f n is the template image I m The gray value of each point in (x, y), f is the template image I m The grayscale mean square value of (x,y), I n For image I g 'The gray value of each point in (x, y), I is the image I g '(x,y), N is the total number of pixels in the image I'(x,y).
[0080] Set the threshold σ that can make the template match successful. When r≥σ, the match is considered successful, otherwise continue searching for matches. Take the image I' corresponding to the maximum value of r, which is the template area matching block to be found. The acquisition of the template area matching block indicates that the image to be matched contains the gap information to be detected. Find the template image I m The relationship between the matching block and the template area is expressed by the translation transformation matrix G as follows:
[0081]
[0082] Among them, (x1, y1) and (x2, y2) represent the template image I m The coordinates of the center pixel of the block matching the template area.
[0083] In order to reduce the algorithm running time, it is no longer necessary to perform pyramid search matching on the reference area and the area to be detected. Instead, the translation transformation matrix G is used to perform translation transformation on the reference area grayscale image and the grayscale image of the area to be detected to obtain the reference area matching block and the matching block of the area to be detected. The relationship between the reference area matching block and the reference area grayscale image is calculated as:
[0084]
[0085] Among them, (x c ,y c ) is the coordinate of the center pixel of the grayscale image of the reference area, (x p ,y p ) is the coordinate of the center pixel of the matching block in the reference area, and G is the translation transformation matrix.
[0086] Obtain the coordinates of the center pixel of the reference area matching block (x p ,y p ), according to the reference area ROI size, the reference area matching block can be found in the image to be matched. The central pixel coordinates of the grayscale image of the area to be detected are obtained, and the matching block of the area to be detected can be obtained in the same way. The acquisition of the reference area matching block and the matching block of the area to be detected facilitates the extraction of the baseline and the line to be detected in the specified area, thereby calculating the gap value. At this point, the template matching of the template area, the reference area, and the area to be detected is completed.
[0087] Step 3: Perform image preprocessing operations such as smoothing and noise removal on the obtained reference area matching blocks and the to-be-detected area matching blocks.
[0088] When collecting images, the image quality is inevitably deteriorated due to the influence of image acquisition equipment or environmental factors. The quality of the image directly affects the effectiveness of the detection algorithm. Therefore, the image needs to be preprocessed before the algorithm is studied. Gaussian filtering is performed on the reference area matching block and the matching block in the area to be detected to suppress the noise in the image and smooth the image. The image is further closed by grayscale value operation to fill the holes that still exist on the edge of the image after Gaussian filtering. A second smoothing process is performed. The processed reference area matching block and the matching block in the area to be detected are respectively recorded as T c (x,y) and T d (x, y). After image preprocessing, redundant information in the image is removed, making it easier to extract the baseline in the reference area matching block and the line to be detected in the detection area matching block.
[0089] Step 4: Perform grayscale integral projection on the reference area matching block and the detection area matching block to find the grayscale mutation point in the image.
[0090] Use the grayscale integral projection algorithm to obtain image T c (x,y) and T d The average gray value data of (x, y) is convenient for analyzing and extracting the baseline and the line to be detected. c (x,y) and T d There is a grayscale mutation in the column direction of (x, y). By calculating the grayscale integral projection function in the column direction, we can intuitively obtain the position of the grayscale mutation in the image, that is, the position of the baseline and the line to be detected. Therefore, for T c (x,y) and T d (x, y) are projected in the vertical direction to obtain the average grayscale value of the pixels in the vertical direction. The positions of the baseline and the line to be detected can be found by selecting according to the size of the average grayscale value of each column.
[0091] Calculate T c (x,y) and T dThe average grayscale value of pixels in the vertical direction (x,y) is V(y):
[0092]
[0093] Where I(x,y) is the grayscale value of the pixel in the image at (x,y), [x1,x2] is the required area of the image in the horizontal direction, and [y1,y2] is the required area of the image in the vertical direction.
[0094] By analyzing the image to be processed, we know that the image T c (x,y) and T d The grayscale value difference of (x, y) in the horizontal direction is small, which has little impact on finding grayscale mutation points, while the grayscale value difference in the vertical direction is large, which can be used as a basis for finding the position of the baseline and the line to be detected. The grayscale integral projection method has a better effect on the recognition of the edge line of the gap image and can achieve accurate positioning of the gap.
[0095] Step 5: The average gray value data obtained is subjected to offset subtraction to extract mutation points, thereby extracting the gap baseline and the line to be detected.
[0096] After getting the image T c (x,y) and T d (x, y) After calculating the average gray value of each column in the vertical direction, the maximum value is selected to obtain the corresponding edge line in the vertical direction. However, selecting the edge line corresponding to the maximum value of the average gray value may result in error in edge line extraction. To ensure the accuracy of edge line extraction, the average gray value is processed by extracting mutation points by dislocation subtraction:
[0097] 1. Construct a one-dimensional array M with n elements, where each element corresponds to the average grayscale value of each column in the vertical direction. Add a zero element at the beginning and end of the array M to form arrays M1 and M2 with n+1 elements.
[0098] 2. Subtract the corresponding elements of arrays M1 and M2 to obtain a one-dimensional difference array with n+1 elements, and normalize each element of the array to obtain a normalized array M3.
[0099] 3. Set the difference ratio threshold A, compare the elements in array M3 with the A value one by one, filter out the largest element B in array M3, divide the elements in array M3 by A, and obtain a new normalized array M4.
[0100] 4. Each element in array M4 is rounded down to get array M5, and the required element can be obtained, that is, the column coordinate values of the baseline and the line to be detected are found.
[0101] By subtracting the column coordinate values of the baseline and the line to be detected, the number of pixels between the two lines can be obtained. The conversion relationship between pixel units and scale units obtained through camera calibration and image size measurement experiments can be used to calculate the size of the gap in millimeters to achieve automatic detection of the gap value.
[0102] The baseline and the line to be detected are extracted by extracting mutation points by staggered subtraction. Even if the average grayscale value of each column of the image is very small, after the above data processing, the gap between the average grayscale values of each column can be magnified, so as to accurately extract the baseline and the line to be detected, avoiding the possible misjudgment of directly extracting the maximum value of the average grayscale value in the vertical direction as the edge line, thereby improving the accuracy of edge detection.
[0103] The present invention is further described below with reference to a specific embodiment.
[0104] The gap pictures taken inside the ZDJ-9 switch machine were selected for the experiment. The gap pictures in the positioning state are as follows: Figure 4 As shown in the figure, the resolution of the image is 720 × 576. This image is dark as a whole and contains noise. The required ROI area is located by the template matching algorithm. Since the gray value of the image has obvious differences at the edge, gray integral projection can be performed to extract the gap reference line and the line to be detected in the ROI area, and calculate the distance between the two lines to verify the effectiveness and robustness of the algorithm.
[0105] Step 1: After the switch gap detection system is configured, start the corresponding gap image acquisition and upload it to the indoor host in real time. Collect an image that can show the gap between the fixed end and the mobile end of the gap as the standard image, create three rectangular ROI areas for the standard image, record them as the template area, reference area, and area to be detected, and get the image in the corresponding area as follows Figure 5 As shown in (a), the largest rectangular area represents the template area with a pixel size of 120×120, which is used to select the size of the template image when the template is matched; the rectangular area on the left represents the reference area with a pixel size of 85×100, which is used to define the size of the image to be found when searching for the matching block in the reference area; the rectangular area on the right represents the area to be detected with a pixel size of 100×272, which is used to define the size of the image to be found when searching for the matching block in the area to be detected. Figure 5 (b) is the grayscale image corresponding to the obtained template area, that is, the template image I m , save the template information for use in template matching.
[0106] Step 2: Read the template image I m , the collected image to be detected is recorded as I o , using the pyramid search algorithm and similarity measurement method to detect the image I oPerform template matching to find the image to be detected I o The template image I m Find the matching block I m '. When performing pyramid search, the number of layered processing is set to 2. For the threshold σ for successful template matching, when the σ value is set to less than 0.5, matching errors will occur. When σ≥0.8, correct matching can be achieved. Therefore, σ=0.8 is set. After the template matching is successful, the matching block I is obtained. m 'With template image I m The translation transformation matrix between The central pixel coordinates (410, 153.5) of the reference area matching block can be obtained from the central pixel coordinates (466, 107.5) of the grayscale image of the reference area; the central pixel coordinates (399, 286) of the reference area matching block can be obtained from the central pixel coordinates (455, 240) of the grayscale image of the area to be detected. Thus, the reference area matching block and the area to be detected matching block can be found in the image to be matched.
[0107] Step 3: Match block I with the area to be detected d Take the image as an example to preprocess the image. d Gaussian filtering is performed with a filter order of 5, and then grayscale value closing operation is performed. The size of the filter template used is 11×1px. The matching block I of the area to be detected obtained after image preprocessing d 'like Figure 6 shown.
[0108] Step 4: Match block I to the detection area d Grayscale integral projection is performed. Since the detection area matches block I d The pixel size is 100×272, so 272 average gray value data can be obtained in the vertical direction.
[0109] Step 5: The 272 data obtained above are subjected to the method of extracting mutation points by dislocation subtraction to extract the line to be detected. Among them, the one-dimensional array M is 272 average gray value data, array M1 is a new array formed by adding zero elements before the first element of array M, and array M2 is a new array formed by adding zero elements after the last element of array M. Subtract the corresponding elements of arrays M1 and M2 to obtain a one-dimensional difference array with 273 elements, and normalize the elements of the array to obtain a normalized array M3. Set the difference ratio threshold A=0.2, compare the elements in array M3 with the A value one by one, screen out the largest element B=0.440118 in array M3, divide the elements in array M3 by A=0.2, and obtain a new normalized array M4. Round down each element in array M4 to obtain array M5, and it can be obtained that the sequence number of the required element in the table is 185, that is, the column coordinates of the line to be detected are found. The data obtained by array M5 is the final data processing result, and the corresponding gray value segmentation result is as follows: Figure 7 As shown in the figure, it can be seen intuitively that there are only three areas, black, gray, and white, which correspond one-to-one to 0.0, 1.0, and 2.0 in the data processing results, verifying the correctness of the gray value segmentation result.
[0110] The same method as extracting the line to be detected is used to extract the mutation point by offset subtraction to obtain the column coordinate value of the baseline, which is 28. It is calculated that there are 157 pixels between the baseline and the line to be detected. The camera calibration and image size measurement experiment using the checkerboard target shows that 1 mm corresponds to 0.06 pixels. The gap value in millimeters is calculated to be 9.42 mm, realizing automatic detection of the gap value. The final detection result is as follows: Figure 8 shown.
[0111] In order to further verify the performance of the algorithm, the gaps under different working conditions were tested, and the test results were as follows: Fig. 9 (a)-(f) are shown. It can be seen from the figure that within the limited variation range of the gap size, the method used in the present invention can accurately identify the reference line and the line to be detected, and the error between the gap value calculated by the algorithm and the actual gap value is less than 0.1mm. Therefore, the algorithm used in the present invention has a good detection function for the switch gap and meets the safety requirements of rail driving.
[0112] A second aspect of the present invention provides a switch machine gap automatic detection system, the system comprising:
[0113] memory and one or more processors;
[0114] The memory is communicatively connected to the one or more processors, and the memory stores instructions that can be executed by the one or more processors. The instructions are executed by the one or more processors so that the one or more processors are used to execute the method as described above.
[0115] A third aspect of the present invention provides a computer-readable storage medium having computer-executable instructions stored thereon, which, when executed by a computing device, can be operated to perform the method as described above.
[0116] In summary, the present invention provides an automatic detection method, system and storage medium for the gap of a switch machine. The method applies the template matching algorithm and the grayscale integral projection algorithm to the real-time detection of the gap, which greatly gives play to the advantages of the template matching algorithm and the grayscale integral projection method in the fault diagnosis of the switch machine. The gap value is accurately and intuitively detected by analyzing the real-time shot of the switch machine gap picture or video. The method uses the template matching algorithm and the grayscale integral projection algorithm for the detection of the gap of the switch machine, which is an intelligent detection method. It can be seen from the actual test that the algorithm used in the present invention is suitable for the detection of the gap of the switch machine. Changing the light intensity during the image acquisition process will not affect the detection result. The noise in the acquired image has no effect on the extraction of the gap detection line. Therefore, the robustness of the algorithm is strong. Starting from the algorithm itself, the innovation of the algorithm is that the baseline of the gap detection adopts an automatic recognition method and does not need to be manually delineated. Combined with the actual situation on site, the present invention solves the problem of manually delineating the baselines of the gap fixed ends of multiple switch machines, and avoids the calibration work that must be done due to the inaccurate manual delineation of the baseline, which greatly improves the actual work efficiency and improves the intelligence level of the gap detection.
[0117] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, and do not constitute a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modifications that fall within the scope and boundaries of the appended claims, or the equivalent forms of such scope and boundaries.
Claims
1. A method for automatically detecting a switch gap, characterized in that: The steps include: Collect switch machine gap images; Read pre-created template information; Perform template matching between the acquired image and the pre-created template; Generate a matching block; the matching block includes a template area matching block, a reference area matching block, and a to-be-detected area matching block; the acquisition of the template area matching block indicates that the to-be-matched image contains the gap information to be detected; Perform image preprocessing on the obtained matching blocks; Perform grayscale integral projection on the reference area matching block and the to-be-detected area matching block, and calculate the average grayscale value; The gray value mutation points are extracted according to the average gray value to calculate the gap size value; Before the step of collecting the switch machine gap image, the method further includes the steps of collecting a standard image and creating a template; The steps of acquiring a standard image and creating a template include: An image capable of showing the gap between the fixed end and the moving end of the gap is collected as a standard image; Three rectangular regions of interest, i.e., rectangular ROI regions, are created for the standard image, which are respectively recorded as a template region, a reference region, and a region to be detected; the reference region is a region including a baseline; the region to be detected is a region including a line to be detected; Gray-scale processing is performed on the standard image to obtain a grayscale image, and corresponding template area grayscale image, reference area grayscale image and to-be-detected area grayscale image are obtained; The template area grayscale image, the reference area grayscale image and the to-be-detected area grayscale image are saved as template information, and the template area grayscale image is recorded as template image I m The step of extracting gray value mutation points according to the average gray value to calculate the gap size value includes: extracting gray value mutation points by using the method of offset subtraction on the average gray value, extracting the baseline in the reference area matching block, and extracting the line to be detected in the matching block of the area to be detected; The gap size value is calculated according to the number of pixels between the gap reference line and the line to be detected; the method of offset subtraction includes: Construct a one-dimensional array M with n elements, where each element corresponds to the average grayscale value of each column in the vertical direction, and add a zero element at the beginning and end of the array M to form arrays M1 and M2 with n+1 elements. Subtract the corresponding elements of arrays M1 and M2 to obtain a one-dimensional difference array with n+1 elements, and normalize the elements of the arrays to obtain a normalized array M3; Set the difference ratio threshold A, compare the elements in array M3 with the value of A one by one, select the largest element B in array M3, divide the elements in array M3 by A, and obtain a new normalized array M4; Each element in the array M4 is rounded down to get the array M5, and the required element can be obtained, that is, the column coordinate values of the baseline and the line to be detected are found; Subtract the column coordinate values of the baseline and the line to be detected to obtain the number of pixels between the two lines.
2. The automatic detection method for switch machine gap according to claim 1 is characterized in that: The step of performing template matching between the acquired image and the pre-created template comprises: Read the template image in the template information; Grayscale the acquired image to obtain the image to be matched; The image pyramid search strategy is used to search the image area with the greatest similarity to the template image in the image to be matched as the template area matching block.
3. The automatic detection method for switch machine gap according to claim 2 is characterized in that: in, The similarity r is calculated by the following formula: Among them, (x, y) represents the coordinates of a pixel point, f n is the gray value of each point in the template image, is the grayscale mean square value of the template image, I n is the gray value of each point in the image to be matched, is the grayscale mean square value of the image to be matched; Set the threshold σ for successful template matching. When r≥σ, the match is considered successful, otherwise continue searching for matches. The image corresponding to the maximum value of r is selected as the template area matching block.
4. The automatic detection method for switch machine gap according to claim 3 is characterized in that: The step of generating a matching block comprises: The translation transformation matrix G is used to perform translation transformation on the grayscale image of the reference area and the grayscale image of the area to be detected, respectively, to obtain a matching block of the reference area and a matching block of the area to be detected; Among them, the translation transformation matrix G is: (x1, y1) and (x2, y2) represent the coordinates of the center pixel of the template image Im and the matching block of the template area respectively.
5. The automatic detection method for switch machine gap according to claim 4 is characterized in that: The image preprocessing of the obtained reference area matching block and the to-be-detected area matching block comprises: Perform Gaussian filtering on the matching blocks in the reference area and the matching blocks in the area to be detected to suppress noise in the image and smooth the image; Then perform grayscale closing operation on the image to fill the holes that still exist on the edge of the image after Gaussian filtering, and perform a second smoothing process; The processed reference area matching block and the to-be-detected area matching block are denoted as T c (x,y) and T d (x,y).
6. The automatic detection method for switch machine gap according to claim 5 is characterized in that: The steps of performing grayscale integral projection on the preprocessed reference area matching block and the to-be-detected area matching block and calculating the average grayscale value include: Calculate T c (x,y) and T d The average grayscale value of pixels in the vertical direction (x,y) is V(y): Among them I * (x, y) is the grayscale value of the pixel in the image at (x, y), [x1, x2] is the required area of the image in the horizontal direction, and [y1, y2] is the required area of the image in the vertical direction.
7. A switch machine gap automatic detection system, characterized in that: The system includes: memory and one or more processors; The memory is communicatively connected to the one or more processors, and the memory stores instructions executable by the one or more processors, and the instructions are executed by the one or more processors so that the one or more processors are used to execute the method described in any one of claims 1-6.
8. A computer-readable storage medium having computer-executable instructions stored thereon, which, when executed by a computing device, are operable to perform the method of any one of claims 1 to 6.
