Method and system for automatically detecting morphological parameters of irregular object

By using ROI local focusing skeletonization processing and custom convolution kernel detection endpoints, combined with bidirectional BFS and breakpoint repair mechanisms, the problems of low efficiency, insufficient accuracy and poor robustness in the detection of morphological parameters of irregular small objects are solved, achieving efficient and accurate multi-parameter detection that can adapt to objects with complex shapes.

CN121999205APending Publication Date: 2026-05-08QILIN REDRYING FACTORY YUNNAN TOBACCO REDRYING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610162949.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-05
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing technologies suffer from low efficiency, insufficient accuracy, poor robustness, and engineering practicality challenges in the detection of morphological parameters of irregular small objects. In particular, they are difficult to meet real-time requirements in high-resolution images or batch detection, and traditional methods cannot effectively handle ring targets and skeleton fracture problems.

Method used

We employ ROI local focusing skeletonization processing, combined with custom convolutional kernels to detect endpoints, and utilize bidirectional BFS and breakpoint repair mechanisms to integrate skeleton axis length, straight-line distance between the two ends, and average width of dynamic partitions to construct a multi-parameter detection method. We also adopt a layered encapsulation architecture to manage the parameters.

Benefits of technology

It significantly improves detection efficiency and accuracy, enhances robustness, meets the real-time requirements of industrial online detection, provides more comprehensive morphological parameter support, and reduces engineering integration difficulty and system maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121999205A_ABST
    Figure CN121999205A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic detection method and system for morphological parameters of an irregular object, and relates to the technical field of image processing. The method comprises the following steps: extracting an effective contour from a preprocessed image, generating a mask, and cutting an ROI (Region of Interest) to focus a target; secondly, skeleton endpoints are accurately detected through a user-defined convolution kernel, the longest skeleton path is extracted through a bidirectional BFS algorithm, breakpoints are repaired through linear interpolation, and finally path coordinates are mapped back to an original image; therefore, core morphological parameters such as skeleton axis length, maximum linear distance between two ends of the contour and average width based on dynamic partition and distance transformation are comprehensively calculated. According to the scheme, the efficiency is remarkably improved through ROI local processing, robustness and high precision are ensured by means of an innovative endpoint detection and path repair mechanism, comprehensive, automatic and precise detection of the morphological characteristics of the irregular small object is realized, and the problems of low efficiency, processing failure, poor engineering adaptability and the like in the prior art are effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to an automatic detection method and system for irregular object shape parameters. Background Technology

[0002] In fields such as industrial inspection and biomedicine, accurate detection of the morphological parameters of irregular small objects is crucial for ensuring product quality and studying sample characteristics. Traditional inspection relies on manual or contact equipment, which has drawbacks such as low efficiency, high labor intensity, susceptibility to human influence, and difficulty in adapting to complex shapes, and may even damage delicate or soft objects.

[0003] With the development of machine vision technology, non-contact detection methods based on image processing, especially those centered on skeleton extraction, have become a research hotspot in the industry. Skeleton extraction aims to simplify the shape of an object into a single-pixel centerline, providing a basis for the detection of parameters such as length and orientation. However, existing technologies face a series of severe challenges in engineering implementation, making it difficult to directly meet the stringent requirements of real-time performance, accuracy, and robustness in industrial settings, such as: General skeleton algorithms often adopt a full-image processing mode, which wastes a lot of computing resources and is difficult to meet the real-time requirements of high-resolution images or batch detection. The skeletons generated by the algorithms contain a large number of redundant branches, which seriously interfere with the extraction of the core skeleton of the object and reduce the engineering practicality of parameter detection. For circular targets, traditional methods fail because they cannot locate effective endpoints; they also lack effective repair mechanisms for the breakage problems that easily occur during skeletonization, leading to increased measurement errors. In addition, traditional endpoint detection methods have poor anti-interference capabilities and lack coordinate mapping mechanisms, making it difficult to directly apply the algorithm results to the localization and annotation of the original image, resulting in high engineering integration complexity.

[0004] Therefore, the industry urgently needs an innovative testing solution that can systematically solve the aforementioned problems of efficiency, accuracy, robustness, and engineering applicability. Summary of the Invention

[0005] In view of the above-mentioned defects or deficiencies in the prior art, the present invention provides an automatic detection method and system for irregular object shape parameters. By using ROI local focusing skeletonization processing, the detection efficiency is greatly improved; a custom convolution kernel is used to accurately detect endpoints, and combined with bidirectional BFS and breakpoint repair mechanism, the robustness and accuracy of longest path extraction are significantly enhanced; by fusing detection of multiple parameters such as skeleton axis length, straight-line distance between two ends and average width of dynamic partitions, the object shape is comprehensively characterized; and a systematic configuration management architecture ensures the flexibility and maintainability of engineering applications.

