【问题标题】:OpenCV: Returning Point type from a function to mainOpenCV:从函数返回点类型到主
【发布时间】:2014-07-07 19:55:34
【问题描述】:

使用 MSVS2010 在 Windows 上编译

我需要编写一个函数来接受一个 Mat 图像并返回 std::vector 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

return points 上的两个错误

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

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    您的函数签名表明该函数返回单个点(在本例中为 cv::Point),而您似乎正试图返回它们的完整列表。要返回集合,您的函数定义应如下所示:

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

    【讨论】:

    • 谢谢。顺便说一句,如果我必须将点作为参数传递,我可以这样做: foo(Mat image, std::vector points)
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多