Picture compression method and related device

文档序号:192747 发布日期:2021-11-02 浏览:27次 中文

阅读说明:本技术 一种图片压缩方法及相关装置 (Picture compression method and related device ) 是由 何文亚 顾晔佳 于 2021-06-30 设计创作,主要内容包括:本发明实施例公开了一种图片压缩方法及相关装置,该方法可包括:获取待压缩图片的第一参数信息和预设的第二参数信息,通过对比待压缩图片的第一参数信息和预设的第二参数信息得到第一对比结果,根据第一对比结果确定输出图片或明确压缩参数并压缩图片,得到压缩后的图片;然后再对比压缩后的图片的第三参数信息和预设的第二参数信息得到第二对比结果,进一步根据第二对比结果确定输出图片或重新调整压缩参数并继续压缩该压缩后的图片,重复对比、调整、压缩过程直至达到第二预设条件。本发明实施例可以通过多次对比、动态调整压缩参数、多次压缩,最终输出符合要求的图片,提升用户体验。(The embodiment of the invention discloses a picture compression method and a related device, wherein the method comprises the following steps: acquiring first parameter information and preset second parameter information of a picture to be compressed, obtaining a first comparison result by comparing the first parameter information and the preset second parameter information of the picture to be compressed, determining an output picture or determining a compression parameter and compressing the picture according to the first comparison result, and obtaining a compressed picture; and then comparing the third parameter information of the compressed picture with the preset second parameter information to obtain a second comparison result, further determining to output the picture or readjust the compression parameter according to the second comparison result and continuously compressing the compressed picture, and repeating the comparison, adjustment and compression processes until a second preset condition is reached. According to the embodiment of the invention, the picture meeting the requirements can be finally output through multiple comparison, dynamic adjustment of compression parameters and multiple compression, and the user experience is improved.)

1. A picture compression method, comprising:

acquiring first parameter information and preset second parameter information of a picture to be compressed;

comparing the first parameter information with the preset second parameter information to obtain a first comparison result; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture;

acquiring third parameter information of the compressed picture, and comparing the third parameter information with the preset second parameter information to obtain a second comparison result; if the second comparison result does not meet a second preset condition, adjusting the compression parameter according to the second comparison result, compressing the compressed picture according to the adjusted compression parameter, repeating the processes of comparison, adjustment and compression until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed.

2. The method of claim 1, wherein the compression parameters include a compression coefficient and a quality coefficient;

compressing the picture to be compressed according to the compression parameters, including:

compressing the pixel width and the pixel quality of the picture to be compressed according to the compression coefficient and the quality coefficient;

compressing the compressed picture according to the adjusted compression parameters, including:

and compressing the pixel width and the pixel quality of the compressed picture according to the adjusted compression coefficient and the quality coefficient.

3. The method according to any one of claims 1-2, wherein the obtaining of the first parameter information and the preset second parameter information of the picture to be compressed comprises:

acquiring first pixel width and height information of the picture to be compressed, first pixel quality information of the picture to be compressed, one or more of the number of bytes of a first memory occupied by the picture to be compressed and one or more of the maximum value and the minimum value of the number of bytes of a preset memory;

the obtaining of the third parameter information of the compressed picture includes:

and acquiring one or more of second pixel width and height information of the compressed picture, second pixel quality information of the compressed picture and third memory byte number occupied by the compressed picture.

4. The method of claim 3, wherein the first parameter information includes the first number of memory bytes; the second parameter information comprises the maximum value of the preset memory byte number;

the comparing the first parameter information with the preset second parameter information to obtain a first comparison result, including:

and calculating a first difference value between the first memory byte number and the preset maximum value of the second memory byte number to obtain the first comparison result, wherein the first comparison result comprises the first difference value.

5. The method as claimed in claim 4, wherein outputting the picture to be compressed if the first comparison result satisfies a first predetermined condition comprises:

if the first difference value is smaller than or equal to a first preset value, outputting the picture to be compressed;

if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture, including:

and if the first difference is larger than the first preset value, determining the compression parameters according to the first difference through a preset index relation table, and compressing the picture to be compressed according to the compression parameters to obtain a compressed picture.

6. The method of claim 5, wherein the third parameter information includes the third number of memory bytes; the second parameter information also comprises the minimum value of the number of bytes of the preset second memory;

comparing the third parameter information of the compressed picture with the preset second parameter information to obtain a second comparison result, including:

calculating the difference between the third memory byte number occupied by the compressed picture and the preset second memory byte number maximum value to obtain a second difference value;

calculating a difference value between the third memory byte number occupied by the compressed picture and the preset second memory byte number minimum value to obtain a third difference value; and obtaining the second comparison result, wherein the second comparison result comprises the second difference and the third difference.

7. The method according to claim 6, wherein the target picture corresponding to the picture to be compressed comprises the compressed picture, a picture before the current compression or a picture after the last compression;

if the second comparison result meets a second preset condition, outputting a target picture corresponding to the picture to be compressed, including:

if the second difference value is smaller than or equal to a second preset value and the third difference value is larger than or equal to a third preset value, outputting the compressed picture;

if the second difference value is smaller than the second preset value and the third difference value is smaller than the third preset value, outputting the picture before the current compression;

if the second comparison result does not satisfy a second preset condition, adjusting the compression parameter according to the second comparison result, and compressing the compressed picture according to the adjusted compression parameter, including:

if the second difference value is larger than the second preset value, adjusting the compression parameter through the preset index relation table according to the second difference value; compressing the compressed picture according to the adjusted compression parameters to obtain a picture compressed again;

repeating the comparison, adjustment and compression processes until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed, wherein the steps comprise:

and if the compression times reach the preset compression times and the second difference value is still larger than the second preset value, outputting the picture after the last compression.

8. A picture compression apparatus, comprising:

