Image encoding and decoding methods, electronic devices, and computer-readable storage media

By using reference images and motion detection results in image encoding to select the processing method, and only some areas containing the moving targets are encoded, the problem of low encoding compression rate and efficiency in the prior art is solved, and more efficient image encoding and decoding is achieved.

CN115022641BActive Publication Date: 2025-06-13ZHEJIANG DAHUA TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210580450.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-25
Publication Date
2025-06-13
Estimated Expiration
2042-05-25

AI Technical Summary

Technical Problem

The existing image encoding methods are not compressible and efficient when encoding, especially in scenarios containing motion targets.

Method used

By obtaining the reference image detection result and motion detection result of the current image, the processing method is selected: when there is a reference image and the moving target exists, only a part of the area containing the moving target is encoded, and a matching flag bit is set.

Benefits of technology

The encoding compression rate and efficiency are improved, the encoding consumption of the moving target scene is reduced, and the decoding sub-regions are superimposed during the decoding process to obtain a complete image, thereby improving the decoding efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115022641B_ABST
    Figure CN115022641B_ABST
Patent Text Reader

Abstract

The present application discloses an image encoding and decoding method, an electronic device, and a computer-readable storage medium. The method includes: obtaining a current image and determining a reference image detection result of the current image; in response to the reference image detection result indicating that there is a reference image, obtaining a motion detection result and selecting a processing method based on the motion detection result to process the current image; wherein the reference image is an image after frame-by-frame encoding, and when the motion detection result indicates that there is a moving target, the processing method is to encode at least a partial region of the current image, and the partial region includes the moving target; setting a flag bit matching the processing method for the processed current image. The above solution can improve the encoding compression ratio and encoding efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image encoding and decoding technologies, and particularly to an image encoding and decoding method, an electronic device, and a computer-readable storage medium. Background Art

[0002] As the image or video quality captured by a camera device becomes higher and higher, higher requirements are put forward for the compression ratio during image encoding. Existing image encoding methods usually encode images within an image based on spatial domain redundancy features. When encoding within an image, each complete image needs to be encoded sequentially, resulting in low encoding compression ratio and encoding efficiency. In view of this, how to improve the encoding compression ratio and encoding efficiency has become an urgent problem to be solved. Summary of the Invention

[0003] The main technical problem to be solved by this application is to provide an image encoding and decoding method, an electronic device, and a computer-readable storage medium, which can improve the encoding compression ratio and encoding efficiency.

[0004] To solve the above technical problem, in a first aspect of this application, an image encoding method is provided. The method includes: obtaining a current image, and determining a reference image detection result of the current image; in response to the reference image detection result indicating that there is a reference image, obtaining a motion detection result and selecting a processing method based on the motion detection result to process the current image; where the reference image is an image encoded as a whole frame, and when the motion detection result indicates that there is a moving target, the processing method is to encode at least a partial region of the current image, and the partial region includes the moving target; setting a flag bit matching the processing method for the processed current image.

[0005] To solve the above technical problem, in a second aspect of this application, an image decoding method is provided, which is applied to the image encoding method described in the first aspect above. The method includes: obtaining a current image to be decoded, and determining the processing method of the current image based on a flag bit matching the processing method; in response to the processing method being to encode at least a partial region of the current image, decoding the encoded region to obtain a decoded sub-region, and superimposing the timestamp corresponding to the current image and the decoded sub-region onto the corresponding position on the reference image corresponding to the current image to obtain a decoded current image, and using the decoded current image as a new reference image.

[0006] To solve the above technical problem, in a third aspect of this application, an electronic device is provided. The electronic device includes: a memory and a processor coupled to each other, where the memory stores program data, and the processor calls the program data to execute the method described in the first aspect or the second aspect above.

[0007] To solve the above technical problems, a fourth aspect of the present application provides a computer storage medium, on which program data is stored, and when the program data is executed by a processor, the method described in the first aspect or the second aspect above is implemented.

[0008] In the above solution, after obtaining the current image, the reference image detection result of the current image is determined in the current image. Among them, the reference image is the image after frame-by-frame encoding. When the reference image detection result is that there is a reference image, the motion detection result is obtained and the processing method is selected based on the motion detection result to process the current image. When the motion detection result is that there is a moving target, and the processing method is to encode at least part of the region of the current image, it is possible to only encode at least part of the region including the moving target, improve the encoding compression ratio, and for a scene with a moving target, effectively reduce the encoding consumption and thus improve the encoding efficiency. During the decoding process, the encoded partial region is decoded and then superimposed on the decoded reference image, and the complete image corresponding to the image with the processing method of encoding at least part of the region can be obtained, thereby improving the decoding efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. Among them:

