Collision detection method and device

By using a quad-tree to recursively divide and dynamic updates of the video picture in video editing, the problem of slow collision detection speed in the existing technology is solved, efficient and real-time collision detection is achieved, and the fluency and accuracy of video editing is improved.

CN120281908APending Publication Date: 2025-07-08SHANGHAI BILIBILI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510370870.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

The existing collision detection schemes have a large amount of calculation in video editing, resulting in slow detection speed, affecting real-time and fluency, especially on devices with limited computing resources, which are prone to lag.

Method used

The quad-tree is used to recursively divide the video picture, and a quad-tree is constructed to represent the regional hierarchical relationship and element position of the video picture. The element collision is judged by the comparison between the target node and the adjacent node, and the quad-tree structure is dynamically updated to adapt to element changes.

Benefits of technology

Improve the speed and accuracy of collision detection, real-time collision detection is realized, and the response speed and user experience of video editing are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120281908A_ABST
    Figure CN120281908A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a collision detection method and related equipment / products, and belongs to the technical field of video editing. The method comprises the following steps: determining a target element in a plurality of elements of a video picture, wherein the video picture is associated with a pre-constructed quadtree; according to the quadtree, a target node and adjacent nodes are determined, the target node represents an area where the target element is located, and the adjacent nodes comprise brother nodes of the target node and brother nodes of a father node of the target node; determining adjacent elements according to the target node and the adjacent nodes; the target element and the adjacent element are compared to obtain a detection result, and the detection result is used for representing whether collision occurs between the target element and the adjacent element. According to the technical scheme provided by the embodiment of the invention, the range of elements in which collision possibly occurs can be quickly positioned, unnecessary element comparison is reduced, the collision detection speed is remarkably improved, real-time collision detection in a video editing process is realized, and the response speed of video editing is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the field of video editing technology, and in particular, to a collision detection method, device, computer device, computer-readable storage medium, and computer program product. Background Art

[0002] With the development of video technology, video editors are widely popular. Through a video editor, elements such as stickers, emojis, and subtitles can be added to the video screen to enhance the interest and expressiveness of the video. When there are multiple elements in the video screen, collision detection is required to ensure a reasonable layout.

[0003] However, existing collision detection solutions currently need to traverse all elements and compare position and boundary information one by one to determine whether a collision occurs. When the number of elements is large, the computational amount is extremely large, resulting in a slow detection speed, thus affecting the real-time performance and smoothness of video editing. Especially in an environment with relatively limited computing resources such as mobile devices, there is an easy occurrence of lag, reducing the video editing experience.

[0004] It should be noted that the above content is not necessarily prior art and is not used to limit the patent protection scope of the present application. Summary of the Invention

[0005] Embodiments of the present application provide a collision detection method, device, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the above technical problems.

[0006] One aspect of embodiments of the present application provides a collision detection method, and the method includes: Determine a target element among multiple elements in a video screen, where the video screen is associated with a pre-constructed quadtree, nodes in the quadtree represent regions in the video screen, and the quadtree is used to represent the hierarchical relationship between regions in the video screen and the regions where each of the elements is located; According to the quadtree, determine a target node and adjacent nodes, where the target node represents the region where the target element is located, and the adjacent nodes include sibling nodes of the target node and sibling nodes of the parent node of the target node; According to the target node and the adjacent nodes, determine adjacent elements; Compare the target element with the adjacent elements to obtain a detection result, where the detection result is used to indicate whether a collision occurs between the target element and the adjacent elements.

[0007] Optionally, each element has two-dimensional spatial information for describing the position and size of the element in the video frame; correspondingly, the quadtree is constructed through the following operations: Performing recursive partitioning on the video frame according to a preset rule to obtain multiple regions at multiple levels, and forming a quadtree according to the hierarchical relationship between the multiple regions, where each region has a coordinate range; wherein, the quadtree includes a root node, multiple internal nodes, and multiple leaf nodes, the root node corresponds to the video frame, the internal nodes correspond to regions with the next level, the leaf nodes correspond to regions without the next level, the regions without the next level are used to accommodate the elements, and the leaf nodes are associated with an element list; Traversing the quadtree downward starting from the root node, and allocating the multiple elements to the element lists of the multiple leaf nodes; Wherein, the coordinate range of the region corresponding to the leaf node matches the two-dimensional spatial information of the elements allocated to the associated element list.

[0008] Optionally, performing recursive partitioning on the video frame according to a preset rule includes: Determining the maximum number of levels according to the device performance and / or the preset maximum number of elements; Performing recursive partitioning on the video frame until the maximum number of levels is reached; or Performing recursive partitioning on the video frame until the number of elements in the newly partitioned region does not exceed the preset element capacity.

[0009] Optionally, the collision detection method further includes: Determining a first element, where the first element includes an element newly added to the video frame; Traversing the quadtree downward starting from the root node, determining a first leaf node and adding the first element to the corresponding element list, where the coordinate range of the region corresponding to the first leaf node matches the two-dimensional spatial information of the first element.

[0010] Optionally, the collision detection method further includes: Determining a second element, where the second element includes an element deleted from the video frame; Traversing the quadtree downward starting from the root node, determining a second leaf node and removing the second element from the corresponding element list, where the coordinate range of the region corresponding to the second leaf node matches the two-dimensional spatial information of the second element.

