voidbezier(conststd::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 i=0;i<1.;i+=0.0001){ auto point=recursive_bezier(control_points,i); window.at<cv::Vec3b>(point.y,point.x)[1]=255; } }
int point_num=4;//global variale voidmouse_handler(int event, int x, int y, int flags, void *userdata) { if (event == cv::EVENT_LBUTTONDOWN && control_points.size() < point_num)//这里修改为了point_num { std::cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << '\n'; control_points.emplace_back(x, y); } }
intmain(int argc,constchar*argv[]) { if(argc==2&&std::string(argv[1])=="--help"){ std::cout<<"The first data is use antialiasing or not.\nInput '-a' to use it!\nInput '-' to defualt\n" <<"The second data is number of contol point, maybe you should input more than 4"<<std::endl; return0; } cv::Mat window = cv::Mat(700, 700, CV_8UC3, cv::Scalar(0)); cv::cvtColor(window, window, cv::COLOR_BGR2RGB); cv::namedWindow("Bezier Curve", cv::WINDOW_AUTOSIZE); cv::setMouseCallback("Bezier Curve", mouse_handler, nullptr); bool use_anti =false; int key = -1; if(argc>=2&&std::string(argv[1])=="-a")use_anti=true; if(argc>=3&&std::stoi(argv[2])>4)point_num=std::stoi(argv[2]); while (key != 27) { for (auto &point : control_points) { cv::circle(window, point, 3, {255, 255, 255}, 3); } std::cout<<"point_num"<<control_points.size()<<std::endl;