#ifndef IMAGESTITCHER_H #define IMAGESTITCHER_H #include #include #include #include class param; using namespace std; using namespace cv; int curl_upload(const QString filename); class ImageStitcher : public QObject { Q_OBJECT Q_PROPERTY(QStringList p_list READ p_listGet WRITE p_listSet NOTIFY p_listChanged ) //图片路径 signals: void stitchSuccess(QString result_path); void stitchFailed(); void pathChanged(QStringList imagepath); void process(QString log_info); void p_listChanged(); void change_stitch_photonum(int val); public: ImageStitcher(); void optimizeSeam(cv::Mat leftImage, cv::Mat leftImageTransform, cv::Mat rightImageTransform, cv::Mat &dstImage, std::vector sceneCorners); int stitch_default(); Q_INVOKABLE void stitch_thread(); QStringList p_listGet() const { //【线程安全】QML 侧可在任意时刻读取,不能直接访问全局 QStringList return param::photoPathsSnapshot(); } void p_listSet(QStringList n_list) { //【线程安全】QML 侧整体赋值与相机线程 append 竞争,需持锁 { QMutexLocker locker(¶m::photoListMutex()); param::ptlist = n_list; } emit p_listChanged(); } void saveStitchPamera(int index) { param::stitch_photonum = index; emit change_stitch_photonum(index); } void merge_pic(vector& images); private: QString m_resultPath; QStringList m_imagepath; QFuture future_stitch; static inline QImage cvMatToQImage( const cv::Mat &inMat ) { switch ( inMat.type() ) { // 8-bit, 4 channel case CV_8UC4: { QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB32 ); return image; } // 8-bit, 3 channel case CV_8UC3: { QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB888 ); return image.rgbSwapped(); } // 8-bit, 1 channel case CV_8UC1: { static QVector sColorTable; // only create our color table once if ( sColorTable.isEmpty() ) { for ( int i = 0; i < 256; ++i ) sColorTable.push_back( qRgb( i, i, i ) ); } QImage image( inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_Indexed8 ); image.setColorTable( sColorTable ); return image; } default: WARN("ASM::cvMatToQImage() - cv::Mat image type not handled in switch: {}", static_cast(inMat.type())); break; } return QImage(); } }; #endif // IMAGESTITCHER_H