#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
template<typename _Tp>
vector<_Tp> convertMat2Vector(const Mat &mat)
{
return (vector<_Tp>)(mat.reshape(1, 1));
}
template<typename _Tp>
cv::Mat convertVector2Mat(vector<_Tp> v, int channels, int rows)
{
cv::Mat mat = cv::Mat(v);//将vector变成单列的mat
cv::Mat dest = mat.reshape(channels, rows).clone();
return dest;
}
int main(void)
{
vector<double> temp;
Mat src1(3,3,CV_64FC1,Scalar::all(1));
temp=convertMat2Vector<double>(src1);
temp.clear();
for(size_t i=0;i<12;i++)
{
temp.push_back(2*i);
}
Mat src2=convertVector2Mat(temp, 1 ,3);
double value=src2.at<double>(1,1);
cout<<value<<endl;
}