1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 20 #ifdef _WIN32 21 #ifdef DBREG_EXPORTS 22 #define DBREG_API __declspec(dllexport) 23 #else 24 #define DBREG_API __declspec(dllimport) 25 #endif 26 #else 27 #define DBREG_API 28 #endif 29 30 extern "C" { 31 #include "vp_motionmodel.h" 32 } 33 34 #define MOTION_ARRAY 5 35 36 37 /*! 38 * Performs smoothing on the motion estimate from feature_stab. 39 */ 40 class DBREG_API db_StabilizationSmoother 41 { 42 public: 43 db_StabilizationSmoother(); 44 ~db_StabilizationSmoother(); 45 46 /*! 47 * Initialize parameters for stab-smoother. 48 */ 49 void Init(); 50 51 //! Smothing type 52 typedef enum { 53 SimpleSmooth = 0, //!< simple smooth 54 AdaptSmooth = 1, //!< adaptive smooth 55 PanSmooth = 2 //!< pan motion smooth 56 } SmoothType; 57 58 /*! 59 * Smooth-motion is to do a weight-average between the current affine and 60 * motLF. The way to change the affine is only for the display purpose. 61 * It removes the high frequency motion and keep the low frequency motion 62 * to the display. IIR implmentation. 63 * \param inmot input motion parameters 64 * \param outmot smoothed output motion parameters 65 */ 66 bool smoothMotion(VP_MOTION *inmot, VP_MOTION *outmot); 67 68 /*! 69 * The adaptive smoothing version of the above fixed smoothing function. 70 * \param hsize width of the image being aligned 71 * \param vsize height of the image being aligned 72 * \param inmot input motion parameters 73 * \param outmot smoothed output motion parameters 74 */ 75 bool smoothMotionAdaptive(/*VP_BIMG *bimg,*/int hsize, int vsize, VP_MOTION *inmot, VP_MOTION *outmot); 76 bool smoothPanMotion_1(VP_MOTION *inmot, VP_MOTION *outmot); 77 bool smoothPanMotion_2(VP_MOTION *inmot, VP_MOTION *outmot); 78 79 /*! 80 * Set the smoothing factor for the stab-smoother. 81 * \param factor the factor value to set 82 */ setSmoothingFactor(float factor)83 inline void setSmoothingFactor(float factor) { f_smoothFactor = factor; } 84 85 /*! 86 * Reset smoothing 87 */ resetSmoothing(bool flag)88 inline void resetSmoothing(bool flag) { f_smoothReset = flag; } 89 /*! 90 * Set the zoom factor value. 91 * \param zoom the value to set to 92 */ setZoomFactor(float zoom)93 inline void setZoomFactor(float zoom) { f_zoom = zoom; } 94 /*! 95 * Set the minimum damping factor value. 96 * \param factor the value to set to 97 */ setminDampingFactor(float factor)98 inline void setminDampingFactor(float factor) { f_minDampingFactor = factor; } 99 100 /*! 101 * Returns the current smoothing factor. 102 */ getSmoothingFactor(void)103 inline float getSmoothingFactor(void) { return f_smoothFactor; } 104 /*! 105 * Returns the current zoom factor. 106 */ getZoomFactor(void)107 inline float getZoomFactor(void) { return f_zoom; } 108 /*! 109 * Returns the current minimum damping factor. 110 */ getminDampingFactor(void)111 inline float getminDampingFactor(void) { return f_minDampingFactor; } 112 /*! 113 * Returns the current state of the smoothing reset flag. 114 */ getSmoothReset(void)115 inline bool getSmoothReset(void) { return f_smoothReset; } 116 /*! 117 * Returns the current low frequency motion parameters. 118 */ getMotLF(void)119 inline VP_MOTION getMotLF(void) { return f_motLF; } 120 /*! 121 * Returns the inverse of the current low frequency motion parameters. 122 */ getImotLF(void)123 inline VP_MOTION getImotLF(void) { return f_imotLF; } 124 /*! 125 * Set the dimensions of the alignment image. 126 * \param hsize width of the image 127 * \param vsize height of the image 128 */ setSize(int hsize,int vsize)129 inline void setSize(int hsize, int vsize) { f_hsize = hsize; f_vsize = vsize; } 130 131 protected: 132 133 bool smoothMotion(VP_MOTION *inmot, VP_MOTION *outmot, double smooth_factor); 134 bool smoothMotion1(VP_MOTION *inmot, VP_MOTION *outmot, VP_MOTION *motLF, VP_MOTION *imotLF, double smooth_factor); 135 void iterativeSmooth(VP_MOTION *input, VP_MOTION *output, double border_factor); 136 bool is_point_in_rect(double px, double py, double rx, double ry, double w, double h); 137 138 139 private: 140 int f_hsize; 141 int f_vsize; 142 bool f_smoothOn; 143 bool f_smoothReset; 144 float f_smoothFactor; 145 float f_minDampingFactor; 146 float f_zoom; 147 VP_MOTION f_motLF; 148 VP_MOTION f_imotLF; 149 VP_MOTION f_hist_mot[MOTION_ARRAY]; 150 VP_MOTION f_hist_mot_speed[MOTION_ARRAY-1]; 151 VP_MOTION f_hist_diff_mot[MOTION_ARRAY-1]; 152 VP_MOTION f_disp_mot; 153 VP_MOTION f_src_mot; 154 VP_MOTION f_diff_avg; 155 156 }; 157 158