开发者

OpenCV CvMat to Mat and pointers

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_project开发者_如何学JAVAedTrainFaceMat->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*.


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:

d_i = projectTestFace[i] - (*m_projectedTrainFaceMat).at<float>(row, col);

Similar to Andrey I'm assuming that your m_projectedTrainFaceMat is intialized as having CV_32FC1 elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