SquarePoints *transform_square(SquarePoints *square, r3transform *trans) { SquarePoints *result = new_squarepoints(); *result = (SquarePoints) { { apply_transformation(square->points[0], trans), apply_transformation(square->points[1], trans), apply_transformation(square->points[2], trans), apply_transformation(square->points[3], trans) } }; return result; }
static int evaluate_index_and_insert_into_db(void *context, const char *expression, transformation *tr) { struct evaluate_index_context *ctx; string_list *values = NULL; string_list_item *item = NULL; int status = U1DB_OK; ctx = (struct evaluate_index_context *)context; if (ctx->obj == NULL || !json_object_is_type(ctx->obj, json_type_object)) { return U1DB_INVALID_JSON; } if (status != U1DB_OK) goto finish; if (status != U1DB_OK) goto finish; if ((status = init_list(&values)) != U1DB_OK) goto finish; status = apply_transformation(tr, ctx->obj, values); for (item = values->head; item != NULL; item = item->next) { if ((status = add_to_document_fields(ctx->db, ctx->doc_id, expression, item->data)) != U1DB_OK) goto finish; } finish: destroy_list(values); return status; }
static int apply_transformation(transformation *tr, json_object *obj, string_list *result) { int status = U1DB_OK; string_list *tmp_values = NULL; if (tr->next != NULL) { init_list(&tmp_values); status = apply_transformation(tr->next, obj, tmp_values); if (status != U1DB_OK) goto finish; if (tr->args->head != NULL) { status = ((op_function)tr->op)(result, tmp_values, tr->args); } else { status = ((op_function)tr->op)(result, tmp_values, NULL); } } else { status = extract_field_values(result, obj, tr->args, tr->value_type); } finish: destroy_list(tmp_values); return status; }
bool PhotoGeocoder::geocoding_pipeline(string photoPath, GPSCoords &lla){ //--- Extract Exif data //--------------------- cv::Mat K; extract_k_matrix(photoPath, ccdData, K); //--- Extract Features & Descriptors //---------------------------------- vector<Feature> features; vector<Descriptor> descriptors; ftk->extract_features(photoPath,features,descriptors); //--- VTree Match //--------------- logger << INDENT << "Quering vocabulary tree for similar documents..." << "\n"; QueryResults listDocuments = vtree.query(descriptors, MAX_DOCUMENTS); for(int i = 0; i < MAX_DOCUMENTS && i < (int) listDocuments.size(); i++){ logger << INDENT << "Loading document " << i << "\n"; vector<Descriptor> documentDescs; vector<Point3D> points3D; string pathDoc; dbm.query_synth_path(listDocuments[i].Id, pathDoc); //--- Load documents //------------------ if(!load_synthetic(pathDoc, points3D, documentDescs)) return EXIT_FAILURE; //--- Match photo<->documents //--------------------------- logger << INDENT << "Matching with document... " << "\n"; vector<pair<int,int> > matches; int nMatches = ftk->match_features(descriptors, documentDescs, matches); logger << INDENT << nMatches << " sift matches were found" << "\n"; //--- If not enough matches if(nMatches < M_LIMIT){ logger << INDENT << "not enough matches...skipping." << "\n"; continue; } vector<cv::Point2f> matchedPoints2D = vector<cv::Point2f>(nMatches); vector<cv::Point3f> matchedPoints3D = vector<cv::Point3f>(nMatches); for(int j = 0; j < nMatches; j++){ matchedPoints2D[j] = features[matches[j].first].pt; matchedPoints3D[j] = points3D[matches[j].second]; } //--- Compute Projection //---------------------- cv::Matx34f P; if(!find_proj_matrix(matchedPoints2D, matchedPoints3D,K,P)){ logger << INDENT << "Fail to compute P...skipping." << "\n"; continue; } cv::Matx44f G; float error; load_transformation_mat(strip_path(pathDoc) + "/../" + "transformMat.txt", error, G); //--- Apply GPS transformation //---------------------------- lla = apply_transformation(P, G); //--- Compute Error //----------------- //TODO: this //distance_gps(lla1,lla2); logger << INDENT << photoPath << " --> geocoded at:" << "\n"; logger << INDENT << INDENT << "Latitude: " << lla.lat << "\n"; logger << INDENT << INDENT << "Longitude: " << lla.lon << "\n"; return true; } logger << INDENT << photoPath << " --> not geocoded" << "\n"; return false; }
void apply_trans(double *m, t_coord *move) { apply_transformation(m, move); }
int main(int argc, char **argv) { // process input arguments if (argc != 6) { fprintf(stderr, "usage: \n \t imageIn n hom imageOut parameter \n"); return 0; } char *filename_ImgIn = argv[1]; int n = atoi(argv[2]); char *hom = argv[3]; char *filename_ImgOut = argv[4]; float delta = atof(argv[5]); char filename_hom[n*n][256]; int nn = n*n; int w, h; float *im = iio_read_image_float(filename_ImgIn, &w, &h); float H[nn*9]; float *coordx = malloc(n*n*sizeof(float)); float *coordy = malloc(n*n*sizeof(float)); coordinates_centers(w, h, n, coordx, coordy); for(int i = 0 ; i < nn ; i++) { sprintf(filename_hom[i], "%s_%d.txt", hom, i+1); FILE* f = NULL; f = fopen(filename_hom[i], "r"); if (f != NULL) { fscanf(f, "%f %f %f %f %f %f %f %f %f", &H[9*i+0], &H[9*i+1], &H[9*i+2], &H[9*i+3], &H[9*i+4], &H[9*i+5], &H[9*i+6], &H[9*i+7], &H[9*i+8]); fclose(f); } else { printf("Impossible to open file"); } } float *out = malloc(w*h*sizeof(float)); float *Tx = malloc(w*h*sizeof(float)); float *Ty = malloc(w*h*sizeof(float)); delta = delta*(w+h)/(n+2); compute_transformation(n, coordx, coordy, H, Tx, Ty, w, h, delta); apply_transformation(im, Tx, Ty, w, h, out); iio_save_image_float(filename_ImgOut, out, w, h); free(out); free(Tx); free(Ty); free(coordx); free(coordy); return 0; }