编译CV_MAT_ELEM中的错误 [英] Compile error in CV_MAT_ELEM

查看:290
本文介绍了编译CV_MAT_ELEM中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于调用estimateRigidTransform(),我得到一个名为trans的cv :: Mat对象。要检索其包含的矩阵,我尝试以这种方式访问​​其元素:

  for(i = 0; i <2; i ++) for(j = 0; j <3; j ++)
{
mtx [j] [i] = CV_MAT_ELEM(trans,double,i,j)不幸的是在VS2010我收到一个编译错误







 错误C2228:'.ptr'的左侧必须有类/ struct / union 

用于具有CV_MAT_ELEM的行。当我解开这个宏我发现像

 (mat).data.ptr +(size_t)(mat).step *当我删除后面的.ptr时,会出现这样的情况:(a)(b)(b)(b)(b) (mat).data它编译。但我不能想象这是解决方案(或者不能想象这是一个错误,我是唯一一个注意到它)。 

解决方案

你不能像这样访问垫元素。对于遍历,请参阅我的其他答案与示例代码:
color matrix遍历



或查看opencv refman的灰度Mat:

  Mat M; // should be grayscale 
int cols = M.cols,rows = M.rows;
for(int i = 0; i< rows; i ++)
{
const double * Mi = M.ptr double(i);
for(int j = 0; j< cols; j ++)
{
Mi [j]; //是矩阵元素。
}
}


As a result of a call to estimateRigidTransform() I get a cv::Mat object named "trans". To retrieve its contained matrix I try to access its elements this way:

for (i=0; i<2; i++) for (j=0; j<3; j++)
{
   mtx[j][i]=CV_MAT_ELEM(trans,double,i,j);
}

Unfortunately with VS2010 I get a compiler error

error C2228: left of '.ptr' must have class/struct/union

for the line with CV_MAT_ELEM. When I unwrap this macro I find something like

(mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))

When I remove the ".ptr" behind (mat).data it compiles. But I can't imagine that's the solution (or can't imagine that's a bug and I'm the only one who noticed it). So what could be wrong here really?

Thanks!

解决方案

You don't access the mat elements like this. For a traversal see my other answer here with sample code: color matrix traversal

or see the opencv refman for grayscale Mat:

Mat M; // should be grayscale
int cols = M.cols, rows = M.rows;
for(int i = 0; i < rows; i++) 
{
  const double* Mi = M.ptr<double>(i); 
  for(int j = 0; j < cols; j++)
  {
    Mi[j]; // is the matrix element.
  }
}

这篇关于编译CV_MAT_ELEM中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