OpenCV CvMat 到 Mat 和指针
我正在尝试将一些代码从使用 OpenCV 的 CvMat 转换为 Mat,但在指针方面遇到了一些问题。
这是原始代码:
CvMat *m_projectedTrainFaceMat;
float d_i;
i = 0;
d_i = projectTestFace[i] - m_projectedTrainFaceMat->data.fl[iTrain * m_nEigens + i];
这是我更新的代码:
Mat *m_projectedTrainFaceMat;
float d_i;
i = 0;
d_i = projectTestFace[i] - m_projectedTrainFaceMat->data[iTrain * m_nEigens + i];
如您所见,我从数据调用中删除了 .fl,但我不太清楚如何将数据作为浮点数返回。
有什么建议吗?我尝试将其转换为 float 和 (float *) 但它们最终导致了错误/错误。
e:projectTestFace 是一个 float*。
I'm trying to convert some code from using OpenCV's CvMat to Mat but am having some trouble with pointers.
This is the original code:
CvMat *m_projectedTrainFaceMat;
float d_i;
i = 0;
d_i = projectTestFace[i] - m_projectedTrainFaceMat->data.fl[iTrain * m_nEigens + i];
Here is my updated code:
Mat *m_projectedTrainFaceMat;
float d_i;
i = 0;
d_i = projectTestFace[i] - m_projectedTrainFaceMat->data[iTrain * m_nEigens + i];
As you can see, I removed the .fl from the call to data but I can't quite figure out how to return the data as floats.
Any suggestions? I tried casting it to float and (float *) but they ended up causing errors/mistakes.
e: projectTestFace is a float*.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的记忆是连续的,安德烈上面的代码是正确的。在某些情况下,情况并非如此,我们不应该假设。也许更直接的方法(无需使用指针)如下:
与 Andrey 类似,我假设您的 m_projectedTrainFaceMat 被初始化为具有 CV_32FC1 元素。
Andrey's code above is correct assuming that your memory is continuous. There are cases when that is not and we should not assume. Perhaps a more straightforward way (without having to use pointers) would be as follows:
Similar to Andrey I'm assuming that your m_projectedTrainFaceMat is intialized as having CV_32FC1 elements.