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]; else { std::vector<cv::Point2f> points; for (auto i = 0; i < control_points.size() - 1; i += 1) { auto &p0 = control_points[i]; auto &p1 = control_points[i + 1]; points.emplace_back((1 - t) * p0 + t * p1); } returnrecursive_bezier(points, t); } }
1 2 3 4 5 6 7 8 9 10 11
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);