the device comprises an acquisition unit, a compression unit and a compression unit, wherein the acquisition unit is used for acquiring first parameter information and preset second parameter information of a picture to be compressed;

the first processing unit is used for comparing the first parameter information with the preset second parameter information to obtain a first comparison result; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture;

the second processing unit is used for acquiring third parameter information of the compressed picture and comparing the third parameter information with the preset second parameter information to obtain a second comparison result; if the second comparison result does not meet a second preset condition, adjusting the compression parameter according to the second comparison result, compressing the compressed picture according to the adjusted compression parameter, repeating the processes of comparison, adjustment and compression until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed.

9. An electronic device, comprising: a processor, a memory, and a communication interface; the processor is connected with the memory and the communication interface, wherein the network interface is used for providing a data communication function, the memory is used for storing program codes, and the processor is used for calling the program codes so as to enable the computer equipment to execute the method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that it stores a computer program adapted to be loaded and executed by a processor to cause a computer device having said processor to perform the method of any of claims 1 to 7.

Technical Field

The present invention relates to the field of communications technologies, and in particular, to a picture compression method and a related apparatus.

Background

The picture identification is a scene generally encountered when on-line business is handled daily, but when different applications or platforms perform picture identification, different requirements are imposed on parameters such as a picture format to be uploaded and the number of bytes of memory occupied by the picture, and users often need to compress the picture and then upload the picture to the applications or platforms for picture identification.

However, in the prior art, the situation that the picture is excessively compressed often occurs in the picture compression process, and the compressed picture does not meet the requirement, so that the success rate of many systems or platforms for picture identification is low, and therefore, the user needs to compress the picture again and then upload the picture for identification, and the situation that the identification fails for a plurality of times continuously occurs easily, and the user experience is poor. Therefore, how to provide an effective picture compression scheme can output pictures meeting the target requirements, improve the success rate of picture identification, and improve user experience is a problem to be solved urgently.

Disclosure of Invention

The embodiment of the invention provides a picture compression method and a related device, which can output pictures meeting target requirements, improve the success rate of picture identification and improve user experience.

In a first aspect, an embodiment of the present invention provides a picture compression method, which may include:

acquiring first parameter information and preset second parameter information of a picture to be compressed;

comparing the first parameter information with the preset second parameter information to obtain a first comparison result; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture;

acquiring third parameter information of the compressed picture, and comparing the third parameter information with the preset second parameter information to obtain a second comparison result;

if the second comparison result does not meet a second preset condition, adjusting the compression parameter according to the second comparison result, compressing the compressed picture according to the adjusted compression parameter, repeating the processes of comparison, adjustment and compression until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed.

According to the embodiment of the invention, the parameter information of the picture to be compressed and the preset parameter information are firstly obtained, then the two sets of parameter information are compared, if the result of the first comparison does not meet the condition, the picture to be compressed is subjected to the first round of compression after the compression parameters are determined according to the result of the first comparison, if the picture after the first round of compression does not meet the condition, the compression parameters are readjusted according to the new comparison result, then the next round of compression is continued, and the processes of comparison, adjustment and compression are repeatedly executed until the finally output picture meets the requirement. In the process of each compression, the compression parameters are dynamically determined according to the comparison result of each time, namely, the compression parameters of each time are not set in advance (namely, are not fixed) but are more matched with the current picture compression condition, so that the picture can be prevented from being compressed excessively; and based on the mechanisms of multiple comparison, multiple adjustment and multiple compression, repeated iteration can reduce the times of user operation and improve the user experience. In other words, in the picture compression process, the embodiment of the invention allows multiple comparisons, multiple adjustments of compression parameters (and the parameters are dynamically adjusted according to the current comparison result), and multiple compression until the preset conditions are reached, and then outputs the picture meeting the preset parameter information requirements, so that excessive compression can be prevented, the success rate of picture identification is improved, and the user experience is improved.

In one possible implementation, the compression parameters include a compression coefficient and a quality coefficient; compressing the picture to be compressed according to the compression parameters, including: compressing the pixel width and the pixel quality of the picture to be compressed according to the compression coefficient and the quality coefficient; compressing the compressed picture according to the adjusted compression parameters, including: and compressing the pixel width and the pixel quality of the compressed picture according to the adjusted compression coefficient and the quality coefficient.

According to the embodiment of the invention, the two dimensions of the pixel width and the pixel height and the pixel quality of the picture are compressed through the compression coefficient and the quality coefficient, so that the compression process of the picture is more targeted, and excessive compression is more effectively prevented, so that the picture meeting the preset parameter information requirement is output, the success rate of picture identification is improved, and the user experience is improved.

In one possible implementation, the method further includes: and if the first comparison result meets a first preset condition, outputting the picture to be compressed.

In the embodiment of the invention, after the parameter information of the picture to be compressed and the preset parameter information are obtained, the information of the picture to be compressed and the preset parameter information are compared to obtain a first comparison result. And if the first comparison result meets a first preset condition, the picture to be compressed is not required to be compressed, and then the picture to be compressed is output. Blind compression can be avoided, and user experience is guaranteed.

In one possible implementation, the method further includes: and if the second comparison result meets a second preset condition, outputting a target picture corresponding to the picture to be compressed.

In the embodiment of the invention, after the picture to be compressed is compressed according to the compression parameters, another pair of comparison results, namely a second comparison result, is obtained by comparing the compressed picture with the preset parameter information. And if the second comparison result meets a second preset condition, the compressed picture is not required to be compressed, and then the corresponding picture is output according to the specific condition of the second preset condition. Blind compression can be avoided, and user experience is guaranteed.

