Image perspective transformation method and device, electronic equipment and computer storage medium
By directly determining the perspective transformation matrix of the Y channel of the YUV image and modifying the U and V channel matrices, the complexity of the perspective transformation process of YUV images is solved, achieving efficient image processing and reducing resource consumption and time costs.
Patent Information
- Application Number
- CN202210322776.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-29
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-03-29
AI Technical Summary
In existing technologies, the perspective transformation process of YUV images is complex and requires color space transformation, resulting in low efficiency, especially causing unnecessary resource consumption in resource-constrained terminal devices.
By directly determining the perspective transformation matrix of the Y channel in the YUV image and modifying the perspective transformation matrices of the U and V channels according to the sampling format, the additional color space transformation process is avoided, and the perspective transformation of the YUV image is performed directly.
It improves the efficiency of perspective transformation and reduces the consumption of storage and computing resources. In particular, it significantly improves the processing speed when implementing perspective transformation of YUV images on mobile terminals.
Smart Images

Figure CN114926321B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to, but is not limited to, computer vision processing technology, and in particular to an image perspective transformation method and device, an electronic device and a computer storage medium. BACKGROUND
[0002] Perspective transformation is a common image mapping transformation technique in the field of robot vision, and the specific implementation of perspective transformation is: using the principle that the perspective center, the image point and the target point are collinear, the imaging is projected from one view plane to another view plane. Perspective transformation is also called projection mapping, which is usually described in the form of matrix multiplication, that is, multiplying the perspective transformation matrix and the input matrix to obtain the output matrix; wherein the input matrix represents the original view plane image, the perspective transformation matrix is used to represent the conversion relationship between the view planes, and the output matrix represents the new view plane image, and the calculation logic of perspective transformation is clear and simple. OpenCV can provide the implementation of perspective transformation, and perspective transformation can be implemented on various computing platforms such as central processing unit (CPU) and graphics processing unit (GPU).
[0003] In related technologies, in order to realize the perspective transformation of the YUV image, the YUV image needs to be color space transformed to obtain a red green blue (RGB) image, and after the RGB image is processed by perspective transformation, the RGB image processed by perspective transformation is color space transformed to obtain a corresponding YUV image. It can be seen that the implementation process of the perspective transformation of the YUV image is relatively complex, which reduces the efficiency of the perspective transformation. SUMMARY
[0004] The present disclosure provides at least an image perspective transformation method, device, electronic device and computer storage medium.
[0005] The present disclosure provides an image perspective transformation method, which can include: obtaining a YUV image and a sampling format of the YUV image; determining a perspective transformation matrix of a Y channel in the YUV image according to a first mapping relationship; the first mapping relationship is used to represent the coordinate mapping relationship between at least four pairs of pixel points between the YUV image and a target image; determining a perspective transformation matrix of a U channel and a perspective transformation matrix of a V channel in the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image; performing perspective transformation on the YUV image according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel to obtain the target image.
[0006] In some embodiments, the perspective transformation matrix of the Y channel includes a first type of element for implementing image linear transformation, a second type of element for implementing pixel coordinate translation, and a third type of element for implementing three-dimensional space transformation of the image. According to the roles of the various types of elements in the perspective transformation matrix of the Y channel, the element transformation relationship between the perspective transformation matrices of different channels can be accurately determined in the embodiments of the present disclosure. Furthermore, according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be accurately determined.
[0007] In some embodiments, the determining the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel of the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image includes: modifying the second type of element and the third type of element in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image to obtain a modified perspective transformation matrix; and determining the modified perspective transformation matrix as the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel.
[0008] As can be seen, the embodiments of the present disclosure can more easily derive the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel by modifying the second type of element and the third type of element in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of perspective transformation is further improved.
[0009] In some embodiments, the second type of element in the perspective transformation matrix of the Y channel has a first value, and the third type of element in the perspective transformation matrix of the Y channel has a second value. The modifying the second type of element and the third type of element in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image includes: in response to the sampling format of the YUV image being a YUV420 sampling format, modifying the first value of the second type of element to half of the first value, and modifying the second value of the third type of element to twice the second value.
[0010] It can be seen that the embodiment of the present disclosure can be applied to the YUV image in the YUV420 sampling format, and the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of the perspective transformation is further improved.
[0011] In some embodiments, the perspective transformation matrix of the Y channel is a 3*3 matrix, the first type of elements include the element of the first row and the first column, the element of the first row and the second column, the element of the second row and the first column, and the element of the second row and the second column; the second type of elements include the element of the first row and the third column and the element of the second row and the third column, and the third type of elements include the element of the third row and the first column and the element of the third row and the second column. It can be seen that since two transformation relationships can be determined according to each pair of pixel points, and the number of the first type of elements, the second type of elements and the third type of elements is eight, in the case that the other elements of the perspective transformation matrix of the Y channel except the first type of elements, the second type of elements and the third type of elements are known elements, the first type of elements, the second type of elements and the third type of elements of the perspective transformation matrix of the Y channel can be accurately solved according to the coordinate mapping relationship between at least four pairs of pixel points, that is, the perspective transformation matrix of the Y channel can be accurately obtained.
[0012] In some embodiments, the method further comprises: determining a first region in the Y channel image of the YUV image, the first region being a quadrilateral region; determining a second region corresponding to the first region, the second region being a quadrilateral region, and four vertices of the second region forming a one-to-one correspondence relationship with four vertices of the first region; in response to determining the second region as a region in the Y channel image of the target image, determining the first mapping relationship between four pairs of pixel points according to the correspondence relationship between the four vertices of the second region and the four vertices of the first region, each pair of pixel points in the four pairs of pixel points including a pair of vertices forming the correspondence relationship in the first region and the second region.
[0013] It can be seen that the embodiment of the present disclosure can accurately determine the first mapping relationship according to the known first region and the second region when the second region is taken as a region in the Y channel image of the target image, thereby facilitating the subsequent accurate determination of the perspective transformation matrix of the Y channel, and further facilitating the accurate implementation of the perspective transformation of the YUV image.
[0014] In some embodiments, the determining, according to the predetermined first mapping relationship, the perspective transformation matrix of the Y channel in the YUV image comprises: determining, for the at least four pairs of pixel points, a first transformation relationship between the horizontal coordinates of each pair of pixel points and a second transformation relationship between the vertical coordinates of the each pair of pixel points; and determining the perspective transformation matrix of the Y channel according to the first transformation relationship and the second transformation relationship. It can be seen that the perspective transformation matrix of the Y channel can be accurately determined according to the coordinate transformation relationship between each pair of pixel points, thereby facilitating accurate implementation of the perspective transformation of the YUV image.
[0015] The embodiments of the present disclosure further provide an image perspective transformation device, which can comprise an acquisition module, a determination module and a processing module. The acquisition module is configured to acquire a YUV image and a sampling format of the YUV image. The determination module is configured to determine, according to a predetermined first mapping relationship, a perspective transformation matrix of a Y channel in the YUV image. The first mapping relationship is used to represent a coordinate mapping relationship between at least four pairs of pixel points between the YUV image and a target image. The determination module is further configured to determine, according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, a perspective transformation matrix of a U channel and a perspective transformation matrix of a V channel in the YUV image. The processing module is configured to perform perspective transformation on the YUV image according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel, to obtain the target image.
[0016] It can be seen that the perspective transformation matrix of the Y channel can be determined first, and then the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be determined according to the perspective transformation matrix of the Y channel, so that the YUV image can be directly subjected to perspective transformation according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel. Since the process of implementing additional color space transformation is not required, the implementation process of the perspective transformation of the YUV image is relatively simple, and the efficiency of the perspective transformation is improved.
[0017] In some embodiments, the perspective transformation matrix of the Y channel comprises a first type of element used to implement image linear transformation, a second type of element used to implement pixel point coordinate translation, and a third type of element used to implement three-dimensional space transformation of the image.
[0018] In the embodiments of the present disclosure, according to the roles of the various types of elements in the perspective transformation matrix of the Y channel, the element transformation relationship between the perspective transformation matrices of different channels can be accurately determined, and then the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be accurately determined according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image.
[0019] In some embodiments, the determining module 502 is configured to determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel of the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, including: modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image to obtain a modified perspective transformation matrix; and determining the modified perspective transformation matrix as the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel.
[0020] It can be seen that, in the embodiments of the present disclosure, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and thus the efficiency of perspective transformation is improved.
[0021] In some embodiments, the second type of elements in the perspective transformation matrix of the Y channel has a first value, and the third type of elements in the perspective transformation matrix of the Y channel has a second value. The determining module 502 is configured to modify the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image, including: in response to the sampling format of the YUV image being YUV420 sampling format, modifying the first value of the second type of elements to half of the first value, and modifying the second value of the third type of elements to twice the second value.
[0022] It can be seen that, in the embodiments of the present disclosure, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel for the YUV image in YUV420 sampling format. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and thus the efficiency of perspective transformation is improved.
[0023] In some embodiments, the perspective transformation matrix of the Y channel is a 3*3 matrix, the first type of elements include an element in the first row and the first column, an element in the first row and the second column, an element in the second row and the first column, and an element in the second row and the second column; the second type of elements include an element in the first row and the third column and an element in the second row and the third column; and the third type of elements include an element in the third row and the first column and an element in the third row and the second column.
[0024] It can be seen that, since two transformation relationships can be determined according to each pair of pixel points, and the number of the first type of elements, the second type of elements and the third type of elements is eight, in the case that other elements of the perspective transformation matrix of the Y channel except the first type of elements, the second type of elements and the third type of elements are known elements, the first type of elements, the second type of elements and the third type of elements of the perspective transformation matrix of the Y channel can be accurately solved according to the coordinate mapping relationship between at least four pairs of pixel points, that is, the perspective transformation matrix of the Y channel can be accurately obtained.
[0025] In some embodiments, the determining module 502 is further configured to: determine a first region in the Y channel image of the YUV image, the first region being a quadrilateral region; determine a second region corresponding to the first region, the second region being a quadrilateral region, and four vertices of the second region forming a one-to-one correspondence with four vertices of the first region; in response to determining the second region as a region in the Y channel image of the target image, determine the first mapping relationship between four pairs of pixel points according to the correspondence between the four vertices of the second region and the four vertices of the first region, each pair of pixel points in the four pairs of pixel points including a pair of vertices forming the correspondence in the first region and the second region.
[0026] It can be seen that, according to the known first region and the second region, the first mapping relationship can be accurately determined when the second region is taken as a region in the Y channel image of the target image, thereby facilitating the subsequent accurate determination of the perspective transformation matrix of the Y channel, and further facilitating the accurate implementation of the perspective transformation of the YUV image.
[0027] In some embodiments, the determining module is configured to determine the perspective transformation matrix of the Y channel of the YUV image according to the predetermined first mapping relationship, including: determining, for the at least four pairs of pixel points, a first transformation relationship between the horizontal coordinates of each pair of pixel points and a second transformation relationship between the vertical coordinates of the each pair of pixel points; and determining the perspective transformation matrix of the Y channel according to the first transformation relationship and the second transformation relationship.
[0028] It can be seen that, according to the coordinate transformation relationship between each pair of pixel points, the perspective transformation matrix of the Y channel can be accurately determined, thereby facilitating the accurate implementation of the perspective transformation of the YUV image.
[0029] Embodiments of the present disclosure also provide an electronic device, which includes a processor and a memory for storing a computer program capable of running on the processor; wherein the processor is configured to run the computer program to perform any of the above image perspective transformation methods.
[0030] In some embodiments, the electronic device is a mobile terminal.
[0031] The embodiment of the present disclosure further provides a computer storage medium, which stores a computer program, and the computer program is executed by a processor to implement any one of the image perspective transformation methods.
[0032] It can be seen that the embodiment of the present disclosure can first determine the perspective transformation matrix of the Y channel, then determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel according to the perspective transformation matrix of the Y channel, and thus according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel, the YUV image can be directly subjected to perspective transformation. Since the process of implementing additional color space transformation is not required, the implementation process of the perspective transformation for the YUV image is relatively simple, the efficiency of the perspective transformation is improved, the consumption of storage resources and computing resources can be reduced to a certain extent, and the time cost of the perspective transformation can be reduced. In the case of implementing the perspective transformation of the YUV image by using a mobile terminal such as a mobile phone, the efficiency of the perspective transformation can be improved.
[0033] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, rather than limiting the technical solutions of the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0034] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present disclosure and, together with the specification, serve to explain the technical solutions of the present disclosure.
[0035] Figure 1 A flowchart of an image perspective transformation method according to an embodiment of the present disclosure;
[0036] Figure 2 A flowchart of determining a first mapping relationship according to an embodiment of the present disclosure;
[0037] Figure 3 A flowchart of determining a perspective transformation matrix of a Y channel in a YUV image according to an embodiment of the present disclosure;
[0038] Figure 4 A flowchart of determining a perspective transformation matrix of a U channel and a perspective transformation matrix of a V channel according to an embodiment of the present disclosure;
[0039] Figure 5 A structural schematic diagram of an image perspective transformation device according to an embodiment of the present disclosure;
[0040] Figure 6 A hardware entity schematic diagram of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0041] In order to make the objectives, technical solutions and advantages of the present disclosure clearer, the technical solutions of the present disclosure are further described in detail below with reference to the drawings and embodiments. The described embodiments should not be regarded as limitations of the present disclosure, and all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present disclosure.
[0042] In the following description, "some embodiments" are described, which describe a subset of all possible embodiments, but it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0043] The terms "first / second / third" involved are only to distinguish similar objects, and do not represent a specific order of the objects. It can be understood that "first / second / third" can be interchanged with a specific order or sequence as allowed, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0044] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present disclosure belongs. The terms used herein are only for the purpose of describing the present disclosure and are not intended to limit the present disclosure.
[0045] In order to better understand the image perspective transformation method provided by the embodiments of the present disclosure, the image perspective transformation method used in the related art will be described first.
[0046] In the related art, the perspective transformation of an image is only applicable to RGB or blue-green-red (BGR) images; in order to realize the perspective transformation of a YUV image, color space transformation can be performed on the YUV image to obtain an RGB or BGR image, then the perspective transformation can be performed on the RGB or BGR image to obtain an RGB or BGR image after perspective transformation, and color space transformation can be performed on the RGB or BGR image after perspective transformation to obtain a corresponding YUV image. It can be seen that in order to realize the perspective transformation of a YUV image, two color space transformations are required, which causes additional storage and time overhead. Since the perspective transformation of a YUV image is usually realized by using a terminal-side device such as a mobile phone with limited storage and performance, the additional color space conversion process will cause unnecessary resource consumption of the terminal-side device.
[0047] The embodiment of the present disclosure provides a perspective transformation method of an image, which can be executed by a processor of an electronic device. The electronic device can be a server, a notebook computer, a tablet computer, a desktop computer, a smart television, a set-top box, a mobile device (such as a mobile phone, a portable video player, a personal digital assistant, a dedicated messaging device, a portable game device) or the like.
[0048] Figure 1 A flowchart of the perspective transformation method of the image according to the embodiment of the present disclosure is shown in Figure 1 The flowchart can include the following steps:
[0049] Step 101: Obtain a YUV image and a sampling format of the YUV image.
[0050] In some embodiments, the YUV image can be a planar YUV format image or a packed YUV format image. The planar YUV format is to store Y channel data of each pixel point first, then store U channel data of each pixel point, and finally store V channel data of each pixel point. The packed YUV format is to store Y channel data, U channel data and V channel data of each pixel point continuously and alternately. The Y channel data of the pixel point can also be referred to as the Y value of the pixel point, the U channel data of the pixel point can also be referred to as the U value of the pixel point, and the V channel data of the pixel point can also be referred to as the V value of the pixel point.
[0051] In some embodiments, the sampling format of the YUV image can be YUV420 sampling format, YUV444 sampling format or YUV422 sampling format. For the YUV444 sampling format image, the sampling rate of the Y channel is the same as that of the UV channel, and each Y channel data corresponds to a group of UV channel data; for the YUV422 sampling format image, the sampling rate of the Y channel is different from that of the UV channel, and each two Y channel data share a group of UV channel data; for the YUV420 sampling format image, the sampling rate of the Y channel is different from that of the UV channel, and each four Y channel data share a group of UV channel data.
[0052] In actual application, the YUV image can be obtained from a local storage space or a network, or the YUV image can be collected by using an image collection device such as a camera.
[0053] Step 102: Determine a perspective transformation matrix of the Y channel in the YUV image according to a predetermined first mapping relationship; the first mapping relationship is used to represent a coordinate mapping relationship between at least four pairs of pixel points between the YUV image and a target image.
[0054] It should be noted that the target image is an unknown image before the perspective transformation of the YUV image is performed. In actual applications, at least four pixel points can be determined in the YUV image, a first region formed by the at least four pixel points can be determined, a second region corresponding to the first region can be determined in advance, and the four vertices of the second region and the four vertices of the first region form a one-to-one correspondence. Then, the second region can be determined as a region in the Y channel image of the target image, so that the first mapping relationship can be determined. It can be seen that, in order to determine the first mapping relationship, the target image does not need to be obtained in advance, but the second region corresponding to the first region can be determined as a region in the Y channel image of the target image.
[0055] Here, the second region can be set according to actual requirements, and the first mapping relationship can be determined according to the vertex coordinates of the known first region and the vertex coordinates of the known second region.
[0056] In the embodiment of the present disclosure, the target image is an image obtained after the perspective transformation of the YUV image is performed. In the YUV image, the Y channel represents the brightness of the image, so the Y channel image is taken as a grayscale image, and the conversion relationship between the Y channel image of the YUV image before the perspective transformation and the Y channel image of the YUV image after the perspective transformation is determined according to the first mapping relationship, that is, the perspective transformation matrix of the Y channel in the YUV image can be determined.
[0057] Step 103: determining the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image.
[0058] It can be understood that, since the sampling format of the YUV image can reflect the ratio of the sampling rate of the Y channel to the sampling rate of the U channel and the ratio of the sampling rate of the Y channel to the sampling rate of the V channel, after the perspective transformation matrix of the Y channel is determined, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image can be determined according to the fixed ratio of the sampling rate of the Y channel to the sampling rate of the U channel and the fixed ratio of the sampling rate of the Y channel to the sampling rate of the V channel.
[0059] Step 104: performing perspective transformation on the YUV image according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel to obtain a target image.
[0060] In the embodiments of the present disclosure, the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be adopted to perform perspective transformation on the Y channel data, the U channel data and the V channel data in the YUV image respectively, to obtain the perspective transformed Y channel data, the perspective transformed U channel data and the perspective transformed V channel data; the perspective transformed Y channel data, the perspective transformed U channel data and the perspective transformed V channel data can be combined to obtain the target image.
[0061] It can be seen that the embodiments of the present disclosure can first determine the perspective transformation matrix of the Y channel, and then determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel according to the perspective transformation matrix of the Y channel, so that the YUV image can be directly subjected to perspective transformation according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel; since the process of additional color space transformation is not required, the implementation process of the perspective transformation for the YUV image is relatively simple, the efficiency of the perspective transformation is improved, the consumption of storage resources and computing resources can be reduced to a certain extent, and the time cost of the perspective transformation can be reduced. In the case of implementing the perspective transformation of the YUV image by using a mobile terminal such as a mobile phone, the efficiency of the perspective transformation can be improved.
[0062] In some embodiments, with reference to Figure 2 , the process of determining the first mapping relationship can include the following steps:
[0063] Step 201: In the Y channel image of the YUV image, a first region is determined, and the first region is a quadrilateral region.
[0064] In the embodiments of the present disclosure, one quadrilateral region can be arbitrarily selected as the first region in the Y channel image of the YUV image. After the first region is determined, the image pixel coordinates of the four vertices of the first region can be determined.
[0065] Step 202: A second region corresponding to the first region is determined, the second region is a quadrilateral region, and the four vertices of the second region form a one-to-one correspondence with the four vertices of the first region.
[0066] In the embodiments of the present disclosure, in the process of perspective transformation, the image can be projected from the original view plane to the new view plane, so that after the first region in the original view plane is determined, the second region in the new view plane can be determined; after the second region is determined, the image pixel coordinates of the four vertices in the second region can be determined.
[0067] Step 203: in response to determining the second region as the region in the Y channel image of the target image, determining a first mapping relationship between four pairs of pixel points according to the correspondence between the four vertices of the second region and the four vertices of the first region, each pair of pixel points in the four pairs of pixel points including a pair of vertices forming the correspondence in the first region and the second region.
[0068] Here, the first mapping relationship can be determined according to the image pixel coordinates of the four vertices of the second region and the image pixel coordinates of the four vertices of the first region, and the correspondence between the four vertices of the second region and the four vertices of the first region.
[0069] It can be seen that the embodiments of the present disclosure can accurately determine the first mapping relationship according to the known first region and the second region when the second region is taken as the region in the Y channel image of the target image, thereby facilitating subsequent accurate determination of the perspective transformation matrix of the Y channel, and further facilitating accurate implementation of the perspective transformation of the YUV image.
[0070] In some embodiments, with reference to Figure 3 , the flow of determining the perspective transformation matrix of the Y channel in the YUV image can include the following steps:
[0071] Step 301: for at least four pairs of pixel points, determining a first transformation relationship between the horizontal coordinates of each pair of pixel points and a second transformation relationship between the vertical coordinates of each pair of pixel points.
[0072] Here, each pair of pixel points can include a first pixel point on the original view plane and a second pixel point on the new view plane; the image pixel coordinates of the first pixel point include a horizontal coordinate and a vertical coordinate, and the image pixel coordinates of the second pixel point include a horizontal coordinate and a vertical coordinate.
[0073] In some embodiments, the first transformation relationship between the horizontal coordinates of the first pixel point and the second pixel point can be represented by using unknown elements of the perspective transformation matrix of the Y channel; similarly, the second transformation relationship between the vertical coordinates of the first pixel point and the second pixel point can also be represented by using unknown elements of the perspective transformation matrix of the Y channel.
[0074] In some embodiments, the perspective transformation matrix of the Y channel is a 3*3 matrix, and the perspective transformation matrix of the Y channel can be denoted as matrix A, and the elements of the matrix A can be represented by formula (1).
[0075]
[0076] The perspective transformation process based on the matrix A can be represented by formula (2).
[0077]
[0078] wherein x and y respectively represent the horizontal coordinate and the vertical coordinate of the first pixel point, X, Y and Z respectively represent the three-dimensional coordinates of the three-dimensional space point obtained through the perspective transformation processing; the pixel point corresponding to the three-dimensional space point on the new view plane is a second pixel point, and the horizontal coordinate X' and the vertical coordinate Y' of the second pixel point can be calculated according to formula (3) and formula (4).
[0079]
[0080]
[0081] According to formula (1), formula (2), formula (3) and formula (4), the first transformation relationship shown in formula (5) and the second transformation relationship shown in formula (6) can be obtained.
[0082]
[0083]
[0084] In formula (5) and formula (6), a 11 , a 12 , a 13 , a 21 , a 22 , a 23 , a 31 , a 32 , a 33 There are unknown elements in each element of matrix A. 33 In some embodiments, in each element of matrix A, a 33 is a preset constant value, for example, the value of a 33 is 1. The elements in each element of matrix A except a 33 are unknown elements.
[0085] Step 302: determining the perspective transformation matrix of the Y channel according to the first transformation relationship and the second transformation relationship.
[0086] In the embodiments of the present disclosure, two transformation relationships can be determined according to each pair of pixel points, that is, the first transformation relationship and the second transformation relationship are determined, so that in the case that the number of pixel point pairs is sufficient, a sufficient number of transformation relationships can be determined to solve the unknown elements in the perspective transformation matrix of the Y channel; for example, for the above-mentioned matrix A, in the case that the number of pixel point pairs is greater than or equal to 4, the 8 unknown elements of the above-mentioned matrix A can be determined, and then according to the solving results of the 8 unknown elements of the above-mentioned matrix A and the element a 33 in matrix A, the calculation result of matrix A can be determined.
[0087] For example, the second region is a rectangular region, and position and size information of the rectangular region is known information. According to the pixel coordinates of the four pairs of pixel points in the second region and the first region, eight equations for solving eight unknown elements in the matrix A can be determined. By solving the eight equations, the matrix A can be calculated.
[0088] It can be seen that, according to the coordinate transformation relationship between each pair of pixel points, the perspective transformation matrix of the Y channel can be accurately determined, thereby facilitating accurate implementation of perspective transformation of the YUV image.
[0089] In some embodiments, the perspective transformation matrix of the Y channel includes first-type elements for implementing linear transformation of an image, second-type elements for implementing coordinate translation of a pixel point, and third-type elements for implementing three-dimensional space transformation of the image.
[0090] Here, the first-type elements can represent scaling, cropping, rotation and other operations of the image, the second-type elements can represent translation operations of the image, and the third-type elements are space transformation elements.
[0091] According to the effects of the various types of elements in the perspective transformation matrix of the Y channel, the element transformation relationship between the perspective transformation matrices of different channels can be accurately determined in the embodiments of the present disclosure. Furthermore, according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be accurately determined.
[0092] In some embodiments, the perspective transformation matrix of the Y channel is a 3*3 matrix, the first-type elements include an element in the first row and the first column, an element in the first row and the second column, an element in the second row and the first column, and an element in the second row and the second column; the second-type elements include an element in the first row and the third column and an element in the second row and the third column, and the third-type elements include an element in the third row and the first column and an element in the third row and the second column.
[0093] For example, for the matrix A, the first-type elements include a 11 , a 12 , a 21 and a 22 , the second-type elements include a 13 and a 23 , and the third-type elements include a 31 and a 32 .
[0094] It can be seen that, since two transformation relations can be determined according to each pair of pixel points, and the number of the first type of elements, the second type of elements and the third type of elements is eight, in the case that other elements of the perspective transformation matrix of the Y channel except the first type of elements, the second type of elements and the third type of elements are known elements, the first type of elements, the second type of elements and the third type of elements of the perspective transformation matrix of the Y channel can be accurately solved according to the coordinate mapping relations between at least four pairs of pixel points, that is, the perspective transformation matrix of the Y channel can be accurately obtained.
[0095] In some embodiments, with reference to Figure 4 , the implementation of step 103 can include the following steps:
[0096] Step 401: modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image, to obtain a modified perspective transformation matrix.
[0097] For example, for the above-mentioned matrix A, the first type of elements and a 33 are kept unchanged, and the second type of elements and the third type of elements in the matrix A are modified, to obtain a modified perspective transformation matrix.
[0098] Step 402: determining the modified perspective transformation matrix as the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel.
[0099] In the embodiments of the present disclosure, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel are the same perspective transformation matrix.
[0100] It can be seen that, in the embodiments of the present disclosure, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel, since it is not necessary to calculate the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of the perspective transformation is further improved.
[0101] In some embodiments, the value of the second type of elements of the perspective transformation matrix of the Y channel is a first value, and the value of the third type of elements of the perspective transformation matrix of the Y channel is a second value.
[0102] Correspondingly, the process of modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image can include: in response to the sampling format of the YUV image being YUV420 sampling format, modifying the first value of the second type of elements to half of the first value, and modifying the second value of the third type of elements to twice the second value.
[0103] For example, for the matrix A, the first value of the second type of element can be modified to half of the first value, and the second value of the third type of element can be modified to twice the second value, to obtain a matrix A', which is a perspective transformation matrix of the U channel and a perspective transformation matrix of the V channel. It can be seen that the matrix A' can be represented by formula (7).
[0104]
[0105] It can be seen that the embodiment of the present disclosure can be directed to a YUV image in YUV420 sampling format, and the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of element and the third type of element in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of perspective transformation is further improved.
[0106] The image perspective transformation method of the embodiment of the present disclosure can be applied in computer images and visual software products. The embodiment of the present disclosure is directed to a YUV image in YUV420 sampling format, and proposes an image perspective transformation method directly acting on the YUV image without implementing color space transformation.
[0107] In related technologies, the perspective transformation matrix of the R channel, the perspective transformation matrix of the G channel, and the perspective transformation matrix of the B channel are the same matrix. In the embodiment of the present disclosure, two different perspective transformation matrices can be proposed according to the difference in sampling rates of different channels for a YUV image in YUV420 sampling format. The perspective transformation matrix of the Y channel is different from the perspective transformation matrix of the U channel, and the perspective transformation matrix of the Y channel is different from the perspective transformation matrix of the V channel, while the perspective transformation matrix of the U channel is the same as the perspective transformation matrix of the V channel. In the case of perspective transformation processing for a YUV image, the respective perspective transformation matrices of the Y channel, the U channel, and the V channel are used for matrix multiplication, so as to obtain a target image.
[0108] Based on the foregoing embodiments, the image perspective transformation device provided by the embodiments of the present disclosure includes various units and various modules included in the units, which can be implemented by a processor in an electronic device. Of course, the device can also be implemented by a specific logic circuit. In the implementation process, the processor can be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field-Programmable Gate Array (FPGA), a CPU, a controller, a microcontroller, and a microprocessor.
[0109] Figure 5 A structural schematic diagram of the image perspective transformation device of the embodiments of the present disclosure is shown in FIG. 1. The device includes an acquisition module 501, a determination module 502, and a processing module 503. In the device, Figure 5
[0110] The acquisition module 501 is configured to acquire a YUV image and a sampling format of the YUV image.
[0111] The determination module 502 is configured to determine a perspective transformation matrix of a Y channel in the YUV image according to a predetermined first mapping relationship. The first mapping relationship is used to represent a coordinate mapping relationship between at least four pairs of pixel points between the YUV image and a target image.
[0112] The determination module 502 is further configured to determine a perspective transformation matrix of a U channel and a perspective transformation matrix of a V channel in the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image.
[0113] The processing module 503 is configured to perform perspective transformation on the YUV image according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel, and the perspective transformation matrix of the V channel to obtain the target image.
[0114] It can be seen that the embodiment of the present disclosure can first determine the perspective transformation matrix of the Y channel, and then determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel according to the perspective transformation matrix of the Y channel, so that the perspective transformation of the YUV image can be directly performed according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel. Since the process of implementing additional color space transformation is not required, the implementation process of the perspective transformation of the YUV image is relatively simple, and the efficiency of the perspective transformation is improved.
[0115] In some embodiments, the perspective transformation matrix of the Y channel includes a first type of element for implementing image linear transformation, a second type of element for implementing pixel point coordinate translation, and a third type of element for implementing three-dimensional space transformation of the image.
[0116] In the embodiment of the present disclosure, according to the role of each type of element in the perspective transformation matrix of the Y channel, the element transformation relationship between the perspective transformation matrices of different channels can be accurately determined, and then according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be accurately determined.
[0117] In some embodiments, the determining module 502 is configured to determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image according to the perspective transformation matrix of the Y channel and the sampling format of the YUV image, including:
[0118] According to the sampling format of the YUV image, the second type of element and the third type of element in the perspective transformation matrix of the Y channel are modified to obtain a modified perspective transformation matrix;
[0119] The modified perspective transformation matrix is determined as the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel.
[0120] It can be seen that the embodiment of the present disclosure can easily derive the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel by modifying the second type of element and the third type of element in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of the perspective transformation is further improved.
[0121] In some embodiments, the value of the second type of element of the perspective transformation matrix of the Y channel is a first value, and the value of the third type of element of the perspective transformation matrix of the Y channel is a second value.
[0122] The determining module 502 is configured to modify the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image, including:
[0123] In response to the sampling format of the YUV image being YUV420 sampling format, the first value of the second type of elements is modified to half of the first value, and the second value of the third type of elements is modified to twice the second value.
[0124] It can be seen that the embodiments of the present disclosure can be aimed at the YUV image of YUV420 sampling format, and the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel can be derived more easily by modifying the second type of elements and the third type of elements in the perspective transformation matrix of the Y channel. Since the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel do not need to be calculated by solving equations, the calculation efficiency of the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel is improved, and the efficiency of perspective transformation is further improved.
[0125] In some embodiments, the perspective transformation matrix of the Y channel is a 3*3 matrix, the first type of elements include elements of the first row and the first column, elements of the first row and the second column, elements of the second row and the first column, and elements of the second row and the second column; the second type of elements include elements of the first row and the third column and elements of the second row and the third column, and the third type of elements include elements of the third row and the first column and elements of the third row and the second column.
[0126] It can be seen that since two transformation relationships can be determined according to each pair of pixel points, and the number of the first type of elements, the second type of elements and the third type of elements is eight, in the case that other elements of the perspective transformation matrix of the Y channel except the first type of elements, the second type of elements and the third type of elements are known elements, the first type of elements, the second type of elements and the third type of elements of the perspective transformation matrix of the Y channel can be accurately solved according to the coordinate mapping relationship between at least four pairs of pixel points, that is, the perspective transformation matrix of the Y channel can be accurately obtained.
[0127] In some embodiments, the determining module 502 is further configured to:
[0128] In the Y channel image of the YUV image, a first region is determined, the first region is a quadrilateral region;
[0129] A second region corresponding to the first region is determined, the second region is a quadrilateral region, and four vertices of the second region form a one-to-one correspondence with four vertices of the first region;
[0130] In response to determining the second region as the region in the Y channel image of the target image, the first mapping relationship between four pairs of pixel points is determined according to the correspondence between the four vertices of the second region and the four vertices of the first region, each pair of pixel points in the four pairs of pixel points including a pair of corresponding vertices in the first region and the second region.
[0131] It can be seen that the embodiments of the present disclosure can accurately determine the first mapping relationship according to the known first region and the second region when the second region is taken as the region in the Y channel image of the target image, thereby facilitating subsequent accurate determination of the perspective transformation matrix of the Y channel, and further facilitating accurate implementation of perspective transformation of the YUV image.
[0132] In some embodiments, the determining module 502 is configured to determine the perspective transformation matrix of the Y channel in the YUV image according to the predetermined first mapping relationship, including:
[0133] For the at least four pairs of pixel points, a first transformation relationship between the horizontal coordinates of each pair of pixel points and a second transformation relationship between the vertical coordinates of the each pair of pixel points are determined.
[0134] According to the first transformation relationship and the second transformation relationship, the perspective transformation matrix of the Y channel is determined.
[0135] It can be seen that the embodiments of the present disclosure can accurately determine the perspective transformation matrix of the Y channel according to the coordinate transformation relationship between each pair of pixel points, thereby facilitating accurate implementation of perspective transformation of the YUV image.
[0136] The above description of the device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. In some embodiments, the device provided by the embodiments of the present disclosure has functions or includes modules that can be used to perform the methods described in the above method embodiments. For technical details not disclosed in the device embodiments of the present disclosure, please refer to the description of the method embodiments of the present disclosure.
[0137] It should be noted that, in the embodiments of the present disclosure, if the image perspective transformation method described above is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present disclosure can be embodied in the form of a software product in essence or the part that contributes to the related art, which is stored in a storage medium, includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the methods described in the embodiments of the present disclosure. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various media that can store program codes. Thus, the embodiments of the present disclosure are not limited to any specific hardware, software or firmware, or any combination of hardware, software and firmware.
[0138] The embodiments of the present disclosure provide a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements part or all of the steps of any of the image perspective transformation methods described above. The computer-readable storage medium can be transitory or non-transitory.
[0139] The embodiments of the present disclosure provide a computer program, which includes computer-readable code. When the computer-readable code runs in a computer device, a processor in the computer device executes part or all of the steps of any of the image perspective transformation methods described above.
[0140] The embodiments of the present disclosure provide a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, it implements part or all of the steps of the above method. The computer program product can be implemented by hardware, software or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium, and in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (Software Development Kit, SDK) and the like.
[0141] It should be noted that the above description of the various embodiments tends to emphasize the differences between the various embodiments, and the same or similar parts can be referred to each other. The above description of the device, storage medium, computer program and computer program product embodiments is similar to the description of the method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the device, storage medium, computer program and computer program product embodiments, please refer to the description of the method embodiments of the present disclosure.
[0142] It should be noted that, Figure 6 A schematic diagram of a hardware entity of an electronic device in the embodiments of the present disclosure is shown in FIG. 6. Figure 6 As shown in FIG. 6, the electronic device 600 can include a memory 601, a processor 602, and a computer program stored in the memory 601 and executable on the processor 602; wherein,
[0143] The processor 602 is configured to execute the computer program to perform any of the image perspective transformation methods described above.
[0144] In actual applications, the memory 601 can be a volatile memory (volatile memory), such as RAM, or a non-volatile memory (non-volatile memory), such as ROM, flash memory, hard disk (Hard Disk Drive, HDD) or solid state disk (Solid-State Drive, SSD), or a combination of the above types of memories, and provides instructions and data to the processor 602.
[0145] In some embodiments, the electronic device 600 described above can be a mobile terminal.
[0146] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present disclosure. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present disclosure, the size of the sequence number of each step / process does not mean the order of execution, and the execution order of each step / process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure. The sequence number of the above embodiments of the present disclosure is only for description, not representing the advantages or disadvantages of the embodiments.
[0147] It should be noted that in this document, the term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "comprises a" does not exclude the presence of additional identical elements in the process, method, article or device including the element.
[0148] In several embodiments provided by the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other manners. The embodiments described above are merely exemplary, and the unit division is merely logical function division, and there can be other division manners in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed coupling, direct coupling, or communication connection between the components can be indirect coupling or communication connection through some interfaces, and can be electrical, mechanical, or in other forms.
[0149] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units; they can be located in one place, or distributed on a plurality of network units; and some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0150] In addition, each functional unit in each embodiment of the present disclosure can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; and the integrated unit can be implemented in the form of hardware, or in the form of hardware plus software functional units.
[0151] Those of ordinary skill in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by a program instructing related hardware, and the aforementioned program can be stored in a computer readable storage medium, and when the program is executed, the steps of the method embodiments are executed; and the aforementioned storage medium includes a mobile storage device, a read-only memory (ROM), a magnetic disk or an optical disk, and various storage media that can store program codes.
[0152] Alternatively, when the integrated units of the present disclosure are implemented in the form of software functional modules and sold or used as independent products, they can also be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present disclosure can be embodied in the form of a software product, and the computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present disclosure. The aforementioned storage medium includes: a mobile storage device, a ROM, a magnetic disk, or an optical disk, and various storage media that can store program codes.
[0153] The above merely describes the embodiments of the present disclosure, but the protection scope of the present disclosure is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present disclosure, which should be covered within the protection scope of the present disclosure.
Claims
1. A method for image perspective transformation, characterized in that, The method includes: Obtain the YUV image and the sampling format of the YUV image; Based on a predetermined first mapping relationship, the perspective transformation matrix of the Y channel in the YUV image is determined; the first mapping relationship is used to characterize the coordinate mapping relationship between at least four pairs of pixels between the YUV image and the target image. Based on the perspective transformation matrix of the Y channel and the sampling format of the YUV image, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image are determined; the sampling format of the YUV image represents the ratio of the sampling rate of the Y channel to the sampling rate of the U channel, and the ratio of the sampling rate of the Y channel to the sampling rate of the V channel. The YUV image is subjected to perspective transformation based on the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel, and the perspective transformation matrix of the V channel to obtain the target image.
2. The method according to claim 1, characterized in that, The perspective transformation matrix of the Y channel includes a first type of elements for realizing linear transformation of the image, a second type of elements for realizing translation of pixel coordinates, and a third type of elements for realizing three-dimensional spatial transformation of the image.
3. The method according to claim 2, characterized in that, The step of determining the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image based on the perspective transformation matrix of the Y channel and the sampling format of the YUV image includes: Based on the sampling format of the YUV image, the second and third types of elements in the perspective transformation matrix of the Y channel are modified to obtain the modified perspective transformation matrix. The modified perspective transformation matrix is determined as the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel.
4. The method according to claim 3, characterized in that, The second type of element in the perspective transformation matrix of the Y channel takes the first value, and the third type of element in the perspective transformation matrix of the Y channel takes the second value. The modification of the second and third types of elements in the perspective transformation matrix of the Y channel according to the sampling format of the YUV image includes: In response to the sampling format of the YUV image being YUV420, the first value of the second type of element is modified to half of the first value, and the second value of the third type of element is modified to twice the second value.
5. The method according to any one of claims 2 to 4, characterized in that, The perspective transformation matrix of the Y channel is a 3*3 matrix, and the first type of elements includes the elements in the first row and first column, the elements in the first row and second column, the elements in the second row and first column, and the elements in the second row and second column. The second type of elements includes the elements in the first row and third column and the elements in the second row and third column, and the third type of elements includes the elements in the third row and first column and the elements in the third row and second column.
6. The method according to any one of claims 1 to 4, characterized in that, The method further includes: In the Y channel image of the YUV image, a first region is determined, and the first region is a quadrilateral region; A second region corresponding to the first region is determined. The second region is a quadrilateral region, and the four vertices of the second region correspond one-to-one with the four vertices of the first region. In response to determining the second region as a region in the Y channel image of the target image, the first mapping relationship between four pairs of pixels is determined based on the correspondence between the four vertices of the second region and the four vertices of the first region, wherein each of the four pairs of pixels includes a pair of vertices that form a correspondence between the first region and the second region.
7. The method according to any one of claims 1 to 4, characterized in that, The step of determining the perspective transformation matrix of the Y channel in the YUV image according to a predetermined first mapping relationship includes: For the at least four pairs of pixels, determine a first transformation relationship between the horizontal coordinates of each pair of pixels and a second transformation relationship between the vertical coordinates of each pair of pixels; The perspective transformation matrix of the Y channel is determined based on the first transformation relationship and the second transformation relationship.
8. An image perspective transformation device, characterized in that, The device includes: an acquisition module, a determination module, and a processing module; wherein... The acquisition module is used to acquire YUV images and the sampling format of the YUV images; The determining module is used to determine the perspective transformation matrix of the Y channel in the YUV image according to a pre-determined first mapping relationship; the first mapping relationship is used to characterize the coordinate mapping relationship between at least four pairs of pixels between the YUV image and the target image; The determining module is further configured to determine the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel in the YUV image based on the perspective transformation matrix of the Y channel and the sampling format of the YUV image; the sampling format of the YUV image represents the ratio of the sampling rate of the Y channel to the sampling rate of the U channel, and the ratio of the sampling rate of the Y channel to the sampling rate of the V channel; The processing module is used to perform perspective transformation on the YUV image according to the perspective transformation matrix of the Y channel, the perspective transformation matrix of the U channel and the perspective transformation matrix of the V channel to obtain the target image.
9. An electronic device, characterized in that, It includes a processor and a memory for storing a computer program capable of running on the processor; wherein the processor is used to run the computer program to perform the method according to any one of claims 1 to 7.
10. The electronic device according to claim 9, characterized in that, The electronic device is a mobile terminal.
11. A computer storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Image synthesis method and device and computer storage medium
CN108876705A
Image perspective transformation method, device and equipment
CN110060200A