A global color patch detection method based on template color features

By using a global color block detection method based on template color features, the robustness and accuracy issues of machine vision color detection schemes are solved, enabling efficient detection of color defects in industrial production, adapting to changes in lighting and improving detection speed and accuracy.

CN123118503APending Publication Date: 2026-11-17GUANGZHOU HEYI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611283812.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-24
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing machine vision color detection solutions are susceptible to interference from manual selection, have poor adaptability to ambient lighting, weak robustness of fixed parameters, and unstable accuracy of detection results, making it difficult to effectively detect color defects in workpieces in industrial production.

Method used

A global color block detection method based on template color features is adopted. By obtaining the effective feature extraction region of the region of interest, a three-channel differential adaptive tolerance interval is constructed. Combined with morphological opening operation and downsampling processing, color segmentation and target localization are performed, and the detection results are output.

Benefits of technology

It improves the anti-interference ability, accuracy and adaptability of detection, adapts to changes in lighting, and enhances detection speed and accuracy to meet the real-time requirements of industrial production lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123118503A_ABST
    Figure CN123118503A_ABST
Patent Text Reader

Abstract

This invention relates to the field of visual inspection technology, specifically disclosing a global color block detection method based on template color features. The method includes: converting the obtained effective feature extraction region to the HSV color space and constructing a corresponding template color feature vector, and constructing an adaptive tolerance interval with a color difference tolerance coefficient; performing downsampling processing on the image to be inspected to obtain a final low-resolution image, converting the final low-resolution image to the HSV color space, and performing threshold segmentation based on the adaptive tolerance interval to obtain a color block binarized mask image; performing a morphological opening operation on the color block binarized mask image based on the size of the morphological opening kernel to obtain a clean mask image; performing contour processing on the clean mask image to obtain the target contour, and solving for the minimum bounding rectangle to obtain the target color block bounding box; restoring the parameter information of the target color block bounding box to the original image to be inspected, then judging the target color block and outputting the detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual inspection technology, and more specifically, to a global color block detection method based on template color features. Background Technology

[0002] Machine vision color inspection technology is widely used in modern industrial quality control, covering color defect detection for various workpieces such as injection molded parts, spray-painted shells, and printed labels. It can also be adapted to applications that use different colored labels based on product pass / defect status, enabling automated product sorting and distribution by recognizing label colors. In industrial production, factors such as batch differences in raw materials, fluctuations in process parameters, and changes in ambient lighting can easily cause color defects in the workpiece itself, such as color differences, color deviations, and incorrect colors. Differences in the paper quality of the label material, adhesive wrinkles, and reflections can also cause color signal disturbances. Therefore, color consistency detection is a crucial step in ensuring product quality and achieving automated sorting on the production line.

[0003] However, some existing machine vision color detection solutions have technical defects such as susceptibility to interference from manual selection, poor adaptability to ambient lighting, weak robustness of fixed parameters, and unstable accuracy of detection results. Summary of the Invention

[0004] To address the shortcomings and defects of the existing technology, this invention provides a global color block detection method based on template color features.

[0005] The technical solution adopted in this invention is:

[0006] A global color patch detection method based on template color features, the method comprising: After detecting the region of interest in the reference image, at least a portion of the region of interest is obtained as the effective feature extraction region; the effective feature extraction region is converted to the HSV color space and the corresponding template color feature vector is constructed. A three-channel differential adaptive tolerance range is constructed based on the template color feature vector and combined with the preset color difference tolerance coefficient; The image to be inspected is downsampled to obtain the final low-resolution image. The final low-resolution image is converted to the HSV color space and three-channel joint thresholding is performed based on the three-channel differential adaptive tolerance range to obtain a color patch binarized mask image. The size of the morphological opening operation kernel is adaptively determined based on the size parameter of the region of interest. The adaptive kernel is used to perform morphological opening operation on the color block binarized mask image to obtain a pure mask image that retains the complete outline of the effective target color block. The target contour is obtained by contour processing of the clean mask image, and the minimum bounding rotation rectangle is solved for the target contour to obtain the target color block box on the final low-resolution image. The parameter information of the target color block bounding box is restored to the original image to be inspected. Based on the restored target color block bounding box, the target color block is judged according to the selected color block existence judgment rule, and the corresponding detection result is output.

[0007] Preferably, after detecting the region of interest in the bounding reference image, at least a portion of the region of interest is obtained as the effective feature extraction region, including: After detecting the region of interest in the reference image, the cropping ratio of the region of interest is obtained; Based on the obtained truncation ratio, at least a portion of the region of interest is truncated as the effective feature extraction region; When the shortest side length of the effective feature extraction region meets the preset cancellation condition, the complete region of interest is directly selected as the effective feature extraction region.

[0008] Preferably, after using the average values ​​of H, S, and V as the template color feature vector, and before constructing a three-channel differential adaptive tolerance range based on the template color feature vector and a preset color difference tolerance coefficient, the method further includes: Calculate the HSV space Euclidean distance between the HSV features of each pixel within the effective feature extraction region and the template color feature vector; The standard deviation of the Euclidean distance distribution is calculated based on the Euclidean distance of each pixel, and used as the confidence index of the template feature. When the template feature confidence index is less than or equal to the preset threshold, proceed to the next step; When the template feature confidence index is greater than the preset threshold, a prompt message indicating insufficient uniformity of the region of interest is output.

[0009] Furthermore, a three-channel differential adaptive tolerance range is constructed based on the template color feature vector and a preset color difference tolerance coefficient, including: Obtain the template feature confidence index; The preset color difference tolerance coefficient is dynamically adjusted according to the template feature confidence index to obtain the adjusted color difference tolerance coefficient. The value of the adjusted color difference tolerance coefficient is inversely related to the value of the template feature confidence index. Based on the template color feature vector and the adjusted color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S, and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

