Image recognition method and device, electronic equipment and storage medium

By performing color quantization and block processing on images, identifying image types, and employing appropriate compression coding methods, the accuracy problem of image classification compression is solved, achieving more efficient bandwidth utilization and cost control.

CN119520799BActive Publication Date: 2026-05-19HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD
Filing Date
2023-08-18
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

In existing technologies, image recognition methods cannot classify and partition images, which makes it impossible to achieve classification compression, resulting in increased bandwidth and costs.

Method used

The image to be identified is divided into multiple macroblocks by color quantization, and the image type is identified based on the number of quantized colors and the number of original colors in the macroblock. Different compression encoding methods are used to process text blocks and image blocks.

Benefits of technology

It improves the accuracy of image recognition, enables better control over the display quality of different areas and the size of compressed data, and avoids increased bandwidth and costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119520799B_ABST
    Figure CN119520799B_ABST
Patent Text Reader

Abstract

The application provides an image recognition method and device, electronic equipment and storage medium, and relates to the technical field of image processing. The method comprises the following steps: performing color quantization processing on a to-be-recognized image to obtain a respective quantized color value corresponding to each pixel; dividing the to-be-recognized image into a plurality of macroblocks, determining a respective quantized color quantity corresponding to each macroblock based on the respective quantized color value corresponding to each pixel in the macroblock; and identifying an image type corresponding to each macroblock based on the respective quantized color quantity corresponding to each macroblock and the original color quantity corresponding to each macroblock, wherein the image type is used to represent whether the macroblock is a text block. In the embodiment, the text block and the non-text block can be identified from the image, and the recognition accuracy is high. Furthermore, different compression encoding modes can be used for the text block and the non-text block, so that the display quality and the data size after compression of different regions can be better controlled, and the problems of increased bandwidth and increased bandwidth cost can be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image recognition method, apparatus, electronic device and storage medium. Background Technology

[0002] Cloud desktops utilize cloud computing to place computing and storage in the cloud, providing a virtual desktop service. They offer advantages such as centralized management, security, reliability, cost savings, and energy efficiency. Users can overcome the limitations of time, location, terminal, and application, accessing cloud desktops for work anytime, anywhere. Since cloud desktops run in the cloud, updated desktop content needs to be encoded before being transmitted to the terminal for display. Different encoding methods determine the display quality and the required network bandwidth. To achieve a balance between display quality and network bandwidth, different areas of the updated screen can be encoded and compressed differently based on content type. For example, lossy compression encoding is used for image areas to save bandwidth, while lossless compression encoding is used for text areas to achieve clear display.

[0003] In related technologies, the smoothness of the entire image to be encoded is calculated, and the image type is determined based on the smoothness. Regardless of size, the image is classified as a single type. If an image contains multiple types of content, it cannot be accurately categorized and distinguished. This results in the method's inability to precisely classify and compress images. Therefore, an image can only be compressed using one encoding method, and the display quality of different areas of an image and the size of the compressed data cannot be precisely controlled, leading to increased bandwidth and bandwidth costs. Summary of the Invention

[0004] This application provides an image recognition method, apparatus, electronic device, and storage medium to solve the problem that images cannot be classified and partitioned, thus making it impossible to achieve classified compression.

[0005] In a first aspect, embodiments of this application provide an image recognition method, the method comprising: performing color quantization processing on an image to be recognized to obtain quantized color values ​​corresponding to each pixel; dividing the image to be recognized into multiple macroblocks, and determining the number of quantized colors corresponding to each macroblock based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks; and identifying the image type corresponding to each macroblock based on the number of quantized colors corresponding to each macroblock and the number of original colors corresponding to each macroblock, wherein the image type is used to characterize whether the macroblock is a text block.

