29 #include "opencv2/opencv.hpp" 30 #include "opencv2/highgui/highgui.hpp" 34 inline QImage mat_2_qimage_ref_policy(cv::Mat &mat, QImage::Format format)
36 return QImage(mat.data, mat.cols, mat.rows, mat.step, format);
39 inline QImage mat_2_qimage_cpy_policy(cv::Mat
const &mat, QImage::Format format)
41 return QImage(mat.data, mat.cols, mat.rows, mat.step, format).copy();
47 struct qimage_2_mat_cpy_policy
49 static cv::Mat start(QImage
const &img,
int format)
51 return cv::Mat(img.height(), img.width(), format, const_cast<uchar*>(img.bits()), img.bytesPerLine()).clone();
60 struct qimage_2_mat_ref_policy
62 static cv::Mat start(QImage &img,
int format)
64 return cv::Mat(img.height(), img.width(), format, img.bits(), img.bytesPerLine());
71 template<
typename Policy>
74 template<
typename Image>
75 static cv::Mat run(Image &img,
bool swap);
83 template<
typename Policy>
84 template<
typename Image>
85 cv::Mat qimage_2_mat<Policy>::run(Image &img,
bool swap)
91 switch (img.format()) {
92 case QImage::Format_RGB888:{
93 cv::Mat result = Policy::start(img, CV_8UC3);
95 cv::cvtColor(result, result, CV_RGB2BGR);
99 case QImage::Format_Indexed8:{
100 return Policy::start(img, CV_8U);
102 case QImage::Format_RGB32:
103 case QImage::Format_ARGB32:
104 case QImage::Format_ARGB32_Premultiplied:{
105 return Policy::start(img, CV_8UC4);
123 QImage mat_2_qimage_cpy(Mat
const &mat,
bool swap);
124 Mat qimage_2_mat_cpy(QImage
const &img,
bool swap);
Definition: imagepro.h:117