[0010] Furthermore, the reverse association specifically refers to: Preset color difference tolerance coefficient and reference standard deviation; The preset color difference tolerance coefficient is positively adjusted based on the relative ratio of the template feature confidence index to the reference standard deviation; wherein, the larger the value of the template feature confidence index, the larger the adjustment range of the preset color difference tolerance coefficient, and vice versa.

[0011] Furthermore, a three-channel differential adaptive tolerance range is constructed based on the template color feature vector and a preset color difference tolerance coefficient, including: Based on the template color feature vector and the preset color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

[0012] Preferably, the downsampling process is executed by calling the embedded platform's built-in RGA raster graphics accelerator hardware.

[0013] Furthermore, the size of the structural kernel for morphological opening operations is adaptively determined based on the size parameters of the region of interest, including: Get the shortest side length of the region of interest; The basic dimensions of the structural kernel for morphological opening operations are calculated based on the shortest side length of the region of interest and a preset scaling ratio. The base size is compared with a preset lower limit threshold size. If the basic size is less than the lower size threshold, then the final size of the structural core is set to the lower size threshold. If the basic size is greater than or equal to the lower limit threshold of the size, then the final size of the structural core is set to the basic size.

[0014] Furthermore, the parameter information of the target color block bounding box is restored to the original image to be inspected, including: Obtain the total downsampling factor of the downsampling process; The pixel coordinates, width, and height of the target color block box on the final low-resolution image are multiplied by the total downsampling factor and mapped to the pixel coordinate system of the original image to be inspected. The rotation angle of the target color block remains unchanged before and after the restoration.

[0015] Furthermore, the rules for determining the existence of color blocks include any one or more of the following: basic existence determination, relative area deviation determination, absolute area range determination, and limited area existence determination.

[0016] Compared with the prior art, the beneficial effects of the present invention are:

[0017] This invention extracts template color features by extracting the effective feature extraction area of ​​the Region of Interest (ROI) selected by the user (instead of directly using the entire ROI), which effectively avoids the contamination of template features by edge noise introduced by user selection errors.

[0018] This invention constructs a three-channel differentiated adaptive tolerance range based on template color feature vectors and a preset color difference tolerance coefficient. Unlike traditional methods that use a uniform tolerance range for the H, S, and V channels, this invention sets differentiated tolerance ranges for each of the three channels based on their physical characteristics, improving adaptability. In particular, the tolerance for the S channel is appropriately relaxed to accommodate saturation fluctuations caused by changes in illumination, enabling color segmentation to maintain sensitivity to the target color while possessing stronger adaptability to illumination changes. Simultaneously, threshold segmentation using all three channels effectively reduces missegmentation and improves the accuracy of color selection compared to single-channel segmentation.

[0019] This invention performs downsampling processing on the image to be inspected according to a preset number of layers. Especially for large-size, high-resolution images, downsampling can reduce the computational complexity by several to tens of times, significantly improving the detection speed while ensuring detection accuracy. It is particularly suitable for industrial production lines with stringent real-time requirements.

[0020] This invention adaptively determines the size of the morphological opening operation kernel based on the size parameter of the region of interest in the reference image. This allows the denoising intensity to automatically scale with the size of the target color patch. Small targets can use small-sized kernels to prevent the target color patch from being over-eroded and disappearing, while large targets can use large-sized kernels to effectively remove background noise. Compared to traditional morphological processing methods with fixed kernel sizes, this invention's adaptive mechanism maintains good denoising performance and target integrity in detection scenarios with targets of different sizes, significantly improving the method's versatility for products of different specifications.

[0021] This invention solves for the minimum bounding rectangle of rotation after contour processing of a clean mask image, which can accurately describe the actual position, angle, and size of tilted color blocks. Based on this, the target color block bounding box parameter information on the low-resolution image is restored to the coordinate system of the original image to be inspected, ensuring that the positioning accuracy of the final output detection result is not affected by pyramid downsampling, thus balancing detection speed and positioning accuracy. Attached Figure Description

[0022] Figure 1 This is a flowchart of a global color block detection method based on template color features provided by the present invention.

[0023] Figure 2 This is a flowchart of another global color block detection method based on template color features provided by the present invention.

[0024] Figure 3 This is a flowchart of another global color block detection method based on template color features provided by the present invention.

[0025] Figure 4 This is a schematic diagram of a computer device provided by the present invention. Detailed Implementation

[0026] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. 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. The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0027] It should be understood that, when used in this specification, the terms “comprising” and “including” indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0028] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification, unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “the” are intended to include the plural forms.

[0029] It should also be further understood that the term "and / or" as used in this specification refers to any combination of one or more of the associated listed items, as well as all possible combinations, and includes such combinations.

[0030] In industrial production, color defects such as color difference, color deviation, and color mismatch are easily generated in the workpiece due to factors such as batch differences in raw materials, fluctuations in process parameters, and changes in ambient lighting. However, existing machine vision color detection solutions have technical shortcomings such as susceptibility to interference from manual selection, poor adaptability to ambient lighting, weak robustness of fixed parameters, and unstable accuracy of detection results.

[0031] To address this, this invention proposes a global color block detection method based on template color features. It optimizes and upgrades the entire process from template color feature extraction, color segmentation, image denoising, target localization, coordinate restoration, and result judgment. It effectively solves the technical defects of existing color block detection technologies, such as susceptibility to interference from manual selection, poor adaptability to ambient lighting, weak robustness of fixed parameters, and unstable accuracy of detection results. Overall, it has the advantages of strong anti-interference ability, high detection accuracy, wide scene adaptability, and high degree of automation.

