下面是一个OpenCV的小程序:
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
template<typename _Tp>
vector<_Tp> convertMat2Vector(const Mat &_t1f)
{
//_t1f.convertTo(t1f, CV_64F);
return (vector<_Tp>)(_t1f.reshape(1, 1));//通道数不变,按行转为一行
}
template<typename _Tp>
cv::Mat convertVector2Mat(vector<_Tp> v,int cn,int rows)
{
cv::Mat mat = cv::Mat(v);//将vector变成一列的mat
cv::Mat dest=mat.reshape(cn, rows);
cout << "dest=\n" << dest << endl;
return dest;
}
int main()
{
int arr[4][3] = { { 1, 1,1 },{ 2, 2,2 },{ 3, 3,3 },{ 4,4, 4 } };
cv::Mat srcData(4, 3, CV_8UC1, arr);
cout << "srcData=\n"<< srcData<< endl;
vector<uchar> v = convertMat2Vector<uchar>(srcData);
cv::Mat dest =convertVector2Mat<uchar>(v,1, 4);//函数里的dest和还回dest的结果为什么不一样的呀?
cout << "dest=\n" << dest << endl;
system("pause");
waitKey();
return 0;
}
运行结果:
问题是:各位大神啊,我这哪里出问题?为什么函数里的dest和还回的dest的结果值为什么不一样的呀?