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. 将const float float转换成Mat
- 2. 将T * array(Jet *或float *)转换为cv :: Mat <CV_32f>
- 3. 将uchar Mat转换为OpenCV中的Mat?
- 4. 将.mat转换为.wav
- 5. 将HBITMAP转换为cv :: Mat
- 6. 将BufferedImage转换为OpenCv Mat
- 7. 将cv :: Mat转换为SDL_Texture
- 8. Sybase将float从float转换为varchar
- 9. Java将Arraylist <Float>转换为float []
- 10. 将NSData转换为Java float?
- 11. mysql将float转换为double
- 12. 将int转换为float?
- 13. 将float []转换为android.graphics.Matrix
- 14. 将float转换为int
- 15. Haskell将Float转换为Int
- 16. 将FLOAT转换为INT
- 17. 将double转换为float?
- 18. 将Float转换为Int
- 19. JSON将float转换为int
- 20. 将int转换为float/double
- 21. 将float(YYYY)转换为datetime
- 22. 将double [] []转换为float [] []
- 23. 将float转换为char *
- 24. 将OpenCV的cv :: Mat转换为Eigen
- 25. 转换为float
- 26. 如何将IplImage转换为Mat?
- 27. 如何将opencv cv :: Mat转换为qimage
- 28. 将BufferedImage转换为OpenCV中的Mat
- 29. 将PXCImage转换为OpenCV Mat(PIXEL_FORMAT_YUY2)
- 30. 将mat转换为iplimage *在opencv中
谢谢!代码示例非常好! – 2011-10-17 13:24:45