#pragma once #include "featureMatch.h" #include "graphPro.h" #include "topology.h" #include "levmar.h" #include #include #define PENALTY_COEFF 0.10 //! set for LM only #define Lambada 0.12 //! set for BA only #define OPT_GROUP_NUM 30 #define BKGRNDPIX 255 #define Need_Mask 1 using namespace std; using namespace cv; using namespace Utils; struct Match_Net { int imgNo; //! image no. start from 0 vector relatedImgs; //! the position index of overlap-image in visitOrder vector > PointSet; }; struct LMData { vector *matchPtr; vector > *modelPtr; vector visitOrder; int sIndex; int eIndex; }; //-------------------------------------------------------------------- //! Notification : imgIndex/imgNo start from 0 class ImageAligner { public: ImageAligner(vector filePathList) { _filePathList = filePathList; _imgNum = filePathList.size(); _refImgNo = 0; }; ~ImageAligner(){}; public: //*** functions for sorting the topological relationship of images ***// void sortImageOrder(int referNo, bool shallLoad, bool isInorder); void divideImageGroups(); bool loadMatchPts(int imgIndex1, int imgIndex2, vector &pointSet1, vector &pointSet2); public: //*** functions for building and optimizing the alignment ***// void imageStitcherbyGroup(int referNo); void imageStitcherbySolos(int referNo); void fillImageMatchNet(); //! initial alignment by affine model void solveGroupModels(int sIndex, int eIndex); //! initial alignment by similarity transformation model void solveGroupModelsS(int sIndex, int eIndex); //! initial alignment by affine model void solveSingleModel(int imgIndex); int findVisitIndex(int imgNo); //! alignment refinement to homographic model : LM Optimization void RefineAligningModels(int sIndex, int eIndex); void buildIniSolution(double* X, int sIndex, int eIndex); static void OptimizationFunction(double* X, double* d, int m, int n, void* data); //! alignment refinement to homographic model : Least Square Optimization void bundleAdjustingA(int sIndex, int eIndex); //! method 1 : big matrix void bundleAdjustinga(int sIndex, int eIndex); //! method 1 : normalize by point void bundleAdjusting(int sIndex, int eIndex); //! method 2 : normalize by point void buildIniSolution(double* X, double* initX, int sIndex, int eIndex); double CalWarpDeviation(vector pointSet1, vector pointSet2, Mat_ cvtMat, vector weightList); //! detect potential overlapping relationships based on the new position (only used in the refinement) void recheckTopology(int sIndex, int eIndex); //! display or output functions Rect setImageSize(vector &nodePts); void saveMosaicImage(); //! aligning in added order void saveMosaicImageP(); //! aligning in image no. order void outputPrecise(); void loadHomographies(); void saveModelParams(); void drawTopologyNet(); void labelGroupNodes(); void drawSimilarMatrix(); private: PointMatcher *_matcher; Mat_ _similarityMat; int _refImgNo; int _imgNum; int _alignedNum; vector _groupCusorList; vector _visitOrder; //! aligning order according this stack vector _projCoordSet; //! same order with "_visitOrder" vector _matchNetList; //! matching relation of each image (order agree with image no.) vector > _alignModelList; //! aligning model parameters of each image (order agree with '_visitOrder') vector > _initModelList; vector reliabilityList; //! record the mean square error of the initial affine model of each image vector _filePathList; vector _imgSizeList; //! order agree with image no. };