[0011] Optionally, the collision detection method further includes: Determine a third element, where the third element includes the element with changed two-dimensional spatial information, and the change is obtained by moving the element or adjusting the size of the element; Traverse the quadtree downward starting from the root node, determine a third leaf node, and remove the third element from the corresponding element list, where the coordinate range of the area corresponding to the third leaf node matches the two-dimensional spatial information of the third element before the change; Traverse the quadtree downward starting from the root node, determine a fourth leaf node, and add the third element to the corresponding element list, where the coordinate range of the area corresponding to the fourth leaf node matches the two-dimensional spatial information of the third element after the change.

[0012] Optionally, the element list has an element capacity; the collision detection method further includes: For a leaf node with a new element added to the element list, determine whether the element list has exceeded the element capacity; In the case where it has exceeded the element capacity, determine the adjacent nodes of the leaf node; Based on the new element, determine whether the element list of the adjacent node will exceed the element capacity; In the case where it will not exceed the element capacity, adjust the new element to the element list of the adjacent node; In the case where it will exceed the element capacity: divide the corresponding area of the leaf node to obtain areas at the next level; create new leaf nodes based on the areas at the next level, and adjust the new element to the element list of the new leaf nodes.

[0013] Optionally, the element list has an element capacity, and the collision detection method further includes: For a leaf node with an element removed from the element list, obtain the sum of the elements of the leaf node and its sibling nodes; In the case where the sum of the elements is less than or equal to the element capacity, merge the leaf node and its sibling nodes.

[0014] Another aspect of the embodiments of the present application provides a collision detection device, and the device includes: A first determination module, configured to determine a target element among multiple elements in a video frame. The video frame is associated with a pre-constructed quadtree, nodes in the quadtree represent areas in the video frame, and the quadtree is used to represent the hierarchical relationship between the areas in the video frame and the areas where each of the elements is located; A second determination module, configured to determine a target node and adjacent nodes according to the quadtree, where the target node represents the region where the target element is located, and the adjacent nodes include sibling nodes of the target node and sibling nodes of the parent node of the target node; A third determination module, configured to determine adjacent elements according to the target node and the adjacent nodes; A collision detection module, configured to compare the target element and the adjacent elements to obtain a detection result, where the detection result is used to indicate whether a collision occurs between the target element and the adjacent elements.

[0015] Another aspect of the embodiments of the present application provides a computer device, including: 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 method as described above.

[0016] Another aspect of the embodiments of the present application provides a computer-readable storage medium, where computer instructions are stored in the computer-readable storage medium, and when the computer instructions are executed by a processor, the method as described above is implemented.

[0017] Another aspect of the embodiments of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method as described above is implemented.

[0018] The embodiments of the present application adopting the above technical solutions may include the following advantages: The video frame includes multiple elements and is associated with a pre-constructed quadtree. The nodes in the quadtree represent the regions in the video frame, and the quadtree is used to represent the hierarchical relationship of the regions in the video frame and the regions where the elements are located. The target element is determined among the multiple elements, and its corresponding node in the quadtree is located according to the region where it is located, that is, the target node. Based on the quadtree, the sibling nodes of the target node and the sibling nodes of the parent node of the target node are determined as adjacent nodes. According to the target node and the adjacent nodes, the adjacent elements are determined. The target element and the adjacent elements are compared to obtain a detection result, which is used to indicate whether a collision occurs between the target element and the adjacent elements. It can be seen that through the quadtree, the embodiments of the present application recursively divide the video frame, can efficiently organize, manage and retrieve the regions and multiple elements of the video frame, quickly locate the range of elements that may collide, reduce unnecessary element comparisons, significantly improve the collision detection speed, achieve real-time collision detection during the video editing process, and improve the response speed and user experience of video editing. Description of the Drawings

[0019] The accompanying drawings exemplarily illustrate embodiments and form part of the specification, and are used together with the written description of the specification to explain the exemplary embodiments of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. In all the accompanying drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0020] Figure 1 Schematically shows a flowchart of a collision detection method according to Embodiment 1 of the present application; Figure 2 Schematically shows a flowchart of the construction of a quadtree according to Embodiment 1 of the present application; Figure 3 Schematically shows the tree structure of a quadtree according to Embodiment 1 of the present application; Figure 4 Schematically shows a quadtree according to Embodiment 1 of the present application; Figure 5 Schematically shows Figure 2 The sub-step flowchart of step S200 in; Figure 6 Schematically shows a flowchart of the update of a quadtree according to Embodiment 1 of the present application; Figure 7 Schematically shows a flowchart of the update of a quadtree according to Embodiment 1 of the present application; Figure 8 Schematically shows a flowchart of the update of a quadtree according to Embodiment 1 of the present application; Figure 9 Schematically shows a flowchart of the update of a quadtree according to Embodiment 1 of the present application; Figure 10 Schematically shows a flowchart of the update of a quadtree according to Embodiment 1 of the present application; Figure 11 Schematically shows a flowchart of a collision detection method according to Embodiment 1 of the present application; Figure 12 Schematically shows a flowchart of the overall update of a quadtree according to Embodiment 1 of the present application; Figure 13 Schematically shows a block diagram of a collision detection device according to Embodiment 2 of the present application; and Figure 14 Schematically shows a schematic diagram of the hardware architecture of a computer device according to Embodiment 3 of the present application. Detailed implementation manners

[0021] To make the objectives, technical solutions and advantages of the present application more clear and understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts belong to the scope of protection of the present application.

[0022] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be construed as indicating or implying their relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between various embodiments can be combined with each other, but it must be based on the fact that those of ordinary skill in the art can implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present application.

