bool vpHomography::degenerateConfiguration(const std::vector<double> &xb, const std::vector<double> &yb, const std::vector<double> &xa, const std::vector<double> &ya) { unsigned int n = (unsigned int)xb.size(); if (n < 4) throw(vpException(vpException::fatalError, "There must be at least 4 matched points")); std::vector<vpColVector> pa(n), pb(n); for (unsigned i=0; i<n;i++) { pa[i].resize(3); pa[i][0] = xa[i]; pa[i][1] = ya[i]; pa[i][2] = 1; pb[i].resize(3); pb[i][0] = xb[i]; pb[i][1] = yb[i]; pb[i][2] = 1; } for (unsigned int i = 0; i < n-2; i++) { for (unsigned int j = i+1; j < n-1; j++) { for (unsigned int k = j+1; k < n ; k++) { if (isColinear(pa[i], pa[j], pa[k])) { return true; } if (isColinear(pb[i], pb[j], pb[k])){ return true; } } } } return false; }
static void stripColinear(gdPointPtr tpts, int *num_pts){ int total = 0; int i; gdPointPtr npts, first, second; if (*num_pts <= 2){ return; } npts = (gdPointPtr)umalloc(sizeof(gdPoint) * *num_pts); assert(npts); first = tpts; second = tpts+1; for (i=2; i < *num_pts; ++i){ gdPointPtr third = &tpts[i]; if (isColinear(first, second, third)){ second = third; } else { npts[total].x = first->x; npts[total].y = first->y; ++total; first = second; second = third; } } npts[total].x = first->x; npts[total].y = first->y; ++total; npts[total].x = second->x; npts[total].y = second->y; ++total; memcpy(tpts, npts, sizeof(gdPoint)*total); free(npts); *num_pts = total; #ifdef DEBUG printf("--------------------------------------\n"); for (i=0; i < total; ++i){ printf("strip: (%d, %d)\n", tpts[i].x, tpts[i].y); } #endif }