试图了解Lineiterator的用法

时间:2014-06-30 10:42:16

标签: c++ opencv

关注this文章,我试图了解如何使用lineiterator。我写了以下代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main( )
{

     Mat img = imread("C:\\Users\\Acme\\Desktop\\image-processing\\2.bmp");


LineIterator it(img, 1, 200, 8);
LineIterator it2 = it;

vector<Vec3b> buf(it.count);

for(int i = 0; i < it.count; i++, ++it)
{
    buf[i] = *(const Vec3b)*it;
printf("%d\n", buf[i]);

}

      return 0;

}

但它会出错:

Error   1   error C2664: 'cv::LineIterator::LineIterator(const cv::Mat &,cv::Point,cv::Point,int,bool)' : cannot convert parameter 2 from 'int' to 'cv::Point'  c:\users\acme\documents\visual studio 2010\projects\iterator\opencv1\helloworld.cpp 15


Error   2   error C2100: illegal indirection    c:\users\acme\documents\visual studio 2010\projects\iterator\opencv1\helloworld.cpp 22


3   IntelliSense: no instance of constructor "cv::LineIterator::LineIterator" matches the argument list c:\users\acme\documents\visual studio 2010\projects\iterator\opencv1\helloworld.cpp 15



4   IntelliSense: no operator "*" matches these operands    c:\users\acme\documents\visual studio 2010\projects\iterator\opencv1\helloworld.cpp 22

我期待buf会打印出存储在整个行中的值。有人可以帮我理解如何纠正这个问题吗?

1 个答案:

答案 0 :(得分:2)

LineIterator it(img, Point(1,1), Point(20,20), 8);

vector<Vec3b> buf;   

for(int i=0; i<it.count; i++)
{
    buf.push_back( Vec3b(*it) );
    it++;
}

cerr << Mat(buf) << endl;