fit point(8, -11) fit point(1, -10) fit point(-3, -9) fit point(-6, -8) fit point(-7,…
- User
fit point(8, -11) fit point(1, -10) fit point(-3, -9) fit point(-6, -8) fit point(-7, -7) fit point(-6, -6) fit point(-5, -5) fit point(-4, -4) fit point(-4, -3) fit point(-18, -8) fit point(-16, -7) fit point(-14, -6) fit point(-13, -5) fit point(-11, -4) fit point(-9, -3) fit point(-7, -2) fit point(-6, -1) fit point(-4, 0) fit point(-2, 1) fit point(0, 2) 如果有这些点,又该如何创建画布 float fa = vehicle_coeff(3, 0); float fb = vehicle_coeff(2, 0); float fc = vehicle_coeff(1, 0); float fd = vehicle_coeff(0, 0); float y0 = vehicle_r_start; float y1 = vehicle_r_end; int draw_size = 2; cv::Scalar color_ori = cv::Scalar(0, 0, 255); cv::Scalar color_fit = cv::Scalar(0, 255, 0); cv::Mat canvas(100, 100, CV_8UC3, cv::Scalar(255, 255, 255)); for (int j = static_cast(y0); j <= static_cast(y1); j++) { int x = fa * pow(j, 3) + fb * pow(j, 2) + fc * j + fd; cv::circle(canvas, cv::Point(x < 0 ? -x : x, j < 0 ? -j : j), draw_size, color_fit); std::cout << "fit point(" << x << ", " << j << ")" << " "; }
- Assistant
可以使用cv::Mat类创建画布,指定画布的宽度和高度,以及颜色模式(CV_8UC3表示8位无符号整数,3通道的彩色图像)和颜色(cv::Scalar类型表示颜色)。根据给定的点坐标和曲线拟合系数,可以使用循环在画布上绘制每个点。以下是一个示例代码:
cpp#include <opencv2/opencv.hpp> int main() { float fa = vehicle_coeff(3, 0); float fb = vehicle_coeff(2, 0); float fc = vehicle_coeff(1, 0); float fd = vehicle_coeff(0, 0); float y0 = vehicle_r_start; float y1 = vehicle_r_end; int draw_size = 2; cv::Scalar color_ori = cv::Scalar(0, 0, 255); cv::Scalar color_fit = cv::Scalar(0, 255, 0); cv::Mat canvas(100, 100, CV_8UC3, cv::Scalar(255, 255, 255)); for (int j = static_cast<int>(y0); j <= static_cast<int>(y1); j++) { int x = fa * pow(j, 3) + fb * pow(j, 2) + fc * j + fd; cv::circle(canvas, cv::Point(x < 0 ? -x : x, j < 0 ? -j : j), draw_size, color_fit); std::cout << "fit point(" << x << ", " << j << ")" << " "; } cv::imshow("Canvas", canvas); cv::waitKey(0); return 0; }