OpenCV:从函数返回到main的点类型

OpenCV: Returning Point type from a function to main

本文关键字:main 类型 返回 函数 OpenCV      更新时间:2023-10-16

使用MSVS2010在Windows上编译

我需要写一个函数,将接受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

的误差

谁能告诉我如何正确返回点?

你的函数签名说函数返回一个点(在这种情况下,cv::Point),当它看起来像你试图返回它们的完整列表。要返回集合,函数定义应该如下所示:

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