[0006] Secondly, embodiments of this application provide an image recognition device, which includes: a processing module, configured to perform color quantization processing on an image to be recognized to obtain quantized color values ​​corresponding to each pixel; a determining module, configured to divide the image to be recognized into multiple macroblocks, and determine the number of quantized colors corresponding to each of the multiple macroblocks based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks; and a recognition module, configured to recognize the image type corresponding to each of the multiple macroblocks based on the number of quantized colors corresponding to each of the multiple macroblocks and the number of original colors corresponding to each of the multiple macroblocks, wherein the image type is used to characterize whether the macroblock is a text block.

[0007] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor implements any of the methods described above when executing the computer program.

[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method described in any of the above-mentioned embodiments.

[0009] Compared with the prior art, this application has the following advantages:

[0010] This application provides an image recognition method, apparatus, electronic device, and storage medium. First, the image to be recognized is subjected to color quantization processing to obtain the quantized color value corresponding to each pixel. Second, the image to be recognized is divided into multiple macroblocks. Based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks, the number of quantized colors corresponding to each macroblock is determined. Finally, based on the number of quantized colors and the number of original colors corresponding to each macroblock, the image type corresponding to each macroblock is identified. The image type is used to characterize whether the macroblock is a text block. In this embodiment, by dividing the image to be recognized into multiple macroblocks and utilizing the number of quantized colors and the number of original colors corresponding to each macroblock, text blocks and non-text blocks are identified from the image with high accuracy. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality of different areas and the size of the compressed data, avoiding the problems of increased bandwidth and bandwidth costs.

[0011] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application, it can be implemented according to the contents of the specification. In order to make the above and other objects, features and advantages of this application more obvious and understandable, specific embodiments of this application are given below. Attached Figure Description

[0012] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the various drawings denote the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings depict only some embodiments according to this application and should not be construed as limiting the scope of this application.

[0013] Figure 1 A schematic diagram illustrating an application scenario of the image recognition method provided in this application;

[0014] Figure 2 This is a flowchart of an image recognition method according to an embodiment of this application;

[0015] Figure 3 This is a schematic diagram illustrating an embodiment of the present application of establishing an index based on color values;

[0016] Figure 4 This is a schematic diagram illustrating the storage of color values ​​in an octree according to an index, as per an embodiment of this application.

[0017] Figure 5 This is a flowchart of an image recognition method according to an embodiment of this application;

[0018] Figure 6 This is a structural block diagram of an image recognition device according to an embodiment of this application; and

[0019] Figure 7 This is a block diagram of an electronic device used to implement embodiments of this application. Detailed Implementation

[0020] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the concept or scope of this application. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.

[0021] To facilitate understanding of the technical solutions of the embodiments of this application, the relevant technologies of the embodiments of this application are described below. The following relevant technologies are optional solutions and can be combined with the technical solutions of the embodiments of this application in any way, and all of them fall within the protection scope of the embodiments of this application.

[0022] Figure 1 This is a schematic diagram illustrating an application scenario of the image recognition method provided in this application. For example... Figure 1As shown, in this embodiment, the updated cloud desktop image is used as the cloud desktop image to be identified. The cloud server is used to identify the cloud desktop image, specifically including: First, color quantization processing is performed on the cloud desktop image to obtain the quantized color value corresponding to each pixel in the image; second, the cloud desktop image to be identified is divided into multiple macroblocks, and the number of quantized colors corresponding to each macroblock is determined based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks; finally, based on the number of quantized colors corresponding to each macroblock and the number of original colors corresponding to each macroblock, the image type corresponding to each macroblock is identified from the cloud desktop image to be identified, i.e., whether the macroblock is a text block or an image block. Different compression encoding methods are used for text blocks and image blocks: lossless encoding is performed on text blocks, and lossy compression encoding is performed on image blocks to obtain compressed encoded images. These compressed encoded images are sent to the user terminal through a virtual desktop transmission protocol. The user terminal decodes the text blocks and image blocks using different decoding methods to obtain the cloud desktop image and displays it. The virtual desktop transmission protocol may include the Simple Protocol for Independent Computing Environment (SPICE), etc.

[0023] This application provides an image recognition method. This method can be applied to a computing device, which may include a server, a user terminal, etc. Figure 2 The diagram shown is a flowchart of an image recognition method according to an embodiment of this application, including:

[0024] Step S201: Perform color quantization processing on the image to be recognized to obtain the quantized color value corresponding to each pixel.

[0025] Step S202: Divide the image to be recognized into multiple macroblocks, and determine the number of quantized colors corresponding to each macroblock based on the quantized color values ​​of each pixel in the multiple macroblocks.

[0026] Step S203: Based on the number of quantized colors corresponding to each macroblock and the number of original colors corresponding to each macroblock, identify the image type corresponding to each macroblock. The image type is used to characterize whether the macroblock is a text block.

[0027] Color quantization processing includes reducing the number of colors in the image to be identified, ensuring that the number of colors does not exceed a preset value. For example, the color values ​​of multiple pixels with similar colors in the image are merged into the same color value, thus reducing the number of colors.

[0028] When dividing an image to be recognized, each macroblock can include multiple pixels. The original number of colors corresponding to a macroblock is the number of colors obtained by counting the color values ​​of each pixel in the macroblock before color quantization processing of the image to be recognized. Color values ​​differ in different color spaces; for example, in the RGB space, color values ​​are RGB values. If color values ​​are the same, they are determined to be the same color.

[0029] By comparing the number of quantized colors and the number of original colors corresponding to a macroblock, the image type corresponding to the macroblock is determined, that is, whether the macroblock is a text block or an image block. Different encoding and compression methods are used for text blocks and image blocks respectively. The text blocks are lossless encoded, and the image blocks are lossy compressed encoded to obtain a compressed image that is sent to the user terminal.

[0030] It is understood that the image recognition method in this application is not limited to recognizing cloud desktop images, but can be applied to the encoding and compression of any image including different types of content.

[0031] The image recognition method provided in this embodiment first performs color quantization processing on the image to be recognized to obtain the quantized color value corresponding to each pixel; second, the image to be recognized is divided into multiple macroblocks, and based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks, the number of quantized colors corresponding to each macroblock is determined; finally, based on the number of quantized colors and the number of original colors corresponding to each macroblock, the image type corresponding to each macroblock is identified, and the image type is used to characterize whether the macroblock is a text block. In this embodiment, by dividing the image to be recognized into multiple macroblocks and utilizing the number of quantized colors and the number of original colors corresponding to each macroblock, text blocks and non-text blocks are identified from the image with high recognition accuracy. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality of different areas and the size of the compressed data, avoiding the problems of increased bandwidth and bandwidth costs.

[0032] In one implementation, step S201, which involves color quantization processing of the image to be recognized to obtain the quantized color value corresponding to each pixel, includes: traversing each pixel in the image to be recognized and storing the color value corresponding to each pixel in multiple nodes of an octree; performing quantization processing on the multiple nodes and obtaining the quantized color value corresponding to each pixel based on the color value stored in the processed nodes.

[0033] In practical applications, an octree algorithm is used to store and quantize the color values ​​corresponding to each pixel. Different color spaces have different color values; for example, in the RGB space, the color values ​​are RGB values. Each pixel in the image to be recognized is traversed, and its corresponding color value is stored in an octree and quantized. Pixels with similar colors are grouped together to form a single color value, reducing the number of colors. The color value of each pixel is then queried from the quantized octree.

[0034] In one example, pixels of the image to be recognized are read in a preset order. First, the first K different color values ​​are read. When more than K (where K is a preset number of colors, which can be chosen according to specific needs; in this embodiment, K is 256) new colors appear, colors that are similar and occur less frequently are merged to ensure that the number of colors does not exceed K. An octree is used to select representative colors. Whenever a pixel in the image to be recognized is read, if the number of corresponding colors is less than K, a new leaf node is inserted into the octree. If the number of colors exceeds K, a similar color merging operation is performed on the octree to reduce the number of leaf nodes, ensuring that the number of leaf nodes does not exceed K.

[0035] In one implementation, traversing each pixel in the image to be recognized and storing the color value corresponding to each pixel in multiple nodes of an octree includes: traversing each pixel in the image to be recognized, establishing an index corresponding to each pixel based on the color value corresponding to each pixel, and storing the color value corresponding to each pixel in multiple nodes of an octree based on the index corresponding to each pixel.

[0036] In practical applications, when storing color values ​​in an octree, an index is first created based on the color value corresponding to each pixel. Then, the color value of each pixel is stored in each node according to the index. Creating an index ensures the uniqueness of the data and helps the octree locate the required data more quickly during queries, thereby reducing query time and resource consumption and improving query efficiency.

[0037] The following is combined Figure 3 and Figure 4 The process of storing the color values ​​of each pixel is introduced through a specific embodiment.

[0038] In one example, the octree has eight levels, with eight nodes at each level. Each node stores color information for those who have passed through it. The attribute information of each node is as follows:

[0039]

[0040]

[0041] Insert the color value of each pixel into each node, such as Figure 3 As shown, the RGB value (167, 102, 34) corresponding to the pixel is split into three binary numbers: 10100111, 01100110, and 00100010. Then, from the most significant bit to the least significant bit, the binary number is converted to a decimal number, resulting in eight indices: 100→4, 010→2, 111→7…100→4. The color information is then inserted into the octree according to these indices, and the data structure information in each node is updated. For example… Figure 4 As shown, the RGB value (167,102,34) is stored in each level of the node according to index 42700674. The position 4 in the root node (Level 0) stores 100, the position 2 in the child node (Level 1) stores 010, and so on. The position 4 in the leaf node (Level 7) stores 100.

[0042] In one implementation, quantization processing is performed on multiple nodes, including: if the cumulative number of colors obtained by accumulating the number of colors when traversing each pixel in the image to be identified exceeds the preset number of colors, then in the multiple nodes, the target node is queried and the child nodes of the target node are deleted in the direction from the child node to the root node. The target node has at least two child nodes and the number of pixels corresponding to the target node is the minimum.

[0043] In practical applications, when traversing each pixel in the image to be recognized and storing color values, the number of colors is accumulated according to the different color values. When the accumulated number of colors exceeds the preset number of colors, the color values ​​are stored in an octree. Then, from the child node to the root node, the node with at least two child nodes is queried. If there are multiple nodes with at least two child nodes, the node with the fewest stored pixels is selected as the target node, and the child nodes of the target node are deleted. For example, the bool Reduce attribute value of the leaf node of the target node is set to the preset value, so that the target node becomes a leaf node, thereby merging similar colors and reducing the number of leaf nodes.

[0044] In one implementation, the quantized color value corresponding to each pixel is obtained based on the color values ​​stored in the processed nodes, including: querying the quantized color value corresponding to each pixel in the octree after deleting the child nodes of the target node.

[0045] In practical applications, a color palette is established to traverse each pixel. The color palette queries the color value corresponding to each pixel from the root node to the leaf node in the octree. Since the nodes of the octree have been quantized, the pixels in the image to be recognized have been represented by a preset number of colors. Therefore, when traversing each pixel to query the color, different pixels with similar original colors are represented by the same color.

[0046] In one implementation, the number of quantized colors corresponding to each macroblock is determined based on the quantized color values ​​corresponding to each pixel in the macroblock. This includes: for any macroblock, traversing each pixel in the macroblock, querying the color values ​​corresponding to each pixel in the macroblock in the octree after deleting the child nodes of the target node, and counting the number of quantized colors corresponding to the macroblock.

[0047] In practical applications, when calculating the number of quantized colors corresponding to each macroblock, we traverse each pixel in the macroblock, and in the octree after deleting the child nodes of the target node, we query the color value corresponding to each pixel. Different color values ​​indicate different colors, and thus we obtain the number of colors corresponding to the macroblock, i.e., the number of quantized colors.

[0048] In one implementation, based on the number of quantized colors corresponding to multiple macroblocks and the number of original colors corresponding to multiple macroblocks, the image type corresponding to each macroblock is identified, including: for any macroblock, if the number of quantized colors corresponding to the macroblock exceeds a first preset value, and the ratio of the number of quantized colors corresponding to the macroblock to the number of original colors corresponding to the macroblock exceeds a second preset value, then the image type corresponding to the macroblock is determined to be a text block.

[0049] In practical applications, macroblocks are identified as text or image blocks based on the ratio of the number of quantized colors to the number of original colors. Different encoding types are used for different image types, allowing for better control over the display quality of different areas and the size of the compressed data. The first preset value is an integer, which can be set to a specific value as needed. For example, the first preset value can be 2. The second preset value is a decimal, which can also be set to a specific value as needed. For example, the second preset value can be 20%.

[0050] The process of the image recognition method will be described in detail below through a specific embodiment. Figure 5 As shown, the method includes the following steps:

[0051] Step S501: Perform octree quantization calculation on all pixels in the image. Specifically, index the color value of each pixel in the image, and store each color value in the node of the octree according to the index.

[0052] Step S502: Obtain color values ​​from the quantized octree. Specifically, quantize multiple nodes of the octree. If, when traversing each pixel in the image to be recognized, the accumulated number of colors exceeds a preset number, then, following the direction from the child nodes to the root node, query the target node and delete its child nodes. The target node has at least two child nodes, and the number of pixels corresponding to the target node is minimized. In the octree after deleting the child nodes of the target node, query the quantized color value corresponding to each pixel.

[0053] Step S503: Perform 32*32 macroblock segmentation on the entire image. Divide the image into multiple macroblocks, each macroblock consisting of 32*32 pixels.

[0054] Step S504: Color statistics are performed within the current macroblock, revealing a total of A colors. The color value of each pixel in the current macroblock is then queried, and the original number of colors in the macroblock is counted as A.

[0055] Step S505: The number of colors B corresponding to the pixels in the current macroblock on the color palette. Specifically, by querying the octree after deleting the child nodes of the target node using the color palette, the color value corresponding to each pixel in the current macroblock is calculated, and the number of quantized colors corresponding to the macroblock is counted as B.

[0056] Step S506: Determine whether B≥2 and B / A*100%>20% are satisfied. If satisfied, the current macroblock is identified as a text block and the macroblock analysis ends; if not satisfied, the current macroblock is identified as a non-text block and step S507 is executed.

[0057] Step S507: Calculate the color smoothness within the macroblock; macroblock analysis ends.

[0058] Step S508: Determine if this is the last macroblock. If so, the full image analysis ends; otherwise, return to step S504 to process the next macroblock.

[0059] After that, different compression encoding methods are used for the identified text blocks and non-text blocks. The text blocks are lossless encoded, and the non-text blocks are lossy compressed and encoded to obtain a compressed image, which is then sent to the user terminal for decoding and display via a virtual desktop transmission protocol.

[0060] Corresponding to the application scenarios and methods provided in the embodiments of this application, the embodiments of this application also provide an image recognition device. For example... Figure 6 The diagram shown is a structural block diagram of an image recognition device according to an embodiment of this application. The device includes:

[0061] The processing module 601 is used to perform color quantization processing on the image to be recognized to obtain the quantized color value corresponding to each pixel.

[0062] The determining module 602 is used to divide the image to be recognized into multiple macroblocks, and determine the number of quantized colors corresponding to each macroblock based on the quantized color values ​​of each pixel in the multiple macroblocks.

[0063] The recognition module 603 is used to identify the image type corresponding to each of the multiple macroblocks based on the number of quantized colors and the number of original colors corresponding to each of the multiple macroblocks. The image type is used to characterize whether the macroblock is a text block.

[0064] The image recognition device provided in this embodiment first performs color quantization processing on the image to be recognized to obtain the quantized color value corresponding to each pixel; secondly, it divides the image to be recognized into multiple macroblocks, and determines the number of quantized colors corresponding to each macroblock based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks; finally, it identifies the image type corresponding to each macroblock based on the number of quantized colors and the number of original colors corresponding to each macroblock, whereby the image type is used to characterize whether the macroblock is a text block. In this embodiment, by dividing the image to be recognized into multiple macroblocks and utilizing the number of quantized colors and the number of original colors corresponding to each macroblock, text blocks and non-text blocks are identified from the image with high recognition accuracy. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality of different areas and the size of the compressed data, avoiding the problems of increased bandwidth and bandwidth costs.

[0065] In one implementation, the processing module 601 is used to: traverse each pixel in the image to be recognized, store the color value corresponding to each pixel in multiple nodes of an octree; perform quantization processing on the multiple nodes, and obtain the quantized color value corresponding to each pixel based on the color value stored in the processed nodes.

[0066] In one implementation, when the processing module 601 traverses each pixel in the image to be recognized and stores the color value corresponding to each pixel in multiple nodes of the octree, it is used to: traverse each pixel in the image to be recognized, establish an index corresponding to each pixel according to the color value corresponding to each pixel; and store the color value corresponding to each pixel in multiple nodes of the octree according to the index corresponding to each pixel.

[0067] In one implementation, when the processing module 601 performs quantization processing on multiple nodes, it is used to: if the number of accumulated colors obtained by traversing each pixel in the image to be identified exceeds the preset number of colors, then in the multiple nodes, in the direction from the child node to the root node, query the target node and delete the child nodes of the target node, wherein the target node has at least two child nodes and the number of pixels corresponding to the target node is the minimum.

[0068] In one implementation, when the processing module 601 obtains the quantized color value corresponding to each pixel based on the color values ​​stored in the processed node, it is used to: query the quantized color value corresponding to each pixel in the octree after deleting the child nodes of the target node.

[0069] In one implementation, when determining the number of quantized colors corresponding to each macroblock based on the quantized color values ​​of each pixel in the macroblock, the determining module 602 is used to: for any macroblock, traverse each pixel in the macroblock, query the color values ​​corresponding to each pixel in the macroblock in the octree after deleting the child nodes of the target node, and count the number of quantized colors corresponding to the macroblock.

[0070] In one implementation, the recognition module 603 is configured to: for any macroblock, if the number of quantized colors corresponding to the macroblock exceeds a first preset value, and the ratio of the number of quantized colors corresponding to the macroblock to the number of original colors corresponding to the macroblock exceeds a second preset value, then determine the image type corresponding to the macroblock as a text block.

[0071] The functions of each module in the embodiments of this application can be found in the corresponding descriptions in the above methods, and they have corresponding beneficial effects, which will not be repeated here.

[0072] Figure 7 This is a block diagram of an electronic device used to implement embodiments of this application. For example... Figure 7 As shown, the electronic device includes a memory 710 and a processor 720. The memory 710 stores a computer program that can run on the processor 720. When the processor 720 executes the computer program, it implements the method described in the above embodiments. The number of memories 710 and processors 720 can be one or more.

[0073] The electronic device also includes:

[0074] The communication interface 730 is used to communicate with external devices and perform data exchange and transmission.

[0075] If the memory 710, processor 720, and communication interface 730 are implemented independently, they can be interconnected via a bus to communicate with each other. This bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0076] Optionally, in a specific implementation, if the memory 710, processor 720, and communication interface 730 are integrated on a single chip, then the memory 710, processor 720, and communication interface 730 can communicate with each other through an internal interface.

