openCV C++查找轮廓
openCV C++ find Contours
我想从我的图片中获得轮廓的坐标。我想把它保存为.txt文档。
首先我创建了:
vector<vector<cv:Pont> >extract<cv::Mat &binaryImage){
vector<vector<cv::Point> > coordinatesContours;
cv::findContours(binaryImage, coordinatesContours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
return coordinatesContours;
}
我调用Main中的函数:
oTest.extract(binaryImage);
现在我想将坐标作为输出导出到.txt 中
我的功能:
void Export(vector<vector<cv::Point> > coordinatesContours){
string json;
json = "{ntt "vertices" : [ntttt";
for(int i=0; i< coordinatesContours.size; i++)
for(int j=0; i< coordinatesContours.size; j++)
cout << i << "(" << coordinatesContours[i][j].x << ", " << coordinatesContours[i][j].y << ")" << endl;
但是我怎样才能完成我的任务呢??
在我的Main中如何称呼它??
请帮助thx
我不得不说,您可以直接在Extract函数中添加Export函数。您应该使用fstream
导出此处的点,例如:
#indlude fstream
// edit : typo corrected Pont -> Point
... vector<vector<cv::Point> >extract<cv::Mat &binaryImage){
vector<vector<cv::Point> > coordinatesContours;
cv::findContours(binaryImage, coordinatesContours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
fstream export_file;
export_file.open("Some_Name.txt",std::ios::out);
for(int i=0; i< coordinatesContours.size; i++)
for(int j=0; i< coordinatesContours[i].size; j++)
export_file << "Contour: " << i << ", Point: " << j << ",(" << coordinatesContours[i][j].x << ", " << coordinatesContours[i][j].y << ")" << endl;
export_file.close();
}
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 在C++中查找文件
- 模板元程序查找相似的连续类型名称
- 在UNIX系统中使用DIR查找文件的字节大小
- 查找最接近的大于当前数字的数字的索引
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 查找后更改类变量
- 使用正则表达式regex_search在字符串中查找字符串
- 使用gcc从静态链接的文件中查找可选符号
- 在C++中查找范围的长度
- 查找从轮廓到点OPENCV C 的距离
- 在 OpenCV 和 C++ 中查找距轮廓中心最近的黑色像素
- 重载函数查找轮廓的实例与参数列表不匹配
- OpenCV查找近距离物体的轮廓
- OpenCV查找轮廓的示例代码:向量释放问题
- 查找轮廓中的分割错误
- 在 OpenCV 中查找轮廓函数错误
- openCV C++查找轮廓
- 通过OpenCV中的轮廓矩查找椭圆的参数
- openCV 2.3.1 查找轮廓函数的链接错误