[0006] This invention provides an automatic detection method for the shape parameters of irregular objects, comprising: Obtain the original image of the target object and convert it into a binary image; Multiple object contours are extracted from the binary image and the contour points are compressed, while the key points of each object contour are retained, and the effectiveness of the contours is verified. A target region mask image is generated for each valid contour. A region of interest image containing only the target region is cropped from the target region mask image according to the bounding rectangle parameter of the valid contour. The region of interest image is converted into a binary image and then skeletonized to obtain a skeleton image with a single pixel width. A convolution operation is performed on the skeleton image to detect the skeleton endpoints. Starting from the skeleton endpoints or, if there are no endpoints, from the skeleton geometric center, a breadth-first search is used to determine the two furthest points on the skeleton and construct the longest skeleton path between them. Based on the longest skeleton path, a new path list is initialized, and the Euclidean distance between subsequent points and the end point of the new path is checked point by point in the path order. When the distance is greater than the preset maximum gap value for path interpolation, it is determined to be a breakpoint. The longest continuous skeleton path is obtained through interpolation repair and mapped to the original image coordinate system. The skeleton axis length of the target object is calculated based on the longest continuous skeleton path in the original image coordinate system. The skeleton axis length is the actual physical length of the longest continuous skeleton path of the object. The average width of the object and the straight-line distance between its two ends are calculated based on the mask image of the target region.

[0007] Furthermore, the step of verifying the validity of the contour includes: A contour is considered valid if the number of key points on the object's outline is greater than or equal to a preset number and the area of ​​the region enclosed by the outline is greater than or equal to a preset number of pixels.

[0008] Furthermore, the step of performing convolution operations on the skeleton image to detect skeleton endpoints specifically includes: Construct a 3×3 custom convolution kernel, set the weight of the kernel center position to n, where n is an integer greater than 1, and set the weight of the other 8 neighboring positions to 1; The skeleton image is convolved using the 3×3 custom convolution kernel, and the pixels with a convolution result of n+1 are selected as skeleton endpoints.

[0009] Furthermore, the geometric center point of the skeleton is obtained by the following steps: extracting the coordinates of all skeleton pixels in the skeleton image, and calculating the average of the horizontal and vertical coordinates of all the skeleton pixels as the coordinates of the geometric center point of the skeleton.

[0010] Furthermore, the step of determining the two farthest points of the skeleton through breadth-first search and constructing the longest skeleton path between the two farthest points includes: determining the first farthest point from the starting point through a first breadth-first search, determining the second farthest point from the first farthest point through a second breadth-first search; starting from the second farthest point, backtracking to the first farthest point according to the second breadth-first search record, and reconstructing the complete path between the first farthest point and the second farthest point as the longest skeleton path.

[0011] Furthermore, the step of calculating the length of the skeleton axis of the target object based on the longest continuous skeleton path in the original image coordinate system includes: Calculate and sum the Euclidean distances between consecutive adjacent skeleton points in the longest continuous skeleton path in the original image coordinate system to obtain the skeleton axis pixel length. Divide the skeleton axis pixel length by the pixel equivalent to obtain the skeleton axis length of the target object.

[0012] Furthermore, the step of calculating the average width of the object based on the target region mask image includes: The object in the target region mask image is divided into regions based on the length of the bounding rectangle of the object contour, the preset number of regions and the minimum region length. The target region is extracted in each region. The straight-line distance from each pixel in the target region to the nearest contour edge pixel is calculated by L2 distance transformation. The maximum straight-line distance is taken as the maximum radius of the object in that region. Multiplying it by 2 gives the width of the object region. The average width of all object region widths is taken as the average width of the object.

[0013] Another aspect of the present invention provides an automatic detection system for irregular object shape parameters, comprising: The image preprocessing module is used to obtain the original image of the target object and convert it into a binary image; The contour processing module is used to extract multiple object contours from the binary image and compress contour points, retain key points of each object contour, and verify the validity of the contours. The skeleton processing module is used to generate a target region mask image for each valid contour, and to crop a region of interest image containing only the target region from the target region mask image according to the bounding rectangle parameters of the valid contour; after converting the region of interest image into a binary image, skeletonization processing is performed to obtain a skeleton image with a single pixel width, and convolution operation is performed on the skeleton image to detect skeleton endpoints; The path extraction module is used to determine the two farthest points of the skeleton by breadth-first search, starting from the skeleton endpoints or the geometric center of the skeleton when there are no endpoints, and construct the longest skeleton path between the two farthest points. Based on the longest skeleton path, a new path list is initialized, and the Euclidean distance between subsequent points and the end point of the new path is checked point by point in the path order. When the distance is greater than the preset maximum gap value of path interpolation, it is determined as a breakpoint. The longest continuous skeleton path is obtained by interpolation repair and mapped to the original image coordinate system. The morphological parameter detection module is used to calculate the length of the skeleton axis of the target object based on the longest continuous skeleton path in the original image coordinate system. The length of the skeleton axis is the actual physical length of the longest continuous skeleton path of the object. The module also calculates the average width of the object and the straight-line distance between its two ends based on the mask image of the target region.

[0014] Furthermore, it also includes a configuration management module, which includes: The parameter encapsulation layer divides the callable parameters of the entire morphological parameter detection process into a preprocessing parameter layer, a measurement parameter layer, and an output parameter layer. The parameters are encapsulated in key-value pairs as a dictionary structure for algorithm parsing and invocation. The core algorithm layer includes configuration loading and parsing algorithms, recursive partial algorithms, parameter precise location algorithms, and parameter persistence algorithms, which are used for parameter configuration management. The interface adaptation layer includes parameter acquisition and parameter update interfaces, which are used to enable adapted calls between the core algorithm layer and other modules.

