A traditional Chinese medicine pill appearance quality online detection method
By using asynchronous structured light field modulation and image processing with multi-ring LED light sources and a global shutter CMOS camera, the problems of mechanical displacement error and environmental interference in the appearance inspection of traditional Chinese medicine pills were solved, achieving high-precision surface defect identification and misjudgment suppression.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CANGZHOU MEDICAL COLLEGE
- Filing Date
- 2026-04-10
- Publication Date
- 2026-07-10
AI Technical Summary
During the production of traditional Chinese medicine pills, existing machine vision inspection methods are difficult to effectively identify surface defects such as pits and cracks, and are easily misjudged due to mechanical displacement errors, dimensional tolerances, and interference from environmental dust reflections.
Asynchronous structured light field modulation is performed using a multi-ring LED light source, and a dual-frame high-light sequence image is acquired using a global shutter CMOS industrial camera. The high-light connected components are extracted and refined, the kinematic displacement transformation matrix is calculated, and the dynamic reference curvature distribution function is reconstructed. Defects are distinguished and environmental noise is filtered out through inverse affine transformation and multimodal orthogonal verification.
It enables precise detection of the appearance quality of traditional Chinese medicine pills, eliminates mechanical displacement errors and dimensional tolerance interference, identifies different types of surface defects and distinguishes environmental noise interference, and improves the accuracy and reliability of detection.
Smart Images

