Vector Point类的生成、使用及释放
Point的生成
vector常用于存储动态点对
已知:横坐标x , 纵坐标vectordem_arr
相关代码如下:
vector<Point2f> points;
double x[]; //给定的数组x
int len = y.size();
for (int s = 0; s < len; s++)
{
points.push_back(Point2f(x[s], y[s]));
}
Point的使用——直线拟合
// 拟合曲线斜率的计算,返回斜率值 k
float slope_cal(vector<Point> point)
{
Vec4f lines; //存放拟合后的直线
float param = 0; //距离模型中的数值参数C
float reps = 0.01; //坐标原点与直线之间的距离
float aeps = 0.01; //角度精度
fitLine(point, lines, CV_DIST_L2, parm, reps, aeps);
float k = lines[1] / lines[0]; //直线斜率
return k;
}
Point的释放
vector <Point2f>().swap(points);