错误:' -> '的基本操作数具有非指针类型' cv::Mat '
error: base operand of ‘->’ has non-pointer type ‘cv::Mat’
我有一个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;
看到使用'->'的每一行的错误。请帮帮我……
您不应该仅仅转换每一行代码,而应该巧妙地使用c++ api。您的函数可以简单地重写为:
bool foo(const Mat& tmp1, const Mat& tmp2, int cost) {
int count = countNonZero(tmp1 == 255);
count += countNonZero(tmp2 == 0);
return count < cost;
}
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 为什么使用 "this" 指针调用派生成员函数?
- Difference in displaying cv2 Mat
- 函数向量_指针有不同的原型,我可以构建一个吗
- OpenCV如何处理Mat作为指针来加速代码
- 'cv::Mat::type':非标准语法;使用 '&' 创建指向成员的指针
- 为什么用cv::Mat(opencv)更改指向数据的指针与cv::filter2D有问题
- 如何强制CV :: MAT表现为明智的指针
- 从指针创建Mat
- Mat初始化的双指针
- 通过模糊 mat 从 std::vector: <int>cv::Exception 中获取错误指针
- c++中有Opencv 2.3 Mat指针吗?
- 当重新分配或作为ROI时,是否会自动释放Mat指针,源Mat被释放
- 如何将Mat数据类型转换为无符号短指针
- OpenCV -如何从uint8_t指针创建Mat
- OpenCV CvMat到Mat和指针
- 错误:' -> '的基本操作数具有非指针类型' cv::Mat '
- 如何将cv::Mat转换为浮点指针
- 表达式列表在创建指向 Mat 向量的指针时被视为初始值设定项中的复合表达式