Qt图像处理时需要OpenCv中Mat与QImage互转,具体代码如下
创建EditPhoto,头文件,使用前需要配置好opencv
#include <QObject>
#include <QImage>
#include <QDebug>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/imgcodecs/imgcodecs.hpp>
#include<opencv2/opencv.hpp>
#include <iostream>
using namespace std;
class EditPhoto: public QObject
{
Q_OBJECT
public:
explicit EditPhoto(QObject *parent = 0);
~EditPhoto();
static QImage MatToImage(cv::Mat &m); //Mat转QImage
static cv::Mat ImageToMat(const QImage &image); //QImage转Mat
};
#endif // EDITPHOTO_H
.cpp文件
#include "editphoto.h"
EditPhoto::EditPhoto(QOb