C++ 常有代码段摘奇

一、Opencv

1.1 类型转换

(1)将vector<Point2f>转换成vector<Point>

vector<Point2f> vd{ { 1.1, 2.2 }, { 3.3, 4.4 }, {5.5, 6.6} };
vector<Point> v(vd.begin(), vd.end());

2.1 文档数据读取

(1)从txt中读取坐标数据(每一行为 x, y 格式,如下图所示),并赋值给vector<Point>

ifstream infile;
infile.open("distortPoints/"+names[i]+"_points.txt");
if (!infile.is_open()) {
    std::cout << "read txt file is failed!" << std::endl;
    return false;
}
vector<Point2f> Points;
float x, y;
char delim;

while (infile >> x >> delim>> y) {
    Points.emplace_back(Point2f(x, y));
}

猜你喜欢

转载自blog.csdn.net/qq_23981335/article/details/124712149