A method and system for detecting surface defects of plastic pipes and a storage medium

By calculating the displacement vector between adjacent frames and aligning feature points, combined with gradient compensation and image stitching, the image blurring problem caused by equipment jitter was solved, achieving high-precision, panoramic coverage detection of surface defects in plastic pipes.

CN122391176APending Publication Date: 2026-07-14HENAN QINGLONG PLASTIC PIPE IND CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HENAN QINGLONG PLASTIC PIPE IND CO LTD
Filing Date
2026-05-07
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

During the production of plastic pipes, due to image blurring caused by equipment vibration and camera field of view limitations, existing technologies struggle to achieve high-precision, panoramic defect detection, which can easily lead to missed detections and misjudgments.

Method used

A blurred region distribution map is generated by calculating the displacement vector between adjacent frames. Clear feature points are identified for spatial alignment. The information of clear feature points and blurred regions are fused. Image stitching is performed using gradient compensation and matching point sets of adjacent frames. Correction is performed by combining detection confidence screening.

Benefits of technology

It significantly improves the clarity and integrity of defect edges, eliminates abrupt transitions at splicing boundaries, avoids misjudgment of long strip defects, and improves the accuracy and robustness of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122391176A_ABST
    Figure CN122391176A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of automatic industrial detection, and discloses a plastic pipe surface defect detection method and system and a storage medium, which comprises the following steps: acquiring continuous images, positioning a motion-blurred defect edge area and calculating an interframe displacement vector; extracting adjacent frame image features, mapping to generate an initial contour and fusing and enhancing the initial contour with a current frame; calculating a local gradient, extracting a compensation gradient from an adjacent frame, and superimposing to generate an intermediate image; cross-frame matching is performed on defect edge high-gradient feature points, and a complete pipe panorama image is spliced; the panorama image is input into a pre-trained model to detect defects, and low-confidence results are corrected by using adjacent frame information. The application effectively overcomes image blurring and field splitting caused by industrial vibration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated industrial inspection technology, and in particular to a method, system and storage medium for detecting surface defects in plastic pipes. Background Technology

[0002] In modern pipe manufacturing, the surface quality of plastic pipes directly affects their pressure-bearing capacity and service life. Therefore, automated detection of surface defects such as scratches, cracks, and dents has become a key aspect of quality control. However, in actual continuous extrusion production lines, the mechanical operation of the traction equipment inevitably generates high-frequency vibrations, coupled with the continuous high-speed movement of the pipes, making it easy for the visual acquisition equipment deployed on the production line to capture images with localized motion blur.

[0003] Furthermore, traditional machine vision inspection solutions typically employ a single-frame independent processing mode. When faced with edge blurring or texture distortion caused by jitter, they often fail to extract a coherent defect contour, resulting in serious missed detections.

[0004] Furthermore, due to the limited physical field of view of industrial cameras, a single frame image can often only cover a local area of ​​the pipe surface. For long, multi-frame scratch defects, direct local identification not only leads to the same defect being counted separately, but also, when existing deep learning detection models encounter suspected defects with unclear boundaries, they often output low-confidence erroneous results and lack self-correction mechanisms. This results in unreliable reports with blind spots or misjudgments directly entering the downstream quality control process, making it difficult to meet the stringent inspection requirements of modern production lines for high precision, high stability, and panoramic coverage. Summary of the Invention

[0005] To address the aforementioned technical problems, this application provides a method, system, and storage medium for detecting surface defects in plastic pipes, enabling high-precision detection of surface defects in plastic pipes.

[0006] In a first aspect, this application provides a method for detecting surface defects in plastic pipes, the method comprising: Step S1: Acquire a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas according to the comparison result of the displacement vector and the preset threshold, and generate a blurred area distribution map; Step S2: Based on the blurry area distribution map, identify the less affected areas, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets the preset conditions as the base image for repair. Step S3: Fuse the clear feature points in the repair base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image; Step S4: Calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than a preset gradient threshold, extract supplementary gradient information from adjacent frames and perform superposition compensation to obtain an intermediate image with improved edge clarity. Step S5: Extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than a preset stitching threshold, and stitch multiple frames of images based on the set of matching points to obtain a complete image of the plastic pipe surface. Step S6: Input the complete plastic pipe surface image into the pre-trained defect detection model to identify potential defects. For identification results with a detection confidence level lower than the preset confidence threshold, correct them using the corresponding region information of adjacent frames to obtain the final defect-annotated image.

[0007] Secondly, this application provides a detection system for surface defects in plastic pipes, the system comprising: The distribution map generation unit is used to acquire a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas according to the comparison result of the displacement vector and a preset threshold, and generate a blurred area distribution map. The basic image restoration unit is used to identify less affected areas based on the blurry area distribution map, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets a preset condition as the restoration base image. The edge image enhancement unit is used to fuse the clear feature points in the repair base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image; The intermediate image acquisition unit is used to calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than a preset gradient threshold, supplementary gradient information is extracted from adjacent frames and superimposed for compensation to obtain an intermediate image with improved edge clarity. The surface image acquisition unit is used to extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than a preset stitching threshold, and stitch multiple frames of images based on the set of matching points to obtain a complete surface image of the plastic pipe. The defect image annotation unit is used to input the complete plastic pipe surface image into a pre-trained defect detection model, identify potential defects, and correct the identification results with a detection confidence level lower than a preset confidence threshold by using the corresponding region information of adjacent frames to obtain the final defect annotation image.

[0008] A third aspect of this application provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the aforementioned method for detecting surface defects in plastic pipes.

[0009] Compared with the prior art, the beneficial effects of the present invention are at least as follows: This application uses a local dynamic deblurring mechanism in the spatiotemporal dimension and an edge cross-frame reconstruction mechanism to accurately locate the blurred and incomplete areas caused by device jitter. It also cleverly utilizes the clear features of adjacent frames for skeleton fusion and gradient superposition compensation, thereby effectively overcoming the drawback of traditional single-frame deblurring algorithms that are prone to losing details and significantly improving the clarity and integrity of defect edges under dynamic conditions.

[0010] Secondly, this application innovatively uses high-gradient feature points as natural cross-frame markers based on the edge-enhanced image, and combines matching point coverage evaluation to achieve accurate coordinate mapping and weighted stitching of multi-frame local images. This successfully breaks the limitations of the camera's physical field of view, not only eliminating the abrupt transition of the stitching boundary, but also fundamentally avoiding the risk of misjudging long strip cross-frame defects by cutting them apart, and generating a geometrically coherent panoramic image of the surface.