[0032] like Figure 1 As shown, this example provides a global color patch detection method based on template color features. The method includes: After detecting the region of interest in the reference image, at least a portion of the region of interest is obtained as the effective feature extraction region; the effective feature extraction region is converted to the HSV color space and the corresponding template color feature vector is constructed. A three-channel differential adaptive tolerance range is constructed based on the template color feature vector and combined with the preset color difference tolerance coefficient; The image to be inspected is downsampled to obtain the final low-resolution image. The final low-resolution image is converted to the HSV color space and three-channel joint thresholding is performed based on the three-channel differential adaptive tolerance range to obtain a color patch binarized mask image. The size of the morphological opening operation kernel is adaptively determined based on the size parameter of the region of interest. The adaptive kernel is used to perform morphological opening operation on the color block binarized mask image to obtain a pure mask image that retains the complete outline of the effective target color block. The target contour is obtained by contour processing of the clean mask image, and the minimum bounding rotation rectangle is solved for the target contour to obtain the target color block box on the final low-resolution image. The parameter information of the target color block bounding box is restored to the original image to be inspected. Based on the restored target color block bounding box, the target color block is judged according to the selected color block existence judgment rule, and the corresponding detection result is output.

[0033] It should be noted that the global color patch detection method based on template color features described in this invention does not strictly limit the data processing steps. That is, the data processing steps can be followed as described above, or they can be deviated from. For example, the step of constructing the three-channel differential adaptive tolerance range can be completed after converting the final low-resolution image to the HSV color space and before performing three-channel joint thresholding to obtain the color patch binarization mask image. Figure 2 As shown.

[0034] When selecting template color features, the traditional method is to manually select the region of interest (ROI) of the reference image to extract template color features. This method is prone to introducing edge background color, transition noise, and invalid edge pixels, which can lead to template color feature shift and detection misjudgment. Therefore, this invention extracts template color features by obtaining at least a portion of the ROI as the effective feature extraction region after manually selecting the ROI of the reference image. That is, the template color features are extracted from a portion of the center of the ROI.

[0035] In this example, after detecting the region of interest in the reference image, at least a portion of the region of interest is obtained as the effective feature extraction region, including: After detecting the region of interest in the reference image, the cropping ratio of the region of interest is obtained; Specifically, the system receives the region of interest (ROI) of the reference image interactively selected by the user, records the basic parameters of the ROI such as pixel coordinates, width, and height, and locks the initial template region for feature extraction. After detecting the ROI in the reference image, it obtains the basic parameters of the ROI such as pixel coordinates, width, and height. A fixed cropping ratio of the ROI can be preset, such as 70% or other ratios. The cropping ratio of the ROI is obtained by reading the pre-stored cropping ratio.

[0036] Based on the obtained truncation ratio, at least a portion of the region of interest is truncated as the effective feature extraction region; For example, if the cropping ratio is 70%, then a rectangular area representing 70% of the geometric center of the region of interest can be selected as the effective feature extraction region. The cropping is based on the center point of the region of interest and scaled symmetrically upwards, downwards, left, and right, retaining only the core solid-color pixels of the region of interest and completely eliminating redundant areas selected manually around the edges, background noise, edge transition colors, and other interfering pixels.

[0037] For example, the preset cropping ratio of the region of interest (ROI) is not fixed. Instead, after detecting the ROI in the reference image, the shortest side length of the ROI is obtained, and the preset cropping ratio is dynamically adjusted based on the shortest side length of the ROI to obtain the adjusted cropping ratio. Specifically, when the preset cropping ratio of the ROI is 70%, if the shortest side length of the ROI is greater than 200 pixels, the cropping ratio decreases to 50%; if the shortest side length of the ROI is less than 50 pixels, the cropping ratio increases to 85%. By establishing a piecewise function relationship between the adjusted cropping ratio p and the shortest side length L: p = 0.7 + 0.15 × (50 - L) / 50, (L < 50); p = 0.7 - 0.2 × (L - 200) / 200, (L > 200), the effective feature extraction ratio adapts to the size of the ROI, avoiding excessive internal texture noise introduced by large ROIs and insufficient effective pixels extracted by small ROIs.

[0038] By obtaining at least a portion of the region of interest as the effective feature extraction region according to the final truncation ratio, the problem of template color feature shift and detection misjudgment is avoided when manually selecting the region of interest, which is prone to introducing edge background color, transition noise, and invalid edge pixels.

[0039] When the shortest side length of the effective feature extraction region meets the preset cancellation condition, the complete region of interest is directly selected as the effective feature extraction region. By detecting the side length parameter of the effective feature extraction region after cropping, if the shortest side length of the effective feature extraction region is less than 5 pixels, it is determined that the effective feature extraction region has no value for further cropping. The cropping rule of obtaining at least a part of the region of interest as the effective feature extraction region according to the cropping ratio is automatically canceled, and the entire region of interest (ROI) selected by the bounding box is directly selected as the effective feature extraction region. By setting a fault tolerance boundary mechanism for extremely small regions, the problem of missing color feature pixels and algorithm failure in extremely small template scenarios can be effectively avoided.

[0040] In this example, after extracting the effective feature region, the effective feature region is converted to the HSV color space and the corresponding template color feature vector is constructed, specifically including: Convert the effective feature extraction region to the HSV color space; Calculate the average values ​​of the H, S, and V channels of all pixels in the effective feature extraction region, and use the average values ​​of H, S, and V as the template color feature vector.

[0041] It should be noted that the reference image and the image to be tested mentioned above are both RGB color images; by converting the RGB color image from the RGB color space to the HSV color space, the defect of brightness and chromaticity coupling interference in the RGB color space can be eliminated; the HSV color space is composed of three channel components: hue (H), saturation (S), and value (V).

[0042] This invention extracts template color features by obtaining the effective feature extraction region of the region of interest, avoiding interference from invalid pixels such as edge background, burrs, reflections, and noise that are easily introduced during the manual selection of the region of interest. It effectively avoids edge noise pixels from contaminating the template color reference features, ensuring that the template color feature vector composed of the average values ​​of the extracted H, S, and V is pure, reliable, and closely matches the true color of the standard color block, thus fundamentally improving the accuracy of the template reference.

