OpenCV:从函数返回Point类型到main

时间:2014-07-07 11:48:48

标签: c++ opencv

在Windows上使用MSVS2010进行编译

我需要编写一个接受Mat图像并返回std :: vector<的函数。点>点;.但我无法理解函数定义中的返回类型。

Point collectpoints(Mat image)  //return type???

{

std::vector<Point> points;

//calculated  points here, and now want to return the points to main()// 


return points  //this has error 

}


int main

{
   int X1=0, Y1=0, X2=0, Y2=0;
 Mat img = imread("chhha.png", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);

std::vector<Point> points1;

points1 = colectpoints(img); //type casting required?  

//now check the collected points

X1=points[0].x; 
X2=points[1].x; 


Y1=points[0].y; 
Y2=points[1].y; 
cout<<"First and second X  coordinates are given below"<<endl;
cout<<X1<<'\t'<<X2<<endl; 

cout<<"First and second Y coordinates are given below"<<endl;
cout<<Y1<<'\t'<<Y2<<endl; 

return 0;
} 

上述情况不起作用,我不确定应该如何归还积分值。

基本上错误是:

 error C2664: 'cv::Point_<_Tp>::Point_(const cv::Point_<_Tp> &)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const cv::Point_<_Tp> &'   plotfunction.cpp   272


 IntelliSense: no suitable user-defined conversion from "std::vector<cv::Point, std::allocator<cv::Point>>" to "cv::Point" exists    plotfunction.cpp   272

return points

上的错误

有人可以告诉我如何正确返回积分吗?

1 个答案:

答案 0 :(得分:2)

你的函数签名是说该函数返回一个Point(在本例中为cv :: Point),当你看起来正在尝试返回它们的完整列表时。要返回集合,您的函数定义应如下所示:

std::vector<Point> collectPoints(Mat image)
{
    std::vector<Point> points;
    ...
    return points;
}
相关问题