# Efficient method of inserting an image into the horizon of handheld footage

I'm doing the special effects for a video where I need to insert an image of a submarine into the horizon (where the question mark is):

At first, I attempted to do a full 3D Motion Track. I properly tracked as many points as I could, but when the camera motion was solved for, it was extremely jumpy. So then I decided that since most of the motion in the video is 2D that I would only use two tracks, and then take the image of the submarine and apply the 2D stabilization node to it. I'm kind of surprised that it stabilized the video perfectly (including rotation), but when I used the node to translate the submarine placeholder image, it slid around quite a bit.
The effect it had can be seen in this video:
https://youtu.be/jHQHfG-YaI8

So the next thing I did was use one of the tracks, create an empty for it, import the image as a plane, and make the empty a parent of it. This worked excellent for translation of the image, but it did not take into account the rotation needed to fit nicely into the video motion (which is normally calculated with a second tracker so that rotation can be stabilized in normal 2D stabilization). How is it possible to properly accomplish the desired effect?

Terrible shot to track, since everything is moving (the character, the waves and the camera). There are hardly distinct features to compute any parallax, lens distortion or extract any spatial information. 3D tracking and reconstruction are not going to work here.

On the other hand because there is so little to go by, any errors on the composite will not be as noticeable... so a 2D solution might indeed work.

Track just two points on the sky an the clouds, they are about the only thing that will not change from frame to frame. One tracker on the left side of the frame an one on the right . That should give you enough information for 2D stabilization.

Use both trackers to stabilize the shot (with the trackers selected press the + sign to the right of the 2D stabilization box)

Make sure you don't use Autoscale.

and use only one to compute the rotation:

The trick now is doing the rest in the compositor: Instead of stabilizing the shot you want to make the 3D scene move (and rotate) in the opposite direction as the stabilization, and thus match the movement of the camera...

A node setup like this would work. Where you first flip the render layer, stabilize it and scale it to -1 (flipping it again it and making it move like the camera) before compositing on top of the movie clip.

Now, how do you match the perspective? you'll have to guesstimate a bit. or use the technique from this answer: https://blender.stackexchange.com/a/40330/1853 using the background image as a reference and moving the camera using Lock Camera to View...

• Okay, thanks for the answer. It hasn't worked so far although it seems like it should. I'll keep testing tomorrow. As of right now, it seems like the y translation imposed by the 2D Stabilization is inverted. Commented Nov 14, 2015 at 6:57