[0023] In the description of the present application, it should be understood that the numerical labels before the steps do not identify the order of execution of the steps, but are only used to facilitate the description of the present application and to distinguish each step, and thus cannot be construed as a limitation to the present application.

[0024] First, the following provides the term explanations involved in the present application: Quadtree: A tree-shaped data structure that recursively divides a two-dimensional space into four regions (quadrants), represents the regions through nodes, and is used for efficient organization, management, and retrieval of two-dimensional space data.

[0025] APP (Application): Application program.

[0026] Secondly, to facilitate the understanding of the technical solutions provided in the embodiments of the present application by those skilled in the art, the related technologies are described below: With the development of video technology, video editors are widely popular. Through video editors, elements such as stickers, expressions, and subtitles can be added to the video screen to enhance the fun and expressiveness of the video. When there are multiple elements in the video screen, collision detection is required to ensure a reasonable layout.

[0027] However, the existing collision detection schemes currently need to traverse all elements and compare information such as positions and boundaries one by one to determine whether a collision occurs. When the number of elements is large, the amount of calculation is extremely large, resulting in a slow detection speed, which affects the real-time performance and smoothness of video editing. Especially in an environment with relatively limited computing resources such as mobile devices, lags are likely to occur, reducing the video editing experience.

[0028] To this end, the embodiments of the present application provide a technical solution for collision detection. In this technical solution: (1) An efficient and accurate collision detection method based on a quadtree is provided, which can be used in video editing on the APP side to improve the efficiency of collision detection; (2) The quadtree is used to recursively divide the two-dimensional space of the video frame, efficiently organize, manage, and retrieve each region of the video frame and multiple elements, quickly locate the range of elements that may collide, reduce unnecessary element comparisons, significantly improve the speed of collision detection, achieve real-time collision detection during the video editing process, and improve the real-time responsiveness of editing operations; (3) Through optimized coordinate calculation and boundary judgment logic, accurately judge the collision situation between elements, ensure the accuracy of the detection results, reduce misjudgment or missed judgment, and ensure the rationality and aesthetics of the element layout in the video frame; (4) Considering the dynamic changes of elements during the video editing process, such as addition, deletion, movement, size change, etc., a dynamic update mechanism that can update the quadtree structure and the attribution relationship of elements in the tree in real time and efficiently is provided to ensure that the quadtree can always adapt to the changes of elements and provide accurate support for collision detection. See the following for details.

[0029] The technical solution of the present application will be introduced below through multiple embodiments. It should be noted that these embodiments can be implemented in many different forms and should not be construed as being limited only to the embodiments described herein.

[0030] Embodiment 1 Figure 1 A flowchart of the collision detection method according to Embodiment 1 of the present application is schematically shown.

[0031] As Figure 1 and Figure 11 shown, the collision detection method may include steps S100 to S106, where: Step S100, determine a target element among multiple elements in the video frame. The video frame is associated with a pre-constructed quadtree, and the nodes in the quadtree represent regions in the video frame. The quadtree is used to represent the hierarchical relationship between each region of the video frame and the regions where each of the elements is located.

[0032] Step S102, according to the quadtree, determine a target node and adjacent nodes. The target node represents the region where the target element is located, and the adjacent nodes include the sibling nodes of the target node and the sibling nodes of the parent node of the target node.

[0033] Step S104, according to the target node and the adjacent nodes, determine adjacent elements.

[0034] Step S106: Compare the target element with the adjacent elements to obtain a detection result, which is used to indicate whether a collision occurs between the target element and the adjacent elements.

[0035] The collision detection method provided in this embodiment. The video frame includes multiple elements and is associated with a pre-constructed quadtree. The nodes in the quadtree represent regions in the video frame, and the quadtree is used to represent the hierarchical relationship of each region in the video frame and the regions where each element is located. Determine a target element among the multiple elements, and locate the corresponding node in the quadtree based on the region where it is located, that is, the target node. Based on the quadtree, determine the sibling nodes of the target node and the sibling nodes of the parent node of the target node as adjacent nodes. Determine adjacent elements according to the target node and the adjacent nodes. Compare the target element with the adjacent elements to obtain a detection result, which is used to indicate whether a collision occurs between the target element and the adjacent elements. It can be seen that in the embodiment of the present application, by recursively partitioning the video frame through the quadtree, it is possible to efficiently organize, manage, and retrieve each region and multiple elements of the video frame, quickly locate the range of elements where a collision may occur, reduce unnecessary element comparisons, significantly improve the collision detection speed, achieve real-time collision detection during the video editing process, and improve the response speed and user experience of video editing.

[0036] The following will combine Figure 1 to elaborate in detail on each step in steps S100 to S106 and other optional steps.

[0037] Step S100 Determine a target element among the multiple elements in the video frame. The video frame is associated with a pre-constructed quadtree. The nodes in the quadtree represent regions in the video frame, and the quadtree is used to represent the hierarchical relationship between each region in the video frame and the regions where each element is located.

[0038] The video frame can be loaded and displayed through a video editor as an object for video editing. Multiple elements can be added to the video frame through the video editor. The elements can be stickers, emojis, subtitles, special effects, etc. The elements can have two-dimensional spatial information, which can include coordinate information (such as abscissa x, ordinate y) and size information (such as width w, height h), etc., for describing the position, size, shape, and boundary of the element in the video frame.

