ImageStitcher.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. return param::ptlist;
  30. }
  31. void p_listSet(QStringList n_list)
  32. {
  33. param::ptlist = n_list;
  34. emit p_listChanged();
  35. }
  36. void saveStitchPamera(int index)
  37. {
  38. param::stitch_photonum = index;
  39. emit change_stitch_photonum(index);
  40. }
  41. void merge_pic(vector<Mat>& images);
  42. private:
  43. QString m_resultPath;
  44. QStringList m_imagepath;
  45. QFuture<int> future_stitch;
  46. static inline QImage cvMatToQImage( const cv::Mat &inMat )
  47. {
  48. switch ( inMat.type() )
  49. {
  50. // 8-bit, 4 channel
  51. case CV_8UC4:
  52. {
  53. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB32 );
  54. return image;
  55. }
  56. // 8-bit, 3 channel
  57. case CV_8UC3:
  58. {
  59. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB888 );
  60. return image.rgbSwapped();
  61. }
  62. // 8-bit, 1 channel
  63. case CV_8UC1:
  64. {
  65. static QVector<QRgb> sColorTable;
  66. // only create our color table once
  67. if ( sColorTable.isEmpty() )
  68. {
  69. for ( int i = 0; i < 256; ++i )
  70. sColorTable.push_back( qRgb( i, i, i ) );
  71. }
  72. QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_Indexed8 );
  73. image.setColorTable( sColorTable );
  74. return image;
  75. }
  76. default:
  77. WARN("ASM::cvMatToQImage() - cv::Mat image type not handled in switch: {}", static_cast<int>(inMat.type()));
  78. break;
  79. }
  80. return QImage();
  81. }
  82. };
  83. #endif // IMAGESTITCHER_H