123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #pragma once
- #include <opencv2/opencv.hpp>
- #include "OptimizeCal.h"
- #include "MfcLabel.h"
- #include "FusionAndTailor.cuh"
- #include <queue>
- 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<cv::Mat> vMat;
- /// <summary>
- /// the class is used to fuse the image
- /// </summary>
- 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<cv::Mat>& vLaplacePyramid,int nLayer,int nSize,float Sigma);
- void GetDogPyramid(cv::Mat& Mask, std::vector<cv::Mat>& DogPyr,int nLevel);
- //set a function to get the Image gauss Pyramid
- void GetGaussPyramid(cv::Mat& Image, std::vector<cv::Mat>& 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<bool>& 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;
- };
|