[0010] Figure 1 is a flowchart of an embodiment of the image encoding method of the present application;

[0011] Figure 2 is a flowchart of another embodiment of the image encoding method of the present application;

[0012] Figure 3 is Figure 2 a flowchart of an embodiment corresponding to step S203 in

[0013] Figure 4 is Figure 2 a schematic diagram of an application scenario corresponding to step S204 in

[0014] Figure 5 is Figure 2 a schematic diagram of another application scenario corresponding to step S204 in

[0015] Figure 6 is a flowchart of an embodiment of the image decoding method of the present application;

[0016] Figure 7It is a schematic structural diagram of an embodiment of the electronic device of the present application;

[0017] Figure 8 It is a schematic structural diagram of an embodiment of the computer-readable storage medium of the present application. Specific embodiments

[0018] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0019] The terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article only describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article generally represents an "or" relationship between the associated objects before and after. In addition, "multiple" in this article means two or more than two.

[0020] In this article, the original data of an image includes, but is not limited to, YUV and RGB data, and the image formats corresponding to the encoded images include, but are not limited to, jpeg, jpg, and png formats. The image encoding method provided by the present application is used to encode the original data of an image into a file in an image format. Among them, the original data of an image can be a video frame extracted from video data or an image arranged in sequence. The image decoding method provided by the present application is used to decode the file in the image format into the original data of the image for display.

[0021] Please refer to Figure 1 , Figure 1 It is a schematic flowchart of an embodiment of the image encoding method of the present application. The method includes:

[0022] S101: Obtain the current image and determine the reference image detection result of the current image.

[0023] Specifically, obtain the current image to be encoded, and perform reference image detection on the current image to determine the reference image detection result of the current image. Among them, the reference image detection result includes no reference image and there is a reference image. The reference image is an image that has been completely encoded and whose time sequence is before the current image.

[0024] In an application mode, after the reference image is referred to once, the usage count value corresponding to the reference image is incremented once and reset to zero after reaching the count threshold. Based on the usage count value, it is determined whether there is a reference image that has been completely encoded and available for the current image to refer to before the current image, so as to obtain the reference image detection result of the current image.

[0025] In an application scenario, the reference image is an image that has been completely encoded. When the reference image is reused, the usage count value corresponding to the reference image is incremented. When the usage count value exceeds the count threshold, it is determined that the current image has no reference image, so as to perform full-frame encoding on the current image subsequently, thereby avoiding the reuse of the same reference image too many times, improving the coding compression rate while reducing the probability of poor image quality after coding.

[0026] S102: In response to the reference image detection result indicating that there is a reference image, obtain the motion detection result and select a processing method based on the motion detection result to process the current image. Among them, the reference image is an image after full-frame encoding. When the motion detection result indicates that there is a moving target, the processing method is to encode at least a part of the current image, and the part includes the moving target.

[0027] Specifically, when the reference image detection result indicates that there is a reference image, obtain the motion detection result, where the motion detection result includes no moving target and there is a moving target.

[0028] Furthermore, the reference image is an image after full-frame encoding. When the motion detection result indicates that there is a moving target, the processing method is to encode at least a part of the current image, and the part includes the moving target. That is to say, when the current image includes a moving target, the processing method is to encode at least a part of the current image, and the part includes the moving target.

[0029] Optionally, when the current image does not include a moving target, the processing method is to reuse the reference image corresponding to the current image.

[0030] In an application mode, when the motion detection result is no moving target and there is a reference image, the processing method can be selected as reusing the reference image corresponding to the current image and incrementing the usage count value of the reference image once. When the motion detection result is there is a moving target and there is a reference image, the processing method can be selected as encoding at least a part of the current image and incrementing the usage count value of the reference image once, so as to select a matching processing method based on the combination of different motion detection results and reference image detection results.

[0031] Further, when the motion detection result indicates the presence of a moving object, when encoding a partial area on the current image, the partial area includes the moving object. Thus, by combining the encoded partial area and the reference image, the complete picture of the image can be decoded and the status of the moving object can be fed back.