Figure CN122367937A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of visual inspection technology, specifically to an online method for inspecting the appearance quality of traditional Chinese medicine pills. Background Technology
[0002] During the production and molding process of traditional Chinese medicine pills, surface defects such as pits, cracks, or indentations are easily formed. In industry, machine vision technology is often used for online screening to replace manual visual inspection. Because the surface of traditional Chinese medicine pills is relatively smooth and spherical, conventional two-dimensional imaging is insufficient to effectively capture the subtle topological changes on the surface. Existing inspection methods typically introduce multi-angle illumination or structured light systems to acquire reflective features, thereby resolving surface depth or morphological information.
[0003] In actual dynamic conveyor lines, these detection methods suffer from insufficient recognition accuracy and adaptability. The herbal pills under test move continuously with the conveyor mechanism. When the detection system acquires multiple frames of images under different light field conditions, unavoidable physical translation occurs between camera exposures, causing misalignment of the image sequence in spatial coordinates. Directly comparing these unregistered image features results in significant calculation errors. Furthermore, the herbal pills themselves have minute diameter tolerances during the rolling process. When comparing the morphology of the actual acquired images with a fixed standard theoretical template, conventional systems struggle to distinguish normal dimensional fluctuations from genuine surface defects, easily leading to false screening. Free dust or stray light in the production environment can also form random reflective spots on the pill surface. Existing methods, when analyzing local reflective features, struggle to effectively distinguish between optical path breaks caused by genuine physical deformation and pseudo-features generated by dust reflection, limiting the accuracy of the detection system in classifying different types of defects. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides an online inspection method for the appearance quality of traditional Chinese medicine pills. This method solves the problem that the appearance inspection of traditional Chinese medicine pills on a dynamic production line is easily affected by mechanical displacement errors, dimensional tolerances, and interference from environmental dust reflections, leading to inaccurate identification of surface morphology defects and the tendency to make misjudgments.
[0005] To achieve the above objectives, the present invention provides the following technical solution: an online method for detecting the appearance quality of traditional Chinese medicine pills, comprising the following steps: Control the multi-ring LED light source to perform asynchronous structured light field modulation and synchronously trigger the camera to acquire a two-frame high-light sequence image; The spectroscopic connected components of the dual-frame spectroscopic sequence images are extracted and dimensionality reduction is performed using a thinning algorithm to obtain the spectroscopic skeleton network of odd-numbered rings and even-numbered rings. Spatial calibration is performed by addressing the outermost specular features of the skeleton network to obtain the instantaneous physical sphere center coordinates, solve the kinematic displacement transformation matrix, and reconstruct the dynamic reference curvature distribution function; Calculate the local actual curvature of continuous curve segments inside the skeleton line network, compare the local actual curvature with the dynamic reference curvature distribution function by difference, and extract candidate distortion nodes; Perform an inverse affine transformation based on the kinematic displacement transformation matrix, and perform multimodal orthogonal verification on candidate distortion nodes in a unified coordinate system to distinguish defects and filter out environmental noise.
[0006] Preferably, the acquisition of the dual-frame highlight sequence image specifically includes the following steps: When a position arrival signal is received, the instantaneous speed of the transmission mechanism is written into the internal register; A non-overlapping double-pulse trigger signal is sent to the controller of the multi-ring LED light source. The time interval between the two high-level pulses is determined based on the instantaneous movement speed of the transmission mechanism and the actual physical size equivalent of a single pixel on the target plane of the camera target surface. The first high-level pulse is routed to the drive channel controlling the odd-numbered ring light source set, the second high-level pulse is routed to the drive channel controlling the even-numbered ring light source set, and the synchronization pulse signal is sent to the global shutter CMOS industrial camera. The first exposure is performed during the duration of the first high-level pulse to generate the first frame of the highlight sequence image, and the second exposure is performed during the duration of the second high-level pulse to generate the second frame of the highlight sequence image.
[0007] By combining the spatiotemporal state constraints with the camera exposure action, the macroscopic physical displacement error within the two-frame image acquisition interval is limited. The surface reflection characteristics at different incident angles are captured in a continuous flow state, thus constructing a data source for reverse deconstructing the surface morphology.
[0008] Preferably, the extraction of the specular connected components of the dual-frame specular sequence image specifically includes the following steps: The global gray-level histogram of the image is statistically analyzed using the maximum inter-class variance method, and the adaptive gray-level threshold is obtained by solving the problem. The adaptive grayscale threshold is used to perform a binarization mask operation on the image, transforming the original grayscale image into a shape matrix containing only 0 and 1; Calculate the total number of pixels in each connected region and the aspect ratio of the bounding box. Remove isolated connected regions with a total number of pixels less than a preset area threshold or an aspect ratio less than a preset aspect ratio threshold, and retain the specular connected regions that meet the area requirements.
[0009] The above scheme achieves the separation of target light field signal from background diffuse reflection based on adaptive threshold, and filters environmental stray light noise by combining morphological features to obtain effective specular shape boundary.
[0010] Preferably, the step of using a thinning algorithm for dimensionality reduction to obtain the specular skeleton network of odd-numbered and even-numbered rings specifically includes the following steps: The Zhang-Suen thinning algorithm is used to examine the boundary pixels with a value of 1 in the specular connected region one by one. When the boundary pixel is not a line segment endpoint and removing the corresponding pixel will not destroy the existing connectivity of the connected region, the value of the boundary pixel is changed from 1 to 0 until the specular connected region is compressed and stripped into a line form with a width of one pixel. The processed image matrix is translated into a coordinate set format containing multiple nodes, generating odd-ring specular skeleton networks and even-ring specular skeleton networks. Each node stores horizontal and vertical pixel coordinates.
[0011] The above scheme eliminates the uneven spot width caused by local reflectivity differences, transforms two-dimensional morphological features into geometric line segments composed of discrete nodes, and establishes a basic data structure for subsequent algebraic coordinate operations and curvature analysis.
[0012] Preferably, the spatial calibration of the outermost specular features of the skeleton network to obtain the instantaneous physical sphere center coordinates specifically includes the following steps: Calculate the average pixel distance from the pixel node on each connected curve segment to the geometric center pixel coordinate of the image plane, and extract the connected curve segment with the largest average pixel distance as the outermost highlight feature; Extract the set of all pixel coordinate points contained in the outermost highlight feature, construct a general quadratic curve algebraic equation, and introduce constraints to ensure that the fitted curve is strictly an elliptical closed shape. The least squares method is used to fit and calculate the coefficients of the algebraic equation, and the instantaneous physical center coordinates and actual pixel radius are calculated in reverse.
[0013] Using the above scheme, the reflective ring near the equatorial tangent, which is least affected by internal deformation, is used as a reference. The absolute physical center coordinates of the target at the moment of exposure are obtained through inverse spatial calculation, and a relative rigid body coordinate system is established.
[0014] Preferably, the step of solving the kinematic displacement transformation matrix and reconstructing the dynamic reference curvature distribution function specifically includes the following steps: Calculate the difference between the instantaneous physical center coordinates of the sphere in the horizontal and vertical directions at two consecutive moments, establish a two-dimensional translation vector that reflects the macroscopic displacement of the target, and construct the corresponding kinematic translation matrix in memory based on the two-dimensional translation vector as the kinematic displacement transformation matrix; The instantaneous physical sphere center coordinates and the actual pixel radius are input into the perspective projection mapping model, and the surface normal vector distribution is calculated by combining the spatial physical coordinates of the light source array. Based on the surface normal vector distribution, the theoretical skeleton curvature value under the current spatial pose is derived in a forward direction, and the odd-ring dynamic reference curvature distribution function and the even-ring dynamic reference curvature distribution function are generated.
[0015] The above scheme extracts the mechanical motion error generated by the translation vector quantization transmission mechanism, and positively reconstructs the curvature benchmark based on the external features of the current measured object, thereby decoupling the interference caused by the size tolerance of different Chinese medicine pills on the surface morphology judgment.
[0016] Preferably, calculating the local actual curvature of continuous curve segments within the skeleton network specifically includes the following steps: The internal continuous curve segments are converted into parametric equations, and the arc length parameter is approximated by the cumulative Euclidean distance between adjacent connected pixel nodes. The Gaussian kernel function in Gaussian smoothing filter is used to perform one-dimensional convolution operations with the horizontal pixel coordinate function and the vertical pixel coordinate function respectively, and the smoothed coordinate sequence is output. The first-order and second-order difference approximate derivatives in the horizontal and vertical directions are calculated using the central difference method for the smoothed coordinate sequence; Substituting the first-order difference approximation derivative and the second-order difference approximation derivative into the discrete plane curve curvature equation, the local actual curvature of each node is calculated.
[0017] Using the above scheme, one-dimensional convolution denoising is used to suppress the quantization and discretization interference of pixel grids within the differential geometry framework. Combined with the central difference to preserve the spatial alignment characteristics, numerical values reflecting the actual reflective topology of the surface of traditional Chinese medicine pills are calculated.
[0018] Preferably, the step of performing a differential comparison between the local actual curvature and the dynamic reference curvature distribution function to extract candidate distortion nodes specifically includes the following steps: Calculate the absolute value of the difference between the actual local curvature and the dynamic reference curvature distribution function at the corresponding coordinate position, and compare the absolute value with the preset curvature tolerance threshold point by point; Extract nodes whose absolute difference value is greater than the curvature tolerance threshold; Spatial connectivity verification is performed on the extracted nodes. When the number of adjacent nodes that continuously meet the curvature tolerance threshold condition is greater than the preset lower limit of defect size, they are confirmed as candidate distortion nodes, forming a set of candidate distortion nodes for odd-numbered rings and a set of candidate distortion nodes for even-numbered rings.
[0019] The above scheme performs differential verification of curvature fluctuations and spatial connectivity determination, filters out isolated high-frequency noise points left over from discrete operations, and achieves accurate positioning and initial screening of surface morphology distortion areas.
[0020] Preferably, the step of performing an inverse affine transformation based on the kinematic displacement transformation matrix and performing multimodal orthogonal verification on candidate distortion nodes in a unified coordinate system specifically includes the following steps: Subtract the two-dimensional translation vector from the coordinates of each node in the even-ring candidate distortion node set and perform an inverse affine transformation to generate an aligned even-ring candidate distortion node set. Within the theoretical mapping neighborhood of the candidate distorted node of the odd-numbered ring, search for whether there exists a corresponding aligned candidate distorted node of the even-numbered ring; If found, the actual spatial displacement offset vector is obtained by subtracting the coordinates of the candidate distortion nodes of the odd ring from the coordinates of the candidate distortion nodes of the even ring after alignment. The theoretical displacement vector is derived by combining the instantaneous physical sphere center coordinates with the actual pixel radius; By comparing the actual spatial displacement vector with the theoretical displacement vector, if the vector L2 norm of both is less than the tolerance norm, then the slowly varying topological defects can be distinguished in the multimodal orthogonal verification.
[0021] The above scheme eliminates cross-frame translation deviation based on kinematic algebra operations, tracks deformation offset trajectory according to optical deflection law in the same physical space, and completes the identification of smooth pits and other deformations that do not cause light breakage.
[0022] Preferably, the process of distinguishing defects and filtering out environmental noise specifically includes the following steps: If an aligned even-ring candidate distortion node cannot be found in the theoretical mapping neighborhood of the odd-ring candidate distortion node, then a local image neighborhood is set with the coordinates of the odd-ring candidate distortion node plus the absolute coordinates pointed to by the theoretical displacement vector as the center. Extract all pixel gray values in the local image neighborhood of the aligned second frame of the highlight sequence image, and calculate the mean energy integral and gray variance; If the mean integral of energy is less than the preset energy cutoff threshold and the gray variance is greater than the preset gradient mutation threshold, then step morphology defects can be distinguished in multimodal orthogonal verification. If the energy mean integral is greater than or equal to the energy cutoff threshold, then the odd-numbered ring candidate distortion node is determined to be caused by environmental noise, identified as a pseudo-defect feature, and removed from the candidate set.
[0023] The above scheme introduces a local energy loss and gradient mutation model to form an orthogonal verification mechanism, which identifies scattering or absorption breakpoints caused by microcracks, and separates interference signals generated by dust reflection or environmental speckle, thus completing defect classification and pseudo-feature cleaning.
[0024] This invention provides an online method for detecting the appearance quality of traditional Chinese medicine pills. It has the following beneficial effects: 1. This invention extracts the outermost highlight features of the skeleton network, inversely calculates the instantaneous physical center coordinates and actual pixel radius of the target at the moment of exposure, and then forward reconstructs a dynamic reference curvature distribution function specific to the current object under test. This replaces the traditional fixed standard template comparison, eliminates the interference of the dimensional tolerances of different Chinese medicine pills during the molding process on the judgment of surface morphology anomalies, and reduces the probability of traditional detection methods misjudging normal geometric fluctuations as defects.
[0025] 2. This invention establishes a two-dimensional translation vector by calculating the difference in physical sphere center coordinates between two consecutive acquisition times, and constructs the corresponding kinematic displacement transformation matrix. An inverse affine transformation is then performed on the candidate distortion nodes extracted in the subsequent frame. This step extracts the macroscopic physical displacement of the tested pellet caused by the conveying mechanism during the dual-pulse exposure time interval from the coordinate data, achieving spatial registration of the highlight features of the two frames in a unified absolute coordinate system, and eliminating cross-frame misalignment errors caused by the mechanical translation of the dynamic pipeline.
[0026] 3. This invention identifies gradually changing topological defects such as smooth pits by comparing the deviation between the actual spatial displacement vector and the theoretical displacement vector. Simultaneously, it introduces local energy mean integral and gray-level variance calculations in regions where cross-frame matching fails to identify step-like morphological defects such as microcracks where light is severely scattered. This branch-determination logic not only achieves the classification and identification of defects with different physical forms but also identifies and eliminates false defect signals caused by reflections from environmental dust. Attached Figure Description
[0027] Figure 1 This is a flowchart of the method steps of the present invention; Figure 2 This is a simulated specular skeleton extraction effect diagram of the present invention, wherein... Figure 2 Subgraph (a) in the image is the original binarized hyperspectral connected component graph. Figure 2 Neutron map (b) is the dimensionality-reduced single-pixel specular skeleton network diagram; Figure 3 This is a comparison curve of the local actual curvature and the dynamic reference curvature of the present invention. Detailed Implementation
[0028] The technical solutions in 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, and 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.
[0029] Please see the appendix Figure 1 This invention provides an online inspection method for the appearance quality of traditional Chinese medicine pills, relying on hardware equipment including a multi-ring LED light source, a global shutter CMOS industrial camera, an industrial control computer, and a conveying mechanism.
[0030] Global shutter CMOS industrial cameras have a multi-ring LED light source coaxially mounted around the lens. This multi-ring LED light source comprises multiple independently controlled concentric ring light-emitting arrays, physically connected and divided into an odd-numbered set of ring light sources. and even-numbered ring light source set .
[0031] The industrial control computer connects to a global shutter CMOS industrial camera and a multi-ring LED light source via a communication interface, and is used to send hardware trigger signals and receive corresponding image data. The conveyor mechanism is used to carry and continuously transport the Chinese medicine pills to be tested through the field of view of the global shutter CMOS industrial camera.
[0032] Based on the law of optical reflection, spatially incident light emitted from a multi-ring LED light source undergoes specular reflection on the surface of the traditional Chinese medicine pill, forming a highlight region on the two-dimensional target surface of the camera. Changes in the geometric morphology of the traditional Chinese medicine pill surface alter the local normal vector, thereby deforming the highlight topology on the two-dimensional target surface. This method uses this highlight topology as the data basis for analyzing surface morphology.
[0033] The method may include the following steps: S1. Control the multi-ring LED light source to perform asynchronous structured light field modulation, synchronously trigger the global shutter CMOS industrial camera, and acquire two-frame high-light sequence images of the Chinese medicine pills to be tested.
[0034] S2. Extract the hyperspectral connected components from the dual-frame hyperspectral sequence images, and use a thinning algorithm to reduce the dimensionality of the hyperspectral connected components to obtain odd-numbered ring hyperspectral skeleton networks and even-numbered ring hyperspectral skeleton networks that characterize the surface reflection features of traditional Chinese medicine pills.
[0035] S3 addresses the outermost specular features of the odd-ring specular skeleton network and the even-ring specular skeleton network, performs two-frame independent spatial calibration to obtain the instantaneous physical center coordinates of the Chinese medicine pill, solves the kinematic displacement transformation matrix of the target translation, and reconstructs the corresponding dynamic reference curvature distribution function.
[0036] S4. Calculate the local actual curvature of continuous curve segments inside the odd-ring specular skeleton network and the even-ring specular skeleton network, compare it with the dynamic reference curvature distribution function, and extract candidate distortion nodes that exceed the tolerance threshold.
[0037] S5. Perform inverse affine transformation on the characteristics of even-numbered rings based on the kinematic displacement transformation matrix, perform multimodal orthogonal verification on candidate distortion nodes of odd-numbered and even-numbered rings in a unified coordinate system, distinguish between slowly varying topological defects and step morphological defects of traditional Chinese medicine pills, and filter out environmental noise.
[0038] Step S1 discloses the physical execution process of asynchronous structured light field modulation and image sequence acquisition. This process truncates the continuously changing physical light field and converts it into a discrete digital image matrix through low-level control timing. In this embodiment, in order to obtain the multi-angle reflection characteristics of the surface of the object under test, the industrial control computer controls the hardware system to generate specific timing signals to convert the physical light field on the surface of the traditional Chinese medicine pill into a two-dimensional digital image.
[0039] To achieve the conversion from physical optical field to digital matrix on a dynamically moving production line, the system needs to overcome the phase error caused by high-frequency vibration and mechanical delay of the conveyor belt. As a preferred implementation, the system is built upon a hardware-level synchronization framework based on an optocoupler mechanism. The industrial control computer generates the underlying control timing sequence based on the position feedback and instantaneous speed of the conveyor mechanism. The specific hardware triggering and coordinated execution steps are as follows: S111. When the conveyor transports the traditional Chinese medicine pills to the preset physical trigger position of the global shutter CMOS industrial camera, the photoelectric sensor sends a position arrival signal to the industrial control computer. To establish a calculation benchmark for subsequent dynamic compensation, the system, while receiving this signal, also writes the instantaneous movement speed of the conveyor fed back by the encoder into the internal register.
[0040] S112. After receiving the position arrival signal, the industrial control computer sends a non-overlapping double-pulse trigger signal to the controller of the multi-ring LED light source through its internal digital I / O interface. The non-overlapping double-pulse trigger signal consists of two high-level pulses, and the time interval between the two high-level pulses is set to... Considering that traditional Chinese medicine pills are in a state of continuous motion, this time interval... The upper limit must be strictly constrained by the kinematic blur of the imaging system.
[0041] In this embodiment, the system is based on the formula Determine the upper limit of this time interval. Among them, The actual physical size equivalent of a single pixel on the camera target surface in the target plane (unit: mm / pixel). The instantaneous velocity (in millimeters per microsecond) of the conveyor mechanism acquired in the preceding steps. This constraint ensures that the macroscopic physical displacement of the object is limited to within one pixel during the acquisition interval between two image frames. The specific value range is specified as 10-500 μs.
[0042] The controller of the S113 multi-ring LED light source analyzes the non-overlapping double-pulse trigger signal, routes the first high-level pulse to the drive channel controlling the odd-numbered ring light source set, and routes the second high-level pulse to the drive channel controlling the even-numbered ring light source set. The industrial control computer sends the synchronization pulse signal to the global shutter CMOS industrial camera through the camera trigger cable, ensuring that the camera's exposure action and the light source's illumination state are strictly aligned on the time axis.
[0043] For the specific circuit connections and communication protocols for the industrial control computer to send trigger signals and for the camera and light source to trigger synchronously, those skilled in the art can consult the product manual for configuration based on the selected hardware model. This is well-known technology in the field and will not be elaborated here.
[0044] After the underlying light source controller successfully receives and analyzes the aforementioned non-overlapping double pulse signal, the multi-ring LED light source immediately generates a response in physical space. The odd-numbered and even-numbered ring light source sets alternate on the time axis, and the specific evolution process of their physical light field state can be described as follows: S121. A multi-ring LED light source is coaxially mounted around the camera lens, with the light emitted from each concentric ring array converging towards the center of the field of view. The multi-ring LED light source is defined as comprising a total of N concentric ring arrays, where the odd-numbered ring arrays are... An array containing odd-numbered arrays (1, 3, 5, etc.) and a set of even-numbered ring light sources. The array includes even-numbered arrays such as 2, 4, and 6. In practical industrial applications, to balance the light source volume and light field coverage density, the total number N of concentric ring arrays is preferably 4 to 8.
[0045] S122, During the duration of the first high-level pulse, i.e., at time... Odd-numbered ring light source set Even-numbered ring light source set is in the on state. The device is in the off state. At this time, the incident light field illuminating the surface of the herbal pills exhibits a discrete ring-shaped beam distribution emitted by an odd-numbered ring array. This discrete light field forms a light-dark alternating reflection texture with specific intervals on the smooth pill surface, providing a topological basis for subsequent skeleton extraction.
[0046] S123, after a time interval During the duration of the second high-level pulse, i.e. time... Odd-numbered ring light source set Switched to off state, even-numbered ring light source set Switching to the on state. At this time, the incident light field illuminating the same Chinese medicine pill surface switches to a discrete ring beam distribution emitted by an even-numbered ring array, and the spatial angle of the incident light compared to time... Things have changed.
[0047] With the rapid alternation of the aforementioned physical light fields, the global shutter CMOS industrial camera must capture the surface reflection characteristics under these two different incident angles within an extremely short time window. From the perspective of signal processing principles, when the camera captures a moving target, the continuous light radiation energy needs to be converted into a discrete array through the integration of the photoelectric sensor. By coupling the spatiotemporal state constraints with the camera's exposure action, the specific mathematical mapping process for the system to capture two frames of spatiotemporal images is as follows: S131. Define the spatiotemporal image function of the imaging system as follows: .
[0048] In the formula, These are the horizontal pixel coordinates in the physical coordinate system of the two-dimensional image; These are the vertical pixel coordinates in the physical coordinate system of a two-dimensional image. The time variable represents the specific physical moment of image acquisition. Optically, this function characterizes the instantaneous photoradiance energy density received by any coordinate point within the camera's field of view in the continuous time domain.
[0049] S132, at time A global shutter CMOS industrial camera performs the first exposure. The camera target surface receives odd-ring incident light reflected from the surface of the traditional Chinese medicine pill, and after photocharge conversion, generates the first frame of the highlight sequence image. This process can be expressed as spatiotemporal image function truncation under the condition that the set of odd-ring light sources is on: In the formula, This represents the pixel grayscale distribution of the first frame of the highlight sequence image; For a moment Spatiotemporal image function; This represents the physical state constraint for the activation of the odd-numbered ring light source set. When its value is true, it indicates that the hardware drive channel of the odd-numbered ring is closed, allowing light field integration.
[0050] S133, at time The global shutter CMOS industrial camera performs a second exposure. The camera target surface receives even-numbered rings of incident light reflected from the surface of the traditional Chinese medicine pill, generating a second frame of highlight sequence image. This process can also be represented as: In the formula, This represents the pixel grayscale distribution of the second frame of the highlight sequence image; For a moment Spatiotemporal image function; This represents the Boolean control state variable for the even-numbered ring light source set. Because... The two frames acquired at this time record the specular reflection characteristics of the same object under two different incident light fields in a relatively static pose, thus forming a cross-modal raw data source for reverse deconstruction of surface morphology.
[0051] During step S2, the industrial control computer performs digital signal processing on the previously acquired image data, extracting large-area reflective patches and converting them into one-dimensional geometric topological line segments.
[0052] To achieve the conversion of large-area patches into topological line segments, the primary challenge for the system is to accurately separate the effective light field signal from the diffuse background in the original dual-frame image acquired in step S1. Based on the physical characteristics of the high-reflectivity surface of traditional Chinese medicine pills, the local light radiation energy in the effective reflective area is significantly higher than that of the environmental background. Therefore, the system performs pixel-level stripping operations based on an adaptive grayscale threshold. As a preferred implementation, the specific steps of this separation process based on global statistical characteristics are as follows: S211. The system receives a first frame and a second frame of hyperbola image with strictly aligned time and phase. Due to specular reflection caused by the multi-ring LED light source illuminating the smooth surface of the traditional Chinese medicine pills, the grayscale value of the reflective area in the image is higher than that of the background area where no specular reflection occurs. The system needs to separate these two parts of data.
[0053] S212. Calculate the adaptive grayscale threshold for the dual-frame sequence image. At this time, the system uses the maximum inter-class variance method to statistically analyze the global grayscale histogram of the image, and solves for the grayscale value that maximizes the inter-class variance between the target and the background as the adaptive grayscale threshold of the image.
[0054] To ensure the integrity of the algorithm logic, when the overall illumination is extremely low during the statistical process, causing the denominator of the inter-class variance calculation to approach 0, or when the overall variance is less than the preset effective light field lower limit (in this embodiment, the effective light field lower limit is determined by the system pre-collecting the mean value of the dark current noise variance of the camera in a completely dark environment), the system determines that the current frame has failed to effectively capture light field information, and then triggers an anomaly flag and intercepts the frame data, thereby avoiding subsequent matrix singularity operations.
[0055] S213. Perform a binarization mask operation on the image using an adaptive grayscale threshold. The system iterates through each pixel in the image, classifying areas with grayscale values greater than the adaptive grayscale threshold as highlight areas and assigning them a value of 1, while classifying areas with grayscale values less than or equal to the adaptive grayscale threshold as dark background areas and assigning them a value of 0. The calculation logic for this binarization mask operation is expressed by the following formula: In the formula, The output image mask matrix value after binarization masking operation; This represents the grayscale value of the original highlight sequence image at the corresponding pixel coordinates. The index parameter is for the image type, and its value is... or ; These are the horizontal pixel coordinates in the physical coordinate system of the two-dimensional image; These are the vertical pixel coordinates in the physical coordinate system of a two-dimensional image. This is an adaptive grayscale threshold. This binarization matrix not only achieves mathematical decoupling between the target and the background, but also physically defines the boundary benchmark for subsequent morphological analysis.
[0056] S214. After binarization masking, the original grayscale image is transformed into a morphological matrix containing only 0s and 1s. The set of pixels with a value of 1 in this matrix forms multiple connected regions. To avoid biased judgments due to reliance on a single facet value, the system further calculates the total number of pixels in each connected region and the aspect ratio of the bounding box.
[0057] Since real ring specular highlights exhibit obvious linear geometric features when locally unfolded, the system will discard isolated connected regions with a total number of pixels less than a preset area threshold or an aspect ratio less than an aspect ratio threshold as environmental stray light noise, and retain specular connected regions that meet the area requirements.
[0058] The aspect ratio threshold is set based on the fact that when a ring light source illuminates a target object (such as a curved or highly reflective surface), the reflected light spot undergoes geometric stretching on the camera's two-dimensional projection plane, causing the localized spread of true highlights to appear as elongated or arc-shaped linear features. Based on this optical distortion and physical structural characteristic, the system sets the aspect ratio threshold to a constant greater than 3 (preferably, between 3.5 and 5.0). Areas below this ratio are typically diffuse, blocky stray light from the background environment.
[0059] The preset area threshold is determined by the camera's sensor resolution, the lens's optical magnification (or working distance), and the actual luminous area of the ring light source. In practical applications, the system acquires images of standard test samples, statistically analyzes the lower limit of the area distribution of the true specular connected regions, and reserves a certain tolerance margin as the threshold. Preferably, the preset area threshold is set to 50-150 pixels. Minimal connected regions below this area are typically meaningless dust reflections or sensor dark current noise.
[0060] After the above masking and filtering processes, relatively pure specular connected regions were extracted. However, in actual physical scenarios, due to limitations such as local curvature variations, reflectivity differences, and optical diffraction effects on the surface of traditional Chinese medicine pills, these connected regions often exhibit planar patch morphologies with uneven widths. Directly applying planar data would lead to significant geometric variance in subsequent algebraic curve fitting. To eliminate this morphological redundancy, a morphological thinning algorithm is needed to further reduce the dimensionality of these two-dimensional patches and extract the core skeleton lines representing their geometric orientation. This thinning process is based on the principle of topological equivalence, and its specific pixel-level computational steps are as follows: S221. After obtaining the highly visible connected region, given that the width of the reflective region will vary due to the difference in reflectivity of the surface of the traditional Chinese medicine pills, morphological dimension reduction extraction is performed to find the center line representing the geometric direction of the reflective ring.
[0061] S222. A morphological thinning algorithm is used to peel away the boundaries of the specular connected regions layer by layer. At this point, the Zhang-Suen thinning algorithm needs to be used to perform pixel traversal. The algorithm checks the boundary pixels with a value of 1 in the specular connected region one by one and obtains the state of its eight neighboring pixels.
[0062] S223. In the refined iterative calculation, it is also necessary to count the number of non-zero pixels in the neighboring nodes of the center pixel and calculate the number of jumps from 0 to 1 in the neighboring pixel sequence. When the condition that the boundary pixel is not a line segment endpoint and removing the pixel will not destroy the existing connectivity of the connected component is met, the value of the boundary pixel is changed from 1 to 0. This judgment logic ensures that the continuity of the high-brightness ring in the physical topology is not interrupted while eliminating the redundant width of the spot.
[0063] S224. Repeat the above boundary pixel stripping iteration on the entire image's specular connected components. When the entire image has been traversed and no more boundary pixels meeting the deletion criteria exist, the thinning process terminates. At this point, the original specular connected components have been compressed and stripped into lines of single-pixel width.
[0064] For the specific search order of the eight-neighbor traversal and the conventional constraints of the internal condition judgment in the Zhang-Suen thinning algorithm, those skilled in the art can consult image processing literature for application. Its operation rules are well-known technologies in this field and will not be elaborated here.
[0065] At this point, the originally large and unevenly wide specular connected regions have been successfully compressed into topological lines of single-pixel width. It should be noted that these line features are still encapsulated in the form of a two-dimensional image mask matrix. To facilitate rapid coordinate algebraic operations and curvature analysis in subsequent steps, these matrix features need to be translated into a structured set of digital coordinates. In this embodiment, the data structure definition and recombination process of the dimensionality reduction output are as follows: S231. After the morphological thinning algorithm is completed, the processed image matrix needs to be translated into a coordinate set format to generate odd-ring specular skeleton networks and even-ring specular skeleton networks with a single pixel width.
[0066] S232, Define the odd-ring specular skeleton network Even-numbered ring specular skeleton network Both types of skeleton line networks are represented in system memory as ordered lists containing multiple nodes. Each continuous curve in the skeleton line network corresponds to an actual reflective ring formed on the surface of the object being measured by a multi-ring LED light source.
[0067] S233, In the data structure record, odd-ring specular skeleton line network Even-numbered ring specular skeleton network Each node stores a value in two dimensions. These two dimensions are the horizontal and vertical pixel coordinates of the node in the two-dimensional image physical coordinate system, respectively. This transformation from an area matrix to a set of node coordinates abstracts morphological features into geometric line segments composed of discrete nodes, establishing the basic data structure for subsequent algebraic operations and curvature calculations on the nodes.
[0068] In step S3, the system analyzes the specific specular features after dimensionality reduction to calculate the instantaneous spatial pose of the object under test and performs mathematical compensation for the physical displacement between the two exposures. As a preferred implementation, this step aims to establish a relative rigid body coordinate system that eliminates mechanical translation errors and dimensional tolerance interference.
[0069] After dimensionality reduction from a large-area light spot to a one-dimensional skeleton network in step S2, the system obtains a set of discrete coordinates representing the surface reflection morphology of the object. To accurately locate the instantaneous spatial pose of the object during dynamic transmission, it is necessary to extract the baseline features from these skeleton lines that are least affected by local defects and best represent the overall contour of the object. Therefore, the system initiates the addressing mechanism for the outermost specular features and performs inverse spatial calculation based on the least squares method. The specific steps are as follows: S311. The system searches for the outermost specular features in the odd-ring and even-ring specular skeleton networks. First, it calculates the pixel coordinates of the geometric center of the image plane, then traverses all connected curve segments in the skeleton network, and finally calculates the average pixel distance from the pixel node on each connected curve segment to the geometric center.
[0070] To prevent data overflow due to severe loss of image features, the total number of connected segments in the network is checked before computation. If an empty segment is detected, an anomaly flag is triggered and the spatial solution for the current frame is terminated. Simultaneously, using average distance instead of a single extreme distance as the evaluation metric effectively reduces addressing bias caused by local stray light noise. Furthermore, the system extracts the connected curve segment with the largest average pixel distance as the outermost highlight feature. This feature physically corresponds to the reflective ring near the equatorial tangent of the tested traditional Chinese medicine pill, and is least affected by changes in internal morphology.
[0071] S312. Extract the set of all pixel coordinates contained in the outermost highlight feature, and let this set of points be: In the formula, It is the set of pixels that represent the outermost highlight features; The index parameter for the image type has a value of or ; For the set of The horizontal pixel coordinates of each pixel; For the set of The vertical pixel coordinates of each pixel; This represents the total number of pixels contained in the set.
[0072] S313, Utilizing the extracted point set Construct the algebraic equation for a general quadratic curve: In the formula, For horizontal pixel coordinates; For vertical pixel coordinates; , , , , , These are the coefficients of the algebraic equation to be solved. To avoid generating trivial solutions, constraints are introduced into the algebraic calculations. This nonlinear constraint ensures, from an algebraic geometric perspective, that the fitted curve is strictly an elliptical closed shape, thus eliminating the interference of divergent and degenerate solutions such as hyperbolas or parabolas.
[0073] S314. Apply the least squares method to the point set. A fitting calculation is performed to find the coefficients of a set of algebraic equations that minimize the sum of squared residuals. After the coefficient fitting is completed, these coefficients are substituted into the geometric parameter conversion formula to inversely calculate the instantaneous physical center coordinates and actual pixel radius of the target circle at the current moment.
[0074] S315, the system performs this operation independently for each of the two frames of data. For time... The odd-ring specular skeleton network was used to calculate the instantaneous physical sphere center coordinates. Compared with actual pixel radius For time The even-ring specular skeleton network is used to calculate the instantaneous physical sphere center coordinates. Compared with actual pixel radius .
[0075] For the specific mathematical derivation of converting the coordinates of the ellipse center and the radii of the major and minor axes through the coefficients of the algebraic equation, those skilled in the art can consult relevant mathematical handbooks on analytic geometry for calculation. The conversion process is a well-known technique in this field and will not be elaborated here.
[0076] After completing the inverse calculation of the independent two frames using the aforementioned least squares method, the absolute physical center coordinates of the object under test at the instants of the two exposures were successfully obtained. However, due to the continuous operation of the underlying transmission mechanism, the object inevitably undergoes macroscopic physical displacement within these two extremely short time intervals. Without eliminating this displacement component, directly performing cross-frame difference calculations will introduce severe spatial aliasing errors. To ensure that subsequent cross-frame comparisons can be strictly aligned spatially, this displacement must be mathematically compensated. The specific calculation logic for the kinematic translation matrix and the two-dimensional translation vector is as follows: S321. The system obtains the instantaneous physical center coordinates of the sphere at two consecutive moments. and Because the Chinese medicine pills move continuously with the conveying mechanism, there is an absolute positional deviation between these two coordinate nodes on the two-dimensional image plane.
[0077] S322. By calculating the difference between the horizontal and vertical coordinates of the physical sphere's center, a system reflecting the target's position over time intervals is established. Two-dimensional translation vector of internal macroscopic displacement The calculation formula is as follows: In the formula, It is a two-dimensional translation vector; For a moment The horizontal coordinates of the physical center of the sphere; For a moment The horizontal coordinates of the physical center of the sphere; For a moment The physical center of the sphere perpendicular coordinates; For a moment The physical center of the sphere is perpendicular to the coordinates.
[0078] S323. Based on this two-dimensional translation vector, the system constructs the corresponding kinematic translation matrix in memory. This matrix is algebraically represented as a third-order square matrix with diagonal elements of 1 and the last column containing two-dimensional translation components. It represents the mechanical motion error introduced by the transmission mechanism and is used to guide subsequent steps to align the two frames of images to the same static coordinate system.
[0079] After establishing the kinematic compensation matrix to eliminate the interference of mechanical displacement, another core challenge remains: the influence of the dimensional tolerances of different Chinese medicine pills on the determination of surface morphology.
[0080] Because each pellet undergoes minute diameter expansion and contraction during molding, normal geometric tolerances can easily be misjudged as surface morphology defects if a uniform static benchmark template is used for comparison. To completely decouple the correlation between object dimensional tolerances and defect judgment, it is necessary to move away from relying on a fixed standard template and instead extract the just-calculated instantaneous physical sphere center coordinates and actual pixel radius as dynamic input variables to forward reconstruct an ideal benchmark specific to the currently measured object. The specific mapping mechanism of this reconstructed dynamic benchmark curvature distribution function is as follows: S331. Retrieve the pre-calibrated camera perspective projection matrix parameters and the spatial physical coordinates of the light source array from the storage unit. These three-dimensional calibration parameters constitute the deterministic mapping boundary from the lighting geometry of the real physical world to the two-dimensional pixel plane.
[0081] S332, calculate the instantaneous physical sphere center coordinates. Compared with actual pixel radius The data is input into a perspective projection mapping model based on the pinhole imaging principle. Combined with the spatial physical coordinates of the odd-numbered ring light source set, the surface normal vector distribution of the ideal defect-free sphere at each pixel coordinate is calculated.
[0082] Specifically, the current target is approximated as... For the physical projection center, Let be an ideal standard hemisphere representing the projection boundary. Based on the analytical properties of spherical geometry, the three-dimensional spatial normal vector of any point on this ideal surface is the radial unit vector pointing from the virtual center of the sphere to the feature point on the measured surface. Through this mapping mechanism, an up-dimensional solution from two-dimensional planar coordinates to three-dimensional theoretical normals is achieved.
[0083] S333. Based on the normal vector distribution of the ideal surface, the system derives the theoretical skeleton curvature value under the current space-time pose, and then generates the time. The odd-numbered ring dynamic reference curvature distribution function. Similarly, using and By combining the spatial physical coordinates of the even-numbered ring light source set, the generation time is determined. Even-numbered ring dynamic reference curvature distribution function Among them, the odd-ring dynamic reference curvature distribution function is located at the image coordinates. The ideal reference curvature value for the odd-numbered rings; the dynamic reference curvature distribution function for the even-numbered rings is located at the image coordinates. The even-numbered ring ideal reference curvature value at the location. This calculation mechanism, which reconstructs the reference based on its own peripheral features, eliminates the interference of the target object's own dimensional tolerances on curvature determination.
[0084] During step S4, the system uses a differential geometry algorithm to perform numerical analysis on the dimensionality-reduced skeleton network, thereby locating the geometrically deformed regions exhibiting abnormal surface morphology.
[0085] To locate deformation using differential geometry algorithms, the core lies in solving for the derivatives of the skeleton curve. However, since digital images are essentially composed of discrete pixel grids, directly performing differential calculations on discrete coordinates drastically amplifies the quantization noise of the image, causing subsequent curvature calculations to fail. To solve this problem, a Gaussian smoothing mechanism needs to be introduced before differentiation. The specific steps for filtering, noise reduction, and differential approximation derivative calculations are as follows: S411. The system converts the continuous curve segments within the odd-ring specular skeleton network and the even-ring specular skeleton network into parametric equation form. Let any parametric continuous curve segment be: In the formula, For parameterized continuous curve segments on the skeleton network; This is the arc length parameter of the curve; This is the horizontal pixel coordinate function corresponding to the arc length parameter; This is the vertical pixel coordinate function corresponding to the arc length parameter.
[0086] This parameterization maps coordinate information, originally dependent on a two-dimensional mesh, to a one-dimensional sequence along the geometric direction of the curve. To achieve this transition from the continuous domain to the discrete domain, the arc length parameter is used in the specific mesh computation implementation. Approximate quantization is performed using the cumulative Euclidean distance between adjacent connected pixel nodes, thus establishing an independent numerical variable for subsequent calculus operations.
[0087] S412. Since digital images are composed of discrete pixels, directly differentiating discrete coordinates amplifies image quantization noise. Therefore, Gaussian smoothing filtering is used to denoise the parameterized continuous curve segments before calculating the derivative. As a preferred method, the system calls a preset Gaussian kernel function to perform one-dimensional convolution operations with the horizontal and vertical pixel coordinate functions, respectively, and outputs a smoothed coordinate sequence. In this embodiment, the scale parameter (i.e., standard deviation) of the Gaussian kernel function is pre-calibrated in conjunction with the camera's optical resolution and the expected defect spatial bandwidth, and its preferred value range is 1.0-2.5, thereby achieving the best engineering balance between suppressing high-frequency discrete noise and preserving the true physical morphology features.
[0088] For the generation of Gaussian kernel functions and the specific numerical calculation methods for one-dimensional convolution of discrete sequences, those skilled in the art can consult digital signal processing manuals to write the code. The operational logic is a well-known technology in this field and will not be elaborated here.
[0089] S413. After obtaining the smoothed coordinate sequence, the system calculates the first-order and second-order difference approximate derivatives for each node on the parameterized continuous curve segment. In the specific implementation of the lower-level features, to avoid spatial phase shifts caused by conventional forward or backward differencing, the system preferably uses the central difference method for numerical differentiation. The system uses the coordinate difference between adjacent nodes to represent the first-order derivative of that point in the horizontal and vertical directions, and uses the difference in the first-order derivatives of adjacent nodes to represent the second-order derivative of that point in the horizontal and vertical directions. Let the step size be... Then the current node The first-order central difference approximation is: The second-order central difference is approximately: Vertical coordinates The calculation logic for direction is equivalent. This centrally symmetric difference structure ensures that the geometric features before and after differentiation remain strictly aligned in pixel space.
[0090] After the above smoothing, noise reduction, and center difference processing, the system establishes the mathematical algebraic foundation for the local deformation degree of the analytical skeleton network. Next, these discrete derivative values are mapped to differential geometric space to solve for the actual local curvature reflecting the true reflection morphology of the measured object's surface. The specific calculation steps are as follows: S421. After obtaining the horizontal first derivative, vertical first derivative, horizontal second derivative, and vertical second derivative of each node on the continuous curve segment, the system substitutes them into the discrete plane curve curvature equation to calculate the actual local curvature of each node on the skeleton network.
[0091] S422. The specific formula for calculating the actual local curvature is as follows: In the formula, Located at image coordinates The actual local curvature at that point; The first derivative of the horizontal coordinate of the parameterized continuous curve segment at the current node; The first derivative of the vertical coordinate of the parameterized continuous curve segment at the current node; The second derivative of the horizontal coordinate of the parameterized continuous curve segment at the current node; The second derivative of the vertical coordinate of the parameterized continuous curve segment at the current node; This is the absolute value operator.
[0092] S423. After the calculation is completed, all nodes on the odd-numbered ring specular skeleton network and the even-numbered ring specular skeleton network are traversed in turn. The actual local curvature values of each node are calculated one by one according to the above formula, forming a numerical sequence that reflects the actual reflection morphology of the surface of the Chinese medicine pill.
[0093] The actual local curvature numerical sequence generated by the above calculation truly reflects the topological morphology of the current surface of the traditional Chinese medicine pills. To accurately screen for potential morphological defects, the system must perform differential verification against theoretical expectations. Therefore, the system retrieves the reconstructed dynamic baseline curvature distribution function from step S3 and performs a rigorous differential comparison to extract candidate distorted nodes. The specific judgment criteria are as follows: S431. The system establishes differential comparison conditions between the actual local curvature and the dynamic reference curvature distribution function. The system retrieves the odd-ring dynamic reference curvature distribution function and the even-ring dynamic reference curvature distribution function generated in step S3. For any node on the odd-ring specular skeleton network, the system calculates the absolute value of the difference between its actual local curvature and the odd-ring dynamic reference curvature distribution function at the corresponding coordinate position.
[0094] S432. The system sets a curvature tolerance threshold in its internal register. This tolerance threshold characterizes the allowable morphological tolerance range for traditional Chinese medicine pills under normal production processes. The system compares the calculated absolute difference with the curvature tolerance threshold point by point.
[0095] S433. Based on the above comparison conditions, the system extracts nodes that exceed the normal fluctuation range. Extract the candidate distortion node set for odd-numbered rings. The judgment criteria are as follows: In the formula, This is the set of candidate distorted nodes for odd-numbered rings; These are the pixel coordinates in the physical coordinate system of the two-dimensional image. For odd-numbered ring specular skeleton lines; Located at image coordinates The actual local curvature at that point; Located at image coordinates Ideal reference curvature values for odd-numbered rings at the location; This is the absolute value operator; This is the curvature tolerance threshold.
[0096] S434. Similarly, the system extracts the candidate distorted node set for even-numbered cycles. The judgment criteria are as follows: In the formula, For the set of candidate distorted nodes of even-numbered rings; These are the pixel coordinates in the physical coordinate system of the two-dimensional image. For even-numbered ring specular skeleton lines; Located at image coordinates The actual local curvature at that point; Located at image coordinates Even-numbered ring ideal reference curvature values at the location; This is the absolute value operator; This is the curvature tolerance threshold.
[0097] S435. Finally, the coordinate nodes that meet the above criteria are recorded and saved to the candidate distortion node set. In order to avoid system misjudgment caused by a single extreme value mutation, the system further performs spatial connectivity verification on the dataset inside the candidate distortion node set. Specifically, only when the number of adjacent nodes (i.e., equivalent geometric arc length) that continuously meet the above tolerance threshold conditions on the skeleton line is greater than the preset lower limit of the defect size, it is officially confirmed as a suspected surface morphology defect.
[0098] In this embodiment, the lower limit of the defect size is calculated by combining the calibrated optical resolution of the industrial camera with the minimum acceptable physical size allowed in the relevant pharmacopoeia quality specifications. This multi-dimensional judgment logic effectively filters out isolated high-frequency noise points left by the system discretization process, and completes the initial screening operation of suspected surface morphology defects.
[0099] When performing step S5, the system maps abnormal nodes in the two frames of images to the same coordinate system and uses optical laws and local pixel statistical features to distinguish between real morphological defects and environmental noise.
[0100] After extracting the candidate distortion node sets for two independent time points in step S4, the system faces the problem of spatial misalignment in cross-frame feature collision. Due to the continuous movement of the pipeline, the time points... With time The image reference frames do not coincide. To ensure strict matching of the two frames under the same physical reference, the system first needs to eliminate the macroscopic displacement deviation within this small time interval. The specific steps of performing the inverse affine transformation and the absolute coordinate system are as follows: S511. The system retrieves the kinematic translation matrix calculated in step S3 from memory and extracts the two-dimensional translation vector from it. This two-dimensional translation vector characterizes the mechanical motion error introduced by the conveying mechanism during the time interval between two exposures of the traditional Chinese medicine pill.
[0101] S512. Extract the coordinates of all nodes in the even-numbered cycle candidate distortion node set. The even-numbered cycle candidate distortion node set records the time... The suspected defect locations on the surface of the Chinese herbal pills.
[0102] S513. The system performs an inverse affine transformation on each node in the candidate distortion node set of even-numbered rings. The calculation logic of the inverse affine transformation is to subtract the two-dimensional translation vector from the node coordinates, and its formula is as follows: In the formula, The coordinates of the candidate distorted nodes of the even-numbered ring after alignment; The coordinates of the original even-numbered ring candidate distortion nodes; It is a two-dimensional translation vector. This algebraic operation physically removes the conveyor belt translation component, achieving rigid registration of cross-frame features in the spatial dimension.
[0103] S514. After the above inverse affine transformation process, the system will... The acquired even-numbered ring specular features are strictly mapped to time in spatial location. In the absolute spatial coordinate system, the reference frames of the two images are unified, the system eliminates the macroscopic displacement deviation caused by the continuous motion of the pipeline, and generates an aligned set of candidate distortion nodes for even-numbered rings.
[0104] After aligning the absolute coordinate system, the suspected defect features in the two-frame images have been mapped to the same physical space. At this point, the system can track the spatial offset trajectory of the same physical defect under different incident light fields based on the optical reflection law of continuous surfaces.
[0105] In general optical principles, when the incident angle of the illumination source changes known (i.e., switching from an odd-numbered ring to an even-numbered ring), the reflection point on an ideal smooth sphere will undergo an analytically deterministic displacement along the normal. However, local deformation will change the actual local surface normal vector at that point, causing the actual reflection displacement to deviate significantly from the theoretically expected value. Based on this physical causal relationship, for deformations such as gentle pits that do not cause light breakage, the system executes tolerance matching logic to determine gradually changing topological defects. The specific steps are as follows: S521. After establishing a unified absolute spatial coordinate system, the system traverses any odd-ring candidate distortion node in the set of odd-ring candidate distortion nodes, preparing to perform cross-frame feature matching.
[0106] S522. Within the theoretical mapping neighborhood of the odd-numbered ring candidate distortion nodes, retrieve the aligned even-numbered ring candidate distortion node set. The system searches within this region to determine if a corresponding aligned even-numbered ring candidate distortion node exists. In this embodiment, to accommodate minor assembly tolerances and calibration errors in the underlying hardware, the theoretical mapping neighborhood is typically set as a closed circular or square pixel window with a search radius of 2 to 4 pixels, centered on the theoretical mapping target point of the odd-numbered ring node, thus avoiding the omission of normal matches due to overly stringent settings.
[0107] S523. If the corresponding aligned even-numbered ring candidate distortion node is found, the system calculates the actual spatial displacement offset vector between these two nodes. The actual spatial displacement offset vector is equal to the coordinates of the aligned even-numbered ring candidate distortion node minus the coordinates of the odd-numbered ring candidate distortion node.
[0108] S524. Next, using the instantaneous physical sphere center coordinates and actual pixel radius obtained in step S3, combined with the calibration model of the tested Chinese medicine pill and the spatial physical coordinates of the adjacent luminous rings, the theoretical displacement vector is derived in a forward direction. The mathematical derivation of the spatial geometric mapping relationship based on the optical reflection law and the incident angle deflection can be performed by those skilled in the art by consulting relevant basic literature on optical engineering. The optical path tracing conversion is a well-known technique in this field and will not be elaborated here.
[0109] S525. The system presets a tolerance norm in its internal registers to limit the allowable error range of reflection offset caused by actual deformation. The system compares the actual spatial displacement offset vector with the theoretical displacement vector, and determines the following conditions for slowly changing topological defects: In the formula, The vector 2 norm operator; This is the actual spatial displacement offset vector; This is the theoretical displacement vector; This is the tolerance norm. If this condition is met, it indicates that the displacement of the reflection region caused by distortion conforms to the optical path deflection law of a continuous surface, and the system classifies this node region as a gradually varying topological defect. The specific sub-features of gradually varying topological defects include gentle pits and mechanical indentations.
[0110] However, not all surface anomalies exhibit continuous reflection trajectory shifts. When the surface contains step defects that severely disrupt the topology, such as microcracks, the incident beam will be heavily scattered or directly absorbed by the micro-cavity structure, inevitably causing the aforementioned cross-frame matching to fail. Simultaneously, reflections from ambient dust can also trigger similar isolated pseudo-defect interference. To accurately distinguish between optical path breaks and environmental noise, the system further introduces local energy integration for orthogonal verification. The closed-loop conditions for determining step morphology defects and filtering out environmental noise are as follows: S531. If the system fails to find aligned even-ring candidate distortion nodes within the theoretically mapped neighborhood of the odd-ring candidate distortion nodes, it indicates that the specular skeleton is broken in this region. This physical phenomenon originates from a step abrupt change on the surface that blocks the directional reflection path of light. The system then initiates a local energy deficiency determination model.
[0111] S532. The system defines the local image neighborhood. Centered on the coordinates of the odd-ring candidate distortion nodes plus the absolute coordinates pointed to by the theoretical displacement vector, the system sets a fixed-size pixel window (e.g., 5×5 pixels) as the local image neighborhood in the aligned second frame of the highlight sequence image. To ensure the robustness of subsequent mathematical calculations, the system incorporates an out-of-bounds verification mechanism here; if the defined pixel window boundary exceeds the actual effective physical size of the image, the system uses an edge pixel copying method to perform boundary mirroring filling.
[0112] S533. The system extracts the grayscale values of all pixels within the local image neighborhood of the aligned second frame highlight sequence image, and calculates the energy mean integral and grayscale variance of the local image neighborhood. The energy mean integral is equal to the sum of the grayscale values of all pixels within the local image neighborhood divided by the total number of pixels contained in the local image neighborhood. Since step S532 has enforced boundary overflow protection, the denominator of this division operation is always greater than 0 under any operating condition, thus avoiding the risk of division-by-zero anomalies from the bottom layer of the algorithm architecture. The grayscale variance is equal to the average of the sum of the squares of the differences between the grayscale values of all pixels within the local image neighborhood and the energy mean integral.
[0113] S534. The system sets an energy cutoff threshold. This threshold characterizes the grayscale boundary between effective reflection and background diffuse reflection. In this embodiment, the energy cutoff threshold is calibrated based on the statistical mean of the background diffuse reflection grayscale under dark conditions. For a typical 8-bit grayscale image, its value is preferably between 20 and 40. The system compares the calculated energy mean integral with the energy cutoff threshold. The determination criteria are as follows: In the formula, Integrate the mean energy of the local image neighborhood; The energy cutoff threshold is used. To avoid misjudging the dark background texture spots present in the medicinal material as structural defects, the system further introduces local gray-level variance as an orthogonal constraint feature, i.e., a preset gradient abrupt change threshold. This gradient abrupt change threshold is established based on the statistical upper limit of normal texture fluctuations on the surface of multiple batches of good samples (usually set to 15-25). If the energy mean integral is less than the energy cutoff threshold, and the gray-level variance in the neighborhood is greater than the preset gradient abrupt change threshold, it indicates that the light in this area has been severely scattered or absorbed by the structure, and no effective reflected beam has been formed. At this time, the system classifies the node region as a step morphology defect. The specific sub-features of step morphology defects include microcracks and orange peel-like damage.
[0114] S535. The system establishes closed-loop conditions for environmental noise filtering. If the calculated mean energy integral is greater than or equal to the energy cutoff threshold, it means that under even-ring illumination, there are still bright areas in the neighborhood of this theoretical mapping that conform to normal reflective characteristics, but they are not identified in the skeleton distortion determination. The system determines that the candidate distortion node of the odd-ring is caused by free dust reflection or random speckle in the environment, which does not conform to either the continuous mapping model or the local energy loss determination model. The system identifies it as a pseudo-defect feature and removes it from the candidate set. After the above branch determination, the system completes the orthogonal verification of the multimodal features of the appearance of traditional Chinese medicine pills.
[0115] Specific application examples: Application scenarios and hardware parameter configuration: On a pill packaging production line in a traditional Chinese medicine factory, the conveyor speed is set to 500 mm / s. A global shutter CMOS industrial camera is vertically mounted directly above the conveyor belt, with a calibrated spatial resolution of 0.05 mm / pixel. The multi-ring LED light source comprises six concentric ring light-emitting arrays; the odd-numbered rings include rings 1, 3, and 5, while the even-numbered rings include rings 2, 4, and 6. To ensure that the macroscopic physical displacement of the pills does not exceed one pixel during two exposures, the upper limit of the time interval for the dual-pulse trigger signal issued by the industrial control computer is limited by the imaging resolution and conveyor speed, and is calculated to be within 100 μs. In this embodiment, the system sets the actual time interval of the non-overlapping dual-pulse trigger signal to 50 μs.
[0116] a. When the photoelectric sensor detects that the traditional Chinese medicine pill has reached the physical trigger position, the industrial control computer will... Turn on the odd-numbered ring light source and trigger the camera exposure to acquire the first frame of the highlight sequence image; after 50μs, at time... Turn on the even-numbered ring light source and trigger the camera to perform a second exposure to acquire the second frame of the highlight sequence image.
[0117] The system performs adaptive grayscale binarization masking on the two frames of images to remove dark background pixels. Then, the Zhang-Suen thinning algorithm is used to perform morphological dimensionality reduction on the specular connected components, compressing large areas of reflective patches and extracting odd-ring and even-ring specular skeleton networks with a single pixel width.
[0118] b. After obtaining the skeleton network, the system fits the outermost highlight features of the two frames using the least squares method. In this embodiment, the time is calculated. The physical center coordinates of the sphere are (500.5, 500.5), and the time is... The physical center coordinates of the sphere are (500.5, 501.7), from which the two-dimensional translation vector introduced by the transmission mechanism within 50μs is calculated to be (0, 1.2) pixels.
[0119] The system reconstructs a dynamic reference curvature distribution function specific to the current object being measured by deriving the function from the sphere's center coordinates and the actual pixel radius. Subsequently, the system performs Gaussian smoothing and central difference differentiation on the skeleton curve to calculate the actual local curvature of each node on the continuous curve segment. The actual local curvature is then compared with the dynamic reference curvature distribution function. When the absolute value of the difference exceeds a set curvature tolerance threshold, the system extracts the corresponding coordinate node as a candidate distortion node.
[0120] c. For the extracted candidate distortion nodes of odd-numbered rings, the system uses a two-dimensional translation vector to perform an inverse affine transformation on the candidate distortion nodes of even-numbered rings, mapping them to the same absolute coordinate system to eliminate the conveyor belt displacement deviation.
[0121] Within the corresponding theoretical mapping neighborhood, the system performs cross-frame matching and orthogonal verification. If a matching even-numbered node is found, and the deviation norm between the actual spatial displacement vector and the theoretical displacement vector is less than a preset value, the system determines that the region contains gradually changing topological defects such as gentle pits or mechanical indentations. If no matching node is found, the system sets a local image neighborhood in the aligned second frame of the highlight sequence image and calculates the energy mean integral and gray-level variance of that neighborhood. Here, the gray-level variance is equal to the average of the sum of the squares of the differences between the gray-level values of each pixel in the local image neighborhood and the energy mean integral. When the energy mean integral is less than a preset energy cutoff threshold and the gray-level variance is greater than a preset gradient abrupt change threshold, it indicates that the light is severely scattered or absorbed, and the system determines it to be a step-like morphological defect such as microcracks or orange peel damage; if the energy mean integral is greater than or equal to the energy cutoff threshold, it indicates that there is normal free dust reflection at that location, and the system identifies it as a false defect and filters it out.
[0122] Experimental verification and effect comparison: To verify the effectiveness of the above detection scheme in a real industrial environment, data from 10,000 traditional Chinese medicine honey pills were collected on a pill packaging production line. The test set included 8,000 good quality pills, 1,000 samples with gentle pit defects, 500 samples with microcrack defects, and 500 samples with surface dust adhesion interference. In the early stage of image processing, the system converted the acquired images into one-dimensional topological data for calculation. Figure 2 It can be seen that the original binary specular connected regions formed by multi-ring LED light sources on the surface of traditional Chinese medicine pills are often uneven in width due to the influence of local reflectivity. After dimensionality reduction processing using a refinement algorithm, a stable single-pixel specular skeleton network can be output. This process eliminates redundancy in shape width and establishes a reliable set of discrete coordinates for curvature analysis. After obtaining the skeleton coordinate sequence, the system calculates its deformation degree using the principle of differential geometry. Figure 3 As can be seen from the difference comparison curve, the dashed line in the figure represents the dynamic reference curvature of the system's forward reconstruction, while the solid line represents the extracted actual local curvature. Regarding the arc length parameter... Within the 100-120 range, the presence of local surface depressions results in a significant abrupt peak in the actual local curvature. After eliminating the interference from the individual pellet diameter tolerance through a reconstruction mechanism, the system directly and accurately extracts the distorted nodes by identifying whether the peak exceeds the upper limit of the curvature tolerance threshold marked in the figure.
[0123] Based on this dynamic reconstruction and differential mechanism, this scheme was compared with the traditional single-frame static template matching algorithm. The traditional single-frame algorithm, relying on a pre-calibrated fixed template, cannot accommodate the normal minute dimensional tolerances between different individual pills, often misjudging normal morphological fluctuations as surface defects. In the test, its misjudgment rate for good products was as high as 8.5%, and the overall defect detection rate was only 87.4%. This scheme, however, decouples the correlation between dimensional tolerances and morphological defects, significantly reducing the misjudgment rate for good products to 0.6% and increasing the overall defect detection rate to 99.1%. Furthermore, when dealing with the complex environmental noise in the workshop, the traditional single-frame algorithm cannot distinguish between skeleton fractures caused by microcracks and stray reflections caused by spatially dispersed dust, with a dust noise filtering rate of only 32.0%. This scheme, by introducing a dual-frame orthogonal verification mechanism, combines the energy mean integral and gray-level variance within the local image neighborhood for closed-loop judgment, accurately eliminating dust pseudo-defects that do not conform to the law of continuous reflection, achieving a dust noise filtering rate of 98.8%. In terms of processing speed, the overall processing time for a single particle, including operations such as image dimensionality reduction, algebraic equation solving, and cross-frame spatial mapping, is approximately 18 milliseconds, which ensures detection accuracy while meeting the production cycle requirements of high-speed packaging lines.
Claims
1. An online method for detecting the appearance quality of traditional Chinese medicine pills, characterized in that, Includes the following steps: A multi-ring LED light source is controlled to perform asynchronous structured light field modulation and synchronously trigger the camera to acquire a two-frame high-light sequence image of the surface of the Chinese medicine pill to be tested. The hyperspectral connected components of the dual-frame hyperspectral sequence images are extracted and dimensionality reduction is performed using a thinning algorithm to obtain odd-numbered and even-numbered ring hyperspectral skeleton network that characterizes the surface reflection features of traditional Chinese medicine pills. Spatial calibration is performed by addressing the outermost highlight features of the skeleton network to obtain the instantaneous physical center coordinates of the Chinese medicine pill, solve the kinematic displacement transformation matrix, and reconstruct the dynamic reference curvature distribution function; Calculate the local actual curvature of continuous curve segments inside the skeleton line network, compare the local actual curvature with the dynamic reference curvature distribution function by difference, and extract candidate distortion nodes; Perform inverse affine transformation based on the kinematic displacement transformation matrix, perform multimodal orthogonal verification on the candidate distortion nodes in a unified coordinate system, distinguish the appearance quality defects of traditional Chinese medicine pills and filter out environmental noise.
2. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The acquisition of a two-frame high-brightness sequence image of the surface of the Chinese medicine pill to be tested specifically includes the following steps: When a position arrival signal is received, the instantaneous speed of the transmission mechanism is written into the internal register; A non-overlapping double-pulse trigger signal is sent to the controller of the multi-ring LED light source. The time interval between the two high-level pulses is determined based on the instantaneous movement speed of the transmission mechanism and the actual physical size equivalent of a single pixel on the target plane of the camera target surface. The first high-level pulse is routed to the drive channel controlling the odd-numbered ring light source set, the second high-level pulse is routed to the drive channel controlling the even-numbered ring light source set, and the synchronization pulse signal is sent to the global shutter CMOS industrial camera. The first exposure is performed during the duration of the first high-level pulse to generate the first frame of the highlight sequence image, and the second exposure is performed during the duration of the second high-level pulse to generate the second frame of the highlight sequence image, thus obtaining the dual-frame highlight sequence image.
3. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The extraction of the specular connected components from the dual-frame specular sequence images specifically includes the following steps: The global grayscale histogram of the dual-frame spectrophotometer sequence image is statistically analyzed using the maximum inter-class variance method to obtain the adaptive grayscale threshold. The adaptive grayscale threshold is used to perform a binarization mask operation on the image, transforming the original grayscale image into a shape matrix containing only 0 and 1; Calculate the total number of pixels in each connected region and the aspect ratio of the bounding box. Remove isolated connected regions with a total number of pixels less than a preset area threshold or an aspect ratio less than a preset aspect ratio threshold, and retain the specular connected regions that meet the area requirements.
4. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The process of using a refinement algorithm for dimensionality reduction to obtain the odd-numbered and even-numbered ring specular skeleton network representing the surface reflectance characteristics of traditional Chinese medicine pills specifically includes the following steps: The Zhang-Suen thinning algorithm is used to check the boundary pixels with a value of 1 in the specular connected region one by one. When the boundary pixel is not a line segment endpoint and removing the corresponding pixel will not destroy the existing connectivity of the connected region, the value of the boundary pixel is changed from 1 to 0 until the specular connected region is compressed and stripped into a line form with a width of one pixel. The processed image matrix is translated into a coordinate set format containing multiple nodes, generating odd-ring specular skeleton networks and even-ring specular skeleton networks. Each node stores horizontal and vertical pixel coordinates.
5. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The process of addressing the outermost highlight features of the skeleton network to perform spatial calibration and obtain the instantaneous physical center coordinates of the traditional Chinese medicine pill specifically includes the following steps: Calculate the average pixel distance from the pixel node on each connected curve segment to the geometric center pixel coordinate of the image plane, and extract the connected curve segment with the largest average pixel distance as the outermost highlight feature; Extract the set of all pixel coordinate points contained in the outermost highlight feature, construct a general quadratic curve algebraic equation, and introduce constraints to ensure that the fitted curve is an elliptical closed shape. The least squares method is used to fit and calculate the coefficients of the algebraic equation, and the instantaneous physical center coordinates and actual pixel radius are calculated in reverse.
6. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 5, characterized in that, The process of solving the kinematic displacement transformation matrix and reconstructing the dynamic reference curvature distribution function specifically includes the following steps: Calculate the difference between the instantaneous physical center coordinates of the sphere in the horizontal and vertical directions at two consecutive moments, establish a two-dimensional translation vector that reflects the macroscopic displacement of the target, and construct the corresponding kinematic translation matrix in memory based on the two-dimensional translation vector as the kinematic displacement transformation matrix; The instantaneous physical sphere center coordinates and the actual pixel radius are input into the perspective projection mapping model, and the surface normal vector distribution is calculated by combining the spatial physical coordinates of the light source array. Based on the surface normal vector distribution, the theoretical skeleton curvature value under the current spatial pose is derived in a forward direction, and the odd-ring dynamic reference curvature distribution function and the even-ring dynamic reference curvature distribution function are generated.
7. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The calculation of the local actual curvature of the continuous curve segments inside the skeleton line network specifically includes the following steps: The internal continuous curve segments are converted into parametric equations, and the arc length parameter is approximated by the cumulative Euclidean distance between adjacent connected pixel nodes. The Gaussian kernel function in Gaussian smoothing filter is used to perform one-dimensional convolution operations with the horizontal pixel coordinate function and the vertical pixel coordinate function respectively, and the smoothed coordinate sequence is output. The first-order and second-order difference approximate derivatives in the horizontal and vertical directions are calculated using the central difference method for the smoothed coordinate sequence; Substituting the first-order difference approximation derivative and the second-order difference approximation derivative into the discrete plane curve curvature equation, the local actual curvature of each node is calculated.
8. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The step of comparing the actual local curvature with the dynamic reference curvature distribution function to extract the candidate distortion nodes specifically includes the following steps: Calculate the absolute value of the difference between the actual local curvature and the dynamic reference curvature distribution function at the corresponding coordinate position, and compare the absolute value with the preset curvature tolerance threshold point by point; Extract nodes whose absolute difference value is greater than the curvature tolerance threshold; Spatial connectivity verification is performed on the extracted nodes. When the number of adjacent nodes that are sequentially connected in space and all meet the condition of exceeding the curvature tolerance threshold is greater than the preset lower limit of defect size, they are confirmed as candidate distortion nodes, forming a set of candidate distortion nodes for odd-numbered rings and a set of candidate distortion nodes for even-numbered rings.
9. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The step of performing an inverse affine transformation based on the kinematic displacement transformation matrix and performing multimodal orthogonal verification on the candidate distortion nodes in a unified coordinate system specifically includes the following steps: Subtract the two-dimensional translation vector from the coordinates of each node in the even-ring candidate distortion node set and perform an inverse affine transformation to generate an aligned even-ring candidate distortion node set. Within the theoretical mapping neighborhood of the odd-numbered ring candidate distortion node, search for whether there exists a corresponding aligned even-numbered ring candidate distortion node. If found, the actual spatial displacement offset vector is obtained by subtracting the coordinates of the odd-numbered ring candidate distortion nodes from the aligned even-numbered ring candidate distortion node coordinates. The theoretical displacement vector is derived by combining the instantaneous physical sphere center coordinates with the actual pixel radius; By comparing the actual spatial displacement vector with the theoretical displacement vector, if the vector L2 norm of both is less than the tolerance norm, then the slowly varying topological defects can be distinguished in the multimodal orthogonal verification.
10. The method for online detection of the appearance quality of traditional Chinese medicine pills according to claim 1, characterized in that, The process of distinguishing appearance quality defects in traditional Chinese medicine pills and filtering out environmental noise specifically includes the following steps: If an aligned even-ring candidate distortion node cannot be found in the theoretical mapping neighborhood of the odd-ring candidate distortion node, then a local image neighborhood is set with the coordinates of the odd-ring candidate distortion node plus the absolute coordinates pointed to by the theoretical displacement vector as the center. Extract all pixel gray values in the local image neighborhood of the aligned second frame of the highlight sequence image, and calculate the mean energy integral and gray variance; If the mean integral of energy is less than the preset energy cutoff threshold and the gray variance is greater than the preset gradient mutation threshold, then step morphology defects can be distinguished in multimodal orthogonal verification. If the energy mean integral is greater than or equal to the energy cutoff threshold, then the odd-numbered ring candidate distortion node is determined to be caused by environmental noise, identified as a pseudo-defect feature, and removed from the candidate set.