[0043] In this example, a three-channel differential adaptive tolerance range is constructed based on the template color feature vector and a preset color difference tolerance coefficient, including: Based on the template color feature vector and the preset color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

[0044] For example, differentiated adaptive tolerance intervals are constructed for the three channels H, S, and V, as follows:

[0045] For the hue H channel, the tolerance range is ±(180×t), centered on the average H value in the template color feature vector, to accommodate slight hue shifts; where t is the preset color difference tolerance coefficient.

[0046] For the S saturation channel, the tolerance range is ±(255×2t) centered on the average value of S in the template color feature vector. This is double the tolerance of the H and V channels, which can adapt to large fluctuations in color saturation caused by changes in lighting and avoid the incorrect removal of effective color blocks caused by changes in light brightness.

[0047] For the brightness V channel, the tolerance range is ±(255×t) centered on the average value of V in the template color feature vector, controlling the brightness deviation range and filtering out excessively bright or dark interference pixels.

[0048] This invention constructs a three-channel differentiated adaptive tolerance range based on template color feature vectors and a preset color difference tolerance coefficient. In particular, the tolerance of the saturation S channel is appropriately relaxed to adapt to saturation fluctuations caused by changes in illumination, so that color segmentation can have a stronger ability to adapt to changes in illumination while ensuring sensitivity to the target color.

[0049] In another specific embodiment, after using the average values ​​of H, S, and V as the template color feature vector, and before constructing a three-channel differential adaptive tolerance range based on the template color feature vector and a preset color difference tolerance coefficient, the method further includes: Calculate the HSV space Euclidean distance between the HSV features of each pixel within the effective feature extraction region and the template color feature vector; The standard deviation of the Euclidean distance distribution is calculated based on the Euclidean distance of each pixel, and used as the confidence index of the template feature. When the template feature confidence index is less than or equal to the preset threshold, proceed to the next step; When the template feature confidence index is greater than the preset threshold, a prompt message indicating insufficient uniformity of the region of interest is output.

[0050] At this point, the present invention provides a global color block detection method based on template color features, such as... Figure 3 As shown, it includes: After detecting the region of interest in the reference image, at least a portion of the region of interest is obtained as the effective feature extraction region; the effective feature extraction region is converted to the HSV color space and the average values ​​of H, S, and V are calculated respectively, and the average values ​​of H, S, and V are used as the template color feature vector; Calculate the HSV space Euclidean distance between the HSV features of each pixel within the effective feature extraction region and the template color feature vector; The standard deviation of the Euclidean distance distribution is calculated based on the Euclidean distance of each pixel, and used as the confidence index of the template feature. When the template feature confidence index is less than or equal to the preset threshold, proceed to the next step, such as constructing a three-channel differential adaptive tolerance range based on the template color feature vector and the preset color difference tolerance coefficient. The image to be inspected is downsampled to obtain the final low-resolution image. The final low-resolution image is converted to the HSV color space and three-channel joint thresholding is performed based on the three-channel differential adaptive tolerance range to obtain a color patch binarized mask image. The size of the morphological opening operation kernel is adaptively determined based on the size parameter of the region of interest. The adaptive kernel is used to perform morphological opening operation on the color block binarized mask image to obtain a pure mask image that retains the complete outline of the effective target color block. The target contour is obtained by contour processing of the clean mask image, and the minimum bounding rotation rectangle is solved for the target contour to obtain the target color block box on the final low-resolution image. The parameter information of the target color block bounding box is restored to the original image to be inspected. Based on the restored target color block bounding box, the target color block is judged according to the selected color block existence judgment rule, and the corresponding detection result is output.

[0051] When the template feature confidence index exceeds a preset threshold, a prompt message indicating insufficient uniformity of the region of interest is output, and a preset template optimization prompt operation is executed. This preset template optimization prompt operation includes at least one of the following methods: Generate and output a first prompt message to remind the user to change the current reference image; Generate and output a second prompt message to prompt the user to re-select the region of interest on the reference image.

[0052] The first and second prompts can be text prompts, visual / graphic prompts, or voice prompts, and there are no restrictions on them.

[0053] In other words, when the template feature confidence index is greater than the preset threshold, for example, the region of interest can be re-selected or the reference image can be replaced, thereby obtaining a more uniform and effective feature extraction region.

[0054] In addition, after the preset template optimization prompt operation is executed, the currently extracted template color feature vector is cleared, and the process returns to the step of obtaining the region of interest until the template feature confidence index meets the preset threshold before proceeding to the subsequent detection process.

[0055] In another specific embodiment, the HSV spatial Euclidean distance between the HSV features of each pixel within the effective feature extraction region and the template color feature vector is calculated, specifically including: Obtain the feature vectors of multiple pixels within the region of interest in the HSV color space; the feature vectors are composed of H pixel values, S pixel values, and V pixel values. Calculate the HSV space Euclidean distance between the feature vector of each pixel in the effective feature extraction region and the template color feature vector to obtain the Euclidean distance set.

[0056] It should be noted that when calculating the Euclidean distance in HSV space, the difference in the H channel is processed by ring correction. The ring correction includes: calculating the original difference between the H pixel value and the H value in the template color feature vector. If the absolute value of the original difference exceeds the half-cycle threshold of the hue ring, the original difference is corrected across the boundary, and the shortest angular distance is used as the actual difference in the H channel to participate in the Euclidean distance calculation.

[0057] The standard deviation of the Euclidean distance distribution is calculated based on the Euclidean distances of each pixel and used as a confidence index for the template feature. Specifically, the dispersion statistic of the Euclidean distance set is calculated, which is the standard deviation of the distribution. This standard deviation is then used as a confidence index characterizing the color uniformity of the region of interest. The smaller the standard deviation, the higher the color uniformity of the region of interest, and the higher the confidence of the template feature.

