blob: 59cde7daa80e70972f00f950f8a6432c962720bb [file] [log] [blame]
Sascha Haeberling8bddf8c2013-08-14 11:20:34 -07001/*
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/* $Id: db_rob_image_homography.h,v 1.3 2011/06/17 14:03:31 mbansal Exp $ */
18
19#ifndef DB_ROB_IMAGE_HOMOGRAPHY
20#define DB_ROB_IMAGE_HOMOGRAPHY
21
22#include "db_utilities.h"
23#include "db_robust.h"
24#include "db_metrics.h"
25
26#include <stdlib.h> // for NULL
27
28
29/*****************************************************************
30* Lean and mean begins here *
31*****************************************************************/
32/*!
33 * \defgroup LMRobImageHomography (LM) Robust Image Homography
34 */
35/*\{*/
36
37#define DB_HOMOGRAPHY_TYPE_DEFAULT 0
38#define DB_HOMOGRAPHY_TYPE_PROJECTIVE 0
39#define DB_HOMOGRAPHY_TYPE_AFFINE 1
40#define DB_HOMOGRAPHY_TYPE_SIMILARITY 2
41#define DB_HOMOGRAPHY_TYPE_SIMILARITY_U 3
42#define DB_HOMOGRAPHY_TYPE_TRANSLATION 4
43#define DB_HOMOGRAPHY_TYPE_ROTATION 5
44#define DB_HOMOGRAPHY_TYPE_ROTATION_U 6
45#define DB_HOMOGRAPHY_TYPE_SCALING 7
46#define DB_HOMOGRAPHY_TYPE_S_T 8
47#define DB_HOMOGRAPHY_TYPE_R_T 9
48#define DB_HOMOGRAPHY_TYPE_R_S 10
49#define DB_HOMOGRAPHY_TYPE_CAMROTATION 11
50#define DB_HOMOGRAPHY_TYPE_CAMROTATION_F 12
51#define DB_HOMOGRAPHY_TYPE_CAMROTATION_F_UD 13
52
53/*!
54Solve for homography H such that xp~Hx
55\param H best homography
56
572D point to 2D point constraints:
58
59\param im first image points
60\param im_p second image points
61\param nr_points number of points
62
63Calibration matrices:
64
65\param K first camera
66\param Kp second camera
67
68 Temporary space:
69
70 \param temp_d pre-allocated space of size 12*nr_samples+10*nr_points doubles
71 \param temp_i pre-allocated space of size max(nr_samples,nr_points) ints
72
73 Statistics for this estimation
74
75 \param stat NULL - do not compute
76
77 \param homography_type see DB_HOMOGRAPHY_TYPE_* definitions above
78
79 Estimation parameters:
80
81 \param max_iterations max number of polishing steps
82 \param max_points only use this many points
83 \param scale Cauchy scale coefficient (see db_ExpCauchyReprojectionError() )
84 \param nr_samples number of times to compute a hypothesis
85 \param chunk_size size of cost chunks
86*/
87DB_API void db_RobImageHomography(
88 /*Best homography*/
89 double H[9],
90 /*2DPoint to 2DPoint constraints
91 Points are assumed to be given in
92 homogenous coordinates*/
93 double *im,double *im_p,
94 /*Nr of points in total*/
95 int nr_points,
96 /*Calibration matrices
97 used to normalize the points*/
98 double K[9],
99 double Kp[9],
100 /*Pre-allocated space temp_d
101 should point to at least
102 12*nr_samples+10*nr_points
103 allocated positions*/
104 double *temp_d,
105 /*Pre-allocated space temp_i
106 should point to at least
107 max(nr_samples,nr_points)
108 allocated positions*/
109 int *temp_i,
110 int homography_type=DB_HOMOGRAPHY_TYPE_DEFAULT,
111 db_Statistics *stat=NULL,
112 int max_iterations=DB_DEFAULT_MAX_ITERATIONS,
113 int max_points=DB_DEFAULT_MAX_POINTS,
114 double scale=DB_POINT_STANDARDDEV,
115 int nr_samples=DB_DEFAULT_NR_SAMPLES,
116 int chunk_size=DB_DEFAULT_CHUNK_SIZE,
117 ///////////////////////////////////////////////////
118 // flag for the outlier removal
119 int outlierremoveflagE = 0,
120 // if flag is 1, then the following variables
121 // need to input
122 ///////////////////////////////////////////////////
123 // 3D coordinates
124 double *wp=NULL,
125 // its corresponding stereo pair's points
126 double *im_r=NULL,
127 // raw image coordinates
128 double *im_raw=NULL, double *im_raw_p=NULL,
129 // final matches
130 int *final_NumE=0);
131
132DB_API double db_RobImageHomography_Cost(double H[9],int point_count,double *x_i,
133 double *xp_i,double one_over_scale2);
134
135
136DB_API void db_RobCamRotation_Polish(double H[9],int point_count,double *x_i,
137 double *xp_i, double one_over_scale2,
138 int max_iterations=DB_DEFAULT_MAX_ITERATIONS,
139 double improvement_requirement=DB_DEFAULT_IMP_REQ);
140
141
142DB_API void db_RobCamRotation_Polish_Generic(double H[9],int point_count,int homography_type,
143 double *x_i,double *xp_i,double one_over_scale2,
144 int max_iterations=DB_DEFAULT_MAX_ITERATIONS,
145 double improvement_requirement=DB_DEFAULT_IMP_REQ);
146
147
148#endif /* DB_ROB_IMAGE_HOMOGRAPHY */