[0032] S103: Set a flag bit matching the processing method for the processed current image.

[0033] Specifically, based on the combination of different motion detection results and reference image detection results, a matching processing method is selected, and each processing method corresponds to a matching flag bit. After selecting the processing method, set the flag bit matching the processing method for the current image, so as to facilitate determining the processing method of any image during encoding during decoding and improve the decoding efficiency.

[0034] Further, during the decoding process, after decoding the encoded partial area and superimposing it on the decoded reference image, the complete image corresponding to the image whose processing method is to encode at least a partial area can be obtained, thereby reducing the decoding processing amount to improve the decoding efficiency.

[0035] In an application scenario, the reference image is the image after encoding the entire frame. When the processing method of the image is to follow the reference image or encode at least a partial area of the current image, the usage count value of the reference image corresponding to the image needs to be incremented. When the usage count value of the reference image is incremented and exceeds the count threshold, the image is encoded again as a whole to obtain a new reference image. Therefore, when the usage count value exceeds the count threshold or the image is the first image to be encoded, it is considered that the reference image detection result of the current image is no reference image.

[0036] Further, determine whether the reference image detection result corresponds to a reference image. If the reference image detection result is no reference image, encode the current image as a whole so that the entire current image is encoded as a new reference image. If the reference image detection result is a reference image, further determine whether the motion detection result corresponds to a moving object. If the motion detection result is no moving object, follow the reference image corresponding to the current image. If the motion detection result is a moving object, encode the partial area corresponding to the object that has moved in the current image, thereby effectively reducing the encoding amount of image encoding and improving the encoding compression ratio and encoding efficiency when there is a reference image for the current image.

[0037] In the above solution, after obtaining the current image, the reference image detection result of the current image is determined in the current image. Herein, the reference image is the image after whole-frame encoding. When the reference image detection result indicates the existence of a reference image, the motion detection result is obtained, and a processing method is selected based on the motion detection result to process the current image. When the motion detection result indicates the existence of a moving target and the processing method is to encode at least a partial region of the current image, only the at least partial region including the moving target can be encoded, thereby improving the encoding compression ratio. For a scene with a moving target, the encoding consumption can be effectively reduced, thus improving the encoding efficiency. During the decoding process, the encoded partial region is decoded and then superimposed on the decoded reference image, and thus the complete image corresponding to the image whose processing method is to encode at least a partial region can be obtained, thereby improving the decoding efficiency.

[0038] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of another implementation manner of the image encoding method of the present application. The method includes:

[0039] S201: Obtain the current image and determine the reference image detection result of the current image.

[0040] Specifically, if the current image is the initial image of the entire video data, the reference image detection result of the current image is that there is no reference image. If the most recently completely encoded image before the current image in the time sequence is lost, the reference image detection result of the current image is that there is no reference image.

[0041] S202: In response to the reference image detection result indicating no reference image, select the processing method to perform whole-frame encoding on the current image, and use the current image after whole-frame encoding as the new reference image.

[0042] Specifically, when the reference image detection result indicates no reference image, select the processing method to perform whole-frame encoding on the current image, use the encoding algorithm to encode the entire picture of the current image, and use the current image after whole-frame encoding as the new reference image.

[0043] Further, when the reference image corresponds to a usage count value, the usage count value of the new reference image is cleared while obtaining the new reference image.

[0044] In an application manner, when the reference image detection result indicates no reference image, select the processing method to perform whole-frame encoding on the current image, use the encoding algorithm to encode the entire picture of the current image, use the current image after whole-frame encoding as the new reference image, and simultaneously set the usage count value of the new reference image to zero.

[0045] S203: In response to the reference image detection result indicating the existence of a reference image, obtain the motion detection result.

[0046] Specifically, please refer to Figure 3 , Figure 3 which Figure 2 is a schematic flowchart of an implementation manner corresponding to step S203 in

[0047] S301: Divide the current image into multiple macroblocks, and determine the sub-block detection results corresponding to each macroblock.

[0048] Specifically, after obtaining the current image, divide the current image into multiple macroblocks, perform motion detection on each macroblock, and thus determine the sub-block detection results corresponding to each macroblock.