[0058] In another specific embodiment, a three-channel differential adaptive tolerance range is constructed based on the template color feature vector and combined with a preset color difference tolerance coefficient, including: Obtain the template feature confidence index; The preset color difference tolerance coefficient is dynamically adjusted according to the template feature confidence index to obtain the adjusted color difference tolerance coefficient. The value of the adjusted color difference tolerance coefficient is inversely related to the value of the template feature confidence index. Based on the template color feature vector and the adjusted color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S, and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

[0059] Specifically, the reverse association is as follows: Preset color difference tolerance coefficient and reference standard deviation; The preset color difference tolerance coefficient is positively adjusted based on the relative ratio of the template feature confidence index to the reference standard deviation; wherein, the larger the value of the template feature confidence index, the larger the adjustment range of the preset color difference tolerance coefficient, and vice versa.

[0060] Compared to the above method of constructing a differentiated adaptive tolerance range using a preset fixed color difference tolerance coefficient, this invention also dynamically adjusts the preset color difference tolerance coefficient based on the template feature confidence index. For example, when the template color uniformity is high (i.e., the template feature confidence index is low), the preset color difference tolerance coefficient needs to be adjusted to a smaller value to achieve strict color screening; when the template color uniformity is poor (i.e., the template feature confidence index is high), the preset color difference tolerance coefficient needs to be adjusted to a larger value to accommodate the color fluctuations of the effective feature extraction area itself.

[0061] Specifically, the preset color difference tolerance coefficient is dynamically adjusted based on the template feature confidence index to obtain the adjusted color difference tolerance coefficient, and the formula is as follows:

[0062] In the formula, t is the adjusted color difference tolerance coefficient; t is the preset color difference tolerance coefficient. The scaling factor is 0.5 ≤ α ≤ 2.0; For template feature confidence index; This is the preset reference standard deviation.

[0063] Based on the template color feature vector and the adjusted color difference tolerance coefficient, differential adaptive tolerance intervals are constructed for the H, S, and V channels, as follows: For the hue H channel, the tolerance interval is centered on the average H value in the template color feature vector. The color hue is slightly off; among them This is the adjusted color difference tolerance coefficient.

[0064] For the saturation S channel, the tolerance range is centered on the average S value in the template color feature vector. Compared to H and V channels, the tolerance is doubled, which can adapt to large fluctuations in color saturation caused by changes in lighting, and avoid the incorrect removal of effective color blocks due to changes in light brightness. For the luminance V channel, the tolerance range is centered on the average V value in the template color feature vector. It controls the range of brightness deviation and filters out interference pixels that are too bright or too dark.

[0065] It should be noted that when dividing the tolerance range of the target color channel, it is determined whether the average value of the effective feature extraction region on the target color channel is in the region near the boundary of the target color channel; if so, the tolerance range is extended across the boundary of the target color channel so that the tolerance range covers the hue values ​​on both sides of the boundary.

[0066] The target color channel is the H channel in the HSV color space, and the boundary adjacent area is the periodic boundary of the H channel, which includes a 0° boundary or a 180° boundary.

[0067] The cross-boundary extension process includes: When the effective feature extraction region has the average value on the H channel When the distance to the periodic boundary is less than a preset proximity threshold, an initial tolerance interval is constructed with the average value as the center. ,in, This indicates the width of the tolerance range, which is determined by the adjusted color difference tolerance coefficient. The portion of the initial tolerance interval that exceeds the upper or lower limit of the periodic boundary is mapped to the other side of the periodic boundary according to the periodicity of the hue ring, forming a continuous tolerance interval that spans the boundary.

[0068] In general, the tolerance interval on the H channel needs to be circularized. Specifically, when the H value of the effective feature extraction region is close to 0° or 180°, the tolerance interval crosses the 0° / 180° boundary of the hue ring to avoid segmentation errors caused by boundary truncation.

[0069] In another specific embodiment, after calculating the template feature confidence index and determining whether to re-acquire the effective feature extraction region by using a preset threshold, the preset fixed color difference tolerance coefficient can be dynamically adjusted without using the template feature confidence index, or the preset color difference tolerance coefficient can be directly used to construct a differentiated adaptive tolerance interval for the H, S, and V channels.

[0070] This invention constructs a three-channel differentiated adaptive tolerance range based on template color feature vectors and preset color difference tolerance coefficients. It abandons the rigid segmentation mode of traditional methods that use uniform or fixed thresholds, and can achieve differentiated deviation tolerance for color characteristics of hue, saturation, and brightness. In particular, it can adapt to the problem of large color saturation drift caused by light fluctuations in industrial environments, effectively avoiding problems such as erroneous rejection of effective color blocks, missed defect detection, and misjudgment of qualified products caused by changes in lighting and ambient light interference. It significantly improves the robustness and accuracy of color segmentation under complex working conditions.

[0071] In this example, downsampling is performed on the image to be inspected to obtain a final low-resolution image. The downsampling process includes a size scaling operation, an image pyramid downsampling operation, or other methods that can downsample and output a low-resolution image. Preferably, the downsampling process uses an image pyramid downsampling operation.

[0072] To address the limitations of embedded platforms in smart cameras in terms of computing power and the high computational load caused by using original high-definition images, this invention significantly reduces the computational load of the algorithm without sacrificing detection accuracy by downsampling and adapting to embedded hardware acceleration mechanisms.

[0073] Taking the image pyramid downsampling operation as an example, the downsampling process performed on the image to be inspected to obtain the final low-resolution image includes: Based on the equipment's computing power and detection accuracy requirements, the number of image pyramid downsampling layers is pre-configured, i.e., the preset number of layers, and the image pyramid scaling parameters are initialized. Based on the pre-configured number of image pyramid downsampling layers, image pyramid downsampling processing is performed on the image to be inspected. Specifically, the original image to be inspected is used as the original image of layer 0 of the pyramid, and downsampling processing is performed layer by layer according to the set number of layers. The width and height of each layer are half of the previous layer. Correspondingly, with each downsampling layer, the total number of pixels in the image is reduced to 1 / 4 of the original, and the computational load per pixel decreases exponentially accordingly. After performing downsampling for the preset number of layers, the final low-resolution image is output.

[0074] Existing machine vision image pyramid schemes commonly employ CPU software interpolation for layer-by-layer downsampling in embedded smart camera devices equipped with ARM architecture SoCs such as Rockchip. Multi-layer scaling and interpolation consumes significant CPU computing power, resulting in long preprocessing times, encroaching on color block detection resources, and potentially causing a drop in detection frame rate. Furthermore, the RGA hardware built into the smart camera is only used for general image scaling and display processing; its image processing capabilities are not utilized for image pyramid downsampling, leading to wasted computing power. Therefore, for low-computing-power embedded platforms like ARM, this solution abandons the traditional CPU software interpolation scaling method and instead utilizes the smart camera's built-in RGA raster graphics accelerator for processing. In other words, the downsampling process is executed via the embedded platform's built-in RGA raster graphics accelerator hardware, thereby offloading computing power, avoiding CPU core resource consumption, and significantly improving image processing speed.

[0075] In this example, the final low-resolution image is converted to the HSV color space, and three-channel joint thresholding is performed based on the three-channel differential adaptive tolerance range to obtain a color patch binarized mask image, including: The final low-resolution image is converted from the original RGB color space to the HSV color space, yielding the corresponding hue (H channel), saturation (S channel), and lightness (V channel) images. This invention abandons traditional single-channel threshold segmentation or three-channel unified tolerance threshold segmentation methods. Based on the constructed differentiated adaptive tolerance intervals for the H, S, and V channels, it performs three-channel joint threshold segmentation judgment pixel-by-pixel on the final low-resolution image.

[0076] Specifically, each pixel in the final low-resolution image is traversed, and the H, S, and V pixel values ​​of the current pixel are extracted. The pixel values ​​of each channel are compared with the differential adaptive tolerance range of the corresponding channel. Only when the H pixel value of the current pixel falls within the tolerance range of the H channel, the S pixel value falls within the tolerance range of the S channel, and the V pixel value falls within the tolerance range of the V channel, that is, when all three channels simultaneously meet the tolerance threshold conditions, is the pixel determined to be a valid pixel of the target color block and is assigned as a foreground pixel. If the pixel value of any channel of the current pixel exceeds the tolerance range of the corresponding channel, the pixel is determined to be a background interference pixel and is assigned as a background pixel.

[0077] By performing three-channel joint thresholding segmentation on a pixel-by-pixel basis, the entire final low-resolution image is classified into binary values, ultimately generating a binary mask image containing only the target color block foreground and irrelevant background. This invention utilizes the S-channel's high tolerance to adapt to saturation drift caused by lighting and darkness fluctuations, while simultaneously using the H and V channels to precisely constrain hue and brightness ranges. This effectively preserves the true target color block pixels while maximally filtering out noise, light and shadow, and environmental interference pixels, ensuring that the generated binary mask image accurately fits the true target color block region. This provides a high-precision image foundation for subsequent morphological denoising, contour extraction, and target localization.

[0078] In this example, the size of the structure kernel for the morphological opening operation is adaptively determined based on the size parameter of the region of interest, including: Get the shortest side length of the region of interest; The basic dimensions of the structural kernel for morphological opening operations are calculated based on the shortest side length of the region of interest and a preset scaling ratio. The base size is compared with a preset lower limit threshold size. If the basic size is less than the lower size threshold, then the final size of the structural core is set to the lower size threshold. If the basic size is greater than or equal to the lower limit threshold of the size, then the final size of the structural core is set to the basic size.

[0079] In this example, the size of the morphological opening operation's structure kernel is not a fixed value. The basic size of the morphological opening operation's structure kernel is calculated based on the shortest side length of the region of interest and a preset scaling ratio. For example, it can be 0.1 times the shortest side length of the region of interest, or other multiples, so that the denoising intensity automatically scales with the size of the target color block. Small targets are eroded by using a small kernel, while large targets are eroded by using a large kernel to fully remove noise.

[0080] In addition, this example sets a structural kernel size lower limit protection mechanism, which compares the basic size of the structural kernel calculated according to the preset scaling ratio with the preset size lower limit threshold. For example, the preset size lower limit threshold is 20 pixels. That is, if the basic size of the structural kernel is less than 20 pixels, it will be uniformly and forcibly limited to 20 pixels. Through the structural kernel size lower limit protection mechanism, the noise reduction failure caused by the structural kernel size being too small can be avoided.

[0081] In this example, an adaptive structure kernel is used to perform morphological opening operations on the color block binarized mask image to obtain a clean mask image that retains the complete outline of the effective target color block. Specifically, based on the finally determined structure kernel size, a morphological opening operation of erosion followed by dilation is performed. The morphological opening operation of erosion followed by dilation first eliminates small isolated noise points and minor edge interference in the mask through erosion, and then restores the true outline size of the target color block through dilation, ensuring that the integrity of the effective target is not destroyed while denoising.

[0082] This example achieves adaptive denoising by adaptively obtaining the basic size of the morphological opening operation kernel. For example, small-sized target color patches are matched with small kernels to avoid excessive erosion or loss of the target color patches; large-sized target color patches are matched with large kernels to completely remove large-area, dense noise interference. It is perfectly adapted to the detection scenarios of targets of different sizes and has extremely strong versatility.

[0083] In order to accurately extract the target contour, i.e. the effective color block contour, from the denoised clean mask image and filter out the invalid noise contour, so as to provide data support for subsequent multi-rule judgment.