[0039] The video frame can be associated with a pre-constructed quadtree. For example, starting from the entire video frame (corresponding to the root node of the quadtree), recursive partitioning is performed to obtain multiple regions at multiple levels. Among them, each partitioning operation divides a region into four smaller regions. Using nodes to represent regions and a tree structure to represent the hierarchical relationship between multiple regions, a reasonable quadtree can be constructed. According to the two-dimensional spatial information of each element, the region where the element is located is determined, so that each element can be accurately assigned to the corresponding quadtree node, enabling the elements to be distributed in the quadtree orderly. The following provides an exemplary solution.

[0040] In an alternative embodiment, as Figure 2 shown, the quadtree can be constructed through the following steps: Step S200, perform recursive partitioning on the video frame according to a preset rule to obtain multiple regions at multiple levels, and form a quadtree based on the hierarchical relationship between the multiple regions. Each region has a coordinate range. Among them, the quadtree includes a root node, multiple internal nodes, and multiple leaf nodes. The root node corresponds to the video frame, the internal nodes correspond to regions with the next level, the leaf nodes correspond to regions without the next level, the regions without the next level are used to accommodate the elements, and the leaf nodes are associated with an element list.

[0041] Step S204, traverse the quadtree downward starting from the root node, and assign the multiple elements to the element lists of the multiple leaf nodes; among them, the coordinate range of the region corresponding to the leaf node matches the two-dimensional spatial information of the elements assigned to the associated element list.

[0042] Exemplarily, the size information of the video frame can be obtained, such as width W and height H. Based on the size information, the entire video frame is used as the corresponding region of the quadtree root node to create an initial quadtree. Perform recursive partitioning on the video frame according to a preset rule to obtain multiple regions at multiple levels, and form a quadtree based on the hierarchical relationship of the multiple regions. Each region has a coordinate range. Each partitioning operation divides a region into four equal-sized regions and creates four corresponding child nodes. The region partitioning can be performed synchronously with the creation of the quadtree nodes, that is, "partition while constructing". Of course, it is also possible to partition the regions first and then create the quadtree, and map these regions through the nodes of the quadtree. As Figure 3 and Figure 4As shown, a quadtree may include a root node, multiple internal nodes, and multiple leaf nodes. Among them, the root node may correspond to the entire video frame, the internal nodes may correspond to regions with a next level, and the leaf nodes may correspond to regions without a next level. Among them, regions without a next level (regions that do not need to be further divided) can accommodate elements, while regions with a next level will be further divided and cannot accommodate elements, serving only as markers for spatial division. As Figure 3 shown, a leaf node may correspond to an element (such as a sticker) or may be empty. Leaf nodes can manage the corresponding elements through an element list.

[0043] After forming the quadtree, each element in the video frame needs to be orderly allocated to the corresponding leaf node so that the quadtree can efficiently organize, manage, and retrieve multiple elements. Exemplarily, for each element, such as a sticker, its two-dimensional spatial information includes the upper-left coordinate (x1, y1), width w, and height h. Starting from the root node of the quadtree, by comparing the coordinates of the element with the coordinate ranges of the regions corresponding to each node, traverse the quadtree step by step downward until finding the leaf node to which the element belongs, and add the element to the element list corresponding to the leaf node. For example, if the center coordinate of the element is within the coordinate range of the region corresponding to a certain leaf node, it can be determined that the element belongs to that leaf node.

[0044] In this embodiment, according to the size range of the video frame, a root node is created and recursively divided into regions (nodes) at multiple levels to construct a suitable quadtree structure. According to the coordinate positions, sizes, and other attributes of each element in the video editor within the video frame, each element is accurately allocated to the corresponding quadtree node so that the elements can be orderly distributed in the quadtree, thereby efficiently organizing, managing, and retrieving multiple elements through the quadtree.

[0045] In an alternative embodiment, as Figure 5 shown, step S200 may include: Step S500, determining the maximum number of levels according to the device performance and / or a preset maximum number of elements.

[0046] Step S502, performing recursive division on the video frame until the maximum number of levels is reached; or Step S504, performing recursive division on the video frame until the number of elements in the newly divided region does not exceed the preset element capacity.

[0047] Exemplarily, the maximum number of levels can be preset according to device performance, the resolution of the video frame, the estimated maximum number of elements, etc., for example, set to N levels. The video frame is divided recursively until the maximum number of levels is reached. Alternatively, according to the number of elements in the video frame, a preset element capacity is set for the region. Recursive division is performed on the video frame. If the number of elements in the newly divided region is greater than the preset element capacity, division continues. If the number of elements in the newly divided region is less than or equal to the preset element capacity, division can be stopped. For example: the number of elements in the region corresponding to each leaf node does not exceed M, and M can be an empirical value).

[0048] In this embodiment, by adaptively dividing the quadtree according to preset rules and dynamically adjusting the quadtree structure, storage and calculation can be optimized, the collision detection effect can be improved, and the fluency of video editing can be enhanced.

[0049] During the actual video editing process, elements can change dynamically, such as addition, deletion, movement, size adjustment, etc. It is necessary to timely adjust the attribution relationship of the elements in the tree and dynamically update the quadtree so that the quadtree can always adapt to the changes of the elements and accurately manage multiple elements. The following combines Figure 12 to provide an exemplary solution.

[0050] In an alternative embodiment, as Figure 6 shown, the collision detection method may further include dynamically updating the quadtree, and the specific steps are as follows: Step S600, determine a first element, where the first element includes an element newly added to the video frame.

[0051] Step S602, starting from the root node, traverse the quadtree downward to determine a first leaf node and add the first element to the corresponding element list, where the coordinate range of the region corresponding to the first leaf node matches the two-dimensional spatial information of the first element.

