A highway video inspection method, electronic equipment and storage medium
Video data is obtained through highway monitoring equipment, pre-processing and calibration of the connected area, and traffic accidents are judged, which solves the problems of inefficient inspection methods and untimely accident discovery, and realizes intelligent monitoring and rapid response of the expressway.
Patent Information
- Application Number
- CN202411639655.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-04-04
AI Technical Summary
The existing highway patrol methods are inefficient and cannot accurately and promptly detect and handle traffic accidents.
By obtaining video data of the highway monitoring equipment, preprocessing to obtain binary images of the foreground target, calibrating the connection area, calculating the width and height of the external rectangle of the connecting area, and determining whether a traffic accident occurred based on the aspect ratio and the preset threshold.
It realizes comprehensive, real-time and intelligent monitoring of expressways, and quickly responds to sudden traffic accidents, providing guarantees for the safe and efficient operation of expressways.
Smart Images

Figure CN119763030A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent transportation technology, and in particular to a highway video inspection method, electronic equipment and storage medium. Background Art
[0002] A highway is a high-speed, high-capacity road network that is usually used to connect long-distance traffic between cities, regions and countries. It is an important component of modern transportation infrastructure and is crucial to promoting economic development, facilitating people's travel and strengthening connections between cities.
[0003] However, with the continuous increase in highway mileage and traffic volume, highway traffic management faces many challenges, such as traffic congestion, traffic accidents, etc. At present, highway inspections are mainly carried out by manual monitoring or on-site patrols by patrol cars. This inspection method not only has a limited monitoring range and high reliance on manual intervention, but also has the problems of low efficiency and failure to accurately and timely detect and handle accidents. Summary of the invention
[0004] The technical problem to be solved by the present invention is to overcome the defects in the prior art, thereby providing a highway video inspection method, an electronic device and a storage medium.
[0005] To achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a highway video inspection method, comprising the following steps:
[0007] S1, obtaining a video from a monitoring device installed on a highway, and dividing the video into a series of continuous images according to a preset frame rate;
[0008] S2, preprocessing the image to obtain a binary image of the foreground target;
[0009] S3, calibrating the connected area of the binary image of the foreground target, and calculating the width and height of the circumscribed rectangle of the connected area;
[0010] S4, judging whether a traffic accident occurs according to the relationship between the ratio of the width and the height of the circumscribed rectangle of the connected area and a second preset threshold.
[0011] Preferably, S2 specifically includes the following steps:
[0012] S21, performing differential processing on the image to update the image background;
[0013] S22, filtering out noise of the image after background update;
[0014] S23, performing threshold segmentation on the image after noise filtering to obtain a binary image of the foreground target.
[0015] Preferably, the S21 specifically includes the following steps:
[0016] S211, calculate the difference value D(x, y) between the input image pixel point A(x, y) and the background image pixel point B(x, y), that is,
[0017] D(x,y)=|A(x,y)-B(x,y)|
[0018] Where (x, y) represents the coordinates of the image pixel, 0≤x≤m-1, 0≤y≤n-1, m represents the image pixel width, and n represents the image pixel height;
[0019] S212, compare D(x, y) with the first preset threshold to determine whether D(x, y) belongs to the background or the foreground: if D(x, y) is less than the first preset threshold, then D(x, y) is the background and needs to be updated, that is, the new background is A(x, y); if D(x, y) is greater than or equal to the first preset threshold, then D(x, y) is the foreground and does not need to be updated, that is, the background is still B(x, y).
[0020] Preferably, the S23 specifically includes the following steps:
[0021] S231, calculating the variance of the target area A and the background area B;
[0022] Specifically, suppose the grayscale value range in the image is 1 to L, and the number of pixels with grayscale value k is n k , r k represents the kth gray level, then the total number of pixels The probability of each gray level appearing is
[0023] Assume that pixels with grayscale values of 1 to k belong to target area A, and pixels with grayscale values of k+1 to L belong to background area B. Then the probabilities of target area A and background area B are
[0024]
[0025] The average grayscale of the target area A and the background area B is
[0026]
[0027] The variance of the target area A and the background area B is
[0028] σ 2 =ω A ω B (u B-u A ) 2
[0029] S232, calculating a segmentation threshold value, and performing region segmentation according to the segmentation threshold value to obtain a foreground target binary image.
[0030] Specifically, we calculate the variance σ by changing k from 1 to L 2 , when σ 2 The maximum k value is the segmentation threshold value. According to the segmentation threshold value, it is determined whether each pixel in the image belongs to the target area A or the background area B, and finally a binary image of the foreground target and a binary image of the background are obtained.
[0031] Preferably, S3 specifically includes the following steps:
[0032] S31, calibrating the connected regions of the binary image of the foreground target;
[0033] S32, calibrating the circumscribed rectangle of the connected area to obtain the circumscribed rectangle of the target vehicle, and calculating the width and height of the circumscribed rectangle.
[0034] Preferably, the S32 specifically includes:
[0035] S321, scan from top to bottom line by line, and when the first changed pixel is scanned, record the coordinate value I 1 (x, y), scan from bottom to top line by line at the same time, and when the first changed pixel is scanned, record the coordinate value I 2 (x, y), then the height of the circumscribed rectangle of the connected region h = |I 1 (x,y)-I 2 (x,y)|;
[0036] S322, scan from left to right column by column, and when the first changed pixel is scanned, record the coordinate value J 1 (x, y), and scan from right to left column by column. When the first changed pixel is scanned, the coordinate value J is recorded. 2 (x, y), then the height of the circumscribed rectangle of the connected region w = |J 1 (x,y)-J 2 (x,y)|.
[0037] Preferably, if the ratio of the width to the height of the circumscribed rectangle of the connected area is greater than a second preset threshold, it is determined that a traffic accident has occurred.
[0038] In a second aspect, the present invention further provides an electronic device comprising at least one processor, at least one memory and computer program instructions stored in the memory, wherein the highway video inspection method is implemented when the computer program instructions are executed by the processor.
[0039] In a third aspect, the present invention further provides a storage medium having computer program instructions stored thereon, which implement the highway video inspection method when the computer program instructions are executed by a processor.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] The highway video inspection method provided in the above technical solution converts video data into image data, and then pre-processes the image data to obtain a binary image of the foreground target, and then calibrates the connected area, calculates the width and height of the circumscribed rectangle of the connected area, and finally determines whether a traffic accident has occurred based on the ratio of the width and height of the circumscribed rectangle of the connected area and the size relationship of the second preset threshold. The present invention achieves the purpose of video inspection by analyzing and processing the video data collected on the highway to determine whether a traffic accident has occurred. This inspection method can conduct comprehensive, real-time, and intelligent monitoring of the highway, and quickly respond to sudden traffic accidents, providing a strong guarantee for the safe and efficient operation of the highway. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for describing the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0043] Figure 1 The present invention provides a flowchart of the highway video inspection method. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0046] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0047] It should be further understood that the term "and / or" used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0048] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in this application should have the common meanings understood by those skilled in the art to which the present invention belongs.
[0049] like Figure 1 As shown, an embodiment of the present invention provides a highway video inspection method, comprising the following steps:
[0050] S1, obtaining a video from a monitoring device installed on a highway, and dividing the video into a series of continuous images according to a preset frame rate.
[0051] Monitoring equipment is installed at each intersection, checkpoint and other key sections of the highway to collect real-time images of the highway. In order to analyze and identify traffic accidents on the highway, it is first necessary to convert video data into image data, so that dynamic data can be converted into static data for processing.
[0052] Specifically, the video may be divided into a series of continuous images according to a preset frame rate, and the size of the preset frame rate may be adjusted according to actual needs.
[0053] S2, preprocessing the image to obtain a binary image of the foreground target;
[0054] Before analyzing and identifying the image, the image needs to be preprocessed to improve the accuracy of recognition. S2 specifically includes the following steps:
[0055] S21, performing differential processing on the image to update the image background;
[0056] Since the viewing angle of the monitoring equipment installed on the highway is usually fixed, the background in the video shot by it usually does not change much. However, video processing is sensitive to conditions such as lighting and surrounding environment. Therefore, in order to adapt to environmental changes and ensure detection accuracy, it is necessary to perform differential processing on the image background to update the background. The S21 specifically includes the following steps:
[0057] S211, calculate the difference value D(x, y) between the input image pixel point A(x, y) and the background image pixel point B(x, y), that is,
[0058] D(x,y)=|A(x,y)-B(x,y)|
[0059] Where (x, y) represents the coordinates of the image pixel, 0≤x≤m-1, 0≤y≤n-1, m represents the image pixel width, and n represents the image pixel height;
[0060] S212, compare D(x, y) with the first preset threshold to determine whether D(x, y) belongs to the background or the foreground: if D(x, y) is less than the first preset threshold, then D(x, y) is the background and needs to be updated, that is, the new background is A(x, y); if D(x, y) is greater than or equal to the first preset threshold, then D(x, y) is the foreground and does not need to be updated, that is, the background is still B(x, y).
[0061] S22, filtering out noise of the image after background update;
[0062] The image after background update may still have a lot of noise, which will affect the accuracy of subsequent image recognition. Therefore, it is necessary to filter the image, which includes the following steps:
[0063] S221, converting the image into a grayscale image;
[0064] S222, filtering the image using a median filter.
[0065] Median filtering has a good filtering effect on impulse noise, especially when filtering noise, it can protect the edge of the signal so that it is not blurred. These excellent filtering characteristics are not possessed by linear filtering methods. In addition, the algorithm of median filtering is relatively simple and easy to implement in hardware. Therefore, the present invention uses a median filter to filter image noise.
[0066] S23, performing threshold segmentation on the image after noise filtering to obtain a binary image of the foreground target;
[0067] The threshold segmentation algorithm adopted by the present invention utilizes the difference in grayscale characteristics between the target area to be extracted in the image and its background, regards the image as a combination of two areas with different grayscale levels, namely, a combination of the target area and the background area, and then selects a suitable threshold to determine whether each pixel in the image belongs to the target area or the background area, thereby generating a corresponding binary image. The S23 specifically includes the following steps:
[0068] S231, calculating the variance of the target area A and the background area B;
[0069] Specifically, suppose the grayscale value range in the image is 1 to L, and the number of pixels with grayscale value k is n k , r k represents the kth gray level, then the total number of pixels The probability of each gray level appearing is
[0070] Assume that pixels with grayscale values of 1 to k belong to target area A, and pixels with grayscale values of k+1 to L belong to background area B. Then the probabilities of target area A and background area B are
[0071]
[0072] The average grayscale of the target area A and the background area B is
[0073]
[0074] The variance of the target area A and the background area B is
[0075] σ 2 =ω A ω B (u B -u A ) 2
[0076] S232, calculating a segmentation threshold value, and performing region segmentation according to the segmentation threshold value to obtain a foreground target binary image.
[0077] Specifically, we calculate the variance σ by changing k from 1 to L 2 , when σ 2 The maximum k value is the segmentation threshold value. According to the segmentation threshold value, it is determined whether each pixel in the image belongs to the target area A or the background area B, and finally a binary image of the foreground target and a binary image of the background are obtained.
[0078] S3, calibrating the connected area of the binary image of the foreground target, and calculating the width and height of the circumscribed rectangle of the connected area; S3 specifically includes the following steps:
[0079] S31, calibrating the connected regions of the binary image of the foreground target;
[0080] The same pixel in the binary image is connected in the up and down, left and right, upper left corner, lower left corner, upper right corner, and lower right corner, that is, the same pixels adjacent in the horizontal, vertical or diagonal direction are the same object, which completes the connected area calibration of the binary image.
[0081] S32, calibrating the circumscribed rectangle of the connected area to obtain the circumscribed rectangle of the target vehicle, and calculating the width and height of the circumscribed rectangle, wherein S32 specifically includes:
[0082] S321, scan from top to bottom line by line, and when the first changed pixel is scanned, record the coordinate value I 1 (x, y), scan from bottom to top line by line at the same time, and when the first changed pixel is scanned, record the coordinate value I 2 (x, y), then the height of the circumscribed rectangle of the connected region h = |I 1 (x,y)-I 2 (x,y)|;
[0083] S322, scan from left to right column by column, and when the first changed pixel is scanned, record the coordinate value J 1 (x, y), and scan from right to left column by column. When the first changed pixel is scanned, the coordinate value J is recorded. 2 (x, y), then the height of the circumscribed rectangle of the connected region w = |J 1 (x,y)-J 2 (x,y)|.
[0084] S4, judging whether a traffic accident occurs according to the relationship between the ratio of the width and the height of the circumscribed rectangle of the connected area and a second preset threshold.
[0085] Usually, the ratio of width to length of vehicles varies due to different vehicle models. When the vehicle is driving normally, it is basically parallel to the viewing direction of the monitoring device. Even if the vehicle needs to change lanes during driving, such as overtaking, the width-to-length ratio of the vehicle in the image will only change within a small range. However, when the vehicle is out of control or driving abnormally, its width-to-length ratio will exceed a certain range. The width-to-length ratio of the vehicle corresponds to the width-to-height ratio of the circumscribed rectangle of the connected area in its binary image.
[0086] Therefore, the present invention determines whether the vehicle is out of control or driving abnormally by taking the size relationship between the aspect ratio of the circumscribed rectangle of the connected area of the binary image of the vehicle during driving and the second preset threshold as a determination condition.
[0087] If the ratio of the width to the height of the circumscribed rectangle of the connected area is greater than the second preset threshold, it is determined that a traffic accident has occurred, which may be the following situations:
[0088] If the vehicles are moving sideways, a traffic accident has occurred or is likely to occur; if there are two or more vehicles forming the same connected area, it means that the vehicles have collided and their respective connected areas are connected.
[0089] The present invention uses the highway video inspection method to identify traffic accidents such as small car loss of control or collision, large car loss of control or collision, and collision between large and small cars, and obtains a high accuracy rate.
[0090] An embodiment of the present invention further provides an electronic device, comprising at least one processor, at least one memory, and computer program instructions stored in the memory, wherein the highway video inspection method is implemented when the computer program instructions are executed by the processor.
[0091] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0092] In addition, in combination with the highway video inspection method provided in the above embodiment, a storage medium can also be provided in this embodiment, on which computer program instructions are stored, and when the computer program instructions are executed by the processor, the highway video inspection method is implemented.
[0093] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0094] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0095] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A highway video inspection method, characterized in that: The steps include: S1, obtaining a video from a monitoring device installed on a highway, and dividing the video into a series of continuous images according to a preset frame rate; S2, preprocessing the image to obtain a binary image of the foreground target; S3, calibrating the connected area of the binary image of the foreground target, and calculating the width and height of the circumscribed rectangle of the connected area; S4, judging whether a traffic accident occurs according to the relationship between the ratio of the width and the height of the circumscribed rectangle of the connected area and a second preset threshold.
2. The highway video inspection method according to claim 1, characterized in that: The S2 specifically includes the following steps: S21, performing differential processing on the image to update the image background; S22, filtering out noise of the image after background update; S23, performing threshold segmentation on the image after noise filtering to obtain a binary image of the foreground target.
3. The highway video inspection method according to claim 2, characterized in that: The S21 specifically includes the following steps: S211, calculate the difference value D(x, y) between the input image pixel point A(x, y) and the background image pixel point B(x, y), that is, D(x,y)=|A(x,y)-B(x,y)| Where (x, y) represents the coordinates of the image pixel, 0≤x≤m-1, 0≤y≤n-1, m represents the image pixel width, and n represents the image pixel height; S212, compare D(x, y) with the first preset threshold to determine whether D(x, y) belongs to the background or the foreground: if D(x, y) is less than the first preset threshold, then D(x, y) is the background and needs to be updated, that is, the new background is A(x, y); if D(x, y) is greater than or equal to the first preset threshold, then D(x, y) is the foreground and does not need to be updated, that is, the background is still B(x, y).
4. The highway video inspection method according to claim 3, characterized in that: The S23 specifically includes the following steps: S231, calculating the variance of the target area A and the background area B; Specifically, suppose the grayscale value range in the image is 1 to L, and the number of pixels with grayscale value k is n k , r k represents the kth gray level, then the total number of pixels The probability of each gray level appearing is Assume that the pixels with grayscale of 1 to k belong to the target area A, and the pixels with grayscale of k+1 to L belong to the background area B. Then the probabilities of the target area A and the background area B are The average grayscale of the target area A and the background area B is The variance between the target area A and the background area B is σ 2 =ω A ω B (u B -u A ) 2 S232, calculating a segmentation threshold value, and performing region segmentation according to the segmentation threshold value to obtain a foreground target binary image; Specifically, we calculate the variance σ by changing k from 1 to L 2 , when σ 2 The maximum k value is the segmentation threshold value. According to the segmentation threshold value, it is determined whether each pixel in the image belongs to the target area A or the background area B, and finally a binary image of the foreground target and a binary image of the background are obtained.
5. The highway video inspection method according to claim 4, characterized in that: The S3 specifically includes the following steps: S31, calibrating the connected regions of the binary image of the foreground target; S32, calibrating the circumscribed rectangle of the connected area to obtain the circumscribed rectangle of the target vehicle, and calculating the width and height of the circumscribed rectangle.
6. The highway video inspection method according to claim 5, characterized in that: The S32 specifically includes: S321, scan from top to bottom line by line, when scanning the first changed pixel point, record the coordinate value I1(x, y), and scan from bottom to top line by line, when scanning the first changed pixel point, record the coordinate value I2(x, y), then the height of the circumscribed rectangle of the connected area h=|I1(x,y)-I2(x,y)|; S322, scan from left to right column by column, when scanning the first changed pixel point, record the coordinate value J1 (x, y), and scan from right to left column by column, when scanning the first changed pixel point, record the coordinate value J2 (x, y), then the height of the circumscribed rectangle of the connected area w=|J1(x,y)-J2(x,y)|.
7. The highway video inspection method according to claim 6, characterized in that: If the ratio of the width to the height of the circumscribed rectangle of the connected area is greater than a second preset threshold, it is determined that a traffic accident has occurred.
8. An electronic device comprising at least one processor, at least one memory and computer program instructions stored in the memory, wherein when the computer program instructions are executed by the processor, the highway video inspection method according to any one of claims 1 to 7 is implemented.
9. A storage medium having computer program instructions stored thereon, which, when executed by a processor, implements the highway video inspection method as described in any one of claims 1 to 7.