[0011] Finally, this application breaks through the limitations of the traditional AI model's "one-time black-box decision-making". By introducing a detection confidence screening and a secondary correction mechanism for cross-frame corresponding area information, the system is given the ability to automatically identify and repair defects with unclear edges. At the same time, by combining the clarity and accuracy of the detection results for evaluation, automatic feedback and closed-loop optimization for unreliable results are realized, which greatly improves the accuracy and robustness of the detection results in complex industrial environments. Attached Figure Description

[0012] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart illustrating the steps of a method for detecting surface defects in plastic pipes according to an embodiment of this application. Figure 2 This is a schematic diagram of adjacent frames in a continuous image sequence in an embodiment of this application; Figure 3 This is a structural diagram of a plastic pipe surface defect detection system according to an embodiment of this application. Detailed Implementation

[0014] This application provides a method, system, and storage medium for detecting surface defects in plastic pipes. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0015] Example 1: For ease of understanding, the specific process of the embodiments of this application is described below, such as... Figure 1 The method for detecting surface defects in plastic pipes shown in the embodiments of this application includes: Step S1: Collect a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas based on the comparison result of the displacement vector and the preset threshold, and generate a blurred area distribution map.

[0016] The step S1 of generating a fuzzy region distribution map includes: targeting, for example... Figure 2 In the continuous image sequence shown, adjacent frames are used to calculate the displacement vector between adjacent frames using a displacement estimation method. Based on the distribution of the displacement vector, regions whose displacement vectors continuously exceed a preset threshold are identified as blurred regions. These blurred regions are then marked and statistically analyzed to generate a blurred region distribution map. The calculation of the displacement vector between adjacent frames involves dividing the image into multiple regions and calculating the positional offset of each region in adjacent frames. The positional offset of each region is determined by finding the region with the smallest change in grayscale value between two adjacent frames. The positional offsets of all regions are then summed to obtain the inter-frame displacement vector. Regions continuously exceeding the preset threshold refer to regions that exceed the preset threshold between a set number of consecutive adjacent frames, such as two or more consecutive frames. Furthermore, dividing the image into multiple regions can be done by proportionally dividing the image into grids based on the expected physical size of the defect or the camera resolution, for example, dividing it into 16×16 pixel image blocks.

[0017] Specifically, in the high-speed continuous production process of plastic pipes, the relative motion between the industrial camera and the pipe surface, especially the unavoidable vibration during equipment operation, will cause local motion blur in the acquired single-frame images. This blurring phenomenon directly masks the geometric edge features of defects such as tiny cracks and scratches on the pipe surface, which is the core technical obstacle causing missed defects and misjudgments.

[0018] To address the aforementioned issues, this application does not perform blind global deblurring on the images. Instead, it analyzes the spatiotemporal variation patterns between consecutive image sequences to explicitly identify areas of image quality degradation caused by jitter in a spatial dimension, providing a precise spatial operation mask for subsequent cross-frame information compensation and restoration.

[0019] In practice, the first step is to acquire a sequence of images of the plastic pipe surface continuously captured by a high-speed industrial camera. This sequence records visual information of the same surface area of ​​the pipe at high temporal resolution. Adjacent frames are highly correlated in spatial content, but the image clarity varies due to instantaneous jitter. To quantify this spatiotemporal difference, the inter-frame motion information of each pair of adjacent frames in the sequence needs to be calculated. The calculation process divides the image into several spatial regions and estimates the positional offset of each region between adjacent frames. This estimation is based on the fact that the reflectivity of the same physical point on the surface remains approximately unchanged within a short time interval. Therefore, by searching for positional matching relationships in adjacent frames that minimize the sum of pixel grayscale value changes in the corresponding region, the positional offset of that region can be determined. The positional offsets of all local regions are summarized to form a set that can characterize the amplitude and direction of motion of the entire image at different spatial positions. This set is defined as an inter-frame displacement vector field, where each vector carries its regional position coordinates in the image.

[0020] After obtaining the displacement vector field between each pair of adjacent frames, for a given image region, its motion state at multiple consecutive time nodes needs to be tracked in order to distinguish between continuous motion and occasional jitter. Specifically, for a region in the displacement vector field calculated in frame t and frame t+1, the displacement vector magnitude of that region between multiple pairs of adjacent frames, such as frame t-1 and frame t, frame t and frame t+1, and frame t+1 and frame t+2, is obtained. Only when the displacement vector magnitude of that region exceeds a preset threshold in a preset number of consecutive time nodes, such as in the calculation of at least two or three consecutive adjacent frame pairs, is it determined that the region has experienced continuous, high-speed relative sliding sufficient to cause blurring in frame t and frame t+1, and the region is marked as a blurred region. By performing this spatiotemporal continuity determination on all regions of the entire frame image, a blurred region distribution map is finally generated. This process, by introducing consistency constraints from multi-frame observations, eliminates misjudgments caused by occasional jitter in a single frame, and accurately transforms the physical phenomenon of motion blur into a spatialized blur mask.

[0021] By judging and marking the position of all pixels in the entire frame image one by one according to the spatiotemporal continuity criterion, a blurry region distribution map corresponding to the original image space is finally generated. In this distribution map, the marked blurry regions are the target positions that need to be repaired by relying on the information of adjacent clear frames in subsequent processing. This process transforms the physical phenomenon of motion blur into an image processing problem that can be accurately described and located by a mathematical model, laying a reliable data processing foundation for the entire detection method.

[0022] Inter-frame displacement vectors are used to quantify image shifts caused by equipment jitter or pipe movement. A preset threshold is a decision threshold to tolerate slight motion, measured as the magnitude of the displacement vectors within each region of the displacement vector field, i.e., the absolute physical distance of the relative sliding of that region between adjacent image frames, in pixels. This preset threshold is set based on the sensitivity requirements of defect detection: if the detection of minute defects of a certain size is required, the allowable image blur length should be much smaller than the feature scale of the defect. A feasible setting is to set the preset threshold as a fraction of the defect feature scale. When the smallest defect of interest occupies several pixels in the image, the empirical range for the preset threshold is 1 to several pixels. For high-speed production lines, since the vibration amplitude may be greater under the same exposure time, to maintain the same defect detection sensitivity, the preset threshold should be kept at the same or more stringent level as that of low-speed production lines. When the magnitude of the displacement vector corresponding to a certain region is greater than the preset threshold, the motion amplitude of that region is determined to be sufficient to cause image blur, and it is thus marked as a blurred region. The blurred region distribution map is used to avoid blurred regions in subsequent processing, thereby improving the reliability of feature extraction.

