看起来似乎很简单。毕竟,我们知道一个std或openCV向量可以很容易地转换成矩阵,就像这样:
vector<Point> iptvec(10);
Mat iP(iptvec);
在openCV cheatSheet中建议采用相反的方法:
vector<Point2f> ptvec = Mat_ <Point2f>(iP);
然而,有一个要注意的地方:矩阵必须只有一行或一列。如果想转换任意矩阵,则需要进行重塑操作:
int sz = iP.cols*iP.rows;
vector<Point2f> ptvec = Mat <Point2f>(iP.reshape(1, sz));
否则,您将会得到一个错误:
*OpenCV错误:断言失败(dims == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0))在create,文件/home/.../OpenCV-2.4.2/modules/core/src/matrix.cpp,第1385行...