Color detection method and electronic device
By employing the HSV color space and Halcon algorithm in light color detection, the subjectivity of manual visual inspection and the shortcomings of traditional machine vision methods are overcome, achieving efficient and accurate automatic light color detection that adapts to different detection tasks and environmental changes.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QUECTEL TELECOM TECH CHANGZHOU CO LTD
- Filing Date
- 2026-02-10
- Publication Date
- 2026-06-09
AI Technical Summary
Current light color detection mainly relies on manual visual inspection, which is easily affected by the subjective state of the inspector, resulting in a high error rate and low efficiency. Furthermore, traditional machine vision methods are insufficient in distinguishing between ambient light interference and color differences, have poor adaptability, and are difficult to meet the high efficiency and high precision requirements of industrial production.
The HSV color space is used instead of the RGB color space. The image is converted from RGB to HSV using the Halcon algorithm. By utilizing the brightness and color separation characteristics of the HSV color space, combined with morphological operations and threshold segmentation, the target color region is extracted and compared with standard color data to achieve automated detection.
It improves the accuracy and efficiency of light color detection, effectively resists changes in lighting and interference from complex backgrounds, accurately distinguishes subtle color differences, has high adaptability, and meets the high efficiency and high precision requirements of industrial automation.
Smart Images

Figure CN122175878A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, specifically to a color detection method and electronic device. Background Technology
[0002] In the fields of industrial automation and intelligent manufacturing, lighting quality testing of lamps is a crucial step in ensuring the pass rate of products leaving the factory. Lighting quality testing includes light color testing. Currently, light color testing is typically conducted manually by visual inspection, whereby inspectors visually check whether the emitted color of the lamps is normal.
[0003] However, manual visual inspection is easily affected by the subjective state of the inspector (such as fatigue), resulting in a high error rate and low efficiency in light color detection. Summary of the Invention
[0004] This application provides a color detection method and electronic device to improve detection accuracy and efficiency.
[0005] On one hand, embodiments of this application provide a color detection method applied to electronic devices, the method comprising:
[0006] Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
[0007] In some embodiments, the standard color data includes standard feature parameters and standard color values; The step of comparing the target color region with standard color data to obtain the color detection result corresponding to the object to be detected includes: Determine the feature parameters of the target color region; The color detection result is obtained by comparing the feature parameters of the target color region with the standard feature parameters and comparing the color value of the target color region with the standard color value.
[0008] In some embodiments, the feature parameters include one or more of the location, area, and contour information of the target color region; The color detection result is either a normal color result or a color abnormal result; wherein, the color abnormal result includes abnormal location and / or abnormal color.
[0009] In some embodiments, determining the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected includes: Based on the HSV color space values of the first image, the initial color region in the first image is extracted; The initial color region is optimized to obtain the target color region.
[0010] In some embodiments, extracting the initial color region from the first image based on the HSV color space values of the first image includes: If the HSV color space value of a pixel in the first image meets the preset emission conditions, the pixel is determined as a pixel in the initial color region. The preset light emission conditions include at least one of the following conditions: The H value of the pixel is within the first threshold range; The S value of the pixel is within the second threshold range; The V value of the pixel is within the third threshold range.
[0011] In some embodiments, the preset luminescence conditions are related to the detection scenario of the object to be detected; When the detection scenario indicates the detection color type, the preset illumination condition includes at least the H value of the pixel being within a first threshold range; When the detection scenario indicates the detection of color purity, the preset light emission condition includes at least the S value of the pixel being within a first threshold range; When the detection scene indicates a reflective scene, the preset luminescence condition includes at least the V value of the pixel being within a third threshold range.
[0012] In some embodiments, before extracting the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected, the method further includes: The color space of the second image corresponding to the object to be detected is converted from RGB to HSV to obtain the first image; wherein, the second image is obtained by taking a picture of the object to be detected when the object to be detected is emitting light.
[0013] In some embodiments, converting the color space of the second image corresponding to the object to be detected from RGB to HSV includes: The Halcon algorithm is used to convert the color space of the second image corresponding to the object to be detected from RGB to HSV.
[0014] On the other hand, embodiments of this application also provide a color detection device, the device comprising: The region determination module is configured to determine the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The color detection module is configured to compare the target color region with standard color data to obtain the color detection result corresponding to the object to be detected.
[0015] On the other hand, embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps: Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
[0016] On the other hand, embodiments of this application also provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in any color detection method provided in embodiments of this application.
[0017] On the other hand, embodiments of this application also provide a computer-readable storage medium storing a computer program or instructions thereon, including a computer program or instructions that, when executed by a processor, implement the steps in any color detection method provided in embodiments of this application.
[0018] The color detection method provided in this application acquires a first image. The first image is obtained by capturing the object being detected emitting light, meaning the first image includes the object's emission status. Using the HSV color space values of the first image corresponding to the object, a target color region is determined—that is, the region capable of displaying the emission color of the object. Then, the target color region is compared with standard color data to determine whether it conforms to the standard, i.e., whether the emission color of the object conforms to the standard. This yields the color detection result corresponding to the object, enabling automatic detection of the object's emission color, improving emission color detection efficiency, and eliminating the need for manual visual inspection, thus avoiding the influence of subjective human factors and ensuring accurate color detection results. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a schematic diagram of an HSV color space provided in the embodiments of this application; Figure 2 This is a flowchart illustrating a color detection method provided in an embodiment of this application; Figure 3 This is a schematic diagram of a light-emitting image provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a color detection device provided in the embodiments of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] In the following description, specific embodiments of the invention will be illustrated with reference to steps and symbols performed by one or more computers, unless otherwise stated. Therefore, these steps and operations will be referred to several times as being performed by a computer, and computer execution as referred to herein includes operations by a computer processing unit representing electronic signals of data in a structured format. This operation transforms the data or maintains it at a location in the computer's memory system, which can be reconfigured or otherwise alter the operation of the computer in a manner well known to those skilled in the art. The data structure maintained by the data is the physical location of the memory, which has specific characteristics defined by the data format. However, the principles of the invention described above are not intended to be limiting, and those skilled in the art will understand that many of the steps and operations described below can also be implemented in hardware.
[0023] The terms "module" or "unit" as used herein can be considered as software objects executing on the computing system. The various components, modules, engines, and services described herein can be considered as implementations on the computing system. While the apparatus and methods described herein are preferably implemented in software, they can also be implemented in hardware, both of which are within the scope of this invention.
[0024] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when an element is “connected” or “coupled” to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein may include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0025] In the fields of industrial automation and intelligent manufacturing, quality inspection is a crucial step in ensuring the pass rate of products leaving the factory. Quality inspection includes color inspection. Taking a product that emits light as an example, color inspection can include detecting the color of light emitted by the object, such as the color of light emitted by a light-emitting diode (LED).
[0026] In some embodiments, color detection methods primarily rely on manual visual inspection. This method is not only inefficient and labor-intensive, but also highly susceptible to the subjective state of the inspectors (such as fatigue and emotional fluctuations) and changes in ambient light, leading to inconsistent inspection standards, poor stability, and high rates of missed and false detections. It is difficult to meet the high efficiency and accuracy requirements of high-speed production lines. With the development of machine vision technology, using industrial cameras and image processing algorithms to replace the human eye has become the mainstream solution. Therefore, some machine vision inspection methods based on simple threshold segmentation or fixed color spaces exist. However, these methods still have the following significant limitations in practical industrial applications: Sensitive to ambient light interference: The lighting conditions in industrial production sites are difficult to keep absolutely stable. Even slight changes in lighting (such as intensity, angle, and color temperature) can cause significant deviations in the collected product color information, resulting in poor robustness of the simple color threshold method and easy misjudgment due to ambient light interference.
[0027] Insufficient color differentiation capability: For scenarios with small color differences but strict quality requirements (such as color difference detection of high-end textiles and color consistency inspection of different batches of products), traditional color space models such as RGB are difficult to effectively differentiate and quantify.
[0028] Poor adaptability: When the object to be inspected (or the product to be inspected) has multiple color variations, or when the production line products need to be changed frequently, traditional inspection methods often require manual adjustment of a large number of parameters (such as color threshold, region of interest, etc.), the debugging process is cumbersome, lacks adaptability, and cannot quickly respond to the needs of flexible manufacturing.
[0029] Weak anti-interference ability: The surface of the object to be detected may have interference factors such as reflection, overexposure, and texture. Simple color matching algorithms can easily mistake these interferences for color defects, leading to an increased false detection rate.
[0030] Therefore, to address the aforementioned problems, this application provides a color detection method that overcomes the above-mentioned defects. This method is based on Halcon and utilizes the HSV (Hue Saturation Value) color space (e.g., ...). Figure 1 Color detection is achieved using the HSV color space model shown. Specifically, by converting the image corresponding to the object to be detected from the light-sensitive RGB color space to the more visually perceptual HSV color space, and by specifically utilizing the characteristics of the HSV channels, brightness and color information are effectively separated. This effectively resists changes in lighting and interference from complex backgrounds, while also possessing high precision, accurately distinguishing subtle color differences, and quickly adapting to different detection tasks. This meets the requirements of high efficiency, high precision, and high stability in industrial automation testing, and also exhibits high adaptability.
[0031] The following example, using the scenario where the object to be detected is a luminous object and the detection task is luminous color detection (i.e., detecting the luminous color of the object), details the color detection method described above. Figure 2 As shown, the color detection method may include: S201. Based on the HSV color space value of the first image corresponding to the object to be detected, the electronic device determines the target color region in the first image; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light.
[0032] In this embodiment, the electronic device acquires a first image corresponding to the object to be detected, and the color space of the first image is HSV. The image content of the first image is obtained by capturing the object to be detected while it is emitting light; that is, the first image can reflect the emitting state of the object to be detected (e.g., ...). Figure 3 (As shown).
[0033] Given that the RGB color space is based on additive color mixing of three primary colors, where the R, G, and B components are all tightly coupled with luminance information, changes in light intensity will simultaneously alter the values of all three components, making color recognition methods based on absolute RGB values extremely unstable. In contrast, the HSV color space is more in line with human subjective perception, using H, S, and V components to describe color. This provides a theoretical basis for solving the light sensitivity problem mentioned in the background technology.
[0034] Here, H refers to hue, which indicates the type of color (such as red, yellow, and blue), and is the most essential attribute of color. S refers to saturation, which indicates the purity or vividness of a color. V refers to lightness or darkness, which indicates the brightness or darkness of a color.
[0035] Furthermore, the HSV color space (such as the H and S components (or channels, spatial values, or values, etc.)) is largely independent of lighting conditions. This means that even if changes in lighting cause changes in the brightness of an image, the changes in lighting only alter the total intensity of the light, but do not change the proportion of light wavelengths, thus the essence (hue) and vividness (saturation) of the colors remain essentially unchanged.
[0036] Based on this, electronic devices use the HSV color space values of pixels in the first image (which is HSV) to determine the target color region. They extract color regions that can reflect the luminescence of the object to be detected from complex backgrounds. Since HSV is less sensitive to light, the accuracy of color region recognition is guaranteed, thus ensuring the accuracy and speed of target color region extraction.
[0037] In some embodiments, the first image may be obtained through color space conversion. The electronic device converts the color space of the second image corresponding to the object to be detected from RGB to HSV to obtain the first image; wherein, the second image is obtained by photographing the object to be detected when the object emits light.
[0038] In this embodiment, a camera device (such as an industrial camera) captures a second image of the object under test when it emits light, and then transmits the second image to an electronic device. This second image can represent the emitting state of the object under test. For example, the second image is a color image of the object under test captured by the industrial camera under set lighting conditions (such as a ring light source or a coaxial light source). Since the color space of a generally captured image is RGB, the electronic device can convert the color space of the second image from RGB to HSV, and the second image with the HSV color space can be used as the first image.
[0039] Optionally, the electronic device can employ the Halcon algorithm to convert the color space of the second image corresponding to the object to be detected from RGB to HSV, thereby achieving color space conversion. For example, the electronic device can utilize the trans_from_rgb operator or the decompose3 method combined with a transformation matrix provided by the Halcon vision library (or the Halcon algorithm) to convert the acquired RGB color image into an image in the HSV color space. Furthermore, the electronic device outputs three single-channel images, corresponding to the H (hue), S (saturation), and V (brightness) components, respectively.
[0040] Specifically, the conversion principle and formula from RGB to HSV are as follows: Assume the values of R, G, and B are all normalized to the interval [0, 1], MAX is the maximum value among R, G, and B, and MIN is the minimum value among them. The conversion formula is as follows: Calculate the V (color value) component: V = MAX.
[0041] Calculate the S (saturation) component: When MAX = 0, it represents black, so S = 0; when MAX ≠ 0, S = (MAX - MIN) / MAX.
[0042] Calculate the H (hue) component: When MAX = MIN, H = 0 (representing gray or colorless).
[0043] Otherwise, the formula for calculating H is as follows, and the calculation result needs to be adjusted to the range of [0°, 360°] according to the conditions: If MAX = R: .
[0044] If MAX = G: .
[0045] If MAX = B: .
[0046] If H < 0: .
[0047] In some embodiments, to ensure the accuracy of color detection, after obtaining the second image, the electronic device can perform image preprocessing on the second image, and then convert the preprocessed second image from RGB to HSV. The image preprocessing may include Gaussian filtering or median filtering to suppress noise interference and provide a high-quality source image for color space conversion.
[0048] It should be noted that electronic devices can determine the first image through the second image, or they can directly receive the first image transmitted by other devices; this application does not limit this.
[0049] The process of determining the first image has been described above. The process of determining the target color region will be described below.
[0050] In some embodiments, the electronic device can extract an initial color region from the first image based on the HSV color space values of the first image. Then, the electronic device can optimize the initial color region to obtain a target color region. In this embodiment, the electronic device can use HSV color space values to segment the first image to extract regions including the emission characteristics of the object to be detected from a complex background, thus obtaining an initial color region. The number of initial color regions can be one or more. Subsequently, the electronic device can use morphological operations of the Halcon algorithm (such as connected component analysis and shape selection) for optimization to ensure the accuracy of the color region extraction.
[0051] Optionally, the electronic device may use HSV color space values (or alternatively described as HSV channels) for thresholding to obtain an initial color region. If the HSV color space value of a pixel in the first image satisfies a preset emission condition, the electronic device determines that pixel as a pixel in the initial color region; wherein the preset emission condition includes at least one of the following: The H value of the pixel is within the first threshold range; The S-value of the pixel is within the second threshold range; The V value of the pixel is within the third threshold range.
[0052] In addition, if the HSV color space value of a pixel does not meet the preset emission conditions, the electronic device will not use that pixel as a pixel in the initial color area.
[0053] In this embodiment of the application, by adopting the HSV color space and focusing on the analysis of H, S, and V values, the sensitivity of RGB to light intensity is effectively overcome, ensuring the accuracy of the determination of the luminous color area and the accuracy of color detection.
[0054] In some embodiments, the electronic device may selectively choose channels and perform threshold segmentation using the selected channels based on the detection scenario (or alternatively described as the detection task). For example, the preset illumination conditions described above are related to the detection scenario of the object to be detected.
[0055] When the detection scene indicates the type of color to be detected, the preset illumination conditions include at least that the H value of the pixel is within a first threshold range. That is, when the detection task is a color discrimination task, since the H component is not sensitive to illumination, threshold segmentation can be primarily based on the H component. Furthermore, it is understood that the preset illumination conditions may also include other conditions, such as that the S value of the pixel is within the first threshold range.
[0056] When the detection scenario indicates the detection of color purity, the preset illumination conditions include at least that the S-value of the pixel is within a first threshold range. That is, when the detection task is color purity, uneven saturation often indicates contamination or process problems, thus affecting color purity. Therefore, threshold segmentation can be performed based on the S-component. Similarly, the preset illumination conditions can also include other conditions.
[0057] When detecting a reflective scene, the preset illumination conditions include at least that the V value of the pixel is within a third threshold range. That is, when the object to be detected emits light, the detection area of the object will be highly reflective, and correspondingly, the V value will be high. Therefore, a specific area can be located by the brightness difference of the V channel, thereby achieving threshold segmentation. Similarly, the preset illumination conditions can also include other conditions, such as the H value of the pixel being within a first threshold range and the S value of the pixel being within a second threshold range. In this way, the electronic device can use the V value for initial positioning, and then use the H and S channels for precise color recognition within the area obtained from the initial positioning.
[0058] It should be noted that the specific conditions included in the above-mentioned preset illumination conditions can be configured by the user according to the detection scenario, or automatically set by the electronic device according to the retrieval scenario. For example, under high reflectivity, the electronic device can determine whether the RGB channel values corresponding to the average grayscale value of the first image meet the standard. If all channel values meet the standard, it means that the target color area can be accurately determined using the V value. In this case, the preset illumination conditions can include the V value of the pixel being within the third threshold range. If some channel values do not meet the standard, it means that the color cannot be accurately identified using the V value, and the target color area needs to be determined by combining the H value and S value. In this case, the preset illumination conditions can include the V value of the pixel being within the third threshold range, the H value of the pixel being within the first threshold range, and the S value of the pixel being within the second threshold range.
[0059] Specifically, for each channel corresponding to RGB, if the channel value is within the specified threshold range corresponding to that channel, then the channel value conforms to the standard.
[0060] In some embodiments, the target color region can be implemented using the Halcon algorithm. In the Halcon algorithm, the threshold operator is used to segment the selected H, S, and V component images. For example: threshold(H_Image, Regions, MinHue, MaxHue). Threshold segmentation is performed by setting the minimum and maximum hue values (MinHue and MaxHue) corresponding to the target color.
[0061] S202. The electronic device compares the target color area with the standard color data to obtain the color detection result corresponding to the object to be detected.
[0062] The standard color data indicates the acceptance criteria. Optionally, the standard color data may include standard characteristic parameters and / or standard color values.
[0063] The above color detection results are either normal or abnormal; wherein, the abnormal color results include abnormal location (i.e., the location where the defect occurs) and / or abnormal color.
[0064] In this embodiment of the application, after determining the target color region in the first image, the electronic device compares the target color region with standard color data to determine whether the emission of the object to be detected meets the standard, that is, to determine whether the emission color of the object to be detected meets the requirements, thereby realizing the automated detection of the color of the object to be detected and improving the efficiency of emission color detection.
[0065] Taking standard color data, which includes standard feature parameters and standard color values, as an example, the process of obtaining the color detection result corresponding to the object to be detected can include: the electronic device determining the feature parameters of the target color region; then, the electronic device comparing the feature parameters of the target color region with the standard feature parameters to determine whether the feature parameters of the target color region match the standard feature parameters; and comparing the color value of the target color region with the standard color value to determine whether the feature parameters of the target color region match the standard feature parameters, thus obtaining the color detection result.
[0066] For example, when the feature parameters of the target color region do not match the standard feature parameters, it indicates that the actual emission color position of the object to be detected is incorrect, and the electronic device can determine that the color detection result is an abnormal color result. Specifically, abnormal color results include abnormal positions. For example, red should be located at position 1, but is actually located at position 2.
[0067] When the color value of the target color area does not match the standard color value, it indicates that the actual emitted color of the object being detected is incorrect, and the electronic device can determine that the color detection result is an abnormal color result. Specifically, an abnormal color result includes abnormal colors. For example, the emitted color should include a certain color type, but it does not actually exist.
[0068] In addition, when the feature parameters of the target color region match the standard feature parameters, and the color value of the target color region matches the standard color value, the electronic device can determine that the color detection result is a normal color result.
[0069] Optionally, if the difference between the feature parameters of the target color region and the standard feature parameters is large (i.e., the difference exceeds the preset feature difference value), it indicates that the feature parameters of the target color region do not match the standard feature parameters. Conversely, if the difference between the feature parameters of the target color region and the standard feature parameters is small, it indicates that the feature parameters of the target color region match the standard feature parameters.
[0070] Similarly, when the color value of the target color region differs significantly from the standard color value (i.e., the difference exceeds a preset color difference value), it indicates that the color value of the target color region does not match the standard color value. Conversely, when the color value of the target color region differs slightly from the standard color value, it indicates that the color value of the target color region matches the standard color value. Specifically, a significant difference between the color value of the target color region and the standard color value can mean that the color values of a large number (exceeding a specified value) of pixels in the target color region differ significantly from the standard color value, or that the color value of the target color region is the average color value.
[0071] Optionally, the aforementioned color values can be RGB channel values (or RGB color space values), such as the RGB channel values corresponding to the average grayscale value mentioned above. Alternatively, they can be other types of color values, such as grayscale values, H values, etc.
[0072] Furthermore, when the color values of the target color region include multiple channel values, if there is a significant difference between any channel value and its corresponding standard color value, it can be determined that the color values of the target color region differ significantly from the standard color values. Conversely, if the differences between all channel values and their corresponding standard color values are small, it can be determined that the color values of the target color region differ slightly from the standard color values.
[0073] In some embodiments, the feature parameters of the target color region are obtained through localization. The feature parameters include one or more parameters among the location, area, and contour information of the target color region. Contour information may refer to contour location. Accordingly, when there is a significant difference between a parameter and its corresponding standard feature parameter, it can be determined that the feature parameters of the target color region differ significantly from the standard feature parameters.
[0074] In this embodiment, by replacing RGB with the HSV color space and combining it with Halcon's powerful machine vision library, a more adaptable industrial automation color detection method is constructed that can effectively resist illumination interference, accurately identify subtle color features, and is more resilient. Specifically, this color detection method can solve the following problems: Addressing the issue of sensitivity to changes in lighting: This application overcomes the instability of color characteristics caused by variations in light intensity and angle in RGB color recognition algorithms. In the RGB color space, luminance and color information are highly coupled; even minor fluctuations in lighting can cause drastic changes in the R, G, and B component values, leading to false detections. This application separates luminance and color information to improve the stability of the detection system under complex lighting conditions.
[0075] This application addresses the issue of insufficient ability to distinguish subtle color differences in the RGB color space: the RGB color space does not conform to human color perception habits, resulting in poor performance when calculating color similarity. It employs the HSV color space, which is closer to human visual perception, and can better represent the essential attributes of colors such as hue, saturation, and value, improving the accuracy of color differentiation and recognition, thereby achieving more precise color matching and more sensitive color difference detection.
[0076] Addressing the issue of poor adaptability: This application reduces sensitivity to non-target factors (such as brightness changes and slight surface reflections) by optimizing the selection and processing strategy of color space, thereby reducing misjudgments. This enables the application to maintain high detection stability when switching between different objects to be detected or encountering slight interference, reducing the complexity of debugging and maintenance, eliminating the need for frequent manual parameter adjustments, improving the ability to resist interference (such as reflections and textures), and enhancing adaptability.
[0077] To facilitate better implementation of the color detection method provided in this application, this application also provides a color detection device based on the above-described color detection method. The meanings of the terms used are the same as in the color detection method described above, and specific implementation details can be found in the descriptions within the method embodiments.
[0078] Figure 4 This is a schematic diagram of the structure of a color detection device provided in an embodiment of this application. Please refer to... Figure 4 This color detection device has the functionality to implement the method example described above on the electronic device side. This functionality can be implemented in hardware or by hardware executing corresponding software. The color detection device can be the electronic device described above, or it can be installed within an electronic device. For example... Figure 4 As shown, the color detection device 400 may include: a region determination module 410 and a color detection module 420.
[0079] The region determination module 410 is configured to determine a target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object emits light; The color detection module 420 is configured to compare the target color region with standard color data to obtain the color detection result corresponding to the object to be detected.
[0080] Figure 5 This is a schematic diagram of the structure of an electronic device provided in some embodiments of this application. Figure 5 The dashed line in the text indicates that the unit or module is optional. Figure 5 The electronic device 700 can be used to implement the methods described in the above method embodiments. The electronic device 700 can be a chip, a terminal device, or a first server.
[0081] Electronic device 700 may include one or more processors 710. The processor 710 can support the electronic device 700 in implementing the methods described in the preceding method embodiments. The processor 710 may be a general-purpose processor or a special-purpose processor. For example, the processor may be a Central Processing Unit (CPU). Alternatively, the processor 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.
[0082] The electronic device 700 may also include one or more memories 720. Computer programs are stored on the memories 720. The memories 720 may be independent of the processor 710 or integrated into the processor 710.
[0083] The electronic device 700 may also include a transceiver 730. The processor 710 can communicate with other devices or chips via the transceiver 730. For example, the processor 710 can send and receive data with other devices or chips via the transceiver 730.
[0084] The computer program in memory 720 can be executed by processor 710, causing processor 710 to perform the following steps: Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
[0085] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0086] Therefore, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, the computer program being loaded by a processor to execute the steps described in the above-described method embodiments of this application. For example, the computer program, when loaded by a processor, can execute the following steps: Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
[0087] For details on the implementation of each of the above operations / steps, please refer to the previous examples, which will not be repeated here.
[0088] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0089] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the above method embodiments provided in the embodiments of this application, the beneficial effects that the methods described in any of the above method embodiments can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.
[0090] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.
[0091] The above provides a detailed description of a color detection method and electronic device provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A color detection method characterized by, include: Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
2. The method of claim 1, wherein, The standard color data includes standard feature parameters and standard color values; The step of comparing the target color region with standard color data to obtain the color detection result corresponding to the object to be detected includes: Determine the feature parameters of the target color region; The color detection result is obtained by comparing the feature parameters of the target color region with the standard feature parameters and comparing the color value of the target color region with the standard color value.
3. The method of claim 2, wherein, The feature parameters include one or more of the location, area, and contour information of the target color region; The color detection result is either a normal color result or a color abnormal result; wherein, the color abnormal result includes abnormal location and / or abnormal color.
4. The method according to any one of claims 1 to 3, characterized in that, The step of determining the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected includes: Based on the HSV color space values of the first image, the initial color region in the first image is extracted; The initial color region is optimized to obtain the target color region.
5. The method of claim 4, wherein, The step of extracting the initial color region from the first image based on the HSV color space values of the first image includes: If the HSV color space value of a pixel in the first image meets the preset emission conditions, the pixel is determined as a pixel in the initial color region. The preset light emission conditions include at least one of the following conditions: The H value of the pixel is within the first threshold range; The S value of the pixel is within the second threshold range; The V value of the pixel is within the third threshold range.
6. The method of claim 5, wherein, The preset luminescence conditions are related to the detection scenario of the object to be detected; When the detection scenario indicates the detection color type, the preset illumination condition includes at least the H value of the pixel being within a first threshold range; When the detection scenario indicates the detection of color purity, the preset light emission condition includes at least the S value of the pixel being within a first threshold range; When the detection scene indicates a reflective scene, the preset luminescence condition includes at least the V value of the pixel being within a third threshold range.
7. The method according to any one of claims 1 to 3, characterized in that, Before extracting the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected, the method further includes: The color space of the second image corresponding to the object to be detected is converted from RGB to HSV to obtain the first image; wherein, the second image is obtained by taking a picture of the object to be detected when the object to be detected is emitting light.
8. The method according to claim 7, characterized in that, The step of converting the color space of the second image corresponding to the object to be detected from RGB to HSV includes: The Halcon algorithm is used to convert the color space of the second image corresponding to the object to be detected from RGB to HSV.
9. A color detection device, characterized in that, The device includes: The region determination module is configured to determine the target color region in the first image based on the HSV color space values of the first image corresponding to the object to be detected; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The color detection module is configured to compare the target color region with standard color data to obtain the color detection result corresponding to the object to be detected.
10. An electronic device, characterized in that, It includes a memory and a processor, wherein the memory stores computer programs or instructions, and when the computer programs or instructions are executed by the processor, the processor causes the processor to perform the following steps: Based on the HSV color space values of the first image corresponding to the object to be detected, the target color region in the first image is determined; wherein, the image content of the first image is obtained by taking a picture of the object to be detected when the object to be detected emits light; The target color region is compared with standard color data to obtain the color detection result corresponding to the object to be detected.
11. A computer-readable storage medium, characterized in that, It stores a computer program or instructions that, when executed by a processor, implement the steps of the color detection method as described in any one of claims 1 to 8.