[0023] Step S2: Based on the distribution map of blurred areas, identify areas that are less affected, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets the preset conditions as the base image for repair.

[0024] In step S2, extracting clear feature points from adjacent frames includes: traversing the distribution map of blurred regions, identifying regions that are not marked as blurred or whose displacement vectors are less than a preset threshold as regions less affected; and extracting points with grayscale gradient values ​​higher than a preset gradient threshold as clear feature points within regions less affected.

[0025] In step S2, spatial alignment of clear feature points based on displacement vectors and selection of a set of feature points whose positional consistency meets preset conditions between adjacent frames includes: using a feature alignment method to calculate the positional offset of clear feature points in adjacent frames, and performing reverse offset correction based on displacement vectors to map clear feature points in different frames to the same coordinate system to complete spatial alignment; connecting adjacent and oriented feature points based on the aligned clear feature points to construct a preliminary outline of the defect area; statistically analyzing the frequency of occurrence and positional changes of feature points in multiple frames, selecting a set of feature points that repeatedly appear in multiple frames and whose positional changes are less than a preset offset threshold as the set of feature points whose positional consistency meets preset conditions, and using the selected set of feature points as the base image for repair.

[0026] Specifically, in the detection of surface defects in plastic pipes, motion blur causes the loss of defect features in the current frame, which cannot be fundamentally repaired by the single-frame image itself. To solve this problem, this application discards the blurred information of the current frame and instead extracts stable defect features from adjacent clear frames. It uses the previously obtained displacement vector as the basis for spatial correction to unify these clear features across frames into the current coordinate system, thereby constructing a repair base image containing only reliable defect information, providing an accurate feature framework for subsequent image fusion and enhancement.

[0027] In specific implementation, the method first clarifies the effective spatial range of feature extraction. By traversing the fuzzy region distribution map generated in step S1, areas labeled as non-fuzzy, i.e. not marked as fuzzy in S1, are identified as less affected areas. These areas are clearly imaged in the corresponding frames and have the basic conditions for extracting reliable feature points. Subsequently, clear feature points are extracted in the less affected areas. The extraction method is as follows: for each pixel, the gradient operator is used to calculate the gradient magnitude of its grayscale change. Points with gradient magnitude values ​​higher than a preset gradient threshold are selected as clear feature points. This threshold is measured in units of grayscale value per pixel and is empirically set to a range of 10 to 30 on an 8-bit grayscale image. These feature points correspond to the edge positions of defects on the pipe surface.

[0028] Since there is a spatial offset between the image coordinate systems of different frames, the inter-frame displacement vector field calculated in step S1 needs to be used for spatial alignment. Specifically, for each clear feature point, the coordinates of the feature point are reverse offset corrected according to the displacement vector corresponding to the region in the inter-frame displacement vector field, so as to uniformly map the feature points extracted from different frames to the same coordinate system of the current frame.

[0029] After alignment, based on the spatial distribution of feature points, adjacent feature points with the same direction are preferentially connected to form an internal reference structure describing the direction of the defect. On this basis, spatiotemporal consistency screening is performed: the occurrence of each feature point in N consecutive adjacent frames is tracked, and its occurrence frequency and position changes are statistically analyzed. Feature points with an occurrence ratio reaching a preset frequency threshold and whose Euclidean distance fluctuation after alignment between frames is always less than a preset offset threshold, such as 1 to 3 pixels, are selected. These feature points constitute a set of feature points whose positional consistency meets the preset conditions. This set is a structured feature point set in terms of data form, recording the spatial coordinates and attributes of each clear feature point. This application collectively refers to it as the repair base image. This feature point set preserves reliable contour information of the defect area, serving as a precise spatial reference for weighted fusion with the blurred pixels of the current frame in subsequent steps.

[0030] Clear feature points are points in an image with significant grayscale changes. Clear feature points are obtained by traversing the less affected areas, calculating the grayscale gradient value of each pixel, and selecting points whose grayscale gradient values ​​are higher than a preset gradient threshold. Clear feature points are extracted from multiple frames of images to ensure the number of feature points.

[0031] The feature alignment method calculates the positional offset of sharp feature points in adjacent frames and performs reverse offset correction based on the displacement vector, mapping sharp feature points in different frames to the same coordinate system, thus ensuring the positional consistency of feature points between different frames.

[0032] The initial outline of the defective region is formed by connecting adjacent aligned, clear feature points. When connecting, priority is given to connecting feature points that are close in distance and have the same direction to form a closed or semi-closed outline. When multiple feature points are concentrated in a specific area and are linearly distributed, it is determined that the area has a defect and the corresponding initial outline is constructed. It should be noted that the specific area here is not a fixed grid position predefined on the current frame image, but a spatial range dynamically identified after feature point alignment through cluster analysis or spatial density evaluation. The formation of this area must simultaneously meet two conditions: first, a sufficient number of aligned feature points are spatially adjacent to each other; second, the distribution direction of these adjacent points has a linear trend. Once both conditions are met in a certain local area, it is determined that the specific area has a defect, and the feature points in the area are connected to form the corresponding initial outline.

[0033] The feature point set with consistency higher than the preset condition is the set of feature points that appear repeatedly in multiple frames of images and whose position changes are less than the preset offset threshold; the screening process is completed by statistically analyzing the frequency of occurrence and position stability of feature points in multiple frames, and prioritizing the retention of feature points that are stable in multiple frames; the repair base image is an image containing the preliminary outline of the defect area, and the feature point set in the repair base image is used to provide a reference for subsequent image enhancement processing to reduce the interference of blurred areas on defect detection.

[0034] Step S3: Fuse the clear feature points in the repair base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image.

[0035] Step S3 further includes: obtaining clear feature points in the repair base image as reference data, and extracting pixel information in the blurred area from the current frame as auxiliary data; using a weighted superposition method to fuse the clear feature points and the pixel information in the blurred area to generate a preliminary defect edge image, wherein the clear feature points are given a higher weight than the pixel information in the blurred area; and performing detail optimization to enhance the grayscale contrast of the edge area on the preliminary defect edge image to obtain an enhanced defect edge image.

