A method for visual detection and adjustment of surface defects of a candy punch forming
By processing images of surface defects in candy stamping and statistically aggregating station markers, the problem of specular artifact interference was solved, enabling accurate identification and local adjustment of periodic defects, thus ensuring the stability and efficiency of the production process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHONGSHIJIA FOOD TECHNOLOGY (JIANGSU) CO LTD
- Filing Date
- 2026-02-10
- Publication Date
- 2026-05-29
AI Technical Summary
In the current technology for candy stamping and molding, the detection of highly reflective surfaces is easily affected by high-light artifacts, making it impossible to identify the periodic defect chain caused by a specific work station. This leads to misjudgment as global process drift and causes global misadjustment, making it impossible to achieve stable production control.
By acquiring candy image sequences, extracting character pattern regions, calculating and correcting single-frame pit defect scores, performing aggregated statistics based on workstation identifiers, identifying abnormal workstations, generating local adjustment instructions to update control parameters, and combining closed-loop evaluation indicators for real-time verification.
It significantly improves the accuracy of defect identification under strong reflective backgrounds, accurately locates abnormal workstations in periodic defect chains, realizes local parameter optimization control, and ensures the stability and consistency of the production process.
Smart Images

Figure CN122115369A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of machine vision and industrial automation control technology, and in particular to a method for visual detection and adjustment of surface defects in candy stamping. Background Technology
[0002] In the candy stamping or tableting process, the equipment usually uses a high-speed rotating turret structure to drive multiple punches to operate continuously. Because the surface of the candy has strong reflective properties, and the humidity fluctuation of the production environment or the change of the raw material state can easily cause local adhesion, water film residue or abnormal demolding resistance on the surface of the punch. These factors can easily cause appearance defects such as tearing, pitting or scratches on the surface of the candy after demolding, especially in the vicinity of the letter pattern. These defects often present a non-random distribution pattern, but are triggered by local abnormalities in a few specific stations in the turret, thus showing a chain-like aggregation phenomenon that repeats at a fixed pitch in the continuous tableting sequence.
[0003] Existing online visual inspection technologies typically focus on the independent judgment of individual products or the statistics of overall defect rates. They struggle to effectively distinguish between genuine dents and artifacts in highly reflective backgrounds, lack in-depth analysis of the spatiotemporal distribution patterns of defects, and cannot accurately identify the phase correlation between defects and turret stations. When a few stations exhibit persistent anomalies, they are often misjudged as global process drift, leading to a uniform parameter adjustment strategy for the entire machine. This global adjustment approach not only fails to eradicate persistent defects at specific stations but may also cause the process parameters of other normal stations to deviate from their optimal state, resulting in adjustment oscillations and production instability. Summary of the Invention
[0004] The purpose of this invention is to address the shortcomings of existing technologies, such as the susceptibility to high-gloss artifacts in the inspection of highly reflective candy surfaces leading to low detection reliability, the inability to identify periodic defect chains caused by specific workstations, and the tendency to misjudge local workstation anomalies as global process drift, thereby causing global misadjustment. Therefore, this invention proposes a visual inspection and adjustment method for candy stamping surface defects.
[0005] To address the problems existing in the prior art, the present invention adopts the following technical solution:
[0006] A method for visual inspection and adjustment of surface defects in candy stamping includes:
[0007] S1. Collect the original image sequence of the candy and determine the workstation identifier corresponding to the candy;
[0008] S2. Extract the font region from the original image of the candy and calculate the single-frame font pit defect score. Correct the single-frame font pit defect score to obtain a reliable defect score.
[0009] S3. Aggregate and statistically analyze the reliable defect scores based on the workstation identifier to obtain the phase locking strength, and determine the abnormal workstations based on the phase locking strength;
[0010] S4. Generate local adjustment instructions for abnormal workstations to update the control parameters of abnormal workstations;
[0011] S5. After the local adjustment command is executed, calculate the closed-loop evaluation index and adjust the control parameters of the abnormal workstation according to the closed-loop evaluation index.
[0012] Preferably, determining the workstation identifier corresponding to the candy includes:
[0013] Obtain the candy's output sequence number and the total number of turret stations on the equipment;
[0014] Take the remainder of the candy's output sequence number divided by the total number of turret stations on the equipment, and use the remainder as the station identifier.
[0015] Preferably, extracting the font region from the original image of the candy and calculating the font pit defect score for a single frame includes:
[0016] The original image is pose-normalized and cropped according to the preset character pattern area to obtain the standard character pattern area;
[0017] Morphological black hat enhancement is applied to the standard area of the character pattern to obtain the pit response map;
[0018] The pit response map is binarized and connected component extraction is performed to obtain a set of connected components.
[0019] For each connected component in the set of connected components, calculate the area, pit contrast, and boundary sharpness of the connected component.
[0020] Calculate the product of the area of the connected component, the pit contrast, and the boundary sharpness, and select the maximum value of the product among all connected components as the single-frame font pit defect score.
[0021] Preferably, the correction of the single-frame font pit defect score includes:
[0022] Acquire the standard area of the same candy in a dual-frame font under differential illumination or differential viewing angle;
[0023] Calculate the two-frame pit response map corresponding to the standard region of the two-frame font respectively, and perform binarization to obtain the binary map of the pit region;
[0024] Calculate the ratio of the intersection area to the union area of the pit regions in the two binary images of the pit regions, and use it as a region consistency index;
[0025] The reliable defect score is obtained by multiplying the single-frame font pit defect score by the regional consistency index.
[0026] Preferably, the reliable defect scores are aggregated and statistically analyzed based on the workstation identifier to obtain the phase-locking strength, and the abnormal workstation is determined based on the phase-locking strength, including:
[0027] The reliable defect scores of candies with the same workstation identifier are summed to obtain the cumulative phase intensity corresponding to each workstation.
[0028] The ratio of the maximum cumulative phase intensity to the sum of the cumulative phase intensities of all workstations is taken as the phase locking intensity.
[0029] The workstation with the highest cumulative phase intensity is identified as an abnormal workstation.
[0030] Preferably, after identifying the abnormal workstation, the length of the pit chain is calculated, including:
[0031] The pit chain threshold is set based on the statistical value of the reliable defect score;
[0032] When the workstation of a candy is identified as an abnormal workstation and the credible defect score is not less than the pit chain threshold, the candy is marked as a chain defect point.
[0033] Calculate the maximum number of consecutive chain-like defect points, and define the maximum number as the pit chain length.
[0034] Preferably, generating a local adjustment command for the abnormal workstation to update the control parameters of the abnormal workstation includes:
[0035] Calculate the median and median absolute deviation of the cumulative phase intensity for all workstations. Based on the median and the median absolute deviation, standardize the cumulative phase intensity of each workstation to obtain the phase outlier.
[0036] An adaptive step size is constructed, which is positively correlated with the phase locking strength and positively correlated with the phase outlier of the abnormal work position.
[0037] Based on the adaptive step size and the preset adjustment direction, the control parameters of abnormal workstations are incrementally updated, while the control parameters of other workstations remain unchanged.
[0038] The control parameters include at least one of the following: local cleaning cycle, local drying air blowing duration, local demolding pulse amount, or local ejection compensation.
[0039] Preferably, after the local adjustment command is executed, a closed-loop evaluation index is calculated, and the control parameters of the abnormal workstation are adjusted according to the closed-loop evaluation index, including:
[0040] Acquire a preset number of candy images after executing the local adjustment command, and calculate the corresponding average confidence defect score, phase locking strength, and pit chain length;
[0041] The closed-loop evaluation index is obtained by weighting the average credible defect score, phase locking strength and pit chain length according to the preset weights.
[0042] The adjusted closed-loop evaluation index is compared with the unadjusted closed-loop evaluation index. If the adjusted closed-loop evaluation index is greater than the unadjusted closed-loop evaluation index, a rollback operation is performed; otherwise, the adjusted local adjustment instruction is maintained.
[0043] Compared with the prior art, the beneficial effects of the present invention are:
[0044] 1. This invention enhances the standard region of the character mold with morphological black hat enhancement and multi-dimensional feature quantization of connected components, and introduces a dual-frame region consistency verification mechanism under micro-difference illumination or micro-difference perspective. It uses the cross-union ratio of the two-frame pit regions to calculate the consistency index and weight the defect score of the single frame, thereby effectively suppressing the specular artifacts and random noise interference that drift with the illumination conditions. Under strong reflective background, it significantly improves the recognition credibility and feature quantization accuracy of real character mold tear pits, ensuring that the detection results can truly reflect the physical defect state of the candy surface.
[0045] 2. This invention maps defect detection data to the phase domain of the turret station. By calculating the phase locking strength and phase outlier, it accurately locates abnormal stations that trigger periodic defect chains. Based on the locking strength, it constructs an adaptive step size to generate local adjustment commands for the specific station, realizing independent optimization control of local cleaning, drying, or demolding parameters. At the same time, it combines the pit chain length and closed-loop evaluation index to verify the adjustment effect in real time and provide backtracking protection, ensuring that while eliminating stubborn defects at specific stations, it does not interfere with the operation of other normal stations, thus achieving stable closed-loop control of the production process. Attached Figure Description
[0046] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0047] Figure 1 This is a flowchart illustrating a method for visual inspection and adjustment of surface defects in candy stamping according to the present invention.
[0048] Figure 2 This is a schematic diagram illustrating the phase locking strength and abnormal workstation determination of the present invention. Detailed Implementation
[0049] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0050] Example: This example provides a method for visual inspection and adjustment of surface defects in candy stamping. See [link to example]. Figure 1 Specifically, including:
[0051] S1. Collect the original image sequence of the candy and determine the workstation identifier corresponding to the candy;
[0052] In an embodiment of the present invention, acquiring the original image sequence of the candy and determining the workstation identifier corresponding to the candy includes:
[0053] Collect the original image of the candy;
[0054] Obtain the candy's output sequence number and the total number of turret stations on the equipment;
[0055] Take the remainder of the candy's output sequence number divided by the total number of turret stations on the equipment, and use the remainder as the station identifier.
[0056] Specifically, the output sequence number refers to the incremental number assigned to each candy according to its time sequence as it is continuously output along the production cycle, used to characterize the relative position of the candy in the output sequence; the equipment turret refers to the component in the stamping and forming equipment that carries multiple punches or dies and rotates periodically with the spindle; the total number of turret stations refers to the number of stations evenly arranged along the circumference of the turret that can independently perform stamping or ejection, and this number is determined by the equipment structure and corresponds to the number of discrete positions experienced by the turret in each rotation; using the obtained remainder as the station identifier means using the remainder to uniquely identify the discrete turret station position corresponding to the current candy, so that each candy can be associated with the specific station that produced it, so as to perform aggregate analysis and local adjustment control on defects at the same station in the future.
[0057] In detail, an industrial camera and supplementary lighting assembly are installed above the candy stamping and forming equipment's sheet-out conveyor belt, and a fixed mounting bracket is used to align the camera's optical axis vertically or at a predetermined angle with the candy surface at the sheet-out detection position. Simultaneously, the camera's external trigger terminal is connected to the equipment's sheet-out cycle signal to achieve one-piece trigger acquisition. The supplementary lighting assembly uses two high-brightness pulse light sources and is synchronized with the camera trigger to achieve stable exposure. Preferably, the camera exposure time is set to one to three milliseconds, and the gain is set within a range that does not cause grayscale saturation in the character area to avoid highlight overflow. At each trigger, a frame of the candy's original image is acquired and cached as the original image of the candy, forming an original image sequence. When obtaining the candy's sheet-out sequence number and the total number of turret stations, the sheet-out sequence number is obtained by the controller or host computer incrementing a counter by one each time the camera trigger arrives. The initial value of the counter is set to... The sequence number is reset during equipment startup or batch switching to ensure continuity and consistency with the output cycle. The total number of turret stations is determined by the equipment structure parameters provided by the equipment controller or input and stored via the human-machine interface. The preferred value is the actual number of punches or mold seats on the turret and is updated synchronously after model change to ensure consistency with the mechanical structure. In the host computer or controller, an integer division operation is performed on the current output sequence number to obtain the remainder. This remainder is directly used as the station identifier to represent the discrete turret station position corresponding to the candy. When the remainder is zero, the station identifier is determined as the station corresponding to the total number of turret stations to complete the one-to-one mapping from the remainder to the station number. This mapping is established based on the cycle relationship that the turret stations are divided equally in the circumference and the turret advances one station for each candy output, so that the continuous output sequence cycles periodically within one circumference of the turret according to the total number of stations.
[0058] S2. Extract the font region from the original image of the candy and calculate the single-frame font pit defect score. Correct the single-frame font pit defect score to obtain a reliable defect score.
[0059] In an embodiment of the present invention, the font region is extracted from the original image of the candy and the single-frame font pit defect score is calculated. The single-frame font pit defect score is then corrected to obtain a reliable defect score, including:
[0060] The original image is pose-normalized and cropped according to the preset character pattern area to obtain the standard character pattern area;
[0061] Morphological black hat enhancement is applied to the standard area of the character pattern to obtain the pit response map;
[0062] The pit response map is binarized and connected component extraction is performed to obtain a set of connected components.
[0063] It should be noted that the standard region of the character pattern refers to a fixed-scale image region containing the character pattern and its neighborhood, which is cropped from the normalized image after the original image of the candy has been normalized in terms of posture, based on the pre-calibrated position and size parameters of the character pattern. This region has a uniform spatial alignment and pixel scale among different candies, which is used to eliminate the influence of changes in the candy's delivery posture and imaging position, thereby ensuring that subsequent defect feature extraction is performed under the same reference coordinate system. The pit response map refers to the grayscale response result obtained by applying morphological black hat enhancement to the standard region of the character pattern. It suppresses large-scale illumination fluctuations and slowly changing background components by performing a closing operation on the standard region of the character pattern using structuring elements and subtracting it from the original image, highlighting the low-brightness details corresponding to local dark pits or torn pits, so that the pits appear as strong response regions in the response map, which is convenient for subsequent binarization, connected component extraction and defect quantization.
[0064] Specifically, the outer contour of the candy is located in the original image. Gray-scale thresholding and morphological closing operations are preferably used to obtain the connected regions of the candy. The principal axis direction of the minimum bounding rectangle of this connected region is calculated as the candy's pose angle. Simultaneously, the candy's centroid is calculated as a translation reference. Then, rotation correction is performed on the original image with a preset target pose angle of zero degrees, and the candy's centroid is aligned to a fixed reference point to complete pose normalization. Bilinear interpolation is used for rotation to ensure gray-scale continuity, and the rotation angle range is from -45 degrees to +45 degrees to cover common placement deviations. In the pose-normalized image, a preset character pattern area is cropped to obtain a standard character pattern area. This preset character pattern area is obtained through device calibration. During calibration, the average coordinates of the center position of the character pattern area are calculated based on the continuous acquisition of at least fifty qualified candy images, and this average coordinate is used as the cropping center. Simultaneously, the cropping window size is set according to the maximum bounding dimension of the character pattern. Preferably, the cropping window is square with a side length of two to three times the maximum bounding dimension of the character pattern to cover the character pattern and its neighborhood for pit detection.
[0065] When performing morphological black-hat enhancement on the standard region of the font to obtain the pit response map, it is preferable to use a disk structure element to perform morphological closing operations and subtract the standard region of the font from the closing operation result to obtain the black-hat enhancement result. The radius of the disk structure element is set to one to three times the font linewidth to suppress large-scale illumination changes and highlight local dark pits. Simultaneously, to reduce noise, a 3x3 median filter can be performed on the standard region of the font before black-hat enhancement. When performing binarization and connected component extraction on the pit response map to obtain the connected component set, the pits are first... The response map is intensity normalized and binarized using either an adaptive threshold or a fixed threshold. The preferred threshold is the median of the pixel values in the pit response map plus the median absolute deviation, which can accommodate reflection and brightness fluctuations. After binarization, a morphological opening operation with a radius of one to two pixels is performed to remove isolated noise. Subsequently, the binary map is labeled with connected components using the eight-neighbor connectivity rule. The pixel set, area, and bounding rectangle of all connected components are output as the connected component set, thus providing basic data for subsequent defect quantification and screening of each connected component.
[0066] For each connected component in the set of connected components, calculate the area, pit contrast, and boundary sharpness of the connected component.
[0067] Calculate the product of the area of the connected component, the pit contrast, and the boundary sharpness, and select the maximum value of the product in all connected components as the single-frame font pit defect score.
[0068] It should be noted that the single-frame font dent defect score refers to the scalar evaluation value obtained by binarizing and extracting the connected components of the dent response map under the condition of using only one frame of font standard area image of the same candy, and quantifying the connected component area, dent contrast and boundary sharpness of each connected component, and taking the maximum value of the combined result in all connected components. This evaluation value is used to characterize the intensity and significance of the most significant dent defects in the font region of that frame. The larger the value, the higher the probability that there are dent defects with a larger range, higher dent response and clearer edges in the font neighborhood.
[0069] Specifically, after obtaining the set of connected components, the area, pit contrast, and boundary sharpness of each connected component are calculated sequentially. The binarized pit region is used as the foreground, and the pixel index set of each connected component is obtained using eight-neighbor connectivity labels. The area of any connected component is obtained by pixel counting, that is, the number of foreground pixels contained in the connected component is used as the area of the connected component. The number of pixels can be converted into the actual area according to the pixel size obtained from camera calibration. In order to suppress the small pseudo-connected components introduced by binarization noise, a minimum area threshold of nine to twenty-five pixels is preferably set, and connected components smaller than the threshold are removed. The basis for this value is that isolated noise and highlight edge fragments at a three-by-three to five-by-five pixel scale usually do not represent real pits. The pit contrast is calculated using the pit response map within the connected component. The average response value is used as the pit contrast, which is obtained by averaging the gray values of all pixels corresponding to the connected component on the pit response map. It is preferable to first normalize the pit response map to the range of zero to one so that it is comparable under different batch brightness conditions. The boundary sharpness is calculated based on the gradient magnitude of the standard region of the character pattern. The horizontal and vertical gradients are calculated on the standard region of the character pattern using the 3x3 Sobel operator and synthesized into a gradient magnitude map. Then, the boundary pixel set is extracted for any connected component. The boundary pixel set is preferably obtained by performing an erosion on the binary mask of the connected component and subtracting the erosion result from the original mask. The average gradient magnitude of the boundary pixel set on the gradient magnitude map is calculated as the boundary sharpness. The basis for the value is that real tear pits usually have clear gray-scale abrupt edges, while the edge gradients of highlight artifacts or background gradual change areas are weaker.
[0070] The product value of the pit features for a connected region is obtained by multiplying the area, pit contrast, and boundary sharpness of the same connected region. Multiplying these three values simultaneously constrains and amplifies the discriminative power of the true defects by using a single value for the three complementary attributes of the pit defect in imaging: the connected region area reflects the extent and sustained damage of the defect; the pit contrast reflects the local grayscale decrease and black hat response intensity caused by the pit; and the boundary sharpness reflects the abrupt grayscale changes and structural clarity caused by tearing the pit edge. Using product fusion creates a joint gating effect, significantly suppressing candidate regions with weaker attributes. This suppresses background shadows that are large but have a gradual grayscale change, noise that is strong in contrast but small in area, and noise that is sharp at the edge but mainly composed of specular reflection or texture. The pseudo-response caused by the boundary is eliminated, while the candidate regions of the pit that simultaneously meet the requirements of large area, strong response and clear edge are given higher scores, so that the single frame font pit defect score is more stably dominated by real tearing pits. In order to avoid the single extreme value causing the value to be too large, it is preferable to take the square root of the area or limit the three features to a preset upper limit before multiplying them. The upper limit can be taken as the statistical value of each feature in the most recent turret cycle to ensure robustness to abnormal noise. The product value of pit features of all connected regions is compared, and the maximum value is selected as the single frame font pit defect score, so that the single frame font pit defect score is dominated by the most significant pit candidate connected region and used for subsequent credibility and workstation aggregation analysis.
[0071] Acquire the standard area of the same candy in a dual-frame font under differential illumination or differential viewing angle;
[0072] Calculate the two-frame pit response map corresponding to the standard region of the two-frame font respectively, and perform binarization to obtain the binary map of the pit region;
[0073] Calculate the ratio of the intersection area to the union area of the pit regions in the two binary images of the pit regions, and use it as a region consistency index;
[0074] The reliable defect score is obtained by multiplying the single-frame font pit defect score by the regional consistency index.
[0075] It should be noted that the region consistency index refers to a dimensionless value obtained by extracting candidate pit regions from two frames of text region images of the same candy under differential illumination or differential viewing angle, forming two binary images of the pit regions, and then using the ratio of the area of the pixel region jointly identified as a pit in both binary images to the area of the pixel region identified as a pit in either of the two binary images. This value is used to characterize the degree of spatial overlap and shape consistency of the candidate pit regions under varying dual-frame imaging conditions. A larger value indicates that the candidate pit regions are more stable in both frames. The smaller the value, the more likely the candidate region is to drift with changes in illumination or viewing angle, corresponding to specular highlight artifacts or noise response. The reliable defect score is a defect reliability evaluation value obtained by combining the single-frame font pit defect score with the region consistency index. It uses the region consistency index to weight and suppress the single-frame font pit defect score, so that the pit candidate regions with consistent spatial position and shape in the two frames get higher final scores, while the inconsistent or obviously drifting responses in the two frames are significantly reduced. Thus, the score reflects both the significance of the pit defect and the stability across imaging conditions.
[0076] Specifically, to obtain the standard area of the two-frame font for the same candy under differential illumination or differential viewing angle, the same industrial camera is set at the output detection position and configured with two independent and controllable pulse light sources. The incident direction or polarization state of the two light sources is different to form differential illumination. Preferably, the two light sources are arranged symmetrically on the left and right sides of the camera optical axis and the angle between them and the normal of the candy surface is 15 to 30 degrees to change the specular highlight distribution while maintaining the visibility of the font. The controller triggers the first light source and the camera in a fixed delay sequence within a single dwell window of the same candy passing through the detection position to obtain the first frame original image, and triggers the second light source and the camera to obtain the second frame original image after one to five milliseconds. The pose normalization and font area cropping are performed on the two original images in the same manner as described above to obtain the standard area of the two-frame font. Then, morphological black hat enhancement is performed on the standard area of the two-frame font to obtain the two-frame pit response map. The structural element is preferably a disk structural element consistent with the single frame processing, and the radius is one to three times the width of the font line to ensure response consistency.
[0077] The two-frame pit response maps are binarized to obtain two pit region binary maps. The binarization threshold is preferably determined adaptively by adding the median of the pixel values in each pit response map to the median of the absolute deviation. After binarization, a morphological opening operation with a radius of one to two pixels is performed to remove isolated noise, so that the pit region binary map mainly covers the pit candidate region. When calculating the region consistency index, the set of pixels that are both foreground in the two pit region binary maps is defined as the intersection region, and the number of pixels is counted as the intersection area. The set of pixels that are either foreground in the two pit region binary maps is defined as the union region, and the number of pixels is counted as the union area. The intersection region is then divided into two parts. The ratio of area to union area is used as a region consistency index. The ratio ranges from zero to one, and the higher the ratio, the more consistent the spatial position and shape of the candidate pit regions in the two frames. After obtaining the region consistency index, the single-frame font pit defect score is multiplied by the region consistency index to obtain the reliable defect score. The single-frame font pit defect score can be the larger of the single-frame font pit defect scores calculated separately for the two frames or the average value. It is preferred to take the average value of the two frames to reduce the influence of occasional noise in the single frame. This makes the reliable defect score stable for real pits and suppresses specular artifacts that drift significantly with changes in illumination, and provides a more reliable input for subsequent aggregation statistics by workstation.
[0078] S3. Aggregate and statistically analyze the reliable defect scores based on the workstation identifier to obtain the phase locking strength, and determine the abnormal workstations based on the phase locking strength;
[0079] In an embodiment of the present invention, the reliable defect score is aggregated and statistically analyzed based on the workstation identifier to obtain the phase-locking strength, and the abnormal workstation is determined based on the phase-locking strength, including:
[0080] The reliable defect scores of candies with the same workstation identifier are summed to obtain the cumulative phase intensity corresponding to each workstation.
[0081] The ratio of the maximum cumulative phase intensity to the sum of the cumulative phase intensities of all workstations is taken as the phase locking intensity.
[0082] The workstation with the highest cumulative phase intensity is identified as an abnormal workstation.
[0083] It should be noted that phase-locking strength refers to the cumulative phase strength of each station by aggregating and accumulating the credible defect scores of each candy in the continuous output sequence according to its corresponding station identifier. The ratio of the maximum cumulative phase strength to the sum of the cumulative phase strengths of all stations forms a dimensionless evaluation quantity. This evaluation quantity is used to characterize the degree of concentration and periodic locking of defect energy in the turret station phase. When the defect is mainly caused by local anomalies in a few stations and recurs with the turret pitch, the cumulative strength of the station with the maximum strength will significantly account for the overall strength, thus increasing the phase-locking strength. However, when the defect is randomly distributed or the strength of each station is similar due to global process drift, the phase-locking strength tends to be at a lower level.
[0084] Specifically, an accumulation buffer indexed by workstation identifier is established in the host computer or controller to achieve aggregate statistics for each workstation. The length of the accumulation buffer is set to the total number of turret workstations, and each buffer unit is used to store the phase accumulation intensity of one workstation. During initialization, all buffer units are set to zero. Subsequently, a preset statistical window is used to traverse the continuous candies and perform cumulative updates. The statistical window preferably covers the number of films produced in one to three turret cycles to balance response speed and statistical stability. When the total number of turret workstations is twenty to sixty and the film production rate is stable, the statistical window can take one to two turret cycles. The number of films produced corresponding to the turret cycle can be taken as the number of films produced for two to three turret cycles when the humidity fluctuates greatly or the probability of defects is low. During the traversal, the station identifier of each candy is read and the reliable defect score of the candy is accumulated into the buffer unit corresponding to the station identifier, so as to obtain the phase cumulative intensity corresponding to each station. After completing the traversal of a statistical window, the phase cumulative intensity of all stations is globally summarized, and the sum of the phase cumulative intensity of all stations and the maximum value are calculated respectively. The station corresponding to the maximum value is the station with the largest phase cumulative intensity.
[0085] The phase-locking intensity is calculated by comparing the maximum cumulative phase intensity with the total intensity. This intensity characterizes the degree of clustering of credible defect scores at a given workstation. This ratio increases significantly when defects are triggered by a few workstations and repeatedly occur at fixed intervals in the sequence. Finally, the workstation with the highest cumulative phase intensity is identified as the abnormal workstation, and its output is used as the target workstation for generating subsequent local adjustment commands. To avoid accidental maximum values causing false identification when the overall defect rate is extremely low, a minimum total intensity threshold is preferably set, and the abnormal workstation determination is only performed when the sum of the cumulative phase intensities of all workstations exceeds the threshold. The threshold is preferably calculated as the average of the credible defect scores within the statistical window multiplied by the number of films produced, to ensure that the abnormal workstation determination has sufficient defect evidence to support it.
[0086] After identifying the abnormal workstation, a pit chain threshold is set based on the statistical value of the reliable defect score;
[0087] When the workstation of a candy is identified as an abnormal workstation and the credible defect score is not less than the pit chain threshold, the candy is marked as a chain defect point.
[0088] Calculate the maximum number of consecutive chain-like defect points, and define the maximum number as the pit chain length;
[0089] It should be noted that the pit chain length refers to the integer evaluation value obtained by identifying each candy in the output sequence after determining the abnormal workstation and setting the pit chain threshold. When the workstation corresponding to the candy is identified as an abnormal workstation and its reliable defect score is not less than the pit chain threshold, the candy is marked as a chain defect point. Then, the number of chain defect points contained in the longest continuous segment of the chain defect points along the output sequence is counted. This evaluation value is used to characterize the continuity and chain aggregation degree of pit defects caused by abnormal workstations in the time series. The larger the value, the higher the probability that the abnormal workstation will continue to produce significant pit defects in multiple consecutive output cycles.
[0090] Specifically, after determining the abnormal workstation according to the phase cumulative intensity, in order to evaluate whether the abnormal workstation forms a continuous chain of pits in the film output sequence, the reliable defect score of each candy is first collected within a preset statistical window and robust statistics are performed to set the pit chain threshold. The statistical window is preferably consistent with the aggregation window of the phase cumulative intensity, taking the number of films output corresponding to one to three turret cycles to maintain the consistency of the indicators. Specifically, the median of all reliable defect scores within the window is calculated and its absolute deviation median is calculated as a discrete measure. Then, the median and the absolute deviation median are added to obtain the pit chain threshold. The absolute deviation median can suppress the effect of a small number of extreme defect points on the threshold, so that the threshold is robust to humidity fluctuations and reflectivity changes. When the overall defect level is low and the absolute deviation median is close to zero, it is preferable to add a preset small positive number to the absolute deviation median to avoid threshold degradation. The small positive number can be taken as one-thousandth to one-ten-thousandth of the normalized intensity level so as not to affect the normal threshold level.
[0091] After obtaining the pit chain threshold, the output sequence within the statistical window is traversed sequentially by time. When a candy's workstation is identified as an abnormal workstation and its reliable defect score is not less than the pit chain threshold, the candy is marked as a chain defect point and recorded as one in the chain defect marking sequence; otherwise, it is recorded as zero, thus obtaining a chain defect marking sequence of the same length as the output sequence. Subsequently, run-length statistics are performed on the chain defect marking sequence to calculate the maximum number of consecutively occurring chain defect points. Specifically, the initial value of the current consecutive count is set to zero, and the initial value of the maximum consecutive count is set to zero. The sequence is scanned from beginning to end. When a chain defect point is encountered, the current continuous count is incremented by one and the maximum continuous count is updated using the current continuous count. When a non-chain defect point is encountered, the current continuous count is reset to zero. After the scan is completed, the maximum continuous count is the maximum number of consecutive chain defect points and is defined as the pit chain length. In order to avoid the truncation effect at the window boundary, it is preferable to make the statistical window cover at least one turret cycle and, in the case of frequent defects at abnormal workstations, take more than two cycles. This allows the pit chain length to truly reflect the persistence and aggregation degree of chain defects at abnormal workstations and be used for subsequent closed-loop evaluation and adjustment decisions.
[0092] S4. Generate local adjustment instructions for abnormal workstations to update the control parameters of abnormal workstations;
[0093] In an embodiment of the present invention, generating a local adjustment command for an abnormal workstation to update the control parameters of the abnormal workstation includes:
[0094] Calculate the median and median absolute deviation of the cumulative phase intensity for all workstations. Based on the median and the median absolute deviation, standardize the cumulative phase intensity of each workstation to obtain the phase outlier.
[0095] Specifically, the cumulative phase intensities of all workstations are sorted, and the value in the middle position after sorting is taken as the median. When the total number of workstations is even, the average of the two middle values is taken as the median, resulting in a robust central value reflecting the overall workstation level. Using this median as a benchmark, the absolute difference between the cumulative phase intensity and the median is calculated for each workstation. All absolute differences are then sorted again, and the absolute difference in the middle position after sorting is taken as the median of the absolute deviation. When the total number of workstations is even, the average of the two middle values is again taken as the median of the absolute deviation, resulting in a robust dispersion reflecting the fluctuation scale of each workstation. To avoid the standardization failure caused by the median of the absolute deviation being zero when the overall defect rate is extremely low or when all workstations are almost identical, it is preferable to use a median of the absolute deviation... A preset small positive number is added to the median to obtain the corrected absolute deviation median. The preset small positive number can be on the normalized intensity scale from one-thousandth to one-ten-thousandth, so that it does not change the discreteness scale when normal fluctuations exist, but provides the smallest denominator when the discreteness is zero. After obtaining the median and the corrected absolute deviation median, a standardization process is performed on each station, that is, the cumulative phase intensity of the station is subtracted from the median and then divided by the corrected absolute deviation median. The result is used as the phase outlier of the station. The phase outlier is a dimensionless quantity, and the larger the value, the more prominent the cumulative phase intensity of the station is relative to the overall station level. This can be used to determine the significance of abnormal stations and provide input for the subsequent adaptive adjustment step size construction.
[0096] An adaptive step size is constructed, which is positively correlated with the phase locking strength and positively correlated with the phase outlier of the abnormal work position.
[0097] Based on the adaptive step size and the preset adjustment direction, the control parameters of abnormal workstations are incrementally updated, while the control parameters of other workstations remain unchanged.
[0098] Specifically, after calculating the phase lock strength, identifying the abnormal workstation, and obtaining the phase outlier of the abnormal workstation, an adaptive step size is constructed as the amplitude coefficient for local adjustment to avoid over-adjustment when evidence is insufficient and to quickly suppress chain defects when evidence is sufficient. The adaptive step size is jointly determined by the base step size, the phase lock strength factor, and the phase outlier factor. The base step size is set according to the physical execution resolution of the control parameter and the acceptable perturbation range of the process. When the control parameter is the local drying air blowing duration, the base step size is preferably between 20 and 100 milliseconds. When the control parameter is the local cleaning cycle, the base step size is preferably one to three film ejections per step. When the control parameter is the local demolding pulse amount or local ejection compensation, the base step size is preferably one percent to five percent of the minimum adjustable resolution of the controller to ensure that a single update is executable on the equipment and does not cause shock instability.
[0099] The phase-locking strength factor is obtained by limiting and normalizing the phase-locking strength. Specifically, the phase-locking strength is limited to the range of zero to one and directly used as a multiplicative coefficient, so that the step size increases when defects are highly concentrated at a certain station and decreases when defects are dispersed. The phase outlier factor is obtained by non-negatively truncating the phase outlier of abnormal stations and normalizing it according to a preset upper limit. The preset upper limit is preferably three to eight. The basis for the value is that an outlier greater than three after robust normalization usually indicates a significant outlier, while an excessively large value may be caused by short-term anomalies. In order to prevent over-adjustment caused by a single anomaly, the part of the outlier exceeding the upper limit is treated as the upper limit and normalized as a multiplicative coefficient so that the higher the outlier, the larger the step size. Finally, the basic step size is multiplied by the above two factors to obtain the adaptive step size, and a maximum allowable value of two to five times the basic step size is set for the adaptive step size to further limit the adjustment intensity.
[0100] After obtaining the adaptive step size, the control parameters of the abnormal station are incrementally updated according to the preset adjustment direction. The adjustment direction is predetermined by the defect mechanism and fixed in the form of increase or decrease. For example, when the chain pit is determined to be related to local water film residue, the adjustment direction is set to increase the local drying air blowing time or shorten the local cleaning cycle. When the chain pit is determined to be related to insufficient demolding, the adjustment direction is set to increase the local demolding pulse amount or increase the local ejection compensation. During the incremental update, the control parameters of the abnormal station are increased or decreased by one step along the adjustment direction according to the adaptive step size based on the original parameters, and at the same time, the control parameters are set... The upper and lower limits are set to not exceed the allowable range of the equipment. The upper limit of the local drying air blowing time is preferably 1.5 times the basic setting value and the lower limit is not less than 0.5 times the basic setting value. The upper limit of the local cleaning cycle is preferably twice the basic setting value and the lower limit is not less than one cycle per turret revolution. The upper limit of the local demolding pulse quantity or local ejection compensation is preferably 90% of the maximum value allowed by the controller to leave a safety margin. After the parameter update of the abnormal station is completed, the same control parameters of other stations are kept unchanged at the original setting value, so as to realize the incremental adjustment that is local, controllable and adaptive to the phase lock evidence strength only for the abnormal station.
[0101] S5. After the local adjustment command is executed, calculate the closed-loop evaluation index and adjust the control parameters of the abnormal workstation according to the closed-loop evaluation index.
[0102] In an embodiment of the present invention, after the local adjustment command is executed, a closed-loop evaluation index is calculated, and the control parameters of the abnormal workstation are adjusted according to the closed-loop evaluation index, including:
[0103] Acquire a preset number of candy images after executing the local adjustment command, and calculate the corresponding average confidence defect score, phase locking strength, and pit chain length;
[0104] The closed-loop evaluation index is obtained by weighting the average credible defect score, phase locking strength and pit chain length according to the preset weights.
[0105] Compare the adjusted closed-loop evaluation index with the unadjusted closed-loop evaluation index, and adjust the local adjustment instructions based on the comparison results.
[0106] Specifically, after the local adjustment command is issued and the equipment controller updates the control parameters of the abnormal workstation, in order to verify the adjustment effect and achieve reversible closed-loop control, a preset number of candy images are acquired as a subsequent observation window after the execution of the local adjustment command. The preset number preferably covers the number of films produced corresponding to one to three turret cycles. The value is based on the fact that the phase-locking phenomenon repeats with one turret cycle. Covering at least one cycle allows observation of whether the abnormal workstation still exhibits periodic clustering, while covering two to three cycles improves the statistical stability of occasional fluctuations. Within this subsequent observation window, each candy is processed according to the same procedure as before adjustment, including character pattern standard region extraction, pit response calculation, connected component analysis, and double-frame processing. Consistency calculations are performed to obtain the reliable defect score and its workstation identifier for each candy. The arithmetic mean of all reliable defect scores within the window is then calculated to obtain the average reliable defect score. Simultaneously, within the same window, the reliable defect scores are accumulated according to the workstation identifier to obtain the cumulative phase intensity of each workstation, and the phase lock intensity is calculated accordingly. Furthermore, based on the determined abnormal workstations and pit chain thresholds, chain-like defect point markers are generated for the output sequence, and the pit chain length is obtained through run statistics. The pit chain threshold is preferably the same as the threshold of the window before adjustment to ensure comparability of the indicators before and after adjustment. Alternatively, it can be recalculated in the window after adjustment using the median and the median of the absolute deviation, but the same rule must be used before and after adjustment to avoid false improvements caused by threshold drift.
[0107] After obtaining the average reliable defect score, phase-locking strength, and pit chain length, a closed-loop evaluation index is obtained by weighting and summing these three factors according to preset weights. The preset weights preferably satisfy the principle of being more sensitive to phase-locking phenomena, making the weights of phase-locking strength and pit chain length greater than the weight of the average reliable defect score. Specifically, under the conditions that the average reliable defect score is normalized to zero to one, the phase-locking strength itself is zero to one, and the pit chain length is normalized to zero to one according to the window length, the weight of the average reliable defect score can be 0.2 to 0.4, the weight of the phase-locking strength can be 0.3 to 0.5, and the weight of the pit chain length can be 0.3 to 0.5, with the sum of the three weights being one. The goal is to suppress phase-locking pits caused by abnormal workstations. Instead of simply reducing the mean of random defects, the system compares the adjusted closed-loop evaluation index with the original closed-loop evaluation index. Based on the comparison result, the local adjustment command is adjusted. Specifically, when the adjusted closed-loop evaluation index is less than or equal to the original closed-loop evaluation index, the control parameter of the current abnormal station is kept as the new setpoint and the next observation cycle begins. When the adjusted closed-loop evaluation index is greater than the original closed-loop evaluation index, the control parameter of the abnormal station is rolled back to the original setpoint and the local adjustment command is marked as invalid. To avoid frequent repetitions, it is preferable to reduce the subsequent adaptive step size or increase the trigger threshold when two consecutive rollbacks occur, thereby achieving stable convergence of the local adjustment of the abnormal station under the constraints of quantitative indicators.
[0108] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described method for visual detection and adjustment of surface defects in candy stamping.
[0109] like Figure 2 As shown in the figure, this graph illustrates the relationship between different workstation identifiers and cumulative phase intensity. The horizontal axis represents the workstation identifier, ranging from 1 to 30, and the vertical axis represents the cumulative phase intensity. The blue bars in the graph represent the cumulative phase intensity of each workstation, with the height of each bar corresponding to the cumulative phase intensity value of each workstation. The workstation indicated by the arrow is an abnormal workstation, whose cumulative phase intensity is significantly higher than other workstations, indicating that there is a significant periodic defect in this workstation. The formula on the right explains the calculation method of phase locking intensity, which is obtained by dividing the maximum cumulative phase intensity by the sum of the cumulative phase intensities of all workstations. This graph visually demonstrates the process of identifying abnormal workstations and further adjusting them through cumulative phase intensity.
[0110] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for visual inspection and adjustment of surface defects in candy stamping, characterized in that, Includes the following steps: S1. Collect the original image sequence of the candy and determine the workstation identifier corresponding to the candy; S2. Extract the font region from the original image of the candy and calculate the single-frame font pit defect score. Correct the single-frame font pit defect score to obtain a reliable defect score. S3. Aggregate and statistically analyze the reliable defect scores based on the workstation identifier to obtain the phase locking strength, and determine the abnormal workstations based on the phase locking strength; S4. Generate local adjustment instructions for abnormal workstations to update the control parameters of abnormal workstations; S5. After the local adjustment command is executed, calculate the closed-loop evaluation index and adjust the control parameters of the abnormal workstation according to the closed-loop evaluation index.
2. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 1, characterized in that, Determine the workstation identifier corresponding to the candy, including: Obtain the candy's output sequence number and the total number of turret stations on the equipment; Take the remainder of the candy's output sequence number divided by the total number of turret stations on the equipment, and use the remainder as the station identifier.
3. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 1, characterized in that, Extract the font region from the original image of the candy and calculate the font pit defect score for each frame, including: The original image is pose-normalized and cropped according to the preset character pattern area to obtain the standard character pattern area; Morphological black hat enhancement is applied to the standard area of the character pattern to obtain the pit response map; The pit response map is binarized and connected component extraction is performed to obtain a set of connected components. For each connected component in the set of connected components, calculate the area, pit contrast, and boundary sharpness of the connected component. Calculate the product of the area of the connected component, the pit contrast, and the boundary sharpness, and select the maximum value of the product among all connected components as the single-frame font pit defect score.
4. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 1, characterized in that, Correcting the single-frame font pockmark defect score includes: Acquire the standard area of the same candy in a dual-frame font under differential illumination or differential viewing angle; Calculate the two-frame pit response map corresponding to the standard region of the two-frame font respectively, and perform binarization to obtain the binary map of the pit region; Calculate the ratio of the intersection area to the union area of the pit regions in the two binary images of the pit regions, and use it as a region consistency index; The reliable defect score is obtained by multiplying the single-frame font pit defect score by the regional consistency index.
5. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 1, characterized in that, Based on the workstation identifier, the reliable defect scores are aggregated and statistically analyzed to obtain the phase-locking strength. Abnormal workstations are then identified based on the phase-locking strength, including: The reliable defect scores of candies with the same workstation identifier are summed to obtain the cumulative phase intensity corresponding to each workstation. The ratio of the maximum cumulative phase intensity to the sum of the cumulative phase intensities of all workstations is taken as the phase locking intensity. The workstation with the highest cumulative phase intensity is identified as an abnormal workstation.
6. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 5, characterized in that, After identifying the abnormal workstation, calculate the pit chain length, including: The pit chain threshold is set based on the statistical value of the reliable defect score; When the workstation of a candy is identified as an abnormal workstation and the credible defect score is not less than the pit chain threshold, the candy is marked as a chain defect point. Calculate the maximum number of consecutive chain-like defect points, and define the maximum number as the pit chain length.
7. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 6, characterized in that, Generate local adjustment instructions for the abnormal workstation to update the control parameters of the abnormal workstation, including: Calculate the median and median absolute deviation of the cumulative phase intensity for all workstations. Based on the median and the median absolute deviation, standardize the cumulative phase intensity of each workstation to obtain the phase outlier. An adaptive step size is constructed, which is positively correlated with the phase locking strength and positively correlated with the phase outlier of the abnormal work position. Based on the adaptive step size and the preset adjustment direction, the control parameters of abnormal workstations are incrementally updated, while the control parameters of other workstations remain unchanged. The control parameters include at least one of the following: local cleaning cycle, local drying air blowing duration, local demolding pulse amount, or local ejection compensation.
8. The method for visual inspection and adjustment of surface defects in candy stamping according to claim 7, characterized in that, After the local adjustment command is executed, the closed-loop evaluation index is calculated, and the control parameters of the abnormal workstation are adjusted according to the closed-loop evaluation index, including: Acquire a preset number of candy images after executing the local adjustment command, and calculate the corresponding average confidence defect score, phase locking strength, and pit chain length; The closed-loop evaluation index is obtained by weighting the average credible defect score, phase locking strength and pit chain length according to the preset weights. The adjusted closed-loop evaluation index is compared with the unadjusted closed-loop evaluation index. If the adjusted closed-loop evaluation index is greater than the unadjusted closed-loop evaluation index, a rollback operation is performed; otherwise, the adjusted local adjustment instruction is maintained.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements a visual inspection and adjustment method for surface defects in candy stamping as described in any one of claims 1 to 8.