A catenary slot measurement method and device based on machine vision technology
By employing a contact wire channel measurement method based on machine vision technology, and utilizing the YOLOv5-LiteSE model and adaptive median filtering algorithm, rapid automatic focusing and high-precision measurement of contact wire channels within tunnels were achieved, solving the problem that existing devices cannot achieve rapid automatic focusing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA RAILWAY ELECTRIFICATION ENGINEERING GROUP CO LTD
- Filing Date
- 2022-12-30
- Publication Date
- 2026-04-17
AI Technical Summary
Existing machine vision measurement devices cannot quickly complete automatic focusing inside tunnels, resulting in low measurement accuracy of contact wire channels.
A method for measuring contact wire channels based on machine vision technology is adopted, including automatic focusing of the measuring device, acquisition of contact wire channel images, image preprocessing and detection modules. The YOLOv5-LiteSE recognition model is used to mark the ROI region, perform grayscale processing and adaptive median filtering, obtain the straight line equation by Hough transform, and calculate parallelism and size.
It enables rapid automatic focusing of the contact wire channel inside the tunnel, improves measurement accuracy, and solves the problem that existing devices cannot achieve rapid automatic focusing.
Smart Images

Figure CN116091780B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of contact wire channel measurement technology, and particularly relates to a contact wire channel measurement method and device based on machine vision technology. Background Technology
[0002] The overhead contact line channel is a metal device embedded in the concrete wall of a tunnel. Typically, two channel fittings are embedded at each point. The overhead contact line boom of a high-speed railway is fixed to the tunnel ceiling via these channels. Due to the high precision requirements and the fact that the channels are located at the tunnel ceiling clearance, manual measurement and inspection at height is inefficient and dangerous. Machine vision measurement technology, with its non-contact measurement characteristics, is suitable for measuring overhead contact line channels. However, existing machine vision measurement equipment is mainly used in stable working environments on assembly lines, where the distance between the object being measured and the camera remains almost constant. A manual focus adjustment before starting the assembly line is sufficient for all subsequent work requirements. Furthermore, assembly line operations emphasize quality, accuracy, and stability. Autofocus lenses, compared to manual fixed-focus lenses, have a more complex structure and introduce more distortion and instability. Therefore, existing machine vision measurement devices do not support autofocus. However, the complex working environment inside tunnels requires the measuring device to achieve rapid autofocus. Therefore, a method is urgently needed to address the inability of existing machine vision measurement devices to achieve rapid autofocus within tunnels. Summary of the Invention
[0003] In view of this, the present invention provides a method and apparatus for measuring contact wire channels based on machine vision technology, so as to solve the problem that existing machine vision measuring devices cannot complete fast automatic focusing when measuring contact wire channels in tunnels, resulting in low measurement accuracy.
[0004] The first aspect of the present invention provides a method for measuring contact wire channels based on machine vision technology, comprising:
[0005] S1: Place the measuring device below the contact wire channel to be measured, and the measuring device will automatically focus;
[0006] S2: The measuring device acquires the original image of the contact wire channel and marks the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model;
[0007] S3: Perform grayscale processing on the ROI region of the original image, convert the RGB format ROI region to the HSB format ROI region; perform adaptive median filtering algorithm to process noise on the HSB format ROI region, obtain the contact wire channel edge of the HSB format ROI region, and perform Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured.
[0008] S4: Select the four longest linear equations from the set of linear equations of the contact wire channel to be measured, and cluster the four linear equations into two categories; calculate the slope and center point of the two categories of linear equations, and obtain the angle values of the two categories of linear equations based on the slope; compare the angle values of the two categories of linear equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of linear equations and determine the actual size of the contact wire channel to be measured by referring to the comparison table of pixel spacing and actual contact wire channel spacing size under different focal lengths to complete the size detection of the contact wire channel to be measured.
[0009] Optionally, placing the measuring device below the contact wire channel to be measured and completing automatic focusing of the measuring device includes:
[0010] S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured.
[0011] S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11.
[0012] S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
[0013] Optionally, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, including:
[0014] The Sobel operator is introduced into the test image to calculate the first-order gradient of the test image. The Sobel operator extracts the edge gradients in four directions: 0°, 45°, 90°, and 135°, respectively, to detect edges in more directions. The calculation formula of the improved Tenengrad sharpness evaluation algorithm includes:
[0015] S1=f(x-1,y+1)+f(x+1,y+1)+2f(x,y+1)-f(x-1,y-1)-f(x+1,y-1)-2f(x,y-1)
[0016] S2=f(x,y+1)+f(x+1,y)+2f(x+1,y+1)-f(x-1,y)-f(x,y-1)-2f(x-1,y-1)
[0017] S3=f(x-1,y+1)+f(x+1,y+1)+2f(x,y+1)-f(x-1,y-1)-f(x+1,y-1)-2f(x,y-1)
[0018] S4=f(x-1,y)+f(x,y+1)+2f(x-1,y+1)-f(x,y-1)-f(x+1,y)-2f(x+1,y-1)
[0019]
[0020] Where f(x, y) is the pixel value of pixel (x, y), and e(x, y) is the edge gradient value of pixel (x, y);
[0021] Using the standard deviation of the gray levels of the test image as a threshold, the edge sharpness evaluation function of the test image is constructed as follows:
[0022] E = ∑ x ∑ y e(x,y), f(x,y)>T
[0023] E represents the edge sharpness evaluation value of the test image, and T represents the standard deviation of the gray level of the test image.
[0024] Optionally, the training steps of the YOLOv5-LiteSE contact wire channel recognition model include:
[0025] First, we collected photos of the pre-embedded contact wire channels at the construction site from the as-built data department, and then sorted, compressed, and transformed them to export the pre-embedded contact wire channel images in the format used by YOLOv5-LiteSE to form a training dataset.
[0026] Secondly, the training weights were extracted from the v5lite-s.pt file, the number of training parameters (Batch_size) was set to 32, the iteration period (epochs) was set to 200, the confidence threshold was set to 0.45, and the IOU threshold was set to 0.65. YOLOv5-LiteSE was trained using the Warmup learning rate method to obtain the trained YOLOv5-LiteSE catenary channel recognition model.
[0027] Optionally, the step of converting the ROI region of the original image to grayscale, and converting the RGB format ROI region to the HSB format ROI region, includes:
[0028] The algorithm for converting individual pixels in an RGB format ROI region to an HSB format ROI region is as follows:
[0029]
[0030] H represents the converted pixel value of each pixel;
[0031] The adaptive median filtering algorithm for noise processing of the HSB format ROI region includes:
[0032] Zmin = the minimum gray value in Sxy, Zmax = the maximum gray value in Sxy;
[0033] Zmed = the median of grayscale values in Sxy, Smax = the maximum window size allowed by Sxy;
[0034] Process A:
[0035] A1 = Z med -Z min A2 = Z med -Z max
[0036] If A1 is greater than 0 and A2 is less than 0, execute process B; otherwise, increase the window size. If the increased window size is not greater than Smax, return to execute process A; otherwise, output Zmed.
[0037] Process B:
[0038] B1 = Zxy - Zmin, B2 = Zxy - Zmax
[0039] If B1 is greater than 0 and B2 is less than 0, output Zxy; otherwise, output Zmed.
[0040] Where Zxy represents the gray value at coordinates (x, y).
[0041] Optionally, the step of obtaining the contact wire channel edge of the ROI region in HSB format and performing a Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured includes:
[0042] The Sobel operator is used to extract the edge gradients of the ROI region in HSB format at four directions: 0°, 45°, 90°, and 135°, and then converted into N coordinate points in a Cartesian coordinate system, as follows:
[0043] (x0, y0)(x1, y1)……(x n-1 y n-1 )
[0044] Performing a Hough transform on N coordinate points yields the linear equations of the ROI region in HSB format, representing the edges of the contact wire channel:
[0045] y0=kx0+b, y1=kx1+b……y n-1 =kx n-1 +b
[0046] Where k is the slope of the line and b is the intercept of the line;
[0047] Eight straight lines were obtained from the edge of the contact wire channel extracted from the concrete dome of the tunnel, which are the four long sides and four short sides of the contact wire channel to be measured.
[0048] Optionally, calculating the minimum distance between the two types of linear equations includes:
[0049] The linear vector equation of line segment L1 is: P(λ1)=P1+λ1S1, and the linear vector equation of line segment L2 is: Q(λ2)=Q1+λ2S2.
[0050] Where P1 and P2 are the two endpoints of line segment L1, and the direction vector of line segment L1 is S1 = P2 - P1; Q1 and Q2 are the two endpoints of line segment L2, and the direction vector of line segment L2 is S2 = Q2 - Q1; the range of values for variables λ1 and λ2 is: 0 ≤ λ1, λ2 ≤ 1;
[0051] The minimum spacing between line segments L1 and L2 is transformed into a constrained optimization problem:
[0052] minf(λ1, λ2)=||P(λ1)-Q(λ2)|| 2 =||(P1+λ1S1)-(Q1+λ2S2)|| 2
[0053] st0≤λ1,λ2≤1
[0054] By the minimum condition: We can obtain:
[0055]
[0056] If 0≤λ1, λ2≤1, then d2min=f(λ1,λ2). Conversely, by finding the shortest distances d1 from endpoint P1 to line segment L2, d2 from endpoint P2 to line segment L2, d3 from endpoint Q1 to line segment L1, and d4 from endpoint Q2 to line segment L1, we can obtain the shortest distance between the two line segments dmin=min{d1,d2,d3,d4}.
[0057] A second aspect of the present invention provides a contact wire channel measuring device based on machine vision technology, including an automatic focusing module for the measuring device, a contact wire channel image acquisition module, a contact wire channel image preprocessing module, and a contact wire channel image detection module.
[0058] The automatic focusing module of the measuring device is used to place the measuring device under the contact wire channel to be measured, and the measuring device completes automatic focusing;
[0059] The contact wire channel image acquisition module is used by the measuring device to acquire the original image of the contact wire channel and mark the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model.
[0060] The contact wire channel image preprocessing module is used to perform grayscale processing on the ROI region of the original image, converting the RGB format ROI region to the HSB format ROI region; performing an adaptive median filtering algorithm to process noise in the HSB format ROI region, obtaining the contact wire channel edge of the HSB format ROI region, and performing Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured.
[0061] The contact wire channel image detection module is used to extract the four longest straight line equations from the set of straight line equations of the contact wire channel to be measured and cluster the four straight line equations into two categories; calculate the slope and center point of the two categories of straight line equations, and obtain the angle values of the two categories of straight line equations based on the slope; compare the angle values of the two categories of straight line equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of straight line equations and determine the actual size of the contact wire channel to be measured by referring to the pixel spacing and actual contact wire channel spacing size comparison table under different focal lengths to complete the size detection of the contact wire channel to be measured.
[0062] Optionally, the autofocus module of the measuring device is used to perform the following steps:
[0063] S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured.
[0064] S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11.
[0065] S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
[0066] The advantages of this invention compared to the prior art are:
[0067] This invention provides a method and apparatus for measuring contact wire grooves based on machine vision technology, comprising: S1: placing the measuring device below the contact wire groove to be measured, and the measuring device completing automatic focusing; S2: the measuring device acquiring the original image of the contact wire groove, and marking the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire groove recognition model; S3: performing grayscale processing on the ROI region of the original image, converting the RGB format ROI region to the HSB format ROI region; performing an adaptive median filtering algorithm on the HSB format ROI region to process noise, obtaining the contact wire groove edge of the HSB format ROI region, and processing the obtained edge edge. The following steps are performed: S4: A Hough transform is applied to the edge of the contact wire channel to obtain the linear equation of the contact wire channel to be measured; S5: The four longest linear equations from the set of linear equations of the contact wire channel to be measured are selected and clustered into two classes; The slope and center point of the two classes of linear equations are calculated, and the angle values of the two classes of linear equations are obtained based on the slopes; The angle values of the two classes of linear equations are compared with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; The minimum spacing between the two classes of linear equations is calculated, and the actual size of the contact wire channel to be measured is determined by referring to the comparison table of pixel spacing and actual contact wire channel spacing dimensions under different focal lengths to complete the size detection of the contact wire channel to be measured. This invention can solve the problem of low measurement accuracy caused by the inability of existing machine vision measurement devices to achieve fast automatic focusing when measuring contact wire channels in tunnels. Attached Figure Description
[0068] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0069] Figure 1 This is a flowchart illustrating the implementation of a contact wire channel measurement method based on machine vision technology, as provided in an embodiment of the present invention.
[0070] Figure 2 This is a schematic diagram of the measuring device provided in an embodiment of the present invention;
[0071] Figure 3 This is a rendering of the tunnel pre-embedded channel provided in an embodiment of the present invention;
[0072] Figure 4 This is a structural diagram of the YOLOv5-LiteSE training model provided in an embodiment of the present invention;
[0073] Figure 5 This is a comparison table of pixel spacing at different focal lengths and actual contact wire channel spacing dimensions provided in the embodiments of the present invention;
[0074] Figure 6 This is a schematic diagram of the structure of a contact wire channel measuring device based on machine vision technology provided in an embodiment of the present invention. Detailed Implementation
[0075] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known apparatuses and methods have been omitted so as not to obscure the description of the invention with unnecessary detail.
[0076] To make the objectives, technical solutions, and advantages of the present invention clearer, specific embodiments will be described below in conjunction with the accompanying drawings.
[0077] Example 1
[0078] See Figure 1 This invention provides a method for measuring contact wire channels based on machine vision technology, including:
[0079] S1: Place the measuring device below the contact wire channel to be measured, and the measuring device will automatically focus;
[0080] S2: The measuring device acquires the original image of the contact wire channel and marks the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model;
[0081] S3: Perform grayscale processing on the ROI region of the original image, convert the RGB format ROI region to the HSB format ROI region; perform adaptive median filtering algorithm to process noise on the HSB format ROI region, obtain the contact wire channel edge of the HSB format ROI region, and perform Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured.
[0082] S4: Select the four longest linear equations from the set of linear equations of the contact wire channel to be measured, and cluster the four linear equations into two categories; calculate the slope and center point of the two categories of linear equations, and obtain the angle values of the two categories of linear equations based on the slope; compare the angle values of the two categories of linear equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of linear equations and determine the actual size of the contact wire channel to be measured by referring to the comparison table of pixel spacing and actual contact wire channel spacing size under different focal lengths to complete the size detection of the contact wire channel to be measured.
[0083] in, Figure 2 This is a schematic diagram of the measuring device provided in an embodiment of the present invention. Figure 3 This is a rendering of the tunnel pre-embedded channel provided in an embodiment of the present invention.
[0084] In this embodiment, placing the measuring device below the contact wire channel to be measured and completing automatic focusing of the measuring device includes:
[0085] S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured.
[0086] S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11.
[0087] S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
[0088] In this embodiment, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, including:
[0089] The Sobel operator is introduced into the test image to calculate the first-order gradient of the test image. The Sobel operator extracts the edge gradients in four directions: 0°, 45°, 90°, and 135°, respectively, to detect edges in more directions. The calculation formula of the improved Tenengrad sharpness evaluation algorithm includes:
[0090] S1=f(x-1,y+1)+f(x+1,y+1)+2f(x,y+1)-f(x-1,y-1)-f(x+1,y-1)-2f(x,y-1)
[0091] S2=f(x,y+1)+f(x+1,y)+2f(x+1,y+1)-f(x-1,y)-f(x,y-1)-2f(x-1,y-1)
[0092] S3=f(x-1,y+1)+f(x+1,y+1)+2f(x,y+1)-f(x-1,y-1)-f(x+1,y-1)-2f(x,y-1)
[0093] S4=f(x-1,y)+f(x,y+1)+2f(x-1,y+1)-f(x,y-1)-f(x+1,y)-2f(x+1,y-1)
[0094]
[0095] Where f(x, y) is the pixel value of pixel (x, y), and e(x, y) is the edge gradient value of pixel (x, y);
[0096] Using the standard deviation of the gray levels of the test image as a threshold, the edge sharpness evaluation function of the test image is constructed as follows:
[0097] E = ∑ x ∑ y e(x,y), f(x,y)>T
[0098] E represents the edge sharpness evaluation value of the test image, and T represents the standard deviation of the gray level of the test image.
[0099] The advantages of this invention compared to the prior art are:
[0100] This invention provides a method and apparatus for measuring contact wire grooves based on machine vision technology, comprising: S1: placing the measuring device below the contact wire groove to be measured, and the measuring device completing automatic focusing; S2: the measuring device acquiring the original image of the contact wire groove, and marking the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire groove recognition model; S3: performing grayscale processing on the ROI region of the original image, converting the RGB format ROI region to the HSB format ROI region; performing an adaptive median filtering algorithm on the HSB format ROI region to process noise, obtaining the contact wire groove edge of the HSB format ROI region, and processing the obtained edge edge. The following steps are performed: S4: A Hough transform is applied to the edge of the contact wire channel to obtain the linear equation of the contact wire channel to be measured; S5: The four longest linear equations from the set of linear equations of the contact wire channel to be measured are selected and clustered into two classes; The slope and center point of the two classes of linear equations are calculated, and the angle values of the two classes of linear equations are obtained based on the slopes; The angle values of the two classes of linear equations are compared with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; The minimum spacing between the two classes of linear equations is calculated, and the actual size of the contact wire channel to be measured is determined by referring to the comparison table of pixel spacing and actual contact wire channel spacing dimensions under different focal lengths to complete the size detection of the contact wire channel to be measured. This invention can solve the problem of low measurement accuracy caused by the inability of existing machine vision measurement devices to achieve fast automatic focusing when measuring contact wire channels in tunnels.
[0101] Example 2
[0102] See Figure 1 This invention provides a method for measuring contact wire channels based on machine vision technology, including:
[0103] S1: Place the measuring device below the contact wire channel to be measured, and the measuring device will automatically focus;
[0104] S2: The measuring device acquires the original image of the contact wire channel and marks the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model;
[0105] S3: Perform grayscale processing on the ROI region of the original image, convert the RGB format ROI region to the HSB format ROI region; perform adaptive median filtering algorithm to process noise on the HSB format ROI region, obtain the contact wire channel edge of the HSB format ROI region, and perform Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured.
[0106] S4: Select the four longest linear equations from the set of linear equations of the contact wire channel to be measured, and cluster the four linear equations into two categories; calculate the slope and center point of the two categories of linear equations, and obtain the angle values of the two categories of linear equations based on the slope; compare the angle values of the two categories of linear equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of linear equations and determine the actual size of the contact wire channel to be measured by referring to the comparison table of pixel spacing and actual contact wire channel spacing size under different focal lengths to complete the size detection of the contact wire channel to be measured.
[0107] In this embodiment, placing the measuring device below the contact wire channel to be measured and completing automatic focusing of the measuring device includes:
[0108] S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured.
[0109] S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11.
[0110] S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
[0111] In this embodiment, the training steps of the YOLOv5-LiteSE contact wire channel recognition model include:
[0112] First, we collected photos of the pre-embedded contact wire channels at the construction site from the as-built data department, and then sorted, compressed, and transformed them to export the pre-embedded contact wire channel images in the format used by YOLOv5-LiteSE to form a training dataset.
[0113] Secondly, the training weights were extracted from the v5lite-s.pt file, the number of training parameters (Batch_size) was set to 32, the iteration period (epochs) was set to 200, the confidence threshold was set to 0.45, and the IOU threshold was set to 0.65. YOLOv5-LiteSE was trained using the Warmup learning rate method to obtain the trained YOLOv5-LiteSE catenary channel recognition model.
[0114] in, Figure 4 This is a structural diagram of the YOLOv5-LiteSE training model provided in an embodiment of the present invention.
[0115] In this embodiment, the grayscale conversion of the ROI region of the original image to the HSB format ROI region includes:
[0116] The algorithm for converting individual pixels in an RGB format ROI region to an HSB format ROI region is as follows:
[0117]
[0118] H represents the converted pixel value of each pixel;
[0119] The adaptive median filtering algorithm for noise processing of the HSB format ROI region includes:
[0120] Zmin = the minimum gray value in Sxy, Zmax = the maximum gray value in Sxy;
[0121] Zmed = the median of grayscale values in Sxy, Smax = the maximum window size allowed by Sxy;
[0122] Process A:
[0123] A1 = Z med -Z min A2 = Z med -Z max
[0124] If A1 is greater than 0 and A2 is less than 0, execute process B; otherwise, increase the window size. If the increased window size is not greater than Smax, return to execute process A; otherwise, output Zmed.
[0125] Process B:
[0126] B1 = Zxy - Zmin, B2 = Zxy - Zmax
[0127] If B1 is greater than 0 and B2 is less than 0, output Zxy; otherwise, output Zmed.
[0128] Where Zxy represents the gray value at coordinates (x, y).
[0129] In this embodiment, the step of obtaining the contact wire channel edge of the ROI region in HSB format and performing a Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured includes:
[0130] The Sobel operator is used to extract the edge gradients of the ROI region in HSB format at four directions: 0°, 45°, 90°, and 135°, and then converted into N coordinate points in a Cartesian coordinate system, as follows:
[0131] (x0, y0)(x1, y1)……(x n-1 y n-1 )
[0132] Performing a Hough transform on N coordinate points yields the linear equations of the ROI region in HSB format, representing the edges of the contact wire channel:
[0133] y0=kx0+b, y1=kx1+b……y n-1 =kx n-1 +b
[0134] Where k is the slope of the line and b is the intercept of the line;
[0135] Eight straight lines were obtained from the edge of the contact wire channel extracted from the concrete dome of the tunnel, which are the four long sides and four short sides of the contact wire channel to be measured.
[0136] In this embodiment, calculating the minimum distance between the two types of linear equations includes:
[0137] The linear vector equation of line segment L1 is: P(λ1)=P1+λ1S1, and the linear vector equation of line segment L2 is: Q(λ2)=Q1+λ2S2.
[0138] Where P1 and P2 are the two endpoints of line segment L1, and the direction vector of line segment L1 is S1 = P2 - P1; Q1 and Q2 are the two endpoints of line segment L2, and the direction vector of line segment L2 is S2 = Q2 - Q1; the range of values for variables λ1 and λ2 is: 0 ≤ λ1, λ2 ≤ 1;
[0139] The minimum spacing between line segments L1 and L2 is transformed into a constrained optimization problem:
[0140] minf(λ1, λ2)=||P(λ1)-Q(λ2)|| 2 =||(P1+λ1S1)-(Q1+λ2S2)|| 2
[0141] st0≤λ1,λ2≤1
[0142] By the minimum condition: We can obtain:
[0143]
[0144] If 0 ≤ λ1, λ2 ≤ 1, then d 2 min = f(λ1, λ2), and conversely, find the shortest distances d1 from endpoint P1 to line segment L2, d2 from endpoint P2 to line segment L2, d3 from endpoint Q1 to line segment L1, and d4 from endpoint Q2 to line segment L1 respectively, and you can get the shortest distance d between the two line segments. min =min{d1, d2, d3, d4}.
[0145] in, Figure 5 This is a comparison table of pixel spacing at different focal lengths and the actual contact wire channel spacing size provided in the embodiments of the present invention.
[0146] Example 3
[0147] See Figure 6 This invention provides a contact wire channel measuring device based on machine vision technology, including an automatic focusing module, a contact wire channel image acquisition module, a contact wire channel image preprocessing module, and a contact wire channel image detection module.
[0148] The automatic focusing module of the measuring device is used to place the measuring device under the contact wire channel to be measured, and the measuring device completes automatic focusing;
[0149] The contact wire channel image acquisition module is used by the measuring device to acquire the original image of the contact wire channel and mark the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model.
[0150] The contact wire channel image preprocessing module is used to perform grayscale processing on the ROI region of the original image, converting the RGB format ROI region to the HSB format ROI region; performing an adaptive median filtering algorithm to process noise in the HSB format ROI region, obtaining the contact wire channel edge of the HSB format ROI region, and performing Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured.
[0151] The contact wire channel image detection module is used to extract the four longest straight line equations from the set of straight line equations of the contact wire channel to be measured and cluster the four straight line equations into two categories; calculate the slope and center point of the two categories of straight line equations, and obtain the angle values of the two categories of straight line equations based on the slope; compare the angle values of the two categories of straight line equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of straight line equations and determine the actual size of the contact wire channel to be measured by referring to the pixel spacing and actual contact wire channel spacing size comparison table under different focal lengths to complete the size detection of the contact wire channel to be measured.
[0152] In this embodiment, the autofocus module of the measuring device is used to perform the following steps:
[0153] S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured.
[0154] S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11.
[0155] S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
[0156] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A method for measuring a catenary channel based on machine vision technology, characterized in that, include: S1: Place the measuring device below the contact wire channel to be measured, and the measuring device will automatically focus; S2: The measuring device acquires the original image of the contact wire channel and marks the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model; S3: Perform grayscale processing on the ROI region of the original image, convert the RGB format ROI region to the HSB format ROI region; perform adaptive median filtering algorithm to process noise on the HSB format ROI region, obtain the contact wire channel edge of the HSB format ROI region, and perform Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured. S4: Select the four longest linear equations from the set of linear equations of the contact wire channel to be measured, and cluster the four linear equations into two categories; calculate the slope and center point of the two categories of linear equations, and obtain the angle values of the two categories of linear equations based on the slope; compare the angle values of the two categories of linear equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of linear equations and determine the actual size of the contact wire channel to be measured by referring to the comparison table of pixel spacing and actual contact wire channel spacing size under different focal lengths to complete the size detection of the contact wire channel to be measured.
2. The catenary channel measurement method based on machine vision technology according to claim 1, characterized in that, The step of placing the measuring device below the contact wire channel to be measured and having the measuring device automatically focus includes: S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured. S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11. S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
3. The catenary channel measurement method based on machine vision technology according to claim 2, characterized in that, The measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, including: The Sobel operator is introduced into the test image to calculate the first-order gradient of the test image. The Sobel operator extracts the edge gradients in four directions: 0°, 45°, 90°, and 135°, respectively, to detect edges in more directions. The calculation formula of the improved Tenengrad sharpness evaluation algorithm includes: in, f ( x , y ) is a pixel ( x , y The pixel value of ) e ( x , y ) is a pixel ( x , y The edge gradient value; Using the standard deviation of the gray levels of the test image as a threshold, the edge sharpness evaluation function of the test image is constructed as follows: E T represents the edge sharpness evaluation value of the test image, and T is the standard deviation of the gray level of the test image.
4. The contact wire channel measurement method based on machine vision technology as described in claim 1, characterized in that, The training steps of the YOLOv5-LiteSE contact wire channel recognition model include: First, we collected photos of the pre-embedded contact wire channels at the construction site from the as-built data department, and then sorted, compressed, and transformed them to export the pre-embedded contact wire channel images in the format used by YOLOv5-LiteSE to form a training dataset. Secondly, the training weights were extracted from the v5lite-s.pt file, the number of training parameters (Batch_size) was set to 32, the iteration period (epochs) was set to 200, the confidence threshold was set to 0.45, and the IOU threshold was set to 0.
65. YOLOv5-LiteSE was trained using the Warmup learning rate method to obtain the trained YOLOv5-LiteSE catenary channel recognition model.
5. The contact wire channel measurement method based on machine vision technology as described in claim 1, characterized in that, The step of converting the ROI region of the original image to grayscale, and converting the RGB format ROI region to the HSB format ROI region, includes: The algorithm for converting individual pixels in an RGB format ROI region to an HSB format ROI region is as follows: H represents the converted pixel value of each pixel; The adaptive median filtering algorithm for noise processing of the HSB format ROI region includes: Process A: If A1 is greater than 0 and A2 is less than 0, execute process B; otherwise, increase the window size. If the increased window size is not greater than S... max If the result is positive, return to process A; otherwise, output Z. med ; Process B: If B1 is greater than 0 and B2 is less than 0, then output Z. xy Otherwise, output Z. med ; Where Zxy represents the gray value at coordinates (x, y).
6. The contact wire channel measurement method based on machine vision technology as described in claim 1, characterized in that, The process of obtaining the contact wire channel edge of the ROI region in HSB format and performing a Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured includes: The Sobel operator is used to extract the edge gradients of the ROI region in HSB format at four directions: 0°, 45°, 90°, and 135°, and then converted into n coordinate points in a Cartesian coordinate system, as follows: Performing a Hough transform on n coordinate points yields the linear equations of the ROI region in HSB format, representing the edges of the contact wire channel: ; ; ; Where k is the slope of the line and b is the intercept of the line; Eight straight lines were obtained from the edge of the contact wire channel extracted from the concrete dome of the tunnel, which are the four long sides and four short sides of the contact wire channel to be measured.
7. The contact wire channel measurement method based on machine vision technology as described in claim 1, characterized in that, The calculation of the minimum distance between the two types of linear equations includes: The linear vector equation of line segment L1 is: P(λ1) = P1 + λ1S1, and the linear vector equation of line segment L2 is: Q(λ2) = Q1 + λ2S2. Where P1 and P2 are the coordinates of the two endpoints of line segment L1, and the direction vector of line segment L1 is S1 = P2 - P1; Q1 and Q2 are the coordinates of the two endpoints of line segment L2, and the direction vector of line segment L2 is S2 = Q2 - Q1; the range of values for variables λ1 and λ2 is: 0 ≤ λ1, λ2 ≤ 1; The minimum spacing between line segments L1 and L2 is transformed into a constrained optimization problem: By the minimum condition: We can obtain: If 0 ≤ λ1, λ2 ≤ 1, then d 2 min = f (λ1, λ2), conversely, by finding the shortest distances d1 from endpoint P1 to line segment L2, d2 from endpoint P2 to line segment L2, d3 from endpoint Q1 to line segment L1, and d4 from endpoint Q2 to line segment L1 respectively, the shortest distance d between the two line segments can be obtained. min =min{d1, d2, d3, d4}.
8. A contact wire channel measuring device based on machine vision technology, characterized in that, It includes an automatic focusing module for measuring devices, an image acquisition module for contact wire channels, an image preprocessing module for contact wire channels, and an image detection module for contact wire channels. The automatic focusing module of the measuring device is used to place the measuring device under the contact wire channel to be measured, and the measuring device completes automatic focusing; The contact wire channel image acquisition module is used by the measuring device to acquire the original image of the contact wire channel and mark the ROI region of the original image based on the trained YOLOv5-LiteSE contact wire channel recognition model. The contact wire channel image preprocessing module is used to perform grayscale processing on the ROI region of the original image, converting the RGB format ROI region to the HSB format ROI region; performing an adaptive median filtering algorithm to process noise in the HSB format ROI region, obtaining the contact wire channel edge of the HSB format ROI region, and performing Hough transform on the obtained contact wire channel edge to obtain the straight line equation of the contact wire channel to be measured. The contact wire channel image detection module is used to extract the four longest straight line equations from the set of straight line equations of the contact wire channel to be measured and cluster the four straight line equations into two categories; calculate the slope and center point of the two categories of straight line equations, and obtain the angle values of the two categories of straight line equations based on the slope; compare the angle values of the two categories of straight line equations with the preset standard values of contact wire channel angles to complete the parallelism detection of the contact wire channel to be measured; calculate the minimum spacing between the two categories of straight line equations and determine the actual size of the contact wire channel to be measured by referring to the pixel spacing and actual contact wire channel spacing size comparison table under different focal lengths to complete the size detection of the contact wire channel to be measured.
9. The contact wire channel measuring device based on machine vision technology as described in claim 8, characterized in that, The autofocus module of the measuring device is used to perform the following steps: S11: Place the measuring device below the contact wire channel to be measured, level the measuring device with reference to the bubble level on the measuring device, and the measuring device will collect the test image of the contact wire channel to be measured. S12: The data terminal acquires the test image, calculates the average pixel grayscale value of the test image, compares the average pixel grayscale value with the optimal pixel grayscale range, and when the average pixel grayscale value is less than the preset optimal lower limit of the pixel, the measuring device increases the illumination brightness and re-executes step S11; when the average pixel grayscale value is greater than the preset optimal upper limit of the pixel, the measuring device decreases the illumination brightness and re-executes step S11. S13: After the image brightness adjustment is completed, the measuring device first uses the hill climbing method to sequentially collect image sets with focal lengths from minimum to maximum. Then, the measuring device calculates the edge sharpness of the test image based on the improved Tenengrad sharpness evaluation algorithm, and selects the focal length of the image with the highest edge sharpness to automatically focus the measuring device.
Citation Information
Patent Citations
Machine-vision-based online dimensional measurement method of precise instrument
CN103292701A
Method and system for positioning steady ears in catenary images
CN104794720A