A method and apparatus for automatic 3D camera localization based on scene size adaptation
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-08-14
AI Technical Summary
[0003]该功能仅复制当前视图角度,完全依赖于用户手动调整视图,对于不同尺寸的场景,用户需要凭借经验和反复尝试来调整视图,以确保整个场景或目标物体在摄像机视野内,无法自动适配;由于依赖人眼判断,难以保证场景边界恰好完整地位于摄像机视锥体内,容易出现裁剪或构图不饱满的问题,对于需要多个角度且视角一致的项目,难以通过手动操作实现精确复制;另外,在处理大型或复杂场景时,用户需要为每一个需要的角度重复进行“调整视角->对齐摄像机->检查效果->微调”的循环操作,过程繁琐,费时费力,工作效率低
[0032]本发明至少具有如下有益效果:本发明能够自动分析三维场景的尺寸,并基于该尺寸和用户指定的俯仰角来确定摄像机的位置,因而可以适配不同尺寸的场景,适用范围广;同时,最终的摄像机位置是系统通过计算得到的,不依赖于人的主观判断,结果更加准确,这也省却了用户反复调试的过程,有效提升了工作效率。
Smart Images

Figure CN121616641B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of 3D modeling software technology, and in particular to a method and apparatus for automatic positioning of a 3D camera based on scene size adaptation. Background Technology
[0002] In the field of 3D modeling, the camera is a core tool for defining the viewpoint, composition, and narrative focus of the final rendered image. To quickly set up the camera, mainstream 3D software (such as Blender and 3ds Max) generally provides a function called "Align Camera to Current View." The basic workflow of this function is as follows: the user first adjusts the 3D view window to a desired viewing angle using mouse operations (such as rotating, panning, and zooming the view) or predefined view switches; then, the user executes the "Align Camera to Current View" command, and the software automatically sets the spatial position and rotation angle of the selected active camera in the current scene to be completely consistent with the viewing parameters of the current view. This function enables the rapid creation of a corresponding camera from any viewpoint, becoming a fundamental and frequently used operation in 3D content creation.
[0003] This function only copies the current view angle and relies entirely on the user to manually adjust the view. For scenes of different sizes, users need to rely on experience and repeated attempts to adjust the view to ensure that the entire scene or target object is within the camera's field of view. It cannot be automatically adapted. Because it relies on human judgment, it is difficult to ensure that the scene boundary is exactly and completely within the camera's field of view, which can easily lead to cropping or incomplete composition. For projects that require multiple angles with consistent perspectives, it is difficult to achieve accurate copying through manual operation. In addition, when dealing with large or complex scenes, users need to repeatedly perform the cycle of "adjusting the view -> aligning the camera -> checking the effect -> fine-tuning" for each required angle. The process is tedious, time-consuming, laborious, and inefficient. Summary of the Invention
[0004] This invention provides a method and apparatus for automatic positioning of a 3D camera based on scene size adaptation, which can adapt to scenes of different sizes, automatically and accurately locate the optimal camera position, and improve work efficiency.
[0005] To solve the above problems, the present invention adopts the following technical solution:
[0006] According to a first aspect of the present invention, embodiments of the present invention provide an automatic positioning method for a 3D camera based on scene size adaptation, comprising the following steps:
[0007] Retrieve the object specified by the user in the 3D scene;
[0008] Read the vertex data of the axis-aligned bounding box of the object specified by the user and convert it to the world coordinate system;
[0009] Traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box;
[0010] Receive the pitch angle α selected or set by the user;
[0011] Calculate the field of view angle b of the camera in the horizontal direction, and calculate the base distance D1 required for the camera to be directly facing the center of the three-dimensional scene with the field of view angle;
[0012] When the camera is shooting at the aforementioned pitch angle, distance compensation is performed based on the aforementioned base distance in order to see the complete horizontal scene;
[0013] Based on the compensated distance D2 and pitch angle a, determine the camera's displacement S1 on the Y-axis and displacement S2 on the Z-axis;
[0014] Based on the displacement, a new camera is created in three-dimensional space, and the angle of the new camera is set to face the center point of the scene.
[0015] In some embodiments, the steps of calculating the width and length of the scene specifically include: finding the maximum and minimum values of the vertices on the X-axis and Y-axis respectively, subtracting the maximum and minimum values on the X-axis to obtain the length of the scene, and subtracting the maximum and minimum values on the Y-axis to obtain the width of the scene.
[0016] In some embodiments, the base distance D1 = (diagonal length of the 3D scene / 2) / tan(b / 2).
[0017] In some embodiments, the compensated distance D2 = [D1 / cos(a)] * K, where K is a preset safety factor.
[0018] In some embodiments, the displacement of the camera on the Y-axis is S1 = -D2*cos(a), and the displacement of the camera on the Z-axis is S2 = D2*sin(a).
[0019] According to a second aspect of the present invention, embodiments of the present invention provide an automatic positioning device for a three-dimensional camera based on scene size adaptation, comprising:
[0020] The object acquisition module is used to acquire objects specified by the user in the 3D scene;
[0021] The data conversion module is used to read the vertex data of the axis-aligned bounding box of the object specified by the user and convert it to the world coordinate system.
[0022] The length calculation module is used to traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box.
[0023] Angle receiving module, used to receive the pitch angle α selected or set by the user;
[0024] The distance calculation module is used to calculate the field of view angle b of the camera in the horizontal direction, and to calculate the basic distance D1 required for the camera when the field of view angle is directly facing the center of the three-dimensional scene;
[0025] The distance compensation module is used to perform distance compensation based on the base distance in order to see the complete horizontal scene when the camera is shooting at the pitch angle.
[0026] The displacement calculation module is used to determine the camera's displacement S1 on the Y-axis and displacement S2 on the Z-axis based on the compensated distance D2 and pitch angle a.
[0027] A camera positioning module is used to create a new camera in three-dimensional space based on the displacement, and the angle of the new camera is set to face the center point of the scene.
[0028] In some embodiments, the length calculation module is used to find the maximum and minimum values of the vertices on the X-axis and Y-axis respectively, and to obtain the length of the scene by subtracting the maximum and minimum values on the X-axis, and to obtain the width of the scene by subtracting the maximum and minimum values on the Y-axis.
[0029] In some embodiments, the base distance D1 = (diagonal length of the 3D scene / 2) / tan(b / 2).
[0030] In some embodiments, the compensated distance D2 = [D1 / cos(a)] * K, where K is a preset safety factor.
[0031] In some embodiments, the displacement of the camera on the Y-axis is S1 = -D2*cos(a), and the displacement of the camera on the Z-axis is S2 = D2*sin(a).
[0032] The present invention has at least the following beneficial effects: The present invention can automatically analyze the size of a three-dimensional scene and determine the position of the camera based on the size and the pitch angle specified by the user, thus it can adapt to scenes of different sizes and has a wide range of applications; at the same time, the final camera position is obtained by the system through calculation, without relying on human subjective judgment, and the result is more accurate, which also saves users from the process of repeated debugging and effectively improves work efficiency. Attached Figure Description
[0033] Figure 1This is a flowchart illustrating an embodiment of the automatic positioning method for a 3D camera based on scene size adaptation according to the present invention.
[0034] Figure 2 This is a schematic diagram of the structure of an automatic positioning device for a 3D camera based on scene size adaptation according to an embodiment of the present invention. Detailed Implementation
[0035] The present invention is provided below with reference to the accompanying drawings to aid in a full understanding of the various embodiments of the invention as defined by the claims and their equivalents. The description includes various specific details to aid understanding, but these details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the various embodiments described herein without departing from the scope and spirit of the invention.
[0036] In the description of this invention, the orientation descriptions, such as up, down, front, back, left, right, etc., are based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.
[0037] It should be understood that when one element (e.g., the first element) is “connected” to another element (e.g., the second element), the element may be directly connected to the other element, or there may be an intermediary element (e.g., the third element) between the element and the other element.
[0038] Embodiments of the present invention provide a method for automatic localization of a 3D camera based on scene size adaptation, such as... Figure 1 As shown, it includes the following steps:
[0039] S100: Get the object specified by the user in the 3D scene.
[0040] After a user opens the 3D modeling software, the 3D scene is presented on the user's display interface at the initial camera position. The 3D scene can include one or more objects, which can be the floor representing the entire scene area or objects with boundaries. Users can directly select the model of an object in the 3D scene, or select the corresponding object from the model tree in the sidebar.
[0041] S200: Reads the vertex data of the axis-aligned bounding box of the user-specified object and converts it to the world coordinate system.
[0042] Each object in the 3D scene has pre-stored vertex data with axis-aligned bounding boxes, which the system can directly read from storage. Since this data is not stored in world coordinates, it needs to be converted to world coordinates for subsequent calculations.
[0043] S300: Traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box.
[0044] The system iterates through all vertices and calculates the width and length of the scene based on them. Only by knowing the width and length of the 3D scene can the camera's bounding box be set to ensure that the entire 3D scene is placed within the camera's field of view. The diagonal length is a key parameter to ensure that the scene is placed within the field of view without any omissions.
[0045] S400: Receives the pitch angle α selected or set by the user.
[0046] The system offers multiple pitch angles (α) for users to choose from, such as "Top View" and "20-degree Top View," which users can directly select. Additionally, the system provides a customization function, allowing users to adjust the angle data and thus customize the pitch angle. This provides users with diverse options, greater flexibility, and meets their varied needs.
[0047] S500: Calculate the field of view angle b of the camera in the horizontal direction, and calculate the base distance D1 required for the camera to be directly facing the center of the three-dimensional scene with the field of view angle.
[0048] The system can determine the horizontal field of view angle b of the camera based on the camera's focal length. The specific determination process is existing technology and is a built-in function of the system, so it will not be described in detail here. The calculation of the base distance D1 aims to ensure that the diagonal of the scene bounding box can be completely placed in the field of view.
[0049] S600: When the camera is shooting at the stated pitch angle, distance compensation is performed based on the stated base distance in order to see the complete horizontal scene.
[0050] Because cameras have a pitch angle, changes in the pitch angle can cause a deviation between the actual distance and the baseline distance. In order for the camera's perspective to fully see the scene, the original baseline distance needs to be compensated to obtain the true and correct distance.
[0051] S700: Based on the compensated distance D2 and pitch angle a, determine the camera's displacement S1 on the Y-axis and displacement S2 on the Z-axis.
[0052] The displacement is calculated based on the compensated distance D2, which is the displacement from the initial camera position to the target position. The ideal target position can display the entire 3D scene completely within the field of view.
[0053] S800: Based on the displacement, create a new camera in three-dimensional space, with the angle of the new camera set to face the center point of the scene.
[0054] Starting from the initial camera position, move the camera according to the displacement amount mentioned above. The final position is the ideal target position. Create a new camera at this target position. The angle of the new camera is set to face the center point of the scene. Of course, internal parameters such as focal length can also be set at the same time. In this way, the entire 3D scene can be fully displayed in the field of view of the new camera.
[0055] Therefore, this embodiment can automatically analyze the size of the 3D scene and determine the position of the camera based on the size and the pitch angle specified by the user. Thus, it can adapt to scenes of different sizes and has a wide range of applications. At the same time, the final camera position is obtained by the system through calculation, without relying on human subjective judgment, and the result is more accurate. This also saves users from repeated debugging and effectively improves work efficiency.
[0056] In some embodiments, the step S300 of calculating the width and length of the scene specifically includes: finding the maximum and minimum values of the vertices on the X-axis and Y-axis respectively, subtracting the maximum and minimum values on the X-axis to obtain the length of the scene, and subtracting the maximum and minimum values on the Y-axis to obtain the width of the scene.
[0057] In the world coordinate system, these vertices must have maximum and minimum values on the X and Y axes. Subtracting the minimum value on the X-axis from the maximum value on the X-axis gives the length of the scene, and subtracting the minimum value on the Y-axis from the maximum value on the Y-axis gives the width of the scene.
[0058] In some embodiments, the diagonal length of the bounding box in step S300 can be obtained according to the Pythagorean theorem, that is, the square of the diagonal length of the bounding box is equal to the sum of the square of the length of the bounding box and the square of the width of the bounding box. The length and width of the bounding box are preset data of the system and are known, so the diagonal length of the bounding box can be calculated accordingly.
[0059] In some embodiments, the base distance D1 in step S500 is calculated as (diagonal length of the 3D scene / 2) / tan(b / 2), meaning the base distance D1 equals half the diagonal length of the 3D scene divided by the tangent of half the field of view angle. The diagonal length of the 3D scene can also be obtained using the Pythagorean theorem, where the square of the diagonal length of the 3D scene equals the sum of the square of the scene's length and the square of its width. Since the scene's length and width have already been calculated, the diagonal length of the 3D scene can be calculated accordingly.
[0060] In some embodiments, in step S600, the compensated distance D2 = [D1 / cos(a)]*K, where K is a preset safety factor. That is, the compensated distance D2 is equal to the base distance divided by the cosine of the pitch angle, and then multiplied by a safety factor, which is determined by those skilled in the art based on experience, for example, it can be 1.1.
[0061] In some embodiments, in step S700, the displacement S1 of the camera on the Y-axis is equal to -D2*cos(a), and the displacement S1 of the camera on the Y-axis is equal to the negative value of the product of the compensated distance and the cosine of the pitch angle.
[0062] The camera's displacement on the Z-axis, S2, is equal to D2*sin(a), which is the product of the compensated distance and the sine of the pitch angle. In this embodiment, the camera's displacement on the Y and Z axes is decomposed using trigonometric functions based on the compensated distance and pitch angle. The camera's coordinates on the X-axis are usually aligned with the scene center or slightly offset to optimize the composition; therefore, it is not necessary to calculate the camera's displacement on the X-axis.
[0063] According to a second aspect of the present invention, embodiments of the present invention provide an automatic positioning device for a three-dimensional camera based on scene size adaptation, such as... Figure 2 As shown, it includes:
[0064] The object acquisition module 100 is used to acquire objects specified by the user in the 3D scene;
[0065] The data conversion module 200 is used to read the vertex data of the axis-aligned bounding box of the object specified by the user and convert it to the world coordinate system.
[0066] The length calculation module 300 is used to traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box.
[0067] Angle receiving module 400 is used to receive the pitch angle α selected or set by the user;
[0068] The distance calculation module 500 is used to calculate the field of view angle b of the camera in the horizontal direction, and to calculate the basic distance D1 required by the camera when the field of view angle is directly facing the center of the three-dimensional scene;
[0069] The distance compensation module 600 is used to perform distance compensation based on the base distance in order to see the complete horizontal scene when the camera is shooting at the pitch angle.
[0070] The displacement calculation module 700 is used to determine the displacement S1 of the camera on the Y-axis and the displacement S2 on the Z-axis based on the compensated distance D2 and the pitch angle a.
[0071] The camera positioning module 800 is used to create a new camera in three-dimensional space based on the displacement, and the angle of the new camera is set to face the center point of the scene.
[0072] In some embodiments, the length calculation module 300 is used to find the maximum and minimum values of the vertices on the X-axis and Y-axis respectively, and to obtain the length of the scene by subtracting the maximum and minimum values on the X-axis, and to obtain the width of the scene by subtracting the maximum and minimum values on the Y-axis.
[0073] In some embodiments, the base distance D1 = (diagonal length of the 3D scene / 2) / tan(b / 2).
[0074] In some embodiments, the compensated distance D2 = [D1 / cos(a)] * K, where K is a preset safety factor.
[0075] In some embodiments, the displacement of the camera on the Y-axis is S1 = -D2*cos(a), and the displacement of the camera on the Z-axis is S2 = D2*sin(a).
[0076] Since the above-described embodiments of the automatic positioning device for a 3D camera based on scene size adaptation are embodiments corresponding to the above-described method class, specific descriptions of the embodiments of the automatic positioning device for a 3D camera based on scene size adaptation can be found in the above embodiments, and will not be repeated here.
[0077] The terms and words used in the foregoing description and claims are not limited to their literal meaning, but are merely used by the applicant to enable a clear and consistent understanding of the invention. Therefore, those skilled in the art will understand that the foregoing description of various embodiments of the invention is illustrative only and not intended to limit the invention as defined by the appended claims and their equivalents.
Claims
1. A method for automatic positioning of a 3D camera based on scene size adaptation, characterized in that, Includes the following steps: Retrieve the object specified by the user in the 3D scene; Read the vertex data of the axis-aligned bounding box of the object specified by the user and convert it to the world coordinate system; Traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box; Receive the pitch angle α selected or set by the user; Calculate the field of view angle b of the camera in the horizontal direction, and calculate the base distance D1 required for the camera to be directly facing the center of the three-dimensional scene with the field of view angle; When the camera is shooting at the aforementioned pitch angle, distance compensation is performed based on the aforementioned base distance in order to see the complete horizontal scene; Based on the compensated distance D2 and pitch angle a, determine the camera's displacement S1 on the Y-axis and displacement S2 on the Z-axis; Based on the displacement, a new camera is created in three-dimensional space, and the angle of the new camera is set to face the center point of the scene; The base distance D1 is calculated as (diagonal length of the 3D scene / 2) / tan(b / 2).
2. The automatic positioning method for a 3D camera based on scene size adaptation according to claim 1, characterized in that, The steps for calculating the width and length of the scene specifically include: finding the maximum and minimum values of the vertices on the X-axis and Y-axis respectively; subtracting the maximum and minimum values on the X-axis to obtain the length of the scene; and subtracting the maximum and minimum values on the Y-axis to obtain the width of the scene.
3. The automatic positioning method for a 3D camera based on scene size adaptation according to claim 1, characterized in that, The compensated distance D2 = [D1 / cos(a)]*K, where K is a preset safety factor.
4. The automatic positioning method for a 3D camera based on scene size adaptation according to claim 1, characterized in that, The displacement of the camera on the Y-axis is S1 = -D2*cos(a), and the displacement of the camera on the Z-axis is S2 = D2*sin(a).
5. A three-dimensional camera automatic positioning device based on scene size adaptation, characterized in that, include: The object acquisition module is used to acquire objects specified by the user in the 3D scene; The data conversion module is used to read the vertex data of the axis-aligned bounding box of the object specified by the user and convert it to the world coordinate system. The length calculation module is used to traverse all vertices and calculate the width and length of the scene, as well as the diagonal length of the bounding box. Angle receiving module, used to receive the pitch angle α selected or set by the user; The distance calculation module is used to calculate the field of view angle b of the camera in the horizontal direction, and to calculate the basic distance D1 required for the camera when the field of view angle is directly facing the center of the three-dimensional scene; The distance compensation module is used to perform distance compensation based on the base distance in order to see the complete horizontal scene when the camera is shooting at the pitch angle. The displacement calculation module is used to determine the camera's displacement S1 on the Y-axis and displacement S2 on the Z-axis based on the compensated distance D2 and pitch angle a. A camera positioning module is used to create a new camera in three-dimensional space based on the displacement amount, and the angle of the new camera is set to face the center point of the scene; The base distance D1 is calculated as (diagonal length of the 3D scene / 2) / tan(b / 2).
6. The automatic positioning device for a 3D camera based on scene size adaptation according to claim 5, characterized in that, The length calculation module is used to find the maximum and minimum values of the vertices on the X-axis and Y-axis respectively. The difference between the maximum and minimum values on the X-axis is used to obtain the length of the scene, and the difference between the maximum and minimum values on the Y-axis is used to obtain the width of the scene.
7. The automatic positioning device for a 3D camera based on scene size adaptation according to claim 5, characterized in that, The compensated distance D2 = [D1 / cos(a)]*K, where K is a preset safety factor.
8. The automatic positioning device for a 3D camera based on scene size adaptation according to claim 5, characterized in that, The displacement of the camera on the Y-axis is S1 = -D2*cos(a), and the displacement of the camera on the Z-axis is S2 = D2*sin(a).
Citation Information
Patent Citations
Generation method of optimal monitoring position according to monitoring target position
CN105635698A
Camera attitude parameter verification method and device, storage medium and terminal
CN117544759A