ImageStitcher.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef IMAGESTITCHER_H
  2. #define IMAGESTITCHER_H
  3. #include <QObject>
  4. #include <QImage>
  5. #include <main.h>
  6. #include <m_loger.h>
  7. class param;
  8. using namespace std;
  9. using namespace cv;
  10. int curl_upload(const QString filename);
  11. class ImageStitcher : public QObject
  12. {
  13. Q_OBJECT
  14. Q_PROPERTY(QStringList p_list READ p_listGet WRITE p_listSet NOTIFY p_listChanged ) //图片路径
  15. signals:
  16. void stitchSuccess(QString result_path);
  17. void stitchFailed();
  18. void pathChanged(QStringList imagepath);
  19. void process(QString log_info);
  20. void p_listChanged();
  21. void change_stitch_photonum(int val);
  22. public:
  23. ImageStitcher();
  24. void optimizeSeam(cv::Mat leftImage, cv::Mat leftImageTransform, cv::Mat rightImageTransform, cv::Mat &dstImage, std::vector<cv::Point2f> sceneCorners);
  25. int stitch_default();
  26. Q_INVOKABLE void stitch_thread();
  27. QStringList p_listGet() const
  28. {
  29. //【线程安全】QML 侧可在任意时刻读取,不能直接访问全局 QStringList
  30. return param::photoPathsSnapshot();
  31. }
  32. void p_listSet(QStringList n_list)
  33. {
  34. //【线程安全】QML 侧整体赋值与相机线程 append 竞争,需持锁
  35. {
  36. QMutexLocker locker(&param::photoListMutex());
  37. param::ptlist = n_list;
  38. }
  39. emit p_listChanged();
  40. }
  41. void saveStitchPamera(int index)
  42. {
  43. param::stitch_photonum = index;
  44. emit change_stitch_photonum(index);
  45. }
  46. void merge_pic(vector<Mat>& images);
  47. private:
  48. QString m_resultPath;
  49. QStringList m_imagepath;
  50. QFuture<int> future_stitch;
  51. static inline QImage cvMatToQImage( const cv::Mat &inMat )
  52. {
  53. switch ( inMat.type() )
  54. {
  55. // 8-bit, 4 channel
  56. case CV_8UC4:
  57. {
  58. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB32 );
  59. return image;
  60. }
  61. // 8-bit, 3 channel
  62. case CV_8UC3:
  63. {
  64. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB888 );
  65. return image.rgbSwapped();
  66. }
  67. // 8-bit, 1 channel
  68. case CV_8UC1:
  69. {
  70. static QVector<QRgb> sColorTable;
  71. // only create our color table once
  72. if ( sColorTable.isEmpty() )
  73. {
  74. for ( int i = 0; i < 256; ++i )
  75. sColorTable.push_back( qRgb( i, i, i ) );
  76. }
  77. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_Indexed8 );
  78. image.setColorTable( sColorTable );
  79. return image;
  80. }
  81. default:
  82. WARN("ASM::cvMatToQImage() - cv::Mat image type not handled in switch: {}", static_cast<int>(inMat.type()));
  83. break;
  84. }
  85. return QImage();
  86. }
  87. };
  88. #endif // IMAGESTITCHER_H