[0015] Furthermore, it also includes: The log management module is used to record operation logs, error logs, and warning logs in a hierarchical manner for troubleshooting. The acquisition module is used to acquire the camera preview in real time, draw operation prompts and acquisition boxes, respond to case commands to complete the acquisition of irregular small objects, and transmit the acquired raw images to the image preprocessing module to start real-time detection. The anomaly handling module is used to verify the validity of image paths and contours, and to capture and record anomalies during the detection process through decorators. The batch detection module is used to acquire the original images of all irregular small objects in a specified folder, transmit them sequentially to the image preprocessing module to start batch detection, and summarize and save all detection data.

[0016] The present invention provides an automatic detection method and system for irregular object shape parameters, which has the following beneficial effects: This invention uses the bounding rectangle of the effective contour to accurately crop out the region of interest containing only the target object from the mask image. This allows subsequent computationally intensive operations such as skeletonization, endpoint detection, and path extraction to be performed only within the region of interest, which is much smaller than the original image. This avoids meaningless calculations on a large number of background pixels across the entire image, thereby significantly improving the processing speed and enabling it to meet the real-time requirements of industrial online inspection and the efficiency requirements of batch image processing. This invention integrates skeleton extraction and contour analysis algorithms. By extracting the longest skeleton path and discarding redundant branches, it directly obtains the core path representing the main axis of the target. Combined with dynamic partitioning distance transformation, it achieves width detection without the need for additional branch culling processing, and can directly output accurate morphological parameters. A custom convolutional kernel is used for endpoint detection, and the neighborhood features of the endpoints are enhanced by weight settings. Compared with the traditional neighborhood counting method, the probability of false detection and false negative detection of endpoints is greatly reduced, and a reliable starting point guarantee is provided for the longest path extraction. A center point starting mechanism is designed for ring-shaped irregular objects to solve the problem of failure in traditional algorithms. At the same time, a breakpoint repair step is added to complete the skeleton breakpoints through linear interpolation to ensure path continuity and significantly improve robustness. Through the coordinate mapping mechanism, the path coordinates of the region of interest are accurately mapped back to the original image coordinate system. The output results can be directly used for target localization and morphological parameter annotation of the original image without additional coordinate transformation processing, which reduces the difficulty of engineering integration and optimizes engineering adaptability. The system simultaneously detects the length of the skeleton axis and the straight-line distance between the two ends of an object. The former reflects the actual axial extension length of the object (for curved parts), while the latter reflects the maximum straight-line span of the object. Combined with dynamic partitioning and L2 distance transformation, the system calculates the average width, providing a more comprehensive and three-dimensional representation of the complex morphological characteristics of irregular objects. This provides richer and more accurate data support for industrial inspection and scientific research. The configuration management module adopts a "layered encapsulation + algorithm-driven" architecture to achieve structured and modular parameter management. The recursive completion algorithm ensures parameter integrity, and the interface adaptation layer improves the flexibility of parameter calling, significantly reducing the maintenance cost of adapting the system to different detection scenarios. The configuration management module supports flexible parameter configuration, the log management module facilitates problem tracing, and the camera acquisition module and batch detection module adapt to different industrial application scenarios, improving the system's versatility, practicality, and scalability. Attached Figure Description

[0017] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a flowchart illustrating an automatic detection method for irregular object shape parameters according to an embodiment of this application; Figure 2 This is a schematic diagram of the structure of an automatic detection system for irregular object shape parameters provided in one embodiment of this application. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] refer to Figure 1 An embodiment of the present invention provides an automatic detection method for irregular object shape parameters, comprising the following steps: Step S100: Obtain the original image of the target object and convert it into a binary image; Specifically, in S101, the original image of the irregular small object is first obtained. In this embodiment, the irregular object is a tobacco stem. If the original image is a color image, it is converted into a grayscale image. S102, the grayscale image is subjected to Gaussian filtering noise reduction processing by a preset Gaussian filter kernel size, which provides a clearer image foundation for subsequent threshold processing and kernel contour extraction. For example, the preset Gaussian filter kernel size is 5×5. S103, after Gaussian filtering for noise reduction, the standard deviation of the grayscale values ​​in the grayscale image is calculated as the contrast. When the standard deviation is less than 50, the grayscale image is determined to be a low-contrast image. Adaptive Gaussian thresholding is then used to obtain a preliminary binary image. Specifically, in this embodiment, the parameters for adaptive Gaussian thresholding are set as follows: block size is 15×15, that is, the image is divided into multiple non-overlapping 15×15 pixel local blocks, C value is 2, where C value is a constant offset. Gaussian weighted average is calculated for all pixels in the local block to obtain the weighted average, and then the C value is subtracted to obtain the local threshold of the current pixel. Binarization is then performed to obtain a preliminary binary image. When the standard deviation is greater than or equal to 50, the grayscale image is determined to be a high-contrast image. The maximum inter-class variance method is used to automatically select the globally optimal threshold based on the grayscale distribution of the image, without the need for additional parameter configuration. Binarization is then performed based on the globally optimal threshold to obtain a preliminary binary image. S104, morphological operations include dilation, erosion, and closure operations. A preset number of dilation iterations and erosion iterations are obtained. A closure operation is performed on the initial binary image, which is a composite operation of dilation followed by closure. In this embodiment, a 5×5 elliptical kernel is used. First, a closure operation is performed to quickly repair small gaps and internal holes in the contour without changing the overall size of the target. Then, a dilation operation is performed according to the preset number of dilation iterations to strengthen the contour connection. Finally, an erosion operation is performed according to the preset number of erosion iterations to remove burrs from the contour edges, eliminate noise from small components, and accurately restore the target contour. After completing the morphological operations, small noise filtering is performed. Small noise filtering involves extracting all contours in the image, calculating the area of ​​the region enclosed by each contour, and deleting contour regions with an area smaller than the preset minimum contour area. In this embodiment, the preset minimum contour area is 100 pixels. Morphological operations optimize the initial binary image by repairing contour edge defects and internal holes, while small noise filtering further optimizes the initial binary image by deleting isolated small contours in the background, thereby obtaining the final binary image.