[0049] In an application scenario, after obtaining the current image, divide the current image into multiple macroblocks according to the pixel size. Among them, the pixel size of the macroblocks at the edge positions of the current image is adaptively adjusted, and the pixel size of the macroblocks at non-edge positions of the current image is a preset pixel value. Perform motion detection on each macroblock, and thus output the motion detection flag bits corresponding to the motion detection results within each macroblock. Obtain the sub-block detection results of each macroblock based on the motion detection flag bits of each macroblock. Among them, the sub-block detection results are that there is a moving target and there is no moving target. The macroblocks with moving targets are motion macroblocks. By dividing the current image into multiple macroblocks for judgment, the fineness and accuracy of the judgment are improved.

[0050] S302: In response to the current image including at least one motion macroblock whose sub-block detection result is that there is a moving target, determine that the motion detection result corresponding to the current image is that there is a moving target.

[0051] Specifically, if there is at least one motion macroblock in the current image whose sub-block detection result is that there is a moving target, then determine that the motion detection result corresponding to the current image is that there is a moving target.

[0052] S303: In response to the sub-block detection results corresponding to all macroblocks of the current image being that there is no moving target, determine that the motion detection result corresponding to the current image is that there is no moving target.

[0053] Specifically, if the sub-block detection results of all macroblocks in the current image are motion macroblocks with no moving target, then determine that the motion detection result corresponding to the current image is that there is no moving target.

[0054] S204: In response to the motion detection result being that there is no moving target, select the processing method as to continue to use the reference image corresponding to the current image, extract the timestamp of the current image, and increment the usage count value corresponding to the reference image.

[0055] Specifically, when the motion detection result is no moving target and the reference frame detection result is a reference frame, select the encoding method as using the reference frame corresponding to the current frame, extract the timestamp in the current frame from the current frame for saving, and increment the usage count value corresponding to the reference frame on the existing basis.

[0056] S205: In response to the motion detection result being a moving target, select the processing method as encoding at least part of the current image, so as to extract at least the region corresponding to the moving target that has occurred from the current image for encoding and increment the usage count value corresponding to the reference image.

[0057] Specifically, when the motion detection result is a moving target and the reference image detection result is a reference image, select the processing method as encoding at least part of the current image, extract the region corresponding to the moving target that has occurred in the current image or extract the region corresponding to the moving target that has occurred and its surrounding regions for partial encoding, so that only partial encoding is performed when there is a moving target in the current image. Since only partial encoding is performed, the partially encoded image needs to be decoded by superimposing the reference image during decoding. Therefore, when selecting the processing method as encoding at least part of the current image, increment the usage count value corresponding to the reference image.

[0058] In an application mode, the step of encoding at least part of the current image includes: determining the motion boundary region corresponding to the motion macroblock, expanding the motion boundary region outward by a preset macroblock step size to obtain the region to be cropped; determining the position information of the region to be cropped in the current image, and encoding the region to be cropped in the current image based on the encoding parameters matching the position information.

[0059] Specifically, when determining the motion detection result of the current image, divide the current image into multiple macroblocks. When performing partial encoding on the current image, drive the motion boundary corresponding to the motion macroblock based on the position of the motion macroblock, and expand the motion boundary region outward according to the preset macroblock step size to obtain the region to be cropped, thereby expanding the range of partial encoding and improving the fault tolerance rate for judging the motion boundary region to ensure that the moving target is within the region to be cropped.

[0060] Furthermore, determine the position information of the region to be cropped in the current image, adjust the encoding parameters, and encode the region to be cropped in the current image after making the encoding parameters match the position information of the region to be cropped.

[0061] In an application scenario, the steps of determining the motion boundary region corresponding to a motion macroblock and expanding the motion boundary region outward by a preset macroblock step size to obtain a region to be matte-extracted include: in response to the distance between any motion macroblock and the nearest motion macroblock being within the distance threshold, determining the motion boundary region based on all motion macroblocks; in response to the distance between at least two motion macroblocks and the nearest motion macroblock exceeding the distance threshold, dividing all motion macroblocks into at least two motion macroblock aggregation regions based on the distance threshold, and respectively determining the motion boundary regions corresponding to the motion macroblock aggregation regions.

