Anti-shake method for panoramic video, and portable terminal

11388339 · 2022-07-12

Assignee

Inventors

Cpc classification

International classification

Abstract

The present invention provides an anti-shake method for a panoramic video, which comprises: obtaining, in real time, an output video frame, a fisheye image corresponding thereto, a pixel timestamp in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the pixel timestamp in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video. According to the present invention, the rolling shutter distortion of a panoramic video sequence can be corrected, the image distortion caused by the rolling shutter of a CMOS can be corrected, and the rolling shutter is eliminated, thereby achieving a better anti-shake effect of a video image.

Claims

1. An anti-shake method for a panoramic video, comprising steps of: obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video, wherein the step of obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp, specifically comprises: obtaining the output video frame and the fisheye image corresponding to the output video frame; obtaining the timestamp t.sup.k.sub.frame.sup.p(x,y) of the pixel p(x,y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and obtaining the gyroscope timestamp t.sup.k.sub.gyro.sup.p(x,y) in the time axis of the corresponding camera gyroscope acquisition system.

2. The method of claim 1, wherein the step of synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp, specifically comprises: calculating the timestamp t.sup.k.sub.frame.sup.p(x,y) of the pixel P(x, Y) in the k video frame by formula (1): t frame k p ( x , y ) = t frame k + Δ t H y - 1 2 Δ t ; ( 1 ) in formula (1), t.sup.k.sub.frame is the timestamp of the pixel at the beginning of the k video frame, Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image; synchronizing the timestamp of the pixel in the k video frame with the camera gyroscope timestamp, a conversion relationship between the two as formula (2):
t.sup.k.sub.gyro.sup.p(x,y)=ΔT.sub.0+t.sup.k.sub.frame.sup.p(x,y)  (2) in formula (2), ΔT.sub.0=t.sup.k.sub.gyro=t.sup.k.sub.frame, t.sup.k.sub.gyro is the camera gyroscope timestamp at the beginning of the k video frame; and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp at time t.sup.k.sub.gyro.sup.p(x,y) by formula (3):
R.sub.w2s(t.sup.k.sub.gyro.sup.p(x,y)=R.sub.w2g(t.sup.k.sub.gyro.sup.p(x,y).Math.R.sub.g2s(t.sup.k.sub.gyro.sup.p(x,y))  (3) in formula (3), R.sub.w2g (t.sup.k.sub.gyro.sup.p(x,y) is a rotation matrix measured by a gyroscope sensor at time t.sup.k.sub.gyro.sup.p(x,y), and R.sub.g2s(t.sup.k.sub.gyro.sup.p(x,y)) is a rotation matrix from the calibrated gyroscope coordinate system to the camera.

3. The method of claim 2, wherein the step of smoothing the camera movement and establishing a coordinate system of a smooth trajectory, specifically comprises: where P.sup.s representing the 3D coordinates in the camera coordinate system, let t=t.sup.k.sub.gyro.sup.p(x,y), converting the 3D coordinates P.sub.t.sup.w in the world coordinate system to the 3D coordinates P.sub.t.sup.s in the camera coordinate system at time t by a formula:
P.sub.t.sup.s=R.sub.w2s(t).Math.P.sub.t.sup.w+t.sub.0  (4) in the formula (4), R.sub.w2s(t) is a matrix of the camera coordinate system relative to the world coordinate system at time t, and {right arrow over (t)}.sub.0 is a translation amount of the two frames before and after of the video frame of the camera; smoothing the camera movement, where setting {right arrow over (t)}0=0 and then obtaining P t w = P t s R w 2 s ( t ) ; establishing a coordinate system P′.sub.t of a smooth trajectory, performing a 3D grid rendering processing on the coordinate system P′.sub.t of the camera's smooth trajectory by a rendering formula: P.sub.t.sup.gl=K.Math.R.sub.awp.Math.P′.sub.t; where K is a perspective matrix, R.sub.mvp is a rotation matrix of the view direction manually controlled, and P.sub.t.sup.gl is the 3D coordinates rendered in the coordinate system of the smooth trajectory; and in the coordinate system of the smooth trajectory, obtaining the minimum square difference of any pixel in P.sub.t′ in the two frames before and after by a formula: min (P.sub.t+1′−P.sub.t′).sup.2+(P.sub.t′−P.sub.t.sup.w).sup.2, where P.sub.t′ and P.sub.t+1′ are the coordinate systems of the smooth trajectory of the two frames before and after, respectively; setting P.sub.t′=P.sub.t+1′=P.sub.t.sup.w, and obtaining the rendering formula as formula (5):
P.sub.t.sup.gl=K.Math.R.sub.mvp.Math.R.sub.w2s(t).sup.−1.Math.P.sub.t.sup.s  (5) calculating the 3D coordinates of the camera rendered to the coordinate system of the smooth trajectory by the formula (5).

4. The method of claim 3, wherein the step of correcting the fisheye image distortion, specifically comprises: where let P s = P t gyro k p ( x , y ) s , obtaining a panoramic expanded image of P.sup.s in the camera coordinate system: P s = { cos ( u ) cos ( v ) cos ( u ) sin ( v ) sin ( u ) ( 6 ) in formula (6), u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively; a fisheye distortion model ρf(θ)=θ(1+k.sub.0θ.sup.2+k.sub.1θ.sup.4+k.sub.2θ.sup.6+k.sub.3θ.sup.8) where θ is an incident angle of the light, k.sub.0, k.sub.1, k.sub.2, and k.sub.3 are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image: { x = f x .Math. ρ .Math. P x s r + x c y = f y .Math. ρ .Math. P y s r + y c ( 7 ) in formula (7), r=√{square root over (P.sub.x.sup.s2+P.sub.y.sup.s2)}, and θ=atan (r,P.sub.z.sup.s); the point (x.sub.c,y.sub.c) is a projection center of the sensor, x and y are the 2D coordinates of a projection position of the camera sensor respectively.

5. The method of claim 4, wherein the step of rendering the fisheye image by means of forward rendering to generate a stable video, specifically comprises: establishing a correspondence between the fisheye image and grid points of the spherical model in the camera coordinate system by means of a fisheye image distortion correction method; generating grid points of the spherical model in the coordinate system of the smooth trajectory by rendering; and performing panoramic expansion for the grid points of the spherical model in the coordinate system of the smooth trajectory to generate a stable video.

6. A non-transitory computer-readable medium that stores one or more computer programs including a set of computer-executable instructions, wherein when being executed by one or more processors, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim 1.

7. A portable terminal, comprising: one or more processors; a memory; and one or more computer programs including a set of computer-executable instructions, where the set of computer-executable instructions are stored in the memory and are configured to be executed by the one or more processors, wherein when being executed by the one or more processors, cause the one or more processors to perform steps of an anti-shake method for a panoramic video: obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video; wherein the step of obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp, specifically comprises: obtaining the output video frame and the fisheye image corresponding to the output video frame: obtaining the timestamp t.sup.k.sub.frame.sup.p(x,y) of the pixel p(x,y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and obtaining the gyroscope timestamp t.sup.k.sub.gyro.sup.p(x,y) in the time axis of the corresponding camera gyroscope acquisition system.

8. The portable terminal of claim 7, wherein the step of synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp, specifically comprises: calculating the timestamp t.sup.k.sub.frame.sup.p(x,y) of the pixel P(x,y) in the k video frame by formula (1): t frame k p ( x , y ) = t f r a m e k + Δ t H y - 1 2 Δt ; ( 1 ) in formula (1), t.sup.k.sub.frame is the timestamp of the pixel at the beginning of the k video frame, Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image; synchronizing the timestamp of the pixel in the k video frame with the camera gyroscope timestamp, a conversion relationship between the two as formula (2):
t.sup.k.sub.gyro.sup.p(x,y)=ΔT.sub.0+t.sup.k.sub.frame.sup.p(x,y)  (2) in formula (2), ΔT=t.sub.gyro.sup.k−t.sub.frame.sup.k, t.sub.gyro.sup.k is the camera gyroscope timestamp at the beginning of the k video frame; and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp at time t.sup.k.sub.gyro.sup.p(x,y) by formula (3):
R.sub.w2s(t.sup.k.sub.gyro.sup.p(x,y)=R.sub.w2g(t.sup.k.sub.gyro.sup.p(x,y).Math.R.sub.g2s(t.sup.k.sub.gyro.sup.p(x,y))  (3) in formula (3), R.sub.w2g(t.sup.k.sub.gyro.sup.p(x,y)) is a rotation matrix measured by a gyroscope sensor at time t.sup.k.sub.gyro.sup.p(x,y), and R.sub.g2s(t.sup.k.sub.gyro.sup.p(x,y)) is a rotation matrix from the calibrated gyroscope coordinate system to the camera.

9. The portable terminal of claim 8, wherein the step of smoothing the camera movement and establishing a coordinate system of a smooth trajectory, specifically comprises: where P.sup.s representing the 3D coordinates in the camera coordinate system, let t=t.sup.k.sub.gyro.sup.p(x,y), converting the 3D coordinates P.sub.t.sup.w in the world coordinate system to the 3D coordinates P.sub.t.sup.s in the camera coordinate system at time t by a formula:
P.sub.t.sup.s=R.sub.w2s(t).Math.P.sub.t.sup.w+{right arrow over (t.sub.0)}  (4) in the formula (4), R.sub.w2s(t) is a matrix of the camera coordinate system relative to the world coordinate system at time t, and {right arrow over (t.sub.0)} a translation amount of the two frames before and after of the video frame of the camera; smoothing the camera movement, where setting {right arrow over (t.sub.0)}=0 and then obtaining P t w = P t s R w 2 s ( t ) ; establishing a coordinate system P′.sub.t of a smooth trajectory, performing a 3D grid rendering processing on the coordinate system P′.sub.t of the camera's smooth trajectory by a rendering formula: P.sub.t.sup.gl=K.Math.R.sub.mvp.Math.P′.sub.t; where K is a perspective matrix R.sub.mvp is a rotation matrix of the view direction manually controlled, and P.sub.t.sup.gl is the 3D coordinates rendered in the coordinate system of the smooth trajectory; and in the coordinate system of the smooth trajectory, obtaining the minimum square difference of any pixel in P.sub.t′ in the two frames before and after by a formula: min(P.sub.t+1′−P′.sub.t).sup.2+(P.sub.t′−P.sub.t.sup.w).sup.2, where P.sub.t′ and P.sub.t+1′ are the coordinate systems of the smooth trajectory of the two frames before and after, respectively; setting P′.sub.t=P.sub.t+1′=P.sub.t.sup.w, and obtaining the rendering formula as formula (5):
P.sub.t.sup.gl=K.Math.R.sub.mvp.Math.R.sub.w2s(t).sup.−1.Math.P.sub.t.sup.s  (5) calculating the 3D coordinates of the camera rendered to the coordinate system of the smooth trajectory by the formula (5).

10. The portable terminal of claim 9, wherein the step of correcting the fisheye image distortion, specifically comprises: where let P s = P t gyro k p ( x , y ) s , obtaining a panoramic expanded image of P.sup.s in the camera coordinate system: P s = { cos ( u ) cos ( v ) cos ( u ) sin ( v ) sin ( u ) ( 6 ) in formula (6), u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively; a fisheye distortion model ρ=f(θ)=θ(1+k.sub.0θ.sup.2+k.sub.1θ.sup.4+k.sub.2θ.sup.6+k.sub.3θ.sup.8) where θ is an incident angle of the light, k.sub.0, k.sub.1, k.sub.2, and k.sub.3 are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image: { x = f x .Math. ρ .Math. P x s r + x c y = f y .Math. ρ .Math. P y s r + y c ( 7 ) in formula (7), √{square root over (r=P.sub.x.sup.s2+P.sub.y.sup.s2)}, and θ=atan (r,P.sub.z.sup.s); the point (x.sub.c,y.sub.c) is a projection center of the sensor, x and y are the 2D coordinates of a projection position of the camera sensor respectively.

11. The portable terminal of claim 10, wherein the step of rendering the fisheye image by means of forward rendering to generate a stable video, specifically comprises: establishing a correspondence between the fisheye image and grid points of the spherical model in the camera coordinate system by means of a fisheye image distortion correction method; generating grid points of the spherical model in the coordinate system of the smooth trajectory by rendering; and performing panoramic expansion for the grid points of the spherical model in the coordinate system of the smooth trajectory to generate a stable video.

12. An anti-shake method for a panoramic video, comprising steps of: S201, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; S202, synchronizing the timestamp of the pixel in the video frame to the corresponding camera gyroscope acquisition system, and calculating a rotation matrix of the camera movement in the timestamp of the pixel in the current video frame, as an approximate rotation matrix of the camera when collecting the current pixel; S203, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using a fisheye image distortion correction method to establish a relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels; S204, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system; and S205, using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using a mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video.

13. The method of claim 12, wherein S201 specifically comprises: obtaining the output video frame and the fisheye image corresponding to the output video frame; obtaining the timestamp t.sup.k.sub.frame.sup.p(x,y) of the pixel p(x,y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and obtaining the gyroscope timestamp t.sup.k.sub.gyro.sup.p(x,y) in the time axis of the corresponding camera gyro gyroscope acquisition system.

14. The method of claim 13, wherein S202 specifically comprises steps: synchronizing the timestamp of the pixel in the video frame to the corresponding camera gyroscope acquisition system, a conversion relationship between the two as shown in formula (8):
t.sub.gyro.sup.k=ΔT.sub.0+t.sub.frame.sup.k  (8) where in formula (8), ΔT.sub.0=t.sub.gyro.sup.k−t.sub.frame.sup.k, t.sub.gyro.sup.k is the camera gyroscope timestamp at the beginning of the k video frame, and t.sub.frame.sup.k is the timestamp at the beginning of the k video frame; and calculating a rotation matrix of the camera movement under the timestamp of the pixel in the current video frame at time t.sub.gyro.sup.k by formula (9):
R.sub.w2s(t.sub.gyro.sup.k)=R.sub.w2g(t.sub.gyro.sup.k).Math.R.sub.g2s(t.sub.gyro.sup.k)  (9) where in formula (9), R.sub.w2g(t.sub.gyro.sup.k) is s rotation matrix measured by the gyroscope sensor at time t.sub.gyro.sup.k, and R.sub.g2s(t.sub.gyro.sup.k) is a rotation matrix from the calibrated gyroscope coordinate system to the camera.

15. The method of claim 14, wherein S203 is that: where let P s = P t gyro k p ( x , y ) s , obtaining a panoramic expanded image of P.sup.s in the camera coordinate system: P s = { cos ( u ) cos ( v ) cos ( u ) sin ( v ) sin ( u ) , where u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively; a fisheye distortion model ρ=f(θ)=θ(1+k.sub.0θ.sup.2+k.sub.1θ.sup.4+k.sub.2θ.sup.6+k.sub.3θ.sup.8), where θ is an incident angle of the light, k.sub.0, k.sub.1, k.sub.2, and k.sub.3 are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image: { x = f x .Math. ρ .Math. P x s r + x c y = f y .Math. ρ .Math. P y s r + y c , where r=√{square root over (P.sub.x.sup.s2+P.sub.y.sup.s2)} and θ=atan (r, P.sub.z.sup.s); the point (x.sub.c,y.sub.c) is a projection center of the sensor, x and y are the 2D coordinates of a projection position of the camera sensor respectively.

16. The method of claim 15, wherein the step of calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera motion when collecting the current pixel, specifically is: using the approximate reverse-mapping pixels in the fisheye image to calculate the camera gyroscope timestamp of the pixel by the formula: t gyro k p ( x , y ) = Δ T 0 + t frame k p ( x , y ) + Δ t H y - 1 2 Δ t ( 10 ) where in formula (10), Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image; then calculating the accurate rotation matrix R.sub.w2s(t.sup.k.sub.gyro.sup.p(x,y) of the camera motion under the camera gyroscope timestamp, where the calculation formula is:
R.sub.w2s(t.sup.k.sub.gyro.sup.p(x,y)=R.sub.w2g(t.sup.k.sub.gyro.sup.p(x,y)).Math.R.sub.g2s(t.sup.k.sub.gyro.sup.p(x,y)).

17. The method of claim 16, wherein S205 specifically is: projecting the output video frame pixel A.sub.4 to the corresponding grid point A.sub.3 of the spherical model, using the approximate rotation matrix to rotate A.sub.3 to obtain A.sub.2 in the sensor coordinate system, using the fisheye image distortion correction method to project A.sub.2 onto the fisheye image to obtain the pixel A.sub.1, using the accurate rotation matrix to rotate A.sub.1 to obtain A′.sub.2 in the sensor coordinate system, and then using the fisheye image distortion correction method to project A′.sub.2 to the fisheye image to obtain the accurate pixel A′.sub.1; using the mapping relationship between the output video frame pixel A.sub.4 and the accurate pixel A′.sub.1; in the fisheye image to render the fisheye image in reverse rendering to generate a stable video; similarly, projecting the output video frame pixel B.sub.4 to the corresponding grid point B.sub.3 of the spherical model, using the approximate rotation matrix to rotate B.sub.3 to obtain B.sub.2 in the sensor coordinate system, using the fisheye image distortion correction method to project B.sub.2 onto the fisheye image to obtain pixel B.sub.1, using the accurate rotation matrix to rotate B.sub.1 to obtain B′.sub.2 in the sensor coordinate system, and then using the fisheye image distortion correction method to project B′.sub.2 to the fisheye image to obtain the accurate pixel B′.sub.1; using the mapping relationship between the output video frame pixel B.sub.4 and the accurate pixel B′.sub.1 in the fisheye image to render the fisheye image in reverse rendering to generate a stable video.

18. A non-transitory computer-readable medium that stores one or more computer programs including a set of computer-executable instructions, wherein when being executed by one or more processors, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim 12.

19. A portable terminal, comprising: one or more processors; a memory; and one or more computer programs including set of computer-executable instructions, where the set of computer-executable instructions are stored in the memory and are configured to be executed by the one or more processors, wherein being executed by the one or more processors execute, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim 12.

Description

BRIEF DESCRIPTION OF THE DRAWINGS

(1) FIG. 1 is a flowchart of an anti-shake method for a panoramic video in accordance with a first embodiment of the present invention;

(2) FIG. 2 is a schematic diagram of the timestamp of the scan line sequence of the CMOS camera in accordance with the first embodiment of the present invention;

(3) FIG. 3 is a mapping process diagram of a forward mapping rendering method in the anti-shake method for a panoramic video in accordance with the first embodiment of the present invention;

(4) FIG. 4 is a flowchart of the anti-shake method for a panoramic video in accordance with a second embodiment of the present invention;

(5) FIG. 5 is a mapping process diagram of a backward mapping rendering method in the anti-shake method for a panoramic video in accordance with the second embodiment of the present invention; and

(6) FIG. 6 is a schematic structural diagram of a portable terminal in accordance with a fourth embodiment of the present invention.

DETAILED DESCRIPTION OF THE INVENTION

(7) The foregoing objects, technical solutions and advantages of the invention will be much clearer from the following detail description taken with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

(8) In order to explain the technical solutions of the present invention, the following will be described by specific embodiments.

First Embodiment

(9) Referring to FIG. 1, an anti-shake method for a panoramic video provided in the first embodiment of the present invention comprising the following steps:

(10) S101, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

(11) in the first embodiment of the present invention, S101 may specifically comprise the following steps:

(12) S1011, obtaining the output video frame and the fisheye image corresponding to the output video frame;

(13) S1012, obtaining the timestamp t.sub.frame.sup.k.sup.p(x,y) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and

(14) S1013, obtaining the gyroscope timestamp t.sub.gyro.sup.k.sup.p(x,y) in the time axis of the corresponding camera gyroscope acquisition system.

(15) S102, synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp;

(16) referring to FIG. 2, in the first embodiment of the present invention, S102 may specifically comprise the following steps:

(17) S1021, calculating the timestamp t.sub.frame.sup.k.sup.p(x,y) of the pixel p(x, y) in the k video frame by formula (1):

(18) t frame k p ( x , y ) = t frame k + Δ t H y - 1 2 Δ t ; ( 1 )

(19) in formula (1), t.sub.frame.sup.k.sup.p(x,y) is the timestamp of the pixel at the beginning of the k video frame, Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image;

(20) S1022, synchronizing the timestamp of the pixel in the k video frame with the camera gyroscope timestamp, a conversion relationship between the two as formula (2):
t.sub.gyro.sup.k.sup.p(x,y)=ΔT.sub.0+t.sub.frame.sup.k.sup.p(x,y)  (2) in formula (2), ΔT.sub.0=t.sub.gyro.sup.k−t.sub.frame.sup.k, t.sub.gyro.sup.k is the camera gyroscope timestamp at the beginning of the k video frame;

(21) S1023, calculating a rotation matrix of the camera movement in the camera gyroscope timestamp at time t.sub.gyro.sup.k.sup.p(x,y) by formula (3):
R.sub.w2s(t.sub.gyro.sup.k.sup.p(x,y))=R.sub.w2g(t.sub.gyro.sup.k.sup.p(x,y)).Math.R.sub.g2s(t.sub.gyro.sup.k.sup.p(x,y))  (3)

(22) in formula (3), R.sub.w2g(t.sub.gyro.sup.k.sup.p(x,y)) is a rotation matrix measured by a gyroscope sensor at time t.sub.gyro.sup.k.sup.p(x,y), R.sub.g2s(t.sub.gyro.sup.k.sup.p(x,y)) is a rotation matrix from the calibrated gyroscope coordinate system to the camera, and R.sub.w2s(t.sub.gyro.sup.k.sup.p(x,y)) is a 3*3 matrix.

(23) S103, smoothing the camera movement and establishing a coordinate system of a smooth trajectory;

(24) in the first embodiment of the present invention, S103 may specifically comprise the following steps:

(25) S1031, where P.sup.s representing the 3D coordinates in the camera coordinate system, let t=t.sub.gyro.sup.k.sup.p(x,y), converting the 3D coordinates P.sub.t.sup.w in the world coordinate system to the 3D coordinates P.sub.t.sup.s in the camera coordinate system at time t by a formula:
P.sub.t.sup.s=R.sub.w2s(t).Math.P.sub.t.sup.w+{right arrow over (t.sub.0)}  (4)

(26) in the formula (4), R.sub.w2s(t) is a matrix of the camera coordinate system relative to the world coordinate system at time t, and {right arrow over (t.sub.0)} is a translation amount of the two frames before and after of the video frame of the camera;

(27) S1032, smoothing the camera movement, where setting {right arrow over (t.sub.0)}=0 and then obtaining

(28) P t w = P t s R w 2 s ( t ) ;

(29) S1033, establishing the coordinate system P.sub.t′ of the smooth trajectory, performing a 3D grid rendering processing on the coordinate system P.sub.t′ of the camera's smooth trajectory by OpenG1 Rendering formula: P.sub.t.sup.g1=K.Math.R.sub.mvp.Math.P.sub.t′; where K is a perspective matrix, R.sub.mvp is a rotation matrix of the view direction manually controlled, and P.sub.t.sup.g1 is the 3D coordinates rendered by OpenG1 in the coordinate system of the smooth trajectory; and

(30) S1034, in the coordinate system of the smooth trajectory, obtaining the minimum square difference of any pixel in P.sub.t′ in the two frames before and after by a formula: min(P.sub.t+1′−P.sub.t′).sup.2+(P.sub.t′−P.sub.t.sup.w).sup.2, where P.sub.t′ and P.sub.t+1′ are the coordinate systems of the smooth trajectory of the two frames before and after, respectively; setting P.sub.t′=P.sub.t+1′=P.sub.t.sup.w, and obtaining the rendering formula as formula (5):
P.sub.t.sup.g1=K.Math.R.sub.mvp.Math.R.sub.x2z(t).sup.−1.Math.P.sub.t.sup.s  (5)
calculating the 3D coordinates of the camera rendered to the coordinate system of the smooth trajectory by formula (5).

(31) S104, correcting the fisheye image distortion.

(32) In the first embodiment of the present invention, S104 may specifically comprise:

(33) where let

(34) P s = P t gyro k p ( x , y ) s ,
obtaining a panoramic expanded image of P.sup.s in the camera coordinate system:

(35) P s = { cos ( u ) cos ( v ) cos ( u ) sin ( v ) sin ( u ) ( 6 )

(36) in formula (6), u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively;

(37) a fisheye distortion model ρ=f(θ)=θ(1+k.sub.0θ.sup.2+k.sub.1θ.sup.4+k.sub.2θ.sup.5+k.sub.3θ.sup.8), where θ is an incident angle of the light, k.sub.0, k.sub.1, k.sub.2, and k.sub.3 are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image:

(38) { x = f x .Math. ρ .Math. P x s r + x c y = f y .Math. ρ .Math. P y s r + y c ( 7 )

(39) in formula (7), r=√{square root over (P.sub.x.sup.s2+P.sub.y.sup.s2)}, and θ=atan (r,P.sub.z.sup.s); the point (x.sub.c, y.sub.c) is a projection center of the sensor, x and y are the 2D coordinates of the projection position of the camera sensor respectively.

(40) S105, rendering the fisheye image by means of forward rendering to generate a stable video.

(41) In the first embodiment of the present invention, S105 may specifically comprise the following steps of:

(42) establishing a correspondence between the fisheye image and the grid points of the spherical model in the camera coordinate system by means of the fisheye image distortion correction method;

(43) generating the grid points of the spherical model in the coordinate system of the smooth trajectory by rendering; and

(44) performing panoramic expansion of the grid points of the spherical model in the coordinate system of the smooth trajectory to generate a stable video. Where, specifically, color information can be input by interpolation, and projection can generate perspective images or asteroid images.

(45) Referring to FIG. 3, in the first embodiment of the present invention:

(46) A.sub.1 corresponds to A.sub.2, where A.sub.1 is the coordinate in the fisheye image, A.sub.2 corresponds to A.sub.1, is the coordinate of the grid point of the spherical model in the camera coordinate system; A.sub.3 corresponds to A.sub.2, is the coordinate of the grid point of the spherical model in the coordinate system of the smooth trajectory generated by rendering; and A.sub.4 is the coordinate point generated by the panoramic expansion projection of A.sub.3;

(47) Similarly, B.sub.1 corresponds to B.sub.2, where B.sub.1 is the coordinate in the fisheye image, B.sub.2 corresponds to B.sub.1, is the coordinate of the grid point of the spherical model in the camera coordinate system; B.sub.3 corresponds to B.sub.2, is the coordinate of the grid point of the spherical model in the coordinate system of the smooth trajectory generated by rendering; and B.sub.4 is the coordinate point generated by the panoramic expansion projection of B.sub.3.

(48) In the first embodiment of the present invention, based on the timestamp of the pixel in the video frame, the fisheye image is pixel by pixel converted into the coordinate system of the smooth trajectory using the rotation matrix of the camera motion under the timestamp of the current video frame pixel in real time, and then rendered and output; thereby the distortion of the rolling shutter of the panoramic video sequence can be corrected. The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, and achieve better video image anti-shake effect.

Second Embodiment

(49) Referring to FIG. 4, an anti-shake method for a panoramic video provided in is the second embodiment of the present invention comprising the following steps:

(50) S201, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

(51) in the second embodiment of the present invention, S201 may specifically comprise steps of:

(52) S2011, obtaining the output video frame and the fisheye image corresponding to the output video frame;

(53) S2012, obtaining the timestamp t.sub.frame.sup.k.sup.p(x,y) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and

(54) S2013, obtaining the gyroscope timestamp t.sub.gyro.sup.k.sup.p(x,y) in the time axis of the corresponding camera gyroscope acquisition system.

(55) S202, synchronizing the timestamp of the pixel in the video frame to the camera gyroscope acquisition system, and calculating the rotation matrix of the camera movement in the timestamp of the pixel in the current video frame as the approximate rotation matrix of the camera when collecting the current pixel;

(56) in the second embodiment of the present invention, S202 may specifically include the following steps:

(57) S2021, synchronizing the timestamp of the pixel in the video frame to the camera gyroscope acquisition system, the conversion relationship between the two as shown in formula (8):
t.sub.gyro.sup.k=ΔT.sub.0+t.sub.frame.sup.k  (8)

(58) in formula (8), ΔT.sub.0=t.sub.gyro.sup.k−t.sub.frame.sup.k, t.sub.gyro.sup.k is the camera gyroscope timestamp at the beginning of the k video frame, and t.sub.frame.sup.k is the timestamp of the pixel at the beginning of the k video frame;

(59) S2022, calculating a rotation matrix of the camera movement under the timestamp of the pixel in the current video frame at time t.sub.gyro.sup.k by formula (9):
R.sub.w2s(t.sub.gyro.sup.k)=R.sub.w2g(t.sub.gyro.sup.k).Math.R.sub.g2s(t.sub.gyro.sup.k)  (9)

(60) in formula (9), R.sub.w2g(t.sub.gyro.sup.k) is the rotation matrix measured by the gyroscope sensor at time t.sub.gyro.sup.k, R.sub.w2g(t.sub.gyro.sup.k) is a 3*3 matrix; and R.sub.g2s(t.sub.gyro.sup.k) is the rotation matrix from the calibrated gyroscope coordinate system to the camera.

(61) S203, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels;

(62) in the second embodiment of the present invention, S203 may specifically be:

(63) where let

(64) P s = P t gyro k p ( x , y ) s ,
obtaining a panoramic expanded image of P.sup.s in the camera coordinate system:

(65) P s = { cos ( u ) cos ( v ) cos ( u ) sin ( v ) sin ( u ) ,
where u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively;

(66) a fisheye distortion model 92=f(θ)=θ(1+k.sub.0θ.sup.2+k.sub.1θ.sup.4+k.sub.2θ.sup.B+k.sub.3θ.sup.B), where θ is an incident angle of the light, k.sub.0, k.sub.1, k.sub.2, and k.sub.3 are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image:

(67) { x = f x .Math. ρ .Math. P x s r + x c y = f y .Math. ρ .Math. P y s r + y c

(68) where r=√{square root over (P.sub.x.sup.s2+P.sub.y.sup.s2)} and θ=atan (r,P.sub.z.sup.s); the point (x.sub.c,y.sub.c) is a projection center of the sensor, x and y are the 2D coordinates of the projection position of the camera sensor respectively.

(69) S204, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate is rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system;

(70) in the second embodiment of the present invention, the step of calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera motion when collecting the current pixel, specifically is:

(71) using the approximate reverse-mapping pixels in the fisheye image to calculate the camera gyroscope timestamp of the pixel by the formula:

(72) t gyro k p ( x , y ) = Δ T 0 + t frame k p ( x , y ) + Δ t H y - 1 2 Δ t ( 10 )

(73) in formula (10), Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image;

(74) further calculating the accurate rotation matrix R.sub.w2s(t.sub.gyro.sup.k.sup.p(x,y)) of the camera motion under the camera gyroscope timestamp, where the calculation formula is:
R.sub.w2s(t.sub.gyro.sup.k.sup.p(x,y))=R.sub.w2g(t.sub.gyro.sup.k.sup.p(x,y)).Math.R.sub.g2s(t.sub.gyro.sup.k.sup.p(x,y)).

(75) S205, using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video.

(76) Referring to FIG. 5, in the second embodiment of the present invention:

(77) projecting the output video frame pixel A.sub.4 to the corresponding grid point A.sub.3 of the spherical model, using the approximate rotation matrix to rotate A.sub.3 to obtain A.sub.2 in the sensor coordinate system, using the fisheye image distortion correction method to project A.sub.2 onto the fisheye image to obtain the pixel A.sub.1, using the accurate rotation matrix to rotate A.sub.1 to obtain A′.sub.2 in the sensor coordinate system, and then using the fisheye image distortion correction method to project A′.sub.2 to the fisheye image to obtain the accurate pixel A′.sub.1; using the mapping relationship between the output video frame pixel A.sub.4 and the accurate pixel A′.sub.1 in the fisheye image to render the fisheye image in reverse rendering to generate a stable video;

(78) Similarly, projecting the output video frame pixel B.sub.4 to the corresponding grid point B.sub.3 of the spherical model, using the approximate rotation matrix to rotate B.sub.3 to obtain B.sub.2 in the sensor coordinate system, using the fisheye image distortion correction method to project B.sub.2 onto the fisheye image to obtain pixel B.sub.1, using the accurate rotation matrix to rotate B.sub.1 to obtain B′.sub.2 in the sensor coordinate system, and then using the fisheye image distortion correction method to project B′.sub.2 to the fisheye image to obtain the accurate pixel B′.sub.1; using the mapping between the output video frame pixel B.sub.4 and the accurate pixel B′.sub.1 in the fisheye image to render the fisheye image in reverse rendering to generate a stable video;

(79) It should also be noted that the perspective view generated by the projection or the color information of the asteroid image is input by interpolation, and finally a stable video can be generated.

(80) In the second embodiment of the present invention, according to the timestamp of the video frame pixel, calculating the rotation matrix of the camera movement under the timestamp of the current video frame pixel as the approximate rotation matrix of the camera when collecting the current pixel, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the is spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video. Thereby, the distortion of the rolling shutter of the panoramic video sequence can be corrected.

(81) The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, thereby achieve a better video image anti-shake effect.

Third Embodiment

(82) The third embodiment of the present invention provides a computer-readable storage medium that stores a computer program or computer programs including set of computer-executable instructions, which when being executed by a processor or processors, cause the processor or processors to perform steps of the anti-shake method for a panoramic video provided in the first or second embodiment of the present invention.

Fourth Embodiment

(83) FIG. 6 shows a structural block diagram of a portable terminal provided in the fourth embodiment of the present invention. A portable terminal 100 comprises:

(84) one or more processors 101, a memory 102, and one or more computer programs, where the one or more processors 101 and the memory 102 are connected by a bus, the one or more computer programs including set of computer-executable instructions are stored in the memory 102, and are configured to be executed by the one or more processors 101. The one or more processors 101 execute the one or more computer programs to perform steps of the anti-shake method for a panoramic video provided in the first or second embodiment of the present invention.

(85) A person of ordinary skill in the art may understand that all or part of the steps in the method of the above-mentioned embodiments can be implemented by a program or programs instructing relevant hardware. The program or programs can be stored in a computer-readable storage medium, and the storage media can be, such as ROM/RAM, magnetic disk, optical disk, etc.

(86) The above descriptions are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modification, equivalent replacements and improvement made within the spirit and principle of the present invention shall be included in the protection of the present invention.