In a possible implementation manner, the acquiring first parameter information and preset second parameter information of a picture to be compressed includes: acquiring first pixel width and height information of the picture to be compressed, first pixel quality information of the picture to be compressed, one or more of the number of bytes of a first memory occupied by the picture to be compressed and one or more of the maximum value and the minimum value of the number of bytes of a preset memory; the obtaining of the third parameter information of the compressed picture includes: and acquiring one or more of second pixel width and height information of the compressed picture, second pixel quality information of the compressed picture and third memory byte number occupied by the compressed picture.

According to the embodiment of the invention, one or more of the pixel width and height information, the pixel quality information and the occupied memory byte number of the picture to be compressed, the maximum value and the minimum value of the memory byte number in the preset second parameter information, and one or more of the pixel width and height information, the pixel quality information and the occupied memory byte number of the compressed picture are obtained, so that a basis can be provided for the subsequent memory byte number comparison and the picture compression of two dimensions of the pixel width and height and the pixel quality, the success rate of picture identification is improved, and the guarantee is provided for improving the user experience.

In a possible implementation manner, the first parameter information includes a number of bytes of the first memory; the second parameter information comprises the maximum value of the preset memory byte number; the comparing the first parameter information with the preset second parameter information to obtain a first comparison result, including: and calculating a first difference value between the first memory byte number and the preset maximum value of the second memory byte number to obtain the first comparison result, wherein the first comparison result comprises the first difference value.

The embodiment of the invention can obtain the first difference value by subtracting the maximum value of the preset memory byte number from the memory byte number occupied by the picture to be compressed. And finishing the first comparison and providing a basis for subsequent judgment and compression.

In a possible implementation manner, if the first comparison result satisfies a first preset condition, outputting the picture to be compressed includes: if the first difference value is smaller than or equal to a first preset value, outputting the picture to be compressed; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture, including: and if the first difference is larger than the first preset value, determining the compression parameters according to the first difference through a preset index relation table, and compressing the picture to be compressed according to the compression parameters to obtain a compressed picture.

In the embodiment of the present invention, after the first difference is calculated, it is determined whether the first difference meets a requirement of a first preset condition, where the first preset condition requires that the first difference is not greater than a first preset value, for example, the first preset value may be set to 0, that is, the number of bytes of a memory occupied by the picture to be compressed is less than or equal to a maximum requirement of the number of bytes of a second preset memory. If the first difference value is smaller than or equal to a first preset value, the picture to be compressed is not required to be compressed, and therefore the picture to be compressed is output; if the first difference is larger than the first preset value, a specific numerical value of the first difference needs to be further clarified, and then a range to which the first difference belongs is clarified from a preset index relation table, so that a compression parameter corresponding to the range to which the first difference belongs is determined, and the picture to be compressed is compressed according to the compression parameter. Therefore, according to the specific difference value between the number of memory bytes occupied by the picture to be compressed and the number of preset second memory bytes, the compression parameter corresponding to the specific difference value is determined, and the first compression of the picture to be compressed is completed according to the compression parameter. Because the determination of the compression parameter is associated with the specific difference between the number of memory bytes occupied by the picture to be compressed and the preset number of second memory bytes, rather than being set in advance (i.e., the compression parameter is not fixed), it is possible to effectively prevent over-compression, and also to provide a data basis for subsequent re-comparison determination.

In a possible implementation manner, the third parameter information includes a number of bytes of the third memory; the second parameter information also comprises the minimum value of the number of bytes of the preset second memory; comparing the third parameter information of the compressed picture with the preset second parameter information to obtain a second comparison result, including: calculating the difference between the third memory byte number occupied by the compressed picture and the preset second memory byte number maximum value to obtain a second difference value; calculating a difference value between the third memory byte number occupied by the compressed picture and the preset second memory byte number minimum value to obtain a third difference value; and obtaining the second comparison result, wherein the second comparison result comprises the second difference and the third difference.

In the embodiment of the invention, after the first compression of the picture to be compressed is finished, the maximum value of the number of bytes of a preset second memory is subtracted by the number of bytes of the memory occupied by the compressed picture to obtain a second difference value; meanwhile, the number of bytes in the memory occupied by the compressed picture is subtracted by the preset minimum value of the number of bytes in the second memory to obtain a third difference value. Therefore, the comparison between the parameter information of the compressed picture and the preset second parameter information is completed, namely, the comparison for the second time is performed, and a basis is provided for subsequent judgment and recompression.

In a possible implementation manner, the target picture corresponding to the picture to be compressed includes the compressed picture, the picture before the current compression, or the picture after the last compression; if the second comparison result meets a second preset condition, outputting a target picture corresponding to the picture to be compressed, including: if the second difference value is smaller than or equal to a second preset value and the third difference value is larger than or equal to a third preset value, outputting the compressed picture; if the second difference value is smaller than the second preset value and the third difference value is smaller than the third preset value, outputting the picture before the current compression; if the second comparison result does not satisfy a second preset condition, adjusting the compression parameter according to the second comparison result, and compressing the compressed picture according to the adjusted compression parameter, including: if the second difference is larger than the second preset value, adjusting the compression parameters through the preset index relation table according to the second difference; compressing the compressed picture according to the adjusted compression parameters to obtain a picture compressed again; repeating the comparison, adjustment and compression processes until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed, wherein the steps comprise: and if the compression times reach the preset compression times and the second difference value is still larger than the second preset value, outputting the picture after the last compression.