[0062] Specifically, it is judged whether the distance between any one motion macroblock and the nearest motion macroblock is within the distance threshold. If the distances between all motion macroblocks and the nearest motion macroblocks are within the distance threshold, the motion boundary region is determined based on all motion macroblocks, thereby obtaining a region to be matte-extracted. If the distances between at least two motion macroblocks and the nearest motion macroblock exceed the distance threshold, the motion macroblocks are divided according to the distance threshold to obtain at least two motion macroblock aggregation regions. Among them, when there are N motion macroblocks whose distances from the nearest motion macroblock exceed the distance threshold, N motion macroblock aggregation regions are obtained. Each motion macroblock aggregation region includes at least one motion macroblock. The motion boundary regions are determined based on each motion macroblock aggregation region, thereby obtaining the regions to be matte-extracted corresponding to each motion boundary region. When the motion macroblocks are far apart, partial encoding is performed separately on different motion macroblock aggregation regions, thereby reducing the encoding amount of partial encoding and improving the compression ratio of encoding.

[0063] In a specific application scenario, please refer to Figure 4 , Figure 4 is Figure 2 a schematic diagram of an application scenario of an embodiment corresponding to step S204 in Figure 4 . Among them, the slant boxes correspond to motion macroblocks. The distance threshold is the distance of 4 motion macroblocks. If the distance between any motion macroblock and the nearest motion macroblock is within the distance threshold, only one motion macroblock aggregation region is obtained. Among them, what the motion detection algorithm returns is a one-dimensional array (the array stores in sequence from left to right and from top to bottom of the image). Each member in the array represents the motion state of a macroblock, 1 represents motion, and 0 represents non-motion. Through this array and the width and height of the image, the coordinates of each motion macroblock can be obtained. Then, the aspect ratios of the horizontal and vertical coordinates of all coordinates are judged, and the maximum and minimum values are respectively taken, that is, the upper left corner and the lower right corner within the dashed box. The region enclosed by the dashed box in the figure is the motion boundary region. After obtaining the motion boundary region, a region to be matte-extracted is obtained according to the preset macroblock step size, that is, the region enclosed by the gray macroblocks in

[0064] In another specific application scenario, please refer to Figure 5 Figure 5 isFigure 2 Schematic diagram of an application scenario of another embodiment corresponding to step S204, wherein the slanted boxes correspond to motion macroblocks, the distance threshold is the distance of 5 motion macroblocks, the distance between the regions corresponding to two motion macroblocks exceeds the distance threshold, and there are two aggregation regions between the motion macroblocks, then Figure 5 the two motion macroblock aggregation regions shown within the dashed boxes are obtained, and then based on the two motion macroblock regions respectively, expansion is performed outward by a preset macroblock step size to obtain two regions to be matte-extracted, that is Figure 5 the regions enclosed by the gray macroblocks. Thus, when the distance between the motion macroblock aggregation regions is large, region-by-region encoding can be performed to reduce the encoding amount of non-motion regions, thereby improving the encoding compression ratio.

[0065] Optionally, before the step of selecting the processing method as encoding at least a part of the current image, thereby at least extracting from the current image the regions corresponding to the objects that have moved and encoding them and incrementing the usage count value corresponding to the reference image, it further includes: determining whether the area of the region corresponding to the object that has moved accounts for more than a proportion threshold of the total area of the current image; in response to exceeding the proportion threshold, selecting the processing method as performing full-frame encoding on the current image, thereby using the full-frame encoded current image as a new reference image and clearing the usage count value.

[0066] Specifically, when the motion detection result is that there is a moving object and the reference image detection result is that there is a reference image, first determine whether the area of the region corresponding to the object that has moved accounts for more than a proportion threshold of the total area of the current image. When it exceeds the proportion threshold, it is determined that there are many and large moving objects in the current image, and the processing method is selected as performing full-frame encoding on the current image to reduce direct encoding of the image by other judgment processes, improve the encoding efficiency and avoid loss of moving objects. When the proportion does not exceed the proportion threshold, the processing method is selected as encoding at least a part of the current image.

[0067] In an application scenario, when determining whether the area of the region corresponding to the object that has moved accounts for more than a proportion threshold of the total area of the current image, the ratio of the area of the region corresponding to the object that has moved to the total area of the current image is determined by the ratio between the motion macroblocks and all the macroblocks corresponding to the current image.

[0068] S206: In response to the usage count value exceeding the count threshold, perform full-frame encoding on the current image and clear the usage count value.