[0084] The target contour is obtained by contour processing of the clean mask image, including: Perform an outer contour extraction operation on the obtained pure mask image, retain only the outer closed contour of the target color block, and remove internal holes and fragmented false contours to ensure the effectiveness of the contour; The entire set of extracted outer contours is filtered by contour area. Specifically, based on the preset minimum effective area threshold and maximum effective area threshold, all extracted contours are traversed, and fine noise contours with an area smaller than the minimum effective area threshold and ultra-large interference region contours with an area larger than the maximum effective area threshold are directly filtered out. Only effective color block contours with a size within the range of the minimum and maximum effective area thresholds are retained, thus obtaining the target contour.

[0085] The minimum bounding rectangle of the target contour is calculated to obtain the target color block bounding box on the final low-resolution image. The minimum bounding rectangle of the target contour can be obtained using conventional techniques, such as the following: Obtain the set of contour points corresponding to the target contour, and calculate the convex hull point set of the contour point set; The rotational caliper algorithm is used to traverse the vertices of the convex hull, solve for the bounding rectangle of the convex hull under different rotational orientations, and calculate the area of ​​the corresponding rectangle. The smallest bounding rectangle is selected from these to obtain the smallest bounding rotated rectangle. Output the center position, rectangle size, and rotation angle of the smallest bounding rectangle to generate the target color block bounding box on the final low-resolution image.

[0086] As another implementation method, the minimum circumscribed rotating rectangle can be solved directly based on the contour point set without going through the convex hull calculation.

[0087] In this example, the parameter information of the target color swatch bounding box is restored to the original image to be inspected, including: Obtain the total downsampling factor of the downsampling process; The pixel coordinates, width, and height of the target color block box on the final low-resolution image are multiplied by the total downsampling factor and mapped to the pixel coordinate system of the original image to be inspected. The rotation angle of the target color block remains unchanged before and after the restoration.

[0088] For example, taking image pyramid downsampling as an example, the scale restoration factor (i.e., the total downsampling factor) is determined according to the preset number of layers of the image pyramid; the parameter information of the target color block obtained on the low-resolution image is scaled according to the scale restoration factor, and combined with pixel boundary correction and sub-pixel rounding, the parameter information of the target color block is mapped and restored to the original coordinate system of the image to be inspected; the parameter information includes pixel coordinate parameters, width parameters, and height parameters; the rotation angle of the target color block remains unchanged before and after the restoration.

[0089] Specifically, based on the number of downsampling layers N, the scale restoration factor is determined to be 2 to the power of N. The pixel coordinate parameters, width parameters, and height parameters of the target color block boxes detected on the low-resolution image are uniformly multiplied by the scale restoration factor, and pixel boundary correction and sub-pixel rounding are performed to accurately restore all target position and size information to the original image coordinate system, thus completely solving the coordinate scale offset problem caused by downsampling.

[0090] In this example, based on the pixel coordinates, width, and height of the restored target color block bounding box, the physical area of ​​each valid color block on the original image to be inspected is recalculated or directly scaled. Then, the areas of all the valid color blocks that pass the screening are summed to obtain the total area of ​​the valid color blocks in the current image to be inspected. The target color blocks are judged according to the selected color block existence judgment rules, and the corresponding detection results are output.

[0091] In this example, the rules for determining the existence of color blocks include any one or more of the following: basic existence determination, relative area deviation determination, absolute area range determination, and limited area existence determination.

[0092] The basic existence determination means that if any valid color block is found in the image to be inspected, the color block is determined to exist; if no valid color block is found, the color block is determined to not exist. This method is suitable for simple detection scenarios where only the presence or absence of a color block needs to be determined.

[0093] The area relative deviation determination involves obtaining the total area of ​​standard color blocks in the reference image and using it as the total area of ​​the template; calculating the relative deviation between the total effective color block area of ​​the current image to be inspected and the total area of ​​the template; if the deviation value is within a preset area deviation tolerance range, the color block is determined to exist; otherwise, it is determined not to exist. This method is suitable for high-precision detection scenarios where slight deviations in color block area are permissible.

[0094] The absolute area range determination is based on a preset upper and lower absolute range of the total area of ​​valid color patches. If the total area of ​​valid color patches in the current image to be inspected falls within this upper and lower absolute range, it is determined that the patch exists; otherwise, it is determined that the patch does not exist. This method is suitable for standardized inspection scenarios where the patch area specifications are fixed and there is no deviation.

[0095] The determination of the existence of the limited region is automatically enabled when a specified detection limit for the Region of Interest (ROI) is configured. It only determines whether there are valid color blocks within the specified ROI and returns the index information of the corresponding target color block, ignoring color block interference outside the region. It is suitable for local area fixed-point detection scenarios.

[0096] Finally, a color block presence status identifier is generated according to the selected color block presence determination rule, and the determination result is uniformly mapped to a standardized output: if the color block exists, output OK; if the color block does not exist, output NG. In this way, the color block detection and determination of the entire image to be inspected is completed.

[0097] This invention supports multiple judgment rules, including basic judgment based on the existence of color blocks, judgment based on relative area deviation, judgment based on absolute area range, and target index judgment based on restricted areas. The ability to configure multiple selectable judgment rules allows this invention to adapt to the differentiated detection needs of various industrial scenarios, such as color difference detection of injection molded parts, color deviation detection of shell coating, and color error detection of label printing, demonstrating good engineering applicability and scalability.

[0098] Please see Figure 4 , Figure 4 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 500 is a server, which can be a standalone server or a server cluster composed of multiple servers.

[0099] See Figure 4 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.

[0100] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. When the computer program 5032 is executed, it causes the processor 502 to perform a global color block detection method suitable for template color features.

[0101] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0102] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a global color block detection method applicable to template color features.

[0103] This network interface 505 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device 500 to which the present invention is applied. The specific computer device 500 may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0104] The processor 502 is used to run a computer program 5032 stored in a memory to implement the global color block detection method based on template color features disclosed in the embodiments of the present invention.