In the embodiment of the present invention, after the parameter information of the compressed picture is compared with the preset parameter information, whether a comparison result of the parameter information and the preset parameter information meets a requirement of a second preset condition is determined, where the requirement of the second preset condition is that a second difference is not greater than a second preset value, for example, the second preset value may be set to 0. Firstly, judging whether the second difference value is larger than 0, if so, further defining the specific numerical value of the second difference value, then defining the range to which the second difference value belongs again from the preset index table relationship, so as to determine the compression parameter corresponding to the range to which the second difference value belongs, performing secondary compression on the compressed picture according to the compression parameter, repeating the processes of comparison, adjustment and compression until reaching a second preset condition, ending the compression, or when the compression times reach the upper limit of the preset compression times, the second difference value is still larger than 0, ending the compression and outputting the picture after the last compression; if the second difference is less than or equal to 0, it is further determined whether the third difference is greater than or equal to a third preset value, for example, the third preset value may be set to 0, and if the third difference is also less than 0, the picture before the current compression is output, where the third difference being less than 0 indicates that the number of memory bytes occupied by the compressed picture is less than the minimum value of the preset number of memory bytes, and it can be considered that the difference between the picture before the compression and the maximum value of the preset number of memory bytes is not large, and it is also possible that the picture is successfully identified, so the picture before the current compression is output; and if the third difference is greater than or equal to 0, outputting the compressed picture, namely the picture participating in the comparison. Through multiple times of comparison and judgment, the compression parameters are dynamically adjusted according to the judgment result, the compression blindness can be avoided, the pictures meeting the preset parameter information requirements are output, the success rate of picture identification is improved, and the user experience is improved.

In a second aspect, an embodiment of the present invention provides a picture compression apparatus, which may include:

the device comprises an acquisition unit, a compression unit and a compression unit, wherein the acquisition unit is used for acquiring first parameter information and preset second parameter information of a picture to be compressed;

the first processing unit is used for comparing the first parameter information with the preset second parameter information to obtain a first comparison result; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture;

the second processing unit is used for acquiring third parameter information of the compressed picture and comparing the third parameter information with the preset second parameter information to obtain a second comparison result; if the second comparison result does not meet a second preset condition, adjusting the compression parameter according to the second comparison result, compressing the compressed picture according to the adjusted compression parameter, repeating the processes of comparison, adjustment and compression until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed.

According to the embodiment of the invention, firstly, the parameter information of the picture to be compressed and the preset parameter information are obtained through the obtaining unit, then the two sets of parameter information are compared through the first processing unit, if the result of the first comparison does not meet the condition, the picture to be compressed is subjected to first round of compression after the compression parameters are determined according to the result of the first comparison, and the compressed picture is obtained. Then, the parameter information of the compressed picture is compared with preset parameter information through a second processing unit, and if the picture after the first round of compression still does not meet the condition, the compression parameters are readjusted according to a new comparison result; and finally, the second processing unit compresses the compressed picture according to the adjusted compression parameters, and repeats the processes of comparison, adjustment and compression until the finally output picture meets the requirements. In the process of each compression, the compression parameters are dynamically determined according to the comparison result of each time, namely, the compression parameters of each time are not set in advance (namely, are not fixed) but are more matched with the current picture compression condition, so that the picture can be prevented from being compressed excessively; and based on the mechanisms of multiple comparison, multiple adjustment and multiple compression, repeated iteration can reduce the times of user operation and improve the user experience. In other words, in the picture compression process, the embodiment of the invention allows multiple comparisons, multiple adjustments of compression parameters (and the parameters are dynamically adjusted according to the current comparison result), and multiple compression until the preset conditions are reached, and then outputs the picture meeting the preset parameter information requirements, so that excessive compression can be prevented, the success rate of picture identification is improved, and the user experience is improved.

In one possible implementation, the compression parameters include a compression coefficient and a quality coefficient; wherein the compression coefficients are used for compressing for pixel width and height of a picture and the quality coefficients are used for compressing for pixel quality of the picture.

In a possible implementation manner, the first processing unit is specifically further configured to:

and if the first comparison result meets a first preset condition, outputting the picture to be compressed.

In a possible implementation manner, the second processing unit is specifically further configured to:

and if the second comparison result meets a second preset condition, outputting a target picture corresponding to the picture to be compressed.

In a possible implementation manner, the first parameter information includes one or more of first pixel width and height information of the picture to be compressed, first pixel quality information of the picture to be compressed, and a first number of bytes of a memory occupied by the picture to be compressed; the preset second parameter information comprises one or more of a maximum value and a minimum value of the number of bytes of a preset memory; the third parameter information includes one or more of second pixel width and height information of the compressed picture, second pixel quality information of the compressed picture, and a third memory byte number occupied by the compressed picture.

In a possible implementation manner, the first parameter information includes a number of bytes of the first memory; the second parameter information comprises the maximum value of the preset memory byte number;

the first processing unit is specifically configured to:

and calculating a first difference value between the first memory byte number and the preset maximum value of the second memory byte number to obtain the first comparison result, wherein the first comparison result comprises the first difference value.

In a possible implementation manner, the first processing unit is specifically configured to:

if the first difference value is smaller than or equal to a first preset value, outputting the picture to be compressed; and if the first difference is larger than the first preset value, determining the compression parameters according to the first difference through a preset index relation table, and compressing the picture to be compressed according to the compression parameters to obtain a compressed picture.

In a possible implementation manner, the third parameter information includes a number of bytes of the third memory; the second parameter information also comprises the minimum value of the number of bytes of the preset second memory;

the second processing unit is specifically configured to:

calculating the difference between the third memory byte number occupied by the compressed picture and the preset second memory byte number maximum value to obtain a second difference value; calculating a difference value between the third memory byte number occupied by the compressed picture and the preset second memory byte number minimum value to obtain a third difference value; and obtaining the second comparison result, wherein the second comparison result comprises the second difference and the third difference.

In a possible implementation manner, the target picture corresponding to the picture to be compressed includes the compressed picture, the picture before the current compression, or the picture after the last compression;

the second processing unit is specifically configured to:

if the second difference value is smaller than or equal to a second preset value and the third difference value is larger than or equal to a third preset value, outputting the compressed picture; if the second difference value is smaller than the second preset value and the third difference value is smaller than the third preset value, outputting the picture before the current compression; if the second difference is larger than the second preset value, adjusting the compression parameters through the preset index relation table according to the second difference; and if the compression times reach the preset compression times and the second difference value is still larger than the second preset value, outputting the picture after the last compression.

In a third aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes a processor, and the processor is configured to support the electronic device to implement a corresponding function in the picture compression method provided in the first aspect. The electronic device may also include a memory, coupled to the processor, that stores program instructions and data necessary for the electronic device. The electronic device may also include a communication interface for the electronic device to communicate with other devices or a communication network.

In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium for storing computer software instructions for a processor in a picture compression apparatus provided in the second aspect, which includes a program designed to execute the above aspects.

In a fifth aspect, an embodiment of the present invention provides a chip system, where the chip system includes a processor, configured to enable a device to implement the functions referred to in the first aspect, for example, to generate or process information referred to in the above picture compression method. In one possible design, the system-on-chip further includes a memory for storing program instructions and data necessary for the device. The chip system may be constituted by a chip, or may include a chip and other discrete devices.

Drawings

In order to more clearly illustrate the technical solutions in the embodiments or the background art of the present invention, the drawings required to be used in the embodiments or the background art of the present invention will be described below.

Fig. 1 is a flowchart illustrating a picture compression method.

Fig. 2a is a schematic flowchart of a picture compression method according to an embodiment of the present invention.

Fig. 2b is a schematic flowchart of another picture compression method according to an embodiment of the present invention.

Fig. 3 is a schematic diagram of a determination process of a picture compression method according to an embodiment of the present invention.

Fig. 4 is a schematic structural diagram of a picture compression apparatus according to an embodiment of the present invention.

Fig. 5 is a schematic structural diagram of another picture compression apparatus according to an embodiment of the present invention.

Detailed Description

The embodiments of the present invention will be described below with reference to the drawings.

The terms "first," "second," "third," and "fourth," etc. in the description and claims of this application and in the accompanying drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.

Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.

As used in this specification, the terms "component," "module," "system," and the like are intended to refer to a computer-related entity, either hardware, firmware, a combination of hardware and software, or software in execution. For example, a component may be, but is not limited to being, a process running on a processor, an object, an executable, a thread of execution, a program, and/or a computer. By way of illustration, both an application running on a computing device and the computing device can be a component. One or more components can reside within a process and/or thread of execution and a component can be localized on one computer and/or distributed between 2 or more computers. In addition, these components can execute from various computer readable media having various data structures stored thereon. The components may communicate by way of local and/or remote processes such as in accordance with a signal having one or more data packets (e.g., data from two components interacting with another component in a local system, distributed system, and/or across a network such as the internet with other systems by way of the signal).

First, some terms in the present application are explained so as to be easily understood by those skilled in the art.

(1) And compressing the compression coefficient, reducing the number of memory bytes occupied by the picture by reducing the number of the width and the height of the picture pixels, and ensuring that the quality of each pixel is not reduced.

(2) And (3) compressing the quality coefficient, reducing the number of bytes of memory occupied by the picture by reducing the quality of each pixel of the picture, and not reducing the number of the width and the height of the pixel.

First, the technical problems to be specifically solved by the present application are analyzed and presented. In the prior art, the technique related to picture compression includes the following scheme one:

the first scheme is as follows: referring to fig. 1, fig. 1 is a schematic flow chart of a picture compression method, which may specifically include the following steps S100 to S102:

and S100, acquiring parameter information of the picture to be compressed.

Step S101, a user gives compression parameters.

And S102, compressing the picture to be compressed according to the given compression parameters.

This solution has several disadvantages:

disadvantage 1: the compression parameters are randomly given by a user, and the situation of over-compression is easy to occur.

And (2) disadvantage: and only once compression is carried out, the specific compression result is judged by the user whether to meet the requirement, if not, the user needs to give a new compression parameter again at random, and then compression and judgment are carried out again. The linear proportion relation does not exist between the compression parameters and the change of the number of bytes of the memory occupied before and after the picture compression. The recompressed picture may still be unsatisfactory, and when the recompressed picture is applied to a picture recognition scene, the probability that the picture is successfully recognized is low. The user needs to perform multiple compression operations, and the user experience is poor.

In order to solve the problem that the current picture compression technology can not meet the actual use requirements of users, avoid excessive compression, reduce user operation, output the pictures meeting the requirements, improve the success rate of picture identification, promote user experience's purpose, comprehensively consider the shortcomings of the prior art, the technical problem that this application will actually solve includes following several aspects:

1. a more reasonable compression parameter determination mechanism (drawback 1 of scheme one). In the first scheme, the compression parameters are randomly given by a user, and the problem of recovering the picture compression is partially solved. However, situations of over-compression are prone to occur, which severely degrade the user experience. Therefore, a more reasonable compression parameter determination mechanism is needed to be provided, so that the picture can be prevented from being compressed excessively, the picture meeting the requirements is output, and the user experience is improved.

2. Adding a judgment mechanism and adjusting the compression mechanism multiple times based on the judgment (disadvantage 2 of the first scheme). In the first scheme, only one compression is performed, whether the specific compression result meets the requirement is judged by the user, if not, the user needs to give a new compression parameter again, and then the compression and the judgment are performed again. Therefore, a judgment mechanism and a multiple compression mechanism based on the judgment mechanism are needed, so that the number of times of compression operations of a user is reduced, and the user experience is improved.

In summary, the existing picture compression scheme cannot meet the higher requirements of users on the use experience. Therefore, the picture compression method provided by the present application is used for solving the above technical problems.

In order to facilitate understanding of the embodiments of the present invention, the following examples illustrate a scene to which the picture compression method in the present application is applied. For example, the picture compression method in the present application can be applied to a picture recognition scene of an online platform.

