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

标签 c++ opencv

使用 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/

相关文章:

c++ - VTK:可视化深度缓冲区

c++ - 从 C++ 中的系统命令检索 ping 时间 (ping x.x.x.x -n)

opencv - 如何使用Catalano框架进行人脸特征提取?顺便说一句,我们使用Java

c++ - 如何处理 C++ 中的 "DNN module was not built with CUDA backend; switching to CPU"警告?

windows - OpenCV 2.4.5、eclipse CDT Juno、MinGW 错误 0xc0000005

opengl - 如何将 cudaArray (Cuda) 复制到 GpuMat (OpenCV)?

c++ - 传递本地创建的 lambda 用于回调,然后超出范围

c++ - 仅当从我的程序打开 CMD 时出现奇怪的 CMD 错误

c++ - 如何包含不是参数的 C++ 模板类型

python - 无法获得具有亮点的图像的准确阈值