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///////////////////////////////////////////////////
18// Align.h
19// S.O. # :
20// Author(s): zkira
21// $Id: AlignFeatures.h,v 1.13 2011/06/17 13:35:47 mbansal Exp $
22
23#ifndef ALIGN_H
24#define ALIGN_H
25
26#include "dbreg/dbreg.h"
27#include <db_utilities_camera.h>
28
29#include "ImageUtils.h"
30#include "MatrixUtils.h"
31
32class Align {
33
34public:
35  // Types of alignment possible
36  static const int ALIGN_TYPE_PAN    = 1;
37
38  // Return codes
39  static const int ALIGN_RET_LOW_TEXTURE  = -2;
40  static const int ALIGN_RET_ERROR        = -1;
41  static const int ALIGN_RET_OK           = 0;
42  static const int ALIGN_RET_FEW_INLIERS  = 1;
43
44  ///// Settings for feature-based alignment
45  // Number of features to use from corner detection
46  static const int DEFAULT_NR_CORNERS=750;
47  static const double DEFAULT_MAX_DISPARITY=0.1;//0.4;
48  // Type of homography to model
49  static const int DEFAULT_MOTION_MODEL=DB_HOMOGRAPHY_TYPE_R_T;
50// static const int DEFAULT_MOTION_MODEL=DB_HOMOGRAPHY_TYPE_PROJECTIVE;
51//  static const int DEFAULT_MOTION_MODEL=DB_HOMOGRAPHY_TYPE_AFFINE;
52  static const unsigned int DEFAULT_REFERENCE_UPDATE_PERIOD=1500; //  Manual reference frame update so set this to a large number
53
54  static const int MIN_NR_REF_CORNERS = 25;
55  static const int MIN_NR_INLIERS = 10;
56
57  Align();
58  ~Align();
59
60  // Initialization of structures, etc.
61  int initialize(int width, int height, bool quarter_res, float thresh_still);
62
63  // Add a frame.  Note: The alignment computation is performed
64  // in this function
65  int addFrameRGB(ImageType image);
66  int addFrame(ImageType image);
67
68  // Obtain the TRS matrix from the last two frames
69  int getLastTRS(double trs[3][3]);
70  char* getRegProfileString();
71
72protected:
73
74  db_FrameToReferenceRegistration reg;
75
76  int frame_number;
77
78  double Hcurr[9];   // Homography from the alignment reference to the frame-t
79  double Hprev[9];   // Homography from frame-0 to the frame-(t-1)
80
81  int reference_frame_index; // Index of the reference frame from all captured frames
82  int num_frames_captured; // Total number of frames captured (different from frame_number)
83  double average_tx_per_frame; // Average pixel translation per captured frame
84
85  int width,height;
86
87  bool quarter_res;     // Whether to process at quarter resolution
88  float thresh_still;   // Translation threshold in pixels to detect still camera
89  ImageType imageGray;
90};
91
92
93#endif
94