cv::Point2f recursive_bezier(const std::vector<cv::Point2f> &control_points, float t) { // TODO: Implement de Casteljau's algorithm if (control_points.size() == 1) return control_points[0]; std::vector<cv::Point2f> new_points; for (int i = 1; i < control_points.size(); i++) { //t比例下的贝塞尔点 auto point = (1.0f - t) * control_points[i - 1] + t * control_points[i]; new_points.emplace_back(point); } returnrecursive_bezier(new_points, t);
}
voidbezier(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.
for (double t = 0.0; t <= 1.0; t += 0.001) { auto point = recursive_bezier(control_points, t); window.at<cv::Vec3b>(point.y, point.x)[1] = 255; } }