#pragma once #include #include "OptimizeCal.h" #include "MfcLabel.h" #include "FusionAndTailor.cuh" #include const int OVERLAP_WIDEN = 20; const int FUSION_WINDOW_SIZE = 5; #define CATCH_OPENCV_ERROR(Func) \ try \ { \ Func; \ } \ catch (cv::Exception& e) \ { \ std::cout << e.what() << std::endl; \ } \ typedef std::vector vMat; /// /// the class is used to fuse the image /// class ImageFusion { public: ImageFusion(); //********************************laplace fusion function************************** //set a function to initialize the laplace ImageFusion void Init(unsigned char * pImage, int nPanoWidth, int nPanoHeight,int nPanoPitch); void Init_Gpu(unsigned char* pImage, int nPanoWidth, int nPanoHeight, int nPanoPitch); //set a function to get the Image laplace Pyramid void GetLaplacePyramid(cv::Mat& Image, std::vector& vLaplacePyramid,int nLayer,int nSize,float Sigma); void GetDogPyramid(cv::Mat& Mask, std::vector& DogPyr,int nLevel); //set a function to get the Image gauss Pyramid void GetGaussPyramid(cv::Mat& Image, std::vector& vGaussPyramid, int nLayer, int nSize, float Sigma); //set a funcion to cal the blend image void CalBlendImage(vMat& vInferPy, vMat& vTargetPy, vMat& vMaskPy, vMat& vResultPy); //the function to use laplace pyramid to fuse the image void FusionImageByLaplacePyramid(cv::Mat* pLeft,cv::Mat* Right,int nLayer,int nSize,float Sigma); //cv::Mat Pano void FusionImageByLaplacePyramid(cv::Mat* pPano,cv::Rect InferRc ,cv::Mat* pCvTarget, int nLayer, int nSize, float Sigma); //unsigned char* Pano void FusionImageByLaplacePyramid(unsigned char* pPano, cv::Rect InferRc,unsigned char* pCvTarget,cv::Size SzTargetMat, int nLayer, int nSize, float Sigma, cv::Point LeftTop); //get result void GetLaplaceFusionImage(unsigned char* pFusionImage, int& nWidth, int& nHeight, int& nPitch); /***************************Thin Rect Window Slide Mean Fusion***********************************************************/ //define a function to fusion image by mean image void FusionImageByThinRectWindowSlideMean(unsigned char* pPano, cv::Rect InferRc, int nSize, int nType = 0, float Sigma = 0); //define a function to fusion image by mean image,fusion single refresh mode void FusionImageByThinRectWindowSlideMean(unsigned char* pPano, cv::Rect InferRc, cv::Mat& InferImg,cv::Rect CurCoordinateRc,cv::Mat& TargetImg,cv::Rect TargetRc,int nSize, int nType=0, float Sigma=0); cv::Mat CreateThinRectWindow(int nHeight, int nWidth, int nType, int nChannels); // double CaculateGaussWeight(double x, double sigma); void Convolution2D(cv::Mat& Src, cv::Mat& Dst, cv::Mat& Kernel); //1d convolution void Convolution1D(cv::Mat& Src, cv::Mat& Dst, cv::Mat& Kernel); /*****************************Blending gradient*********************************/ void FusionImageByBlendingGradient(unsigned char* pPano, cv::Rect InferRc, cv::Mat& InferImg, cv::Rect CurCoordinateRc, cv::Mat& TargetImg, cv::Rect TargetRc); void FusionImageByBlendingGradientYUV( unsigned char* pPano, cv::Rect InferRc, unsigned char* pInfer, int nInferWidth, int nInferHeight, int nInferPitch, cv::Rect CurCoordinateRc, unsigned char* pTarget, int nTargetWidth, int nTargetHeight, int nTargetPitch, cv::Rect TargetRc, bool bUseSSE2 = false ); void FusionImageByBlendingGradientYUVByGpu( unsigned char* pPano, cv::Rect InferRc, unsigned char* pInfer, int nInferWidth, int nInferHeight, int nInferPitch, cv::Rect CurCoordinateRc, unsigned char* pTarget, int nTargetWidth, int nTargetHeight, int nTargetPitch, cv::Rect TargetRc ); void GetGradientMask(cv::Rect Infer, cv::Rect Target, cv::Mat& MaskTarget,cv::Mat& MaskInfer ,std::vector& bAddOrSub); /*****************************Blending gradient by yuv***************************************************/ void BlendingLinearYUV( unsigned char* pInfer, int nInferWidth, int nInferHeight, int nInferPitch, unsigned char* pTarget, int nTargetWidth, int nTargetHeight, int nTargetPitch, cv::Mat& cvInferWeight, cv::Mat& cvTargetWeight, unsigned char*& pResult, bool bUseAVX = false ); void BlendingLinearYUVByGpu( unsigned char* pInfer, int nInferWidth, int nInferHeight, int nInferPitch, unsigned char* pTarget, int nTargetWidth, int nTargetHeight, int nTargetPitch, cv::Mat& cvInferWeight, cv::Mat& cvTargetWeight, unsigned char*& pResult ); /*****************************************粘贴指定部分yuv图像到yuv全景上面*************************************/ void PastePartInWholeImageYUV( unsigned char* pPanoImg, int nPanoWidth, int nPanoHeight, int nPanoPitch, unsigned char* pPartImg, int nPartWidth, int nPartHeight, int nPartPitch, int nLeft, int nTop, bool bUseAVX = false ); void PastePartInWholeImageYUVByGpu( unsigned char* pPanoImg, int nPanoWidth, int nPanoHeight, int nPanoPitch, unsigned char* pPartImg, int nPartWidth, int nPartHeight, int nPartPitch, int nLeft, int nTop, CUstream* pStream = NULL ); /****************************************************GPU初始化**************************************************/ private: //pointer to store the image,and this image has been aligned4 unsigned char* pPanoImageBuffer; //设置一个用于存放gpu运算的buffer unsigned char* pPanoImageBufferGpu; //pano image width int nPanoWidth; //pano image height int nPanoHeight; //pano image pitch int nPanoPitch; //Additional Window Widen int nAdditionalWiden; //create a queue to send the command let the painter process work bool bIsModified; };