[0077] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method provided in this application.

[0078] This application also provides a chip including a processor for calling and executing instructions stored in a memory, causing a communication device with the chip installed to perform the method provided in this application.

[0079] This application also provides a chip, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected through an internal connection path. The processor is used to execute code in the memory. When the code is executed, the processor is used to execute the method provided in the application embodiment.

[0080] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or 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. General-purpose processors can be microprocessors or any conventional processor. It is worth noting that the processor can be a processor supporting Advanced Reduced Instruction Set Machines (ARM) architecture.

[0081] Further, optionally, the aforementioned memory may include read-only memory and random access memory. The memory may be volatile memory or non-volatile memory, or may include both. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which serves as an external cache. By way of example, but not limitation, many forms of RAM are available. Examples include Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).

[0082] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.

[0083] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of those different embodiments or examples.

[0084] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.

[0085] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process. Furthermore, the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functionality involved.

[0086] The logic and / or steps described in the flowchart or otherwise herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).

[0087] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. All or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware, the program being stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiments.

[0088] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. This storage medium can be a read-only memory, a disk, or an optical disk, etc.

[0089] The above description is merely an exemplary embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope described in this application, and these should all be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. An image recognition method, characterized in that, The method includes: The image to be identified is subjected to color quantization processing to obtain the quantized color value corresponding to each pixel; The image to be identified is divided into multiple macroblocks, and the number of quantized colors corresponding to each macroblock is determined based on the quantized color value of each pixel in the multiple macroblocks. Based on the number of quantized colors corresponding to the plurality of macroblocks and the number of original colors corresponding to the plurality of macroblocks, the image type corresponding to the plurality of macroblocks is identified. The image type is used to characterize whether the macroblock is a text block. For any macroblock, if the number of quantized colors corresponding to the macroblock exceeds a first preset value and the ratio of the number of quantized colors corresponding to the macroblock to the number of original colors corresponding to the macroblock exceeds a second preset value, then the image type corresponding to the macroblock is determined to be a text block.

