Narrow area detection method and device based on center line extraction and medium
By extracting the centerline and dividing the spear-shaped area in narrow area detection, the problem of low accuracy and high computational complexity in complex scenes is solved, and efficient narrow area detection is achieved, which is suitable for multiple application fields.
Patent Information
- Application Number
- CN202410439508.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-12
- Publication Date
- 2024-09-10
AI Technical Summary
Existing narrow area detection methods have low accuracy and high computational complexity in complex scenes, and deep learning methods require a large amount of annotated data and computing resources.
The narrow area detection method based on center line extraction preprocesses the image to be detected, extracts the center line of the target area, and divides continuous rectangular areas on the center line, and determines whether the wide edge outside the rectangular area is within the target area. for a narrow area.
It improves the accuracy of narrow area detection, reduces computational complexity, and reduces the demand for computing resources. It is suitable for many fields such as road design and circuit wiring.
Smart Images

Figure CN118628433A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image detection, and in particular relates to a narrow area detection method, device and medium based on centerline extraction. Background Art
[0002] Narrow area detection is mostly used in the following areas: facilitating the design of traffic roads; monitoring changes in river morphology to respond to flood disasters in a timely manner; finding circuits that are too close in circuit layout and wiring to prevent electromagnetic interference between each other, etc. Among them, image detection is widely used, such as traditional image processing methods and deep learning-based methods.
[0003] Traditional methods rely on calculating the area of the region, which can only achieve low accuracy and take a long time for some complex scenes. Deep learning methods have good performance in image recognition tasks, but they require a large amount of labeled data and complex network structures that require high computing resources.
[0004] Therefore, it is necessary to propose a narrow area detection method with high accuracy and low computational complexity. Summary of the invention
[0005] In view of the above defects or improvement needs of the prior art, the present invention provides a narrow area detection method, device and medium based on centerline extraction, which solves the problems of low accuracy and high calculation difficulty of the existing narrow area detection method.
[0006] To achieve the above object, according to a first aspect of the present invention, a method for detecting a narrow area based on centerline extraction is provided, the method comprising:
[0007] Perform image preprocessing on the image to be detected;
[0008] Extract the center line of the target area in the image to be detected;
[0009] Divide continuous rectangular areas on the center line;
[0010] Whether the area is a narrow area is determined based on whether the two widths outside the rectangular area are within the target area.
[0011] Furthermore, the image to be detected is preprocessed, including:
[0012] The image to be detected is binarized, the pixel value of the target area is set to 1, and the pixel value of the non-target area is set to 0.
[0013] Furthermore, the image to be detected is converted into a grayscale image, the image to be detected is binarized, and a closing operation is performed on the binarized image.
[0014] Furthermore, the center line of the target area in the image to be detected is extracted based on the center line extraction algorithm, including:
[0015] Extract the center line of the target area in the image to be detected based on the thinning algorithm to obtain a center line image;
[0016] Perform inversion and distance transformation operations on the binary image;
[0017] Perform a dot product of the image after the inversion and distance transformation operations and the center line image to obtain a dot product image;
[0018] The dot product image is binarized according to a preset threshold to obtain the center line.
[0019] Furthermore, the center line of the target area in the image to be detected is extracted based on a thinning algorithm, including:
[0020] Step 1: Traverse the pixels with a pixel value of 1 in the binary image and mark the pixels that meet the following four conditions at the same time: (1) the sum of the pixel values of the pixels around the target pixel is greater than or equal to 2 and less than or equal to 6; (2) the pixel values of the pixels around the target pixel change from 0 to 1 once; (3) at least one of the three pixels above, to the right, and below the target pixel is 0; (4) at least one of the three pixels to the right, below, and to the left of the target pixel is 0;
[0021] Step 2: After the traversal is completed, the pixel value of the marked pixel is set to 0;
[0022] Step 3: Repeat step 1, but condition (3) is different from condition (4): (3) at least one of the three pixels to the left, above, and right of the target pixel is 0; (4) at least one of the three pixels below, left, and above the target pixel is 0;
[0023] Step 4: After the traversal is completed, the pixel value of the marked pixel is set to 0;
[0024] Step 5: Repeat steps 1 to 4 until no new pixels are marked.
[0025] Furthermore, continuous rectangular areas are divided on the center line, including:
[0026] Step 1: Take any point on the center line as the starting point and find a point on the center line that is a distance b from the starting point; where b is the preset distance;
[0027] Step 2: two specific rectangles with the starting point and the line connecting the found point as the dividing line form a rectangular area. If multiple points are found, multiple rectangular areas are divided; wherein the length of one side of the specific rectangle overlapping the line is b, and the length of the other side is a, where a is the narrow area judgment threshold;
[0028] Step 3: Use the found point as the new starting point and repeat steps 1 to 2 until there is no point on the center line that is a distance b from the starting point.
[0029] Furthermore, the preset distance b is the narrow area determination threshold a.
[0030] Further, judging whether the area is a narrow area according to whether the two widths outside the rectangular area are within the target area includes:
[0031] Obtain the coordinates of all points on the two wide sides of each rectangular area by calculation;
[0032] Traverse the rectangular area, bring the coordinates of the points on the wide edge into the image to be detected, and determine the relationship between the wide edge and the target area;
[0033] If the wide side extends beyond the target area, the rectangular area is considered to be a narrow area.
[0034] According to a second aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the narrow area detection method based on centerline extraction described above are implemented.
[0035] According to a third aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the above-mentioned methods for detecting narrow areas based on centerline extraction are implemented.
[0036] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:
[0037] The present invention sets continuous rectangular areas based on the center line, and detects narrow areas by determining whether the wide sides outside the rectangular areas are within the target area. This can effectively reduce the complexity of image calculation, improve the efficiency of narrow area detection, and ensure high accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flow chart of a narrow area detection method based on centerline extraction provided by an embodiment of the present invention;
[0039] Figure 2 A schematic diagram of a process for extracting a center line of a target area provided by an embodiment of the present invention;
[0040] Figure 3 A schematic diagram of a process for setting continuous rectangular areas on a center line provided by an embodiment of the present invention;
[0041] Figure 4 A schematic diagram of a process for determining a narrow area by using a rectangular wide side provided by an embodiment of the present invention;
[0042] Figure 5 A restoration principle diagram of a narrow area detection method provided by an embodiment of the present invention;
[0043] Figure 6 A schematic diagram of a rectangular area provided by an embodiment of the present invention;
[0044] Figure 7 A schematic diagram of the effect of a narrow area detection method provided by an embodiment of the present invention;
[0045] Figure 8 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0047] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as limiting the present invention.
[0048] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0049] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0050] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being "above", "above" or "above" a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being "below", "below" or "below" a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.
[0051] In order to solve the problem of low efficiency and accuracy of traditional image methods in complex scenes in existing narrow area detection methods, and the problem that deep learning methods require a large amount of labeled data for training and have high computing resource requirements, the present invention proposes a narrow area method, device and medium based on centerline extraction to improve the accuracy and efficiency of narrow area detection.
[0052] Embodiment 1
[0053] This embodiment provides a narrow area detection method based on centerline extraction. Figure 5 This is a restoration principle diagram of the narrow area detection method based on centerline extraction proposed by the present invention: the black area is the target area, the white area is the non-target area, the white line segment is the centerline extracted from the target area based on the centerline extraction algorithm, and a continuous rectangular area is set on the centerline through calculation. Whether the rectangular area is a narrow area is determined based on whether there are points on the two wide sides outside the rectangular area that are outside the target area. In the figure, a part of the wide side of the rectangular area pointed by the arrow is already outside the target area, so it is considered to be a narrow area.
[0054] In order to more intuitively demonstrate the effect of the present invention in detecting narrow areas, Figure 7 The figure is a schematic diagram showing the effect of using the narrow area detection method based on centerline extraction proposed by the present invention on a watershed map, wherein the area indicated by the arrow is considered to be a narrow area.
[0055] Figure 1The present invention provides a method for detecting a narrow area based on centerline extraction, which includes the following steps:
[0056] S1: preprocess the image to be detected;
[0057] S2: extracting the center line of the target area in the image to be detected by a center line extraction algorithm;
[0058] S3: Divide the continuous rectangular area consisting of two squares to cover all the center lines;
[0059] S4: Determine whether the area is a narrow area according to whether the two widths outside the rectangular area are within the target area.
[0060] The image preprocessing is to convert the image to be detected into a grayscale image, and then perform binarization processing to set the pixel value of the target area to 1 and the pixel value of the non-target area to 0. The binarized image can also be closed to perform preliminary filtering of noise.
[0061] The present invention obtains the center line of the target area from the image to be detected based on the center line extraction algorithm. The center line is set by calculation to make the center line completely covered by the rectangular area. If there are parts of the two wide sides of the rectangle that are located in the non-target area, it means that the rectangular area exceeds the target area, and the rectangular area is a narrow area. In fact, when judging a narrow area, it is only necessary to judge whether the rectangular area is a narrow area based on whether there are points on the two wide sides outside the rectangular area that are outside the target area, without calculating the entire rectangular area. Therefore, the narrow area detection method proposed by the present invention has a small calculation complexity and a high accuracy.
[0062] In some embodiments of the present invention, Figure 2 As shown, step S2 includes:
[0063] S21: Obtaining the center line of the target area in the image to be detected based on a thinning algorithm;
[0064] S22: performing inversion and distance transformation operations on the preprocessed image;
[0065] S23: performing a dot multiplication of the image after the above operation and the center line image;
[0066] S24: Binarizing the dot product image according to a preset threshold value to further optimize the center line.
[0067] The centerline obtained by the refinement algorithm can only approximate the centerline of the target area, but further optimization is needed to improve the accuracy of narrow area detection.
[0068] Among them, after processing in step S22, the pixel value near the center line of the target area of the image is the highest, the closer to the boundary, the lower the pixel value, and the pixel value of the non-target area is 0. It is multiplied by the initial extracted center line image and then binarized to obtain a more accurate center line of the target area. In fact, after the image is multiplied, it is equivalent to giving a weight to each point on the center line, and filtering out points whose weights are lower than the preset threshold.
[0069] The complex image to be detected is converted into the center line of the target area through the center line extraction algorithm, which provides conditions for the subsequent narrow area detection step and handles various noise interferences that occur in actual situations well.
[0070] Among them, in step 21, the center line is extracted based on the thinning algorithm as follows: Step 1, traverse the pixels with a pixel value of 1 in the image, and mark the pixel points that meet the following four conditions at the same time: (1) the sum of the pixel values of the pixel points in a circle around the target pixel is greater than or equal to 2 and less than or equal to 6, (2) the pixel values of the surrounding pixels change from 0 to 1 once, (3) at least one of the three pixel points above, right, and below the target pixel is 0, (4) at least one of the three pixel points to the right, bottom, and left of the target pixel is 0; Step 2, after the traversal is completed, the pixel value of the marked pixel point is set to 0; Step 3, repeat step 1, but the condition (3) is different from condition (4): (3) at least one of the three pixel points to the left, top, and right of the target pixel is 0, (4) at least one of the three pixel points below, left, and top of the target pixel is 0; Step 4, after the traversal is completed, the pixel value of the marked pixel point is set to 0; Step 5, repeat steps 1 to 4 until no new pixel points are marked. The thinning algorithm extracts the center line by corroding the image from the boundary of the target area, removing the redundant boundary points of the target area, and retaining important points that may contain information, such as connection points and endpoints, through four conditions.
[0071] In some embodiments of the present invention, Figure 3 As shown, step S3 includes:
[0072] S31: Starting from a point on the center line, find a point on the center line that is a distance a from the point, where a is a preset narrow area judgment threshold;
[0073] S32: Divide the rectangular area according to the line connecting the point and the found point, and the rectangle is composed of two squares with a side length of a on both sides of the line, such as Figure 6 As shown in the right figure;
[0074] S33: Starting from the point found, repeat S501 to S502 until no more such points can be found.
[0075] In a specific embodiment of the present invention, after the rectangular area is divided using the point as the starting point, it is saved in the container. Whenever a new point with a distance a from the starting point is found, it is necessary to first determine whether the point already exists in the container to prevent repeated division of the rectangular area and cause the program to fall into an infinite loop. The present invention sets continuous rectangular areas on the center line through this method, and can complete the reasonable division of the rectangular area even in complex scenes such as bends, branches, and closed loops, thereby improving the robustness and accuracy of narrow area detection.
[0076] In some embodiments of the present invention, Figure 4 As shown, step S4 includes:
[0077] S41: Obtain the coordinates of all points on both sides of each rectangular area by calculation;
[0078] S42: traverse the rectangular area, substitute the coordinates of the points on the wide side into the image to be detected, and determine the relationship between the wide side and the target area;
[0079] S43: If the wide side extends beyond the target area, the rectangular area is considered to be a narrow area.
[0080] The rectangular area is composed of two squares with known side lengths, and the intersection of the two squares is also known. The coordinates of the points on the wide side of the rectangle can be easily obtained by calculation. The image to be detected has been binarized by step S1, so it can be judged whether the point is in the target area by the pixel value of the corresponding coordinate. The present invention only judges the narrow area by simply calculating the wide side of the rectangular area, which can greatly reduce the calculation complexity and effectively improve the efficiency of detection.
[0081] In summary, the present invention extracts the center line from the image to obtain the key information of the target area, thereby making the subsequent narrow area detection more efficient. The present invention divides the continuous rectangular area to cover all the center lines, and uses whether the two wide sides outside the rectangular area extend outside the target area to judge the narrow area, which simplifies the complex rules of narrow area detection, provides higher accuracy and greatly improves the efficiency of narrow area detection.
[0082] Embodiment 2
[0083] This embodiment provides a narrow area detection method based on centerline extraction, including:
[0084] Perform image preprocessing on the image to be detected;
[0085] The center line of the target area in the image to be detected is extracted by a center line extraction algorithm;
[0086] Divide continuous rectangular areas on the center line;
[0087] Whether the area is a narrow area is determined based on whether the two widths outside the rectangular area are within the target area.
[0088] In this embodiment, a continuous rectangular area is set, including:
[0089] Step 1: Take any point on the center line as the starting point and find a point on the center line that is a distance b from the starting point; where b is the preset distance;
[0090] Step 2: Figure 6 As shown in the left figure, two specific rectangles with the starting point and the line connecting the found point as the dividing line form a rectangular area. If multiple points are found, multiple rectangular areas are divided. Among them, the length of one side where the specific rectangle overlaps with the connecting line is b, and the length of the other side is a, where a is the narrow area judgment threshold.
[0091] Step 3: Use the found point as the new starting point and repeat steps 1 to 2 until there is no point on the center line that is a distance b from the starting point.
[0092] It should be noted that the preset distance b may be greater than the narrow area judgment threshold a, or may be less than the narrow area judgment threshold a. The preset distance b may be set according to actual needs. For example, if the center line is relatively straight, a larger b may be set. In particular, if the preset distance b is equal to the narrow area judgment threshold a, it is the situation in the first embodiment.
[0093] Embodiment 3
[0094] like Figure 8 The figure is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server, or a server cluster composed of multiple servers) that can execute programs. The computer device 20 of this embodiment includes at least but is not limited to: a memory 21 and a processor 22 that can communicate with each other via a system bus, such as Figure 8 It should be pointed out that Figure 8 Only computer device 20 is shown with components 21 - 22 , but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0095] In this embodiment, the memory 21 (i.e., readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM). The memory 21 can also be an external storage device of the computer device 20, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 20. Of course, the memory 21 can also include both the internal storage unit of the computer device 20 and its external storage device. In this embodiment, the memory 21 is generally used to store the operating system and various application software installed on the computer device 20, such as the program code of the narrow area detection method based on centerline extraction in the method embodiment. In addition, the memory 21 can also be used to temporarily store various data that have been output or are to be output.
[0096] The processor 22 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 22 is generally used to control the overall operation of the computer device 20. In this embodiment, the processor 22 is used to run the program code stored in the memory 21 or process data, such as running a device storing the program code of the narrow area detection method based on centerline extraction, so as to implement the narrow area detection method based on centerline extraction in the method embodiment.
[0097] Embodiment 4
[0098] The present application also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, and the program realizes the corresponding function when executed by the processor. The computer-readable storage medium of this embodiment is used to store the program code of the narrow area detection method based on centerline extraction, and when executed by the processor, the narrow area detection method based on centerline extraction of the method embodiment is realized.
[0099] In summary, the present invention proposes a method, device and medium for narrow area detection based on centerline extraction, the method comprising: preprocessing the image to be detected; obtaining the centerline of the target area in the image to be detected by extracting the centerline algorithm; dividing a continuous rectangular area composed of two squares to cover all the centerlines, and taking the line connecting the two points on the centerline as the intersection of the two squares; judging whether the area is a narrow area according to whether the two widths on the outside of the rectangular area are in the target area. The present invention simplifies the complex target area into a centerline by an image processing method, and judges the narrow area according to whether the widths on both sides of the rectangular area set on the centerline are in the target area. While ensuring high accuracy, it also effectively reduces the computational complexity of narrow area detection and improves the efficiency of narrow area detection.
[0100] Compared with existing traditional image methods, it performs more reliably in complex scenes, and compared with deep learning methods, it does not require a large amount of computing resources and labeled data support, and can be directly applied to multiple fields such as roads, rivers, and circuits.
[0101] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0102] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0103] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.
[0104] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0105] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0106] It should be pointed out that, according to the needs of implementation, the various steps / components described in this application can be split into more steps / components, and two or more steps / components or partial operations of steps / components can be combined into new steps / components to achieve the purpose of the present invention.
[0107] It will be easily understood by those skilled in the art that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A narrow area detection method based on centerline extraction, characterized in that: The method includes: Perform image preprocessing on the image to be detected; Extract the center line of the target area in the image to be detected; Divide continuous rectangular areas on the center line; Whether the area is a narrow area is determined based on whether the two widths outside the rectangular area are within the target area.
2. The method for detecting narrow areas based on centerline extraction according to claim 1, characterized in that: Perform image preprocessing on the image to be detected, including: The image to be detected is binarized, the pixel value of the target area is set to 1, and the pixel value of the non-target area is set to 0.
3. The method for detecting narrow areas based on centerline extraction according to claim 2, characterized in that: The image to be detected is converted into a grayscale image, then binarized, and the binarized image is closed.
4. The method for detecting narrow areas based on centerline extraction according to claim 2, characterized in that: The center line of the target area in the image to be detected is extracted based on the center line extraction algorithm, including: Extract the center line of the target area in the image to be detected based on the thinning algorithm to obtain a center line image; Perform inversion and distance transformation operations on the binary image; Perform a dot product of the image after the inversion and distance transformation operations and the center line image to obtain a dot product image; The dot product image is binarized according to a preset threshold to obtain the center line.
5. The method for detecting narrow areas based on centerline extraction according to claim 4, characterized in that: Extract the center line of the target area in the image to be detected based on the thinning algorithm, including: Step 1: Traverse the pixels with a pixel value of 1 in the binary image and mark the pixels that meet the following four conditions at the same time: (1) the sum of the pixel values of the pixels around the target pixel is greater than or equal to 2 and less than or equal to 6; (2) the pixel values of the pixels around the target pixel change from 0 to 1 once; (3) at least one of the three pixels above, to the right, and below the target pixel is 0; (4) at least one of the three pixels to the right, below, and to the left of the target pixel is 0; Step 2: After the traversal is completed, the pixel value of the marked pixel is set to 0; Step 3: Repeat step 1, but condition (3) is different from condition (4): (3) at least one of the three pixels to the left, above, and right of the target pixel is 0; (4) at least one of the three pixels below, left, and above the target pixel is 0; Step 4: After the traversal is completed, the pixel value of the marked pixel is set to 0; Step 5: Repeat steps 1 to 4 until no new pixels are marked.
6. The method for detecting narrow areas based on centerline extraction according to claim 1, characterized in that: Divide the continuous rectangular area on the center line, including: Step 1: Take any point on the center line as the starting point and find a point on the center line that is a distance b from the starting point; where b is the preset distance; Step 2: two specific rectangles with the starting point and the line connecting the found point as the dividing line form a rectangular area. If multiple points are found, multiple rectangular areas are divided; wherein the length of one side of the specific rectangle overlapping the line is b, and the length of the other side is a, where a is the narrow area judgment threshold; Step 3: Use the found point as the new starting point and repeat steps 1 to 2 until there is no point on the center line that is a distance b from the starting point.
7. The method for detecting narrow areas based on centerline extraction according to claim 6, characterized in that: The preset distance b is the narrow area judgment threshold a.
8. The method for detecting narrow areas based on centerline extraction according to claim 1, characterized in that: Whether the area is a narrow area is determined based on whether the two widths outside the rectangular area are within the target area, including: Obtain the coordinates of all points on the two wide sides of each rectangular area by calculation; Traverse the rectangular area, bring the coordinates of the points on the wide edge into the image to be detected, and determine the relationship between the wide edge and the target area; If the wide side extends beyond the target area, the rectangular area is considered to be a narrow area.
9. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the narrow area detection method based on centerline extraction described in any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the steps of the narrow area detection method based on centerline extraction described in any one of claims 1 to 8 are implemented.