[0052] Exemplarily, an element newly added to the video frame can be determined as the first element. Starting from the root node, by comparing the two-dimensional spatial information of the first element with the coordinate ranges of the regions corresponding to each node, traverse the quadtree downward step by step until a first leaf node suitable for the attribution of the first element is found, and the first element is added to the element list of the first leaf node.

[0053] In this embodiment, determining the in-tree attribution relationship of new elements in real time can provide accurate support for subsequent collision detection.

[0054] In practical applications, an element list has an element capacity, which represents the maximum number of elements that the corresponding area of a leaf node can accommodate. If the element capacity is exceeded, the splitting of the leaf node will be triggered, that is, the corresponding area will be further divided. Each split will increase the depth of the tree and affect the query efficiency. For this reason, the embodiments of the present application provide an exemplary solution for limiting the depth of the quadtree, reducing memory occupancy, and accelerating the query speed.

[0055] In an alternative embodiment, as Figure 7 shown, the steps of dynamically updating the quadtree may further include: Step S700, for a leaf node with a new element added to the element list, determine whether the element list has exceeded the element capacity.

[0056] Step S702, in the case where the element capacity has been exceeded, determine the adjacent nodes of the leaf node.

[0057] Step S704, based on the new element, determine whether the element list of the adjacent nodes will exceed the element capacity.

[0058] Step S706, in the case where it will not exceed the element capacity, adjust the new element to the element list of the adjacent node.

[0059] Step S708, in the case where it will exceed the element capacity: divide the corresponding area of the leaf node to obtain the areas of the next level; create new leaf nodes based on the areas of the next level, and adjust the new element to the element list of the new leaf nodes.

[0060] Exemplarily, if a new element is added to the element list of a leaf node, it is determined whether the element list has exceeded the element capacity at this time. If the element capacity has been exceeded, the adjacent nodes of the leaf node can be quickly found based on the quadtree. The adjacent nodes may include the sibling nodes of the leaf node and the sibling nodes of the parent node of the leaf node. Determine whether the element list of the adjacent nodes will exceed the element capacity if the new element is added. If it will not exceed the element capacity, the new element can be deleted from the list of the leaf node and added to the element list of the adjacent node. If it will exceed the element capacity, the splitting of the leaf node will be triggered, that is, the corresponding area will be divided into the areas of the next level. New leaf nodes are created based on the areas of the next level. Correspondingly, the original leaf node is converted into an internal node, and the elements in the element list of the original leaf node will be added to the element list of the new leaf nodes.

[0061] In this embodiment, the new element is preferentially adjusted to the adjacent node, unnecessary divisions are reduced, and the query efficiency is improved. The node splitting is triggered only when necessary, and the stability of the quadtree is improved.

[0062] In an alternative embodiment, as Figure 8 shown, the steps of dynamically updating the quadtree may further include: Step S800, determining a second element, where the second element includes elements deleted from the video frame.

[0063] Step S802, traversing the quadtree downward starting from the root node, determining a second leaf node and removing the second element from the corresponding element list, where the coordinate range of the area corresponding to the second leaf node matches the two-dimensional spatial information of the second element.

[0064] Exemplarily, an element deleted from the video frame can be determined as the second element. Starting from the root node, by comparing the two-dimensional spatial information of the second element with the coordinate ranges of the areas corresponding to each node, the quadtree is traversed downward step by step until the second leaf node where the second element is located is found, and the second element is removed from the element list of the second leaf node.

[0065] In this embodiment, by efficiently locating and removing the second element, the data consistency of the quadtree can be maintained, the query performance can be optimized, and accurate support can be provided for subsequent collision detection.

[0066] Considering the depth of the quadtree, it can be determined whether the leaf node after removing the element and its sibling nodes are merged after the elements are reduced to further optimize the quadtree. An exemplary solution is provided below.

[0067] In an alternative embodiment, as Figure 9 shown, the steps of dynamically updating the quadtree may further include: Step S900, for a leaf node with elements removed from its element list, obtaining the sum of the elements of the leaf node and its sibling nodes.

[0068] Step S902, in the case where the sum of the elements is less than or equal to the element capacity, merging the leaf node and its sibling nodes.

[0069] Exemplarily, for a leaf node with elements removed from its element list, the sum of the elements between the leaf node and its sibling nodes can be quickly obtained based on the quadtree. In the case where the sum of the elements is less than the element capacity, a node merging operation will be performed. For example, the elements in the element lists of the leaf node and its sibling nodes are adjusted to the element list of the parent node, the leaf node and its sibling nodes are deleted, and accordingly the parent node is converted from an internal node to a new leaf node.

[0070] In this embodiment, by merging nodes, the tree level can be reduced, the storage overhead can be reduced, the data structure can be made more compact, the query path can be shortened, and the speed of locating elements and collision detection can be effectively accelerated.

[0071] In an alternative embodiment, as Figure 10 shown, the steps of dynamically updating the quadtree may further include: Step S1000, determining a third element, where the third element includes the element whose two-dimensional spatial information has changed, and the change is obtained by moving the element or adjusting the size of the element.

[0072] Step S1002, traversing the quadtree downward starting from the root node, determining a third leaf node, and removing the third element from the corresponding element list, where the coordinate range of the area corresponding to the third leaf node matches the two-dimensional spatial information of the third element before the change.

[0073] Step S1004, traversing the quadtree downward starting from the root node, determining a fourth leaf node, and adding the third element to the corresponding element list, where the coordinate range of the area corresponding to the fourth leaf node matches the two-dimensional spatial information of the third element after the change.

