Focusing method, device, equipment and medium based on three-dimensional model
By calculating the center point of the enclosing box and the radius of the circumferential ball of the three-dimensional three-dimensional model, combining the preset magnification control amount and unit vector, the camera position and focus are automatically adjusted, and the camera cannot be positioned and cropped in the prior art is solved, which improves the user experience.
Patent Information
- Application Number
- CN202111437258.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-26
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2041-11-26
AI Technical Summary
The prior art cannot position the camera to a suitable position according to the size and position of the three-dimensional stereo model, resulting in cropping when the camera rotates around the three-dimensional stereo model, and users cannot fully view the three-dimensional stereo model, resulting in poor user experience.
By calculating the center point coordinates of the enclosing box and the radius of the circumferential ball of the three-dimensional three-dimensional model, combining the preset magnification control amount and unit vector, the adjusted final coordinates of the camera are calculated, and the camera is moved to the final position within the preset time, and the camera focus is set as the center point of the model.
The camera is automatically positioned to the appropriate position, avoiding the trimming of the three-dimensional model, allowing users to fully view the model, and improving the user's visual experience.
Smart Images

Figure CN114332352B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of three-dimensional stereo model visualization, and in particular to a focusing method, device, equipment and medium based on a three-dimensional stereo model. Background Art
[0002] With the development of science and technology, WebGL (Web Graphics Library, also known as 3D drawing protocol) technology continues to mature and improve, and the demand for three-dimensional visualization continues to increase. It is an urgent need to provide users with a good three-dimensional model interaction experience.
[0003] For three-dimensional models, the effects seen at different angles and positions are completely different. Therefore, it is difficult to have a fixed camera observation position so that each three-dimensional model can be well observed. Users need to view the three-dimensional models from different positions, which is troublesome. Currently, there is no method to position the camera to a suitable position according to the size and position of the three-dimensional model. The camera often cuts the three-dimensional model when it rotates around the three-dimensional model. In this way, not only can the three-dimensional model not be fully viewed as a whole, but on the other hand, because the three-dimensional model is composed of points, lines, and surfaces, and the three-dimensional model has no thickness, once the camera cuts the three-dimensional model, it can often be seen that the inside of the three-dimensional model is hollow, making the model effect unrealistic, resulting in a poor user experience.
[0004] Currently, no effective solution has been proposed for the problem that the camera cannot be positioned at a suitable position according to the size and position of the three-dimensional model in the relevant technology, resulting in cropping of the three-dimensional model and poor user experience. Summary of the invention
[0005] The embodiments of the present application provide a focusing method, device, equipment and medium based on a three-dimensional stereo model, so as to at least solve the problem in the related art that the camera cannot be positioned at a suitable position according to the size and position of the three-dimensional stereo model, resulting in cropping of the three-dimensional stereo model and poor user experience.
[0006] In a first aspect, an embodiment of the present application provides a focusing method based on a three-dimensional stereo model, the method comprising:
[0007] Acquire a three-dimensional model, and calculate a bounding box of the three-dimensional model according to vertex coordinates of the three-dimensional model;
[0008] According to the maximum value coordinate and the minimum value coordinate of the bounding box, the center point coordinate O of the bounding box and the circumscribed sphere radius r of the bounding box are calculated respectively;
[0009] Get the initial coordinates C of the camera, and calculate the first vector according to the initial coordinates C of the camera and the coordinates O of the center point For the first vector Normalize it to get the unit vector
[0010] According to the preset magnification control amount A, the unit vector and the circumscribed sphere radius r, calculate the second vector
[0011] The second vector Add the initial coordinate C to the center point coordinate O to obtain the final coordinate P of the camera. Within a preset time, move the camera from the position of the initial coordinate C to the position of the final coordinate P, and set the focus of the camera to the center point coordinate O.
[0012] In some embodiments, after calculating the bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model, the method further includes:
[0013] By comparing the coordinates of each vertex of the three-dimensional model in sequence, the maximum value coordinate and the minimum value coordinate of the bounding box are calculated respectively. The formula of the maximum value coordinate is:
[0014] max=(maxX,maxY,maxZ)
[0015] Wherein, max is the maximum value coordinate, maxX is the maximum value in the X-axis direction, maxY is the maximum value in the Y-axis direction, and maxZ is the maximum value in the Z-axis direction;
[0016] The formula for the minimum coordinate is:
[0017] min=(minX,minY,minZ)
[0018] Wherein, min is the minimum value coordinate, minX is the minimum value in the X-axis direction, minY is the minimum value in the Y-axis direction, and minZ is the minimum value in the Z-axis direction.
[0019] In some embodiments, the maximum value coordinate of the bounding box is (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min ), the formula for calculating the coordinates O of the center point of the bounding box according to the maximum value coordinates and the minimum value coordinates of the bounding box is:
[0020] O=((x max +x min)*0.5,(y max +y min )*0.5,(z max +z min )*0.5)
[0021] Wherein, O is the coordinate of the center point of the bounding box, x max is the maximum value in the x-axis direction, y max is the maximum value in the y-axis direction, z max is the maximum value in the z-axis direction, x min is the minimum value in the x-axis direction, y min is the minimum value in the y-axis direction, z min is the minimum value along the z-axis.
[0022] In some embodiments, the maximum value coordinate of the bounding box is (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min ), the formula for calculating the radius r of the circumscribed sphere of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box is:
[0023]
[0024] Among them, r is the radius of the outer sphere of the bounding box, x max is the maximum value in the x-axis direction, y max is the maximum value in the y-axis direction, z max is the maximum value in the z-axis direction, x min is the minimum value in the x-axis direction, y min is the minimum value in the y-axis direction, z min is the minimum value along the z-axis.
[0025] In some embodiments, the first vector is calculated based on the initial camera coordinates C and the center point coordinates O. The formula is:
[0026]
[0027] in, is the first vector, C is the initial coordinate of the camera, O is the coordinate of the center point; Normalize it to get the unit vector The formula is:
[0028]
[0029] in, is the unit vector, is the first vector, and |n1| is the modulus of the first vector.
[0030] In some embodiments, according to the preset magnification control amount A, the unit vector and the circumscribed sphere radius r, calculate the second vector The formula is:
[0031]
[0032] The preset magnification control amount A is a constant greater than 1.
[0033] In some embodiments, the second vector Adding the coordinates O of the center point to obtain the final coordinates P of the camera is:
[0034]
[0035] Wherein, P is the final coordinate of the camera, is the second vector, and O is the coordinate of the center point.
[0036] In a second aspect, an embodiment of the present application provides a focusing device based on a three-dimensional model, the device comprising:
[0037] A first acquisition unit, used to acquire a three-dimensional model;
[0038] A bounding box calculation unit, used to calculate a bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model;
[0039] A center point coordinate calculation unit, used to calculate the center point coordinate O of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0040] A circumscribed sphere radius calculation unit, used to calculate the circumscribed sphere radius r of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0041] A second acquisition unit is used to acquire the initial coordinates C of the camera;
[0042] A unit vector calculation unit is used to calculate a first vector according to the camera initial coordinate C and the center coordinate O. For the first vector Normalize it to get the unit vector
[0043] The final coordinate calculation unit of the camera is used to calculate the final coordinate of the camera according to the preset magnification control amount A, the unit vector and the circumscribed sphere radius r, calculate the second vector The second vector Adding it to the center point coordinate O, the final coordinate P of the camera is obtained;
[0044] A camera final position determination unit, used to move the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time;
[0045] A focus setting unit is used to set the focus of the camera to the center point coordinate O.
[0046] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a storage medium storing a computer program, wherein the computer program, when executed by the processor, implements any of the methods described above.
[0047] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements any of the methods described above.
[0048] Compared with the related art, the focusing method based on the three-dimensional model provided in the embodiment of the present application takes into account that there is a close cut surface between the camera and the object, and when the distance between the camera and the close cut surface of the three-dimensional model is too small, part of the three-dimensional model will be too close to the camera, resulting in the three-dimensional model being cut off. Therefore, the present application uses the preset magnification control amount A, the unit vector and the radius r of the circumscribed sphere, calculate the second vector The size of the preset magnification control amount A is adjusted so that the distance between the three-dimensional model and the camera is greater than or equal to the near-cutting surface distance. In this way, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut off, so that the user can view the complete three-dimensional model, thereby improving the user's visual experience and avoiding the problem of cutting the three-dimensional model in the related art, so that the user can see the hollow inside the three-dimensional model, resulting in the three-dimensional model effect being unrealistic and the user experience being poor. In addition, after obtaining the final coordinate P of the camera, the present application moves the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time, and sets the focus of the camera to the center point coordinate O. The above steps The advantage is that, without manual setting, the camera can be automatically positioned at a suitable position according to the size and position of the model, thereby focusing on the model. In addition, when the user rotates the viewing angle and adjusts the added position, the camera position (i.e., the best observation point) can be quickly positioned through the above steps, and the focus of the camera can be set to the center point coordinate O to focus on the model. Moreover, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut, and the user can view the complete model, thereby improving the user's visual experience. The problem in the related art that the camera cannot be positioned at a suitable position according to the size and position of the three-dimensional model, resulting in the cutting of the three-dimensional model and poor user experience is solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0050] Figure 1 is a schematic diagram of a process of a focusing method based on a three-dimensional stereo model according to an embodiment of the present application;
[0051] Figure 2 is a first schematic diagram of a bounding box of a three-dimensional model according to an embodiment of the present application;
[0052] Figure 3 is a second schematic diagram of a bounding box of a three-dimensional model according to an embodiment of the present application;
[0053] Figure 4 is a structural block diagram of a focusing device based on a three-dimensional stereo model according to an embodiment of the present application;
[0054] Figure 5 It is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with 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 intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.
[0056] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0057] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.
[0058] With the development of science and technology, WebGL (Web Graphics Library, also known as 3D drawing protocol) technology continues to mature and improve, and the demand for three-dimensional visualization continues to increase. It is an urgent need to provide users with a good three-dimensional model interaction experience.
[0059] For three-dimensional models, the effects seen at different angles and positions are completely different. Therefore, it is difficult to have a fixed camera observation position so that each three-dimensional model can be well observed. Users need to view the three-dimensional models from different positions, which is troublesome. Currently, there is no method to position the camera to a suitable position according to the size and position of the three-dimensional model. The camera often cuts the three-dimensional model when it rotates around the three-dimensional model. In this way, not only can the three-dimensional model not be fully viewed as a whole, but on the other hand, because the three-dimensional model is composed of points, lines, and surfaces, and the three-dimensional model has no thickness, once the camera cuts the three-dimensional model, it can often be seen that the inside of the three-dimensional model is hollow, making the model effect unrealistic, resulting in a poor user experience.
[0060] In order to solve the above problem, the present invention proposes a focusing method based on a three-dimensional model.
[0061] First of all, it should be noted that in various embodiments of the present invention, the terms involved are vectors and the relationship between vectors and coordinates. For ease of understanding, vectors and the relationship between vectors and coordinates will be introduced and explained below:
[0062] A vector as known to those skilled in the art is a quantity with both magnitude and direction. The coordinates of a point in a plane rectangular coordinate system are scalars, which are absolute positions. Once the coordinate system is determined, its position will no longer change. The position of a point can be represented by the coordinates (x, y). From another perspective, the coordinates can be regarded as the end point of a vector whose starting point is the origin (0, 0). The reason why the coordinates of a point are regarded as an absolute position is that the position of the origin is fixed. The relative position of a point to another starting point can be represented by a vector. The position of point A (x, y) relative to B (m, n) can be represented by the formula (x, y)-(m, n) = (xm, ym). The difference between the two coordinates represents a vector, which can be expressed by the formula Indicates; if B(m, n) is the starting point, when the starting point changes, the relative coordinates of this point change, and the vector changes. If the starting point is at the origin, then the coordinates can also represent the vector of this point relative to the origin, and the vector (x, y) represents the direction from the origin to the point (x, y). Since those skilled in the art are aware of the above technical content, they will not be repeated hereafter.
[0063] refer to Figure 1 In one embodiment of the present invention, a focusing method based on a three-dimensional model is proposed by the present invention, and the method comprises the following steps:
[0064] Step S101, obtaining a three-dimensional model, and calculating a bounding box (bounding box) of the three-dimensional model according to the vertex coordinates of the three-dimensional model; it is easy to understand that when the size and shape of the three-dimensional model are different, the calculated bounding box of the three-dimensional model is also different; Figure 2 is a first schematic diagram of a bounding box of a three-dimensional model according to an embodiment of the present application, Figure 3 is a second schematic diagram of a bounding box of a three-dimensional model according to an embodiment of the present application. For easier understanding of the bounding box, please refer to Figure 2 or Figure 3 , where the bounding box is an algorithm for solving the optimal bounding space of a discrete point set. Its basic idea is to use a geometric body (called a bounding box) with a slightly larger volume and simpler characteristics to approximately replace complex geometric objects. In addition, those skilled in the art know that the bounding box algorithm can be an AABB bounding box, a bounding sphere, an oriented bounding box OBB, and a fixed oriented convex hull FDH, etc., so they are not described here one by one. In addition, this application has no requirements for the input three-dimensional stereo model, that is, there is no restriction on the size and shape of the three-dimensional stereo model. The three-dimensional stereo model can be a regularly shaped sphere, a rectangular body, etc., or an irregularly shaped animal, building, etc.;
[0065] It should be noted that those skilled in the art know that a three-dimensional model is a polygonal representation of an object, which is usually displayed by a computer or other video equipment. The object displayed by the three-dimensional model can be a real-world entity or a fictional object, that is, anything that exists in the physical nature can be represented by a three-dimensional model.
[0066] Step S102, calculating the center point coordinate O of the bounding box and the circumscribed sphere radius r of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0067] Step S103, obtain the initial coordinates C of the camera, and calculate the first vector according to the initial coordinates C of the camera and the coordinates O of the center point For the first vector Normalize it to get the unit vector It is easy to understand that the first vector The vector from the center of the bounding box to the camera; the initial camera coordinate C can be any position, which is set according to user needs and is not specifically limited here;
[0068] Step S104: according to the preset magnification control amount A and the unit vector and the radius r of the circumscribed sphere, calculate the second vector In this way, the camera is prevented from clipping the model. It is easy to understand that the second vector is a vector pointing to the camera along the center of the bounding box and positively correlated with r;
[0069] It is worth noting that the previous related technologies did not take into account the existence of a close cut surface between the object and the camera, and the distance between the camera and the model is less than the close cut surface distance, which will cause part of the model to be too close to the camera and cause model clipping. and the radius r of the circumscribed sphere, calculate the second vector Adjust the size of the preset magnification control amount A so that the distance between the model and the camera is greater than or equal to the near cutting surface distance. In this way, when the camera rotates around the 3D model, the 3D model will not be cut off, so that the user can view the complete model, improving the user's visual experience.
[0070] It should be noted that the near clipping distance refers to the closest distance at which the camera can see an object. Once the distance between the model and the camera is less than the near clipping distance, the model will be clipped, and the clipping model mentioned above will occur. If the near clipping distance is not considered, some models may be too close to the camera, resulting in model clipping.
[0071] Step S105: convert the second vector Add the initial coordinate C to the center point coordinate O to obtain the final coordinate P of the camera. Within the preset time, the camera is moved from the position of the initial coordinate C to the position of the final coordinate P, and the focus of the camera is set to the center point coordinate O. In this way, there is no need for manual setting. According to the size and position of the model, it is automatically positioned to the appropriate position, thereby achieving focus on the model and improving the user's visual experience.
[0072] Among them, the preset time can be set according to user needs, and is not specifically limited here; of course, in some other embodiments, the user can rotate the viewing angle at will and adjust the added position. Through the above steps, the position of the camera (i.e., the best observation point) can be quickly located, and the focus of the camera is set to the center point coordinate O to achieve focusing on the model. In addition, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut, and the user can also view the complete model, thereby improving the user's visual experience;
[0073] Through the above steps S101 to S105, the focusing method based on the three-dimensional model provided in the embodiment of the present application takes into account that there is a close cut surface between the camera and the object, and when the distance between the camera and the close cut surface of the three-dimensional model is too small, part of the three-dimensional model will be too close to the camera, resulting in the three-dimensional model being cut off. Therefore, the present application uses the preset magnification control amount A, the unit vector and the radius r of the circumscribed sphere, calculate the second vector The size of the preset magnification control amount A is adjusted so that the distance between the three-dimensional model and the camera is greater than or equal to the near-cutting surface distance. In this way, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut off, so that the user can view the complete three-dimensional model, thereby improving the user's visual experience and avoiding the problem of cutting the three-dimensional model in the related art, so that the user can see the hollow inside the three-dimensional model, resulting in the three-dimensional model effect being unrealistic and the user experience being poor. In addition, after obtaining the final coordinate P of the camera, the present application moves the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time, and sets the focus of the camera to the center point coordinate O. The above steps The advantage is that, without manual setting, the camera can be automatically positioned at a suitable position according to the size and position of the model, thereby focusing on the model. In addition, when the user rotates the viewing angle and adjusts the added position, the camera position (i.e., the best observation point) can be quickly positioned through the above steps, and the focus of the camera can be set to the center point coordinate O to focus on the model. Moreover, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut, and the user can view the complete model, thereby improving the user's visual experience. The problem in the related art that the camera cannot be positioned at a suitable position according to the size and position of the three-dimensional model, resulting in the cutting of the three-dimensional model and poor user experience is solved.
[0074] In some embodiments, after calculating the bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model, the method further includes:
[0075] By comparing the coordinates of each vertex of the three-dimensional model in turn, the maximum value coordinate and the minimum value coordinate of the bounding box are calculated respectively. The formula for the maximum value coordinate is:
[0076] max=(maxX,maxY,maxZ)
[0077] Among them, max is the maximum value coordinate, maxX is the maximum value in the X-axis direction, maxY is the maximum value in the Y-axis direction, and maxZ is the maximum value in the Z-axis direction;
[0078] The formula for the minimum coordinate is:
[0079] min=(minX,minY,minZ)
[0080] Wherein, min is the minimum coordinate, minX is the minimum value in the X-axis direction, minY is the minimum value in the Y-axis direction, and minZ is the minimum value in the Z-axis direction. Of course, in some other embodiments, those skilled in the art may also calculate the maximum value coordinate and the minimum value coordinate of the bounding box by other traversal algorithms, which are not specifically limited here.
[0081] In some embodiments, the maximum value of the bounding box is at coordinate (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min ), the formula for calculating the coordinates O of the center point of the bounding box is as follows according to the maximum and minimum coordinates of the bounding box:
[0082] O=((x max +x min )*0.5,)y max +y min )*0.5,(z max +z min )*0.5)
[0083] Wherein, O is the coordinate of the center point of the bounding box, x max is the maximum value in the x-axis direction, y max is the maximum value in the y-axis direction, z max is the maximum value in the z-axis direction, x min is the minimum value in the x-axis direction, y min is the minimum value in the y-axis direction, z min is the minimum value along the z-axis.
[0084] It should be noted that the maximum value coordinate is (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min ) are all known coordinates. For example, when the maximum value coordinate of the bounding box is (2, 2, 2) and the minimum value coordinate of the bounding box is (1, 1, 1), the coordinate O of the center point of the bounding box can be obtained as (1.5, 1.5, 1.5) according to the above formula. It is easy to understand that in different embodiments, the maximum value coordinate and the minimum value coordinate are different.
[0085] In some embodiments, the maximum value of the bounding box is at coordinate (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min), the formula for calculating the radius r of the circumscribed sphere of the bounding box is as follows based on the maximum and minimum coordinates of the bounding box:
[0086]
[0087] Among them, r is the radius of the outer sphere of the bounding box, x max is the maximum value in the x-axis direction, y max is the maximum value in the y-axis direction, z max is the maximum value in the z-axis direction, x min is the minimum value in the x-axis direction, y min is the minimum value in the y-axis direction, z min is the minimum value along the z-axis.
[0088] It should be noted that the maximum value coordinate is (x max , z max ) and the minimum coordinate of the bounding box is (x min , z min ) are all known coordinates. For example, when the maximum value coordinate of the bounding box is (2, 2, 2) and the minimum value coordinate of the bounding box is (1, 1, 1), the radius r of the circumscribed sphere can be obtained according to the above formula: It is easy to understand that in different embodiments, the maximum value coordinate and the minimum value coordinate are different, and the obtained circumscribed sphere radius r is also different.
[0089] In some embodiments, the first vector is calculated based on the camera initial coordinate C and the center point coordinate O. The formula is:
[0090]
[0091] in, is the first vector, C is the initial coordinate of the camera, and O is the coordinate of the center point;
[0092] It should be noted that the initial coordinates C of the camera are known values. For example, when the initial coordinates C are (2, 2, 2) and the center point coordinates O are (1, 1, 1), the first vector is calculated as is (1, 1, 1).
[0093] For the first vector Normalize it to get the unit vector The formula is:
[0094]
[0095] in, is a unit vector, is the first vector, and |n1| is the modulus of the first vector.
[0096] Among them, the calculation formula of the modulus |n1| of the first vector is as follows:
[0097]
[0098] For example, if the first vector is known is (1, 1, 1), then the modulus of the first vector |n1| is calculated to be for
[0099] In order to avoid the situation of cutting the model, in some embodiments, according to the preset magnification control amount A, the unit vector and the radius r of the circumscribed sphere, calculate the second vector The formula is:
[0100]
[0101] The preset magnification control amount A is a constant greater than 1. For example, if the preset magnification control amount A is 2, the radius of the circumscribed sphere r is 1, and the unit vector is (1, 1, 1), then the second vector is (2, 2, 2).
[0102] In some embodiments, the second vector Adding the coordinates of the center point O, the formula for obtaining the final coordinates P of the camera is:
[0103]
[0104] Among them, P is the final coordinate of the camera, is the second vector and O is the coordinate of the center point.
[0105] For example, if the second vector is (2, 2, 2). Assuming the center point coordinate O is (1, 1, 1), the final coordinate P of the camera is (3, 3, 3).
[0106] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0107] This embodiment also provides a focusing device based on a three-dimensional model, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and conceivable.
[0108] Figure 4 is a structural block diagram of a focusing device based on a three-dimensional model according to an embodiment of the present application, such as Figure 4 As shown, the device comprises:
[0109] A first acquisition unit 41 is used to acquire a three-dimensional model;
[0110] A bounding box calculation unit 42, used to calculate a bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model;
[0111] The center point coordinate calculation unit 43 is used to calculate the center point coordinate O of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0112] The circumscribed sphere radius calculation unit 44 is used to calculate the circumscribed sphere radius r of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0113] A second acquisition unit 45 is used to acquire the initial coordinates C of the camera;
[0114] The unit vector calculation unit 46 is used to calculate the first vector according to the camera initial coordinate C and the center point coordinate O. For the first vector Normalize it to get the unit vector
[0115] The final coordinate calculation unit 47 of the camera is used to calculate the final coordinate of the camera according to the preset magnification control amount A, the unit vector and the radius r of the circumscribed sphere, calculate the second vector The second vector Add it to the center point coordinate O to get the final coordinate P of the camera;
[0116] The camera final position determination unit 48 is used to move the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time;
[0117] The focus setting unit 49 is used to set the focus of the camera to the center point coordinate O. The focusing method based on the three-dimensional model provided in the embodiment of the present application takes into account that there is a close cut surface between the camera and the object, and when the distance between the camera and the close cut surface of the three-dimensional model is too small, part of the three-dimensional model will be too close to the camera, resulting in the three-dimensional model being cut off. Therefore, the present application sets the focus of the camera based on the preset magnification control amount A, the unit vector and the radius r of the circumscribed sphere, calculate the second vector The size of the preset magnification control amount A is adjusted so that the distance between the three-dimensional model and the camera is greater than or equal to the near-cutting surface distance. In this way, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut off, so that the user can view the complete three-dimensional model, thereby improving the user's visual experience and avoiding the problem of cutting the three-dimensional model in the related art, so that the user can see the hollow inside the three-dimensional model, resulting in the three-dimensional model effect being unrealistic and the user experience being poor. In addition, after obtaining the final coordinate P of the camera, the present application moves the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time, and sets the focus of the camera to the center point coordinate O. The above steps The advantage is that, without manual setting, the camera can be automatically positioned at a suitable position according to the size and position of the model, thereby focusing on the model. In addition, when the user rotates the viewing angle and adjusts the added position, the camera position (i.e., the best observation point) can be quickly positioned through the above steps, and the focus of the camera can be set to the center point coordinate O to focus on the model. Moreover, when the camera rotates around the three-dimensional model, the three-dimensional model will not be cut, and the user can view the complete model, thereby improving the user's visual experience. The problem in the related art that the camera cannot be positioned at a suitable position according to the size and position of the three-dimensional model, resulting in the cutting of the three-dimensional model and poor user experience is solved.
[0118] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0119] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0120] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0121] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0122] Step S101, obtaining a three-dimensional model, and calculating a bounding box of the three-dimensional model according to vertex coordinates of the three-dimensional model;
[0123] Step S102, calculating the center point coordinate O of the bounding box and the circumscribed sphere radius r of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box;
[0124] Step S103, obtain the initial coordinates C of the camera, and calculate the first vector according to the initial coordinates C of the camera and the coordinates O of the center point For the first vector Normalize it to get the unit vector
[0125] Step S104: according to the preset magnification control amount A and the unit vector and the radius r of the circumscribed sphere, calculate the second vector
[0126] Step S105: convert the second vector Add it to the center point coordinate O to get the final coordinate P of the camera. Within the preset time, move the camera from the initial coordinate C to the final coordinate P.
[0127] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0128] In addition, in combination with the focusing method based on the three-dimensional stereo model in the above embodiments, the embodiments of the present application can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by the processor, any one of the focusing methods based on the three-dimensional stereo model in the above embodiments is implemented.
[0129] In one embodiment, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a focusing method based on a three-dimensional stereo model is implemented. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a key, trackball, or touchpad provided on the housing of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0130] In one embodiment, Figure 5 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application, such as Figure 5 As shown, an electronic device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 5 As shown. The electronic device includes a processor, a network interface, an internal memory and a non-volatile memory connected through an internal bus, wherein the non-volatile memory stores an operating system, a computer program and a database. The processor is used to provide computing and control capabilities, the network interface is used to communicate with an external terminal through a network connection, the internal memory is used to provide an environment for the operation of the operating system and the computer program, the computer program is executed by the processor to implement a focusing method based on a three-dimensional stereo model, and the database is used to store data.
[0131] Those skilled in the art will understand that Figure 5 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0132] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0133] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0134] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A focusing method based on a three-dimensional model, characterized in that: The method comprises: Acquire a three-dimensional model, and calculate a bounding box of the three-dimensional model according to vertex coordinates of the three-dimensional model; According to the maximum value coordinate and the minimum value coordinate of the bounding box, the center point coordinate O of the bounding box and the circumscribed sphere radius r of the bounding box are calculated respectively; Get the initial coordinates C of the camera, and calculate the first vector according to the initial coordinates C of the camera and the coordinates O of the center point For the first vector Normalize it to get the unit vector Among them, calculate the first vector The formula is: is the first vector, C is the initial coordinate of the camera, O is the coordinate of the center point; according to the preset magnification control amount A, the unit vector and the circumscribed sphere radius r, calculate the second vector Among them, the second vector is calculated The formula is: The preset magnification control amount A is a constant greater than 1; The second vector Add the initial coordinate C to the center point coordinate O to obtain the final coordinate P of the camera. Within a preset time, move the camera from the position of the initial coordinate C to the position of the final coordinate P, and set the focus of the camera to the center point coordinate O.
2. The method according to claim 1, characterized in that: After calculating the bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model, the method further includes: By comparing the coordinates of each vertex of the three-dimensional model in sequence, the maximum value coordinate and the minimum value coordinate of the bounding box are calculated respectively. The formula of the maximum value coordinate is: max=(maxX,maxY,maxZ) Wherein, max is the maximum value coordinate, maxX is the maximum value in the X-axis direction, maxY is the maximum value in the Y-axis direction, and maxZ is the maximum value in the Z-axis direction; The formula for the minimum coordinate is: min=(minX,minY,minZ) Wherein, min is the minimum value coordinate, minX is the minimum value in the X-axis direction, minY is the minimum value in the Y-axis direction, and minZ is the minimum value in the Z-axis direction.
3. The method according to claim 1, characterized in that: The maximum value coordinate of the bounding box is (X max ,Y max ,Z max ) and the minimum coordinate of the bounding box is (X min ,Y min ,Z min ), the formula for calculating the coordinates O of the center point of the bounding box according to the maximum value coordinates and the minimum value coordinates of the bounding box is: O=((X max +X min )*0.5,(Y max +Y min )*0.5,(Z max +Z min )*0.5) Wherein, O is the coordinate of the center point of the bounding box, X max is the maximum value in the x-axis direction, Y max is the maximum value in the y-axis direction, Z max is the maximum value in the z-axis direction, X min is the minimum value in the x-axis direction, Y min is the minimum value in the y-axis direction, Z min is the minimum value along the z-axis.
4. The method according to claim 1, characterized in that: The maximum value coordinate of the bounding box is (X max ,Y max ,Z max ) and the minimum coordinate of the bounding box is (X min ,Y min ,Z min ), the formula for calculating the radius r of the circumscribed sphere of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box is: Among them, r is the radius of the outer sphere of the bounding box, X max is the maximum value in the x-axis direction, Y max is the maximum value in the y-axis direction, Z max is the maximum value in the z-axis direction, X min is the minimum value in the x-axis direction, Y min is the minimum value in the y-axis direction, Z min is the minimum value along the z-axis.
5. The method according to claim 1, characterized in that: The first vector Normalize it to get the unit vector The formula is: in, is the unit vector, is the first vector, and |n1| is the modulus of the first vector.
6. The method according to claim 1, characterized in that: The second vector Adding the coordinates O of the center point to obtain the final coordinates P of the camera is: Wherein, P is the final coordinate of the camera, is the second vector, and O is the coordinate of the center point.
7. A focusing device based on a three-dimensional model, characterized in that: The device comprises: A first acquisition unit, used for acquiring a three-dimensional model; A bounding box calculation unit, used to calculate a bounding box of the three-dimensional model according to the vertex coordinates of the three-dimensional model; A center point coordinate calculation unit, used to calculate the center point coordinate O of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box; A circumscribed sphere radius calculation unit, used to calculate the circumscribed sphere radius r of the bounding box according to the maximum value coordinate and the minimum value coordinate of the bounding box; A second acquisition unit is used to acquire the initial coordinate C of the camera; A unit vector calculation unit is used to calculate a first vector according to the camera initial coordinate C and the center point coordinate O. For the first vector Normalize it to get the unit vector Among them, calculate the first vector The formula is: is the first vector, C is the initial coordinate of the camera, and O is the coordinate of the center point; The final coordinate calculation unit of the camera is used to calculate the final coordinate of the camera according to the preset magnification control amount A, the unit vector and the circumscribed sphere radius r, calculate the second vector The second vector Added to the center point coordinate O, the final coordinate P of the camera is obtained, wherein the second vector is calculated The formula is: The preset magnification control amount A is a constant greater than 1; A camera final position determination unit, used to move the camera from the position of the initial coordinate C to the position of the final coordinate P within a preset time; A focus setting unit is used to set the focus of the camera to the center point coordinate O.
8. An electronic device comprising a processor and a storage medium storing a computer program, characterized in that: When the computer program is executed by the processor, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Focus switching method and system for 3D scene
CN103559742A
Automatic layout method and system of intelligent 3D (three dimensional) model
CN103617317A
