Stabilization algorithm includes the following main elements: detection bias for the current frame, the compensation of the bias and periodically update the background against which there is a stabilization. Below I detail sign for each of them.

Fig. 1 Image stabilization is sometimes very useful.

1) Take the central part of the background image. The magnitude of the indentation determines the maximum possible displacement that we want to define. The central part should not be too small, otherwise the correlation function (see below) will not have enough data for stable operation.

2) the current frame is selected portion of the same size, but offset relative to the center of the picture.

3) For each offset is calculated a metric, which describes the correlation of the central portion of the current image and the background. This may be used, for example, the sum of squared differences for each point of the two images or, for example, sum of absolute difference for each point.

4) Shifting for which the maximum correlation (less than the sum of squared differences or sum of absolute difference) is the required offset.

Fig. 2 Offset the current frame relative to the background.

Naturally, if such an approach is applied on the forehead, the speed of the algorithm will be catastrophically low, even though the fact that the speed of the correlation functions can be very high. This is not surprising, since we will need to go through all the options for possible image offset relative to each other (the complexity of the algorithm can be estimated as O (n ^ 2), where n - number of pixels in the image).

The first optimization is to use a non exhaustive search of all possible embodiments, and using the gradient descent method in the beginning, the correlation is calculated for a 3x3 region of zero offset, then select the maximum correlation shift, and the process is repeated until until a local maximum is detected. This method is considerably faster, but in the worst case of large displacements it will have complexity O (n ^ 1.5), which is not acceptable.

Figure 3. Search for the maximum of the correlation function. Gradient descent.

The way out of this situation is the use of multi-scale images (each zoom level reduces the image twice). Now look for a local maximum correlation we will seek to maximize the scale and then on a smaller scale it consistently refined. Thus, the algorithm reduces the complexity to O (n), which is quite acceptable.

Figure 4 Multiscale image.

2) Payment of camera shake with sub-pixel accuracy.

2) detects and compensated only spatial shift camera, rotate the camera will not be compensated.

3) The background must be sufficiently clear and non-uniform, or the correlation function will be nothing to catch. Therefore, in the dark or in fog stabilization will not function properly.

4) The background should be fixed. Stabilizer on the background of traveling waves is also impossible.

In implementing the stabilizer is desirable to use optimized functions for image manipulation. I used for this purpose library Simd . It can be found in particular:

1) SimdAbsDifferenceSum and SimdAbsDifferenceSumMasked - for the calculation of the correlation function.

2) SimdReduceGray2x2, SimdReduceGray3x3, SimdReduceGray4x4 and SimdReduceGray5x5 - for building multi-scale images.

3) SimdBgrToGray - for gray image.

4) SimdShiftBilinear - to compensate for the shift.

Example 2:

Source: habrahabr.ru/post/219815/

#### Choose the best action-camera summer

#### How to choose a DVR 2015: the largest online FAQ for general consumer

#### Google introduced the Nexus 6

#### Sunset manual

#### The spacecraft "Soyuz TMA-09M"

#### Images of Mars in the artistic treatment

#### The most compact in the world of digital fotooapparat

#### Luggage on wheels

#### Walk through the Space Station ISS

#### What's inside the cable headend