Video cropping method, electronic device and computer-readable storage medium
Through lens segmentation and motion area analysis, combined with face tracking technology, the video clipping position is accurately located, which solves the problem of discontinuous video clipping in the existing technology and improves the playback effect and excitement of the video.
Patent Information
- Application Number
- CN202010953331.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-11
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2040-09-11
AI Technical Summary
Existing video cropping technology is difficult to accurately locate effective and continuous video highlight areas, resulting in cropped content prone to deviations or jumps.
By segmenting the video to be cropped, the video frames under each lens are obtained, the position of the motion area in the video frame under each lens is determined, the cropping position sequence is determined based on the position of the motion region, and the cropping is performed in a scene with people based on face tracking. Ensure continuity and splendor of cuts.
It improves the continuity and excitement of the video after cropping, avoids deviations or jumps in the cropped content, and enhances the video playback effect.
Smart Images

Figure CN112131984B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of Internet technology, and in particular to a video cropping method, an electronic device, and a computer-readable storage medium. Background Art
[0002] Currently, in order to extract the exciting content area of a video, target detection methods are usually used to detect video images frame by frame, and the video context is reassembled based on the detection results, for example, directly cropping the area where people or objects appear.
[0003] However, the inventors have found that there are at least the following problems in the related technology: the results of target detection cannot form an effective association between video contexts, and cannot accurately locate the effective and continuous positions of video highlights, resulting in deviations or jumps in cropped video content. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a video cropping method, an electronic device and a computer-readable storage medium, so that an effective and continuous cropping position can be accurately located, the continuity of the cropped video can be enhanced, and deviation or jump in the cropped video can be avoided.
[0005] To solve the above technical problems, an embodiment of the present invention provides a video cropping method, comprising: performing shot segmentation on a video to be cropped, and obtaining each video frame under each shot; determining the position of a motion area in each video frame under each of the shots; determining a cropping position sequence corresponding to each of the shots according to the position of the motion area; wherein the cropping position sequence includes the cropping position of each video frame under each of the shots; and cropping the video to be cropped according to the cropping position sequence to obtain a cropped target video.
[0006] An embodiment of the present invention also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned video cropping method.
[0007] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, wherein the computer program implements the above-mentioned video cropping method when executed by a processor.
[0008] Compared with the prior art, the embodiments of the present invention perform lens segmentation on the video to be cropped, obtain each video frame under each lens, determine the position of the motion area in each video frame under each lens, determine the cropping position sequence corresponding to each lens according to the position of the motion area, and crop the video to be cropped according to the cropping coordinate position sequence to obtain the cropped target video. That is, one lens is used as the minimum unit for cropping, and the cropping position sequence corresponding to each lens after segmentation is determined. Since each video frame under one lens is usually relatively continuous, the embodiments of the present invention are equivalent to cropping the video with one lens as the minimum unit for cropping, that is, according to the cropping position sequence corresponding to each lens after segmentation, the video to be cropped is cropped to obtain the target video, which is beneficial to improve the continuity of the cropped target video to a certain extent. Moreover, considering that the wonderful area under a lens can usually be expressed by the motion area under the lens, the cropping coordinate sequence corresponding to each lens frame sequence determined according to the position of the motion area of each video frame under each lens can better reflect the position of the wonderful area under each lens, and the change of the motion area can correspond to the change of the cropping position sequence, that is, the cropping position sequence corresponding to a lens changes with the change of the position of the motion area in the lens, which is conducive to accurately locating the effective and continuous cropping position of the wonderful area, enhancing the continuity of the cropped target video, and avoiding deviation or jump in the cropped target video.
[0009] In addition, the method of determining the cropping coordinate sequence corresponding to each of the lenses according to the position of the motion region includes: if it is determined that there is an unmanned lens in each of the lenses, determining the cropping coordinate sequence corresponding to the unmanned lens according to the position of the motion region in each video frame under the unmanned lens; if it is determined that there is a human lens in each of the lenses, tracking the face in each video frame under the human lens to obtain the face identity, and determining the cropping coordinate sequence corresponding to the human lens according to the face identity and the position of the motion region in each video frame under the human lens. In other words, two different methods are used for cropping for human scenes and human scenes respectively. For human scenes, the cropping position sequence corresponding to the unmanned lens is determined by the position of the motion region in each video frame. For human scenes, the cropping position sequence corresponding to the unmanned lens is determined by combining the motion region and the tracked face identity. This is conducive to targeted video cropping in different lens scenes, accurately locating the cropping position of effective and continuous wonderful areas, and further enhancing the continuity of the cropped target video.
[0010] In addition, the determination of the position of the motion region in each video frame under each of the lenses includes: determining multiple motion regions in each video frame under each of the lenses according to the comparison relationship between two adjacent video frames under each of the lenses; clustering the multiple motion regions in each of the video frames to obtain a cluster center for characterizing the motion region; wherein one cluster center is used to characterize one motion region; and determining the position of the motion region in each of the video frames under each of the lenses according to the position of the cluster center. Clustering the multiple motion regions in each video frame is conducive to accurately characterizing the motion region in the video frame through the obtained cluster center, thereby facilitating the determination of the position of the motion region in each of the video frames under each of the lenses.
[0011] In addition, when determining the position of each moving area in the first frame under the unmanned lens as the initial cropping position, the reference cropping position sequence corresponding to the unmanned lens includes: taking the position of each moving area in the first frame under the unmanned lens as the initial cropping position in turn; when the position of each moving area is taken as the initial cropping position, traversing the second frame to the end frame under the unmanned lens in turn, and performing the following steps on the traversed video frames: selecting a target moving area from each moving area of the traversed video frame, and taking the position of the target moving area as the cropping position of the traversed video frame; wherein the position of the target moving area is closest to the cropping position of the previous frame of the traversed video frame; after traversing the end frame, determining the reference cropping position sequence corresponding to the unmanned lens according to the initial cropping position and the cropping position of the traversed video frame. That is to say, for unmanned scenes, the implementation mode of the present invention determines the cropping position sequence corresponding to the unmanned shot through the relative positions between the motion areas in each video frame, and since the position of the target motion area is closest to the cropping position of the previous frame of the traversed video frame, it is beneficial to ensure the continuity of the cropping positions of the two adjacent video frames, thereby helping to improve the continuity of cropping under the unmanned shot.
[0012] In addition, the facial identity is a plurality of facial identities, and the determining of the cropping coordinate sequence corresponding to the lens with people based on the facial identity and the position of the motion region in each video frame under the lens with people includes: determining the plurality of facial regions where the plurality of facial identities are located; determining the cropping positions corresponding to the plurality of facial identities in each video frame under the lens with people based on the positions of the plurality of facial regions; determining the cropping position sequence corresponding to the lens with people based on the cropping positions corresponding to the plurality of facial identities in each video frame under the lens with people and the position of the motion region in each video frame under the lens with people. That is to say, for scenes with people, the cropping positions corresponding to the plurality of facial identities are determined in combination with the position of the motion region in the first type of video frame and the position of the plurality of facial regions, that is, when there are multiple people under the lens with people, the cropping coordinate sequence corresponding to the lens with people is determined in combination with the plurality of facial regions and the motion region, which is conducive to improving the continuity between the previous and next frames cropped under the lens with people.
[0013] In addition, the face tracking of each video frame captured by the human lens to obtain the face identity includes: obtaining the face image in each video frame captured by the human lens; determining the similarity between the face image and several standard face images in a preset face database; wherein the face database stores standard face images belonging to different face identities, and the number of standard face images belonging to the same face identity is multiple; selecting M standard face images whose similarity to the face image is greater than a preset similarity; wherein M is a natural number greater than 1; grouping the M standard face images according to the face identities to which the M standard face images belong and determining the number of standard face images in each group; wherein the standard face images in the same group belong to the same face identity; obtaining the face identity according to the number of standard face images in each group. Since there are multiple standard face images belonging to the same face identity stored in the face database, when matching the face image with several standard face images in the preset face database, N standard face images with a similarity greater than a preset similarity to the face image can be selected, and then the N standard face images belonging to the same face identity are grouped together, and the face identity corresponding to each face region is determined according to the number of standard face images in each group. The number of standard face images in each group can reflect the number of different face identities in the N standard face images, and to a certain extent can reflect which face identity the face image in the face region is most likely to belong to, which is conducive to improving the accuracy of face recognition.
[0014] In addition, the wonderfulness scoring of the cropping positions corresponding to the multiple facial identities to obtain the wonderfulness scores of the cropping positions corresponding to the multiple facial identities includes: determining the motion proportion score of the facial area where each facial identity is located according to the cropping positions corresponding to the multiple facial identities in each video frame under the human lens and the positions of the motion areas in each video frame under the human lens; wherein the motion proportion score is used to characterize the proportion of the number of motion areas associated with the facial area where each facial identity is located to the total number of motion areas; determining a distance score used to characterize the proximity between the facial area corresponding to each facial identity and the motion area; determining a confidence score used to characterize the recognition accuracy of each facial identity; and obtaining the wonderfulness scores of the cropping positions corresponding to the multiple facial identities according to the motion proportion score, the distance score and the confidence score. That is to say, in the case where there are multiple facial identities in a shot with people, that is, in a multi-person scene, the wonderfulness of the cropping position corresponding to each facial identity can be scored from multiple scoring dimensions, so that the cropping coordinate sequence corresponding to the shot with people can be determined according to the wonderfulness score, which is conducive to improving the continuity of the target video after cropping while improving the wonderfulness of the target video. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] One or more embodiments are exemplarily described by the pictures in the corresponding drawings, and these exemplary descriptions do not constitute limitations on the embodiments.
[0016] Figure 1 is a flowchart of a video cropping method according to a first embodiment of the present invention;
[0017] Figure 2 is a schematic diagram of an image of a motion region in a video frame according to a first embodiment of the present invention;
[0018] Figure 3 is an effect diagram of the video frame before and after sharpening according to the first embodiment of the present invention;
[0019] Figure 4 is an effect diagram before and after clustering in a video frame according to the first embodiment of the present invention;
[0020] Figure 5 is a flowchart of determining a clipping coordinate sequence corresponding to an unmanned shot according to a second embodiment of the present invention;
[0021] Figure 6 is a flowchart of determining a clipping coordinate sequence corresponding to a shot with people in it according to a second embodiment of the present invention;
[0022] Figure 7is a flowchart of an implementation process of determining a clipping coordinate sequence corresponding to a shot with people in it according to a second embodiment of the present invention;
[0023] Figure 8 is a flowchart of an implementation process of determining a clipping coordinate sequence corresponding to a shot with people in it according to a third embodiment of the present invention;
[0024] Fig. 9 is a schematic diagram of an implementation process of a video cropping method according to a third embodiment of the present invention;
[0025] Fig.10 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention. DETAILED DESCRIPTION
[0026] To make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented. The division of the following embodiments is for the convenience of description, and should not constitute any limitation on the specific implementation of the present invention. The various embodiments can be combined and referenced with each other without contradiction.
[0027] The first embodiment of the present invention relates to a video cropping method, which is applied to an electronic device; wherein the electronic device can be a server or a terminal, and the terminal can be a device that can play videos, such as a mobile phone and a tablet computer. The electronic device in this embodiment and the following embodiments takes the server as an example, but in the specific implementation, it is not limited to this. The application scenarios of this embodiment may include but are not limited to: extracting the wonderful area in the video, that is, cropping to obtain the wonderful content area in the video to be cropped. The implementation details of the video cropping method of this embodiment are described in detail below. The following content is only the implementation details provided for the convenience of understanding, and is not necessary for the implementation of this solution.
[0028] The flowchart of the video cropping method in this embodiment can be as follows Figure 1 As shown, including:
[0029] Step 101: Segment the video to be cropped into shots and obtain each video frame under each shot.
[0030] The video to be cropped is the video that needs to be cropped.
[0031] In one example, the video to be cropped may be a video resource on a personal computer (PC for short). The video resource on the PC is usually played in horizontal mode, while the mobile terminal, such as a mobile phone, usually plays in vertical mode by default. Considering that, in the prior art, the difference in screen aspect ratio between the PC and the mobile terminal may result in poor playback effect of the video resource on the PC terminal on the mobile terminal, the video cropping method in this embodiment can make the cropped video adapt to the screen size of the mobile terminal, while enhancing the continuity of the cropped video, and improving the playback effect of the video resource on the PC terminal on the mobile terminal. In another example, the video to be cropped may also be a video resource on the mobile terminal.
[0032] It is understandable that the scene in one shot of the video to be cropped is usually continuously changing. The server can determine the specific position of the shot switching in the video to be cropped by detecting the picture changes in the video to be cropped, thereby performing shot segmentation on the video to be cropped and obtaining each video frame under each shot after the shot segmentation. In each subsequent step, each video frame under one shot can be processed as the smallest video unit. For example, video cropping is performed based on each shot after segmentation, and finally the video clips obtained by cropping based on each shot are combined to obtain the target video after cropping the video to be cropped.
[0033] Step 102: Determine the position of the motion area in each video frame under each lens.
[0034] In one example, the server may perform image analysis on each video frame under each lens to determine the position of the motion region in each video frame. For example, the position of the motion region in each video frame may be determined based on the comparison relationship between two adjacent video frames, that is, the image change information between the two previous and next video frames.
[0035] In one example, the server can use a pre-trained deep neural network model to determine the location of the motion area in each video frame under each lens; wherein the input of the deep neural network model is each video frame under each lens, which can be understood as a series of pictures under one lens, and the output of the deep neural network model is an image of the motion area in each video frame detected under each lens. For example, the output image of the motion area in a video frame can be as follows: Figure 2 As shown in the figure, the brightness of different motion areas represents the motion state of different motion areas. The greater the brightness, the higher the motion intensity. In the specific implementation, for each video frame, a similar Figure 2 The motion region diagram shown in FIG. 1 is used to indicate the position of the motion region in each video frame. In addition, in order to conveniently and reasonably represent the position of the motion region, the position of the center of the motion region can be used to represent the position of the motion region.
[0036] In one example, considering that a moving object will generate "motion radiation" to the surrounding objects, the detected motion area will be radial. Therefore, in this embodiment, in order to highlight the center of the motion area, the detection result of the motion area can be sharpened, that is, the image of the motion area in each video frame output by the deep neural network model is sharpened, and the pixel values less than the preset threshold are filtered out to retain the center position of the motion area. Among them, the preset threshold can be set according to actual needs, for example, it can be set to 127 to accurately highlight the center of the motion area. For ease of understanding, the effect diagram before and after sharpening can be referred to. Figure 3 ,in, Figure 3 The left half of the image is the image of the motion region before sharpening, and the right half is the image of the motion region after sharpening. The above sharpening process is helpful to more accurately obtain the position of the motion region in each video frame.
[0037] In one example, the position of the motion region in each video frame under each lens may be determined as follows:
[0038] First, based on the comparison relationship between two adjacent video frames under each lens, multiple motion regions in each video frame under each lens are determined. For example, the multiple motion regions determined in a video frame can be Figure 3 The three white areas shown in the right half of the diagram. Figure 3 In the example, three motion regions are detected in one video frame. In a specific implementation, the number of motion regions detected in one video frame is not limited thereto.
[0039] Next, multiple motion regions in each video frame are clustered to obtain cluster centers for characterizing the motion regions; wherein one cluster center is used to characterize one motion region. Taking into account that multiple motion regions may exist simultaneously in each video frame in the same shot, and some motion regions cover a large area, making it difficult to locate the specific coordinates of each motion region, multiple motion regions are clustered in this embodiment to obtain cluster centers for characterizing the motion regions. Specifically, clustering can be performed based on pixel index (i.e., the position coordinates of the pixel points) and pixel values (i.e., the brightness values of the pixel points), with the position of the cluster center representing the motion region with the cluster center as the center point. For ease of understanding, please refer to Figure 4 , Figure 4 Schematic diagram before and after clustering. Figure 4 The left half is the image of the motion area before clustering, which can also be understood as the image of the motion area after sharpening. Figure 4 The right half is the image of the clustered motion region. The four points in the three motion regions (white elliptical regions) in the clustered motion region image are the cluster centers. Figure 4 After clustering, 4 cluster centers are obtained.
[0040] Then, the location of the cluster center is determined, and the location of the cluster center is used as the location of the motion area represented by the cluster center. In other words, the location of the cluster center can be directly used as the location of the motion area represented by the cluster center. Figure 4 The positions of the four cluster centers in can be the x-axis coordinates of the four cluster centers respectively.
[0041] In one example, in order to obtain the best clustering result, that is, to determine the cluster center that best represents the motion region in a video frame, multiple motion regions in each video frame can be clustered to obtain cluster centers for representing the motion regions, and then the best cluster center can be selected from the obtained cluster centers as the best clustering result. The best clustering result can be selected using the following formula:
[0042]
[0043] Among them, s∈[-1,1], a i represents the average value of the distance between the ith cluster center and other pixels in the motion region i represented by the ith cluster center (i.e., the average value of the intra-class distance), b i represents the average distance between the i-th cluster center and the pixels in other motion regions except motion region i (i.e., the average distance between classes), and d is the number of cluster centers in the video frame. Then, the best clustering effect can be obtained by selecting the number of clusters that maximizes s, that is, the best cluster center that can best characterize the motion region in a video frame. Finally, the position of the best cluster center can be used as the position of the motion region in the video frame.
[0044] For example, reference Figure 4 , Figure 4 There are 4 cluster centers in the cluster, which can be recorded as point 1, point 2, point 3, and point 4. 1 represents the average value of the distance between point 1 and other pixels in the motion area 1 represented by point 1 (i.e., the average value of the intra-class distance of clustering result 1), b 1 It represents the average distance between point 1 and the pixels in motion area 2 represented by point 2, motion area 3 represented by point 3, and motion area 4 represented by point 4 (i.e., the average distance between clustering results 1 and 2, 3, and 4). Assuming that the number of clusters that maximize s includes point 1, point 2, and point 3, then the best cluster centers are point 1, point 2, and point 3, and the positions of point 1, point 2, and point 3 can be used as the positions of the three motion areas in the video frame.
[0045] Step 103: Determine the cropping position sequence corresponding to each lens according to the position of the motion area.
[0046] The cropping position sequence includes the cropping position of each video frame under each lens, and the cropping position can be specifically a cropping coordinate. The cropping position sequence can be understood as a cropping coordinate sequence. Each video frame under each lens has a corresponding cropping coordinate, and the cropping coordinates of each video frame under a lens constitute a cropping coordinate sequence corresponding to the lens. In a specific implementation, the cropping coordinates can be x-axis coordinates, and the cropping coordinate sequence corresponding to a lens can be the x-axis coordinate sequence in each video frame under the lens.
[0047] In one example, the server can determine the cropping position of each video frame according to the position of the motion area in each video frame under each lens, and determine the cropping position sequence corresponding to each lens according to the cropping position of each video frame. Among them, the method of determining the cropping position of each video frame according to the position of the motion area in each video frame under each lens can be: determining the cropping position of each video frame according to the relative position of the motion area in two adjacent video frames. For example, the cropping position of the first frame under a lens is the position of a motion area with the highest motion intensity, the cropping position of the second frame is the position of a motion area closest to the cropping position of the first frame, and so on, to obtain the cropping position of all video frames under the lens. In other words, the cropping positions of two adjacent video frames are closer, which is conducive to obtaining a more continuous cropping position sequence.
[0048] Step 104: Crop the video to be cropped according to the cropping position sequence to obtain a cropped target video.
[0049] Among them, each shot in the video to be cropped corresponds to a cropping position sequence. Each shot can be used as the minimum cropping unit to obtain the video segment after cropping each shot, and then the cropped target video is obtained by combining the video segments after cropping each shot.
[0050] In one example, the cropping position sequence is an x-axis coordinate sequence, and the x-axis coordinate sequence corresponding to a lens can be used as the cropping center to crop each video frame under the lens. For example, the width of the target video can be obtained, and the area to be cropped can be determined according to the width of the target video and the x-axis coordinate sequence; wherein the size of the determined area to be cropped is the size of the target video. Assuming that there are 3 video frames under a lens, the x-axis coordinate sequence is (15cm, 15cm, 16cm), and the width of the target video to be cropped is 20cm, then the area to be cropped in the first and second frames under the lens is the area formed by extending 10cm to both sides with x=15cm as the cropping center, and the area to be cropped in the third frame is the area formed by extending 10cm to both sides with x=16cm as the cropping center. The height of the target video is the same as the height of the video to be cropped.
[0051] In an example, the video to be cropped is a video resource on a PC. In order to adapt the cropped target video to the screen of the mobile terminal when it is played on the mobile terminal, the server can obtain the height of the video resource on the PC and the size ratio of the screen of the mobile terminal (such as 9:16), and then calculate the width of the target video based on the height of the video resource on the PC and the size ratio of the screen of the mobile terminal.
[0052] It should be noted that the above examples in this embodiment are only provided for the convenience of understanding and do not constitute a limitation on the technical solution of the present invention.
[0053] Compared with the prior art, the present embodiment performs lens segmentation on the video to be cropped, obtains each video frame under each lens, determines the position of the motion area in each video frame under each lens, determines the cropping position sequence corresponding to each lens according to the position of the motion area, and crops the video to be cropped according to the cropping coordinate position sequence to obtain the cropped target video. That is, one lens is used as the minimum unit for cropping, and the cropping position sequence corresponding to each lens after segmentation is determined. Since each video frame under one lens is usually relatively continuous, the embodiment of the present invention is equivalent to cropping the video with one lens as the minimum unit for cropping, that is, according to the cropping position sequence corresponding to each lens after segmentation, the video to be cropped is cropped to obtain the target video, which is beneficial to improve the continuity of the cropped target video to a certain extent. Moreover, considering that the wonderful area under a lens can usually be expressed by the motion area under the lens, the cropping coordinate sequence corresponding to each lens frame sequence determined according to the position of the motion area of each video frame under each lens can better reflect the position of the wonderful area under each lens, and the change of the motion area can correspond to the change of the cropping position sequence, that is, the cropping position sequence corresponding to a lens changes with the change of the position of the motion area in the lens, which is conducive to accurately locating the effective and continuous cropping position of the wonderful area, enhancing the continuity of the cropped target video, and avoiding deviation or jump in the cropped target video.
[0054] The second embodiment of the present invention relates to a video cropping method. The implementation details of the video cropping method of this embodiment are described in detail below. The following content is only provided for the convenience of understanding and is not necessary for implementing this solution.
[0055] In this embodiment, step 103 may include different implementation methods in two different scenarios, namely, a scene with people and a scene without people. Among them, a scene with people can be understood as a shot with people detected when the shot is segmented, and each video frame under the shot with people includes a video frame with people, and may also include a video frame without people. A video frame with people means that a person appears in the video frame, and a video frame without people means that no person appears in the video frame. An unmanned scene can be understood as an unmanned shot detected when the shot is segmented, and each video frame under the unmanned shot is a video frame without people.
[0056] In a specific implementation, if it is determined that there is an unmanned shot in each shot, the cropping coordinate sequence corresponding to the unmanned shot is determined according to the position of the motion area in each video frame under the unmanned shot. If it is determined that there is a human shot in each shot, the face is tracked in each video frame under the human shot to obtain the face identity, and the cropping coordinate sequence corresponding to the human shot is determined according to the face identity and the position of the motion area in each video frame under the human shot.
[0057] In one example, for an unmanned shot, the clipping coordinate sequence corresponding to the unmanned shot can be determined by: Figure 5 The substeps shown implement:
[0058] Step 201: determining the position of each motion region in the first frame of the unmanned shot as the initial cropping position, and the reference cropping position sequence corresponding to the unmanned shot.
[0059] Among them, the number of motion regions in the first frame and the number of reference cropping position sequences are both N, and N is a natural number greater than 1. That is to say, the number of reference cropping position sequences under the unmanned lens is multiple, and when the position of each motion region in the first frame under the unmanned lens is used as the initial cropping position, a set of reference cropping position sequences is obtained, and N cluster centers will correspond to N sets of reference cropping position sequences.
[0060] In a specific implementation, if the position of the motion area is represented by the position of the cluster center, the reference cropping position sequence corresponding to the unmanned shot can be determined when the position of each cluster center in the first frame of the unmanned shot is used as the initial cropping position.
[0061] In one example, the implementation process of step 201 may be as follows:
[0062] The position of each moving area in the first frame of the unmanned camera is used as the initial cropping position in turn. When the position of each moving area is used as the initial cropping position, the second frame to the end frame of the unmanned camera are traversed in turn, and the following steps are performed on the traversed video frames:
[0063] A target motion region is selected from each motion region of the traversed video frame, and the position of the target motion region is used as the cropping position of the traversed video frame; wherein the position of the target motion region is closest to the cropping position of the previous frame of the traversed video frame. After traversing the end frame, the reference cropping position sequence corresponding to the unmanned shot is determined based on the initial cropping position and the cropping position of the traversed video frame.
[0064] For example, the position of the motion area is characterized by the position of the cluster center, and the cluster center 1 in the first frame of the unmanned lens can be used as the initial cropping position. When determining the cropping position of the second frame, a cluster center closest to the cropping position of the first frame (i.e., cluster center 1) is selected from the cluster centers in the second frame as the target cluster center, and the position of the target cluster center is used as the cropping position of the second frame. Similarly, the cropping positions of subsequent video frames under the unmanned lens are determined until the cropping position of the end frame, i.e., the last frame, under the unmanned lens is determined. The obtained cropping positions of the various video frames under the unmanned lens are combined to obtain a reference cropping position sequence corresponding to the unmanned lens when cluster center 1 is used as the initial cropping position. Then, referring to the above method, other reference cropping position sequences corresponding to the unmanned lens can be obtained when other cluster centers in the first frame are used as the initial cropping position.
[0065] Step 202: Select one reference cropping position sequence from the N reference cropping position sequences as a cropping coordinate sequence corresponding to the unmanned shot.
[0066] In one example, a reference cropping position sequence may be arbitrarily selected from the N reference cropping position sequences as the cropping coordinate sequence corresponding to the unmanned shot.
[0067] In another example, the variance of each reference cropping position sequence can be calculated based on N reference cropping position sequences, and the reference cropping position sequence with the smallest variance can be selected as the cropping position sequence corresponding to the unmanned shot. This is helpful in improving the continuity of the cropping position sequence corresponding to the unmanned shot that is finally determined, thereby improving the continuity of the video under the unmanned shot that is finally cropped.
[0068] In an example, the reference clipping position sequence may be a reference x-axis coordinate sequence, and the reference clipping position sequence with the smallest variance may be selected by referring to the following formula:
[0069] Among them, e is the number of video frames under the unmanned camera, x i is the x-axis coordinate of the ith video frame, and the reference cropping position sequence that makes f take the minimum value is the cropping coordinate sequence corresponding to the unmanned shot finally determined.
[0070] In one example, for a shot with people, face tracking is performed on each video frame under the shot with people, and the obtained face identities are multiple face identities. When determining the cropping coordinate sequence corresponding to the shot with people, multiple face regions where the multiple face identities are located can be determined; then, based on the positions of the multiple face regions, the cropping positions corresponding to the multiple face identities in each video frame under the shot with people are determined; then, based on the cropping positions corresponding to the multiple face identities in each video frame under the shot with people and the positions of the motion regions in each video frame under the shot with people, the cropping position sequence corresponding to the shot with people is determined. Among them, face tracking can be understood as: the operation performed to determine the face identity in each video frame under the shot with people.
[0071] In one example, for a shot with people, the clipping coordinate sequence corresponding to the shot with people can be determined by: Figure 6 The substeps shown implement:
[0072] Step 301: perform face detection on each video frame captured by a human lens, and determine the position of the face area in the video frame where the face is detected.
[0073] In one example, the server can use a face detection algorithm to perform face detection on each video frame captured by a human lens. The face detection algorithm can detect information such as the face area in the video frame, the coordinates of the bounding box of the face area, and the coordinates of the positions of the facial features. The bounding box can be saved using a quaternary group (x, y, w, h), where x and y represent the coordinate position of the face area relative to the upper left corner of the image, and w and h represent the width and height of the face area. In a specific implementation, the position of the face area can be represented by the above quaternary group.
[0074] It is understandable that among the video frames captured by human lenses, there may also be video frames in which no face is detected. Therefore, the video frames in which the face is detected can be called the first category of video frames, and the video frames in which the face is not detected can be called the second category of video frames.
[0075] Step 302: If multiple face regions are detected, face recognition is performed on the multiple face regions to obtain multiple face identities corresponding to the multiple face regions.
[0076] That is to say, if there are multiple faces in the first type of video frames, face recognition can be performed on the multiple faces respectively to obtain the facial identities corresponding to the multiple faces.
[0077] In one example, the process of face recognition may be as follows: obtain a face image in a face region, convert the face image into a feature vector of fixed length (e.g., a 512-dimensional vector), calculate the Euclidean distance between the feature vector (first feature vector) after the face image is converted and the feature vector (second feature vector) of a standard face image belonging to different face identities stored in a preset face database, and determine the face identity of the face image in the face region according to the Euclidean distance. The calculation formula of the Euclidean distance may be as follows:
[0078]
[0079] Among them, t i and t j Represent two 512-dimensional feature vectors, t i is the first eigenvector mentioned above, t j is the second eigenvector mentioned above, dist∈[0,+∞] represents the Euclidean distance between the two eigenvectors. If dist is less than the preset face recognition threshold, then t i and t j If the face identities are the same, face recognition is successful; otherwise, face recognition fails. The preset face recognition threshold can be set according to actual needs, and this embodiment does not make specific limitations on this.
[0080] In another example, the process of face recognition can be as follows:
[0081] First, obtain the face image in each video frame in which the face is detected by the camera, and determine the similarity between the face image and several standard face images in a preset face database; wherein the face database stores standard face images belonging to different face identities, and the number of standard face images belonging to the same face identity is multiple. The multiple standard face images belonging to the same face identity can be standard face images at different angles, so as to more comprehensively describe the characteristics of the same face identity from multiple angles.
[0082] Then, M standard face images whose similarity with the face image in the face area is greater than a preset similarity are selected; wherein the similarity between two images can be determined by the Euclidean distance between the feature vectors of the two images, the larger the Euclidean distance, the smaller the similarity, and the smaller the Euclidean distance, the smaller the similarity. The preset similarity can be set according to actual needs. In a specific implementation, the first M standard face images with the greatest similarity with the face image in the face area can be selected from the face database.
[0083] Next, according to the facial identities to which the M standard facial images belong, the M standard facial images are grouped and the number of standard facial images in each group is determined; wherein the facial identities to which the standard facial images in the same group belong are the same. In one example, M is 7, and the facial identities to which the 7 standard facial images belong are shown in Table 1:
[0084] Table 1
[0085] Standard face image The face identity to which the standard face image belongs Standard face image 1 Identity A Standard face image 2 Identity A Standard face image 3 Identity A Standard face image 4 Identity B Standard face image 5 Identity B Standard face image 6 Identity C Standard face image 7 Identity C
[0086] As can be seen from Table 1, the 7 standard face images can be divided into 3 groups, among which standard face images 1, 2, and 3 can be divided into one group, referred to as identity group A; standard face images 4 and 5 can be divided into one group, referred to as identity group B; standard face images 6 and 7 can be divided into one group, referred to as identity group C. There are 3 standard face images in identity group A, and the number of standard face images in identity group B and identity group C is 2 each.
[0087] Finally, the face identity corresponding to each face region is determined according to the number of standard face images in each group.
[0088] In one example, if the number of standard face images in each group is not exactly the same, the server can select the group with the largest number, and use the face identity to which the standard face images in the group with the largest number belong as the face identity corresponding to the face region. Referring to Table 1 above, it can be seen that among the three groups, the identity A group has the largest number of standard face images, so it can be determined that the face identity corresponding to the face region is identity A. Considering that the face identity corresponding to the group with the largest number of standard face images is most likely the face identity corresponding to the face region, therefore, if the group with the largest number of standard face images can be selected, the face identity to which the standard face images in the group with the largest number belong is used as the identified face identity, which is conducive to further improving the accuracy of face recognition.
[0089] In another example, if the number of standard face images in each group is the same, the server can determine the average value of the similarity between the standard face images in each group and the face images in the face region, and use the face identity of the standard face images in the group with the largest average value as the face identity corresponding to the face region. Alternatively, the server can determine the average value of the Euclidean distance between the feature vectors of the standard face images in each group and the feature vectors of the face images in the face region, that is, each group corresponds to the average value of the Euclidean distance, and then the face identity of the standard face images in the group with the smallest average value of the Euclidean distance can be used as the face identity corresponding to the face region. Considering that if the number of standard face images in each group is the same, determining the average value of the similarity between the standard face images in each group and the face images in the face region, and using the face identity of the standard face images in the group with the largest average value as the face identity corresponding to the face region, is conducive to improving the accuracy of face recognition while further improving the rationality of face recognition.
[0090] It can be understood that the embodiments of the present invention start from the above two situations and adopt different methods to determine the facial identity corresponding to the facial image for the two situations, which is conducive to adapting to different situations arising in practical applications, while improving the accuracy of the facial identity obtained, and ensuring the rationality of the obtained facial identity.
[0091] Step 303: Determine the corresponding cropping positions of the multiple face identities in each frame under the human lens according to the positions of the multiple face regions.
[0092] In a specific implementation, the cropping positions corresponding to the multiple face identities in the above-mentioned first type of video frames may be determined according to the positions of the multiple face regions.
[0093] In one example, the positions of multiple face regions can be directly used as the cropping positions corresponding to the multiple face identities in the first type of video frame. For example, if face identity 1 is identified in face region 1, then the cropping position corresponding to face identity 1 in the first type of video frame is the position of face region 1. Similarly, if face identity 2 is identified in face region 2, then the cropping position corresponding to face identity 2 in the first type of video frame is the position of face region 2.
[0094] Step 304: Determine a cropping position sequence corresponding to the human shot according to the cropping positions corresponding to the multiple face identities in each video frame under the human shot and the position of the motion area in each video frame under the human shot.
[0095] In one example, the cropping positions corresponding to the multiple facial identities can be scored for their wonderfulness based on the cropping positions corresponding to the multiple facial identities in each video frame under the human lens and the positions of the motion areas in each video frame under the human lens, thereby obtaining wonderfulness scores for the cropping positions corresponding to the multiple facial identities; then, the cropping position sequence corresponding to the human lens is determined based on the wonderfulness scores.
[0096] In one example, this can be done by Figure 7 The sub-steps shown determine the cropping coordinate sequence corresponding to the human shot:
[0097] Step 401: Determine the motion proportion score of the face area where each face identity is located according to the corresponding cropping positions of multiple face identities in each video frame under the human lens and the position of the motion area in each video frame under the human lens.
[0098] The motion ratio score is used to represent the ratio of the number of motion regions associated with the face region corresponding to each face identity to the total number of motion regions. It can also be understood that the motion ratio score is used to represent the ratio of the number of motion regions in the first type of video frame associated with the face region corresponding to each face identity to the total number of motion regions in the first type of video frame. In an example, the motion ratio score can be calculated by the following formula:
[0099]
[0100]
[0101]
[0102] In the above formula, C is the number of motion regions associated with the face region corresponding to each face identity, center face is the center coordinate of the face area, center i is the center coordinate of the ith motion region, dest_width is the width of the target video, sign(x) is a sign function used to determine whether the face region is associated with the ith motion region, n is the total number of motion regions, and norm_C is the proportion score. i is the center coordinate of the i-th motion region in the video frame a, and n is the total number of motion regions in the video frame a. face is the center coordinate of a face area in the video frame a.
[0103] Step 402: Determine a distance score for characterizing the proximity between the face region corresponding to each face identity and the motion region.
[0104] In one example, the average distance score between the center of the face region corresponding to each face identity and the center of the plurality of motion regions in the first type of video frame can be determined, and the average distance score is used to measure the proximity between the face region and the motion region, that is, the distance score can be the average distance score. In one example, the average distance score can be calculated by the following formula:
[0105]
[0106]
[0107] Wherein, the norm_D is the average distance score.
[0108] Step 403: Determine a confidence score for characterizing the tracking accuracy of each of the face identities.
[0109] The recognition confidence score can be used to measure the accuracy of the face recognition result, i.e., the face tracking result. In one example, the recognition confidence score can be calculated by the following formula:
[0110]
[0111] In the above formula, face threshold is the preset face recognition threshold, norm_P is the recognition confidence score, face dist is the Euclidean distance between the first face feature vector and the second face feature vector, the first face feature vector is the feature vector of the face image in the face area corresponding to each face identity, the second face feature vector is the feature vector of the target standard face image in a preset face database, the face database stores standard face images belonging to different face identities, and the Euclidean distance between the feature vector of the target standard face image and the first face feature vector is the smallest.
[0112] Step 404: Obtain the wonderfulness scores of the cropping positions corresponding to the multiple face identities according to the motion proportion score, the distance score and the confidence score.
[0113] In an example, the motion proportion score, distance score and confidence score can respectively correspond to preset weights. The server can sum the motion proportion score, distance score and confidence score according to the weight coefficients corresponding to the motion proportion score, distance score and confidence score corresponding to each facial identity, so as to obtain the wonderfulness score of the cropping position corresponding to each facial identity.
[0114] In one example, the wonderfulness score can be calculated by the following formula:
[0115]
[0116] Among them, norm_C is the motion proportion score, norm_D is the distance score, norm_P is the confidence score, m represents the number of faces detected in the first category of video frames, which can also be understood as the number of face areas in the first category of video frames, and score represents the wonderfulness score of the face area, that is, the wonderfulness score of the cropping position corresponding to the i-th face identity in the first category of video frames.
[0117] Step 405: Determine the cropping position sequence corresponding to the shot with people according to the excitement score.
[0118] In one example, if all video frames captured by human lenses are first-class video frames in which human faces are detected, the method for determining the cropping position sequence corresponding to the human lenses may be as follows:
[0119] First, a cropping position sequence consisting of cropping positions corresponding to the same face identity in each first-category video frame is obtained, and a score sequence consisting of wonderfulness scores of cropping positions corresponding to the same face identity in each first-category video frame is obtained. The cropping position sequence and the score sequence are recorded as <R 1 ,S 1 >, <R 2 ,S 2 >,…, <R n ,S n >; Among them, <R 1 ,S 1 > is the cropping position sequence and score sequence corresponding to the face identity 1 recognized under the human lens, <R 2 ,,S 2 > is the cropping position sequence and score sequence corresponding to the face identity 2 recognized under the human lens, <R n ,,S n > is the cropping position sequence and score sequence corresponding to the face identity n recognized under human lens.
[0120] Then, based on the cropping position sequence and score sequence corresponding to each face identity, the comprehensive score of the cropping position sequence corresponding to each face identity is calculated. For example, the comprehensive score can be calculated by the following formula:
[0121]
[0122] In the example, k is the number of frames in the video captured by a human, and r is i and r i-1 are the cropping positions of the i-th frame and the i-1-th frame, that is, the cropping positions of the two frames before and after, dest_width is the width of the target video, s i is with r iThe corresponding wonderfulness score, O, represents the comprehensive score of the cropping position sequence, O ≥ 0. The scoring principle of the comprehensive score O follows the cropping position difference (coordinate difference) between the previous and next two frames | r i -r i-1 The smaller the |, the more exciting the score i The higher the value, the greater the comprehensive score result O. Referring to the above formula, for each face identity recognized under a human lens, the comprehensive score of the cropping position sequence corresponding to the face identity can be calculated.
[0123] Finally, the cropping position sequence with the largest comprehensive score O can be selected as the cropping position sequence corresponding to the human shot.
[0124] In another example, the camera with people includes the first type of video frames in which faces are detected, and also includes the second type of video frames in which faces are not detected. The first type of cropping position sequence corresponding to all the first type of video frames in the camera with people can be determined based on the wonderfulness score. The second type of cropping position sequence corresponding to all the second type of video frames in the camera with people can be determined by referring to the method for determining the cropping position sequence in the camera without people. According to the arrangement order of the video frames in the camera with people, the cropping position sequence corresponding to the camera with people is obtained by combining the first type of cropping position sequence and the second type of cropping position sequence.
[0125] It should be noted that the above examples in this embodiment are only provided for the convenience of understanding and do not constitute a limitation on the technical solution of the present invention.
[0126] Compared with the prior art, this embodiment distinguishes between scenes with people and scenes without people. For scenes with people, this embodiment determines the cropping position sequence corresponding to the unmanned shots by the relative positions between the cluster centers used to characterize the motion areas in each video frame. Since the position of the target cluster center is closest to the cropping position of the previous frame of the traversed video frame, it is helpful to ensure the continuity of the cropping positions of the two adjacent video frames, thereby improving the continuity of cropping under unmanned shots. For scenes with people, the cropping positions corresponding to multiple face identities in the first type of video frame are determined in combination with the positions of the motion area and the positions of multiple face areas in the first type of video frame. That is, when there are multiple people under the lens with people, the cropping coordinate sequence corresponding to the lens with people is determined in combination with multiple face areas and motion areas, which is helpful to improve the continuity between the previous and next frames cropped under the lens with people.
[0127] The third embodiment of the present invention relates to a video cropping method, which is a further improvement on the implementation method of determining the cropping coordinate sequence corresponding to the human shot in the second embodiment. The implementation details of the video cropping method of this embodiment are described in detail below. The following content is only for the convenience of understanding the implementation details provided, and is not necessary for the implementation of this solution.
[0128] In this embodiment, face tracking is performed on each video frame captured by a human lens to obtain the face identity, which may include: performing face recognition on each video frame captured by a human lens to determine video frames with successful recognition and video frames with unsuccessful recognition; based on the face identity recognized in the successfully recognized video frames, face tracking is performed on the video frames with unsuccessful recognition to obtain tracking results; based on the tracking results, the face identity in the video frames with unsuccessful recognition is obtained.
[0129] In one example, the method for determining the cropping coordinate sequence corresponding to the human shot can be as follows: Figure 8 As shown, including:
[0130] Step 501: perform face detection on each video frame captured by a human lens, and determine the position of the face area in the video frame where the face is detected.
[0131] Among them, step 501 is substantially the same as step 301 in the second embodiment, and will not be described again here to avoid repetition.
[0132] Step 502: If multiple face regions are detected, face recognition is performed on the multiple face regions to determine a sequence of recognized video frames that recognize the same face identity.
[0133] Among them, the method of performing face recognition on multiple face areas is roughly the same as the face recognition method mentioned in the second embodiment. In this embodiment, taking into account the possible recognition failure in actual applications, after performing face recognition on each video frame under the lens of a person, the video frames with successful recognition and the video frames with unsuccessful recognition can be determined. Further, after performing face recognition, the sequence of recognized video frames that recognize the same face identity can be determined, that is, the sequence of video frames that successfully recognize the same face identity is determined. For ease of understanding, the same face identity takes person1 as an example, that is, the sequence of video frames that successfully recognize person1 under the lens of a person is determined.
[0134] Step 503: Determine whether there is a sequence of video frames to be tracked in which the same face identity is not recognized; if so, execute step 504; otherwise, execute step 510.
[0135] For example, referring to the above example, the same face identity is person1. In this step, it can be determined whether there is a sequence of video frames to be tracked in which person1 is not recognized under the camera with someone. That is to say, under the camera with someone, it is determined whether there is a video frame in which person1 is not recognized, and the video frame in which person1 is not recognized is used as the sequence of video frames to be tracked for person1. If it is determined that there is no sequence of video frames to be tracked in which person1 is not recognized, it means that person1 is successfully recognized in the first category of video frames in which faces are detected under the camera with someone. If it is determined that there is a sequence of video frames to be tracked in which person1 is not recognized, it means that there are video frames in the first category of video frames in which faces are detected under the camera with someone that do not recognize person1.
[0136] In an example, the face recognition results of the first type of video frames where a face is detected under a human lens can be referred to Table 2:
[0137] Table 2
[0138]
[0139] It can be seen from Table 2 that for person 1, person 1 was successfully identified in the three video frame sequences of "100-150, 160-180, 185-200", and was not successfully identified in the four video frame sequences of "80-99, 151-159 / 159-151, 181-184 / 184-181, 201-300". For person 2 and other facial identities identified under human shots, the corresponding identified video frame sequences and to-be-tracked video frame sequences can also be obtained. In Table 2, the human shot information can be understood as the video frames under the shot: the 80th to 300th frames of the video to be cropped.
[0140] Step 504: Taking the same face identity as the tracking target, determine whether the video frame is tracked successfully in the sequence of video frames to be tracked; if yes, execute step 505, otherwise execute step 508.
[0141] The video frame that is successfully tracked is the video frame that tracks the tracking target. For example, when the same face identity is person1, the video frame that tracks the face of person1 can be determined in the sequence of video frames to be tracked, and the video frame that successfully tracks the face of person1 is used as the video frame that is successfully tracked, and the video frame that fails to track the face of person1 is used as the video frame that is not successfully tracked. For the video frame that is successfully tracked, step 505 is executed, and for the video frame that is not successfully tracked, step 508 is executed.
[0142] That is, based on the face identity recognized in the successfully recognized video frame (such as person1), face tracking is performed on the unrecognized video frame (such as the sequence of video frames to be tracked) to obtain a tracking result (such as whether the tracking is successful).
[0143] In one example, the tracking method may be one-way tracking, and the one-way tracking method may be: determining the tracking target in the tracking start frame, tracking each video frame in the video frame sequence to be tracked starting from the tracking start frame, determining the similarity between each video frame in the video frame sequence to be tracked and the tracking target, and taking the video frame whose similarity with the tracking target is greater than or equal to a preset similarity as a video frame with successful tracking; taking the video frame whose similarity with the tracking target is less than a preset similarity as a video frame with failed tracking. For example, person1 in the tracking start frame may be determined as the tracking target. In a specific implementation, the tracking start frame may be the first frame or the last frame in the identified video frame sequence.
[0144] In another example, the tracking method may be bidirectional tracking, and the bidirectional tracking method may be:
[0145] The forward tracking target is determined in the forward tracking start frame, and each video frame in the video frame sequence to be tracked is tracked from the forward tracking start frame, and the first similarity between each video frame in the video frame sequence to be tracked and the forward tracking target is determined; wherein the forward tracking start frame is the last frame of an identified video frame sequence before the video frame sequence to be tracked, and the target to be forward tracked is the face belonging to the same face identity in the forward tracking start frame, for example, person1 in the forward tracking start frame can be determined as the forward tracking target. Referring to Table 2 above, for the video frame sequence to be tracked (151-159), the forward tracking start frame is the last frame (the 150th frame) of an identified video frame sequence (100-150) before the video frame sequence to be tracked (151-159). Similarly, the forward tracking start frame corresponding to the video frame sequence to be tracked (181-184) is the 180th frame, and the forward tracking start frame corresponding to the video frame sequence to be tracked (201-300) is the 200th frame.
[0146] A reverse tracking target is determined in a reverse tracking start frame, and each video frame in a video frame sequence to be tracked is tracked starting from the reverse tracking start frame, and a second similarity between each video frame in the video frame sequence to be tracked and the reverse tracking target is determined; wherein the reverse tracking start frame is the first frame of an identified video frame sequence after the video frame sequence to be tracked, and the target to be reverse tracked is a face belonging to the same face identity in the reverse tracking start frame, for example, person1 in the reverse tracking start frame can be determined as the reverse tracking target. Referring to Table 2 above, for a video frame sequence to be tracked (151-159), the reverse tracking start frame is the first frame (the 160th frame) of an identified video frame sequence (160-180) after the video frame sequence to be tracked (151-159). Similarly, the reverse tracking start frame corresponding to the video frame sequence to be tracked (181-184) is the 185th frame, the forward tracking start frame corresponding to the video frame sequence to be tracked (201-300) is the 200th frame, and the reverse tracking start frame corresponding to the video frame sequence to be tracked (99-80) is the 100th frame.
[0147] According to the first similarity between each video frame in the video frame sequence to be tracked and the forward tracking target, and the second similarity between each video frame in the video frame sequence to be tracked and the reverse tracking target, it is determined whether each video frame in the video frame sequence to be tracked is a video frame that has been successfully tracked. That is, for each video frame in the video frame sequence to be tracked, which has a first similarity with the forward tracking target and a second similarity with the reverse tracking target, a larger similarity is selected between the first similarity and the second similarity as the tracking similarity of each video frame in the video frame sequence to be tracked, and the video frame whose tracking similarity is greater than the preset similarity is taken as the video frame that has been successfully tracked. That is, the forward and reverse tracking methods are used at the same time, and the forward and reverse tracking results (the forward tracking result is the first similarity, and the reverse tracking result is the second similarity) have an intersecting tracking area (i.e., a video frame that has the first similarity and the second similarity at the same time), and the result with the higher similarity is taken as the final tracking result.
[0148] In one example, considering that the face area detected by the face detection method only contains facial features of the face, in order to improve the tracking accuracy and avoid the tracking result from "drifting" and causing tracking failure. In this embodiment, the face detection frame that is enlarged according to a certain ratio, that is, the face area bounding box, can be used to initialize the tracker. In addition to the face area, the enlarged bounding box area also introduces image information around the face, which is equivalent to expanding the face area, making it easier to track the face in the face area, and helping to improve the accuracy and robustness of the tracking results. In one example, the bounding box enlargement ratio is set as follows:
[0149]
[0150] Among them, x and y are the coordinate positions of the bounding box of the face area relative to the upper left corner of the image (the coordinate origin), and w and h are the width and height of the bounding box of the face area.
[0151] Step 505: The video frame that is successfully tracked is used as the video frame in which the tracking target is identified.
[0152] That is to say, for the first type of video frames where faces are detected under human lens, if face recognition fails, face tracking will be performed. If tracking is successful, that is, the tracking target is tracked, the video frame with successful tracking will still be regarded as a video frame with recognized faces. For example, if person1 is successfully tracked in a video frame, the video frame will be regarded as a video frame with recognized person1. If person2 is successfully tracked in a video frame, the video frame will be regarded as a video frame with recognized person2. That is, the server can obtain the identity of the face in the video frame that was not successfully recognized based on the tracking result of whether the tracking was successful.
[0153] Step 506: Based on the face identities identified in the identified video frame sequence and the face identities tracked in the successfully tracked video frames, a plurality of face identities corresponding to the plurality of face regions are obtained.
[0154] That is to say, based on face recognition and face tracking, multiple face identities corresponding to multiple face regions are obtained.
[0155] Step 507: Determine, based on the positions of the multiple face regions, the cropping positions corresponding to the multiple face identities in the identified video frame sequence and the cropping positions corresponding to the multiple face identities in the successfully tracked video frames.
[0156] Step 507 is substantially the same as step 303 in the second embodiment, except that the first type of video frames in which faces are detected are further divided into a sequence of recognized video frames and a sequence of video frames with successful tracking.
[0157] Step 508: Select a target face region from the face regions in the video frames that have not been successfully tracked.
[0158] That is to say, if there are video frames that have not been successfully tracked, the server can select a target face area from the face area in the video frames that have not been successfully tracked; wherein the video frames that have not been successfully tracked are video frames that have not tracked the tracking target; the center of the target face area is closest to the center of the reference face area of the previous frame of the video frame that has not been successfully tracked, and the reference face area is the area where the face of the tracking target is located.
[0159] Step 509: Determine the cropping position of the tracking target in the video frame where tracking is not successful according to the target face region.
[0160] For example, the center of the target face area may be used as the cropping position of the tracking target in the video frame where tracking is not successful.
[0161] Step 510: Determine a cropping position sequence corresponding to human shots based on the cropping positions corresponding to multiple facial identities in the identified video frame sequence, the cropping positions corresponding to multiple facial identities in the successfully tracked video frames, the cropping positions of the tracked targets in the unsuccessfully tracked video frames, and the positions of the moving areas in the first category of video frames.
[0162] That is to say, the first category of video frames in which faces are detected includes: a sequence of recognized video frames, i.e., each video frame in which face videos have been successfully completed, video frames that have not been successfully recognized but successfully tracked, and video frames that have not been successfully tracked. The cropping positions corresponding to multiple face identities in the first category of video frames include: the cropping positions corresponding to multiple face identities in the sequence of recognized video frames, the cropping positions corresponding to multiple face identities in the video frames in which tracking has been successful, and the cropping positions of the tracking targets in the video frames in which tracking has not been successful. Since the implementation method of determining the cropping coordinate sequence corresponding to the human shot based on the cropping positions corresponding to the multiple face identities in the first category of video frames and the positions of the moving areas in the first category of video frames has been described in the second embodiment, it will not be repeated here to avoid repetition.
[0163] Step 511: Determine the corresponding cropping positions of the multiple face identities in each video frame captured by a human lens according to the positions of the multiple face regions.
[0164] Step 512: Determine a cropping position sequence corresponding to the human shot according to the cropping positions corresponding to the multiple face identities in each video frame under the human shot and the position of the motion area in each video frame under the human shot.
[0165] Among them, step 511 to step 512 are substantially the same as step 303 to step 304 in the second embodiment, and will not be described again to avoid repetition.
[0166] In an example, for ease of understanding, you can refer to Fig. 9 Schematic diagram of the implementation process of the video cropping method shown:
[0167] Step 601: Shot segmentation: Shot segmentation is performed on the video to be cropped to obtain the segmented shots.
[0168] Step 602: motion region detection. That is, motion region detection is performed on each video under each shot after segmentation to determine the motion region in each video frame.
[0169] Step 603: Sharpening the detection result, that is, sharpening the detection result of the motion area to highlight the center of the motion area.
[0170] Step 604: clustering of motion regions, that is, clustering multiple motion regions in each video frame to obtain cluster centers for characterizing the motion regions.
[0171] Step 605: Determine the cluster center coordinates, that is, use the location of the cluster center as the location of the motion region represented by the cluster center.
[0172] After motion detection is performed on each video frame, the location of the video's highlight area is determined by the relative position relationship of the motion areas in two adjacent video frames for the unmanned shots obtained after segmentation, thereby determining the unmanned shot cropping coordinates. For the segmented human shots, the following steps are performed:
[0173] Step 606: Face detection, that is, determining the first type of video frames in which faces are detected in the video frames captured by people.
[0174] Step 607: Face recognition: That is, face recognition is performed on the first type of video frames in which faces are detected.
[0175] Step 608: Face tracking: that is, face tracking is performed on the first type of video frames where recognition fails.
[0176] Step 609: Determine the coordinates of the face region.
[0177] Step 610: Perform a wonderful score by combining the face area and the motion area, that is, determine the wonderful score of the cropping position corresponding to each face identity in the first type of video frame.
[0178] For shots with people in them, the face area is associated with the motion block in combination with the clustering results of the motion area. The association results and face recognition results are combined to complete the wonderfulness scoring of the face area. The location of the wonderful area of the video under the shot with people is determined based on the scoring results, thereby determining the cropping coordinates of the shot with people.
[0179] Step 611: Acquire the entire video cropping coordinates, that is, combine the cropping coordinates of the human-eye shot and the human-eye shot in the video to be cropped to obtain the cropping coordinates of the entire video.
[0180] It should be noted that the above examples in this embodiment are only provided for the convenience of understanding and do not constitute a limitation on the technical solution of the present invention.
[0181] Compared with the prior art, in this implementation, taking into account the possibility of face recognition failure in actual applications, face tracking is performed on video frames that have not been successfully recognized, which is beneficial to improving the face recognition rate and making the recognized face identity more continuous in each video frame under the human lens, thereby further improving the continuity of the target video obtained after cropping.
[0182] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0183] A fourth embodiment of the present invention relates to an electronic device, such as Fig.10 As shown, it includes at least one processor 701; and a memory 702 that is communicatively connected to the at least one processor 701; wherein the memory 702 stores instructions that can be executed by the at least one processor 701, and the instructions are executed by the at least one processor 701 so that the at least one processor 701 can execute the video cropping method in the first to third embodiments.
[0184] The memory 702 and the processor 701 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 701 and the memory 702 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 701 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 701.
[0185] The processor 701 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 702 can be used to store data used by the processor 701 when performing operations.
[0186] A fifth embodiment of the present invention relates to a computer-readable storage medium storing a computer program, which implements the above method embodiment when executed by a processor.
[0187] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0188] Those skilled in the art will appreciate that the above-mentioned embodiments are specific examples for implementing the present invention, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present invention.
Claims
1. A video cropping method, characterized in that: include: Perform lens segmentation on the video to be cropped and obtain each video frame under each lens; Determine the position of the motion area in each video frame under each of the lenses; Determine, according to the position of the motion area, a cropping position sequence corresponding to each of the lenses; wherein the cropping position sequence includes the cropping position of each video frame under each of the lenses; Cropping the video to be cropped according to the cropping position sequence to obtain a cropped target video; The step of determining the clipping coordinate sequence corresponding to each of the lenses according to the position of the motion area includes: If it is determined that there is an unmanned shot among the shots, determining a cropping coordinate sequence corresponding to the unmanned shot according to the position of the motion area in each video frame under the unmanned shot; If it is determined that there is a shot with a person in each of the shots, face tracking is performed on each video frame under the shot with the person to obtain the face identity, and the cropping coordinate sequence corresponding to the shot with the person is determined based on the face identity and the position of the motion area in each video frame under the shot with the person.
2. The video cropping method according to claim 1, characterized in that: The face identity is a plurality of face identities, and determining the cropping coordinate sequence corresponding to the shot with the person according to the face identity and the position of the motion region in each video frame under the shot with the person, comprises: Determine a plurality of face regions where the plurality of face identities are located; Determining, according to the positions of the multiple face regions, the cropping positions corresponding to the multiple face identities in each video frame captured by the human lens; According to the cropping positions corresponding to the multiple face identities in each video frame under the human shot and the positions of the motion areas in each video frame under the human shot, a cropping position sequence corresponding to the human shot is determined.
3. The video cropping method according to claim 1, characterized in that: The step of tracking the face of each video frame captured by the camera to obtain the face identity includes: Performing face recognition on each video frame captured by the camera with people, and determining video frames with successful recognition and video frames with unsuccessful recognition; According to the face identity recognized in the successfully recognized video frame, performing face tracking on the unsuccessfully recognized video frame to obtain a tracking result; The identity of the face in the unrecognized video frame is obtained according to the tracking result.
4. The video cropping method according to claim 2, characterized in that: The determining, according to the cropping positions corresponding to the plurality of face identities in each video frame under the human-capable lens and the positions of the motion regions in each video frame under the human-capable lens, a cropping position sequence corresponding to the human-capable lens comprises: According to the cropping positions corresponding to the multiple facial identities in each video frame under the human lens and the positions of the motion areas in each video frame under the human lens, scoring the wonderfulness of the cropping positions corresponding to the multiple facial identities to obtain wonderfulness scores of the cropping positions corresponding to the multiple facial identities; The cropping position sequence corresponding to the shot with people is determined according to the excitement score.
5. The video cropping method according to claim 4, characterized in that: The step of scoring the wonderfulness of the cropping positions corresponding to the multiple face identities to obtain the wonderfulness scores of the cropping positions corresponding to the multiple face identities includes: Determine the motion proportion score of the face area where each face identity is located according to the cropping positions corresponding to the multiple face identities in each video frame under the human lens and the position of the motion area in each video frame under the human lens; wherein the motion proportion score is used to represent the proportion of the number of motion areas associated with the face area where each face identity is located to the total number of motion areas; Determining a distance score for characterizing the proximity between the face region corresponding to each of the face identities and the motion region; determining a confidence score characterizing the tracking accuracy of each of the face identities; The wonderfulness scores of the cropping positions corresponding to the multiple facial identities are obtained according to the motion proportion score, the distance score and the confidence score.
6. The video cropping method according to claim 5, characterized in that: The sports proportion score is calculated by the following formula: Where C is the number of motion regions associated with the face region where the face identity is located, center face is the center coordinate of the face area, center i is the center coordinate of the ith motion region, dest_width is the width of the target video, sign(x) is a sign function used to determine whether the face region is associated with the ith motion region, n is the total number of the motion regions, and norm_C is the proportion score.
7. The video cropping method according to claim 6, characterized in that: The distance score is calculated by the following formula: Among them, the norm_D is the distance score.
8. The video cropping method according to claim 1, characterized in that: The step of tracking the face of each video frame captured by the camera to obtain the face identity includes: Acquire a face image in each video frame captured by the human lens; Determine the similarity between the face image and a plurality of standard face images in a preset face database; wherein the face database stores standard face images belonging to different face identities, and the number of standard face images belonging to the same face identity is multiple; Selecting M standard face images whose similarity to the face image is greater than a preset similarity; wherein M is a natural number greater than 1; According to the facial identities to which the M standard facial images belong, the M standard facial images are grouped and the number of standard facial images in each group is determined; wherein the facial identities to which the standard facial images in the same group belong are the same; The face identity is obtained according to the number of standard face images in each group.
9. The video cropping method according to claim 1, characterized in that: The step of determining the cropping coordinate sequence corresponding to the unmanned shot according to the position of the motion area in each video frame under the unmanned shot comprises: When determining the position of each motion region in the first frame of the unmanned shot as the initial cropping position, a reference cropping position sequence corresponding to the unmanned shot; wherein the number of motion regions in the first frame and the number of the reference cropping position sequence are both N, and N is a natural number greater than 1; Among the N reference cropping position sequences, a reference cropping position sequence is selected as the cropping position sequence corresponding to the unmanned shot.
10. The video cropping method according to claim 9, characterized in that: When determining the position of each motion area in the first frame under the unmanned shot as the initial cropping position, the reference cropping position sequence corresponding to the unmanned shot includes: Sequentially taking the position of each motion area in the first frame of the unmanned camera as an initial cropping position; When the position of each motion area is used as the initial cropping position, the second frame to the end frame of the unmanned lens are traversed in sequence, and the following steps are performed on the traversed video frames: Selecting a target motion region from each motion region of the traversed video frame, and using the position of the target motion region as the cropping position of the traversed video frame; wherein the position of the target motion region is closest to the cropping position of a previous frame of the traversed video frame; After traversing the end frame, a reference cropping position sequence corresponding to the unmanned shot is determined according to the initial cropping position and the cropping positions of the traversed video frames.
11. The video cropping method according to any one of claims 1 to 10, characterized in that: The determining the position of the motion area in each video frame under each lens comprises: Determine multiple motion regions in each video frame under each lens according to a comparison relationship between two adjacent video frames under each lens; Clustering multiple motion regions in each of the video frames to obtain cluster centers for characterizing the motion regions; wherein one cluster center is used to characterize one motion region; The position of the cluster center is determined, and the position of the cluster center is used as the position of the motion area represented by the cluster center.
12. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the video cropping method according to any one of claims 1 to 11.
13. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the video cropping method according to any one of claims 1 to 11 is implemented.