Scene recognition of the online platform:

the online platform has a requirement on the number of bytes in memory of the picture to be identified (i.e. the picture uploaded by the user). For example, when a user needs to complete an entry process of an examination through an online platform, the online platform needs the user to upload a close picture of the user for identity authentication. At this time, the online platform requires that the number of memory bytes occupied by the picture uploaded by the user is less than 3M and greater than 1M, but the user only has a personal photograph with the number of memory bytes of 26M as the picture to be compressed. If the user directly uploads the picture to be compressed to the online platform for identification and authentication, the result of identification failure can be obtained because the requirement of the online platform is not met. Therefore, the user needs to compress the picture to be compressed to meet the requirement of the number of bytes in the memory of the online platform, and can successfully finish the picture identification, thereby finishing the registration process of a certain examination.

Based on the technical problems mentioned above and the corresponding application scenarios in the present application, and also for facilitating understanding of the embodiments of the present invention, the following description is made with reference to fig. 2a and 2b and fig. 3. Referring to fig. 2a and fig. 2b and fig. 3, fig. 2a is a schematic flow chart of a picture compression method according to an embodiment of the present invention, fig. 2b is a schematic flow chart of another picture compression method according to an embodiment of the present invention, and fig. 3 is a schematic flow chart of a determination of a picture compression method according to an embodiment of the present invention. Referring to fig. 2a, the picture compression method in the present application may include the following steps S200 to S204:

step S200: acquiring first parameter information and preset second parameter information of a picture to be compressed.

Specifically, the first parameter information of the picture to be compressed may be one or more of first pixel width and height information of the picture to be compressed, first pixel quality information of the picture to be compressed, and a first memory byte count occupied by the picture to be compressed; the preset second parameter information may be one or more of a maximum value and a minimum value of the number of bytes of the memory. As an example of the above online platform picture identification, wherein the number of memory bytes occupied by the picture to be compressed is 26M, the pixel width and height information may be 788 pixels × 1000 pixels, and the pixel quality information may be a bit depth, for example, the bit depth is 32, and the picture 201 in fig. 2b may be the picture to be compressed; the requirement of the preset second parameter information (i.e. the requirement of the online platform on the picture uploaded by the user) for the number of bytes in the memory is less than 3M and greater than 1M. Alternatively, the pixel quality information may be a pixel density, which is not illustrated here.

Step S201: and comparing the first parameter information of the picture to be compressed with the preset second parameter information to obtain a first comparison result.

Specifically, the first difference may be obtained by calculating a difference between the number of memory bytes occupied by the picture to be compressed and a maximum value of the number of preset memory bytes. As in the example above, the first difference is 23M.

Step S202: and judging the first comparison result, determining an output picture or determining compression parameters according to the judgment result, and compressing the picture.

Specifically, the first difference is determined, and the detailed determination logic can refer to fig. 3. If the first difference value is smaller than or equal to a first preset value, outputting the picture to be compressed; if the first difference is larger than a first preset value, determining a compression parameter through a preset index relation table according to the first difference; and compressing the picture to be compressed according to the compression parameters to obtain a compressed picture, such as the picture 202 in fig. 2 b. The compression parameters may include a compression coefficient and a quality coefficient, the compression coefficient is used for compressing the pixel width and the height of the picture, and the quality coefficient is used for compressing the pixel quality of the picture. The first preset value may be 0, and it is understood that the first preset value may also be set to other values, which are not specifically limited herein.

Alternatively, the following principle may be referred to when setting the index relationship table: when the difference of the byte number of the memory is larger, a smaller compression coefficient and a smaller quality coefficient need to be set, so that the byte number of the memory occupied by the compressed picture can be greatly reduced compared with the picture before compression, and therefore the picture meeting the requirements can be quickly obtained; when the difference of the byte number of the memory is smaller, a larger compression coefficient and a larger quality coefficient need to be set, so that the memory byte number occupied by the compressed picture can be reduced in a small amplitude compared with the picture before compression, and the picture can be effectively prevented from being compressed excessively. For ease of understanding, embodiments of the present invention illustratively provide an index relationship table for reference, see the following table.

Index relation table

Compression level Difference (X) Coefficient of compression Coefficient of mass
Super large X is 30M larger 0.4 0.4
Big (a) 30>X≥20M 0.5 0.5
In general 20>X010M 0.6 0.5
Small 10>X05M 0.7 0.7
Light and slight 5 > X micro 1M 0.8 0.7
Conservative 1>X 0.8 1 (not compressed)

In the table, different compression levels are defined according to different difference ranges, and six compression levels from high to low are respectively super-large, common, small, slight and conservative. Wherein, the larger the difference value is, the higher the compression grade is, and the corresponding compression coefficient and quality coefficient are also smaller. As in the above example, when the first difference is 23M, the corresponding compression level is large compression, and the compression coefficient is 0.5 and the quality coefficient is 0.5, which are determined by the correspondence in the preset index relationship table. Then, the picture to be compressed with the memory byte number of 26M is compressed according to the compression coefficient of 0.5 and the quality coefficient of 0.5. Wherein ≧ represents greater than or equal to; > means greater than; the predetermined index relationship table may be determined through a plurality of experiments.

It should be noted that the number of memory bytes in the preset second parameter information may be a range value, and if the number of memory bytes occupied by the picture to be compressed meets the requirement of the preset range value of the second parameter information, the picture will not be compressed.

Step S203: and comparing the third parameter information of the compressed picture with the preset second parameter information to obtain a second comparison result.

