0
A
回答
2
快速浏览一下the documentation for the Mat
class没有透露任何明显的“转换为float**
”操作,但你也许可以自己动手完成它:
Mat mat = (Mat_<float>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
// allocate and initialize a 2d float array
float **m = new float*[mat.Rows];
for (int r = 0; r < mat.Rows; ++r)
{
m[r] = new float[mat.Cols];
for (int c = 0; c < mat.Cols; ++c)
{
m[r][c] = mat.at(r, c);
}
}
// (use m for something)
// don't forget to clean up!
for (int r = 0; r < mat.Rows; ++r)
{
delete[] m[r];
}
delete[] m;
如果您在使用float**
时没有死机,您可以使用std::vector
或boost::multi_array
来避免内存分配/释放的尴尬,并减少泄漏的可能性。
使用Mat::ptr<float>(n)
获得float*
到n
矩阵的第n行也许会有一些运气,但是如果您不复制数据,我不确定您会保留多长时间该指针将保持有效。
1
如果你的意思是这样,
float a[M][N]; //M and N are compile-time constants!
float **p = a; //error
那么你不能做到这一点。
但是,你可以这样做:
float (*p)[N] = a; //ok
但是,如果不帮你,你想float**
不惜任何代价,然后用两个for
循环,做手工,从a
复制的每个元素到p
:
相关问题
- 1. 将uchar Mat转换为OpenCV中的Mat?
- 2. 将BufferedImage转换为OpenCv Mat
- 3. Java将Arraylist <Float>转换为float []
- 4. 将NSData转换为Java float?
- 5. 将float转换为char *
- 6. 将double转换为float?
- 7. 将float(YYYY)转换为datetime
- 8. 将double [] []转换为float [] []
- 9. mysql将float转换为double
- 10. 转换为float
- 11. 将.mat转换为.xls文件
- 12. 将PXCImage转换为OpenCV Mat(PIXEL_FORMAT_YUY2)
- 13. 将OpenCV Mat对象转换为BufferedImage
- 14. C++将cv :: Mat从CV_8U转换为CV_32F
- 15. 将Qimage转换为Mat时出错opencv
- 16. 将Android预览帧转换为OpenCV Mat
- 17. 如何将.caffemodel转换为.mat格式
- 18. 错误将cv :: mat转换为cv :: arr
- 19. 如何将Simd :: View转换为cv :: Mat?
- 20. 将.m文件转换为.mat
- 21. 要将cv :: Mat转换为CvArr *
- 22. 将数据从cv :: Mat转换为mxArray
- 23. 通过opencv将Mat转换为位图
- 24. 如何将QImage转换为opencv Mat
- 25. print Mat float
- 26. 从.mat转换为.obj
- 27. OpenCV Mat到JavaCV Mat转换
- 28. 为什么我在将'float **'转换为'const float **'时出错?
- 29. 为什么eclipse报告将float错误从float转换为double
- 30. 为什么float()无法将我的字符串转换为float?
谢谢!代码示例非常好! – 2011-10-17 13:24:45