[0020] Step S200: Extract multiple object contours from the binary image and compress the contour points, retain the key points of each object contour, and verify the validity of the contours; Specifically, in S201, a computer vision library is used to extract multiple object contours from the final binary image and compress contour points. Preferably, this embodiment uses the OpenCV cv2.findContours function, sets the contour retrieval mode to cv2.RETR_EXTERNAL mode to extract only the external contours, sets the contour approximation mode to cv2.CHAIN_APPROX_SIMPLE mode to compress redundant contour points, and accurately obtains key points of the object contours, such as the endpoints of straight lines and the inflection points of curves, in order to reduce the amount of data and provide concise and reliable contour data for subsequent processing. S202, For the multiple object contours extracted in step S201, the image pixel coordinate system is adopted, with the upper left corner of the original image as the origin, the x-axis horizontal to the right and the y-axis vertically downward. Each contour is sorted according to the x-coordinate of the upper left corner of the contour's bounding rectangle according to a fixed rule, such as from left to right, to ensure the consistency of the detection order. S203, perform small noise filtering again based on the preset minimum contour area of ​​100 pixels, and verify the validity of the filtered contour: the contour with the number of object contour key points greater than or equal to the preset number and the area of ​​the contour enclosed region greater than or equal to the preset number of pixels is determined as a valid contour. For example, the contour with the number of object contour key points greater than or equal to 3 and the area of ​​the contour enclosed region greater than or equal to 10 pixels is determined as a valid contour.

[0021] Step S300: Generate a target region mask image for each valid contour; crop a region of interest image containing only the target region from the target region mask image according to the bounding rectangle parameter of the valid contour; convert the region of interest image into a binary image and then perform skeletonization processing to obtain a skeleton image with a single pixel width; perform convolution operation on the skeleton image to detect skeleton endpoints. Specifically, the extracted valid contours are processed sequentially according to the sorting described in step S202: S301, initialize a blank image with the same size as the aforementioned binary image, and set its initial pixel values ​​to 0. Draw the currently processed valid contour on the blank image, and fill the internal pixel values ​​of the valid contour with 255. For example, this embodiment uses the OpenCV cv2.drawContours function to draw the valid contour on the blank image and fill the internal pixel values ​​with 255, thereby obtaining a target region mask image that only contains the currently processed valid contour, thus achieving the separation of a single target from other targets and the background. S302, calculate the bounding rectangle parameters (x, y, w, h) of the currently processed effective contour. Based on these bounding rectangle parameters, crop the region of interest (ROI) image containing only the target region from the target region mask image. For example, in this embodiment, the OpenCV cv2.boundingRect function is used to calculate the bounding rectangle parameters of a certain effective contour as x=100, y=80, w=200, h=150, all in pixels. Here, x is the x-coordinate of the upper left corner of the bounding rectangle, y is the y-coordinate of the upper left corner of the bounding rectangle, w is the width of the bounding rectangle (the number of pixels in the horizontal direction), and h is the length of the bounding rectangle (the number of pixels in the vertical direction). Based on these bounding rectangle parameters, crop the ROI image from the target region mask image. The cropped area is [y:y+h:x:x+w], which in this embodiment is [80:80+150:100:100+200], resulting in an ROI image containing only the target region. S303, divide the pixel values ​​of the uint8 type ROI image by 255 to convert it into a 0-1 binary image, where 1 represents the skeleton candidate region and 0 represents the background. Perform skeletonization processing on this binary image. Optionally, skeletonization processing can be performed using the SciPy library or skimage library. In this embodiment, the scipy.morphology.skeletonize function of the SciPy library is used to perform skeletonization processing on this binary image. Iteratively shrink the skeleton candidate region to obtain a skeleton binary image with a single pixel width. S304, as an optional implementation, this embodiment uses OpenCV's cv2.filter2D function for subsequent convolution operations. It only supports uint8 type input and requires format conversion. The pixel values ​​of the skeleton binary image are multiplied by 255 to convert it into a uint8 type skeleton image skel, where 255 represents the skeleton and 0 represents the background. S305, define the endpoint detection function find_endpoints(skel) to detect skeleton endpoints. Specifically, if the cv2.filter2D function is used for convolution operation, first convert the input uint8 type skeleton image skel into a 0-1 binary image skel_01; create a 3×3 convolution kernel with a specific weight distribution. For example, in this embodiment, the convolution kernel parameters are [[1,1,1],[1,10,1],[1,1,1]], and the weight of the center position is set to 10 to ensure that endpoint matching can only be triggered when the center is a skeleton point; perform convolution operation on skel_01, and filter out the pixels with a convolution result of 11, which are the skeleton endpoints; extract the coordinates of all skeleton endpoints. For example, the coordinates of all skeleton endpoints are extracted using the np.argwhere function of the NumPy library. If a convolution function that only supports binary input is selected, the above convolution operation can be performed directly on the skeleton binary image obtained in step S303.

[0022] Step S400: Using the skeleton endpoints as the starting point, or the skeleton geometric center point as the starting point when there are no endpoints, determine the two farthest points of the skeleton through breadth-first search and construct the longest skeleton path between the two farthest points. Based on the longest skeleton path, initialize a new path list, and check the Euclidean distance between subsequent points and the end point of the new path point by point according to the path order. When the distance is greater than the preset maximum gap value of path interpolation, it is determined as a breakpoint. Obtain the continuous longest skeleton path through interpolation repair and map it to the original image coordinate system. Specifically, in S401, the longest skeleton path extraction function `get_longest_path(skel)` is defined to extract the longest skeleton path. Specifically, a coordinate system for the ROI image is established, with the top-left corner of the ROI image as the origin, the x' axis horizontally to the right, and the y' axis vertically downwards. The `find_endpoints` function is called to obtain the set of skeleton endpoint coordinates. The first endpoint in the set is selected as the initial starting point. If the length of the endpoint set is 0, it indicates a small, irregularly shaped object such as a miniature ring washer. The mean of all skeleton point coordinates in the skeleton image is calculated using the `np.mean` function from the NumPy library to obtain the center point (cx', cy'), which is then used as the initial starting point. A breadth-first search (BFS) is defined. The Search (BFS) function `bfs_furthest(start)` uses an 8-neighborhood traversal to record the access status of each pixel and its distance from the starting point during the traversal. It takes the pixel farthest from the starting point as the result. It then calls `bfs_furthest` to obtain the farthest point `nodeA` from the selected initial starting point. Starting from `nodeA`, it calls `bfs_furthest` again to obtain the farthest point `nodeB`. Finally, using BFS backtracking, it traces back from `nodeB` to `nodeA` based on the records from the second BFS, and then reverses the path order to reconstruct the complete path between `nodeA` and `nodeB`, i.e., the longest skeleton path. S402. During the skeletonization process, breakpoints may occur due to noise or irregular edges. Therefore, it is necessary to further detect the breakpoints of the longest skeleton path obtained in S401 and complete it through interpolation to ensure the continuity of the path. Specifically, the preset path interpolation maximum gap value max_gap is read. In this embodiment, max_gap is set to 5 pixels. The breakpoint repair function interpolate_breaks(path, max_gap=5) is defined. The new path list new_path is initialized. Starting from the first skeleton point of the original longest skeleton path path, such as nodeA, the skeleton points are added to new_path one by one. Each subsequent skeleton point p in path is traversed. The Euclidean distance between the current p and the current last skeleton point last in new_path is calculated. If the distance is greater than max_gap, the interpolation step is calculated. The interpolation step is the integer part of the distance. The interpolation parameter t of 0-1 is generated by the np.linspace function. The interpolation points (last[0]+t*(p[0]-last[0]), last[1]+t*(p[1]-last[1])) are calculated and added to new_path in turn. If the distance is less than or equal to max_gap, the current p is directly added to new_path. After traversing, the new path new_path is obtained, which is the repaired longest skeleton path. S403 converts the ROI image coordinates (px', py') of each skeleton point in the repaired longest skeleton path to coordinates in the original image coordinate system using the mapping formula (px'+x, py'+y), where (x, y) is the coordinate of the top left corner of the ROI image in the original image coordinate system, thus obtaining the longest skeleton path global_path of the corresponding target object in the original image coordinate system.

[0023] Step S500: Calculate the skeleton axis length of the target object based on the longest continuous skeleton path in the original image coordinate system. The skeleton axis length is the actual physical length of the longest continuous skeleton path of the object. Calculate the average width of the object and the straight-line distance between its two ends based on the target region mask image.

[0024] Specifically, in S501, all points in the global_path are traversed, the Euclidean distance between consecutive adjacent skeleton points is calculated and summed to obtain the pixel length of the skeleton axis; then the pixel length of the skeleton axis of the pre-stored reference object and the actual skeleton axis length are called to calculate the pixel equivalent = pixel length of the reference object skeleton axis / length of the reference object skeleton axis; the pixel length of the target object skeleton axis is divided by the pixel equivalent to obtain the actual skeleton axis length of the object. S502, obtain the preset number of partitions and minimum partition length. For example, in this embodiment, the number of partitions is set to 3 and the minimum partition length is 15 pixels. In this embodiment, the length of the bounding rectangle of the target object outline is h = 150 pixels. Calculate the length of each partition: section_height = max(15, 150 / / 3) = 50 pixels. In this embodiment, the number of pixels y = 80 is the distance from the top left corner of the bounding rectangle of the target object's outline to the top edge of the image. Based on this, the image is divided into 3 partitions, with the y-axis ranges of the 3 partitions being [80, 130], [130, 180], and [180, 230], respectively. The corresponding mask region is extracted within each partition, and then the cv2.distanceTransform function is called, setting the distance type to cv2.DIST_L2 and the neighborhood size of the distance transformation to 5×5. The straight-line distance from each pixel point in the partition to the nearest outline edge pixel point is calculated, generating a distance transformation map. The maximum value in the distance transformation map is the maximum radius of the object in that partition. The maximum radius is multiplied by 2 and then divided by the pixel equivalent to obtain the actual width of the object in that partition. The average of the actual widths of all partitions is calculated as the average width of the target object. S503 extracts the coordinates of all pixels of the target object contour in the original image coordinate system. Optionally, the cv2.convexHull function can be called to extract the convex hull vertices of the contour to reduce the amount of computation. Traverse all points, calculate the Euclidean distance between any two different points, and take the maximum value as the direct distance between the two ends of the object. Together with the length of the skeleton axis, it represents the curvature of the target object. S504 outputs core morphological parameters and parameter charts, including skeleton axis length, straight-line distance between two ends, and average width. The parameter chart output includes: Read the pre-configured measurement data save path and data save format such as xlsx or csv, organize the image file name, object number, skeleton axis length, direct straight distance between the two ends, average width, width of each partition, detection time, image path and other information into a data table, and save it to the specified path in the specified format. Preferably, the pandas library is used to save the data table. Read the pre-configured result image save path and image save format, draw the longest skeleton path, contour, partition width annotation, and straight lines at both ends on the original image, and save the length detection result image and width detection result image to the specified path respectively. Preferably, the OpenCV library is used to save the result image. Generate a histogram of morphological parameter distribution to show the distribution of skeleton axis length, direct straight distance between two ends, and average width, and label the mean and standard deviation. Also generate a comparison chart of object morphological parameters to show the comparison of the three core morphological parameters of multiple objects. Save the results to the image path. Preferably, the above histogram and comparison chart are generated using the matplotlib library.

[0025] This invention provides an automatic detection method for irregular object morphological parameters. Through a ROI local focusing processing mechanism, computational resources are precisely concentrated on the target area, avoiding redundant calculations from traditional full-image traversal and achieving an order-of-magnitude improvement in processing efficiency, perfectly meeting the real-time requirements of industrial online inspection. It employs an adaptive image preprocessing and anti-interference endpoint detection algorithm, accurately identifying skeleton features through a custom convolution kernel. Combined with a bidirectional BFS path search and intelligent breakpoint repair mechanism, it effectively overcomes traditional problems such as ring target processing failure and skeleton breakage, significantly improving the continuity and accuracy of the longest path extraction. Breaking through the limitations of single parameters, it constructs a multi-dimensional morphological parameter fusion system, simultaneously outputting the skeleton axis length, the straight-line distance between the two ends, and the average width of the dynamic partition. This provides a three-dimensional representation of the curvature and cross-sectional features of irregular objects, offering more comprehensive data support for industrial quality control. Based on the longest skeleton path length detection error being ≤0.5%, a width detection method combining dynamic partitioning and distance transformation is adopted. Compared to the traditional bounding rectangle method, the width detection error is reduced by more than 30%, improving the accuracy of morphological parameter detection and accurately adapting to the complex shapes of irregular small objects. In summary, this invention, through the deep integration of algorithmic innovation and engineering design, systematically solves industry pain points such as low efficiency, insufficient accuracy, and poor robustness. It provides a complete solution for the efficient, accurate, comprehensive, and reliable automated detection of the morphological parameters of irregular small objects, and has significant industrial application value.

[0026] refer to Figure 2Another embodiment of the present invention also provides an automatic detection system 600 for irregular object shape parameters, comprising: The image preprocessing module 601 is used to convert the original image of the target object into a grayscale image, calculate the contrast of the grayscale image, perform threshold processing based on the contrast to obtain a preliminary binary image, and perform morphological operations and noise contour filtering on the preliminary binary image to obtain a final binary image. The contour processing module 602 is used to extract the object contours in the final binary image, sort them according to the X coordinate of the contour's bounding rectangle, perform the noise contour filtering again, and verify the validity of the remaining contours. The skeleton processing module 603 is used to generate a target region mask image based on the effective contour, calculate the bounding rectangle parameters of the contour, and crop to obtain a region of interest image containing only the target region; after converting the region of interest image into a binary image, skeletonization processing is performed to obtain a skeleton image with a single pixel width, and the skeleton image is convolved by a custom neighborhood convolution kernel to detect skeleton endpoints. The path extraction module 604 is used to determine the two farthest points of the skeleton and reconstruct the longest skeleton path by using the skeleton endpoints or the skeleton geometric center point calculated when there are no endpoints as the starting point, through breadth-first search, to detect the breakpoints in the path and perform interpolation repair, and to map the coordinates of the repaired longest skeleton path to the original image coordinate system. The morphological parameter detection module 605 is used to calculate the length of the skeleton axis of the object based on the longest skeleton path in the original image coordinate system, calculate the average width of the object through dynamic partitioning and distance transformation, traverse the contour pixels to calculate the direct straight distance between the two ends, and output the core morphological parameters and parameter charts including the skeleton axis length, the direct straight distance between the two ends and the average width.

[0027] Furthermore, it includes a configuration management module, employing a "layered encapsulation + algorithm-driven" architecture. Through modular parameter encapsulation and standardized interface design, it achieves flexible configuration and efficient maintenance of system parameters, significantly improving engineering adaptability and scalability. Specifically, the configuration management module includes a parameter encapsulation layer, a core algorithm layer, and an interface adaptation layer. The parameter encapsulation layer divides the callable parameters of the entire morphological parameter detection process into preprocessing parameter layer, measurement parameter layer, and output parameter layer according to their functions. Parameters are encapsulated in key-value pair format as a dictionary structure for algorithm parsing and invocation, specifically including: The preprocessing parameter layer includes configurable Gaussian filter kernel size parameters, dilation iteration number, erosion iteration number, and minimum contour area. For example, the Gaussian filter size is called in step S102 of the aforementioned method, the dilation iteration number and erosion iteration number are called in step S104 of the aforementioned method, and the minimum contour area is called in steps S104 and S203 of the aforementioned method. The measurement parameter layer includes the pre-stored pixel length of the skeleton axis of the reference object and its actual skeleton axis length, configurable width measurement partition number, minimum partition height and maximum path interpolation gap, etc. For example, the pixel length of the skeleton axis of the reference object and its actual skeleton axis length are called in step S501 of the aforementioned method, the number of width measurement partitions and minimum partition height are called in step S502 of the aforementioned method, and the maximum path interpolation gap is called in step S402 of the aforementioned method. The output parameter layer includes the result image save path, measurement data save path, image save format, and data save format, etc., which are exemplarily called by step S504 in the aforementioned method.

[0028] The core algorithm layer includes configuration loading and parsing algorithms, recursive partial algorithms, parameter precise location algorithms, and parameter persistence algorithms, which are used for parameter configuration management.

[0029] The interface adaptation layer includes parameter acquisition and parameter update interfaces, which are used to enable adapted calls between the core algorithm layer and other modules.

[0030] Furthermore, it also includes: The log management module is used to record operation logs, error logs, and warning logs in a hierarchical manner for troubleshooting. The acquisition module is used to acquire the camera preview in real time, draw operation prompts and acquisition boxes, respond to case commands to complete the acquisition of irregular small objects, and transmit the acquired raw images to the image preprocessing module to start real-time detection. The anomaly handling module is used to verify the validity of image paths and contours, and to capture and record anomalies during the detection process through decorators. The batch detection module is used to acquire the original images of all irregular small objects in a specified folder, transmit them sequentially to the image preprocessing module to start batch detection, and summarize and save all detection data.

[0031] It should be noted that the technical solution corresponding to the irregular object shape parameter automatic detection system 600 provided in this embodiment, which can be used to execute various method embodiments, has a similar implementation principle and technical effect to the method, and will not be repeated here.

[0032] The above description is merely a preferred embodiment of the present invention. Those skilled in the art should understand that the scope of disclosure in this invention is not limited to the specific combination of the above-described technical features, but should also cover other technical solutions formed by any combination of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this invention.

Claims

1. An automatic detection method for the shape parameters of irregular objects, characterized in that, include: Obtain the original image of the target object and convert it into a binary image; Multiple object contours are extracted from the binary image and the contour points are compressed, while the key points of each object contour are retained, and the effectiveness of the contours is verified. A target region mask image is generated for each valid contour. A region of interest image containing only the target region is cropped from the target region mask image according to the bounding rectangle parameter of the valid contour. The region of interest image is converted into a binary image and then skeletonized to obtain a skeleton image with a single pixel width. A convolution operation is performed on the skeleton image to detect the skeleton endpoints. Starting from the skeleton endpoints or, if there are no endpoints, from the skeleton geometric center, a breadth-first search is used to determine the two furthest points on the skeleton and construct the longest skeleton path between them. Based on the longest skeleton path, a new path list is initialized, and the Euclidean distance between subsequent points and the end point of the new path is checked point by point in the path order. When the distance is greater than the preset maximum gap value for path interpolation, it is determined to be a breakpoint. The longest continuous skeleton path is obtained through interpolation repair and mapped to the original image coordinate system. The skeleton axis length of the target object is calculated based on the longest continuous skeleton path in the original image coordinate system. The skeleton axis length is the actual physical length of the longest continuous skeleton path of the object. The average width of the object and the straight-line distance between its two ends are calculated based on the mask image of the target region.

2. The method for automatic detection of irregular object shape parameters according to claim 1, characterized in that, The steps for verifying the validity of the profile include: A contour is considered valid if the number of key points on the object's outline is greater than or equal to a preset number and the area of ​​the region enclosed by the outline is greater than or equal to a preset number of pixels.