Specifically, calculating a difference value between the number of memory bytes occupied by the compressed picture and the maximum value of the number of the preset second memory bytes to obtain a second difference value; and calculating the difference value between the number of memory bytes occupied by the compressed picture and the preset second memory byte number minimum value to obtain a third difference value. As in the above example, assuming that the compressed picture (the picture 202 in fig. 2 b) occupies 10M memory bytes, the pixel width is 394 × 500 pixels, the bit depth is 24, and the memory byte number of the preset second parameter information is required to be less than 3M and greater than 1M, the difference between the maximum value of the memory byte numbers in the compressed picture and the preset second parameter information is 7M, and the difference between the minimum value of the memory byte numbers in the preset second parameter information is 9M, that is, the second difference is 7M, and the third difference is 9M.

Step S204: and judging a second comparison result, determining an output picture or adjusting compression parameters and compressing the picture according to the judgment result, and repeating the comparison, adjustment and compression processes until a second preset condition is reached.

Specifically, the second difference value and the third difference value are determined, and the detailed determination logic may refer to fig. 3. If the second difference is smaller than or equal to a second preset value and the third difference is larger than or equal to a third preset value, outputting the compressed picture; if the second difference value is smaller than a second preset value and the third difference value is smaller than a third preset value, outputting the picture before the current compression; if the second difference is larger than a second preset value, adjusting the compression parameters through a preset index relation table according to the second difference; and performing secondary compression on the compressed picture according to the adjusted compression parameters to obtain a secondary compressed picture, such as the picture 203 in fig. 2b, repeating the steps of comparing, adjusting and compressing until a second preset condition is reached, and outputting a target picture corresponding to the picture to be compressed. The second preset value may be 0, and the third preset value may also be 0. As in the above example, when the second difference is 7M and the third difference is 9M, and the second difference is greater than the second preset value 0, it is determined that the compressed picture still does not meet the requirement of the preset second parameter information on the number of bytes in the memory, and the compressed picture needs to be compressed for the second time. And adjusting the compression coefficient and the quality coefficient through the index relation table according to the second difference. At this time, the compression level corresponding to the second difference value of 7M should be small compression, and the compression coefficient is determined to be 0.7 and the quality coefficient is determined to be 0.7 through the mapping relationship in the preset mapping relationship table, which can be referred to as the above index relationship. It is understood that the second preset value and the third preset value can be set to other values, and are not limited in detail.

The compressed picture is again subjected to a small compression according to the compression coefficient of 0.7 and the quality coefficient of 0.7, resulting in a picture after a second compression (picture 203 in fig. 2 b). For example, the picture after the second compression (the picture 203 in fig. 2 b) occupies 2.5M bytes of memory, the pixel width is 276 pixels by 350 pixels, and the bit depth is 16. Comparing the number of bytes of memory occupied by the secondarily compressed picture with the requirement of the target picture, wherein 2.5M is less than 3M, 2.5M is greater than 1M, the secondarily compressed picture is considered to meet the requirement of the target picture, and the secondarily compressed picture is output. It should be noted that, if the picture after the secondary compression still does not meet the requirement of the preset second parameter information, the comparison is continued, the compression coefficient and the quality coefficient are adjusted again according to the above index relationship table according to the comparison result, and then the new compression coefficient and the quality coefficient are used to re-compress the picture after the secondary compression until a second difference obtained by comparing the picture finally compressed with the preset second parameter information is less than or equal to 0, or the compression frequency reaches the set upper limit of the compression frequency, and the detailed judgment logic may refer to fig. 3. For example, the upper limit of the number of compression times may be set to 4, and when a second difference between the picture obtained after the 4 th compression and the preset second parameter information is still greater than 0, the picture obtained after the 4 th compression (the picture 205 in fig. 2 b) is output, so as to avoid the problem of too long waiting time caused by performing more compression times.

Optionally, when the second difference is smaller than the second preset value and the third difference is smaller than the third preset value, it is indicated that the number of memory bytes occupied by the compressed picture is smaller than the minimum value of the number of memory bytes in the preset second parameter information, at this time, the compression coefficient and the quality coefficient may also be adjusted according to the specific value of the third difference, and the adjustment may be completed by referring to the index relationship table. The picture before compression is compressed according to the up-regulated compression coefficient and quality coefficient, and then compared with the number of bytes in the memory in the preset second parameter information, the above processes of comparison, regulation and compression can be referred to, and details are not described here.

In conclusion, the image compression method and the image compression device overcome the defects of excessive compression and repeated operation in the existing image compression technology, can effectively avoid the image from being excessively compressed, achieve the purpose of outputting the image meeting the requirements, improve the success rate of image identification and improve the user experience.

The method of the embodiments of the present invention is explained in detail above, and the related apparatus of the embodiments of the present invention is provided below.

Referring to fig. 4, fig. 4 is a schematic structural diagram of a picture compression apparatus according to an embodiment of the present invention, where the picture compression apparatus 4 may include an obtaining unit 401, a first processing unit 402, and a second processing unit 403, where details of each unit are described as follows.

An obtaining unit 401, configured to obtain first parameter information and preset second parameter information of a picture to be compressed;

a first processing unit 402, configured to compare the first parameter information with the preset second parameter information, so as to obtain a first comparison result; if the first comparison result does not meet a first preset condition, determining a compression parameter according to the first comparison result, and compressing the picture to be compressed according to the compression parameter to obtain a compressed picture;

a second processing unit 403, configured to obtain third parameter information of the compressed picture, and compare the third parameter information with the preset second parameter information to obtain a second comparison result; if the second comparison result does not meet a second preset condition, adjusting the compression parameter according to the second comparison result, compressing the compressed picture according to the adjusted compression parameter, repeating the processes of comparison, adjustment and compression until the second preset condition is reached, and outputting the target picture corresponding to the picture to be compressed.

In one possible implementation, the compression parameters include a compression coefficient and a quality coefficient;

the first processing unit 402 is specifically configured to:

compressing the pixel width and the pixel quality of the picture to be compressed according to the compression coefficient and the quality coefficient;

