ImageTailor.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include <opencv2/opencv.hpp>
  3. #include <queue>
  4. #include <thread>
  5. #include <mutex>
  6. //set a struct to record the work queue
  7. typedef struct WaitingTailor{
  8. cv::Point ptPosition;
  9. cv::Mat* pROI;
  10. unsigned char* pImage {NULL};
  11. int nWidth;
  12. int nHeight;
  13. int nPitch;
  14. std::vector<std::vector<int>>* pvvOverlap;
  15. } WAIT_TAILOR, *LPWAITLOR;
  16. extern std::mutex g_CurFrameMutex;
  17. extern std::mutex g_PanoMutex;
  18. class ImageTailor
  19. {
  20. public:
  21. ImageTailor();
  22. ~ImageTailor();
  23. //set a function to initialize the Tailor
  24. void Init(unsigned char* pImage, int nPanoWidth, int nPanoHeight, cv::Point cvLeftTop);
  25. void Init_Gpu(unsigned char* pImage,unsigned char* pImageGpu, int nPanoWidth, int nPanoHeight, cv::Point cvLeftTop);
  26. //set a function to calculate the stitching position
  27. int StitchingOnPano(cv::Point LeftTop, cv::Mat* FrameImage, std::vector<std::vector<int>>* pvvOverlap);
  28. //define a function to Copy the YUV I420 image
  29. int StitchingOnPanoYUV(cv::Point LeftTop, unsigned char* pImage, int nWidth, int nHeight, int nPitch, std::vector<std::vector<int>>* pvvOverlap);
  30. int StitchingOnPanoYUV(cv::Point LeftTop,cv::Mat* FrameImage, std::vector<std::vector<int>>* pvvOverlap);
  31. static void TailorWordInThread(ImageTailor* pClass);
  32. int StitchingOnPanoYUVByGPU(cv::Point LeftTop, unsigned char* FrameImage,int nWidth,int nHeight,int nPitch, std::vector<std::vector<int>>* pvvOverlap);
  33. //stitching
  34. int Stitching(int nPostion, cv::Mat& ROI, std::vector<std::vector<int>>* pvvOverlap);
  35. //set a function to Set the overlap
  36. void SetOverlap(std::vector<std::vector<int>>* pvvOverlap);
  37. //set a function to start the tailor thread
  38. bool StartTailorThread();
  39. bool EndTailorThread();
  40. void AddWorkOrderInqueue(cv::Point LeftTop, cv::Mat* FrameImage, std::vector<std::vector<int>>* pvvOverlap);
  41. void ClearWorkOrder();
  42. void AddWorkOrderInQueueGpu(cv::Point LeftTop, unsigned char* pData, int nWidth, int nHeight, int nPitch, std::vector<std::vector<int>>* pvvOverlap);
  43. //set a pointer to store the image,and this image has been aligned4
  44. unsigned char* pPanoImageBuffer;
  45. //另一个用于显存的图像指针
  46. unsigned char* pPanoImageBufferInGpu;
  47. //pano image width
  48. int nPanoWidth;
  49. //pano image height
  50. int nPanoHeight;
  51. //pano image pitch
  52. int nPanoPitch;
  53. //Current panoImage LeftTop position,for the situation that the leftTop is not (0,0)
  54. cv::Point LeftTop;
  55. //save overlap
  56. std::vector<std::vector<int>> vvOverlap;
  57. //work queue use by tailor thread
  58. std::queue<WAIT_TAILOR> qWorkQueue;
  59. //thread handle
  60. std::thread* pTailorThread;
  61. //thread switch
  62. bool bTailorThreadOut;
  63. //thread work status
  64. bool bTailorThreadWork;
  65. // is use yuv or not
  66. bool bUseYUV;
  67. };