Stitching pictures from rotating camera
I have a security camera that is rotating at 1rpm. It is set to 60° FOV, and configured on a preset to take 8 pictures in 1 rotation. With the knowledge of the FOV as well as the picture's direction (angle), how could I use OpenCV to stitch the 8 pictures together into a single 360° panoramic?
With 60° FOV at 8 pictures per rotation, there are 15° of overlap on each side of the picture.
With this information, it possible for me to compute the homography matrix manually? If so, I would greatly appreciate some direction!
Update:
Thank you @Eduardo for pointing me to this tutorial of stitching for a rotating camera. Following the tutorial, I am trying to compose the c1Mo
and c2Mo
matrices representing the "poses" of the camera, whereby the difference in the "poses" is the camera's rotation. Using Blender, I have modeled the scene, which involves the camera (with its known intrinsics inputted into Blender) in 2 "poses":
- Origin pose, looking down the Z axis.
- -22.5° rotation around the Y axis.
Using this script to get the P matrices of the two "poses" (which I assume are supposed to be the c1Mo
and c2Mo
in the tutorial), the tutorial code produces a H
matrix. However, the visual output is the following:
Am I missing some key piece in this solution? Making changes to c1Mo
and c2Mo
, based on rotation around different axes, or even random changes, (or even the K
matrix) lead to the same visual results.
This can be a good start.
Thank you the reference, @Eduardo. I followed the guide, and have tried to apply it to two pictures that have been taken with the security camera. The pictures were taken with the camera at 0° and 22.5° rotation. I know the camera intrinsic matrix, but am stuck trying to figure out
c1Mo
andc2Mo
. Are these homographic projection matrices? Is their difference is supposed to equate to the 22.5° rotation in the Y axis?What is important is that for a rotating camera, the Homography is
H = K x R x K^-1
. WithK
the camera intrinsic parameters andR
the rotation matrix between the two camera viewpoints. Have a look at this page to have an overview of the camera model.Again, thank you for your help @Eduardo. I have studied the camera model in depth, and see the
H = K x R x K^-1
in the tutorial code. I have updated the original question with my results, and would definitely appreciate your further guidance. Also, I am using both the code in the tutorial, as well as this code when running my tests.You can try this code
Computing
R
fromc1Mo
andc2Mo
is just an easy way to compute the rotation between the two camera viewpoints in Blender.In your case, you don't know
c1Mo
andc2Mo
unless you are using a calibration board, or explicitly computing it.For
R
, you should be able compute it using the angle. Look at 3d rotation matrix, and be careful about the camera coordinates system.