| 337 | (C, D) is the point that belongs to the line. */ |
| 338 | |
| 339 | static CvStatus icvFitLine2D( CvPoint2D32f * points, int count, int dist, |
| 340 | float _param, float reps, float aeps, float *line ) |
| 341 | { |
| 342 | double EPS = count*FLT_EPSILON; |
| 343 | void (*calc_weights) (float *, int, float *) = 0; |
| 344 | void (*calc_weights_param) (float *, int, float *, float) = 0; |
| 345 | float *w; /* weights */ |
| 346 | float *r; /* square distances */ |
| 347 | int i, j, k; |
| 348 | float _line[6], _lineprev[6]; |
| 349 | float rdelta = reps != 0 ? reps : 1.0f; |
| 350 | float adelta = aeps != 0 ? aeps : 0.01f; |
| 351 | double min_err = DBL_MAX, err = 0; |
| 352 | CvRNG rng = cvRNG(-1); |
| 353 | |
| 354 | memset( line, 0, 4*sizeof(line[0]) ); |
| 355 | |
| 356 | switch (dist) |
| 357 | { |
| 358 | case CV_DIST_L2: |
| 359 | return icvFitLine2D_wods( points, count, 0, line ); |
| 360 | |
| 361 | case CV_DIST_L1: |
| 362 | calc_weights = icvWeightL1; |
| 363 | break; |
| 364 | |
| 365 | case CV_DIST_L12: |
| 366 | calc_weights = icvWeightL12; |
| 367 | break; |
| 368 | |
| 369 | case CV_DIST_FAIR: |
| 370 | calc_weights_param = icvWeightFair; |
| 371 | break; |
| 372 | |
| 373 | case CV_DIST_WELSCH: |
| 374 | calc_weights_param = icvWeightWelsch; |
| 375 | break; |
| 376 | |
| 377 | case CV_DIST_HUBER: |
| 378 | calc_weights_param = icvWeightHuber; |
| 379 | break; |
| 380 | |
| 381 | /*case CV_DIST_USER: |
| 382 | calc_weights = (void ( * )(float *, int, float *)) _PFP.fp; |
| 383 | break;*/ |
| 384 | |
| 385 | default: |
| 386 | return CV_BADFACTOR_ERR; |
| 387 | } |
| 388 | |
| 389 | w = (float *) cvAlloc( count * sizeof( float )); |
| 390 | r = (float *) cvAlloc( count * sizeof( float )); |
| 391 | |
| 392 | for( k = 0; k < 20; k++ ) |
| 393 | { |
| 394 | int first = 1; |
| 395 | for( i = 0; i < count; i++ ) |
| 396 | w[i] = 0.f; |
no test coverage detected