Video coding method and device, electronic equipment and storage medium
By performing image enhancement and encoding on the area of interest of the video frame, the problem of video encoding quality degradation in the existing technology is solved, and a video encoding effect of higher quality and lower bit rate is achieved.
Patent Information
- Application Number
- CN202410705720.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-10
AI Technical Summary
Existing video encoding technology will reduce video quality and affect user experience.
By obtaining the area of interest information of the video frame, image enhancement is performed, and the enhanced video frame is encoded to improve the encoded video quality and visual effects.
It improves the quality and visual effects of the encoded video, while saving the bit rate and resource consumption required for encoding.
Smart Images

Figure CN118632003A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and more specifically, to a video encoding method and device, an electronic device, a storage medium, and a program product. Background Art
[0002] As an important communication medium, video has been widely used in people's work and life. In order to facilitate the storage, playback, transmission, etc. of video, it is necessary to encode the video.
[0003] In the related art, after encoding a video, the quality of the video will be reduced, thereby reducing the visual effect of the video and affecting the user experience. Summary of the invention
[0004] The embodiments of the present application provide a video encoding method and device, an electronic device, a storage medium, and a program product, which can improve the quality and visual effect of the encoded video.
[0005] According to one aspect of an embodiment of the present application, a video encoding method is provided, the method comprising:
[0006] Obtain multiple video frames contained in the source video to be encoded;
[0007] Performing region of interest detection on each video frame to obtain region of interest information of each video frame;
[0008] According to the region of interest information of each video frame, image enhancement is performed on the region of interest of each video frame to obtain an interest enhancement map corresponding to each video frame;
[0009] The interest enhancement maps corresponding to the multiple video frames are encoded to obtain a target encoded video of the source video.
[0010] According to one aspect of an embodiment of the present application, a video encoding device is provided, the device comprising:
[0011] An acquisition module, configured to acquire multiple video frames contained in a source video to be encoded;
[0012] A detection module is configured to perform region of interest detection on each video frame to obtain region of interest information of each video frame;
[0013] An enhancement module is configured to perform image enhancement on the region of interest of each video frame according to the region of interest information of each video frame to obtain an interest enhancement map corresponding to each video frame;
[0014] The encoding module is configured to encode the interest enhancement images corresponding to the multiple video frames respectively to obtain the target encoded video of the source video.
[0015] According to one aspect of an embodiment of the present application, there is provided an electronic device, including:
[0016] one or more processors;
[0017] The storage device is used to store one or more computer programs, and when the one or more computer programs are executed by the one or more processors, the electronic device implements the method as described above.
[0018] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor of an electronic device, the electronic device implements the method as described above.
[0019] According to one aspect of an embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method as described above is implemented.
[0020] In the technical solution provided in the embodiments of the present application, multiple video frames contained in the source video to be encoded are first obtained, and the region of interest detection is performed on each video frame to obtain the region of interest information of each video frame, and the region of interest of each video frame is enhanced according to the region of interest information of each video frame to obtain the interest enhancement map corresponding to each video frame, and the interest enhancement maps corresponding to the multiple video frames are encoded to obtain the target encoded video of the source video. Since the video frames of the source video are image enhanced before encoding, the quality of the encoded video obtained after encoding can be improved, and only the region of interest of the video frame is image enhanced. Since visual attention is usually concentrated on the region of interest, only the region of interest of the video frame is image enhanced, which can not only improve the visual effect of the encoded video, but also save the bit rate required for encoding and reduce the resources consumed by the image enhancement process.
[0021] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 is a schematic diagram of an implementation environment shown in an exemplary embodiment of the present application;
[0023] Figure 2 is a flowchart of a video encoding method shown in an exemplary embodiment of the present application;
[0024] Figure 3Ais a diagram of a training process of a clarity enhancement model shown in an exemplary embodiment of the present application;
[0025] Figure 3B is a structural schematic diagram of a clarity enhancement model shown in an exemplary embodiment of the present application;
[0026] Figure 3C is a schematic diagram of the structure of a residual block shown in an exemplary embodiment of the present application;
[0027] Figure 3D is a schematic diagram of a source video encoding process shown in an exemplary embodiment of the present application;
[0028] Figure 4 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0029] Figure 5 is a graph showing a relationship between enhancement coefficient and texture complexity according to an exemplary embodiment of the present application;
[0030] Figure 6 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0031] Figure 7 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0032] Figure 8 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0033] Fig. 9 is a schematic diagram of an interest enhancement process shown in an exemplary embodiment of the present application;
[0034] Fig.10 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0035] Fig.11 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0036] Fig.12 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0037] Fig.13 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0038] Fig.14 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0039] Fig.15is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0040] Fig.16 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0041] Fig.17A is a structural diagram of a detection model shown in an exemplary embodiment of the present application;
[0042] Fig. 17B is a structural diagram of a shallow feature enhancement layer shown in an exemplary embodiment of the present application;
[0043] Fig. 17C is a structural diagram of a self-attention layer of a shallow feature enhancement layer shown in an exemplary embodiment of the present application;
[0044] Fig.17D is a processing diagram of a receptive field layer shown in an exemplary embodiment of the present application;
[0045] Fig.17E is a structural diagram of a feature transformation layer shown in an exemplary embodiment of the present application;
[0046] Fig.18 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0047] Fig.19 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0048] Fig. 20 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0049] Fig.21 is a flowchart of a video encoding method shown in another exemplary embodiment of the present application;
[0050] Fig.22A is a comparison diagram of video encoding effects shown by an exemplary embodiment of the present application;
[0051] Fig. 22B is a comparison diagram of video encoding effects shown by an exemplary embodiment of the present application;
[0052] Fig. 22C is a comparison diagram of video encoding effects shown by an exemplary embodiment of the present application;
[0053] Fig.22D is a comparison diagram of video encoding effects shown by an exemplary embodiment of the present application;
[0054] Fig.22Eis a comparison diagram of video encoding effects shown by an exemplary embodiment of the present application;
[0055] Fig.23 is a schematic diagram of a video encoding device shown in an exemplary embodiment of the present application;
[0056] Fig.24 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0057] The exemplary embodiments are now described in a more comprehensive manner with reference to the accompanying drawings. However, the exemplary embodiments can be implemented in various forms and should not be understood as being limited to these examples; on the contrary, the purpose of providing these embodiments is to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.
[0058] In addition, the features, structures or characteristics described in the present application may be combined in one or more embodiments in any suitable manner. In the following description, there are many specific details so that the embodiments of the present application can be fully understood. However, those skilled in the art will appreciate that when implementing the technical scheme of the present application, all the detailed features in the embodiments may not be needed, one or more specific details may be omitted, or other methods, elements, devices, steps, etc. may be adopted.
[0059] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0060] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0061] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0062] It should also be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0063] The following is a detailed introduction to the technical solutions of the embodiments of the present application:
[0064] In the related art, encoding a video will reduce the quality of the video. Based on this, the embodiments of the present application provide a video encoding method and device, electronic equipment, storage medium, and program product, which can improve the quality and visual effect of the encoded video.
[0065] See also Figure 1 , Figure 1 1 is a schematic diagram of an implementation environment involved in the present application, which includes a terminal device 110 and a server 120. The terminal device 110 and the server 120 communicate with each other through a wired or wireless network, and the terminal device 110 can upload its own data to the server 120 or obtain data from the server 120.
[0066] Among them, the terminal device 110 may include but is not limited to mobile phones, tablets, laptops, computers, voice interaction devices, home appliances, vehicle-mounted terminals, aircraft, remote driving terminals, etc.; the server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network) and big data and artificial intelligence platforms. The specific forms of terminal devices and servers are not restricted here.
[0067] It should be noted that Figure 1 The number of terminal devices 110 and servers 120 in the figure is only for illustration, and any number of terminal devices 110 and servers 120 may be provided according to actual needs.
[0068] In an exemplary embodiment, the video encoding method provided by the embodiment of the present application can be executed by the terminal device 110. Exemplarily, the terminal device 110 can first obtain multiple video frames contained in the source video to be encoded, and perform region of interest detection on each video frame to obtain region of interest information of each video frame, and perform image enhancement on the region of interest of each video frame according to the region of interest information of each video frame to obtain an interest enhancement map corresponding to each video frame; then, the interest enhancement maps corresponding to the multiple video frames contained in the source video are respectively encoded to obtain a target encoded video of the source video. Since the video frames of the source video are image enhanced before encoding, the quality of the encoded video obtained after encoding can be improved. Moreover, image enhancement is only performed on the region of interest of the video frame. Since visual attention is usually concentrated on the region of interest, image enhancement is only performed on the region of interest of the video frame, which can not only improve the visual quality after encoding, but also improve the visual quality of the video frame. The video visual effect can be improved, and the bit rate required for encoding can be saved, and the resources consumed by the image enhancement process can be reduced. In addition, by allocating more bit rate to the region of interest in the process of encoding the video frame to improve the quality of the encoded video, since the encoding process of the video frame is processed in units of encoding blocks, the bit rate can only be allocated in units of encoding blocks to achieve quality improvement at the encoding block level, which reduces the accuracy of video processing, and this method can only make the encoded video quality close to the video quality of the source video, and cannot make the encoded video quality exceed the video quality of the source video; in the embodiments of the present application, by performing image enhancement on the region of interest of the video frame before encoding, it is possible to achieve pixel-level quality improvement, improve the accuracy of video processing, and make the encoded video quality exceed the video quality of the source video.
[0069] In another exemplary embodiment, the server 120 may have functions similar to those of the terminal device 110, so as to execute the video encoding method provided in the embodiment of the present application. Exemplarily, the server 120 may first obtain multiple video frames contained in the source video to be encoded, and perform region of interest detection on each video frame to obtain region of interest information of each video frame, and perform image enhancement on the region of interest of each video frame according to the region of interest information of each video frame to obtain an interest enhancement map corresponding to each video frame; then, the interest enhancement maps corresponding to the multiple video frames contained in the source video are encoded to obtain the target encoded video of the source video.
[0070] In another exemplary embodiment, the terminal device 110 and the server 120 may also jointly execute the video encoding method provided in the embodiment of the present application. Exemplarily, the terminal device 110 may obtain the source video and send the source video to the server 120; the server 120 may perform interest region detection on each video frame in the source video to obtain interest region information of each video frame, and perform image enhancement on the interest region of each video frame according to the interest region information of each video frame to obtain an interest enhancement map corresponding to each video frame; then, the interest enhancement maps corresponding to the multiple video frames contained in the source video are encoded to obtain the target encoded video of the source video.
[0071] The video encoding method in the embodiment of the present application can be applied to video encoding scenarios in various applications. The embodiment of the present application involves source video and other user-related data. When the method of the present application is applied to a specific product or technology, it is all done with the user's permission or consent, and the extraction, use and processing of the relevant data comply with local safety standards and local laws and regulations.
[0072] See also Figure 2 , Figure 2 is a flowchart of a video encoding method shown in an exemplary embodiment of the present application. The method can be applied to Figure 1 The implementation environment shown, which can be Figure 1 The terminal device 110 in the implementation environment shown in the figure may also be executed by Figure 1 The server 120 in the implementation environment shown in the figure may also execute the command. Figure 1 The terminal device 110 and the server 120 in the illustrated implementation environment execute together.
[0073] like Figure 2 As shown, in an exemplary embodiment, the video encoding method may include steps S210 to S240, which are described in detail as follows:
[0074] Step S210: obtaining multiple video frames contained in a source video to be encoded.
[0075] It should be noted that the source video refers to any video that needs to be encoded, for example, a video that needs to be encoded for transmission, a video that needs to be transcoded, a video that needs to be compressed, etc. According to whether the video has been encoded, the types of source videos include original videos that have not been encoded, and encoded videos that have been encoded (for example, videos that need to be transcoded); according to the producer of the video, the types of source videos include but are not limited to user-generated content (UGC), professionally produced content (PGC), etc., where UGC refers to content produced by ordinary users, and PGC refers to content produced by professional organizations (for example, radio and television practitioners).
[0076] The source video contains multiple video frames. In order to encode the source video, the source video can be parsed to obtain the multiple video frames it contains. Optionally, if the source video is an encoded video, the source video can be decoded according to the video encoding method corresponding to the source video to obtain the multiple video frames it contains.
[0077] Step S220, performing region of interest detection on each video frame to obtain region of interest information of each video frame.
[0078] A region of interest (ROI) is a focus area selected from an image, which can be an area represented by a box, circle, ellipse, irregular polygon, mask, etc. Optionally, the central area or foreground area of an image is usually a visual focus area, so the foreground area or central area of an image can be used as the region of interest, or the area occupied by the target in the image can be used as the region of interest, and the target includes but is not limited to people, objects, animals, plants, etc. The region of interest information is used to describe the region of interest, and its types include but are not limited to region of interest masks, etc. The region of interest mask of an image contains the probability of interest of each pixel in the image, where the probability of interest refers to the probability of being located in the region of interest, that is, each pixel in the region of interest mask corresponds one-to-one to each pixel in the image, and the pixel value of each pixel in the region of interest mask represents the probability of interest.
[0079] For each video frame, a region of interest can be detected to obtain information about the region of interest.
[0080] Among them, the specific method of detecting the region of interest can be flexibly set according to actual needs. In an optional implementation, a detection model can be deployed, wherein the detection model is an artificial intelligence model for detecting the region of interest of an input image, and the output is the region of interest information of the input image. The model types include but are not limited to convolutional neural networks, recurrent neural networks, etc. The video frame is input into the detection model to obtain the region of interest information of the video frame output by the detection model.
[0081] Step S230, performing image enhancement on the region of interest of each video frame according to the region of interest information of each video frame, and obtaining an interest enhancement map corresponding to each video frame.
[0082] The interest enhancement map refers to a map obtained by performing image enhancement only on the region of interest of the image. For each video frame, only the region of interest is enhanced to obtain the interest enhancement map of the video frame.
[0083] In order to obtain an interest-enhanced map of a video frame, in an optional implementation, the video frame may be divided into an interest region map and a non-interest region map according to the interest region of the video frame, and then the interest region map may be image enhanced to obtain an enhanced interest region map, and then the enhanced interest region map may be spliced with the non-interest region map to obtain the interest-enhanced map of the video frame. In another optional implementation, the video frame may be image enhanced to obtain an enhanced map, and the interest region of the enhanced map may be spliced with the non-interest region of the video frame to obtain the interest-enhanced map of the video frame.
[0084] Among them, image enhancement is used to improve the quality of the image, including but not limited to clarity enhancement, resolution enhancement, etc. Image enhancement can be performed through an image enhancement model, wherein the image enhancement model is an artificial intelligence model for performing image enhancement on the input image, and its output is an enhanced map of the input image. The model type and model structure of the image enhancement model can be flexibly set according to actual needs. For example, the model type of the image enhancement model includes but is not limited to convolutional neural networks, recurrent neural networks, etc. In order to obtain the image enhancement model, an artificial intelligence model corresponding to the image enhancement model can be constructed and a training set can be obtained. The artificial intelligence model is trained according to the training set to obtain the image enhancement model. In an optional embodiment, if the image enhancement is clarity enhancement, the process of obtaining the clarity enhancement model can include steps 1.1-step 1.2, which are described in detail as follows:
[0085] Step 1.1, obtain the training set of the clarity enhancement model.
[0086] The training set of the clarity enhancement model includes multiple training samples, each of which includes an input sample image and its corresponding target enhancement map, wherein the target enhancement map refers to the enhancement map expected to be obtained after the clarity enhancement model is used to enhance the input sample image.
[0087] In order to reduce the difficulty of obtaining the training set, step 1.1 may include steps 1.11-1.12, which are described in detail as follows:
[0088] Step 1.11, obtain multiple images as target enhancement images.
[0089] In order to improve the clarity enhancement effect, an image with a resolution higher than a resolution threshold can be obtained as a target enhancement map, wherein the resolution threshold, the number of target enhancement maps, and the source of the target enhancement map can be flexibly set according to actual needs. In an optional example, 900 2K resolution images can be selected from DIV2K as target enhancement maps. DIV2K is a dataset widely used for super-resolution image reconstruction, which contains high-quality natural images.
[0090] Step 1.12, reduce the resolution of each target enhancement image to obtain the intermediate image of each target enhancement image, and enlarge the resolution of the intermediate image to obtain the input sample image corresponding to each target enhancement image.
[0091] For each target enhancement image, first reduce its resolution to obtain an intermediate image, and then enlarge the resolution of the intermediate image to obtain an image with reduced clarity, which is used as the input sample image of the target enhancement image. The resolution reduction factor and enlargement factor can be flexibly set according to actual needs. In an optional example, the resolution of the intermediate image can be half of the resolution of the target enhancement image, and the resolution of the input sample image is consistent with that of the target enhancement image, that is, the resolution of the target enhancement image = 2*the resolution of the intermediate image = the resolution of the input sample image.
[0092] Step 1.2, create an artificial intelligence model corresponding to the clarity enhancement model, and train the artificial intelligence model based on the training set to obtain the clarity enhancement model.
[0093] During the training process, the artificial intelligence model corresponding to the clarity enhancement model can be trained by batch training. Batch training refers to multiple rounds of model training for the artificial intelligence model until the set stop training conditions are met. The artificial intelligence model that meets the set stop training conditions is the trained model, wherein the set stop training conditions include but are not limited to the convergence of the artificial intelligence model and the training rounds reaching the set round threshold (for example, 300). Each round of model training includes multiple batches of model training. In the model training process of each batch, a plurality of training samples matching the batch size (Batch Size) are sampled from the training set by non-replacement sampling, and model training is performed based on the sampled multiple training samples. Then, the next batch of model training is entered until all training samples in the training set are sampled, and the model training of this round is completed. The specific value of the batch size can be flexibly set according to actual needs, for example, it can be 32, 40, etc. Sampling without replacement refers to a method in which when individuals are sampled one by one, the individuals drawn each time are not returned to the population to participate in the next sampling.
[0094] During the training of each batch of the AI model corresponding to the clarity enhancement model, see Figure 3A As shown, multiple training samples matching the batch size (e.g., 300) are extracted from the training set corresponding to the clarity enhancement model, and the input sample images in the multiple training samples are used as the input of the artificial intelligence model corresponding to the clarity enhancement model. After the input sample images are subjected to image enhancement processing by the artificial intelligence model, a predicted enhancement map is output, and the model loss is calculated according to the predicted enhancement map and the target enhancement map, and the model parameters of the artificial intelligence model are updated according to the model loss to optimize the model, and then the trained artificial intelligence model is used as the clarity enhancement model. Optionally, in the process of updating the model parameters, the model parameters can be updated according to the model loss through error back propagation and adaptive moment estimation (Adam) optimization algorithm.
[0095] The model loss can be calculated by a loss function according to the prediction enhancement map and the target enhancement map, and the artificial intelligence model can be updated based on the model loss; or, the model loss can be calculated by multiple loss functions according to the prediction enhancement map and the target enhancement map, and the loss values calculated by the multiple loss functions can be weighted summed to obtain the total model loss, and the artificial intelligence model can be updated based on the total model loss. The loss function includes but is not limited to at least one of an L1 loss function and a perceptual loss function. In an optional example, the prediction enhancement map can be used to calculate the model loss. hd and the target enhancement graph G hd , the total model loss is calculated by the L1 loss function and the perceptual loss function. The calculation method can be as follows:
[0096]
[0097] in, represents the total model loss, They represent the L1 loss function and the perceptual loss function respectively, λ1 and λ2 represent the weights of the L1 loss function and the perceptual loss function respectively, and their specific values can be flexibly set according to actual needs. In an optional example, λ1 can be 0.9 and λ2 can be 0.1; φ(·) represents the feature map extracted by the 4th convolutional layer before the 5th maximum pooling layer in the VGG-19 model.
[0098] It should be understood that the architecture of the definition enhancement model is different, and the corresponding image enhancement processing process is different. In an optional example, the definition enhancement model can be a convolutional neural network, and the architecture of the convolutional neural network can be as follows: Figure 3B As shown, taking any image I as an example, the image enhancement process may include steps 2.1 to 2.5, which are described in detail as follows:
[0099] Step 2.1, normalize the image I through the normalization layer to obtain a standardized image.
[0100] The specific method of the standardization process can be flexibly set according to actual needs. In an optional example, the standardization process can be performed by the following formula:
[0101]
[0102] Among them, I c is the c channel of the input image I, S c is the c channel of the standardized image S, which may include the red (r) channel, the green (g) channel, and the blue (b) channel, μ c is the mean of the c channel of the image obtained by data statistics, σ c The standard deviation of the c channel of the image obtained by data statistics.
[0103] Step 2.2, convolve the standardized image through convolution layer 1 to obtain the expanded feature map F head .
[0104] The convolution kernel size and the specific convolution method of the convolution layer 1 can be flexibly set according to actual needs. In an optional example, the convolution kernel size can be 3×3, and the convolution method includes expanding the number of channels of the standardized image and outputting n f The expansion characteristic map F of the channel head , that is, the dilated feature map F headThe number of channels of is greater than the number of channels of the standardized image, and the corresponding convolution formula can be as follows:
[0105] F head =conv 3×3 (S)
[0106] Among them, n f The specific value of can be set according to resources, computing power and efficiency. For example, it can be set to 16, 32, 48, 64, etc. 3×3 Refers to the convolution operation with a convolution kernel of 3×3.
[0107] Step 2.3, expand the feature map F through multiple residual blocks and convolutional layers 2 head Process it and compare the processed feature map with the expanded feature map F head Add them together to get a deeper feature map F body .
[0108] The convolution kernel size of the convolution layer 2 and the specific convolution method can be flexibly set according to actual needs. In an optional example, the convolution kernel size of the convolution layer 2 can be 1×1. Under this condition, the feature map F body The calculation method is as follows:
[0109]
[0110] in, Represents the calculation function of the kth residual block (ResBlock). n is the number of residual blocks, and its specific value can be set according to the needs of resources, computing power and efficiency. For example, it can be 6, 12, 18, 24, etc. The input feature map and output feature map of each residual block can both be n f Channel feature map, conv 1×1 Refers to the convolution operation with a convolution kernel of 1×1.
[0111] The specific structure and calculation function of the residual block can be flexibly set according to actual needs. In an optional example, see Figure 3C As shown, the residual block may include a convolutional layer, an activation layer, and a convolutional layer connected in sequence. The input feature map of the previous convolutional layer and the output feature map of the next convolutional layer are added to obtain the output feature map of the residual block, wherein the convolution kernel size of each convolutional layer can be flexibly set according to actual needs, for example, it can be a 3×3 convolutional layer, and the activation function corresponding to the activation layer includes but is not limited to RELU, ELU, etc.
[0112] Step 2.4, through the convolution layer 3, the feature map F body Perform convolution to obtain the output feature map F of convolution layer 3 tail .
[0113] Through the convolution layer 3, the deep feature map F body Convolution is performed to transform the deep feature map F body The number of channels is shrunk to obtain the output feature map F with 3 channels. tail , where the convolution kernel size of the convolution layer 3 can be flexibly set according to actual needs. In an optional example, the convolution kernel size of the convolution layer 3 can be 3×3. Under this condition, the output feature map F tail The way to obtain is as follows:
[0114] F tail =conv 3×3 (F body )
[0115] Step 2.5: Output feature map F through the inverse normalization layer tail Perform inverse normalization to obtain the output prediction enhancement map O hd :
[0116] O c =(F tail ) c ·σ c +μ c
[0117] Among them, (F tail ) c and O c Represent the output feature map F tail and prediction enhancement graph O hd The c-channel characteristics.
[0118] Step S240, encoding the interest enhancement maps corresponding to the multiple video frames respectively to obtain a target encoded video of the source video.
[0119] After obtaining the interest enhancement maps corresponding to the multiple video frames contained in the source video, the obtained multiple interest enhancement maps can be encoded, thereby encoding the video, and the encoded video is used as the target encoded video. Figure 3D As shown, for the source video to be encoded, it is decoded to obtain multiple video frames, each video frame is subjected to interest enhancement processing to obtain an interest enhancement map, and then the interest enhancement map is encoded to obtain a target encoded video.
[0120] exist Figure 2In the illustrated embodiment, since the video frames of the source video are enhanced before encoding, the quality of the encoded video after encoding can be improved. Moreover, since visual attention is usually focused on the region of interest, only the region of interest of the video frame is enhanced, which can not only improve the visual effect of the encoded video, but also save the bit rate required for encoding and reduce the resources consumed by the image enhancement process.
[0121] In an exemplary embodiment, see Figure 4 , Figure 4 is Figure 2 The flowchart of a video encoding method proposed based on the figure, step S230 may include steps S410-step S430, which are described in detail as follows:
[0122] Step S410, calculating the texture complexity corresponding to the region of interest of each video frame according to the region of interest information of each video frame.
[0123] According to the region of interest information of each video frame, the region of interest can be determined from each video frame, thereby calculating the complexity of the region of interest.
[0124] The specific method of calculating the complexity of the region of interest can be flexibly set according to actual needs. For example, the second-order moment (variance) of the gray level histogram of the region of interest can be calculated and the second-order moment can be used as the texture complexity of the region of interest.
[0125] Step S420, calculating an enhancement coefficient of the region of interest according to the texture complexity corresponding to the region of interest; wherein the enhancement coefficient is negatively correlated with the texture complexity.
[0126] The enhancement coefficient is used to characterize the strength of image enhancement, wherein the larger the enhancement coefficient is, the greater the strength of image enhancement is, and the enhancement coefficient may be a value greater than or equal to 0. After the texture complexity of the region of interest is calculated, the enhancement coefficient of the region of interest may be calculated according to the texture complexity.
[0127] It should be understood that, in the process of encoding a video frame, a higher bit rate is usually allocated to a high-frequency or complex region (i.e., a region with a relatively complex texture), while a lower bit rate is allocated to a region with a relatively simple texture. Image enhancement of the region of interest will increase the texture complexity of the region of interest, thereby allocating more bit rate to the region of interest. In order to improve the image quality of the region of interest after encoding, and at the same time, avoid a large bit rate difference between the region of interest and the non-region of interest after encoding, which makes the boundary too obvious, the enhancement coefficient of the region of interest can be negatively correlated with the texture complexity of the region of interest. That is to say, under the condition that the texture complexity of the region of interest itself is relatively high, since the texture of the region of interest is already relatively complex, even if the image enhancement is not performed on the region of interest, the clarity of the region of interest after encoding is also high, and the bit rate difference between the region of interest and the non-region of interest after encoding is also large. Therefore, in order to avoid a further substantial increase in the bit rate difference, the enhancement coefficient of the region of interest can be relatively small; under the condition that the texture complexity of the region of interest itself is relatively low, if the texture enhancement is not performed on the region of interest, the clarity of the region of interest after encoding will be relatively low, therefore, the enhancement coefficient of the region of interest can be relatively large.
[0128] In an optional implementation, the enhancement coefficient of the region of interest may be calculated according to the following formula:
[0129]
[0130] Among them, α is the enhancement coefficient of the region of interest of image I, V m is the texture complexity of the region of interest of image I, h α and l α are the upper and lower limits of α, respectively. Their specific values can be flexibly set according to actual needs. For example, h α Can be 1, l α It can be 0. Ψ and σ are adjustment factors, and their specific values can be flexibly set according to actual needs. Optionally, Ψ can be 2.5. α =1, l α =0,Ψ=2.5,αandV m The relationship can be as follows Figure 5 The curves shown in the figure, where, from left to right, the five curves represent α and V when σ=40000, σ=60000, σ=80000, σ=100000, and σ=120000 respectively. m relationship curve.
[0131] Step S430: performing image enhancement on the region of interest of each video frame according to the enhancement coefficient to obtain an interest enhancement map corresponding to each video frame.
[0132] For each video frame, after the enhancement coefficient of the region of interest is calculated, the image of the region of interest can be enhanced according to the enhancement coefficient to obtain its corresponding interest enhancement map.
[0133] It should be noted that Figure 4 The specific implementation details of steps S210-S220 and step S240 shown in FIG. Figure 2 Steps S210 to S220 and step S240 are shown and will not be described in detail here.
[0134] exist Figure 4 In the illustrated embodiment, an enhancement coefficient is calculated based on the texture complexity of the region of interest, and the region of interest of the video frame is enhanced based on the enhancement coefficient to obtain an interest enhancement map corresponding to the video frame. This can improve the visual effect of the region of interest after encoding while saving bit rate and reducing the difference between the region of interest and the non-region of interest after encoding, thereby improving the quality of the encoded video.
[0135] In an exemplary embodiment, see Figure 6 , Figure 6 is Figure 4 The flowchart of a video encoding method proposed based on the figure, step S410 may include steps S610 to S630, which are described in detail as follows:
[0136] Step S610, searching for a reference area corresponding to each pixel in each video frame; wherein the distance between the pixel included in the reference area and each pixel is less than a set distance threshold.
[0137] For each pixel in the video frame, a reference area of the pixel is searched from the video frame, wherein the distance between the pixel included in the reference area and the pixel is less than a set distance threshold, that is, a region whose distance from the pixel is less than the set distance threshold is searched from the video frame, and the region is used as the reference area. The specific value of the set distance threshold can be flexibly set according to actual needs.
[0138] Step S620, calculating the discreteness between the pixel values of the pixels included in the reference area, and calculating the texture complexity of each pixel according to the discreteness; the texture complexity of each pixel is positively correlated with the discreteness.
[0139] The reference area of each pixel point contains multiple pixel points. According to the discreteness between the pixel values corresponding to the multiple pixel points, the texture complexity of each pixel point can be calculated, wherein the higher the discreteness, the higher the texture complexity. Optionally, the discreteness can be directly used as the texture complexity, or the product of the discreteness and the set coefficient can be used as the texture complexity.
[0140] The degree of discreteness between the pixel values of the multiple pixel points can be characterized by one of the variance, mean difference, standard deviation, etc. of the pixel values of the multiple pixel points. In an optional example, the variance between the pixel values of the multiple pixel points can be used as texture complexity.
[0141] Step S630: Calculate the texture complexity of the region of interest according to the texture complexity corresponding to the pixels included in the region of interest.
[0142] After calculating the texture complexity of each pixel point included in each video frame, the texture complexity of the region of interest can be calculated according to the texture complexity corresponding to the pixel points included in the region of interest.
[0143] In an optional implementation, for each video frame, pixel points located in the region of interest can be found from the video frame according to its region of interest information, and the texture complexity of the found pixel points is summed to obtain the texture complexity of the region of interest.
[0144] In another optional implementation, under the condition that the region of interest information includes a region of interest mask, the region of interest mask of each video frame includes the probability of each pixel in the video frame being located in the region of interest. For each video frame, the product between the texture complexity of each pixel and the probability of interest can be calculated, and the products corresponding to multiple pixels included in the video frame are summed to obtain the texture complexity of the region of interest. In an optional example, the texture complexity of the region of interest can be calculated by the following formula:
[0145]
[0146] Among them, v i,j Indicates the texture complexity of the pixel point with position coordinate (i, j) in image I, M i,j represents the probability of interest corresponding to the pixel point with position coordinates (i, j) in image I, h is the height of image I, and w is the width of image I. i,j It can be obtained from the region of interest mask M of image I, or from the softened region of interest mask M soft M soft The specific method can be found in the subsequent records. Taking the video frame as the input image, the texture complexity of the video frame can be calculated by the above formula.
[0147] It should be noted that Figure 6 The specific implementation details of steps S210-S220 and step S240 shown in FIG. Figure 2 Steps S210 to S220, and step S240 are shown. Figure 6The specific implementation details of steps S420 to S430 shown in FIG. Figure 4 Steps S420 to S430 shown are not repeated here.
[0148] exist Figure 6 In the illustrated embodiment, the texture complexity of each pixel is calculated based on the degree of discreteness between the pixel values of multiple pixels in the reference area of each pixel, and then the texture complexity of the region of interest is calculated based on the texture complexity corresponding to the pixel in the region of interest. This can improve the accuracy of the texture complexity of the region of interest and thereby improve the quality of the encoded video.
[0149] In an exemplary embodiment, see Figure 7 , Figure 7 is Figure 4 The flowchart of a video encoding method proposed based on the figure, step S430 may include steps S710 to S730, which are described in detail as follows:
[0150] Step S710: perform image enhancement on each video frame to obtain a first enhancement image corresponding to each video frame.
[0151] By performing image enhancement on each video frame, a first enhanced image of the video frame can be obtained.
[0152] In an optional implementation, the video frame may be input into an image enhancement model to obtain a predicted enhancement map output by the image enhancement model, and the predicted enhancement map may be used as the first enhancement map.
[0153] Step S720: fusing each video frame with the first enhanced image according to the enhancement coefficient to obtain a second enhanced image.
[0154] After the enhancement coefficient is obtained, each video frame and the first enhancement image can be fused according to the enhancement coefficient to obtain a second enhancement image. In an optional example, the calculation formula of the second enhancement image is as follows:
[0155] l enh =f ada (I′ enh , I, M)
[0156] Among them, f ada (·) represents the process of adaptive enhancement according to the enhancement coefficient, I enh The second enhanced image of image I, I′ enh The first enhancement map of the image I is represented. The enhancement coefficient corresponding to the region of interest can be calculated based on the region of interest mask.
[0157] The specific method of obtaining the second enhancement map can be flexibly set according to actual needs.
[0158] In an optional implementation, for each video frame, the product of its enhancement coefficient and the first enhancement map may be calculated, and then the product may be added to the video frame to obtain the second enhancement map.
[0159] In another optional embodiment, for each video frame, the enhancement coefficient can be used as the weight of the first enhancement map, the weight of each video frame is calculated according to the weight of the first enhancement map, and each video frame and the first enhancement map are weightedly fused according to the weights corresponding to each video frame and the first enhancement map respectively to obtain a second enhancement map.
[0160] The weight of each video frame is a positive number, and the weight of each video frame is negatively correlated with the weight of the first enhancement map, that is, the greater the weight of the first enhancement map, the smaller the weight of each video frame. In an optional example, the weight of each video frame = 1-the weight of the first enhancement map = 1-the enhancement coefficient. Under this condition, the calculation method of the second enhancement map can be as follows:
[0161] I enh =αI′ enh +(1-α)I
[0162] S730: According to the interest region information of each video frame, the interest region of the second enhancement map is merged with the non-interest region of each video frame to obtain an interest enhancement map corresponding to each video frame.
[0163] For each video frame, after obtaining its corresponding second enhancement image, the interest region of the second enhancement image can be spliced with the non-interest region of the video frame to obtain the interest enhancement image.
[0164] Optionally, each video frame may be subjected to denoising to obtain a denoised image corresponding to each video frame, and the region of interest of the second enhanced image may be merged with the region of non-interest of the denoised image to obtain an enhanced image of interest corresponding to each video frame.
[0165] The specific merging method can be flexibly set according to actual needs. In an optional example, under the condition that the region of interest information is a region of interest mask, merging can be performed in the following manner:
[0166] O=M·I enh +(1-M)·I sml
[0167] Where O is the interest enhancement map of image I, M is the mask of the region of interest of image I, (1-M) is the mask of the non-interest region, and I sml is a reference image of the image I, which may be the image I itself or a denoised image obtained by performing denoising processing on the image I.
[0168] It should be noted that Figure 7 The specific implementation details of steps S210-S220 and step S240 shown in FIG. Figure 2 Steps S210 to S220, and step S240 are shown. Figure 7 The specific implementation details of steps S410 to S420 shown in FIG. Figure 4 Steps S410 to S420 shown are not repeated here.
[0169] exist Figure 7 In the illustrated embodiment, after performing image enhancement on each video frame to obtain a first enhanced image, each video frame and the first enhanced image are fused according to the enhancement coefficient to obtain a second enhanced image, and then the region of interest information of the second enhanced image is merged with the region of non-interest of the video frame to obtain an interest enhancement image, which can improve the matching image between the interest enhancement image and its corresponding video frame and avoid the loss of important information of the video frame during the interest enhancement process.
[0170] In an exemplary embodiment, see Figure 8 , Figure 8 is Figure 7 Based on the flowchart of a video encoding method proposed in FIG. 1 , under the condition that the region of interest information includes a region of interest mask, step S730 may include steps S810 to S830, which are described in detail as follows:
[0171] Step S810 , softening the edge of the region of interest of the region of interest mask to obtain a softened region of interest mask, and calculating a non-region of interest mask of each video frame based on the softened region of interest mask.
[0172] In order to avoid the boundary between the region of interest and the non-region of interest being too obvious after merging, which may cause image distortion, for each video frame, the edge (i.e., the outline) of the region of interest in its region of interest mask may be softened, thereby obtaining a softened region of interest mask of the video frame. The region of interest edge may be softened by using a method such as Gaussian blur.
[0173] Then, based on the softened region of interest mask, the non-region of interest mask can be calculated.
[0174] Step S820: The softened region of interest mask is fused with the second enhancement image to obtain a first fused enhancement image, and the non-region of interest mask is fused with each video frame to obtain a second fused enhancement image.
[0175] For each video frame, the softened region of interest mask is fused with the second enhancement image to obtain a first fused enhancement image, that is, the first fused enhancement image contains the region of interest of the second enhancement image, wherein the specific fusion method can be flexibly set according to actual needs, for example, the product between the softened region of interest mask and the second enhancement image can be calculated; the non-interest region mask is fused with each video frame to obtain a second fused enhancement image, that is, the second fused enhancement image contains the non-interest region of each video frame, wherein the specific fusion method can be flexibly set according to actual needs, for example, the product between the non-interest region mask and each video frame can be calculated.
[0176] Optionally, for each video frame, the mask of the non-interested region may be fused with the noise reduction image to obtain a second fused enhanced image.
[0177] Step S830: merge the first fusion enhancement map and the second fusion enhancement map to obtain an interest enhancement map corresponding to each video frame.
[0178] The first fused enhancement image and the second fused enhancement image are fused, so that the region of interest of the second enhancement image is fused with the non-region of interest of each video frame to obtain the enhancement image of interest.
[0179] In an optional example, the interest enhancement map of a video frame may be calculated in the following manner:
[0180] O=M soft I enh +(1-M soft )·I sml
[0181] Among them, M soft Mask to soften the region of interest.
[0182] In an alternative example, see Fig. 9 As shown, Fig. 9 The process of processing any image I to obtain an interest enhancement map includes steps 3.1 to 3.6, which are described in detail as follows:
[0183] Step 3.1, perform region of interest detection on image I to obtain its region of interest mask M.
[0184] The region of interest mask is obtained as follows:
[0185] M=f sd (I)
[0186] Among them, f sd (·) represents the region of interest detection process.
[0187] Step 3.2, softening the edge of the region of interest of the region of interest mask to obtain a softened region of interest mask.
[0188] The softened region of interest mask is obtained as follows:
[0189] M soft =f soft (M)
[0190] Among them, f soft (·) indicates the process of softening the edges.
[0191] Step 3.3, perform image enhancement on image I to obtain a first enhanced image.
[0192] The first enhanced map is obtained as follows:
[0193] I′ enh =f enh (I)
[0194] Among them, f enh (·) represents the image enhancement process, I′ enh represents the first enhancement graph.
[0195] Step 3.4, performing adaptive image enhancement on the first enhanced image to obtain a second enhanced image.
[0196] The second enhanced map is obtained as follows:
[0197] I enh =f ada (I′ enh ,I,M soft )
[0198] The texture complexity of the region of interest may be determined according to the softened region of interest mask, and then the enhancement coefficient may be calculated.
[0199] Step 3.5, obtain a reference image of image I.
[0200] The reference image is obtained as follows:
[0201] I sml =I or I sml =f dn (I)
[0202] Among them, f dn (·) indicates the noise reduction process.
[0203] Step 3.6, the second enhanced image and the reference image are fused according to the softened region of interest mask to obtain the enhanced image of interest.
[0204] The specific method of fusing the second enhanced image and the reference image to obtain the interest enhanced image can refer to steps S820 to S830.
[0205] The video frame can be used as image I through Fig. 9 Compute interest enhancement maps for video frames.
[0206] Optionally, the process of obtaining the interest enhancement map can be encapsulated as an FFmpeg filter, so that the image is processed into the interest enhancement map through the FFmpeg filter. FFmpeg is an open source computer program that can be used to record and convert digital audio and video and convert them into streams.
[0207] It should be noted that Figure 8 The specific implementation details of steps S210-S220 and step S240 shown in FIG. Figure 2 Steps S210 to S220, and step S240 are shown. Figure 8 The specific implementation details of steps S410 to S420 shown in FIG. Figure 4 Steps S410 to S420 are shown. Figure 8 The specific implementation details of steps S710 to S720 shown in FIG. Figure 7 Steps S710 to S720 shown are not repeated here.
[0208] exist Figure 8 In the illustrated embodiment, the edge of the region of interest of the region of interest mask is softened to obtain a softened region of interest mask, and then an interest enhancement map is calculated based on the softened region of interest mask. This can avoid the problem of too obvious boundaries between the region of interest and the non-region of interest after encoding, thereby improving the quality of the encoded video.
[0209] In an exemplary embodiment, see Fig.10 , Fig.10 is Figure 2 Based on the flowchart of a video encoding method proposed in FIG. 1 , under the condition that the region of interest information includes a region of interest mask, step S220 may include steps S1010 to S1020, which are described in detail as follows:
[0210] Step S1010 , detecting the edge corresponding to the region of interest of each video frame to obtain an edge mask of each video frame.
[0211] In order to obtain the region of interest mask of each video frame, the edge (i.e., contour) corresponding to the region of interest of each video frame can be detected to obtain an edge mask. The edge mask of each video frame contains the probability that each pixel in the video frame is located at the edge of the region of interest, that is, the pixel value of each pixel in the edge mask represents the probability that the pixel is located at the edge of the region of interest, wherein the value range of the probability can be [0,1], or the probability can be 0 or 1.
[0212] Step S1020 , performing region of interest detection on each video frame according to the edge mask to obtain a region of interest mask for each video frame.
[0213] After the edge mask of each video frame is obtained, the region of interest of the video frame can be detected according to the edge mask to obtain a region of interest mask.
[0214] It should be noted that Fig.10 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210, S230-S240 shown are not repeated here.
[0215] exist Fig.10 In the illustrated embodiment, the edge mask is detected first, and then the region of interest mask is detected based on the edge mask, which can improve the detection accuracy.
[0216] In an exemplary embodiment, see Fig.11 , Fig.11 is Fig.10 The flowchart of a video encoding method proposed based on the figure, step S1020 may include steps S1110-step S1120, which are described in detail as follows:
[0217] Step S1110, obtaining a focus probability map corresponding to each video frame.
[0218] The focus probability map of an image is used to describe the focus probability of a pixel in the image being in the focus area, that is, the pixel value of each pixel in the focus probability map represents the focus probability of the pixel being in the focus area, where the focus probability value range can be [0,1], or, in an optional example, the focus probability value range can be 0, 1.
[0219] Step S1120 , performing region of interest detection on each video frame according to the focus probability map and the edge mask, and obtaining a region of interest mask of each video frame.
[0220] For each video frame, the region of interest of each video frame can be detected according to its focus probability map and edge mask, so as to obtain a region of interest mask.
[0221] Among them, the detection method can be flexibly set according to actual needs. In an optional implementation, each video frame, the focus probability map of each video frame, and the edge mask can be fused to obtain a focus fusion map, and then the region of interest of the focus fusion map is detected. Since the focus fusion map enhances the focus area and the edge of the region of interest based on each video frame, the accuracy of the detected region of interest can be improved by detecting the region of interest based on the focus fusion video frame.
[0222] It should be noted that Fig.11 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210, S230-S240 shown, Fig.11 The specific implementation details of step S1010 shown in FIG. Fig.10 The step S1010 shown is not repeated here.
[0223] exist Fig.11 In the embodiment shown, the mask of the region of interest is detected based on the focus probability map and the edge mask, which can improve the accuracy of the mask of the region of interest, thereby improving the quality of the encoded video. In addition, for PGC videos, the region of interest is usually focused on, while the non-interested regions are blurred. Therefore, detecting the mask of the region of interest based on the focus probability map can greatly improve the accuracy of the mask of the region of interest.
[0224] In an exemplary embodiment, see Fig.12 , Fig.12 is Fig.11 The flowchart of a video encoding method proposed based on the figure, step S1120 may include steps S1210 to S1230, which are described in detail as follows:
[0225] Step S1210: extract shallow features of each video frame to obtain a shallow feature map of each video frame, and fuse the focus probability map and the shallow feature map to obtain a focus attention feature of each video frame.
[0226] It should be noted that the shallow features of an image refer to the visually perceptible features of the image, such as color, shape, and texture, and the shallow features of the image can be extracted through a shallow network. In an optional embodiment, the shallow feature map can be extracted through a convolutional layer and an encoder, wherein the image can be convolved through the convolutional layer, and the feature map output by the convolutional layer can be extracted through the encoder to obtain the shallow feature map of the image.
[0227] For each video frame, the shallow features of the video frame can be extracted to obtain its corresponding shallow feature map. Then, the shallow feature map of the video frame and the focus probability map are fused to obtain the focus attention feature. That is to say, in the focus attention feature, the focus area of the shallow feature map is enhanced.
[0228] Among them, the specific method of calculating the focus attention feature includes but is not limited to: calculating the product between the focus probability map and the shallow feature map to obtain the focus attention feature; or calculating the sum between the focus probability map and the shallow feature map to obtain the focus attention feature.
[0229] Step S1220, the edge mask, the focus attention feature and the shallow feature map are fused to obtain an enhanced shallow feature map.
[0230] For each video frame, its edge mask, focus attention feature and shallow feature map are fused to obtain the enhanced shallow feature map corresponding to the video frame. That is to say, the enhanced shallow feature map enhances the edges of the focus area and the area of interest in the shallow feature map.
[0231] Among them, the specific method of fusing the edge mask, focus attention feature and shallow feature map can be flexibly set according to actual needs. In an optional example, the edge mask, focus attention feature and shallow feature map can be added to obtain an enhanced shallow feature map. In another optional example, the product of the edge mask, focus attention feature and shallow feature map can be calculated to obtain an enhanced shallow feature map.
[0232] In an optional implementation, the shallow feature map and the focus probability map may be input into the shallow feature enhancement layer to obtain an enhanced shallow feature map output by the shallow feature enhancement layer.
[0233] In an optional implementation, the edge mask can be obtained by detecting the shallow feature map. Alternatively, the high-frequency feature map can be obtained by high-pass filtering the shallow feature map, and then the edge mask can be extracted from the high-frequency feature map through the self-attention layer and the receptive field layer. The edge mask can also be extracted by enhancing the shallow feature map.
[0234] Step S1230, extracting a deep feature map from the enhanced shallow feature map, and detecting the deep feature map to obtain a region of interest mask for each video frame.
[0235] For each video frame, further feature extraction is performed on its enhanced shallow feature map to obtain a deep feature map, and the region of interest of the video frame is detected according to the deep feature map to obtain a region of interest mask.
[0236] It should be noted that Fig.12 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210, S230-S240 shown, Fig.12 The specific implementation details of step S1010 shown in FIG. Fig.10 In step S1010 shown, Fig.12 The specific implementation details of step S1110 shown can be referred to Fig.11 The step S1110 shown is not repeated here.
[0237] exist Fig.12 In the illustrated embodiment, the focus probability map and the shallow feature map are fused to obtain the focus attention feature, and then the edge mask, the focus attention feature and the shallow feature map are fused to obtain an enhanced shallow feature map, thereby enhancing the focus area and the edges of the region of interest in the enhanced shallow feature map, and feature extraction is performed based on the enhanced shallow feature map to obtain a region of interest mask, which can improve the accuracy of the region of interest mask.
[0238] In an exemplary embodiment, see Fig.13 , Fig.13 is Fig.10 A flowchart of a video encoding method proposed based on the above is shown. Under the condition that the edge mask and the region of interest mask of each video frame are obtained by detecting each video frame by the detection model, the video encoding method may further include steps S1310 to S1330, which are described in detail as follows:
[0239] Step S1310, obtaining a target edge mask and a target region of interest mask corresponding to the sample image, and detecting the sample image through a detection model to obtain a predicted edge mask and a predicted region of interest mask of the sample image.
[0240] It should be noted that in the process of detecting the region of interest mask of a video frame, the video frame can be input into a detection model, and the detection model detects the video frame to obtain a predicted edge mask calculated by the detection model, and the predicted edge mask is used as the edge mask of the video frame. Then, the detection model performs further detection based on the edge mask and outputs a predicted region of interest mask, which is used as the region of interest mask of the video frame.
[0241] The sample image refers to an image used to optimize the detection model, the target edge mask of the sample image refers to the edge mask expected to be obtained from the sample image, and the target region of interest mask of the sample image refers to the region of interest mask expected to be obtained from the sample image. Optionally, the value range of any pixel value in the target edge mask and the target region of interest mask can be [0,1], or can be 0 or 1, and the target edge mask can be extracted from the target region of interest mask. The predicted edge mask refers to the edge mask calculated by the detection model, and the predicted region of interest mask refers to the region of interest mask output by the detection model.
[0242] In order to optimize the detection model, a sample image and its corresponding target edge mask and target region of interest mask can be obtained. Then, the sample image is input into the detection model, and the detection model detects the sample image to obtain a predicted edge mask of the sample image. Then, the detection model performs further detection based on the predicted edge mask and outputs a predicted region of interest mask of the sample image.
[0243] In an optional implementation, in order to improve the detection model to be applicable to image detection with different resolutions, images with different resolutions may be obtained as sample images. For example, the sample images may include low-resolution images with a resolution lower than a set first threshold and high-resolution images with a resolution higher than a set second threshold, wherein the first threshold is less than or equal to the second threshold, and the specific value may be flexibly set according to actual needs.
[0244] The number and source of sample images may be flexibly set according to actual needs. In an optional example, 15,000 images may be obtained as sample images, and the sample images may include low-resolution images and high-resolution images.
[0245] In an optional implementation, after acquiring the sample image, the resolution of the sample image can be adjusted to a set resolution, and then the sample image is input into the detection model for detection. The specific value of the set resolution can be flexibly set according to actual needs, for example, it can be 640×640.
[0246] Step S1320, calculating the model loss according to the difference between the target edge mask and the predicted edge mask to obtain an edge loss value, and calculating the model loss according to the difference between the target region of interest mask and the predicted region of interest mask to obtain a region loss value.
[0247] For the sample image, the model loss is calculated based on the difference between the target edge mask and the predicted edge mask, and the loss is recorded as the edge loss value. That is, the edge loss value is used to characterize the difference between the target edge mask and the predicted edge mask. The greater the difference, the greater the edge loss. The model loss is calculated based on the difference between the target region of interest mask and the predicted region of interest mask, and the loss is recorded as the regional loss value. That is, the regional loss is used to characterize the difference between the target region of interest mask and the predicted region of interest mask. The greater the difference, the greater the regional loss.
[0248] In the process of calculating the edge loss value, the weights corresponding to the multiple pixels included in the target edge mask can be obtained, wherein the weight of each pixel is negatively correlated with the distance of each pixel relative to the edge of the region of interest of the target edge mask, that is, the closer the distance between the pixel and the edge of the region of interest, the greater the weight; then, the predicted edge mask and the target edge mask are pixel-aligned to find the predicted pixel corresponding to each pixel of the target coding mask from the predicted coding mask, and the pixel loss value corresponding to each pixel is calculated according to the difference between each pixel and the predicted pixel, and the pixel loss value corresponding to the multiple pixels of the target edge mask is weighted and summed according to the obtained weights to obtain the edge loss value. Among them, whether it is a pixel within the edge of the region of interest or a pixel outside the edge of the region of interest, the corresponding weight can be calculated according to its distance from the edge of the region of interest, that is, as long as it is located near the edge of the region of interest, whether it is located inside or outside the edge, the corresponding weight is higher.
[0249] The specific method for calculating the weight corresponding to each pixel in the target edge mask can be flexibly set according to actual needs, for example, including but not limited to the following methods:
[0250] The first method is to calculate the distance between each pixel and the edge of the region of interest, and calculate the weight of the pixel based on the distance, where the distance is negatively correlated with the weight.
[0251] The second method: according to different filtering parameters, the target edge mask is filtered respectively to obtain multiple filtered edge masks, the difference map between each filtered edge mask and the target edge mask is calculated, and the difference maps corresponding to the multiple filtered edge masks are fused to obtain a fused edge difference map, and the weight map corresponding to the target edge mask is calculated according to the fused edge difference map; wherein the weight map contains the weight of each pixel in the target edge mask.
[0252] The method of filtering the target edge mask includes but is not limited to mean filtering and Gaussian filtering. The filtering methods corresponding to multiple filtering edge masks are the same, but the filtering parameters are different. If the filtering method is mean filtering, the filtering templates corresponding to the multiple filtering edge masks can be different, and the specific size of the filtering template can be flexibly set according to actual needs.
[0253] In an optional embodiment, according to the fused edge difference map, calculating the weight map corresponding to the target edge mask may include: calculating the product between the first edge fusion factor, the fused edge difference map and the target edge mask, adding the product to the second edge fusion factor, and obtaining the weight map corresponding to the target edge mask. Among them, the specific values of the first edge fusion factor and the second edge fusion factor can be flexibly set according to actual needs. In an optional example, when the filtering method is mean filtering, the filtering templates include 3×3, 15×15 and 31×31, the first edge fusion factor is 0.5, and the second edge fusion factor is 1, the weight map corresponding to the target edge mask can be obtained as follows:
[0254]
[0255]
[0256] Among them, ω edge is the weight map of the target edge mask, Indicates that the filter template is a k×k mean filtering process, is the target edge mask, are the filter edge masks, 0.5 is the first edge fusion factor, and 1 is the second edge fusion factor.
[0257] Among them, the types of loss functions corresponding to the calculation of edge loss values include but are not limited to binary cross entropy loss function, intersection-over-union loss function, L1 loss function, etc. In the process of calculating edge loss values based on loss functions, the pixel loss value of each pixel in the target edge mask can be calculated by the loss function, and then the pixel loss values are weighted and summed according to the weights of the pixels to obtain the edge loss value. For example, the method of calculating edge loss values by binary cross entropy loss function can be as follows:
[0258]
[0259] The way to calculate the edge loss value through the intersection-over-union loss function can be as follows:
[0260]
[0261] The way to calculate the edge loss value through the L1 loss function can be as follows:
[0262]
[0263] in, They represent the edge loss values calculated by the binary cross entropy loss function, the intersection-over-union loss function, and the L1 loss function, respectively. Represents the weight of the pixel with position coordinate (i, j) in the target edge mask, that is, ω edge The weight of the pixel with position coordinates (i, j) in ; represents the pixel value of the pixel at position coordinate (i, j) in the target edge mask. The size of the target edge mask of image I is consistent with the size of image I. h and w represent the height and width of the target edge mask (that is, the height and width of image I), respectively. Represents the predicted edge mask M edge The edge mask obtained by upsampling, The height and width of are consistent with the target edge mask. express The pixel value of the pixel point with position coordinates (i, j) in .
[0264] Step S1330, calculate the total model loss value according to the edge loss value and the area loss value, and update the detection model according to the total model loss value.
[0265] After obtaining the edge loss value and the regional loss value, the edge loss value and the regional loss value are summed to obtain the total model loss value, so as to update the detection model according to the total model loss value.
[0266] In an optional implementation, the weights corresponding to the edge loss value and the regional loss value may be obtained, and the edge loss value and the regional loss value may be weightedly summed according to the weights to obtain a total model loss value.
[0267] Among them, one or more loss functions can be used to calculate the edge loss value, or one or more loss functions can be used to calculate the edge loss value. Under the condition that multiple loss functions are used to calculate the edge loss value and multiple loss functions are used to calculate the regional loss value, the edge loss values calculated by the multiple loss functions can be weighted and summed according to the weights corresponding to the multiple loss functions to obtain the total edge loss value; the regional loss values calculated by the multiple loss functions can be weighted and summed according to the weights corresponding to the multiple loss functions to obtain the total regional loss value; then, the total edge loss value and the total regional loss value are weighted and summed to obtain the total model loss value, and the detection model is updated according to the total model loss value. Among them, the weights corresponding to the loss function, the weights corresponding to the total edge loss value, and the weights corresponding to the total regional loss value can be flexibly set according to actual needs, and the loss function for calculating the edge loss and the loss function for calculating the regional loss can be the same or different.
[0268] It should be noted that Fig.13 The model updating process shown can be applied to the training process of the detection model; Fig.13 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210, S230-S240 shown, Fig.13 The specific implementation details of steps S1010 to S1020 can be referred to Fig.10 Steps S1010 to S1020 shown are not repeated here.
[0269] exist Fig.13 In the illustrated embodiment, the total model loss is calculated based on the difference between the predicted edge mask and the target edge mask, and the difference between the predicted region of interest mask and the target region of interest mask, and then the detection model is updated based on the total model loss. This can improve the accuracy of the detection model, and this model update method can be applied to the training process of the detection model to improve the model training speed.
[0270] In an exemplary embodiment, see Fig.14 , Fig.14 is Figure 2 A flowchart of a video encoding method proposed based on the above is shown. Under the condition that the region of interest information includes a region of interest mask obtained by detecting each video frame through a detection model, the video encoding method may further include steps S1410 to S1440, which are described in detail as follows:
[0271] Step S1410, obtaining a target ROI mask corresponding to the sample image, and obtaining weights corresponding to a plurality of pixels included in the target ROI mask; wherein the weight of each pixel is negatively correlated with the distance of each pixel relative to the ROI edge of the target ROI mask.
[0272] The region of interest information may be detected by a detection model, and the region of interest information may be a region of interest mask. Under this condition, in order to optimize the detection model, a sample image and a target region of interest mask corresponding to the sample image may be obtained.
[0273] In order to improve the accuracy of the region of interest detected by the detection model, for each pixel in the target region of interest mask, the weight of the pixel can be determined based on the distance between the pixel and the edge of the region of interest, where the closer the distance, the greater the weight.
[0274] The specific method of obtaining the weight of each pixel in the ROI mask can be flexibly set according to actual needs. In an optional implementation, the distance between each pixel and the edge of the ROI can be calculated, and the weight can be determined based on the distance.
[0275] It should be noted that, whether it is a pixel point within the edge of the target region of interest mask or a pixel point outside the edge of the region of interest, the corresponding weight can be calculated based on its distance from the edge of the region of interest. In other words, as long as it is located near the edge of the region of interest, the corresponding weight is higher regardless of whether it is located inside or outside the edge.
[0276] Step S1420 , detecting the sample image by using the detection model to obtain a predicted region of interest mask of the sample image, and determining a predicted pixel point corresponding to each pixel point from the predicted region of interest mask.
[0277] The sample image is input into the detection model to obtain the predicted region of interest mask of the sample image output by the detection model. In order to calculate the model loss, for each pixel in the target region of interest mask, the pixel corresponding to the pixel can be found from the predicted region of interest mask, and the found pixel is used as the predicted pixel, thereby obtaining the predicted pixel corresponding to each pixel in the target region of interest mask.
[0278] In an optional implementation, the target ROI mask and the predicted ROI mask may be pixel-aligned, and then, for each pixel in the target ROI mask, a pixel aligned with the pixel may be searched in the predicted ROI mask as the predicted pixel.
[0279] Step S1430, calculates the pixel loss value corresponding to each pixel according to the difference between each pixel and the predicted pixel, and performs weighted summation on the pixel loss values corresponding to multiple pixels according to the obtained weights to obtain the regional loss value.
[0280] For each pixel in the target region of interest mask, the loss between the pixel and the predicted pixel corresponding to the pixel is calculated to obtain the pixel loss value of the pixel. Then, according to the weights corresponding to the multiple pixels contained in the target region of interest mask, the pixel loss values corresponding to the multiple pixels are weighted summed to obtain the regional loss value.
[0281] Step S1440, updating the detection model according to the area loss value.
[0282] After obtaining the regional loss value, the detection model can be updated according to the regional loss value.
[0283] In an optional embodiment, the regional loss value can be calculated according to a loss function. Correspondingly, the pixel loss value is calculated by the loss function, and then the pixel loss values corresponding to the multiple pixels are weighted summed according to the weights corresponding to the multiple pixels contained in the mask of the target area of interest to obtain the regional loss value.
[0284] In another optional implementation, the regional loss values may be calculated separately according to a plurality of loss functions, the regional loss values calculated by the plurality of loss functions may be summed to obtain a total regional loss value, and then the detection model may be updated according to the total regional loss value.
[0285] It should be noted that Fig.14 The specific implementation details of steps S210 to S240 shown in FIG. Figure 2 Steps S210 to S240 shown are not repeated here.
[0286] exist Fig.14 In the embodiment shown, in the process of calculating the model loss based on the target region of interest mask and the predicted region of interest mask, the weight of the pixel points at the edge of the region of interest is increased, and the detection model is updated based on the model loss. This can improve the accuracy of the detection model. Applying this model update method to the model training process of the detection model can improve the model training efficiency.
[0287] In an exemplary embodiment, see Fig.15 , Fig.15 is Fig.14 The flowchart of a video encoding method proposed based on the figure, step S1410 may include steps S1510-step S1540, which are described in detail as follows:
[0288] Step S1510, obtaining a target region of interest mask corresponding to the sample image.
[0289] Optionally, the target region of interest mask may be manually set.
[0290] Step S1520 , performing mean filtering on the target region of interest masks according to different filtering parameters, to obtain a plurality of region filtering region masks.
[0291] A plurality of filtering parameters are pre-set, and the target region of interest mask is filtered by each filtering parameter to obtain a filtering region mask corresponding to the filtering parameter, thereby obtaining a plurality of filtering region masks, which are low-frequency images of the target region of interest mask.
[0292] The filtering method may be mean filtering, and the corresponding filtering parameters may be multiple different filtering templates, wherein the specific size of the filtering template may be flexibly set according to actual needs. In an optional example, the multiple filtering templates may include 3×3, 15×15, and 31×31.
[0293] It should be noted that, in this embodiment, the filtering method is mean filtering, and in other embodiments, the filtering method may also be any filtering method that can obtain a low-frequency image, such as Gaussian filtering.
[0294] Step S1530 , calculating a difference map between each filter region mask and the target region of interest mask, and fusing the difference maps corresponding to the plurality of filter region masks to obtain a fused region difference map.
[0295] The difference between each filter area mask and the target region of interest mask is calculated to obtain a difference map, which can characterize the edge of the target region of interest, and is a high-frequency image of the target region of interest mask. Then, the difference maps corresponding to the multiple filter area masks are fused to obtain a fused region difference map, and the fusion method includes but is not limited to a summation operation.
[0296] Step S1540, obtaining a weight map corresponding to the target region of interest mask according to the fused region difference map; wherein the weight map includes the weight of each pixel in the target region of interest mask.
[0297] After obtaining the fused region difference map, the weight map corresponding to the target region of interest mask can be obtained according to the fused region difference map, wherein the weight map contains the weight of each pixel in the target region of interest mask, that is, the weight map is an image of the same size as the target region of interest mask, the pixels in the weight map correspond one-to-one to the pixels in the target region of interest mask, and the pixel values in the weight map represent the weights of the corresponding pixels.
[0298] In an optional implementation, the product between the first region fusion factor and the fusion region difference map can be calculated, and then the product and the second region fusion factor are summed to obtain a weight map of the target region of interest mask, wherein the first region fusion factor and the second region fusion factor are values greater than or equal to 0, and their specific values can be flexibly set according to actual needs. In an optional example, under the condition that multiple filter templates can include 3×3, 15×15 and 31×31, the first region fusion factor is 0.5, and the second region fusion factor is 1, the weight map can be calculated by the following formula:
[0299]
[0300] ω G =1+0.5×(|G1-G|+|G2-G|+|G3-G|)
[0301] Among them, G is the target region of interest mask, G1 is the filter region mask obtained by filtering G using a 3×3 filter template, G2 is the filter region mask obtained by filtering G using a 15×15 filter template, and G3 is the filter region mask obtained by filtering G using a 31×31 filter template. G is the weight map of the target edge mask.
[0302] It should be noted that Fig.15 The specific implementation details of steps S210 to S240 shown in FIG. Figure 2 Steps S210 to S240 are shown. Fig.15 The specific implementation details of steps S1420 to S1440 shown in FIG. Fig.14 Steps S1420 to S1440 shown are not repeated here.
[0303] exist Fig.15 In the illustrated embodiment, according to different filtering parameters, the target region of interest mask is respectively subjected to mean filtering to obtain a plurality of filtering region masks, a difference map between each filtering region mask and the target region of interest mask is calculated, and the difference maps corresponding to the plurality of filtering region masks are fused to obtain a fused region difference map, and a weight map corresponding to the target region of interest mask is obtained based on the fused region difference map, so that the weights of the pixels inside and outside the edge of the region of interest in the target region of interest mask can be larger, and the model loss is calculated based on the weight map and the detection model is updated, so that the accuracy of the detection model can be improved, and the model update method is applied to the model training process of the detection model to improve the model training efficiency.
[0304] In an exemplary embodiment, see Fig.16 , Fig.16 is Figure 2 A flowchart of a video encoding method proposed based on the above is shown. Under the condition that the region of interest information includes a region of interest mask, step S220 may include steps S1610 to S1620, which are described in detail as follows:
[0305] Step S1610, extracting features from the shallow feature map corresponding to each video frame to obtain a deep feature map.
[0306] For each video frame, its shallow feature map can be obtained, wherein the specific introduction of the shallow feature map can be found in the description of the aforementioned embodiment, which will not be repeated here.
[0307] After obtaining the shallow feature map corresponding to each video frame, feature extraction can be performed on the shallow feature map of each video frame to obtain a deep feature map.
[0308] Step S1620, based on the deep feature map, multiple candidate ROI masks corresponding to each video frame are calculated, and the multiple candidate ROI masks are fused to obtain the ROI mask of each video frame.
[0309] For each video frame, multiple candidate ROI masks corresponding to it can be calculated based on the deep feature map, and multiple candidate ROI masks can be fused to obtain the ROI mask.
[0310] In an optional embodiment, the process of calculating multiple candidate region of interest masks based on the deep feature map may include: calculating a first candidate region of interest mask based on the deep feature map, calculating a second candidate region of interest mask based on the first candidate region of interest mask, calculating a third candidate region of interest mask based on the second candidate region of interest mask, and so on, until multiple region of interest masks are obtained.
[0311] In an optional implementation, shallow feature enhancement can be performed on the shallow feature map to obtain an enhanced shallow feature map, feature extraction is performed based on the enhanced shallow feature map to obtain a first deep feature map, and then, feature extraction is performed on the first deep feature map to obtain a second deep feature map, and feature extraction is performed on the second deep feature map to obtain a third deep feature map, and so on, until multiple deep feature maps are obtained, and the multiple deep feature maps are fused to obtain a fused deep feature map, and then a first candidate region of interest mask is calculated based on the fused deep feature map, wherein the fused deep feature map can be directly used as the first candidate region of interest mask.
[0312] Optionally, under the condition that the first candidate region of interest mask is calculated based on the fused deep feature map (i.e., if i=1, the i-th candidate region of interest mask is calculated based on the fused deep feature map), if i=num, the i-th candidate region of interest mask can be calculated based on the i-1-th candidate region of interest mask and the enhanced shallow feature map; if i∈[2, num-1], the i-th candidate region of interest mask can be calculated based on the i-1-th candidate region of interest mask and the ni-th deep feature map, where num is the number of candidate region of interest masks.
[0313] Among them, the specific method of obtaining the enhanced shallow feature map based on the shallow feature map can be found in the description of the aforementioned embodiment, and will not be repeated here.
[0314] In an optional implementation, steps S1610 to S1620 may be implemented by a detection model, wherein the video frame may be used as an input image of the detection model, and a predicted region of interest mask of the input image output by the detection model may be obtained, and the predicted region of interest mask may be used as the region of interest mask of the video frame. The specific structure of the detection model may be flexibly set according to actual needs. In an optional example, see Fig.17A As shown, the detection model may include a feature extraction module, a feature fusion module, and a mask prediction module. Specifically:
[0315] The feature extraction module includes a convolutional layer, an encoder 1, a shallow feature enhancement layer, and encoders 2-4 connected in sequence. The feature extraction process includes steps 4.1-4.6, which are described in detail as follows:
[0316] Step 4.1: Extract features of image I through the convolution layer to obtain the feature map F output by the convolution layer. init .
[0317] Among them, the feature map F can be calculated by the following formula init :
[0318] F init =conv init (I)
[0319] conv init is the convolution operation of the convolution layer. The image I can have 3 channels, F init The number of channels and size can be set flexibly according to actual needs. For example, the number of channels can be 6 and the size can be
[0320] Step 4.2, through encoder 1, the feature map F init Perform feature extraction to obtain the shallow feature map F1.
[0321] F1=encoder1(F init )
[0322] Among them, encoder1 is the feature extraction function corresponding to encoder 1. The number of channels and size of the shallow feature map F1 can be flexibly set according to actual needs. For example, the number of channels can be 48 and the size can be
[0323] Step 4.3, the shallow feature map F1 is enhanced through the shallow feature enhancement layer to obtain an enhanced shallow feature map F2.
[0324] F2 = feat_enh(F1)
[0325] Among them, feat_enh(·) represents the shallow feature enhancement function, and the number of channels and size of the enhanced shallow feature map F2 can be the same as those of the shallow feature map F1.
[0326] In an optional example, the structure of the shallow feature enhancement layer can be as follows Fig. 17B As shown, the process of performing shallow feature enhancement on the shallow feature map F1 to obtain the enhanced shallow feature map F2 may include steps 4.31 to 4.35, which are described in detail as follows:
[0327] Step 4.31, high-pass filter the input shallow feature map F1 to obtain the high-frequency feature map F high .
[0328] F high =high_pass(F1)
[0329] Among them, high_pass represents the high-pass filter function.
[0330] Step 4.32, the high-frequency feature map F is processed by the self-attention layer and the receptive field layer. high Perform detection and obtain the predicted edge mask M edge .
[0331] M edge =f rfb1 (f sa (F high ))
[0332] Among them, f sa represents the processing process corresponding to the self-attention layer, f rfb1 Represents the processing process corresponding to the receptive field layer. The specific structure of the self-attention layer and the receptive field layer can be flexibly set according to actual needs.
[0333] In an optional example, the processing of the self-attention layer can be as follows Fig. 17C As shown, the high-frequency feature map F highPerform global average pooling and batch normalization to obtain features Figure X , and then through Fig. 17C The attention function in the feature Figure X The output of the attention function is convolved through the convolution layer, the output of the convolution layer is activated through the activation layer, and the output of the activation layer is combined with the high-frequency feature map F high Multiply the product with the high-frequency feature map F high Add them together to get the output of the self-attention layer, i.e. f sa (F high ).in, Fig. 17C The convolution kernel of the convolution layer in can be 1×1, and the activation layer can be a Sigmoid activation function.
[0334] The attention function is as follows:
[0335]
[0336] Among them, exp is the exponential function, It means to perform 1×1 convolution on X to get the query vector. It means to perform 1×1 convolution on X to get the key vector. It means performing a 1×1 convolution on X to obtain a value vector.
[0337] In an optional example, the processing of the receptive field layer can be as follows Fig.17D As shown, Fig.17D The convolution kernel sizes of the medium-depth separable convolution layers and convolution layers are only exemplary, and their convolution kernel sizes can be flexibly adjusted according to actual needs. The expansion rates of the 1×1 depth-separable convolution layer and the 3×3 depth-separable convolution layers 2-4 are not exactly the same, for example, they can be 1, 1, 3, and 5 respectively. The 1×1 convolution layers 2-5 are used to reduce the number of channels of their input feature maps, for example, to 1 / 4 of the number of channels of the input feature maps, and the 1×1 convolution layer 6 is used to reduce the number of channels of its input feature maps to 1. The activation function of the activation layer can be RELU.
[0338] Step 4.33, focus probability map M for input image I focus Scale the size.
[0339] Zoomed focus probability map M focus The size of matches that of the shallow feature map F1.
[0340] Step 4.34, the shallow feature map F1 and the scaled focus probability map M focus Multiply them to get the focus attention feature F focus .
[0341] F focus =M focus Formula 1
[0342] The multiplication may be point-to-point multiplication, that is, the pixel values of the pixel points with the same position coordinates are multiplied.
[0343] Step 4.35, the predicted edge mask M edge and the focus attention feature F focus Superimposed on the shallow feature map F1, we get the enhanced shallow feature map F2.
[0344] F2=F1+M edge +F focus
[0345] Step 4.4, extract features from the enhanced shallow feature map F2 through encoder 2 to obtain the first deep feature map E1.
[0346] E1=encoder2(F2)
[0347] Where encoder2 is the feature extraction function corresponding to encoder 2, and the number of channels and size of E1 can be flexibly set according to actual needs. For example, the number of channels can be 80 and the size can be
[0348] Step 4.5, extract features from the first deep feature map E1 through encoder 3 to obtain the second deep feature map E2.
[0349] E2=encoder3(E1)
[0350] Among them, encoder3 is the feature extraction function corresponding to encoder 3, and the number of channels and size of E2 can be flexibly set according to actual needs. For example, the number of channels can be 224 and the size can be
[0351] Step 4.6, extract features from the second deep feature map E2 through encoder 4 to obtain the third deep feature map E3.
[0352] E3=eencoder4(E2)
[0353] Among them, encoder4 is the feature extraction function corresponding to encoder 4, and the number of channels and size of E3 can be flexibly set according to actual needs. For example, the number of channels can be 224 and the size can be
[0354] It should be noted that Fig.17AIn the figure, the number of encoders used to extract deep feature maps is 3, and correspondingly, 3 deep feature maps are obtained. In practical applications, the number of encoders used to extract deep feature maps can be flexibly set according to actual needs. As the depth increases, the number of channels of the deep feature map increases and the size decreases.
[0355] The feature fusion module includes a feature transformation layer, a feature fusion layer, a self-attention layer 1, a batch normalization layer, a zeroing layer, and a self-attention layer 2 connected in sequence. The feature fusion process includes steps 5.1 to 5.4, which are described in detail as follows:
[0356] Step 5.1, perform feature transformation on multiple deep feature maps through the feature transformation layer to obtain transformed feature maps corresponding to the multiple deep feature maps.
[0357] Fig.17A In the example, the number of deep feature maps is 3. Correspondingly, the calculation method of the transformed feature map is as follows:
[0358] E′1=f rfb2 (E1)
[0359] E′2=f rfb2 (E2)
[0360] E′3=f rfb2 (E3)
[0361] Among them, E′1, E′2, and E′3 represent the transformation feature maps corresponding to E1, E2, and E3 respectively, and f rfb2 Represents the feature transformation process of the feature transformation layer. The feature transformation process will reduce the number of channels. The specific values of the number of channels of E′1, E′2, and E′3 can be flexibly set according to actual needs. In an optional example, the number of channels of E′1, E′2, and E′3 are 32, 64, and 128 respectively.
[0362] The specific process of feature transformation can be flexibly set according to actual needs. In an optional example, the feature transformation process can be as follows: Fig.17E As shown, Fig.17E In the above, the convolution kernel size of each convolution can be flexibly adjusted according to actual needs.
[0363] Step 5.2, multiple transformed feature maps are fused through the feature fusion layer to obtain the initial fused feature map E.
[0364] E=f agg (E′2,E′3,E′4)
[0365] The specific values of the number of channels and size of E can be flexibly set according to actual needs. For example, the number of channels can be 224 and the size can be fagg (·) indicates feature fusion.
[0366] Step 5.3, the initial fusion feature map E is subjected to channel feature enhancement and batch normalization through the self-attention layer 1 and the batch normalization layer to obtain the channel enhanced feature map E′ and the channel attention map A c , and the values of unimportant channels with a set proportion in the channel enhancement feature map E′ are set to 0 through the zeroing layer to obtain the channel attenuation feature map E″.
[0367] E′,A c =f bn (f sa (E)
[0368] E″=f drop (E′,A c )
[0369] Among them, f sa and f bn They represent the processing of self-attention layer 1 and batch normalization layer respectively. The number of channels and size of E′ can be flexibly set according to actual needs. For example, the number of channels is 224 and the size is A c represents the channel attention of each channel obtained by the self-attention layer, f drop (·) represents the process of weakening channel features. The number and size of channels of E″ can be flexibly set according to actual needs. The set ratio can be flexibly set according to actual needs. For example, it can be 10%. The unimportant channel can be a channel whose channel attention is less than a set threshold in the multiple channels corresponding to the channel enhancement feature map E′, or it can also be a set ratio of channels extracted from the multiple channels corresponding to the channel enhancement feature map E′ in the order of the corresponding channel attention from small to large.
[0370] Step 5.5, perform feature transformation on the channel attenuation feature map E″ through the self-attention layer 2 to obtain the fused deep feature map E F .
[0371] Among them, the specific processing process of the self-attention layer 2 can be flexibly set according to actual needs. In an optional example, the processing process is as follows:
[0372]
[0373] and There are three convolution operations with a kernel size of 1×1, fusing the deep feature map E. F The number of channels and size can be set flexibly according to actual needs. For example, the number of channels is 1 and the size is
[0374] The mask extraction process of the mask prediction module may include steps 6.1 to 6.5, and the detailed process is as follows:
[0375] Step 6.1: Fusion of deep feature map E F As the first candidate ROI mask D1.
[0376] The size of the first candidate ROI mask is the same as the size of the input image.
[0377] In step 6.2, the first candidate ROI mask D1 and the first deep feature map are processed through the object attention layer to obtain the second candidate ROI mask D2.
[0378] In step 6.3, the second candidate ROI mask and the enhanced shallow feature map are processed through the target attention layer to obtain the third candidate ROI mask D3.
[0379] In step 6.4, the candidate ROI mask is upsampled to obtain an upsampled ROI mask.
[0380] Upsample the candidate ROI masks D1, D2, and D3 respectively to obtain their corresponding upsampled ROI masks in, The number of channels is 1, and the size matches the size of image I.
[0381] Step 6.5, perform average weighted fusion on multiple upsampled ROI masks to obtain a predicted ROI mask D.
[0382]
[0383] For a video frame, it is used as an input image of a detection model to obtain a predicted region of interest mask output by the detection model, and the predicted region of interest mask is used as the region of interest mask of the video frame.
[0384] It should be noted that Fig.16 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210 to S220 and step S240 are shown and will not be described in detail here.
[0385] exist Fig.16 In the illustrated embodiment, a plurality of candidate ROI masks are first calculated, and then the plurality of candidate ROI masks are fused to obtain a ROI mask, which can improve the accuracy of the ROI mask.
[0386] In an exemplary embodiment, see Fig.18 , Fig.18 is Fig.16 A flowchart of a video encoding method proposed based on the above is shown. Under the condition that the region of interest mask is obtained by detecting each video frame through a detection model, the video encoding method may further include steps S1810 to S1840, which are described in detail as follows:
[0387] Step S1810, obtaining a sample image and a target region of interest mask corresponding to the sample image.
[0388] The ROI mask may be obtained through the detection model, that is, the steps S1610 to S1620 may be implemented through the detection model. Under this condition, in order to optimize the detection model, a sample image and a target ROI mask corresponding to the sample image may be obtained.
[0389] Step S1820, performing ROI detection on the sample image through the detection model to obtain multiple candidate ROI masks corresponding to the sample image, and fusing the multiple candidate ROI masks corresponding to the sample image to obtain a predicted ROI mask corresponding to the sample image.
[0390] The sample image is input into the detection model, the sample image is processed by the detection model to obtain multiple candidate region of interest masks corresponding to the sample image, and the multiple candidate region of interest masks are fused to obtain a predicted region of interest mask corresponding to the sample image.
[0391] Step S1830, calculating the model loss according to the differences between the multiple candidate ROI masks corresponding to the sample image and the target ROI mask, and the difference between the predicted ROI mask and the target ROI mask, to obtain a regional loss value.
[0392] For the sample image, the model loss is calculated according to the differences between its multiple candidate ROI masks and the target ROI mask, and the difference between the predicted ROI mask and the target ROI mask, to obtain the regional loss value. Among them, the loss between each candidate ROI mask and the target ROI mask can be calculated, the loss between the predicted ROI mask and the target ROI mask can be calculated, and the calculated losses can be summed to obtain the regional loss value.
[0393] Among them, the loss function can be used to calculate the regional loss value. Among them, the types of loss functions include but are not limited to binary cross entropy loss function, intersection-over-union loss function, L1 loss function, etc. In the process of calculating the candidate loss value based on the loss function, the regional loss value can also be calculated according to the weight map corresponding to the target edge region of interest mask. In an optional example, under the condition of containing 3 candidate region of interest masks, the method of calculating the regional loss through the binary cross entropy loss function can be as follows:
[0394]
[0395] The way to calculate the regional loss through the intersection-over-union loss function can be as follows:
[0396]
[0397] The way to calculate the regional loss through the L1 loss function can be as follows:
[0398]
[0399] in, They represent the regional loss values calculated by the binary cross entropy loss function, the intersection-over-union loss function, and the L1 loss function, respectively. Represents the weight of the pixel with position coordinates (i, j) in the target region of interest mask, that is, ω G The weight of the pixel with the position coordinate (i, j) in G; i,j represents the pixel value of the pixel point with the position coordinate (i, j) in the target region of interest mask; D i,i represents the pixel value of the pixel with the position coordinate (i, j) in the predicted ROI mask, D1, D2, and D3 represent the first, second, and third candidate ROI masks, respectively. Respectively represent the pixel value of the pixel point with position coordinates (i, j) in D1, D2, and D3.
[0400] Step S1840, updating the detection model according to the area loss value.
[0401] After obtaining the regional loss value, the detection model can be updated according to the regional loss value.
[0402] If multiple loss functions are used to calculate the regional loss value, the regional loss values calculated by the multiple loss functions can be weighted summed according to the weights corresponding to the multiple loss functions to obtain the total regional loss value, and the detection model can be updated according to the total regional loss value.
[0403] Optionally, the detection model can also detect the edge mask of the video frame, and detect the mask of the region of interest based on the edge mask. Under this condition, the edge loss value can also be calculated, and the detection model can be updated based on the edge loss value and the region loss value.
[0404] It should be noted that Fig.18 The specific implementation details of steps S210, S230-S240 shown in FIG. Figure 2 Steps S210 to S220, and step S240 are shown. Fig.18 The specific implementation details of steps S1610 to S1620 shown in FIG. Fig.16 Steps S1610 to S1620 shown are not repeated here.
[0405] exist Fig.18 In the illustrated embodiment, in the process of calculating the model loss, not only the difference between the predicted region of interest mask and the target region of interest mask is referenced, but also the difference between the candidate region of interest mask and the target region of interest mask is referenced, which can improve the accuracy of the model loss. Updating the detection model based on the model loss can improve the accuracy of the detection model. Applying the model updating method to the training process of the detection model can improve the model training efficiency.
[0406] In an exemplary embodiment, see Fig.19 , Fig.19 is Figure 2 The flowchart of a video encoding method proposed based on the figure, step S240 may include steps S1910-step S1920, which are described in detail as follows:
[0407] Step S1910, obtaining target encoding parameters corresponding to the source video.
[0408] The reference coded video of the source video refers to a video obtained by encoding multiple video frames contained in the source video, and the target coded video refers to a video obtained by encoding multiple interest enhancement images corresponding to the source video. In order to match the bit rate of the reference coded video with that of the target coded video, the target coding parameters can be obtained.
[0409] The target coding parameters refer to parameters used to encode the interest enhancement graph, and the types thereof include but are not limited to bit rate and constant rate factor (crf).
[0410] In an optional embodiment, the source video can be encoded to obtain a reference encoded video of the source video, and the bit rate of the reference encoded video can be used as a target encoding parameter to encode the interest enhancement graph according to the bit rate of the reference encoded video to obtain the target encoded video. The target encoded video obtained in this way has a high degree of match between the bit rates of the reference encoded video.
[0411] Step S1920, encoding the source video according to the target encoding parameters to obtain a target encoded video whose corresponding bit rate matches the bit rate of the reference encoded video; wherein the reference encoded video is obtained by encoding the source video.
[0412] By encoding the multi-frame interest enhancement graphs corresponding to the source video based on the target encoding parameters, the bit rate of the obtained target encoded video can be matched with the bit rate of the reference encoded video.
[0413] The bit rate of the target coded video matches the bit rate of the reference coded video, which may mean that the bit rate of the target coded video is the same as or close to the bit rate of the reference coded video.
[0414] It should be noted that Fig.19 The specific implementation details of steps S210 to S230 shown in FIG. Figure 2 Steps S210 to S230 shown are not repeated here.
[0415] exist Fig.19 In the illustrated embodiment, the interest enhancement map corresponding to the source video is encoded through target encoding parameters, so that the bit rate of the obtained target encoded video can match the bit rate of the reference encoded video obtained by directly encoding the source video, thereby improving the visual effect of the target encoded video without additionally increasing the bit rate.
[0416] In an exemplary embodiment, see Fig. 20 , Fig. 20 is Fig.19 The flowchart of a video encoding method proposed based on the figure, step S1910 may include steps S2010 to S2040, which are described in detail as follows:
[0417] Step S2010, encoding the multiple sample videos respectively according to the set encoding parameters to obtain a reference encoded video of each sample video, and obtaining interest enhancement maps corresponding to multiple sample video frames contained in each sample video.
[0418] The set encoding parameter is a pre-set encoding parameter, and its type can be any parameter that can control the bit rate, such as crf.
[0419] In order to obtain the target encoding parameters, multiple videos may be first obtained as samples, that is, multiple sample videos may be obtained, and then each sample video may be encoded based on the set encoding parameters, and the obtained encoded video may be used as a reference encoded video of the sample video.
[0420] Each sample video contains multiple sample video frames, and for each sample video frame, the corresponding interest enhancement map is obtained. The method of obtaining the interest enhancement map corresponding to the sample video frame is the same as the method of obtaining the interest enhancement map corresponding to the video frame of the source video in the aforementioned embodiment, that is, performing interest region detection on each sample video frame to obtain the interest region information of the sample video frame, and performing image enhancement on the interest region of the sample video frame according to the interest region information to obtain the interest enhancement map corresponding to the sample video frame.
[0421] Step S2020, encode the interest enhancement maps corresponding to the multiple sample video frames respectively according to the candidate encoding parameters to obtain the candidate encoded video of each sample video, and calculate the total bit rate difference corresponding to the multiple sample videos according to the bit rate difference between the candidate encoded video of each sample video and the reference encoded video.
[0422] The candidate coding parameter refers to a coding parameter that needs to be adjusted to obtain a target coding parameter, and its initial value may be 0, or may be a set coding parameter.
[0423] According to the candidate encoding parameters, the multi-frame interest enhancement map corresponding to each sample video is encoded to obtain the candidate encoded video corresponding to the sample video; the bit rate difference between the bit rate of the candidate encoded video of each sample video and the bit rate of the reference encoded video is calculated to obtain the bit rate difference corresponding to each sample video, and the bit rate differences corresponding to multiple sample videos are summed to obtain the total bit rate difference.
[0424] Step S2030, updating the candidate encoding parameters according to the total bit rate difference, and encoding the interest enhancement maps corresponding to the multiple sample video frames respectively according to the updated candidate encoding parameters, until the calculated total bit rate difference meets the set stop iteration condition.
[0425] In order to reduce the total bit rate difference, the candidate encoding parameters are updated, and then the interest enhancement map corresponding to each sample video is encoded again according to the updated candidate encoding parameters to obtain the candidate encoded video corresponding to each sample video, and the total bit rate difference is recalculated according to the candidate encoded video, and the candidate encoding parameters are updated according to the recalculated total bit rate difference, and it is iterated in sequence until the calculated total bit rate difference meets the set stop iteration condition.
[0426] The conditions for stopping iteration include but are not limited to the total bit rate difference being less than a set bit rate difference threshold, the number of iterations exceeding a set number threshold, the total bit rate difference calculated the most recently being not lower than the total bit rate difference calculated the last time, etc.
[0427] In an optional example, if the type of the candidate coding parameter and the set coding parameter is crf, the candidate coding parameter can be updated by the following formula:
[0428]
[0429] Where m is the number of sample videos, I i represents the multiple sample video frames contained in the i-th sample video, P i represents the multi-frame interest-enhanced sample video frame corresponding to the i-th sample video, crf s represents the set crf, crf′ represents the candidate crf, r compress (x,y) represents the bit rate of the video obtained after transcoding x using y as the crf value, and the crf′ is updated to minimize
[0430] Step S2040: taking the candidate coding parameter corresponding to the total bit rate difference that meets the set iteration stop condition as the target coding parameter.
[0431] The candidate encoding parameters corresponding to the total bit rate difference that meets the set stop iteration condition are used as target encoding parameters, and the multi-frame interest enhancement maps corresponding to the source video are encoded according to the target encoding parameters, so that the bit rate of the encoded target encoded video can match the bit rate of the reference encoded video of the source video.
[0432] In an optional implementation, it is also possible to first determine whether the total bit rate difference that meets the set iteration stop condition is the minimum value among multiple total bit rate differences calculated during the iterative loop. If so, the candidate coding parameters corresponding to the total bit rate difference that meets the set iteration stop condition are used as the target coding parameters. If not, the candidate coding parameters corresponding to the minimum value are used as the target coding parameters.
[0433] After obtaining the target encoding parameters, the target encoding parameters can be stored. When the source video needs to be encoded later, the pre-stored target encoding parameters can be directly obtained without calculating the target encoding parameters each time, thereby improving encoding efficiency.
[0434] It should be noted that Fig. 20 The specific implementation details of steps S210 to S230 shown in FIG. Figure 2 Steps S210 to S230 are shown. Fig. 20The specific implementation details of step S1920 shown in FIG. Fig.19 Step S1920 shown is not repeated here.
[0435] exist Fig. 20 In the illustrated embodiment, the target coding parameters are calculated through the sample video, and then the interest enhancement graph corresponding to the source video is encoded based on the target coding parameters, which not only enables the bit rate of the target encoded video to match the bit rate of the reference encoded video of the source video, but also improves the encoding efficiency.
[0436] In order to better understand the present invention, the application of video encoding in video transcoding is used as an example for explanation. Fig.21 As shown, Fig.21 This is a flowchart of a video encoding method provided in this embodiment. The method includes steps S2101 to S2107, which are described in detail as follows:
[0437] Step S2101, obtaining a detection model and a clarity enhancement model.
[0438] Among them, an artificial intelligence model corresponding to the clarity enhancement model can be constructed, and a training set corresponding to the model can be obtained. The artificial intelligence model is trained according to the training set to obtain the clarity enhancement model. An artificial intelligence model corresponding to the detection model is constructed, and a training set corresponding to the model is obtained. The artificial intelligence model is trained according to the training set using a batch training method, and the detection model is obtained after the training is completed.
[0439] Step S2102, obtaining a source video to be encoded, and decoding the source video to obtain multiple video frames.
[0440] Step S2103: Detect the region of interest mask of the video frame by using the detection model, and soften the region of interest mask to obtain a softened region of interest mask.
[0441] The video frame is used as an input image of the detection model, and a predicted region of interest mask output by the detection model is obtained, and the predicted region of interest mask is used as the region of interest mask of the video frame.
[0442] Step S2104, performing clarity enhancement on the video frame using a clarity enhancement model to obtain a first enhancement map, and calculating an enhancement coefficient according to the softened region of interest mask of the video frame.
[0443] The process of obtaining the first enhancement map may refer to the aforementioned step S710, and the specific process of calculating the enhancement coefficient may refer to the aforementioned steps S410 to S420.
[0444] Step S2105: fuse the first enhanced image and the video frame according to the enhancement coefficient to obtain a second enhanced image.
[0445] The specific calculation process of the second enhancement map may refer to the aforementioned steps S710 to S720.
[0446] Step S2106, obtaining a reference image of the video frame, and fusing the reference image and the second enhanced image according to the softened region of interest mask to obtain an enhanced image of interest.
[0447] The process of obtaining the interest enhancement graph may refer to the aforementioned steps S820 to S830.
[0448] Step S2107, encode the interest enhancement map corresponding to the source video to obtain a target encoded video.
[0449] Among them, the interest enhancement map can be encoded according to the target encoding parameters so that the bit rate of the target encoded video matches the bit rate of the reference encoded video of the source video. The specific process can be found in the aforementioned steps S1910 to S1920.
[0450] Fig.21 In the embodiment shown, compared with directly encoding the video frame, by performing image enhancement on the region of interest of the video frame and then encoding it, the visual effect of the encoded video frame can be improved without additionally increasing the bit rate. For example, see Figure 22A-22E As shown, Figure 22A-22E They are different types of video frames, respectively. The first picture in each attached figure is obtained by directly encoding the video frame, and the second picture is obtained by encoding the region of interest of the video frame after image enhancement. Compared with the first picture, the clarity and resolution of the region of interest in the second picture are significantly improved, and the visual effect is better.
[0451] See also Fig.23 , Fig.23 FIG. 1 is a block diagram of a video encoding device shown in an exemplary embodiment of the present application. Fig.23 As shown, the device includes: an acquisition module 2301, configured to implement the aforementioned step S210 and the specific process of step S210; a detection module 2302, configured to implement the aforementioned step S220 and the specific process of step S220; an enhancement module 2303, configured to implement the aforementioned step S230 and the specific process of step S230; and a coding module 2304, configured to implement the aforementioned step S240 and the specific process of step S240.
[0452] In an exemplary embodiment, the apparatus may further include an updating module configured to implement updates of the detection model and the clarity enhancement model, for example, executing steps S1310-S1330, steps S1410-S1440, steps S1510-S1540, steps S1810-S1840, etc.
[0453] It should be noted that Fig.23 The provided video encoding device and the video encoding method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here.
[0454] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more computer programs, when the one or more computer programs are executed by one or more processors, the electronic device implements the video encoding method provided in the above-mentioned embodiments.
[0455] Fig.24 A schematic diagram showing the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. The electronic device may be Figure 1 The terminal device 110 or the server 120 is shown.
[0456] It should be noted that Fig.24 The computer system 2400 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0457] like Fig.24 As shown, the computer system 2400 includes a central processing unit (CPU) 2401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 2402 or a computer program loaded from a storage part 2408 to a random access memory (RAM) 2403, such as executing the video encoding method in the above-mentioned embodiment. Various computer programs and data required for system operation are also stored in RAM 2403. CPU 2401, ROM 2402 and RAM 2403 are connected to each other via a bus 2404. An input / output (I / O) interface 2405 is also connected to the bus 2404.
[0458] In some embodiments, the following components are connected to the I / O interface 2405: an input section 2406 including a keyboard, a mouse, etc.; an output section 2407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 2408 including a hard disk, etc.; and a communication section 2409 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 2409 performs communication processing via a network such as the Internet. A drive 2410 is also connected to the I / O interface 2405 as needed. A removable medium 2411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 2410 as needed so that a computer program read therefrom is installed into the storage section 2408 as needed.
[0459] In particular, according to an embodiment of the present application, a computer program for implementing the video encoding method may be carried on a computer-readable medium, and the computer program may be downloaded and installed from a network through the communication part 2409 , and / or installed from a removable medium 2411 .
[0460] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a computer program, which may be used by an instruction execution system, device or device or used in combination with it. The computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried, and the propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer program contained in the computer-readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, etc., or any suitable combination of the foregoing.
[0461] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of the boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and a computer program.
[0462] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0463] Another aspect of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor of an electronic device, the electronic device implements the above-mentioned video encoding method. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0464] Another aspect of the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the video encoding method provided in each of the above embodiments is implemented. The computer program can be stored in a computer-readable storage medium. The computer program product can be a computer program as a product, for example, an APP (Application, mobile application software), a web page, a small program, etc.; or, the computer program product can also be a storage medium, a device, a terminal, a virtual machine, etc. containing a computer program.
[0465] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A video encoding method, characterized in that: The method comprises: Obtain multiple video frames contained in the source video to be encoded; Performing region of interest detection on each video frame to obtain region of interest information of each video frame; According to the region of interest information of each video frame, image enhancement is performed on the region of interest of each video frame to obtain an interest enhancement map corresponding to each video frame; The interest enhancement maps corresponding to the multiple video frames are encoded to obtain a target encoded video of the source video.
2. The method according to claim 1, characterized in that The step of performing image enhancement on the region of interest of each video frame according to the region of interest information of each video frame to obtain an interest enhancement map corresponding to each video frame includes: Calculating the texture complexity corresponding to the region of interest of each video frame according to the region of interest information of each video frame; Calculating an enhancement coefficient of the region of interest according to the texture complexity corresponding to the region of interest; wherein the enhancement coefficient is negatively correlated with the texture complexity; According to the enhancement coefficient, image enhancement is performed on the region of interest of each video frame to obtain an interest enhancement map corresponding to each video frame.
3. The method according to claim 2, characterized in that The calculating, according to the information of the region of interest of each video frame, the texture complexity corresponding to the region of interest of each video frame comprises: Searching for a reference area corresponding to each pixel in each video frame; wherein the distance between the pixel included in the reference area and each pixel is less than a set distance threshold; Calculating the discrete degree between the pixel values of the pixel points included in the reference area, and calculating the texture complexity of each pixel point according to the discrete degree; the texture complexity of each pixel point is positively correlated with the discrete degree; The texture complexity of the region of interest is calculated according to the texture complexity corresponding to the pixel points included in the region of interest.
4. The method according to claim 2, characterized in that The step of performing image enhancement on the region of interest of each video frame according to the enhancement coefficient to obtain an interest enhancement map corresponding to each video frame includes: Performing image enhancement on each video frame to obtain a first enhanced image corresponding to each video frame; According to the enhancement coefficient, each video frame is fused with the first enhancement image to obtain a second enhancement image; According to the interest region information of each video frame, the interest region of the second enhancement image is merged with the non-interest region of each video frame to obtain the interest enhancement image corresponding to each video frame.
5. The method according to claim 4, characterized in that The region of interest information includes a region of interest mask; The step of merging the region of interest of the second enhancement map with the non-region of interest of each video frame according to the region of interest information of each video frame to obtain the interest enhancement map corresponding to each video frame includes: Softening the edge of the region of interest of the region of interest mask to obtain a softened region of interest mask, and calculating the non-region of interest mask of each video frame according to the softened region of interest mask; The softened region of interest mask is fused with the second enhancement image to obtain a first fused enhancement image, and the non-region of interest mask is fused with each video frame to obtain a second fused enhancement image; The first fusion enhancement map and the second fusion enhancement map are merged to obtain the interest enhancement map corresponding to each video frame.
6. The method according to claim 1, characterized in that The region of interest information includes a region of interest mask; The detecting of the region of interest for each video frame to obtain the region of interest information for each video frame includes: Detecting the edge corresponding to the region of interest of each video frame to obtain an edge mask of each video frame; Performing region of interest detection on each video frame according to the edge mask to obtain a region of interest mask for each video frame.
7. The method according to claim 6, characterized in that The detecting the region of interest of each video frame according to the edge mask to obtain the region of interest mask of each video frame includes: Obtaining a focus probability map corresponding to each video frame; According to the focus probability map and the edge mask, a region of interest detection is performed on each video frame to obtain a region of interest mask of each video frame.
8. The method according to claim 7, characterized in that The step of performing region of interest detection on each video frame according to the focus probability map and the edge mask to obtain a region of interest mask for each video frame includes: Extracting shallow features of each video frame to obtain a shallow feature map of each video frame, and fusing the focus probability map with the shallow feature map to obtain a focus attention feature of each video frame; fusing the edge mask, the focus attention feature and the shallow feature map to obtain an enhanced shallow feature map; A deep feature map is extracted from the enhanced shallow feature map, and the deep feature map is detected to obtain a region of interest mask for each video frame.
9. The method according to claim 6, characterized in that The edge mask and the region of interest mask of each video frame are obtained by detecting each video frame through a detection model; the method further includes: Acquire a target edge mask and a target region of interest mask corresponding to a sample image, and detect the sample image using the detection model to obtain a predicted edge mask and a predicted region of interest mask of the sample image; Calculating a model loss according to a difference between the target edge mask and the predicted edge mask to obtain an edge loss value, and calculating a model loss according to a difference between the target region of interest mask and the predicted region of interest mask to obtain a region loss value; A total model loss value is calculated according to the edge loss value and the region loss value, and the detection model is updated according to the total model loss value.
10. The method according to claim 1, characterized in that The region of interest information includes a region of interest mask obtained by detecting each video frame through a detection model; the method further includes: Obtain a target region of interest mask corresponding to the sample image, and obtain weights corresponding to a plurality of pixel points included in the target region of interest mask; wherein the weight of each pixel point is negatively correlated with the distance of each pixel point relative to the edge of the region of interest of the target region of interest mask; Detecting the sample image by using the detection model to obtain a predicted region of interest mask of the sample image, and determining a predicted pixel point corresponding to each pixel point from the predicted region of interest mask; According to the difference between each pixel and the predicted pixel, a pixel loss value corresponding to each pixel is calculated, and according to the obtained weight, the pixel loss values corresponding to the multiple pixels are weighted summed to obtain a regional loss value; The detection model is updated according to the area loss value.
11. The method according to claim 10, characterized in that The step of obtaining weights corresponding to a plurality of pixel points included in the target region of interest mask includes: According to different filtering parameters, mean filtering is performed on the target region of interest mask respectively to obtain multiple filtering region masks; Calculating a difference map between each filter region mask and the target region of interest mask, and fusing the difference maps respectively corresponding to the plurality of filter region masks to obtain a fused region difference map; According to the fused region difference map, a weight map corresponding to the target region of interest mask is obtained; wherein the weight map contains the weight of each pixel in the target region of interest mask.
12. The method according to claim 1, characterized in that The region of interest information includes a region of interest mask; The detecting of the region of interest for each video frame to obtain the region of interest information for each video frame includes: Performing feature extraction on the shallow feature map corresponding to each video frame to obtain a deep feature map; According to the deep feature map, multiple candidate region of interest masks corresponding to each video frame are calculated, and the multiple candidate region of interest masks are fused to obtain the region of interest mask of each video frame.
13. The method according to claim 12, characterized in that The region of interest mask is obtained by detecting each video frame through a detection model; the method further comprises: Acquire a sample image and a target region of interest mask corresponding to the sample image; Performing region of interest detection on the sample image by using the detection model to obtain a plurality of candidate region of interest masks corresponding to the sample image, and fusing the plurality of candidate region of interest masks corresponding to the sample image to obtain a predicted region of interest mask corresponding to the sample image; Calculating the model loss according to the differences between the multiple candidate ROI masks corresponding to the sample image and the target ROI mask, and the difference between the predicted ROI mask and the target ROI mask, to obtain a regional loss value; The detection model is updated according to the area loss value.
14. The method according to claim 1, wherein: The step of encoding the interest enhancement graphs respectively corresponding to the plurality of video frames to obtain a target encoded video of the source video includes: Obtain target encoding parameters corresponding to the source video; The interest enhancement maps corresponding to the multiple video frames are encoded according to the target encoding parameters to obtain the target encoded video whose corresponding bit rate matches the bit rate of the reference encoded video; wherein the reference encoded video is obtained by encoding the source video.
15. The method according to claim 14, characterized in that The obtaining of target encoding parameters corresponding to the source video includes: Encode the multiple sample videos respectively according to the set encoding parameters to obtain a reference encoded video of each sample video, and obtain interest enhancement maps corresponding to multiple sample video frames contained in each sample video; Encoding the interest enhancement maps respectively corresponding to the multiple sample video frames according to the candidate encoding parameters to obtain a candidate encoded video of each sample video, and calculating a total bit rate difference corresponding to the multiple sample videos according to a bit rate difference between the candidate encoded video of each sample video and a reference encoded video; The candidate encoding parameters are updated according to the total bit rate difference, and the interest enhancement maps corresponding to the multiple sample video frames are encoded according to the updated candidate encoding parameters until the calculated total bit rate difference satisfies the set stop iteration condition; The candidate coding parameter corresponding to the total bit rate difference that meets the set iteration stop condition is used as the target coding parameter.
16. A video encoding device, characterized in that: The device comprises: An acquisition module, configured to acquire multiple video frames contained in a source video to be encoded; A detection module is configured to perform region of interest detection on each video frame to obtain region of interest information of each video frame; An enhancement module is configured to perform image enhancement on the region of interest of each video frame according to the region of interest information of each video frame to obtain an interest enhancement map corresponding to each video frame; The encoding module is configured to encode the interest enhancement images corresponding to the multiple video frames respectively to obtain the target encoded video of the source video.
17. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more computer programs, which, when executed by the one or more processors, enables the electronic device to implement the method described in any one of claims 1 to 15.
18. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor of an electronic device, the electronic device is enabled to implement the method according to any one of claims 1 to 15.
19. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor of an electronic device, enables the electronic device to implement the method according to any one of claims 1 to 15.
Citation Information
Cited By
Regional high-efficiency video coding method for mine low-bit-rate video transmission
CN119520794A
Airport monitoring video transmission method and device, storage medium and electronic equipment
CN119854508A
Video encoding method and apparatus, and electronic device and storage medium
WO2026103300A1
