/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* $Id: db_rob_image_homography.cpp,v 1.2 2011/06/17 14:03:31 mbansal Exp $ */ #include "db_utilities.h" #include "db_rob_image_homography.h" #include "db_bundle.h" /***************************************************************** * Lean and mean begins here * *****************************************************************/ #include "db_image_homography.h" #ifdef _VERBOSE_ #include using namespace std; #endif /*VERBOSE*/ inline double db_RobImageHomography_Cost(double H[9],int point_count,double *x_i,double *xp_i,double one_over_scale2) { int c; double back,acc,*x_i_temp,*xp_i_temp; for(back=0.0,c=0;cnr_points=point_count; stat->one_over_scale2=one_over_scale2; stat->nr_inliers=i; stat->inlier_fraction=frac; stat->cost=db_RobImageHomography_Cost(H,point_count,x_i,xp_i,one_over_scale2); stat->model_dimension=0; /*stat->nr_parameters=;*/ stat->lambda1=log(4.0); stat->lambda2=log(4.0*((double)db_maxi(1,stat->nr_points))); stat->lambda3=10.0; stat->gric=stat->cost+stat->lambda1*stat->model_dimension*((double)stat->nr_points)+stat->lambda2*((double)stat->nr_parameters); stat->inlier_evidence=((double)stat->nr_inliers)-stat->lambda3*((double)stat->nr_parameters); } return(frac); } /*Compute min_Jtf and upper right of JtJ. Return cost.*/ inline double db_RobImageHomography_Jacobians(double JtJ[81],double min_Jtf[9],double H[9],int point_count,double *x_i,double *xp_i,double one_over_scale2) { double back,Jf_dx[18],f[2],temp,temp2; int i; db_Zero(JtJ,81); db_Zero(min_Jtf,9); for(back=0.0,i=0;i=sample_size) for(i=0;i=2) for(i=0;i=3) for(i=0;i=3) for(i=0;i=3) for(i=0;i=4) for(i=0;i0) && (inr_parameters=8; break; case DB_HOMOGRAPHY_TYPE_AFFINE: if(stat) stat->nr_parameters=6; break; case DB_HOMOGRAPHY_TYPE_SIMILARITY: case DB_HOMOGRAPHY_TYPE_SIMILARITY_U: case DB_HOMOGRAPHY_TYPE_CAMROTATION_F: case DB_HOMOGRAPHY_TYPE_CAMROTATION_F_UD: if(stat) stat->nr_parameters=4; break; case DB_HOMOGRAPHY_TYPE_CAMROTATION: if(stat) stat->nr_parameters=3; break; case DB_HOMOGRAPHY_TYPE_TRANSLATION: case DB_HOMOGRAPHY_TYPE_S_T: case DB_HOMOGRAPHY_TYPE_R_T: case DB_HOMOGRAPHY_TYPE_R_S: if(stat) stat->nr_parameters=2; break; case DB_HOMOGRAPHY_TYPE_ROTATION: case DB_HOMOGRAPHY_TYPE_ROTATION_U: case DB_HOMOGRAPHY_TYPE_SCALING: if(stat) stat->nr_parameters=1; break; } db_RobImageHomography_Statistics(H_temp,db_mini(point_count,max_points),x_i,xp_i,one_over_scale2,stat); /*Put on the calibration matrices*/ db_Multiply3x3_3x3(H_temp2,H_temp,K_inv); db_Multiply3x3_3x3(H,Kp,H_temp2); if (finalNumE) *finalNumE = point_count_new; }