作业要求
具体实现
- recursive_bezier()函数
cv::Point2f recursive_bezier(const std::vector<cv::Point2f> &control_points, float t)
{
// TODO: Implement de Casteljau's algorithm
std::vector<cv::Point2f> tmp,points = control_points;
cv::Point2f T;
while(points.size() != 1)
{
for(int i=0;i<points.size()-1;i++)
{
T.x = points[i].x + (points[i+1].x - points[i].x) * t;
T.y = points[i].y + (points[i+1].y - points[i].y) * t;
tmp.push_back(T);
}
points = tmp;
tmp.clear();
}
return points[0];
}
- bezier()函数
void bezier(const std::vector<cv::Point2f> &control_points, cv::Mat &window)
{
// TODO: Iterate through all t = 0 to t = 1 with small steps, and call de Casteljau's
// recursive Bezier algorithm.
cv::Point2f point;
for (double t = 0.0; t <= 1.0; t += 0.001)
{
point = recursive_bezier(control_points,t);
//设置成绿色
window.at<cv::Vec3b>(point.y, point.x)[1] = 255;
}
}
运行结果
- 注释掉main函数中的naive_bezier()函数的调用
- 去掉注释后