ImageStitcher.h 2.6 KB

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