2. The method according to claim 1, characterized in that, The step of performing color quantization processing on the image to be identified to obtain the quantized color value corresponding to each pixel includes: Traverse each pixel in the image to be identified and store the color value corresponding to each pixel in multiple nodes of an octree; The multiple nodes are quantized, and the quantized color value of each pixel is obtained based on the color value stored in the processed nodes.

3. The method according to claim 2, characterized in that, The step of traversing each pixel in the image to be identified and storing the color value corresponding to each pixel into multiple nodes of an octree includes: Traverse each pixel in the image to be identified, and establish an index corresponding to each pixel based on the color value of each pixel; Based on the index corresponding to each pixel, the color value corresponding to each pixel is stored in multiple nodes of an octree.

4. The method according to claim 2, characterized in that, The quantization process for the plurality of nodes includes: If, when traversing each pixel in the image to be identified, the cumulative number of colors exceeds the preset number of colors, then among the multiple nodes, the target node is queried and its child nodes are deleted in the direction from the child node to the root node. The target node has at least two child nodes and the number of pixels corresponding to the target node is the minimum.

5. The method according to claim 4, characterized in that, The process of obtaining the quantized color value corresponding to each pixel based on the color values ​​stored in the processed nodes includes: In the octree after deleting the child nodes of the target node, query the quantized color value corresponding to each pixel.

