SP_CONFIG_MSG writeImageFeaturesToFile(SPPoint* imFeatures, int numOfFeats, SPConfig config, int imageIndex) { FILE* featsFile; SP_CONFIG_MSG msg = getFeatsFile(config, imageIndex, &featsFile, "w+"); int i, j; if (msg != SP_CONFIG_SUCCESS) { return msg; } fprintf(featsFile, "%d\n", numOfFeats); for (i = 0; i < numOfFeats; i++) { SPPoint point = imFeatures[i]; fprintf(featsFile, "%d,%d\n", spPointGetIndex(point), spPointGetDimension(point)); for (j = 0; j < spPointGetDimension(point); j++) { fprintf(featsFile, "%f\n", spPointGetAxisCoor(point, j)); } } fflush(featsFile); fclose(featsFile); return SP_CONFIG_SUCCESS; }
int* getRealRsltsArray(int k,SPPoint* pointsArray,SPPoint queryPoint,int size){ int i; distanceWithPoint* distancesArray; int *outputArray = (int*)calloc(k, sizeof(int)); if (outputArray == NULL) { spLoggerSafePrintError(ERROR_ALLOCATING_MEMORY,__FILE__,__FUNCTION__,__LINE__); return NULL; } distancesArray = createAndSortDistancesArray(size,queryPoint, pointsArray); if (distancesArray == NULL) { free(outputArray); return NULL; } for (i = 0; i < k; i++) outputArray[i] = spPointGetIndex((distancesArray[i]).point); free(distancesArray); return outputArray; }
/**** * The purpose of the test is to compare the features before and after the saving. */ bool main_saveLoad() { LoadedFeatures loadedFeatures = NULL; LoadedFeatures features = NULL; int numOfImages = 0; int numOfFeatures = 0; int numOfCoords = 0; SPPoint * orgArr = NULL; SPPoint pointOrg = NULL; SPPoint * loadedArr = NULL; SPPoint pointLoad = NULL; SP_CONFIG_MSG msg; char fileName[30] = "./tests/config/saveLoad.cfg"; SPConfig conf = spConfigCreate(fileName, &msg); ASSERT_TRUE(NULL != conf); /**** * Allocates, creates(by imageProc) and saves the features ****/ features = allocateFeaturesList(conf); ASSERT_TRUE(NULL != features); ASSERT_TRUE(true == debugSaveFeatures(conf, features)); /**** * Load the features from the files *****/ loadedFeatures = allocateFeaturesList(conf); ASSERT_TRUE(NULL != loadedFeatures); ASSERT_TRUE(true == loadFeatures(conf, loadedFeatures)); /**************************************** * Compare original and loaded features * ****************************************/ ASSERT_TRUE(getFeaturesImagesNumber(features) == getFeaturesImagesNumber(loadedFeatures)); numOfImages = getFeaturesImagesNumber(features); for (int index_image=0; index_image<numOfImages ; index_image++) { numOfFeatures = getFeaturesNumber(features, index_image); ASSERT_TRUE(numOfFeatures == getFeaturesNumber(loadedFeatures, index_image)); for (int index_feature=0; index_feature<numOfFeatures ; index_feature++) { orgArr = getFeatureArray(features, index_image); loadedArr = getFeatureArray(loadedFeatures, index_image); pointOrg = orgArr[index_feature]; pointLoad = loadedArr[index_feature]; numOfCoords = spPointGetDimension(pointOrg); ASSERT_TRUE(numOfCoords == spPointGetDimension(pointLoad)); ASSERT_TRUE(spPointGetIndex(pointOrg) == spPointGetIndex(pointLoad)); for (int index_coor=0; index_coor<numOfCoords ; index_coor++) { ASSERT_TRUE(spPointGetAxisCoor(pointOrg, index_coor) == spPointGetAxisCoor(pointLoad, index_coor)); } } } loadedFeaturesDestroy(loadedFeatures); loadedFeaturesDestroy(features); return true; }