Masked picture display method, device and masked picture display method and device
By receiving user mask instructions and generating mask image grid attribute information, the mask image is directly rendered, which solves the problem of complex GPU calculations in the Unity engine during rectangular masking and improves display speed.
Patent Information
- Application Number
- CN202010749875.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-30
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2040-07-30
AI Technical Summary
When the Unity game engine uses the RectMask2d component to implement a rectangular mask, it needs to adjust the size and position of the parent and child levels, resulting in complex GPU calculations and a large amount of calculations.
By receiving the user's masking instructions, the grid attribute information of the original image is obtained, and the mesh attribute information of the masked image is generated according to the masking parameters, and the masked image is directly rendered to avoid processing the texture data of the original image and the masked image. Full calculation.
The amount of calculation is reduced, the display speed of the mask image is improved, and the computational complexity of the GPU is reduced.
Smart Images

Figure CN112419137B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a masked image display method and device, and a masked image display method and device. Background Art
[0002] The current Unity (game engine) built-in GUI system provides a RectMask2d component to support rectangular masks when implementing masking of the original image. However, when Unity uses the RectMask2d component to implement rectangular masks, the RectMask2d component needs to first establish a parent-child relationship structure (GameObject), and take the masked object (original image) as a child, and then add a rectangular mask to the original image by adjusting the size and position of the parent and child. The existing method of implementing rectangular masks through the parent-child relationship structure requires adjusting the size and position of the parent and child at the same time, and the GPU (Graphics Processing Unit) needs to calculate the original image and the mask image in the parent and child, which is complex and requires a large amount of calculation. Summary of the invention
[0003] In view of this, a mask image display method, device, computer equipment and computer-readable storage medium are now provided to solve the problems of complex GPU calculation and large amount of calculation in the existing mask image display method.
[0004] The present application provides a mask image display method, comprising:
[0005] Receiving a mask instruction triggered by a user based on the original image, wherein the mask instruction carries mask parameter information;
[0006] Acquire first attribute information of a first grid corresponding to the original image according to the mask instruction;
[0007] Generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information;
[0008] A texture corresponding to the original image is obtained, and the second grid is rendered according to the texture and the second attribute information to display the mask image.
[0009] Optionally, the mask image display further includes:
[0010] A mask parameter setting interface is displayed, so that the user can set the mask parameter information based on the parameter setting interface.
[0011] Optionally, the first attribute information includes vertex coordinates of multiple vertices of the first mesh and texture coordinates corresponding to the multiple vertices of the first mesh, the second attribute information includes vertex coordinates of multiple vertices of the second mesh and texture coordinates corresponding to the multiple vertices of the second mesh, and the second attribute information of the second mesh corresponding to the mask image generated according to the first attribute information and the mask parameter information includes:
[0012] Generate vertex coordinates of a plurality of vertices of a second mesh corresponding to the mask image according to the vertex coordinates of a plurality of vertices of the first mesh and the mask parameter information;
[0013] The texture coordinates corresponding to the multiple vertices of the second mesh corresponding to the mask image are generated according to the texture coordinates corresponding to the multiple vertices of the first mesh and the mask parameter information.
[0014] Optionally, the mask parameter information includes a ratio of the upper mask of the original image, a ratio of the lower mask of the original image, a ratio of the left mask of the original image, and a ratio of the right mask of the original image, and the vertex coordinates of multiple vertices of the second mesh corresponding to the mask image are generated according to the vertex coordinates of multiple vertices of the first mesh and the mask parameter information. The method includes:
[0015] Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a ratio of the upper mask, a ratio of the lower mask, a ratio of the left mask, and a ratio of the right mask;
[0016] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0017] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask and the ratio of the right mask.
[0018] Optionally, the mask parameter information includes a ratio of the upper mask of the original image, a ratio of the lower mask of the original image, a ratio of the left mask of the original image, a ratio of the right mask of the original image, a tilt value of the mask in the horizontal direction, and a tilt value of the mask in the vertical direction. The vertex coordinates of multiple vertices of the second mesh corresponding to the mask image are generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information, including:
[0019] Determine the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask, the ratio of the right mask, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction;
[0020] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0021] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the proportion of the upper mask, the proportion of the lower mask, the proportion of the left mask, the proportion of the right mask, the horizontal tilt value of the mask and the vertical tilt value of the mask.
[0022] Optionally, the mask parameter information includes a radius of a rounded rectangle and a smoothness of the rounded rectangle, and the vertex coordinates of multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of multiple vertices of the first mesh and the mask parameter information include:
[0023] Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a radius of the rounded rectangle, and a smoothness of the rounded rectangle;
[0024] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0025] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle.
[0026] Optionally, before the step of determining the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle, the method further includes:
[0027] The number of vertices of the second mesh is determined according to the smoothness of the rounded rectangle and a preset formula.
[0028] The present application also provides a mask image display device, comprising:
[0029] A receiving module, used for receiving a mask instruction triggered by a user based on an original image, wherein the mask instruction carries mask parameter information;
[0030] An acquisition module, configured to acquire first attribute information of a first grid corresponding to the original image according to the mask instruction;
[0031] A generating module, configured to generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information;
[0032] A rendering module is used to obtain a texture corresponding to the original image, and render the second grid according to the texture and the second attribute information to display the mask image.
[0033] The present application also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0034] Beneficial effects of the above technical solution:
[0035] The embodiment of the present invention receives a mask instruction triggered by a user based on an original image, wherein the mask instruction carries mask parameter information; obtains first attribute information of a first grid corresponding to the original image according to the mask instruction; generates second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information; obtains a texture corresponding to the original image, and renders the second grid according to the texture and the second attribute information to display the mask image. The embodiment of the present invention determines the second attribute information of a second grid corresponding to a mask image obtained after masking according to the mask parameter information set by the user and the first attribute information of the first grid corresponding to the original image, and then generates a mask image according to the second attribute information of the second grid and the texture corresponding to the original image, thereby eliminating the need to calculate and process all texture data of the original image and the mask image, thereby saving calculation amount and improving display speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 A framework diagram of an embodiment of a system framework diagram of the mask image display method described in the present application;
[0037] Figure 2 A flowchart of an embodiment of the mask image display method described in the present application;
[0038] Figure 3 This is a schematic diagram of a mask parameter setting interface in one embodiment of the present application;
[0039] Figure 4 A flowchart of the detailed steps of generating the second attribute information of the second grid corresponding to the mask image according to the first attribute information and the mask parameter information in one embodiment of the present application;
[0040] Figure 5 This is a schematic diagram of an original picture in one embodiment of the present application;
[0041] Figure 6 This is a schematic diagram of a masked image obtained after performing rectangular masking on an original image in one embodiment of the present application;
[0042] Figure 7 This is a schematic diagram of a masked image obtained after performing parallelogram masking processing on an original image in one embodiment of the present application;
[0043] Figure 8 This is a schematic diagram of a masked image obtained after performing parallelogram masking processing on an original image in one embodiment of the present application;
[0044] Fig. 9 A module diagram of an embodiment of the mask image display device described in the present application;
[0045] Fig.10 A schematic diagram of the hardware structure of a computer device that executes a mask image display method or a mask image display method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The advantages of the present application are further described below in conjunction with the accompanying drawings and specific embodiments.
[0047] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0048] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0049] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0050] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0051] Figure 1 The schematic diagram of the application environment of the mask image display method according to the embodiment of the present application is schematically shown. In an exemplary embodiment, the system of the application environment may include a user terminal 10 and a background server 20. Among them, the user terminal 10 forms a wireless or wired connection with the background server 20, and the user terminal 10 has a corresponding application client or web client. Among them, the user terminal 10 can be a PC, a mobile phone, an iPAD, a tablet computer, a laptop computer, a personal digital assistant, etc. The background server 20 can 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.
[0052] See also Figure 2 , which is a flowchart of a mask image display method according to an embodiment of the present application. It can be understood that the flowchart in the present method embodiment is not used to limit the order of executing the steps. As can be seen from the figure, the mask image display method provided in the present embodiment includes:
[0053] Step S20: receiving a mask instruction triggered by the user based on the original image, wherein the mask instruction carries mask parameter information.
[0054] In the prior art, when Unity displays the original image, it does so by means of a mesh. Specifically, when Unity displays the original image, it first creates a GameObject and adds a MeshFilter component and a MeshRender component. Then, it obtains the mesh corresponding to the original image through the MeshFilter component, and gives the obtained mesh to the MeshRender component, so that the original image can be rendered through the MeshRender component.
[0055] Among them, Unity is a client engine for creating 3D games. Mesh is the mesh corresponding to the original image. Mesh contains other useful properties and functional information such as vertex coordinates, normals, texture coordinates, triangle drawing sequence, etc. GameObject is a basic structure built into Unity. MeshRender component is used to obtain the mesh corresponding to the original image. Mesh Render component is a component that renders the mesh. The function of MeshFilter component is to give Mesh to MeshRender so that it can draw and display the original image.
[0056] In this embodiment, after Unity displays the original image through a grid, the user can trigger a mask instruction based on the displayed original image, wherein the mask instruction is an instruction for cropping the original image to keep part of the image content visible.
[0057] In this embodiment, Unity crops the original image based on the mask parameter information. Figure 3 The mask parameter information may include the following parameter information: the ratio of the mask on the top of the original image (MaskTop), the ratio of the mask on the bottom of the original image (Mask Bottom), the ratio of the mask on the left of the original image (Mask Left), the ratio of the mask on the right of the original image (Mask Right), the tilt value of the mask in the horizontal direction (Lean Horizontal), the tilt value of the mask in the vertical direction (Lean Vertical), the radius of the rounded rectangle (Radius), the smoothness of the rounded rectangle (Smoothness), the offset position of the original image in the mask (Scroll X, Scroll Y), etc.
[0058] It should be noted that the proportion of the upper mask of the original image refers to the proportion of cropping the top of the original image; the proportion of the lower mask of the original image refers to the proportion of cropping the bottom of the original image; the proportion of the left mask of the original image refers to the proportion of cropping the left side of the original image; the proportion of the right mask of the original image refers to the proportion of cropping the right side of the original image; the horizontal tilt value of the mask refers to the tilt value of tilting the mask image left / right; the vertical tilt value of the mask refers to the tilt value of tilting the mask image up / down; the radius of the rounded rectangle refers to the radius of the rounded corner when the original image is subjected to a rounded rectangle mask; the smoothness of the rounded rectangle is a parameter that determines how many triangles the rounded rectangle area is divided into when the original image is subjected to a rounded rectangle mask. For example, if the smoothness of the rounded rectangle is n, the rounded rectangle area needs to be divided into n triangles.
[0059] In one embodiment, when the user triggers the mask instruction, the user may trigger the mask instruction by clicking a preset control. It is understandable that before the user triggers the mask instruction, the user needs to set the mask parameter information first.
[0060] In an exemplary embodiment, in order to facilitate setting the mask parameter information, the mask image display further includes:
[0061] A mask parameter setting interface is displayed, so that the user can set the mask parameter information based on the parameter setting interface.
[0062] Specifically, when the user performs mask processing on the original image, a visual mask parameter setting interface can be displayed on the screen, and the user can set various mask parameter information for mask processing of the original image through the mask parameter setting interface. In an exemplary embodiment, the mask parameter setting interface is as follows: Figure 3 shown.
[0063] This embodiment can facilitate the user to set the mask parameter information by displaying the mask parameter setting interface.
[0064] Step S21, obtaining first attribute information of a first grid corresponding to the original image according to the mask instruction.
[0065] Specifically, the first attribute information includes vertex coordinates (vertex), normal (normal), texture coordinates (uv), triangle sequence (triangle), etc.
[0066] Among them, the spatial coordinates of each vertex of the first mesh can be stored in the vertex coordinate array. Since the first mesh has 4 vertices, the size of vertex is 4. The normal array stores the normal of each vertex of the first mesh, and the size corresponds to the vertex coordinates, that is, normal[i] corresponds to the normal of vertex vertex[i]. The texture coordinates (uv) define the position information of each point on the image. These points are interconnected with the 3D model corresponding to the original image to determine the position of the surface texture map. UV is to accurately correspond each point on the original image to the surface of the model object, and uv[i] corresponds to vertex[i]. The triangle sequence (triangles) is an int array, which contains a list of triangles indexed by the vertex array. In this embodiment, the first mesh is composed of 2 triangles, and the three points of the triangle are the points in the vertex coordinates. For example: the first mesh has four vertices 0, 1, 2, and 3, and the vertex coordinates are V0(1,1,0), V1(-1,1,0), V2(1,-1,0), and V3(-1,-1,0). Then these four vertices can form a triangle sequence containing two triangles: tri[0]=ver[0],ver[3],ver[1], tri[1]=ver[0],ver[2],ver[3].
[0067] Step S22: Generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information.
[0068] Specifically, the mask image is an image obtained by masking the original image. In this embodiment, when the mask image is displayed, it is also achieved by mesh. Therefore, in order to display the mask image, it is necessary to first determine the second attribute information of the second mesh corresponding to the mask image based on the first attribute information of the mesh corresponding to the original image and the mask parameter information.
[0069] In this embodiment, the data type included in the second attribute information of the second mesh is completely consistent with the data type included in the first attribute information of the first mesh, that is, the second attribute information also includes vertex coordinates (vertex), normal (normal), texture coordinates (uv), triangle sequence (triangle) and other information.
[0070] In an exemplary embodiment, referring to Figure 4The first attribute information may include vertex coordinates of multiple vertices of the first mesh and texture coordinates corresponding to the multiple vertices of the first mesh, the second attribute information includes vertex coordinates of multiple vertices of the second mesh and texture coordinates corresponding to the multiple vertices of the second mesh, and the second attribute information of the second mesh corresponding to the mask image generated according to the first attribute information and the mask parameter information includes:
[0071] Step S40 , generating vertex coordinates of a plurality of vertices of a second mesh corresponding to the mask image according to the vertex coordinates of a plurality of vertices of the first mesh and the mask parameter information.
[0072] Specifically, after obtaining the vertex coordinates of each vertex constituting the first mesh, the vertex coordinates of multiple vertices of the second mesh corresponding to the mask image can be recalculated using mathematical rules according to the mask parameter information set by the user and the vertex coordinates of the first mesh.
[0073] Step S41 , generating texture coordinates corresponding to multiple vertices of a second mesh corresponding to a mask image according to texture coordinates corresponding to multiple vertices of the first mesh and the mask parameter information.
[0074] Specifically, after the texture coordinates of each vertex constituting the first mesh are obtained, the texture coordinates of multiple vertices of the second mesh corresponding to the mask image can be recalculated using mathematical rules based on the mask parameter information set by the user and the texture coordinates of each vertex of the first mesh.
[0075] It is understandable that when different mask processing is performed on the original image, the mask parameter information that the user needs to set is also different. In an exemplary embodiment, when the original image needs to be subjected to rectangular mask processing, the user can set the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, and the ratio of the right mask of the original image in the mask parameter setting interface, that is, the mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, and the ratio of the right mask of the original image. The vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0076] Vertex coordinates of multiple vertices of the second mesh are determined according to vertex coordinates of multiple vertices of the first mesh, a ratio of the upper mask, a ratio of the lower mask, a ratio of the left mask, and a ratio of the right mask.
[0077] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0078] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask and the ratio of the right mask.
[0079] Specifically, refer to Figure 5 , assuming that the width and height of the original image are both 1, the ratio of the upper mask is T, the ratio of the lower mask is B, the ratio of the left mask is L, and the ratio of the right mask is R.
[0080] Since the original image is displayed in mesh mode, when the original image is masked, the coordinates of the four vertices contained in the first mesh corresponding to the original image can be obtained, which are: the coordinates of the upper left vertex are (1,0), the coordinates of the upper right vertex are (1,1), the coordinates of the lower left vertex are (0,0), and the coordinates of the lower right vertex are (1,0). In addition, the texture coordinates of the four vertices contained in the first mesh corresponding to the original image are: the texture coordinates of the upper left vertex are (1,0), the texture coordinates of the upper right vertex are (1,1), the texture coordinates of the lower left vertex are (0,0), and the texture coordinates of the lower right vertex are (1,0).
[0081] After obtaining the vertex coordinates of multiple vertices of the first grid, the proportion T of the upper mask, the proportion B of the lower mask, the proportion L of the left mask and the proportion R of the right mask, according to mathematical rules, the coordinates of the four vertices of the second grid corresponding to the mask image obtained after rectangular masking of the original image are: the coordinates of the upper left vertex are (L, 1-T), the coordinates of the upper right vertex are (1-R, 1-T), the coordinates of the lower left vertex are (L, B), and the coordinates of the lower right vertex are (1-R, B).
[0082] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, and the ratio R of the right mask, it can be known according to mathematical rules that the texture coordinates of the four vertices of the second mesh corresponding to the mask image obtained after rectangular masking of the original image are as follows: the texture coordinates of the upper left vertex are (L, 1-T), the texture coordinates of the upper right vertex are (1-R, 1-T), the texture coordinates of the lower left vertex are (L, B), and the texture coordinates of the lower right vertex are (1-R, B). Exemplarily, the mask image obtained after rectangular masking of the original image is as follows Figure 6shown.
[0083] In another exemplary embodiment, when the original image needs to be processed with a parallelogram mask, the user can set the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction in the mask parameter setting interface, that is, the mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction. Then, the vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0084] Determine the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask, the ratio of the right mask, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction;
[0085] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0086] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the proportion of the upper mask, the proportion of the lower mask, the proportion of the left mask, the proportion of the right mask, the horizontal tilt value of the mask and the vertical tilt value of the mask.
[0087] Specifically, refer to Figure 5 , assuming that the width and height of the original image are both 1, the ratio of the upper mask is T, the ratio of the lower mask is B, the ratio of the left mask is L, and the ratio of the right mask is R, the tilt value of the mask in the horizontal direction is H, and the tilt value of the mask in the vertical direction is V.
[0088] The parallelogram mask processing performed on the original image can be regarded as the image obtained after the rectangular mask processing is performed on the original image, and then the mask is tilted in the horizontal direction and tilted in the vertical direction.
[0089] After obtaining the vertex coordinates of multiple vertices of the first grid, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, the ratio R of the right mask, the horizontal tilt value of the mask is H, and the vertical tilt value of the mask is V, according to mathematical rules, the coordinates of the four vertices of the second grid corresponding to the mask image obtained after parallelogram masking of the original image are: the coordinates of the upper left vertex are (L+H, 1-TV), the coordinates of the upper right vertex are (1-R+H, 1-T+V), the coordinates of the lower left vertex are (LH, BV), and the coordinates of the lower right vertex are (1-RH, B+V).
[0090] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, the ratio R of the right mask, the horizontal tilt value of the mask H, and the vertical tilt value of the mask V, it can be known according to mathematical rules that the texture coordinates of the four vertices of the second mesh corresponding to the mask image obtained after parallelogram masking of the original image are as follows: the texture coordinates of the upper left vertex are (L+H, 1-TV), the texture coordinates of the upper right vertex are (1-R+H, 1-T+V), the texture coordinates of the lower left vertex are (LH, BV), and the texture coordinates of the lower right vertex are (1-RH, B+V). Exemplarily, the mask image obtained after parallelogram masking of the original image is as follows Figure 7 shown.
[0091] In another exemplary embodiment, when the original image needs to be processed with a rounded corner mask, the user can set the radius of the rounded rectangle and the smoothness of the rounded rectangle in the mask parameter setting interface, that is, the mask parameter information includes the radius of the rounded rectangle and the smoothness of the rounded rectangle, and the vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0092] Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a radius of the rounded rectangle, and a smoothness of the rounded rectangle;
[0093] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0094] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle.
[0095] Specifically, assume that the width and height of the original image are both 1, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4. When the rounded rectangle mask is performed on the original image, it can be regarded as dividing the original image into Figure 8 The image shown includes three groups of rectangles in the middle and rounded rectangular areas in the four corners. In the prior art, Unity draws the rounded rectangle by dividing it into several triangles of the same size. Therefore, in this embodiment, when the original image is subjected to rounded rectangular masking, the original image can be decomposed into the rounded rectangular area consisting of the three groups of rectangles in the middle and four groups of several triangles.
[0096] In addition, in this embodiment, since the number of triangles that can be divided into each rounded rectangular area is determined by the smoothness of the rounded rectangle, after obtaining the smoothness of the rounded rectangle, it is first necessary to determine the number of vertices of the second grid based on the smoothness of the rounded rectangle and a preset formula, wherein the preset formula is: the number of vertices of the second grid obtained after the original image is masked with a rounded rectangle = 4*(smoothness of the rounded rectangle+2), that is, if the number of triangles divided into the rounded rectangular area is 4, the number of vertices of the second grid obtained after the original image is masked with a rounded rectangle is: (4+2)*4=24, and the angle α of the triangle is = 90° / 4=22.5°.
[0097] Exemplarily, after obtaining the texture coordinates of multiple vertices of the first mesh, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4, according to mathematical rules, the texture coordinates of the 24 vertices of the second mesh corresponding to the mask image obtained after the rounded rectangle processing of the original image are respectively:
[0098] The coordinates of the four vertices of the middle rectangle are: the coordinates of the upper left vertex are (0.2,1), the coordinates of the upper right vertex are (0.8,1), the coordinates of the lower left vertex are (0.2,0), and the coordinates of the lower right vertex are (0.8,0).
[0099] The coordinates of the four vertices of the rectangle on the left are: the coordinates of the upper left vertex are (0,0.8), the coordinates of the upper right vertex are (0.2,0.8), the coordinates of the lower left vertex are (0,0.2), and the coordinates of the lower right vertex are (0.2,0.2).
[0100] The coordinates of the four vertices of the rectangle on the right are: the coordinates of the upper left vertex are (0.8, 0.8), the coordinates of the upper right vertex are (1, 0.8), the coordinates of the lower left vertex are (0.8, 0.2), and the coordinates of the lower right vertex are (1, 0.2).
[0101] The coordinates of the three vertices (vertex 1, vertex 2, vertex 3) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper left corner are (0.2-0.2*cosα,0.8+0.2*sinα), (0.2-0.2*cos2α,0.8+0.2*sin2α), and (0.2-0.2*cos3α,0.8+0.2*sin3α) respectively.
[0102] The coordinates of the three vertices (vertex 4, vertex 5, vertex 6) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper right corner are (0.8+0.2*cosα,0.8+0.2*sinα), (0.8+0.2*cos2α,0.8+0.2*sin2α), and (0.8+0.2*cos3α,0.8+0.2*sin3α) respectively.
[0103] The coordinates of the three vertices (vertex 7, vertex 8, vertex 9) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower left corner are (0.2-0.2*cosα, 0.2-0.2*sinα), (0.2-0.2*cos2α, 0.2-0.2*sin2α), and (0.2-0.2*cos3α, 0.2-0.2*sin3α) respectively.
[0104] The coordinates of the three vertices (vertex 10, vertex 11, vertex 12) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower right corner are (0.8+0.2*cosα,0.2-0.2*sinα), (0.8+0.2*cos2α,0.2-0.2*sin2α), and (0.8+0.2*cos3α,0.2-0.2*sin3α) respectively.
[0105] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4, according to mathematical rules, the texture coordinates of the 24 vertices of the second mesh corresponding to the mask image obtained after the rounded mask processing of the original image are respectively:
[0106] The texture coordinates of the four vertices of the middle rectangle are: the texture coordinate of the upper left vertex is (0.2,1), the texture coordinate of the upper right vertex is (0.8,1), the texture coordinate of the lower left vertex is (0.2,0), and the texture coordinate of the lower right vertex is (0.8,0).
[0107] The texture coordinates of the four vertices of the left rectangle are: the texture coordinates of the upper left vertex are (0,0.8), the texture coordinates of the upper right vertex are (0.2,0.8), the texture coordinates of the lower left vertex are (0,0.2), and the texture coordinates of the lower right vertex are (0.2,0.2).
[0108] The texture coordinates of the four vertices of the rectangle on the right are: the texture coordinates of the upper left vertex are (0.8, 0.8), the texture coordinates of the upper right vertex are (1, 0.8), the texture coordinates of the lower left vertex are (0.8, 0.2), and the texture coordinates of the lower right vertex are (1, 0.2).
[0109] The texture coordinates of the three vertices (vertex 1, vertex 2, vertex 3) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper left corner are (0.2-0.2*cosα,0.8+0.2*sinα), (0.2-0.2*cos2α,0.8+0.2*sin2α), and (0.2-0.2*cos3α,0.8+0.2*sin3α) respectively.
[0110] The texture coordinates of the three vertices (vertex 4, vertex 5, vertex 6) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper right corner are (0.8+0.2*cosα,0.8+0.2*sinα), (0.8+0.2*cos2α,0.8+0.2*sin2α), and (0.8+0.2*cos3α,0.8+0.2*sin3α) respectively.
[0111] The texture coordinates of the three vertices (vertex 7, vertex 8, vertex 9) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower left corner are (0.2-0.2*cosα, 0.2-0.2*sinα), (0.2-0.2*cos2α, 0.2-0.2*sin2α), and (0.2-0.2*cos3α, 0.2-0.2*sin3α) respectively.
[0112] The texture coordinates of the three vertices (vertex 10, vertex 11, vertex 12) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower right corner are (0.8+0.2*cosα,0.2-0.2*sinα), (0.8+0.2*cos2α,0.2-0.2*sin2α), and (0.8+0.2*cos3α,0.2-0.2*sin3α) respectively.
[0113] In this embodiment, when the original image is subjected to rectangular mask processing, the vertex coordinates and texture coordinates of the second mesh corresponding to the mask image can be calculated based on the mask parameter information set by the user and the vertex coordinates and texture coordinates of each vertex of the first mesh, so that the second mesh can be subsequently rendered based on the vertex coordinates and texture coordinates of the second mesh to obtain the mask image obtained after the rectangular mask processing of the original image, without the need to calculate and process all the texture data of the original image, thereby saving calculation amount and improving display speed.
[0114] Step S23, obtaining a texture corresponding to the original image, and rendering the second grid according to the texture and the second attribute information to display the mask image.
[0115] Specifically, the texture is a format converted from an image, and is a format that can be processed by a GPU (Graphics Processing Unit).
[0116] The second attribute information includes vertex coordinates and texture coordinates of each vertex constituting the second mesh, as well as attribute information such as a triangle sequence (triangle) composed of each vertex.
[0117] Therefore, after obtaining these attribute information, a second grid can be created based on these attribute information, and then the texture area corresponding to the original image is sampled according to the texture coordinates in the second grid, and the second grid is rendered according to the sampled texture to display the mask image.
[0118] In the embodiment of the present invention, the second attribute information of the second grid corresponding to the mask image obtained after mask processing is determined based on the mask parameter information set by the user and the first attribute information of the first grid corresponding to the original image, and then the mask image is generated based on the second attribute information of the second grid and the texture corresponding to the original image. This eliminates the need to calculate and process all texture data of the original image and the mask image, thereby saving calculation amount and improving display speed.
[0119] See also Fig. 9 , is a program module diagram of an embodiment of a mask image display device 900 of the present application.
[0120] In this embodiment, the mask image display device 900 includes a series of computer program instructions stored in a memory. When the computer program instructions are executed by a processor, the mask image display function of each embodiment of the present application can be implemented. In some embodiments, based on the specific operations implemented by each part of the computer program instructions, the mask image display device 900 can be divided into one or more modules. For example, in Fig. 9 In the embodiment, the mask image display device 900 can be divided into a receiving module 901, an acquiring module 902, a generating module 903, and a rendering module 904.
[0121] The receiving module 901 is used to receive a mask instruction triggered by a user based on an original image, wherein the mask instruction carries mask parameter information.
[0122] In the prior art, when Unity displays the original image, it does so by means of a mesh. Specifically, when Unity displays the original image, it first creates a GameObject and adds a MeshFilter component and a MeshRender component. Then, it obtains the mesh corresponding to the original image through the MeshFilter component, and gives the obtained mesh to the MeshRender component, so that the original image can be rendered through the MeshRender component.
[0123] Among them, Unity is a client engine for creating 3D games. Mesh is the mesh corresponding to the original image. Mesh contains other useful properties and functional information such as vertex coordinates, normals, texture coordinates, triangle drawing sequence, etc. GameObject is a basic structure built into Unity. MeshRender component is used to obtain the mesh corresponding to the original image. Mesh Render component is a component that renders the mesh. The function of MeshFilter component is to give Mesh to MeshRender so that it can draw and display the original image.
[0124] In this embodiment, after Unity displays the original image through a grid, the user can trigger a mask instruction based on the displayed original image, wherein the mask instruction is an instruction for cropping the original image to keep part of the image content visible.
[0125] In this embodiment, Unity crops the original image based on the mask parameter information, which may include the following parameter information: the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the horizontal tilt value of the mask, the vertical tilt value of the mask, the radius of the rounded rectangle, the smoothness of the rounded rectangle, the offset position of the original image in the mask, etc.
[0126] It should be noted that the proportion of the upper mask of the original image refers to the proportion of cropping the top of the original image; the proportion of the lower mask of the original image refers to the proportion of cropping the bottom of the original image; the proportion of the left mask of the original image refers to the proportion of cropping the left side of the original image; the proportion of the right mask of the original image refers to the proportion of cropping the right side of the original image; the horizontal tilt value of the mask refers to the tilt value of tilting the mask image left / right; the vertical tilt value of the mask refers to the tilt value of tilting the mask image up / down; the radius of the rounded rectangle refers to the radius of the rounded corner when the original image is subjected to a rounded rectangle mask; the smoothness of the rounded rectangle is a parameter that determines how many triangles the rounded rectangle area is divided into when the original image is subjected to a rounded rectangle mask. For example, if the smoothness of the rounded rectangle is n, the rounded rectangle area needs to be divided into n triangles.
[0127] In one embodiment, when the user triggers the mask instruction, the user may trigger the mask instruction by clicking a preset control. It is understandable that before the user triggers the mask instruction, the user needs to set the mask parameter information first.
[0128] In an exemplary implementation, in order to facilitate setting of the mask parameter information, the mask image display device 900 further includes: a setting module.
[0129] The setting module is used to display a mask parameter setting interface so that the user can set the mask parameter information based on the parameter setting interface.
[0130] Specifically, when the user performs mask processing on the original image, a visual mask parameter setting interface can be displayed on the screen, and the user can set various mask parameter information for mask processing of the original image through the mask parameter setting interface. In an exemplary embodiment, the mask parameter setting interface is as follows: Figure 3 shown.
[0131] This embodiment can facilitate the user to set the mask parameter information by displaying the mask parameter setting interface.
[0132] The acquisition module 902 is used to acquire the first attribute information of the first grid corresponding to the original image according to the mask instruction.
[0133] Specifically, the first attribute information includes vertex coordinates (vertex), normal (normal), texture coordinates (uv), triangle sequence (triangle), etc.
[0134] Among them, the spatial coordinates of each vertex of the first mesh can be stored in the vertex coordinate array. Since the first mesh has 4 vertices, the size of vertex is 4. The normal array stores the normal of each vertex of the first mesh, and the size corresponds to the vertex coordinates, that is, normal[i] corresponds to the normal of vertex vertex[i]. The texture coordinates (uv) define the position information of each point on the image. These points are interconnected with the 3D model corresponding to the original image to determine the position of the surface texture map. UV is to accurately correspond each point on the original image to the surface of the model object, and uv[i] corresponds to vertex[i]. The triangle sequence (triangles) is an int array, which contains a list of triangles indexed by the vertex array. In this embodiment, the first mesh is composed of 2 triangles, and the three points of the triangle are the points in the vertex coordinates. For example: the first mesh has four vertices 0, 1, 2, and 3, and the vertex coordinates are V0(1,1,0), V1(-1,1,0), V2(1,-1,0), and V3(-1,-1,0). Then these four vertices can form a triangle sequence containing two triangles: tri[0]=ver[0],ver[3],ver[1], tri[1]=ver[0],ver[2],ver[3].
[0135] The generating module 903 is used to generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information.
[0136] Specifically, the mask image is an image obtained by masking the original image. In this embodiment, when the mask image is displayed, it is also achieved by mesh. Therefore, in order to display the mask image, it is necessary to first determine the second attribute information of the second mesh corresponding to the mask image based on the first attribute information of the mesh corresponding to the original image and the mask parameter information.
[0137] In this embodiment, the data type included in the second attribute information of the second mesh is completely consistent with the data type included in the first attribute information of the first mesh, that is, the second attribute information also includes vertex coordinates (vertex), normal (normal), texture coordinates (uv), triangle sequence (triangle) and other information.
[0138] In an exemplary embodiment, referring to Figure 4The first attribute information may include vertex coordinates of multiple vertices of the first mesh and texture coordinates corresponding to the multiple vertices of the first mesh, and the second attribute information may include vertex coordinates of multiple vertices of the second mesh and texture coordinates corresponding to the multiple vertices of the second mesh. The setting module 903 is also used to generate vertex coordinates of multiple vertices of the second mesh corresponding to the mask image based on the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information.
[0139] Specifically, after obtaining the vertex coordinates of each vertex constituting the first mesh, the vertex coordinates of multiple vertices of the second mesh corresponding to the mask image can be recalculated using mathematical rules according to the mask parameter information set by the user and the vertex coordinates of the first mesh.
[0140] The setting module 903 is further used to generate texture coordinates corresponding to multiple vertices of the second mesh corresponding to the mask image according to the texture coordinates corresponding to multiple vertices of the first mesh and the mask parameter information.
[0141] Specifically, after the texture coordinates of each vertex constituting the first mesh are obtained, the texture coordinates of multiple vertices of the second mesh corresponding to the mask image can be recalculated using mathematical rules based on the mask parameter information set by the user and the texture coordinates of each vertex of the first mesh.
[0142] It is understandable that when different mask processing is performed on the original image, the mask parameter information that the user needs to set is also different. In an exemplary embodiment, when the original image needs to be subjected to rectangular mask processing, the user can set the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, and the ratio of the right mask of the original image in the mask parameter setting interface, that is, the mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, and the ratio of the right mask of the original image. The vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0143] Vertex coordinates of multiple vertices of the second mesh are determined according to vertex coordinates of multiple vertices of the first mesh, a ratio of the upper mask, a ratio of the lower mask, a ratio of the left mask, and a ratio of the right mask.
[0144] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0145] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask and the ratio of the right mask.
[0146] Specifically, refer to Figure 5 , assuming that the width and height of the original image are both 1, the ratio of the upper mask is T, the ratio of the lower mask is B, the ratio of the left mask is L, and the ratio of the right mask is R.
[0147] Since the original image is displayed in mesh mode, when the original image is masked, the coordinates of the four vertices contained in the first mesh corresponding to the original image can be obtained, which are: the coordinates of the upper left vertex are (1,0), the coordinates of the upper right vertex are (1,1), the coordinates of the lower left vertex are (0,0), and the coordinates of the lower right vertex are (1,0). In addition, the texture coordinates of the four vertices contained in the first mesh corresponding to the original image are: the texture coordinates of the upper left vertex are (1,0), the texture coordinates of the upper right vertex are (1,1), the texture coordinates of the lower left vertex are (0,0), and the texture coordinates of the lower right vertex are (1,0).
[0148] After obtaining the vertex coordinates of multiple vertices of the first grid, the proportion T of the upper mask, the proportion B of the lower mask, the proportion L of the left mask and the proportion R of the right mask, according to mathematical rules, the coordinates of the four vertices of the second grid corresponding to the mask image obtained after rectangular masking of the original image are: the coordinates of the upper left vertex are (L, 1-T), the coordinates of the upper right vertex are (1-R, 1-T), the coordinates of the lower left vertex are (L, B), and the coordinates of the lower right vertex are (1-R, B).
[0149] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, and the ratio R of the right mask, it can be known according to mathematical rules that the texture coordinates of the four vertices of the second mesh corresponding to the mask image obtained after rectangular masking of the original image are as follows: the texture coordinates of the upper left vertex are (L, 1-T), the texture coordinates of the upper right vertex are (1-R, 1-T), the texture coordinates of the lower left vertex are (L, B), and the texture coordinates of the lower right vertex are (1-R, B). Exemplarily, the mask image obtained after rectangular masking of the original image is as follows Figure 6 shown.
[0150] In another exemplary embodiment, when the original image needs to be processed with a parallelogram mask, the user can set the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction in the mask parameter setting interface, that is, the mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction. Then, the vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0151] Determine the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask, the ratio of the right mask, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction;
[0152] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0153] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the proportion of the upper mask, the proportion of the lower mask, the proportion of the left mask, the proportion of the right mask, the horizontal tilt value of the mask and the vertical tilt value of the mask.
[0154] Specifically, refer to Figure 5 , assuming that the width and height of the original image are both 1, the ratio of the upper mask is T, the ratio of the lower mask is B, the ratio of the left mask is L, and the ratio of the right mask is R, the tilt value of the mask in the horizontal direction is H, and the tilt value of the mask in the vertical direction is V.
[0155] The parallelogram mask processing performed on the original image can be regarded as the image obtained after the rectangular mask processing is performed on the original image, and then the mask is tilted in the horizontal direction and tilted in the vertical direction.
[0156] After obtaining the vertex coordinates of multiple vertices of the first grid, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, the ratio R of the right mask, the horizontal tilt value of the mask is H, and the vertical tilt value of the mask is V, according to mathematical rules, the coordinates of the four vertices of the second grid corresponding to the mask image obtained after parallelogram masking of the original image are: the coordinates of the upper left vertex are (L+H, 1-TV), the coordinates of the upper right vertex are (1-R+H, 1-T+V), the coordinates of the lower left vertex are (LH, BV), and the coordinates of the lower right vertex are (1-RH, B+V).
[0157] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the ratio T of the upper mask, the ratio B of the lower mask, the ratio L of the left mask, the ratio R of the right mask, the horizontal tilt value of the mask H, and the vertical tilt value of the mask V, it can be known according to mathematical rules that the texture coordinates of the four vertices of the second mesh corresponding to the mask image obtained after parallelogram masking of the original image are as follows: the texture coordinates of the upper left vertex are (L+H, 1-TV), the texture coordinates of the upper right vertex are (1-R+H, 1-T+V), the texture coordinates of the lower left vertex are (LH, BV), and the texture coordinates of the lower right vertex are (1-RH, B+V). Exemplarily, the mask image obtained after parallelogram masking of the original image is as follows Figure 7 shown.
[0158] In another exemplary embodiment, when the original image needs to be processed with a rounded corner mask, the user can set the radius of the rounded rectangle and the smoothness of the rounded rectangle in the mask parameter setting interface, that is, the mask parameter information includes the radius of the rounded rectangle and the smoothness of the rounded rectangle, and the vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include:
[0159] Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a radius of the rounded rectangle, and a smoothness of the rounded rectangle;
[0160] The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises:
[0161] The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle.
[0162] Specifically, assume that the width and height of the original image are both 1, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4. When the original image is masked with a rounded rectangle, it can be regarded as dividing the masked image obtained after the original image is processed with the rounded rectangle into the following Figure 8 The image shown includes three groups of rectangles in the middle and rounded rectangular areas in the four corners. In the prior art, Unity draws the rounded rectangle by dividing it into several triangles of the same size. Therefore, in this embodiment, when the original image is subjected to rounded rectangular masking, the original image can be decomposed into the rounded rectangular area consisting of the three groups of rectangles in the middle and four groups of several triangles.
[0163] In addition, in this embodiment, since the number of triangles that can be divided into each rounded rectangular area is determined by the smoothness of the rounded rectangle, after obtaining the smoothness of the rounded rectangle, it is first necessary to determine the number of vertices of the second grid based on the smoothness of the rounded rectangle and a preset formula, wherein the preset formula is: the number of vertices of the second grid obtained after the original image is masked with a rounded rectangle = 4*(smoothness of the rounded rectangle+2), that is, if the number of triangles divided into the rounded rectangular area is 4, the number of vertices of the second grid obtained after the original image is masked with a rounded rectangle is: (4+2)*4=24, and the angle α of the triangle is = 90° / 4=22.5°.
[0164] Exemplarily, after obtaining the texture coordinates of multiple vertices of the first mesh, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4, according to mathematical rules, the texture coordinates of the 24 vertices of the second mesh corresponding to the mask image obtained after the rounded rectangle processing of the original image are respectively:
[0165] The coordinates of the four vertices of the middle rectangle are: the coordinates of the upper left vertex are (0.2,1), the coordinates of the upper right vertex are (0.8,1), the coordinates of the lower left vertex are (0.2,0), and the coordinates of the lower right vertex are (0.8,0).
[0166] The coordinates of the four vertices of the rectangle on the left are: the coordinates of the upper left vertex are (0,0.8), the coordinates of the upper right vertex are (0.2,0.8), the coordinates of the lower left vertex are (0,0.2), and the coordinates of the lower right vertex are (0.2,0.2).
[0167] The coordinates of the four vertices of the rectangle on the right are: the coordinates of the upper left vertex are (0.8, 0.8), the coordinates of the upper right vertex are (1, 0.8), the coordinates of the lower left vertex are (0.8, 0.2), and the coordinates of the lower right vertex are (1, 0.2).
[0168] The coordinates of the three vertices (vertex 1, vertex 2, vertex 3) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper left corner are (0.2-0.2*cosα,0.8+0.2*sinα), (0.2-0.2*cos2α,0.8+0.2*sin2α), and (0.2-0.2*cos3α,0.8+0.2*sin3α) respectively.
[0169] The coordinates of the three vertices (vertex 4, vertex 5, vertex 6) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper right corner are (0.8+0.2*cosα,0.8+0.2*sinα), (0.8+0.2*cos2α,0.8+0.2*sin2α), and (0.8+0.2*cos3α,0.8+0.2*sin3α) respectively.
[0170] The coordinates of the three vertices (vertex 7, vertex 8, vertex 9) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower left corner are (0.2-0.2*cosα, 0.2-0.2*sinα), (0.2-0.2*cos2α, 0.2-0.2*sin2α), and (0.2-0.2*cos3α, 0.2-0.2*sin3α) respectively.
[0171] The coordinates of the three vertices (vertex 10, vertex 11, vertex 12) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower right corner are (0.8+0.2*cosα,0.2-0.2*sinα), (0.8+0.2*cos2α,0.2-0.2*sin2α), and (0.8+0.2*cos3α,0.2-0.2*sin3α) respectively.
[0172] Similarly, after obtaining the texture coordinates of multiple vertices of the first mesh, the radius of the rounded rectangle is 0.2, and the smoothness of the rounded rectangle is 4, according to mathematical rules, the texture coordinates of the 24 vertices of the second mesh corresponding to the mask image obtained after the rounded mask processing of the original image are respectively:
[0173] The texture coordinates of the four vertices of the middle rectangle are: the texture coordinate of the upper left vertex is (0.2,1), the texture coordinate of the upper right vertex is (0.8,1), the texture coordinate of the lower left vertex is (0.2,0), and the texture coordinate of the lower right vertex is (0.8,0).
[0174] The texture coordinates of the four vertices of the left rectangle are: the texture coordinates of the upper left vertex are (0,0.8), the texture coordinates of the upper right vertex are (0.2,0.8), the texture coordinates of the lower left vertex are (0,0.2), and the texture coordinates of the lower right vertex are (0.2,0.2).
[0175] The texture coordinates of the four vertices of the rectangle on the right are: the texture coordinates of the upper left vertex are (0.8, 0.8), the texture coordinates of the upper right vertex are (1, 0.8), the texture coordinates of the lower left vertex are (0.8, 0.2), and the texture coordinates of the lower right vertex are (1, 0.2).
[0176] The texture coordinates of the three vertices (vertex 1, vertex 2, vertex 3) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper left corner are (0.2-0.2*cosα,0.8+0.2*sinα), (0.2-0.2*cos2α,0.8+0.2*sin2α), and (0.2-0.2*cos3α,0.8+0.2*sin3α) respectively.
[0177] The texture coordinates of the three vertices (vertex 4, vertex 5, vertex 6) whose vertex coordinates have not yet been calculated and are included in the rounded area in the upper right corner are (0.8+0.2*cosα,0.8+0.2*sinα), (0.8+0.2*cos2α,0.8+0.2*sin2α), and (0.8+0.2*cos3α,0.8+0.2*sin3α) respectively.
[0178] The texture coordinates of the three vertices (vertex 7, vertex 8, vertex 9) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower left corner are (0.2-0.2*cosα, 0.2-0.2*sinα), (0.2-0.2*cos2α, 0.2-0.2*sin2α), and (0.2-0.2*cos3α, 0.2-0.2*sin3α) respectively.
[0179] The texture coordinates of the three vertices (vertex 10, vertex 11, vertex 12) whose vertex coordinates have not yet been calculated and are included in the rounded area in the lower right corner are (0.8+0.2*cosα,0.2-0.2*sinα), (0.8+0.2*cos2α,0.2-0.2*sin2α), and (0.8+0.2*cos3α,0.2-0.2*sin3α) respectively.
[0180] In this embodiment, when the original image is subjected to rectangular mask processing, the vertex coordinates and texture coordinates of the second mesh corresponding to the mask image can be calculated based on the mask parameter information set by the user and the vertex coordinates and texture coordinates of each vertex of the first mesh, so that the second mesh can be subsequently rendered based on the vertex coordinates and texture coordinates of the second mesh to obtain the mask image obtained after the rectangular mask processing of the original image, without the need to calculate and process all the texture data of the original image, thereby saving calculation amount and improving display speed.
[0181] The rendering module 904 is used to obtain the texture corresponding to the original image, and render the second grid according to the texture and the second attribute information to display the mask image.
[0182] Specifically, the second attribute information includes vertex coordinates and texture coordinates of each vertex constituting the second mesh, as well as attribute information such as a triangle sequence (triangle) composed of each vertex.
[0183] Therefore, after obtaining these attribute information, a second grid can be created based on these attribute information, and then the texture area corresponding to the original image is sampled according to the texture coordinates in the second grid, and the second grid is rendered according to the sampled texture to display the mask image.
[0184] In the embodiment of the present invention, the second attribute information of the second grid corresponding to the mask image obtained after mask processing is determined based on the mask parameter information set by the user and the first attribute information of the first grid corresponding to the original image, and then the mask image is generated based on the second attribute information of the second grid and the texture corresponding to the original image. This eliminates the need to calculate and process all texture data of the original image and the mask image, thereby saving calculation amount and improving display speed.
[0185] Fig.10 The hardware architecture diagram of a computer device 10 suitable for implementing the mask image display method according to an embodiment of the present application is schematically shown. In this embodiment, the computer device 10 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. For example, it can be a tablet computer, a laptop computer, a desktop computer, 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. Fig.10 As shown, the computer device 10 includes at least but is not limited to: a memory 901, a processor 902, and a network interface 903 that can communicate with each other through a system bus. Among them:
[0186] The memory 901 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, 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, disk, optical disk, etc. In some embodiments, the memory 901 can be an internal storage module of the computer device 10, such as a hard disk or memory of the computer device 10. In other embodiments, the memory 901 can also be an external storage device of the computer device 10, such as a plug-in hard disk equipped on the computer device 10, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card (FlashCard), etc. Of course, the memory 901 can also include both the internal storage module of the computer device 10 and its external storage device. In this embodiment, the memory 901 is generally used to store the operating system and various application software installed on the computer device 10, such as the program code of the mask image display method, etc. In addition, the memory 901 can also be used to temporarily store various types of data that have been output or are to be output.
[0187] In some embodiments, the processor 902 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 902 is generally used to control the overall operation of the computer device 10, such as performing control and processing related to data interaction or communication with the computer device 10. In this embodiment, the processor 902 is used to run the program code stored in the memory 901 or process data.
[0188] The network interface 903 may include a wireless network interface or a wired network interface, and the network interface 903 is generally used to establish a communication link between the computer device 10 and other computer devices. For example, the network interface 903 is used to connect the computer device 10 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10 and the external terminal. The network can be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0189] It should be pointed out that Fig.10 Only a computer device having components 901 to 903 is shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0190] In this embodiment, the mask image display method stored in the memory 901 can also be divided into one or more program modules and executed by one or more processors (processor 902 in this embodiment) to complete the present application.
[0191] An embodiment of the present application provides a non-volatile computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the mask image display method in the embodiment are implemented.
[0192] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, 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, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on the computer device, such as the program code of the mask image display method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0193] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on at least two network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present application. Those of ordinary skill in the art may understand and implement them without creative effort.
[0194] Through the description of the above implementation methods, a person of ordinary skill in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0195] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A mask image display method, characterized in that: include: Receiving a mask instruction triggered by a user based on the original image, wherein the mask instruction carries mask parameter information; Acquire first attribute information of a first grid corresponding to the original image according to the mask instruction; Generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information; Acquire a texture corresponding to the original image, and render the second grid according to the texture and the second attribute information to display the mask image; The first attribute information includes: vertex coordinates, normals, texture coordinates and triangle sequence.
2. The mask image display method according to claim 1, characterized in that: The mask image display further includes: A mask parameter setting interface is displayed, so that the user can set the mask parameter information based on the parameter setting interface.
3. The mask image display method according to claim 1, characterized in that: The first attribute information includes vertex coordinates of multiple vertices of the first mesh and texture coordinates corresponding to the multiple vertices of the first mesh, the second attribute information includes vertex coordinates of multiple vertices of the second mesh and texture coordinates corresponding to the multiple vertices of the second mesh, and the second attribute information of the second mesh corresponding to the mask image generated according to the first attribute information and the mask parameter information includes: Generate vertex coordinates of a plurality of vertices of a second mesh corresponding to the mask image according to the vertex coordinates of a plurality of vertices of the first mesh and the mask parameter information; The texture coordinates corresponding to the multiple vertices of the second mesh corresponding to the mask image are generated according to the texture coordinates corresponding to the multiple vertices of the first mesh and the mask parameter information.
4. The mask image display method according to claim 3, characterized in that: The mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, and the ratio of the right mask of the original image. The vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image are generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information, including: Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a ratio of the upper mask, a ratio of the lower mask, a ratio of the left mask, and a ratio of the right mask; The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises: The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask and the ratio of the right mask.
5. The mask image display method according to claim 3, characterized in that: The mask parameter information includes the ratio of the upper mask of the original image, the ratio of the lower mask of the original image, the ratio of the left mask of the original image, the ratio of the right mask of the original image, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction. The vertex coordinates of the multiple vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the multiple vertices of the first mesh and the mask parameter information include: Determine the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the ratio of the upper mask, the ratio of the lower mask, the ratio of the left mask, the ratio of the right mask, the tilt value of the mask in the horizontal direction, and the tilt value of the mask in the vertical direction; The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises: The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the proportion of the upper mask, the proportion of the lower mask, the proportion of the left mask, the proportion of the right mask, the horizontal tilt value of the mask and the vertical tilt value of the mask.
6. The mask image display method according to claim 3, characterized in that: The mask parameter information includes a radius of a rounded rectangle and a smoothness of the rounded rectangle, and the vertex coordinates of the plurality of vertices of the second mesh corresponding to the mask image generated according to the vertex coordinates of the plurality of vertices of the first mesh and the mask parameter information include: Determining vertex coordinates of a plurality of vertices of the second mesh according to vertex coordinates of a plurality of vertices of the first mesh, a radius of the rounded rectangle, and a smoothness of the rounded rectangle; The step of generating texture coordinates corresponding to a plurality of vertices of a second mesh corresponding to a mask image according to the texture coordinates corresponding to a plurality of vertices of the first mesh and the mask parameter information comprises: The texture coordinates corresponding to the multiple vertices of the second mesh are determined according to the texture coordinates corresponding to the multiple vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle.
7. The mask image display method according to claim 6, characterized in that: Before the step of determining the vertex coordinates of the plurality of vertices of the second mesh according to the vertex coordinates of the plurality of vertices of the first mesh, the radius of the rounded rectangle, and the smoothness of the rounded rectangle, the method further includes: The number of vertices of the second mesh is determined according to the smoothness of the rounded rectangle and a preset formula.
8. A mask image display device, characterized in that: include: A receiving module, used for receiving a mask instruction triggered by a user based on an original image, wherein the mask instruction carries mask parameter information; An acquisition module, configured to acquire first attribute information of a first mesh corresponding to the original image according to the mask instruction, wherein the first attribute information includes: vertex coordinates, normals, texture coordinates, and a triangle sequence; A generating module, configured to generate second attribute information of a second grid corresponding to the mask image according to the first attribute information and the mask parameter information; A rendering module is used to obtain a texture corresponding to the original image, and render the second grid according to the texture and the second attribute information to display the mask image.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the mask image display method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the mask image display method according to any one of claims 1 to 7 are implemented.
11. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