3. The method for automatic detection of irregular object shape parameters according to claim 1, characterized in that, The step of performing convolution operations on the skeleton image to detect skeleton endpoints specifically includes: Construct a 3×3 custom convolution kernel, set the weight of the kernel center position to n, where n is an integer greater than 1, and set the weight of the other 8 neighboring positions to 1; The skeleton image is convolved using the 3×3 custom convolution kernel, and pixels with a convolution result of n+1 are selected as skeleton endpoints.

4. The method for automatically detecting the shape parameters of irregular objects according to claim 1, characterized in that, The geometric center point of the skeleton is obtained by the following steps: extracting the coordinates of all skeleton pixels in the skeleton image, and calculating the average of the horizontal and vertical coordinates of all the skeleton pixels as the coordinates of the geometric center point of the skeleton.

5. The method for automatically detecting the shape parameters of irregular objects according to claim 1, characterized in that, The step of determining the two farthest points of the skeleton and constructing the longest skeleton path between the two farthest points through breadth-first search includes: determining the first farthest point from the starting point through a first breadth-first search, determining the second farthest point from the first farthest point through a second breadth-first search; starting from the second farthest point, backtracking to the first farthest point according to the second breadth-first search record, and reconstructing the complete path between the first farthest point and the second farthest point as the longest skeleton path.

6. The method for automatically detecting the shape parameters of irregular objects according to claim 1, characterized in that, The step of calculating the length of the skeleton axis of the target object based on the longest continuous skeleton path in the original image coordinate system includes: Calculate and sum the Euclidean distances between consecutive adjacent skeleton points in the longest continuous skeleton path in the original image coordinate system to obtain the skeleton axis pixel length. Divide the skeleton axis pixel length by the pixel equivalent to obtain the skeleton axis length of the target object.

7. The method for automatic detection of irregular object shape parameters according to claim 1, characterized in that, The step of calculating the average width of the object based on the target region mask image includes: The object in the target region mask image is divided into regions based on the length of the bounding rectangle of the object contour, the preset number of regions and the minimum region length. The target region is extracted in each region. The straight-line distance from each pixel in the target region to the nearest contour edge pixel is calculated by L2 distance transformation. The maximum straight-line distance is taken as the maximum radius of the object in that region. Multiplying it by 2 gives the width of the object region. The average width of all object region widths is taken as the average width of the object.

8. An automatic detection system for irregular object shape parameters, characterized in that, include: The image preprocessing module is used to obtain the original image of the target object and convert it into a binary image; The contour processing module is used to extract multiple object contours from the binary image and compress contour points, retain key points of each object contour, and verify the validity of the contours. The skeleton processing module is used to generate a target region mask image for each valid contour, and to crop a region of interest image containing only the target region from the target region mask image according to the bounding rectangle parameters of the valid contour; after converting the region of interest image into a binary image, skeletonization processing is performed to obtain a skeleton image with a single pixel width, and convolution operation is performed on the skeleton image to detect skeleton endpoints; The path extraction module is used to determine the two farthest points of the skeleton by breadth-first search, starting from the skeleton endpoints or the geometric center of the skeleton when there are no endpoints, and construct the longest skeleton path between the two farthest points. Based on the longest skeleton path, a new path list is initialized, and the Euclidean distance between subsequent points and the end point of the new path is checked point by point in the path order. When the distance is greater than the preset maximum gap value of path interpolation, it is determined as a breakpoint. The longest continuous skeleton path is obtained by interpolation repair and mapped to the original image coordinate system. The morphological parameter detection module is used to calculate the length of the skeleton axis of the target object based on the longest continuous skeleton path in the original image coordinate system. The length of the skeleton axis is the actual physical length of the longest continuous skeleton path of the object. The module also calculates the average width of the object and the straight-line distance between its two ends based on the mask image of the target region.

9. The automatic detection system for irregular object shape parameters according to claim 8, characterized in that, It also includes a configuration management module, which includes: The parameter encapsulation layer divides the callable parameters of the entire morphological parameter detection process into a preprocessing parameter layer, a measurement parameter layer, and an output parameter layer. The parameters are encapsulated in key-value pairs as a dictionary structure for algorithm parsing and invocation. The core algorithm layer includes configuration loading and parsing algorithms, recursive partial algorithms, parameter precise location algorithms, and parameter persistence algorithms, which are used for parameter configuration management. The interface adaptation layer includes parameter acquisition and parameter update interfaces, which are used to enable adapted calls between the core algorithm layer and other modules.

10. The automatic detection system for irregular object shape parameters according to claim 8, characterized in that, Also includes: The log management module is used to record operation logs, error logs, and warning logs in a hierarchical manner for troubleshooting. The acquisition module is used to acquire the camera preview in real time, draw operation prompts and acquisition boxes, respond to case commands to complete the acquisition of irregular small objects, and transmit the acquired raw images to the image preprocessing module to start real-time detection. The anomaly handling module is used to verify the validity of image paths and contours, and to capture and record anomalies during the detection process through decorators. The batch detection module is used to acquire the original images of all irregular small objects in a specified folder, transmit them sequentially to the image preprocessing module to start batch detection, and summarize and save all detection data.