【问题标题】:error: base operand of ‘->’ has non-pointer type ‘cv::Mat’错误:“->”的基本操作数具有非指针类型“cv::Mat”
【发布时间】:2016-08-20 15:19:01
【问题描述】:

我有一个 c-Api opencv 项目,我想改成 c++ (mat) 看到这个原始代码:

current_cost = 0;
basePtr = (unsigned char*)tmp1->imageData;
for( int j=0; j<tmp1->height; basePtr += tmp1->widthStep, j++ )
{
    iterator = basePtr;
    for( int i=0; i<tmp1->width; iterator++, i++ )
        if( *iterator == 255 )
            current_cost++;
}

basePtr = (unsigned char*)tmp2->imageData;
for( int j=0; j < tmp2->height; basePtr += tmp2->widthStep, j++ )
{
    iterator = basePtr;
    for( int i=0; i<tmp2->width; iterator++, i++ )
        if( *iterator == 0 )
            current_cost++;
}
if( current_cost < cost )                
    return true;
else return false;

运行这个项目后,看到这个错误

main.cpp:63:35: error: base operand of ‘->’ has non-pointer type ‘cv::Mat’
 basePtr = (unsigned char*)tmp1->imageData; 

查看使用的每一行的错误 '->' 。 请帮帮我...

【问题讨论】:

  • 错误告诉你 tmp1(等等)不是一个 POINTER,而是类型 cv::Mat。所以,在这种情况下,我会假设处理这个问题的正确形式是 tmp1.imageData (等等)。但这是一个猜测,因为您没有显示足够的代码。
  • 尝试使用tmp1.imageData

标签: c++ opencv c-api


【解决方案1】:

您不应该仅仅转换每一行代码,而是巧妙地使用 C++ api。您的函数可以简单地重写为:

bool foo(const Mat& tmp1, const Mat& tmp2, int cost) {
    int count = countNonZero(tmp1 == 255);
    count += countNonZero(tmp2 == 0);
    return count < cost;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    相关资源
    最近更新 更多