【发布时间】:2013-01-12 07:10:19
【问题描述】:
我正在编写一个函数,其中包含一些行来将二维 STL 向量转换为 OpenCV Mat。因为,OpenCV 支持使用 Mat(vector) 从向量初始化 Mat。但这一次,我尝试了一个 2D 矢量,但没有成功。
函数很简单:
template <class NumType>
Mat Vect2Mat(vector<vector<NumType>> vect)
{
Mat mtx = Mat(vect.size(), vect[0].size(), CV_64F, 0); // don't need to init??
//Mat mtx;
// copy data
for (int i=0; i<vect.size(); i++)
for (int j=0; j<vect[i].size(); j++)
{
mtx.at<NumType>(i,j) = vect[i][j];
//cout << vect[i][j] << " ";
}
return mtx;
}
那么有没有办法用 NumType 相应地初始化 Mat mtx?语法总是固定为 CV_32F, CV_64F, .... 因此,非常受限
谢谢!
【问题讨论】: