使用 MSVS2010 在 Windows 上编译
我需要编写一个函数来接受 Mat 图像并返回 std::vector< Point > points;。但是我无法理解函数定义中的返回类型是什么。
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
返回点
上的两个错误
谁能告诉我如何正确返回积分?
最佳答案
您的函数签名表明该函数返回单个点(在本例中为 cv::Point),而您似乎正试图返回它们的完整列表。要返回集合,您的函数定义应如下所示:
std::vector<Point> collectPoints(Mat image)
{
std::vector<Point> points;
...
return points;
}
关于c++ - OpenCV:从函数返回 Point 类型到 main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24609885/