OpenCV:从函数返回到main的点类型
OpenCV: Returning Point type from a function to main
使用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;
}
相关文章:
- 为什么 c++ 中的 main() 函数不采用除 int 和 void 之外的任何其他返回类型
- \main.cpp|103|error: 与"operator<<"不匹配(操作数类型为"std::ostream {aka std::basic_ostream<char&g
- 未声明的标识符和类型"int"从 main 调用类时出现意外错误
- Bon appetit :从 int 返回类型函数在 main() 中打印字符串
- 在main()中为通用模板类选择数据类型
- 从C (例如Main.CPP)访问注册类型实例
- 在代码块错误中收到此错误:数组下标'main()::fields[int]'的类型无效
- 错误:main的声明中有两个或多个数据类型
- main() 的函数类型
- 将变量(数组类型)从函数传递到"main"范围类型:标准::tr1::match_results<标准::字符串::const_iterator>
- 在 main 中初始化类的 "static const" 类型变量成员的更好方法
- c/c++中main()的默认返回类型
- 在Clang上没有返回类型的main()
- 使用main.cpp、node.cpp/.h和slist.cpp/.h[var SLNode未命名类型:error]构建
- 在int main中的argv[]是否应该总是char*类型(如果使用argv则为char**类型)?
- OpenCV:从函数返回到main的点类型
- 你能在main函数中省略返回类型吗?
- 错误:函数"int main()"中请求从 'double' 型转换为非标量类型'Player';
- 如何将变量(从类类型的对象)传递给函数(在main.cpp中)仅作为对象
- 为什么main()参数argv的类型是char*[]而不是const char*[] ?