vector trilinear_interpolation( vector v0, int n_x, int n_y, int n_z, vector_field field ) { int x1, y1, z1, x0, y0, z0; double xd, yd, zd; vector P1, P2, P3, P4, P5, P6, P7, P8, X1, X2, X3, X4, Y1, Y2, final; x1 = ceil( v0.x ); y1 = ceil( v0.y ); z1 = ceil( v0.z ); x0 = floor( v0.x ); y0 = floor( v0.y ); z0 = floor( v0.z ); xd = v0.x - x0; yd = v0.y - y0; zd = v0.z - z0; if ( x1 >= n_x || y1 >= n_y || z1 >= n_z || x0 < 0 || y0 < 0 || z0 < 0 ) { return nearest_neighbour( v0, n_x, n_y, n_z, field ); } else { set( &P1, field[DataSet::offset( n_x, n_y, x0, y0, z0 )] ); set( &P2, field[DataSet::offset( n_x, n_y, x1, y0, z0 )] ); set( &P3, field[DataSet::offset( n_x, n_y, x0, y0, z1 )] ); set( &P4, field[DataSet::offset( n_x, n_y, x1, y0, z1 )] ); set( &P5, field[DataSet::offset( n_x, n_y, x0, y1, z0 )] ); set( &P6, field[DataSet::offset( n_x, n_y, x1, y1, z0 )] ); set( &P7, field[DataSet::offset( n_x, n_y, x0, y1, z1 )] ); set( &P8, field[DataSet::offset( n_x, n_y, x1, y1, z1 )] ); set( &X1, sum( P1, mult_scalar( subtract( P2, P1 ), xd ) ) ); set( &X2, sum( P3, mult_scalar( subtract( P4, P3 ), xd ) ) ); set( &X3, sum( P5, mult_scalar( subtract( P6, P5 ), xd ) ) ); set( &X4, sum( P7, mult_scalar( subtract( P8, P7 ), xd ) ) ); set( &Y1, sum( X1, mult_scalar( subtract( X3, X1 ), yd ) ) ); set( &Y2, sum( X2, mult_scalar( subtract( X4, X2 ), yd ) ) ); set( &final, sum( Y1, mult_scalar( subtract( Y2, Y1 ), zd ) ) ); return final; } }
DetectionSet StackedModel::detect_occ2dpm(const ImRGBZ& im, DetectionFilter filter) const { DetectionFilter part_fitler = filter; part_fitler.nmax = numeric_limits<int>::max(); part_fitler.thresh = -inf; DetectionSet occ_dets = occ_model->detect(im,part_fitler); DetectionSet dpm_dets = dpm_model->detect(im,part_fitler); DetectionSet merged_dets; for(int iter = 0; iter < occ_dets.size(); ++iter) { DetectorResult occ_det = occ_dets[iter]; auto occFeatFn = occ_det->feature; DetectorResult dpm_det = nearest_neighbour(dpm_dets,occ_det->BB); decltype(occFeatFn) dpmFeatFn; if(rectIntersect(occ_det->BB,dpm_det->BB) > BaselineModel_ExternalKITTI::BB_OL_THRESH) { occ_det->resp = dpm_det->resp + learner->getB(); //occ_det->resp = ;//dpm_platt->prob(dpm_det->resp) * occ_platt->prob(occ_det->resp); dpmFeatFn = dpm_det->feature; } else { occ_det->resp = -inf; //dot(dpm_model->getW(),BaselineModel_ExternalKITTI::minFeat()) + learner->getB(); dpmFeatFn = []() { return vector<double> {BaselineModel_ExternalKITTI::minFeat()}; }; } occ_det->feature = [this,occFeatFn,dpmFeatFn]() { map<string,SparseVector> feats{ {"dpm_model",dpmFeatFn()}, {"occ_model",occFeatFn()}}; return feat_interpreation->pack(feats); }; merged_dets.push_back(occ_det); } log_once(printfpp("merged %d of %d dets",(int)merged_dets.size(),(int)occ_dets.size())); //filter.apply(merged_dets); return merged_dets; }
void main() { float ratio; clrscr(); get(); printf("\n\nthe path is:\n\n"); mincost(1); put(); printf("\nthe pathis (using approximation algo):\n"); nearest_neighbour(1); printf("1"); sum=sum+a[lastcity][1]; printf("minimum cost is%d\n",sum); ratio=(float)sum/cost; printf("the accuracy ratio is %f\n",ratio); getch(); }
int main() { int o_height, o_width; char input[20], output[20]; scanf("%s%s%d%d", input, output, &o_width, &o_height); IplImage *in_image, *out_image; in_image = cvLoadImage(input,-1); if(!in_image) { printf("Error!\n"); return 0; } out_image = cvCreateImage(cvSize(o_width,o_height),IPL_DEPTH_8U,in_image->nChannels); nearest_neighbour(in_image, out_image, o_width*1.0/in_image->width, o_height*1.0/in_image->height); Wavelet_Denoise(out_image); cvSaveImage(output,out_image); }
int nn_langs(User *user, User **set) { return nearest_neighbour(user, set, TRUE); }
int nn(User *user, User **set) { return nearest_neighbour(user, set, FALSE); }