[0069] Specifically, when the usage count value corresponding to the reference image exceeds the count threshold, full-frame encoding is performed on the current image and the usage count value is cleared simultaneously, so as to avoid the same reference image being used or referenced too many times, reduce the inter-frame encoding error and reduce the waiting time during decoding.

[0070] S207: Setting a flag bit matching the processing method for the processed current image.

[0071] Specifically, the processing mode corresponds to a matching flag bit, thereby facilitating efficient determination of the decoding mode during decoding.

[0072] In one application, in response to a processing method of encoding the entire frame of the current image, a first flag corresponding to the processing method is set, and the processed current image and the first flag are packaged and stored; in response to a processing method of using a reference image corresponding to the current image, a second flag corresponding to the processing method is set, and the timestamp of the current image and the second flag are packaged and stored; in response to a processing method of encoding at least a partial area of ​​the current image, a third flag corresponding to the processing method is set, and the position information and the processed partial area are packaged and stored with the third flag.

[0073] Specifically, after selecting a matching processing method for the image, the processed image needs to be packaged and stored. When the processing method is to encode the entire frame of the current image, the first flag corresponding to the processing method is set, and the processed current image and the first flag are packaged and stored. When the processing method is to use the reference image corresponding to the current image, the second flag corresponding to the processing method is set, and the timestamp of the current image extracted previously is packaged and stored with the second flag. When the processing method is to encode at least a partial area of ​​the current image, the third flag corresponding to the processing method is set, and the position information corresponding to the processed partial area and the processed partial area are packaged and stored with the third flag, so that when decoding, it can be determined how the decoded partial image area is superimposed with the reference image, thereby improving the decoding accuracy.

[0074] In an application scenario, when the processing method is to encode at least a partial area of ​​the current image, the partial area corresponds to the area to be cut out in the above step S205, and the position information corresponding to the area to be cut out and the processed area to be cut out are encapsulated and stored with the third flag.

[0075] In this embodiment, the current image is divided into multiple macroblocks for motion detection. After obtaining the motion detection result and the reference image detection result, a suitable processing method is selected based on the motion detection result and the reference image detection result to improve the coding compression ratio in the time domain. Among them, when the processing method is to encode at least part of the current image, the distance between any motion macroblock and the nearest motion macroblock is determined, so as to divide out the motion macroblock aggregation area and expand it to obtain the area to be matteed, and the area to be matteed is encoded. When the distance between the motion macroblock aggregation areas is large, it is possible to encode by regions to reduce the coding amount of non-motion regions, thereby improving the coding compression ratio. After setting matching flag bits for different surfaces, they are encapsulated and stored to improve the decoding efficiency during decoding. When the processing method is to use the reference image corresponding to the current image, there is no need to encode the current image, thereby effectively improving the coding compression ratio and coding efficiency. When the processing method is frame-by-frame encoding, the image can be encoded frame by frame to obtain a new reference image to avoid the same reference image being used too many times, while improving the coding compression ratio and reducing the probability of poor image quality after encoding.

[0076] Please refer to Figure 6 , Figure 6 FIG. is a schematic flowchart of an embodiment of the image decoding method of the present application. Among them, the image decoding method corresponding to this embodiment is applied to the image encoded by the image encoding method described in any of the above embodiments. The method includes:

[0077] S601: Obtain the current image to be decoded, and determine the processing method of the current image based on the flag bit matching the processing method.

[0078] Specifically, when decoding the encoded image, the current image to be decoded is obtained, and based on the flag bit matching the processing method during encoding, the processing method of the current image during encoding is determined.

[0079] S602: In response to the processing method being to encode at least part of the current image, decode the encoded area to obtain a decoded sub-area, and superimpose the time stamp corresponding to the current image and the decoded sub-area on the corresponding position of the reference image corresponding to the current image to obtain the decoded current image, and use the decoded current image as a new reference image.

[0080] Specifically, when the processing method is to encode at least a partial region of the current image, the encoded region is decoded to obtain a decoded sub-region, and the decoded sub-region is superimposed on the current image. Among them, the decoded sub-region is superimposed and replaced based on the position information, so as to display the moving target. The time stamp of the current image is superimposed on the reference image of the current image to ensure the accuracy of the time stamp display, and the decoded current image is used as a new reference image, so as to ensure the continuity and real-time performance of the image during continuous display.