[0036] Specifically, in the detection of surface defects in plastic pipes, the repair base image generated by the above steps provides a clear feature contour of the defect area, but this contour is only composed of feature points and lacks complete regional pixel information. While the blurred area of ​​the current frame is not clear enough, it may still retain local grayscale traces of the defect. To solve the technical problem of how to effectively integrate these two types of heterogeneous information to generate an image with both accurate and complete defect edges, this application proposes a defect edge reconstruction method based on weighted fusion and contrast enhancement: the clear feature points in the repair base image are used as high-confidence reference data, and the pixel information of the blurred area of ​​the current frame is used as supplementary auxiliary data. By assigning different weights, the images are fused, and while prioritizing the accuracy of defect localization, the edge details are restored as much as possible, thereby generating a defect edge image with significantly improved quality.

[0037] In practice, the generated base image for repair is first acquired, and all clear feature points are extracted from it as the main reference data. These feature points are stored in coordinate form, which accurately reflects the position and geometric orientation of the defect area in space. At the same time, the current frame image is traversed, and the pixel gray values ​​in the blurred areas are extracted as auxiliary data based on the blurred area distribution map generated in step S1. Although the auxiliary data has lower clarity, it may contain subtle gray-scale change information of the defect edge. Subsequently, a weighted overlay strategy based on pixel position is used to fuse the two types of data.

[0038] In the fusion process, based on the location of clear feature points, the precise location information of the feature points is assigned a first weight, and the pixel grayscale information extracted from the corresponding location of the blurred region in the current frame is assigned a second weight. The two weights are then superimposed in the image space. The first weight is set to be significantly higher than the second weight; for example, the first weight... The value range is [0.7, 0.9], the second weight. The value range is [0.1, 0.3], and This ensures that the fusion result preferentially inherits the high-precision position information carried by clear feature points, avoiding interference from the uncertainty of the blurred area to the defect localization; at the same time, the second weight can supplement the gray-scale change details remaining in the blurred area, making the defect edge more visually complete; through this weighted superposition operation, a preliminary defect edge image is generated, in which the outline of the defect is dominated by high-weight feature points, while the edge details are filled by the information of the blurred area.

[0039] After generating the initial defect edge image, further detail optimization is performed to obtain an enhanced defect edge image. The optimization process includes enhancing the grayscale contrast of the defect edge region, specifically by increasing the grayscale value of the defect edge pixels while decreasing the grayscale value of the surrounding non-edge regions, making the grayscale difference at the edge more significant and the contour more prominent. This optimization process can also be combined with local image smoothing techniques to suppress random noise in non-edge regions, preventing noise from being mistakenly enhanced and interfering with subsequent analysis. Finally, the enhanced defect edge image is output, which retains the accurate positioning of clear feature points and supplements usable details in blurred areas, providing high-quality input for local gradient analysis and further improvement of edge sharpness in the following sections.

[0040] Clear feature points are feature points in the set of feature points in the base image with a consistency higher than the preset condition. Clear feature points are stored in coordinate form, and each clear feature point contains the horizontal and vertical coordinate information in the image, which is used to reflect the location and shape of the defect area.

[0041] The pixel information within the blurred region is obtained by traversing the current frame image and filtering out the pixel grayscale values ​​of the regions marked as blurred in the blurred region distribution map. The pixel information within the blurred region contains some details of the defect region.

[0042] The initial defect edge image is generated by thresholding the gray values ​​of the fused pixels to highlight the gray value differences at the edge of the defect area. Detail optimization is achieved by enhancing the gray value contrast of the defect edge area, specifically by increasing the gray value of the defect edge pixels and decreasing the gray value of the surrounding non-edge areas. The optimization process combines local image smoothing techniques to reduce noise interference in non-edge areas.

[0043] Step S4: Calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than the preset gradient threshold, extract supplementary gradient information from adjacent frames and perform superposition compensation to obtain an intermediate image with improved edge clarity.

[0044] The process of obtaining the intermediate image with improved edge sharpness in step S4 includes: calculating the local gradient value of each pixel by comparing the gray value difference between each pixel in the enhanced defect edge image and the surrounding pixels; identifying the region with a local gradient value lower than a preset gradient threshold as the region to be compensated; extracting the gradient information corresponding to the region to be compensated from adjacent frames as supplementary gradient information; weighting and superimposing the supplementary gradient information with the gradient value of the current frame to generate an image with richer edge details; and smoothing the image with richer edge details to obtain the intermediate image with improved edge sharpness.

[0045] Specifically, in the detection of defects on the surface of plastic pipes, the enhanced defect edge image has initially reconstructed the outline of the defect. However, due to the limitations of the blurred area information in the current frame, the details of some defect edges may still not be sharp enough. Specifically, the local gray-scale gradient of some edge pixels is weak, resulting in insufficient prominence of edge features.

[0046] To address this issue, this application treats the insufficiently represented edge gradient in a single-frame image as a signal deficiency that can be compensated for by information from adjacent clear frames. By superimposing gradient information in the spatiotemporal dimensions, weak edges are strengthened, thereby obtaining an intermediate image with significantly improved edge clarity.

[0047] In practice, this method first performs local gradient analysis on the enhanced defect edge image. It then iterates through each pixel in the image, calculating the local gradient value by comparing the grayscale value difference between the pixel and its surrounding pixels. The calculation comprehensively considers grayscale changes in the four directions (up, down, left, and right) to arrive at a gradient value that characterizes the severity of the grayscale change at that location. Pixels located on the true edge of the defect typically exhibit higher gradient values, while blurred residues or noisy areas show relatively lower gradient values. After calculation, the local gradient value of each pixel is compared with a preset gradient threshold. This threshold is set based on the image resolution and the saliency of the typical features of the defect to be detected, and is used to distinguish between sufficiently clear edges and weak edges that need compensation. Any area with a local gradient value lower than the preset gradient threshold is identified as a region to be compensated, indicating that the edge features of that region in the current frame are insufficient and need to be enhanced using information from other frames.

[0048] For these areas to be compensated, gradient information corresponding to the spatial location is extracted from adjacent frame images as supplementary gradient information. The extraction process requires spatial alignment based on the displacement vector calculated in step S1 or step S2. The basis for extraction is that, due to the randomness of inter-frame jitter, a blurred area in the current frame may be at the moment of clear imaging in an adjacent frame, and its corresponding position contains richer edge details and higher gradient values. The pixel position in the adjacent frame that matches the coordinates of the area to be compensated is located, and the local gradient value at that position is extracted as supplementary information. Subsequently, the supplementary gradient information is superimposed with the gradient value of the current frame in a weighted manner. During the weighting process, the weights are dynamically assigned according to the sharpness level of the adjacent frames. For example, the sharpness level is achieved using the Tenengrad gradient accumulation function or the image variance value. If the imaging sharpness of the corresponding area in the adjacent frame is higher, the supplementary gradient information is given a higher weight to ensure that the superposition result inherits the edge details of the clear frame to the greatest extent. Through this superposition operation, an image with richer edge details is generated, and the originally weak defect edges become more significant due to the addition of supplementary information.