[0105] Those skilled in the art will understand that Figure 4 The embodiments of the computer device shown do not constitute a limitation on the specific configuration of the computer device. In other embodiments, the computer device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. For example, in some embodiments, the computer device may include only memory and a processor. In such embodiments, the structure and function of the memory and processor are different from those shown. Figure 4 The embodiments shown are consistent and will not be repeated here.

[0106] It should be understood that, in this embodiment of the invention, the processor 502 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0107] In another embodiment of the invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when executed by a processor, the computer program implements the global color patch detection method based on template color features disclosed in the embodiments of the invention.

[0108] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.

[0109] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, or it may be an electrical, mechanical, or other form of connection.

[0110] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0111] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

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

[0113] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the claims of the present invention.

Claims

1. A global color block detection method based on template color features, characterized in that: The method includes: After detecting the region of interest in the reference image, at least a portion of the region of interest is obtained as the effective feature extraction region; the effective feature extraction region is converted to the HSV color space and the corresponding template color feature vector is constructed. A three-channel differential adaptive tolerance range is constructed based on the template color feature vector and combined with the preset color difference tolerance coefficient; The image to be inspected is downsampled to obtain the final low-resolution image. The final low-resolution image is converted to the HSV color space and three-channel joint thresholding is performed based on the three-channel differential adaptive tolerance range to obtain a color patch binarized mask image. The size of the morphological opening operation kernel is adaptively determined based on the size parameter of the region of interest. The adaptive kernel is used to perform morphological opening operation on the color block binarized mask image to obtain a pure mask image that retains the complete outline of the effective target color block. The target contour is obtained by contour processing of the clean mask image, and the minimum bounding rotation rectangle is solved for the target contour to obtain the target color block box on the final low-resolution image. The parameter information of the target color block bounding box is restored to the original image to be inspected. Based on the restored target color block bounding box, the target color block is judged according to the selected color block existence judgment rule, and the corresponding detection result is output.

2. The global color block detection method based on template color features according to claim 1, characterized in that: After detecting the region of interest in the reference image, at least a portion of the region of interest is extracted as the effective feature extraction region, including: After detecting the region of interest in the reference image, the cropping ratio of the region of interest is obtained; Based on the obtained truncation ratio, at least a portion of the region of interest is truncated as the effective feature extraction region; When the shortest side length of the effective feature extraction region meets the preset cancellation condition, the complete region of interest is directly selected as the effective feature extraction region.

3. The global color block detection method based on template color features according to claim 1, characterized in that: After using the average values ​​of H, S, and V as the template color feature vector, and before constructing a three-channel differential adaptive tolerance range based on the template color feature vector and a preset color difference tolerance coefficient, the method further includes: Calculate the HSV space Euclidean distance between the HSV features of each pixel within the effective feature extraction region and the template color feature vector; The standard deviation of the Euclidean distance distribution is calculated based on the Euclidean distance of each pixel, and used as the confidence index of the template feature. When the template feature confidence index is less than or equal to the preset threshold, proceed to the next step; When the template feature confidence index is greater than the preset threshold, a prompt message indicating insufficient uniformity of the region of interest is output.

4. The global color block detection method based on template color features according to claim 3, characterized in that: Based on the template color feature vector and combined with a preset color difference tolerance coefficient, a three-channel differential adaptive tolerance range is constructed, including: Obtain the template feature confidence index; The preset color difference tolerance coefficient is dynamically adjusted according to the template feature confidence index to obtain the adjusted color difference tolerance coefficient. The value of the adjusted color difference tolerance coefficient is inversely related to the value of the template feature confidence index. Based on the template color feature vector and the adjusted color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S, and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

5. The global color block detection method based on template color features according to claim 4, characterized in that: The reverse association specifically refers to: Preset color difference tolerance coefficient and reference standard deviation; The preset color difference tolerance coefficient is positively adjusted based on the relative ratio of the template feature confidence index to the reference standard deviation; wherein, the larger the value of the template feature confidence index, the larger the adjustment range of the preset color difference tolerance coefficient, and vice versa.

6. The global color block detection method based on template color features according to any one of claims 1 or 3, characterized in that: Based on the template color feature vector and combined with a preset color difference tolerance coefficient, a three-channel differential adaptive tolerance range is constructed, including: Based on the template color feature vector and the preset color difference tolerance coefficient, differentiated adaptive tolerance ranges are constructed for the H, S and V channels respectively; among them, the S channel is set with a larger color difference tolerance than the other channels.

7. The global color block detection method based on template color features according to claim 1, characterized in that: The downsampling process is executed by calling the embedded platform's built-in RGA raster graphics accelerator hardware.

8. The global color block detection method based on template color features according to claim 1, characterized in that: The size of the structure kernel for morphological opening operations is adaptively determined based on the size parameters of the region of interest, including: Get the shortest side length of the region of interest; The basic dimensions of the structural kernel for morphological opening operations are calculated based on the shortest side length of the region of interest and a preset scaling ratio. The base size is compared with a preset lower limit threshold size. If the basic size is smaller than the lower size threshold, then the final size of the structural core is set to the lower size threshold. If the basic size is greater than or equal to the lower limit threshold of the size, then the final size of the structural core is set to the basic size.

9. The global color block detection method based on template color features according to claim 1, characterized in that: Restore the parameter information of the target color block bounding box to the original image to be inspected, including: Obtain the total downsampling factor of the downsampling process; The pixel coordinates, width, and height of the target color block box on the final low-resolution image are multiplied by the total downsampling factor and mapped to the pixel coordinate system of the original image to be inspected. The rotation angle of the target color block remains unchanged before and after the restoration.

10. The global color block detection method based on template color features according to claim 1, characterized in that: The rules for determining the existence of color blocks include any one or more of the following: basic existence determination, relative area deviation determination, absolute area range determination, and limited area existence determination.