[0074] Exemplarily, an element that moves or changes size in the video frame and causes the two-dimensional spatial information to change can be determined as the third element. Starting from the root node, by comparing the two-dimensional spatial information of the third element before the change with the coordinate ranges of the areas corresponding to each node, traverse the quadtree step by step downward until the third leaf node where the third element was located before the change is determined, and remove the third element from the element list of the third leaf node. Starting from the root node, by comparing the two-dimensional spatial information of the third element after the change with the coordinate ranges of the areas corresponding to each node, traverse the quadtree step by step downward until the fourth leaf node suitable for the attribution of the third element after the change is found, and add the third element to the element list of the fourth leaf node.

[0075] In this embodiment, the attribution node of the element is updated efficiently, ensuring the data consistency of the quadtree, and improving the accuracy and real-time performance of querying and collision detection.

[0076] Adjusting the attribution node of the third element requires removing the third element from the element list of the original attribution node and adding the third element to the element list of the current attribution node, which may involve node splitting, node merging, or adjusting the attribution node of the element. Therefore, necessary updates to the relevant nodes and structural adjustments to the quadtree can also be made according to the actual situation.

[0077] The above-mentioned multiple embodiments exemplarily introduce how to construct and dynamically update the quadtree, providing accurate support for subsequent collision detection. Next, the collision detection process will be exemplarily introduced.

[0078] Step S102, determine a target node and adjacent nodes according to the quadtree, where the target node represents the area where the target element is located, and the adjacent nodes include the sibling nodes of the target node and the sibling nodes of the parent node of the target node.

[0079] The target element can be any element in the video frame. Exemplarily, starting from the root node, by comparing the two-dimensional spatial information of the element and the coordinate ranges of the corresponding areas of each node, the node where the element is located, i.e., the target node, can be quickly located. According to the tree structure, the adjacent nodes can be quickly determined. The adjacent nodes can include the sibling nodes of the target node and the sibling nodes of the parent node of the target node. As Figure 4 shown, the adjacent nodes of target nodes 1-4 can include 3 nodes, namely 1-1, 1-2, and 1-3 (the sibling nodes of the target node), and can also include 12 nodes, namely 2-1, 2-2... 4-4 (the nodes that can accommodate elements under the sibling nodes of the parent node of the target node). The areas corresponding to the adjacent nodes are the relevant areas that may affect the collision judgment.

[0080] In this embodiment, based on the quadtree, the area where the target element is located and its adjacent areas can be quickly located, which can improve the efficiency and accuracy of collision detection.

[0081] In some embodiments, the adjacent nodes can be further optimized. For example, considering the coordinate ranges of the corresponding areas of the nodes, select the leaf nodes (1-2, 1-3, 2-3, 3-2) that are directly adjacent to the target node (such as 1-4) as the adjacent nodes to reduce unnecessary collision detection calculations. Or consider the leaf nodes that enclose the target node as the adjacent nodes (9 nodes such as 1-1, 1-2, 1-3, 2-1, 2-3, etc.) to balance the accuracy and efficiency of collision detection.

[0082] Step S104 , determine adjacent elements according to the target node and the adjacent nodes.

[0083] Exemplarily, the remaining elements in the target node except the target element, and the elements in the element list of each adjacent node can be determined as adjacent elements.

[0084] Step S106 , compare the target element with the adjacent elements to obtain a detection result, where the detection result is used to indicate whether a collision occurs between the target element and the adjacent elements.

[0085] Exemplarily, for the target element and the adjacent element, assume that the coordinates of the target element A are (x1, y1, w1, h1), and the coordinates of the adjacent element B are (x2, y2, w2, h2), where the coordinates represent the upper left corner coordinates and the width and height. By determining whether the condition (x1 <= x2 + w2) && (x2 <= x1 + w1) is satisfied, it can be determined whether they overlap in the x-axis direction. If there is an overlap in the x-axis direction, then determine whether the condition (y1 <= y2 + h2) && (y2 <= y1 + h1) is satisfied to determine whether there is an overlap in the y-axis direction. Only when both the x-axis and y-axis directions satisfy the overlap condition can it be determined that a collision occurs between the target element and the adjacent element. If any condition is not satisfied, no collision occurs between the target element and the adjacent element.

[0086] In this embodiment, through the optimized coordinate calculation and boundary judgment logic, the collision situation between elements is accurately judged, ensuring the accuracy of the detection result, reducing misjudgment or missed judgment, and ensuring the rationality and aesthetics of the element layout in the video frame.

[0087] Embodiment 2 Figure 13 Schematically shows a block diagram of a collision detection device according to Embodiment 2 of the present application. The device can be divided into one or more program modules. One or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiments of the present application. The program modules referred to in the embodiments of the present application refer to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. As Figure 13 shown, the device 1000 may include: a first determination module 1100, a second determination module 1200, a third determination module 1300, and a collision detection module 1400, where: The first determination module 1100 is configured to determine a target element among multiple elements in a video frame. The video frame is associated with a pre-constructed quadtree, and the nodes in the quadtree represent regions in the video frame. The quadtree is used to represent the hierarchical relationship between the regions in the video frame and the regions where each of the elements is located; The second determination module 1200 is configured to determine a target node and an adjacent node according to the quadtree. The target node represents the region where the target element is located, and the adjacent node includes the sibling nodes of the target node and the sibling nodes of the parent node of the target node; The third determination module 1300 is configured to determine adjacent elements according to the target node and the adjacent node; A collision detection module 1400 is configured to compare the target element and the adjacent elements to obtain a detection result, which is used to indicate whether a collision occurs between the target element and the adjacent elements.