[0049] Finally, the image with richer edge details is smoothed to reduce random noise that may be introduced during the stacking process. The smoothing process is based on the average gray value of local pixels and only applies to non-edge areas where the gradient value is lower than the preset gradient threshold. This suppresses noise while avoiding weakening the enhanced defect edge features. The smoothed image is the intermediate image with improved edge clarity. In this image, the gray value changes of the defect edges are more distinct and the contours are more complete, providing a more reliable data foundation for feature point matching and image stitching in the following sections.

[0050] The local gradient value is calculated by comparing the gray value difference between each pixel and its surrounding pixels. The calculation method is to comprehensively consider the gray value changes in the four directions of the pixel (up, down, left, and right) to obtain a gradient value. The local gradient value is used to characterize the degree of gray value change of pixels in the image. The local gradient value of the defect edge region is higher than that of the non-edge region.

[0051] The preset gradient threshold is set according to the image resolution and the significance of the defect features. When the local gradient value of a certain pixel is lower than the preset gradient threshold, it indicates that the pixel is located in the edge region but the features are not obvious enough. The pixel information of the corresponding position should be extracted from the adjacent frame image as supplementary gradient information.

[0052] The overlay process uses a weighted average method, which combines the supplementary gradient information extracted from adjacent frames with the gradient value of the current frame to generate a new gradient value. The weights are adjusted according to the image sharpness of adjacent frames; the higher the sharpness of adjacent frames, the higher the weight is given to the supplementary gradient information.

[0053] Images with richer edge details are generated by updating the grayscale value of each pixel. Regions with gradient values ​​below the preset gradient threshold are enhanced by the addition of supplementary gradient information, and the grayscale changes at the defect edges are more significant. Smoothing is achieved based on the average grayscale value of local pixels. Grayscale values ​​are adjusted only for non-edge regions with gradient values ​​below the preset gradient threshold to reduce the influence of random noise and avoid affecting the defect edge features.

[0054] Step S5: Extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than the preset stitching threshold, and stitch multiple frames of images based on the matching point set to obtain a complete image of the plastic pipe surface.

[0055] The step S5, obtaining a complete plastic pipe surface image, includes: extracting pixels with gradient values ​​higher than a preset gradient threshold from the defect edge region of the intermediate image as candidate matching points; calculating the spatial distance and grayscale similarity between the candidate matching points and feature points in adjacent frames; selecting a set of matching points whose positional offset is less than a preset offset threshold and whose grayscale gradient value changes in the same trend across multiple frames; determining whether the distribution coverage of the matching point set within the defect region is higher than a preset stitching threshold; if the coverage is higher than the preset stitching threshold, performing weighted fusion of pixel information in corresponding regions of the multi-frame images based on the positional information of the matching point set to complete image stitching; and smoothing the stitching boundary of the stitched image to obtain a complete plastic pipe surface image.

[0056] Specifically, in the detection of surface defects in plastic pipes, although the intermediate images generated in the aforementioned steps have good edge clarity, single-frame images are limited by the physical field of view of the camera and often only cover a local area of ​​the pipe surface, failing to present complete information about the circumferential surface of the pipe. If defect detection is performed directly on the local images, long strip defects may be broken or missed due to the fragmented field of view.

[0057] To address this issue, this application uses high-gradient feature points in the defect edge region as natural markers for cross-frame matching, and utilizes the spatiotemporal stability and spatial distribution coverage of feature points across multiple frames as dual criteria for stitching reliability, thereby synthesizing multiple locally enhanced images into a single image of the plastic pipe surface with complete coverage and geometric coherence.

[0058] In practice, candidate matching points are first extracted from the intermediate image. These points are limited to the defect edge region of the image, and the selection criteria are that the gradient value of the pixel is higher than a preset gradient threshold. These points are usually corner or edge points with significant features on the defect contour that can be repeatedly detected, and have good cross-frame matching potential. Then, the candidate matching points of the current frame are matched with feature points of adjacent frames. The matching process comprehensively calculates two dimensions of information: spatial distance and gray-level similarity between the candidate matching points and the feature points of adjacent frames. Spatial distance is used to measure the proximity of two points in their respective image coordinate systems, and gray-level similarity is used to measure the approximation of the local gray-level distribution around the two points. Based on the above dual measures, the system selects feature points from adjacent frames that are spatially close to the candidate matching points and similar in gray-level distribution. Furthermore, it requires that such matching relationships are stable in multiple consecutive frames, that is, the positional offset of the matching point pair must be less than a preset offset threshold, and the trend of gray-level gradient value changes must be consistent across multiple frames. Feature point pairs that meet the above spatiotemporal consistency conditions are included in the matching point set.

[0059] After obtaining the matching point set, stitching is not performed immediately. Instead, the spatial distribution quality of the matching point set is evaluated. The evaluation index is the coverage rate of the matching point set within the defect area, i.e., the proportion of the defect edge area covered by the matching point set to the entire defect area. The calculated coverage rate is compared with a preset stitching threshold. Only when the coverage rate is higher than the preset stitching threshold does it indicate that the matching point set is sufficiently representative of the defect area in space, and the stitching operation has geometric reliability. After the condition is met, an inter-frame spatial transformation model is established based on the coordinate correspondence of the matching point set. The pixel information of corresponding areas in multiple frames is mapped to the same coordinate system for fusion. The fusion process adopts a weighted average method, and the weight of each frame image is dynamically allocated according to its sharpness. Frames with higher sharpness are given higher fusion weights to ensure that the stitched image retains the high-quality information in each frame to the maximum extent. After the multi-frame pixel fusion is completed, the stitching boundary area is smoothed. The gradual transition is achieved by adjusting the pixel grayscale values ​​at the stitching edge to eliminate stitching traces caused by differences in lighting conditions or grayscale response between different frames. Finally, a complete image of the plastic pipe surface is output.

[0060] Candidate matching points are pixels extracted from the defect edge region of the intermediate image whose gradient values ​​are higher than a preset gradient threshold. Candidate matching points are used to represent the shape and location features of the defect. The extraction process is completed by traversing the defect edge region and selecting pixels that meet the gradient value condition.