the second processing unit 403 is specifically configured to:

and compressing the pixel width and the pixel quality of the compressed picture according to the adjusted compression coefficient and the quality coefficient.

In a possible implementation manner, the first processing unit 402 is further specifically configured to:

and if the first comparison result meets a first preset condition, outputting the picture to be compressed.

In a possible implementation manner, the second processing unit 403 is specifically further configured to:

and if the second comparison result meets a second preset condition, outputting a target picture corresponding to the picture to be compressed.

In a possible implementation manner, the obtaining unit 401 is specifically configured to:

acquiring first pixel width and height information of the picture to be compressed, first pixel quality information of the picture to be compressed, one or more of the number of bytes of a first memory occupied by the picture to be compressed and one or more of the maximum value and the minimum value of the number of bytes of a preset memory;

the second processing unit 403 is specifically configured to:

and acquiring one or more of second pixel width and height information of the compressed picture, second pixel quality information of the compressed picture and third memory byte number occupied by the compressed picture.

In a possible implementation manner, the first parameter information includes a number of bytes of the first memory; the second parameter information comprises the maximum value of the preset memory byte number;

the first processing unit 402 is specifically configured to:

and calculating a first difference value between the first memory byte number and the preset maximum value of the second memory byte number to obtain the first comparison result, wherein the first comparison result comprises the first difference value.

In a possible implementation manner, the first processing unit 402 is specifically configured to:

if the first difference value is smaller than or equal to a first preset value, outputting the picture to be compressed; and if the first difference is larger than the first preset value, determining the compression parameters according to the first difference through a preset index relation table, and compressing the picture to be compressed according to the compression parameters to obtain a compressed picture.

In a possible implementation manner, the third parameter information includes a number of bytes of the third memory; the second parameter information also comprises the minimum value of the number of bytes of the preset second memory;

the second processing unit 403 is specifically configured to:

calculating the difference between the third memory byte number occupied by the compressed picture and the preset second memory byte number maximum value to obtain a second difference value; calculating a difference value between the third memory byte number occupied by the compressed picture and the preset second memory byte number minimum value to obtain a third difference value; and obtaining the second comparison result, wherein the second comparison result comprises the second difference and the third difference.

In a possible implementation manner, the target picture corresponding to the picture to be compressed includes the compressed picture, the picture before the current compression, or the picture after the last compression; the second processing unit 403 is specifically configured to:

if the second difference value is smaller than or equal to a second preset value and the third difference value is larger than or equal to a third preset value, outputting the compressed picture; if the second difference value is smaller than the second preset value and the third difference value is smaller than the third preset value, outputting the picture before the current compression; if the second difference is larger than the second preset value, adjusting the compression parameters through the preset index relation table according to the second difference; and if the compression times reach the preset compression times and the second difference value is still larger than the second preset value, outputting the picture after the last compression.

It should be noted that, for the functions of each functional unit in the picture compression apparatus 4 described in the embodiment of the present invention, reference may be made to the related description of step S200 to step S204 in the embodiment of the method described in fig. 2a, which is not described herein again.

As shown in fig. 5, fig. 5 is a schematic structural diagram of another picture compression apparatus according to an embodiment of the present invention, where the apparatus 5 includes at least one processor 501, at least one memory 502, and at least one communication interface 503. In addition, the device may also include common components such as an antenna, which will not be described in detail herein.

The processor 501 may be a general purpose Central Processing Unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of programs according to the above schemes.

Communication interface 503 is used for communicating with other devices or communication Networks, such as ethernet, Radio Access Network (RAN), core network, Wireless Local Area Networks (WLAN), etc.

The Memory 502 may be, but is not limited to, a Read-Only Memory (ROM) or other type of static storage device that can store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that can store information and instructions, an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Compact Disc Read-Only Memory (CD-ROM) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. The memory may be self-contained and coupled to the processor via a bus. The memory may also be integral to the processor.

The memory 502 is used for storing application program codes for executing the above-mentioned picture compression method, and is controlled by the processor 501 to execute the application program codes. The processor 501 is used to execute application program code stored in the memory 502.

The code stored in the memory 502 may perform the picture method provided in fig. 2a, such as obtaining first parameter information and preset second parameter information of a picture to be compressed; comparing first parameter information of a picture to be compressed with preset second parameter information to obtain a first comparison result; judging the first comparison result, determining an output picture or determining compression parameters according to the judgment result and compressing the picture; comparing the third parameter information of the compressed picture with the preset second parameter information to obtain a second comparison result; and judging a second comparison result, determining an output picture or adjusting compression parameters and compressing the picture according to the judgment result, and repeating the comparison, adjustment and compression processes until a second preset condition is reached.

It should be noted that, for the functions of each functional unit in the picture compression apparatus 5 described in the embodiment of the present invention, reference may be made to the related description of step S200 to step S204 in the embodiment of the method described in fig. 2a, and details are not repeated here.

In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.

It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.

In the embodiments provided in the present application, it should be understood that the disclosed apparatus may be implemented in other manners. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the above-described division of the units is only one type of division of logical functions, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of some interfaces, devices or units, and may be an electric or other form.

The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.

In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.

The integrated unit may be stored in a computer-readable storage medium if it is implemented in the form of a software functional unit and sold or used as a separate product. Based on such understanding, the technical solution of the present application may be substantially implemented or a part of or all or part of the technical solution contributing to the prior art may be embodied in the form of a software product stored in a storage medium, and including several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, and may specifically be a processor in the computer device) to execute all or part of the steps of the above-mentioned method of the embodiments of the present application. The storage medium may include: various media capable of storing program codes, such as a usb disk, a removable hard disk, a magnetic disk, an optical disk, a Read-only memory (ROM) or a Random Access Memory (RAM).

The above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

21页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:图像处理方法、装置、电子设备和计算机可读存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!