6. The method according to claim 4, characterized in that, The step of determining the number of quantized colors corresponding to each of the plurality of macroblocks based on the quantized color values ​​corresponding to each pixel in the plurality of macroblocks includes: For any macroblock, traverse each pixel in the macroblock, query the color value corresponding to each pixel in the macroblock in the octree after deleting the child nodes of the target node, and count the number of quantized colors corresponding to the macroblock.

7. An image recognition device, characterized in that, The device includes: The processing module is used to perform color quantization processing on the image to be recognized to obtain the quantized color value corresponding to each pixel. The determining module is used to divide the image to be identified into multiple macroblocks, and determine the number of quantized colors corresponding to each of the multiple macroblocks based on the quantized color values ​​corresponding to each pixel in the multiple macroblocks. The recognition module is used to identify the image type corresponding to each of the plurality of macroblocks based on the number of quantized colors corresponding to each of the plurality of macroblocks and the number of original colors corresponding to each of the plurality of macroblocks, wherein the image type is used to characterize whether the macroblock is a text block; wherein, for any macroblock, if the number of quantized colors corresponding to the macroblock exceeds a first preset value, and the ratio of the number of quantized colors corresponding to the macroblock to the number of original colors corresponding to the macroblock exceeds a second preset value, then the image type corresponding to the macroblock is determined to be a text block.

8. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory, wherein the processor, when executing the computer program, implements the method of any one of claims 1-6.

9. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method of any one of claims 1-6.