[0061] The set of matching points with consistency higher than the preset condition is a set of feature points whose positional offset is less than the preset offset threshold and whose gray-level gradient value changes in the multi-frame image are consistent; the screening process is achieved by calculating the spatial distance and gray-level similarity between feature points, and feature points that exist stably in the multi-frame image are retained first.

[0062] Coverage rate is the distribution ratio of the matching point set within the defect area. The preset stitching threshold is set according to the size and complexity of the defect area. When the coverage rate of the matching point set is higher than the preset stitching threshold, it indicates that the matching point set can represent the features of the defect area, and the image stitching operation is performed.

[0063] The image stitching operation is based on the position information of the matching point set, and merges the pixel gray values ​​of corresponding regions in different frames. The fusion process adopts a weighted average method, which assigns different weights according to the sharpness of each frame image. Frames with higher sharpness are given higher weights.

[0064] Boundary smoothing is achieved by adjusting the pixel grayscale values ​​at the edges of the splicing area. It gradually adjusts areas where grayscale values ​​change abruptly at the splicing point, making the boundary transition natural. The smoothing process is based on the average grayscale value of local pixels, ensuring that the grayscale changes of the splicing area are consistent with those of the surrounding areas.

[0065] Step S6: Input the complete surface image of the plastic pipe into the pre-trained defect detection model to identify potential defects. For the identification results with a detection confidence level lower than the preset confidence threshold, correct them using the corresponding region information of adjacent frames to obtain the final defect-annotated image.

[0066] The process of obtaining the final defect-annotated image in step S6 includes: inputting the complete plastic pipe surface image into a pre-trained defect detection model, outputting the location coordinates, type label, and corresponding detection confidence of each potential defect region; identifying regions with detection confidence below a preset confidence threshold as regions to be corrected, extracting pixel information corresponding to the regions to be corrected from adjacent frames, correcting the defect type or boundary of the regions to be corrected, and generating repaired defect annotations; performing cross-frame consistency checks on the repaired defect annotations, and using the images that pass the checks as the final defect-annotated images.

[0067] Specifically, after stitching together multiple frames of images to obtain a complete surface image of the plastic pipe, theoretically, the conditions for defect detection of the entire pipe are met. However, even a high-performance pre-trained defect detection model may still have uncertainties in its recognition results when faced with unclear boundaries due to residual blur, texture interference, or atypical defect morphology. This manifests as a low confidence level in the output detection. Directly accepting such low-confidence recognition results will introduce the risk of missed detections or misjudgments.

[0068] To address this issue, this application does not treat the defect detection model as a one-time decision-maker, but rather as a preliminary hypothesis generator. The confidence level of the model output is used as a quantitative indicator to judge the reliability of the recognition result. For unreliable recognition results, the corresponding spatial information in the original adjacent frame images is called again for secondary review and correction. Finally, the accuracy and stability of the output annotation results are ensured through cross-frame annotation consistency check.

[0069] In practice, a complete image of the plastic pipe surface is input into a pre-trained defect detection model. This defect detection model is a visual detection model based on a deep convolutional neural network. The training process is as follows: A large number of pipe surface images with different lighting conditions, different materials, and various defect types and combinations such as cracks, scratches, and dents are collected. The defect areas in each image are manually labeled with location coordinates and type labels to construct a training dataset. The training dataset is input into the constructed convolutional neural network model, and optimization algorithms such as stochastic gradient descent are used to iteratively update the weight parameters inside the model until the detection accuracy of the model on the validation set reaches the preset requirements. The trained model has the ability to automatically extract multi-level visual features from the input image and locate and classify potential defects. When a complete image of the plastic pipe surface is input into the model, the model performs forward inference calculations and outputs the location coordinates, type label, and a detection confidence score reflecting the credibility of the recognition for each potential defect area.

[0070] After obtaining the detection results, they are not directly used as the final annotation. Instead, the detection confidence of each potential defect region is compared with a preset confidence threshold. This preset confidence threshold is pre-set based on the actual production line's tolerance for false negative and false positive rates. Any region with a detection confidence lower than this preset confidence threshold is identified as a region to be corrected, indicating that the model's certainty in identifying this region is insufficient. For each region to be corrected, the system extracts pixel information corresponding to the spatial location of the region to be corrected from the original adjacent frame sequence that constitutes the complete image. Due to differences in jitter between different frames, blurry traces that the model cannot determine in the current frame may appear as clearly identifiable defect edges in adjacent frames. The grayscale features and edge information of the corresponding regions in adjacent frames are analyzed and compared with the model's recognition result in the current frame. Based on this, the original recognition result is corrected. Correction actions include adjusting the boundary range of the defect region or correcting the defect type label. After this correction, a corrected defect annotation is generated.

[0071] Subsequently, a cross-frame consistency check is performed on the repaired defect annotations. The check logic is as follows: if the same defect region is annotated with the same type in multiple consecutive frames, and the deviation of the annotation position between frames is less than a preset position deviation threshold, then the annotation is considered to have spatiotemporal stability and passes the check; conversely, if a certain annotation only appears in the current frame and cannot be verified in adjacent frames, it may be a false detection caused by random noise and is removed. The image that passes the cross-frame consistency check is used as the final defect annotation image. The defect annotation information on this image combines the preliminary recognition capability of the single-frame model with the verification advantage of multi-frame spatiotemporal information, and has higher accuracy and robustness.

[0072] The defect detection model is trained using a large number of labeled images of pipe surfaces with defects. The training data includes images of defects of different types and degrees. The input process involves organizing the pixel data of the complete image according to the format required by the model and then inputting it. The model performs a comprehensive analysis based on the pixel data to identify the location of potential defects.

[0073] The defect detection model determines the presence of defects based on pixel grayscale changes and edge features in the image, and labels the location and type of defects. The recognition process is achieved through feature extraction and classification mechanisms within the model, outputting the location coordinates and type label of each potential defect area.

[0074] The detection confidence score is the model's evaluation of the credibility of the recognition result. The preset confidence score threshold is set according to the actual detection requirements. When the detection confidence score of a potential defect is lower than the preset confidence score threshold, it indicates that the model is uncertain about the judgment of the potential defect. Pixel information at the same position is extracted from adjacent frames as supplementary information.

[0075] Correction adjusts the boundaries or types of defect areas by comparing supplementary information with the initial identification results of the model; the corrected defect annotations update the location and type information of the defect areas.

[0076] Consistency checks are performed by comparing the annotation results of the same defect area in multiple frames of images to determine whether the annotation types are consistent and whether the positional deviation is less than a preset positional deviation threshold. When the same defect area is annotated with the same type in multiple frames and the positional deviation is less than the preset positional deviation threshold, the annotation is confirmed to be consistent.

