2014-06-30 133 views
3

的继this文章中,我想了解如何与lineiterator工作使用。我写了下面的代码:试图了解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将打印存储我跨线的值。有人能帮助我理解如何纠正这个问题吗?

+0

尝试'LineIterator it(img,cv :: Point(startX,startY),cv :: Point(endX,endY),8);'而不是。看看这个例子:http://docs.opencv.org/modules/core/doc/drawing_functions.html#lineiterator – Micka

+0

@Micka这给错误C2100:buf [i] = *(const Vec3b非法间接寻址)*它;这也给智能感知:无操作“*” – gpuguy

+0

看一下例子链接匹配这些操作数。解引用不会给你颜色值,而是像素位置。您必须手动从图像中读取它们的值! – Micka

回答

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; 
+1

感谢您的代码片段。它运作良好。 – gpuguy

+1

*(const Vec3b)* it; //这可能会在文档中被破解 – berak