[0081] In an application scenario, the encoded region is obtained based on the region to be matted in the above embodiment. The encoded region corresponding to the region to be matted is decoded to obtain a decoded sub-region, and then the decoded sub-region is superimposed on the current image based on the position information corresponding to the region to be matted. And the decoded image is used as a new reference image. Furthermore, when a subsequent image needs to use the reference image, the moving target in the current image can still be displayed.

[0082] Further, after the step of obtaining the current image to be decoded and determining the processing method of the current image based on the flag bit matching the processing method, it further includes: in response to the processing method being to perform full-frame encoding on the current image, directly performing full-frame decoding on the current image to obtain the decoded current image, and using the decoded current image as a new reference image; in response to the processing method being to use the reference image corresponding to the current image, superimposing the time stamp of the current image on the reference image corresponding to the current image to ensure the accuracy of the time stamp display, and obtaining the decoded current image.

[0083] Specifically, when the processing method is to perform full-frame encoding on the current image, then during decoding, the current image is directly decoded in full frame to obtain the decoded current image, and the decoded current image after full-frame decoding is used as a new reference image. Among them, after each decoded image after full-frame decoding is obtained, the decoded image after full-frame decoding is used as the reference for the subsequent image in time sequence.

[0084] Further, when the processing method is to use the reference image corresponding to the current image, the current reference image is obtained, and the time stamp of the current image is superimposed on the reference image corresponding to the current image to ensure the accuracy of the time stamp display, and the decoded current image is obtained.

[0085] It can be understood that when it is necessary to drag the video stream for playback, if the processing method of the initial playback image is full-frame encoding, then full-frame decoding can be directly performed on the current image. If the processing method of the initial playback image is to use the reference image corresponding to the current image or partial encoding, then search forward from the current image for at most the counting threshold number of images in the above embodiment, and the reference image corresponding to the initial playback video can surely be obtained, so as to obtain the picture of the initial playback image, and start frame-by-frame display from the initial playback image.

[0086] In the above solution, if the processing method of the current image is to use the reference image corresponding to the current image, only the stored timestamp needs to be extracted. If the processing method of the current image is to encode at least a part of the current image, the encoded region is decoded to obtain a decoded sub-region, and the decoded sub-region and the timestamp corresponding to the current image are superimposed on the reference image, thereby improving the decoding efficiency.

[0087] Please refer to Figure 7 , Figure 7 FIG. is a schematic structural diagram of an embodiment of an electronic device according to the present application. The electronic device 70 includes a memory 701 and a processor 702 that are coupled to each other. Among them, the memory 701 stores program data (not shown in the figure), and the processor 702 calls the program data to implement the method in any of the above embodiments. For the description of related content, please refer to the detailed description of the above method embodiments, and details are not described herein again.

[0088] Please refer to Figure 8 , Figure 8 FIG. is a schematic structural diagram of an embodiment of a computer-readable storage medium according to the present application. The computer-readable storage medium 80 stores program data 800, and when the program data 800 is executed by a processor, the method in any of the above embodiments is implemented. For the description of related content, please refer to the detailed description of the above method embodiments, and details are not described herein again.

[0089] It should be noted that the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0090] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0091] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs.

[0092] The above is only the implementation manner of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.

Claims

1. An image encoding method, characterized in that, the method includes: obtaining a current image and determining a reference image detection result of the current image; in response to the reference image detection result indicating that there is a reference image, obtaining a motion detection result and selecting a processing method based on the motion detection result to process the current image; wherein, the reference image is an image after full-frame encoding, and when the motion detection result indicates that there is a moving target, the processing method is to encode at least a partial region of the current image, and the partial region includes the moving target; setting a flag bit matching the processing method for the processed current image; wherein, the step of obtaining a motion detection result and selecting a processing method based on the motion detection result to process the current image includes: in response to the motion detection result indicating that there is no moving target, selecting the processing method as using the reference image corresponding to the current image, extracting the timestamp of the current image, and incrementing the usage count value corresponding to the reference image; or, in response to the motion detection result indicating that there is a moving target, selecting the processing method as encoding at least a partial region of the current image, so as to at least extract and encode the region corresponding to the target that has moved in the current image and increment the usage count value corresponding to the reference image; in response to the usage count value exceeding a count threshold, performing full-frame encoding on the current image and clearing the usage count value.