[0088] As an alternative embodiment, each element has two-dimensional spatial information, which is used to describe the position and size of the element in the video frame; correspondingly, the quadtree is constructed through the following operations: Performing recursive partitioning on the video frame according to a preset rule to obtain multiple regions at multiple levels, and forming a quadtree according to the hierarchical relationship between the multiple regions, where each region has a coordinate range; wherein, the quadtree includes a root node, multiple internal nodes, and multiple leaf nodes, the root node corresponds to the video frame, the internal nodes correspond to regions with a next level, the leaf nodes correspond to regions without a next level, the regions without a next level are used to accommodate the elements, and the leaf nodes are associated with an element list; Traversing the quadtree downward starting from the root node, and allocating the multiple elements to the element lists of the multiple leaf nodes; Wherein, the coordinate range of the region corresponding to the leaf node matches the two-dimensional spatial information of the elements allocated to the associated element list.

[0089] As an alternative embodiment, performing recursive partitioning on the video frame according to a preset rule includes: Determining the maximum number of levels according to the device performance and / or a preset maximum number of elements; Performing recursive partitioning on the video frame until the maximum number of levels is reached; or Performing recursive partitioning on the video frame until the number of elements in the newly partitioned region does not exceed a preset element capacity.

[0090] As an alternative embodiment, the apparatus 1000 is further configured to: Determine a first element, where the first element includes an element newly added to the video frame; Traversing the quadtree downward starting from the root node, determining a first leaf node and adding the first element to the corresponding element list, where the coordinate range of the region corresponding to the first leaf node matches the two-dimensional spatial information of the first element.

[0091] As an alternative embodiment, the apparatus 1000 is further configured to: Determine a second element, where the second element includes an element deleted from the video frame; Traverse the quadtree downward starting from the root node, determine the second leaf node, and remove the second element from the corresponding element list. The coordinate range of the area corresponding to the second leaf node matches the two-dimensional spatial information of the second element.

[0092] As an optional embodiment, the apparatus 1000 is further configured to: Determine a third element, where the third element includes the element whose two-dimensional spatial information has changed, and the change is obtained by moving the element or adjusting the size of the element; Traverse the quadtree downward starting from the root node, determine the third leaf node, and remove the third element from the corresponding element list. The coordinate range of the area corresponding to the third leaf node matches the two-dimensional spatial information of the third element before the change; Traverse the quadtree downward starting from the root node, determine the fourth leaf node, and add the third element to the corresponding element list. The coordinate range of the area corresponding to the fourth leaf node matches the two-dimensional spatial information of the third element after the change.

[0093] As an optional embodiment, the element list has an element capacity, and the apparatus 1000 is further configured to: For a leaf node where a new element is added to the element list, determine whether the element list has exceeded the element capacity; In the case where it has exceeded the element capacity, determine the adjacent nodes of the leaf node; Based on the new element, determine whether the element list of the adjacent node will exceed the element capacity; In the case where it will not exceed the element capacity, adjust the new element to the element list of the adjacent node; In the case where it will exceed the element capacity: divide the corresponding area of the leaf node to obtain areas at the next level; create new leaf nodes based on the areas at the next level, and adjust the new element to the element list of the new leaf nodes.

[0094] As an optional embodiment, the element list has an element capacity, and the apparatus 1000 is further configured to: For a leaf node where an element is removed from the element list, obtain the sum of the elements of the leaf node and its sibling nodes; In the case where the sum of the elements is less than or equal to the element capacity, merge the leaf node and its sibling nodes.

[0095] Embodiment III Figure 14FIG. schematically shows a hardware architecture diagram of a computer device 10000 suitable for implementing a collision detection method according to Embodiment 3 of the present application. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle-mounted terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server or a server cluster composed of multiple servers), etc. As Figure 14 shown, the computer device 10000 includes, but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can be communicatively linked to each other through a system bus. Among them: The memory 10010 includes at least one type of computer-readable storage medium. The readable storage medium includes flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as the hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc., equipped on the computer device 10000. Of course, the memory 10010 may also include both an internal storage module and an external storage device of the computer device 10000. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed on the computer device 10000, such as the program code of the collision detection method. In addition, the memory 10010 may also be used to temporarily store various data that have been output or will be output.

[0096] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.

[0097] The network interface 10030 may include a wireless network interface or a wired network interface, which is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an enterprise intranet (Intranet), the Internet, the Global System of Mobile communication (GSM for short), Wideband Code Division Multiple Access (WCDMA for short), 4G network, 5G network, Bluetooth, Wi-Fi, etc.

[0098] It should be noted that Figure 14 Only the computer device with components 10010 - 10030 is shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.

[0099] In this embodiment, the collision detection method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as the processor 10020) to complete the embodiments of this application.

[0100] Embodiment 4 The embodiments of this application also provide a computer - readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the collision detection method in the embodiments are implemented.

[0101] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc. equipped on the computer device. Of course, the computer-readable storage medium may also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer-readable storage medium is generally used to store the operating system installed on the computer device and various application software, such as the program code of the collision detection method in the embodiment. In addition, the computer-readable storage medium may also be used to temporarily store various data that have been output or will be output.

[0102] Embodiment 5 The embodiment of the present application further provides a computer program product, including a computer program, which when executed by a processor implements the method in the above embodiment.

