| 28 | using namespace cv; |
| 29 | |
| 30 | vector<Point2f> Spline::splineInterpTimes(const vector<Point2f>& tmp_line, int times) { |
| 31 | vector<Point2f> res; |
| 32 | if(tmp_line.size() == 2) { |
| 33 | double x1 = tmp_line[0].x; |
| 34 | double y1 = tmp_line[0].y; |
| 35 | double x2 = tmp_line[1].x; |
| 36 | double y2 = tmp_line[1].y; |
| 37 | |
| 38 | for (int k = 0; k <= times; k++) { |
| 39 | double xi = x1 + double((x2 - x1) * k) / times; |
| 40 | double yi = y1 + double((y2 - y1) * k) / times; |
| 41 | res.push_back(Point2f(xi, yi)); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | else if(tmp_line.size() > 2) |
| 46 | { |
| 47 | vector<Func> tmp_func; |
| 48 | tmp_func = this->cal_fun(tmp_line); |
| 49 | if (tmp_func.empty()) { |
| 50 | cout << "in splineInterpTimes: cal_fun failed" << endl; |
| 51 | return res; |
| 52 | } |
| 53 | for(int j = 0; j < tmp_func.size(); j++) |
| 54 | { |
| 55 | double delta = tmp_func[j].h / times; |
| 56 | for(int k = 0; k < times; k++) |
| 57 | { |
| 58 | double t1 = delta*k; |
| 59 | double x1 = tmp_func[j].a_x + tmp_func[j].b_x*t1 + tmp_func[j].c_x*pow(t1,2) + tmp_func[j].d_x*pow(t1,3); |
| 60 | double y1 = tmp_func[j].a_y + tmp_func[j].b_y*t1 + tmp_func[j].c_y*pow(t1,2) + tmp_func[j].d_y*pow(t1,3); |
| 61 | res.push_back(Point2f(x1, y1)); |
| 62 | } |
| 63 | } |
| 64 | res.push_back(tmp_line[tmp_line.size() - 1]); |
| 65 | } |
| 66 | else { |
| 67 | cerr << "in splineInterpTimes: not enough points" << endl; |
| 68 | } |
| 69 | return res; |
| 70 | } |
| 71 | vector<Point2f> Spline::splineInterpStep(vector<Point2f> tmp_line, double step) { |
| 72 | vector<Point2f> res; |
| 73 | /* |
no test coverage detected