【问题标题】:Compile error with the Contours example of OpenCV 2 cookbookOpenCV 2 食谱的 Contours 示例编译错误
【发布时间】:2012-07-03 13:08:25
【问题描述】:

我尝试了本书中的示例代码来绘制原始图片中的轮廓。但是,以下代码在带有 Mingw 4.4 的 Qt 下无法成功编译。

 // Eliminate too short or too long contours
   int cmin= 100;  // minimum contour length
   int cmax= 1000; // maximum contour length
   std::vector<std::vector<cv::Point> >::
              const_iterator itc= contours.begin();
   while (itc!=contours.end()) {
      if (itc->size() < cmin || itc->size() > cmax)
         itc= contours.erase(itc);
      else 
         ++itc;
   }

警告:有符号和无符号整数表达式之间的比较 警告:有符号和无符号整数表达式之间的比较 错误:没有匹配函数调用 'std::vector, std::allocator > >, std::allocator, std::allocator > > >::erase(__gnu_cxx::__normal_iterator, std::allocator > >* , std::vector, std::allocator > >, std::allocator, std::allocator > > > > >&)'

它说itc 没有方法size()。然而,这本书真的是这样写的。我错过了什么吗?

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    这是因为std::vector::erase 返回一个iterator,而您正在分配一个const_iterator。这样编译:

    ...
    std::vector<std::vector<cv::Point> >::iterator itc= contours.begin();
                                           // ^
    while (itc!=contours.end()) {
       if (itc->size() < cmin || itc->size() > cmax)
           itc= contours.erase(itc);
       else 
           ++itc;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 2021-03-22
      • 2017-03-19
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多