Image recognition method and device, electronic equipment and storage medium
By performing color quantization processing and macroblock division on the image, identifying the image types and compressing them using different encoding methods, the problem of inaccurate image classification compression in the prior art is solved, and more effective bandwidth management is achieved.
Patent Information
- Application Number
- CN202311050607.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-18
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2043-08-18
AI Technical Summary
The prior art cannot accurately classify and partition images, resulting in the inability to achieve classification compression, resulting in problems such as bandwidth increase and bandwidth cost increase.
By performing color quantization processing on the image to be identified, dividing it into multiple macroblocks, and identifying the image type based on the quantized color number and the original color number of the macroblocks, and then compressing the text blocks and image blocks using different encoding methods.
It realizes accurate identification of text blocks and non-text blocks in the image, and can adopt different compression encoding methods to better control the display quality and compressed data size in different areas, avoiding the problems of increasing bandwidth and increasing costs.
Smart Images

Figure CN119520799A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image recognition method, device, electronic device and storage medium. Background Art
[0002] Cloud desktop is a service that uses cloud computing to place computing and storage in the cloud and provide virtual desktop services. It has the advantages of centralized management, security, reliability, cost savings, and green energy saving. Users can access the cloud desktop anytime and anywhere to work without being restricted by time, location, terminal, and application. Cloud desktop runs in the cloud, and the desktop update screen needs to be encoded and transmitted to the terminal for display. Different encoding methods determine the screen display quality and the size of the transmission network bandwidth. In order to achieve a balance between display quality and transmission network bandwidth, different areas of the update screen can be encoded and compressed in different ways according to the content type. For example, lossy compression encoding is used in the image area to save bandwidth, and lossless compression encoding is used in the text area to achieve clear display.
[0003] In the related art, the smoothness of the entire image to be encoded is calculated, and the image type is determined based on the smoothness. Images are judged as one type regardless of size. If there are multiple types of content in the image, the images cannot be accurately classified and distinguished, resulting in the inability to accurately classify and compress the images. Therefore, a picture can only be compressed in one encoding method, and the display quality of different areas of a picture and the size of the compressed data cannot be accurately controlled, resulting in increased bandwidth and increased bandwidth costs. Summary of the invention
[0004] The embodiments of the present application provide an image recognition method, device, electronic device and storage medium to solve the problem that images cannot be classified and partitioned, and thus classification compression cannot be achieved.
[0005] In a first aspect, an embodiment of the present application provides an image recognition method, the method comprising: performing color quantization processing on an image to be recognized to obtain a quantized color value corresponding to each pixel; dividing the image to be recognized into multiple macroblocks, and determining the number of quantized colors corresponding to the multiple macroblocks based on the quantized color values corresponding to each pixel in the multiple macroblocks; based on the number of quantized colors corresponding to the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, identifying the image types corresponding to the multiple macroblocks, the image type is used to characterize whether the macroblock is a text block.
[0006] In a second aspect, an embodiment of the present application provides an image recognition device, which includes: a processing module, used to perform color quantization processing on an image to be recognized to obtain a quantized color value corresponding to each pixel; a determination module, used to divide the image to be recognized into multiple macroblocks, and determine the number of quantized colors corresponding to the multiple macroblocks based on the quantized color values corresponding to each pixel in the multiple macroblocks; an identification module, used to identify the image types corresponding to the multiple macroblocks based on the number of quantized colors corresponding to the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image type being used to characterize whether the macroblock is a text block.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor implements any of the above methods when executing the computer program.
[0008] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the above is implemented.
[0009] Compared with the prior art, this application has the following advantages:
[0010] The present application provides an image recognition method, device, 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, and the number of quantized colors corresponding to the multiple macroblocks is determined based on the quantized color value corresponding to each pixel in the multiple macroblocks; finally, based on the number of quantized colors corresponding to the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image type corresponding to the multiple macroblocks 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, the number of quantized colors corresponding to the macroblocks and the number of original colors are used to identify text blocks and non-text blocks from the image, and the recognition accuracy is high. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality and compressed data size of different areas, and avoid the problem of increased bandwidth and increased bandwidth costs.
[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments according to the present application and should not be regarded as limiting the scope of the present application.
[0013] Figure 1 A schematic diagram of an application scenario of the image recognition method provided in this application;
[0014] Figure 2 A flowchart of an image recognition method according to an embodiment of the present application;
[0015] Figure 3 A schematic diagram of establishing an index according to a color value according to an embodiment of the present application;
[0016] Figure 4 A schematic diagram of storing color values in an octree according to an index according to an embodiment of the present application;
[0017] Figure 5 A flowchart of an image recognition method according to an embodiment of the present application;
[0018] Figure 6 A structural block diagram of an image recognition device according to an embodiment of the present application; and
[0019] Figure 7 A block diagram of an electronic device used to implement an embodiment of the present application. DETAILED DESCRIPTION
[0020] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the concept or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary in nature and not restrictive.
[0021] To facilitate understanding of the technical solutions of the embodiments of the present application, the following describes the related technologies of the embodiments of the present application. The following related technologies can be combined with the technical solutions of the embodiments of the present application as optional solutions, and they all belong to the protection scope of the embodiments of the present application.
[0022] Figure 1 A schematic diagram of an application scenario of the image recognition method provided in this application. Figure 1As shown, in this embodiment, the cloud desktop update image is used as the cloud desktop image to be identified, and the cloud desktop image to be identified is identified by using the cloud server, specifically including: first, color quantization processing is performed on the cloud desktop image to be identified 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 the multiple macroblocks is determined based on the quantized color value corresponding to each pixel in the multiple macroblocks; finally, based on the number of quantized colors corresponding to the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image type corresponding to the multiple macroblocks is identified from the cloud desktop image to be identified, that is, whether the macroblock is a text block or an image block, different compression encoding methods are used for the text block and the image block, lossless encoding is performed on the text block, and lossy compression encoding is performed on the image block to obtain a compressed encoded image, which is sent to the user terminal through the virtual desktop transmission protocol, and the user terminal decodes the text block and the image block using different decoding methods to obtain the cloud desktop image and display it. Among them, the virtual desktop transmission protocol can include the Simple Protocol for Independent Computing Environment (SPICE) and the like.
[0023] The present application embodiment provides an image recognition method. The method in this embodiment can be applied to a computing device, which may include a server, a user terminal, etc. Figure 2 The flowchart of the image recognition method according to one embodiment of the present application is shown, including:
[0024] Step S201 , performing color quantization processing on the image to be identified to obtain the quantized color value corresponding to each pixel.
[0025] Step S202 : dividing the image to be identified into a plurality of macroblocks, and determining the number of quantized colors corresponding to the plurality of macroblocks based on the quantized color values corresponding to the pixels in the plurality of macroblocks.
[0026] Step S203 , based on the quantized color quantities corresponding to the multiple macroblocks and the original color quantities corresponding to the multiple macroblocks, the image types corresponding to the multiple macroblocks are identified, where the image type is used to indicate whether the macroblock is a text block.
[0027] The color quantization process includes reducing the number of colors in the image to be identified so that the number of colors in the image to be identified does not exceed a preset value, for example, merging the color values of multiple pixels with similar colors in the image into the same color value to reduce the number of colors.
[0028] When the image to be identified is divided, each macroblock may include multiple pixels. The number of original colors corresponding to the macroblock is the number of colors obtained by counting the color value of each pixel in the macroblock before the image to be identified is subjected to color quantization processing. In different color spaces, the color values are different. For example, in the RGB space, the color values are RGB values. If the 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 the 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 compression methods are used for text blocks and image blocks respectively. The text blocks are losslessly encoded and the image blocks are lossy compressed. The compressed encoded image is sent to the user terminal.
[0030] It can be understood that the image recognition method in the technical solution of the present application is not limited to the recognition of cloud desktop images, but can be applied to the encoding 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; secondly, the image to be recognized is divided into multiple macroblocks, and the number of quantized colors corresponding to the multiple macroblocks 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 the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image type corresponding to the multiple macroblocks 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, the number of quantized colors corresponding to the macroblocks and the number of original colors are used to identify text blocks and non-text blocks from the image, and the recognition accuracy is high. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality and compressed data size of different areas, avoiding the problem of increased bandwidth and increased bandwidth costs.
[0032] In one implementation, step S201 performs color quantization processing on the image to be identified to obtain a quantized color value corresponding to each pixel, including: traversing each pixel in the image to be identified, storing the color value corresponding to each pixel in multiple nodes of an octree; performing quantization processing on multiple nodes, and obtaining a quantized color value corresponding to each pixel based on the color values stored in the processed nodes.
[0033] In practical applications, the octree algorithm is used to store and quantize the color value corresponding to each pixel. In different color spaces, the color value is different. For example, in the RGB space, the color value is the RGB value. Each pixel in the image to be identified is traversed, and the color value corresponding to the pixel is stored in the octree, and quantized. The color values of multiple pixels with similar colors in the image are merged into the same color value to reduce the number of colors. In the quantized octree, the color value of each pixel is queried.
[0034] In one example, each pixel of the image to be identified is read in a preset order, wherein the first K different color values are read in first, and when more than K (K is the preset number of colors, which can be taken according to specific needs, and in this embodiment, the value of K is 256) new colors appear, the colors with similar colors and low frequency of occurrence are merged to ensure that the number of colors does not exceed K. Among them, the selection of representative colors is achieved with the help of an octree, and whenever a pixel in the image to be identified is read, if the corresponding number of 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 to ensure that the number of leaf nodes does not exceed K.
[0035] In one implementation, traversing each pixel in the image to be identified and storing the color value corresponding to each pixel in multiple nodes of the octree includes: traversing each pixel in the image to be identified, and establishing the index corresponding to each pixel according to the color value corresponding to each pixel; storing the color value corresponding to each pixel in multiple nodes of the octree according to the index corresponding to each pixel.
[0036] In practical applications, when storing color values in the octree, firstly, an index is created according to the color value corresponding to the pixel, and the color value of each pixel is stored in each node according to the index. By creating an index, the uniqueness of the data can be guaranteed, which can help the octree locate the required data more quickly when executing a query, thereby reducing the query time and resource consumption and improving the query efficiency.
[0037] Combine the following Figure 3 and Figure 4 , the storage process of the color value of each pixel is introduced through a specific embodiment.
[0038] In one example, the octree has eight layers, each layer has eight nodes, and each node stores the color information of the nodes passing 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, 00100010, and then the binary is converted to decimal from high to low, and 8 indexes are obtained: 100→4, 010→2, 111→7…100→4. The color information is inserted into the octree according to the index, and the data structure information in each node is updated. Figure 4 As shown, the RGB value (167, 102, 34) is stored in nodes at each level according to index 42700674. The position 4 in the root node Root (Level 0) stores 100, the position 2 in the child node Level 1 stores 010... The position 4 in the leaf node Level 7 stores 100.
[0042] In one implementation, multiple nodes are quantized, including: if the accumulated color number obtained by adding the color numbers when traversing each pixel in the image to be identified exceeds the preset color number, then in the multiple nodes, query the target node and delete the child nodes of the target node 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 least.
[0043] In practical applications, each pixel in the image to be identified is traversed, and when storing color values, the number of colors is accumulated according to different color values. When the accumulated number of colors exceeds the preset number of colors, the color value is stored in the octree, and then a node with at least two child nodes is queried from the child node to the root node. If there are multiple nodes with at least two child nodes, the node with the least number of stored pixels is used 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 to achieve similar color merging, thereby reducing the number of leaf nodes.
[0044] In one implementation, based on the color value stored in the processed node, the quantized color value corresponding to each pixel is obtained, including: in the octree after deleting the child nodes of the target node, querying the quantized color value corresponding to each pixel.
[0045] In practical applications, a color palette is established and used to traverse each pixel. The color value corresponding to each pixel is queried from the root node to the leaf node on the octree. Since the nodes of the octree have been quantized, the pixels in the image to be identified 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, based on the quantized color values corresponding to each pixel in the multiple macroblocks, the number of quantized colors corresponding to the multiple macroblocks is determined, including: for any macroblock, traversing each pixel in the macroblock, querying the color value 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, traverse each pixel in the macroblock, and query the color value corresponding to each pixel in the octree after deleting the child nodes of the target node. Different color values represent different colors, and the number of colors corresponding to the macroblock, that is, the number of quantized colors, is obtained.
[0048] In one implementation, based on the number of quantized colors corresponding to the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image types corresponding to the multiple macroblocks are 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 as a text block.
[0049] In practical applications, according to the ratio between the number of quantized colors corresponding to the macroblock and the number of original colors corresponding to the macroblock, the macroblock is identified as a text block or an image block, and different encoding types are used for different image types to better control the display quality of different areas and the size of compressed data. Among them, the first preset value is an integer, and a specific value can be set according to specific needs. For example, the first preset value can be 2. The second preset value is a decimal, and a specific value can be set according to specific needs. For example, the second preset value can be 20%.
[0050] The following is a detailed description of the image recognition method process through a specific embodiment. Figure 5 As shown, the method comprises the following steps:
[0051] Step S501, perform octree quantization calculation on all pixels of the image. Specifically, create an index for the color value of each pixel in the image, and store each color value in a node of the octree according to the index.
[0052] Step S502, obtaining color values from the quantized octree. Specifically, multiple nodes of the octree are quantized. If the accumulated color number obtained by accumulating the color number when traversing each pixel in the image to be identified exceeds the preset color number, 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 least. In the octree after deleting the child nodes of the target node, the quantized color value corresponding to each pixel is queried.
[0053] Step S503, the whole image is segmented into 32*32 macroblocks. The image is divided into multiple macroblocks, each macroblock consists of 32*32 pixels.
[0054] Step S504: Perform color statistics in the current macroblock and find out that there are A colors in total. Query the color value of each pixel in the current macroblock, and count the original color number of the macroblock as A.
[0055] Step S505, the number of colors on the color palette corresponding to the pixels in the current macroblock is B. Specifically, the color value corresponding to each pixel in the current macroblock is queried in the octree after deleting the child node of the target node through the color palette, and the number of quantized colors corresponding to the macroblock is counted as B.
[0056] Step S506, determining whether B≥2 and B / A*100%>20% are satisfied. If so, the current macroblock is identified as a text block and the macroblock analysis ends. If not, 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, and the macroblock analysis ends.
[0058] Step S508, determining whether it is the last macroblock, if yes, the full image analysis ends; otherwise, returning 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 losslessly encoded and the non-text blocks are lossy compressed and encoded to obtain a compressed encoded image, which is sent to the user terminal through the virtual desktop transmission protocol for decoding and display.
[0060] Corresponding to the application scenario and method of the method provided in the embodiment of the present application, the embodiment of the present application also provides an image recognition device. Figure 6 The figure is a structural block diagram of an image recognition device according to an embodiment of the present application, and the device comprises:
[0061] The processing module 601 is used to perform color quantization processing on the image to be identified to obtain the quantized color value corresponding to each pixel.
[0062] The determination module 602 is used to divide the image to be identified into multiple macroblocks, and determine the number of quantized colors corresponding to the multiple macroblocks based on the quantized color values corresponding to each pixel in the multiple macroblocks.
[0063] The identification module 603 is used to identify the image types corresponding to the multiple macroblocks based on the quantized color quantities corresponding to the multiple macroblocks and the original color quantities corresponding to the multiple macroblocks, and the image type is used to indicate 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, the image to be recognized is divided into multiple macroblocks, and the number of quantized colors corresponding to the multiple macroblocks 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 the multiple macroblocks and the number of original colors corresponding to the multiple macroblocks, the image type corresponding to the multiple macroblocks 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, the number of quantized colors corresponding to the macroblocks and the number of original colors are used to identify text blocks and non-text blocks from the image, and the recognition accuracy is high. Furthermore, different compression encoding methods can be used for text blocks and non-text blocks to better control the display quality and compressed data size of different areas, avoiding the problem of increased bandwidth and increased bandwidth costs.
[0065] In one implementation, the processing module 601 is used to: traverse each pixel in the image to be identified, and store the color value corresponding to each pixel in multiple nodes of the octree; quantize the multiple nodes, and obtain the quantized color value corresponding to each pixel based on the color values stored in the processed nodes.
[0066] In one implementation, when traversing each pixel in the image to be identified and storing the color value corresponding to each pixel in multiple nodes of the octree, the processing module 601 is used to: traverse each pixel in the image to be identified, and 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 accumulated number of colors obtained by adding 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, query the target node and delete the child nodes of the target node 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 least.
[0068] In one implementation, when the processing module 601 obtains the quantized color value corresponding to each pixel based on the color value 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 node of the target node.
[0069] In one implementation, when determining the number of quantized colors corresponding to multiple macroblocks based on the quantized color values corresponding to each pixel in the multiple macroblocks, the determination module 602 is used to: 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 node of the target node, and count the number of quantized colors corresponding to the macroblock.
[0070] In one implementation, the identification module 603 is used 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 the image type corresponding to the macroblock is determined as a text block.
[0071] The functions of each module in the embodiment of the present application can be referred to the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.
[0072] Figure 7 is a block diagram of an electronic device used to implement an embodiment of the present application. Figure 7 As shown, the electronic device includes: a memory 710 and a processor 720. The memory 710 stores a computer program that can be run on the processor 720. When the processor 720 executes the computer program, the method in the above embodiment is implemented. The number of the memory 710 and the processor 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 transmission.
[0075] If the memory 710, the processor 720 and the communication interface 730 are implemented independently, the memory 710, the processor 720 and the communication interface 730 can be connected to each other through a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0076] Optionally, in a specific implementation, if the memory 710, the processor 720 and the communication interface 730 are integrated on a chip, the memory 710, the processor 720 and the communication interface 730 can communicate with each other through an internal interface.
[0077] An embodiment of the present application provides a computer-readable storage medium storing a computer program, which implements the method provided in the embodiment of the present application when the program is executed by a processor.
[0078] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in the memory from the memory, so that a communication device equipped with the chip executes the method provided by the embodiment of the present application.
[0079] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method provided in the embodiment of the application.
[0080] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor supporting the Advanced RISC Machines (ARM) architecture.
[0081] Further, optionally, the above-mentioned memory may include a read-only memory and a random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of exemplary but not limiting description, many forms of RAM are available. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DR RAM).
[0082] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the present application is generated in whole or in part. 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 transmitted from one computer-readable storage medium to another computer-readable storage medium.
[0083] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples, unless they are contradictory.
[0084] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0085] Any process or method described in the flow chart or otherwise described herein can be understood as a module, fragment or portion of a code representing one or more executable instructions for implementing the steps of a specific logical function or process. And the scope of the preferred embodiment of the present application includes other implementations, in which the functions may not be performed in the order shown or discussed, including in a substantially simultaneous manner or in a reverse order according to the functions involved.
[0086] The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, which can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or used in combination with these instruction execution systems, devices or apparatuses.
[0087] It should be understood that the various parts of the present application can be implemented with hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented with software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium, and when the program is executed, it includes one of the steps of the method embodiment or a combination thereof.
[0088] In addition, each functional unit in each embodiment of the present application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a disk or an optical disk, etc.
[0089] The above is only an exemplary embodiment of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various changes or substitutions within the technical scope recorded in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. An image recognition method, characterized in that: The method comprises: Performing color quantization on the image to be identified to obtain the quantized color value corresponding to each pixel; Dividing the image to be identified into a plurality of macroblocks, and determining the number of quantized colors corresponding to the plurality of macroblocks respectively based on the quantized color values corresponding to the pixels in the plurality of macroblocks; Based on the quantized color quantities respectively corresponding to the multiple macroblocks and the original color quantities respectively corresponding to the multiple macroblocks, the image types respectively corresponding to the multiple macroblocks are identified, and the image types are used to indicate whether the macroblocks are text blocks.
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: Traversing each pixel in the image to be identified, and storing the color value corresponding to each pixel in multiple nodes of the octree; The plurality of nodes are quantized, and based on the color values stored in the processed nodes, quantized color values corresponding to the pixels are obtained.
3. The method according to claim 2, characterized in that The traversing each pixel in the image to be identified and storing the color value corresponding to each pixel in a plurality of nodes of the octree includes: Traversing each pixel in the image to be identified, and establishing an index corresponding to each pixel according to the color value corresponding to each pixel; According to the indexes corresponding to the pixels, the color values corresponding to the pixels are stored in multiple nodes of the octree.
4. The method according to claim 2, characterized in that: The quantizing process of the plurality of nodes includes: If the accumulated number of colors obtained by adding up the number of colors when traversing each pixel in the image to be identified exceeds the preset number of colors, then among the multiple nodes, query the target node and delete the child nodes of the target node 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 least.
5. The method according to claim 4, characterized in that The step of obtaining the quantized color value corresponding to each pixel based on the color value stored in the processed node includes: In the octree after deleting the child nodes of the target node, the quantized color value corresponding to each pixel is queried.
6. The method according to claim 4, characterized in that The determining, based on the quantized color values corresponding to the pixels in the multiple macroblocks, the numbers of quantized colors corresponding to the multiple macroblocks respectively comprises: 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. The method according to any one of claims 1 to 6, characterized in that: The identifying the image types corresponding to the multiple macroblocks respectively based on the quantized color quantities corresponding to the multiple macroblocks respectively and the original color quantities corresponding to the multiple macroblocks respectively comprises: 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, the image type corresponding to the macroblock is determined as a text block.
8. An image recognition device, characterized in that: The device comprises: A processing module is used to perform color quantization processing on the image to be identified to obtain the quantized color value corresponding to each pixel; A determination module, configured to divide the image to be identified into a plurality of macroblocks, and determine the number of quantized colors corresponding to the plurality of macroblocks based on the quantized color values corresponding to the pixels in the plurality of macroblocks; The identification module is used to identify the image types corresponding to the multiple macroblocks based on the quantized color quantities corresponding to the multiple macroblocks and the original color quantities corresponding to the multiple macroblocks, wherein the image type is used to indicate whether the macroblock is a text block.
9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory, wherein the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method, system and software product for color image encoding
CN101065779A
Image data transmitting and restoring method, device and terminal
CN102510434A
Image compression method and image processing apparatus
CN104025561A
Universal on-image text extraction method
CN104978565A
Text block coding method and device
CN107509079A