[0103] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the embodiments of the present application can be implemented by a general computer device. They can be concentrated on a single computer device or distributed on a network composed of multiple computer devices. Optionally, they can be implemented by program codes executable by the computer device, so that they can be stored in a storage device and executed by the computer device. And in some cases, the steps shown or described can be executed in a different order from here, or they can be separately made into individual integrated circuit modules, or multiple modules or steps among them can be made into a single integrated circuit module to implement. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.

[0104] It should be noted that the above are only the preferred embodiments of the present application, and do not limit the patent protection scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are equally included in the patent protection scope of the present application.

Claims

1. A collision detection method, characterized in that The method includes: Determine a target element among multiple elements in a video frame. The video frame is associated with a pre-constructed quadtree, where nodes in the quadtree represent regions in the video frame. The quadtree is used to represent the hierarchical relationship between regions in the video frame and the regions where each of the elements is located; According to the quadtree, determine a target node and adjacent nodes. The target node represents the region where the target element is located, and the adjacent nodes include sibling nodes of the target node and sibling nodes of the parent node of the target node; Determine adjacent elements according to the target node and the adjacent nodes; Compare the target element with the adjacent elements to obtain a detection result, where the detection result is used to indicate whether a collision occurs between the target element and the adjacent elements.

2. The method according to claim 1, wherein Each element has two-dimensional spatial information, which is used to describe the position and size of the element in the video frame; correspondingly, the quadtree is constructed through the following operations: Perform recursive partitioning on the video frame according to preset rules to obtain multiple regions at multiple levels, and form a quadtree according to the hierarchical relationship between the multiple regions. Each region has a coordinate range; where the quadtree includes a root node, multiple internal nodes, and multiple leaf nodes. The root node corresponds to the video frame, the internal nodes correspond to regions with a next level, the leaf nodes correspond to regions without a next level, the regions without a next level are used to accommodate the elements, and the leaf nodes are associated with element lists; Traverse the quadtree downward starting from the root node, and assign the multiple elements to the element lists of the multiple leaf nodes; Among them, the coordinate range of the region corresponding to the leaf node matches the two-dimensional spatial information of the elements assigned to the associated element list.

3. The method according to claim 2, characterized in that, Performing recursive partitioning on the video frame according to preset rules includes: Determine the maximum number of levels according to device performance and / or a preset maximum number of elements; Perform recursive partitioning on the video frame until the maximum number of levels is reached; Or Perform recursive partitioning on the video frame until the number of elements in the newly partitioned region does not exceed the preset element capacity.

4. The method according to claim 2, wherein The method further includes: Determine a first element, where the first element includes an element newly added to the video frame; Traverse the quadtree downward starting from the root node, determine a first leaf node and add the first element to the corresponding element list, where the coordinate range of the region corresponding to the first leaf node matches the two-dimensional spatial information of the first element.

5. The method according to claim 2, wherein The method further includes: Determine a second element, where the second element includes an element deleted from the video frame; Traverse the quadtree downward starting from the root node, determine a second leaf node and remove the second element from the corresponding element list, where the coordinate range of the region corresponding to the second leaf node matches the two-dimensional spatial information of the second element.

6. The method according to claim 2, wherein The method further includes: Determine a third element, where the third element includes the element with changed two-dimensional spatial information, and the change is obtained by moving the element or adjusting the size of the element; Traverse the quadtree downward starting from the root node, determine a third leaf node, and remove the third element from the corresponding element list. The coordinate range of the area corresponding to the third leaf node matches the two-dimensional spatial information of the third element before the change; Traverse the quadtree downward starting from the root node, determine a fourth leaf node, and add the third element to the corresponding element list. The coordinate range of the area corresponding to the fourth leaf node matches the two-dimensional spatial information of the third element after the change.

7. The method according to claim 2, wherein The element list has an element capacity; the method further includes: For a leaf node with a new element added to the element list, determine whether the element list has exceeded the element capacity; In the case where it has exceeded the element capacity, determine the adjacent nodes of the leaf node; Based on the new element, determine whether the element list of the adjacent nodes will exceed the element capacity; In the case where it will not exceed the element capacity, adjust the new element to the element list of the adjacent node; In the case where it will exceed the element capacity: divide the corresponding area of the leaf node to obtain areas at the next level; create new leaf nodes based on the areas at the next level, and adjust the new element to the element list of the new leaf nodes.

8. The method according to claim 2, wherein The element list has an element capacity, the method further includes: For a leaf node with an element removed from the element list, obtain the sum of the elements of the leaf node and its sibling nodes; In the case where the sum of the elements is less than or equal to the element capacity, merge the leaf node and its sibling nodes.

9. A collision detection device, characterized in that, The apparatus includes: A first determination module, configured to determine a target element among multiple elements in a video frame. The video frame is associated with a pre-constructed quadtree, where the nodes in the quadtree represent areas in the video frame, and the quadtree is used to represent the hierarchical relationship between the areas in the video frame and the areas where each of the elements is located; A second determination module, configured to determine a target node and adjacent nodes according to the quadtree. The target node represents the area where the target element is located, and the adjacent nodes include the sibling nodes of the target node and the sibling nodes of the parent node of the target node; A third determination module, configured to determine adjacent elements according to the target node and the adjacent nodes; A collision detection module, configured to compare the target element and the adjacent elements to obtain a detection result, where the detection result is used to indicate whether a collision occurs between the target element and the adjacent elements.

10. A computer device, characterized in that, Includes: 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 method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 8 is implemented.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, the steps of the method according to claims 1 to 8 are implemented.