2. The image encoding method according to claim 1, characterized in that, after the step of obtaining the current image and determining the reference image detection result of the current image, it further includes: in response to the reference image detection result indicating that there is no reference image, selecting the processing method as performing full-frame encoding on the current image, and using the current image after full-frame encoding as a new reference image.

3. The image encoding method according to claim 1, characterized in that, before the step of selecting the processing method as encoding at least a partial region of the current image, so as to at least extract and encode the region corresponding to the target that has moved in the current image and increment the usage count value corresponding to the reference image, it further includes: determining whether the area of the region corresponding to the target that has moved in the current image exceeds a ratio threshold of the total area of the current image; in response to exceeding the ratio threshold, selecting the processing method as performing full-frame encoding on the current image, so as to use the current image after full-frame encoding as a new reference image and clearing the usage count value.

4. The image encoding method according to claim 2, characterized in that, the step of setting a flag bit matching the processing method for the processed current image includes: in response to the processing method being performing full-frame encoding on the current image, setting a first flag bit corresponding to the processing method, and encapsulating and storing the processed current image and the first flag bit; in response to the processing method being using the reference image corresponding to the current image, setting a second flag bit corresponding to the processing method, and encapsulating and storing the timestamp of the current image and the second flag bit; In response to the processing method being to encode at least a partial region of the current image, set a third flag bit corresponding to the processing method, and encapsulate and store the position information corresponding to the partial region and the processed partial region together with the third flag bit.

5. The image encoding method according to claim 1, wherein, the motion detection result is determined based on the following steps, including: divide the current image into a plurality of macroblocks, and determine the sub-block detection results corresponding to each of the macroblocks; in response to the current image including at least one motion macroblock whose sub-block detection result is that there is a moving target, determine that the motion detection result corresponding to the current image is that there is a moving target; in response to the sub-block detection results corresponding to all the macroblocks corresponding to the current image being that there is no moving target, determine that the motion detection result corresponding to the current image is that there is no moving target.

6. The image encoding method according to claim 5, wherein, the step of encoding at least a partial region of the current image includes: determine a motion boundary region corresponding to the motion macroblock, and expand the motion boundary region outward by a preset macroblock step length to obtain a region to be matte; determine the position information of the region to be matte in the current image, and encode the region to be matte in the current image based on encoding parameters matching the position information.

7. The image encoding method according to claim 6, wherein, the step of determining a motion boundary region corresponding to the motion macroblock, and expanding the motion boundary region outward by a preset macroblock step length to obtain a region to be matte includes: in response to the distance between any one of the motion macroblocks and the nearest motion macroblock being within a distance threshold, determine the motion boundary region based on all the motion macroblocks; in response to the distance between at least two of the motion macroblocks and the nearest motion macroblock exceeding the distance threshold, divide all the motion macroblocks into at least two motion macroblock aggregation regions based on the distance threshold, and respectively determine the motion boundary regions corresponding to the motion macroblock aggregation regions.

8. An image decoding method, wherein, the method is applied to the image encoding method according to any one of claims 1-7, and includes: obtain a current image to be decoded, and determine the processing method of the current image based on a flag bit matching the processing method; in response to the processing method being to encode at least a partial region of the current image, decode the encoded region to obtain a decoded sub-region, and superimpose the time stamp corresponding to the current image and the decoded sub-region on the corresponding position of the reference image corresponding to the current image to obtain a decoded current image, and use the decoded current image as a new reference image.

9. The image decoding method according to claim 8, wherein, after the step of obtaining a current image to be decoded and determining the processing method of the current image based on a flag bit matching the processing method, further includes: In response to the processing method being to perform frame - by - frame encoding on the current image, directly perform frame - by - frame decoding on the current image to obtain the decoded current image, and use the decoded current image as a new reference image; In response to the processing method being to continue using the reference image corresponding to the current image, superimpose the timestamp corresponding to the current image on the reference image corresponding to the current image to obtain the decoded current image.

10. An electronic device, characterized in that, it includes: a memory and a processor coupled to each other, wherein the memory stores program data, and the processor calls the program data to execute the method according to any one of claims 1 - 7 or 8 - 9.

11. A computer - readable storage medium, on which program data is stored, characterized in that, when the program data is executed by a processor, it implements the method according to any one of claims 1 - 7 or 8 - 9.

Citation Information

Patent Citations

  • Image processing apparatus and image processing method

    CN102823247A