[0077] Following step S6, the process further includes step S7, which calculates the sharpness index and accuracy index for the final defect annotation image to determine whether the detection reliability meets the preset standards. Specifically, this includes: calculating the overall sharpness index for the final defect annotation image; calculating the accuracy index based on the annotation area in the defect annotation image; comparing the sharpness index and accuracy index with the corresponding preset standards to determine whether the detection result is reliable; if the sharpness index or accuracy index is lower than the corresponding preset standard, the detection result is marked as unreliable; recording the unreliable result and generating feedback data; and using the feedback data as a reference for subsequent optimization.

[0078] Specifically, to address the issue of unreliable reports directly entering the quality control stage due to a lack of reliability assessment of the test results in automated testing of plastic pipes, this application adds step S7 after step S6. It proposes not to regard defect detection results as unconditionally credible final conclusions, but to introduce quantitative indicators of two complementary dimensions, clarity and accuracy, to conduct a secondary assessment of the test results. Based on the assessment results, unreliable tests are automatically marked, and structured feedback data is generated, forming a closed-loop mechanism of "detection-assessment-feedback-optimization".

[0079] In specific implementation, firstly, for the final defect annotation image output in step S6, its overall sharpness index is calculated. The sharpness index measures the imaging quality of the defect annotation image itself. Its calculation method involves analyzing the uniformity of pixel grayscale changes and the edge salience of the defect edge region in the image. A quantized value is derived based on the grayscale gradient distribution of all pixels in the entire image. The higher the quantized value, the more distinct the grayscale contrast between the defect edge and the non-defect region in the image, and the better the image quality. Next, based on the annotation area in the defect annotation image, the accuracy index is calculated. The accuracy index measures the degree of agreement between the annotation result and the actual defect. The calculation basis is the pixel overlap ratio between the annotation area and the true defect area. The true defect area can be derived from the statistical aggregation of high-confidence historical detection results accumulated by the system under stable operating conditions, or from reference images provided in the offline calibration process. After obtaining the sharpness index and accuracy index, the two indices are compared with their respective preset standards. The preset standards are set according to the quality control requirements of the specific production line. For example, for high-pressure conveying pipes with strict surface quality requirements, both standards are set. The preset standards are all raised accordingly. The judgment logic is that the detection result is considered reliable only when both the sharpness and accuracy indicators reach or exceed the corresponding preset standards. If either the sharpness or accuracy indicator is lower than its corresponding preset standard, the detection result is automatically marked as unreliable. For detections marked as unreliable, the system automatically records and generates structured feedback data, including the specific indicator value of the unreliable result, the corresponding image number, the acquisition timestamp, and possible cause analysis items. The cause analysis can be inferred based on the deviation characteristics of the indicators. For example, a low sharpness indicator may be related to camera shake or inaccurate focus, while a low accuracy indicator with repeated labeling deviations at the same position in multiple images may be related to insufficient sensitivity of the model to this type of defect. The feedback data is stored in a structured table format for subsequent optimization reference. After generating the feedback data, it is used as the basis for subsequent detection parameter adjustments and equipment maintenance, such as triggering camera image stabilization calibration, adjusting the brightness of auxiliary light sources, or starting incremental training of the defect detection model, thereby forming a closed loop for continuous improvement of detection reliability.

[0080] Through the coordination of the above steps, this application achieves high-precision and high-robust automated detection of surface defects in plastic pipes.

[0081] Example 2: The above describes a method for detecting surface defects in plastic pipes according to embodiments of this application. The following describes a system for detecting surface defects in plastic pipes according to embodiments of this application. Figure 3 As shown in the figure, a surface defect detection system for plastic pipes in this application embodiment includes: The distribution map generation unit is used to acquire a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas based on the comparison result of the displacement vector and the preset threshold, and generate a blurred area distribution map.

[0082] The basic image restoration unit is used to identify less affected areas based on the blurry area distribution map, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets the preset conditions as the restoration base image.

[0083] The edge image enhancement unit is used to fuse the clear feature points in the base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image.

[0084] The intermediate image acquisition unit is used to calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than the preset gradient threshold, supplementary gradient information is extracted from adjacent frames and superimposed for compensation to obtain an intermediate image with improved edge clarity.

[0085] The surface image acquisition unit is used to extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than a preset stitching threshold, and stitch multiple frames of images based on the matching point set to obtain a complete surface image of the plastic pipe.

[0086] The defect image annotation unit is used to input a complete image of the plastic pipe surface into a pre-trained defect detection model to identify potential defects. For identification results with a detection confidence level lower than a preset confidence threshold, the corresponding region information of adjacent frames is used for correction to obtain the final defect-annotated image.

[0087] Through the synergistic cooperation of the above-mentioned components, this application further realizes high-precision and high-robust automated detection of surface defects in plastic pipes.

[0088] This application also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when the instructions are executed on a computer, cause the computer to perform the steps of the above-described method for detecting surface defects in plastic pipes.

[0089] In summary, this application provides a surface defect detection method for plastic pipes based on spatiotemporal augmentation and deep learning. Addressing core pain points such as local motion blur caused by high-frequency vibrations of industrial equipment and limited physical field of view, this solution overcomes the limitations of traditional single-frame image processing, cleverly constructing an end-to-end closed-loop architecture from local deblurring and reconstruction to global panoramic stitching and intelligent self-correction detection. Through deep fusion of multi-frame spatiotemporal information, this application not only accurately restores the true edge skeleton of incomplete defects but also effectively avoids misjudgment of fractures in long, cross-frame defects. Simultaneously, it innovatively introduces a confidence level review and a dual-index closed-loop feedback mechanism, endowing the detection system with the ability to self-examine and continuously optimize. This method fundamentally eliminates visual blind spots and the risk of model black-box release, significantly improving the accuracy, consistency, and robustness of detection results under complex working conditions, providing a new paradigm of efficient, accurate, and highly reliable automated quality control for the modern pipe manufacturing industry.

[0090] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0091] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0092] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application 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 this application.

Claims

1. A method for detecting surface defects in plastic pipes, characterized in that, The method includes: Step S1: Acquire a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas according to the comparison result of the displacement vector and the preset threshold, and generate a blurred area distribution map; Step S2: Based on the blurry area distribution map, identify the less affected areas, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets the preset conditions as the base image for repair. Step S3: Fuse the clear feature points in the repair base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image; Step S4: Calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than a preset gradient threshold, extract supplementary gradient information from adjacent frames and perform superposition compensation to obtain an intermediate image with improved edge clarity. Step S5: Extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than a preset stitching threshold, and stitch multiple frames of images based on the set of matching points to obtain a complete image of the plastic pipe surface. Step S6: Input the complete plastic pipe surface image into the pre-trained defect detection model to identify potential defects. For identification results with a detection confidence level lower than the preset confidence threshold, correct them using the corresponding region information of adjacent frames to obtain the final defect-annotated image.

2. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, The step S1 of generating the fuzzy region distribution map includes: For adjacent frames in the continuous image sequence, a displacement estimation method is used to calculate the displacement vector between adjacent frames. Based on the distribution of the displacement vector, the region where the displacement vector continuously exceeds a preset threshold is identified as a blurred region. The identified blurred regions are marked and statistically analyzed to generate a blurred region distribution map. Specifically, calculating the displacement vector between adjacent frames involves dividing the image into multiple regions, calculating the positional offset of each region in adjacent frames, finding the region with the smallest change in grayscale value between two adjacent frames to determine the positional offset of each region, and summing the positional offsets of all regions to obtain the inter-frame displacement vector.

3. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, The step S2, which involves extracting clear feature points from adjacent frames, includes: Traverse the distribution map of the blurred regions, and identify regions that are not marked as blurred or whose displacement vectors are less than a preset threshold as regions that are less affected; within the regions that are less affected, extract points whose gray-level gradient values ​​are higher than a preset gradient threshold as clear feature points.

4. The method for detecting surface defects in plastic pipes according to claim 3, characterized in that, In step S2, the sharp feature points are spatially aligned based on the displacement vector, and a set of feature points whose positional consistency between adjacent frames meets a preset condition is selected, including: The feature alignment method is used to calculate the positional offset of the sharp feature points in adjacent frames, and to perform reverse offset correction based on the displacement vector, so as to map the sharp feature points in different frames to the same coordinate system to complete the spatial alignment. Based on the aligned and clear feature points, connect adjacent feature points that are in the same direction to construct the preliminary outline of the defect area; The frequency and positional changes of feature points in multiple frames are statistically analyzed. A set of feature points that appear repeatedly in multiple frames and whose positional changes are less than a preset offset threshold are selected as the feature point set whose positional consistency meets the preset condition. The selected feature point set is used as the base image for restoration.

5. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, Step S3 further includes: Obtain clear feature points from the base image to be repaired as reference data, and extract pixel information in the blurred area from the current frame as auxiliary data; The sharp feature points and the pixel information in the blurred area are fused by weighted superposition to generate a preliminary defect edge image, wherein the sharp feature points are given a higher weight than the pixel information in the blurred area. The preliminary defect edge image is then subjected to detail optimization to enhance the grayscale contrast of the edge region, resulting in an enhanced defect edge image.

6. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, The intermediate image with improved edge sharpness obtained in step S4 includes: The local gradient value of each pixel is calculated by comparing the gray value difference between each pixel and its surrounding pixels in the enhanced defect edge image. Regions with local gradient values ​​lower than a preset gradient threshold are identified as regions to be compensated, and gradient information corresponding to the regions to be compensated is extracted from adjacent frames as supplementary gradient information. The supplementary gradient information is weighted and superimposed with the gradient value of the current frame to generate an image with richer edge details. The image with richer edge details is then smoothed to obtain an intermediate image with improved edge clarity.

7. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, The complete image of the plastic pipe surface obtained in step S5 includes: Pixels with gradient values ​​higher than a preset gradient threshold are extracted from the defect edge region of the intermediate image as candidate matching points. The spatial distance and gray-level similarity between the candidate matching points and the feature points of adjacent frames are calculated. A set of matching points with positional offsets less than a preset offset threshold and consistent gray-level gradient value trends in multiple frames are selected. Determine whether the distribution coverage of the matching point set in the defect area is higher than a preset stitching threshold. If the coverage is higher than the preset stitching threshold, perform weighted fusion of the pixel information of the corresponding area in multiple frames of images based on the location information of the matching point set to complete image stitching. The stitching boundaries of the stitched images are smoothed to obtain a complete image of the plastic pipe surface.

8. The method for detecting surface defects in plastic pipes according to claim 1, characterized in that, The final defect-annotated image obtained in step S6 includes: The complete image of the plastic pipe surface is input into a pre-trained defect detection model, which outputs the location coordinates, type label, and corresponding detection confidence of each potential defect area. The region with a detection confidence level lower than the preset confidence threshold is identified as the region to be corrected. Pixel information corresponding to the region to be corrected is extracted from adjacent frames. The defect type or boundary of the region to be corrected is corrected to generate the repaired defect annotation. The repaired defect annotations are subjected to cross-frame consistency checks, and the images that pass the checks are used as the final defect annotation images.

9. A detection system for surface defects of plastic pipes, used to implement the detection method for surface defects of plastic pipes as described in any one of claims 1-8, characterized in that, The system includes: The distribution map generation unit is used to acquire a continuous image sequence of the surface of the plastic pipe, calculate the displacement vector between adjacent frames, mark the blurred areas according to the comparison result of the displacement vector and a preset threshold, and generate a blurred area distribution map. The basic image restoration unit is used to identify less affected areas based on the blurry area distribution map, extract clear feature points from adjacent frames, spatially align the clear feature points based on the displacement vector, and select a set of feature points whose positional consistency between adjacent frames meets a preset condition as the restoration base image. The edge image enhancement unit is used to fuse the clear feature points in the repair base image with the pixel information of the corresponding blurred area in the current frame to generate an enhanced defect edge image; The intermediate image acquisition unit is used to calculate the local gradient value of each pixel in the enhanced defect edge image. For areas where the local gradient value is lower than a preset gradient threshold, supplementary gradient information is extracted from adjacent frames and superimposed for compensation to obtain an intermediate image with improved edge clarity. The surface image acquisition unit is used to extract feature points of the defect area in the intermediate image as candidate matching points, match them with feature points of adjacent frames, obtain a set of matching points with a matching coverage rate higher than a preset stitching threshold, and stitch multiple frames of images based on the set of matching points to obtain a complete surface image of the plastic pipe. The defect image annotation unit is used to input the complete plastic pipe surface image into a pre-trained defect detection model, identify potential defects, and correct the identification results with a detection confidence level lower than a preset confidence threshold by using the corresponding region information of adjacent frames to obtain the final defect annotation image.

10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instruction is executed by the processor, it implements a method for detecting surface defects in plastic pipes as described in any one of claims 1-8.