Exemplo n.º 1
0
bool initializeWorkingImageKDTreeAndBPQueue(const SPConfig config,
		SPImageData* imagesDataList, SPImageData* currentImageData, SPKDTreeNode* kdTree,
		SPBPQueue* bpq, int numOfImages) {
	SP_CONFIG_MSG configMessage = SP_CONFIG_SUCCESS;
	int totalNumOfFeatures, knn;
	SPPoint* allFeaturesArray;
	SP_KDTREE_SPLIT_METHOD splitMethod;

	spVal(spImagesParserStartParsingProcess(config, imagesDataList) == SP_DP_SUCCESS,
			ERROR_PARSING_IMAGES_DATA, false);

	spLoggerSafePrintDebug(DEBUG_IMAGES_PARSER_FINISHED, __FILE__, __FUNCTION__, __LINE__);

	spVal((*currentImageData = initializeWorkingImage()), ERROR_INITIALIZING_QUERY_IMAGE,
			false);

	spLoggerSafePrintDebug(DEBUG_WORKING_IMAGE_INITIALIZED, __FILE__, __FUNCTION__,
			__LINE__);

	totalNumOfFeatures = calculateTotalNumOfFeatures(imagesDataList, numOfImages);

	spLoggerSafePrintDebug(DEBUG_NUMBER_OF_FEATURES_CALCULATED, __FILE__, __FUNCTION__,
			__LINE__);

	spVal((allFeaturesArray = initializeAllFeaturesArray(imagesDataList, numOfImages,
			totalNumOfFeatures)), ERROR_CREATING_FEATURES_ARRAY, false);

	spLoggerSafePrintDebug(DEBUG_FEATURES_ARRAY_INITIALIZED, __FILE__, __FUNCTION__,
			__LINE__);

	splitMethod = spConfigGetSplitMethod(config, &configMessage);
	spValWc(configMessage == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS,
			free(allFeaturesArray), false);

	spValWc((*kdTree = InitKDTreeFromPoints(allFeaturesArray, totalNumOfFeatures,
			splitMethod)), ERROR_CREATING_KD_TREE, free(allFeaturesArray), false);

	spLoggerSafePrintDebug(DEBUG_KD_TREE_INITIALIZED, __FILE__, __FUNCTION__, __LINE__);

	free(allFeaturesArray);

	knn = spConfigGetKNN(config, &configMessage);

	spVal(configMessage == SP_CONFIG_SUCCESS, ERROR_READING_SETTINGS, false);

	spVal((*bpq = spBPQueueCreate(knn)), ERROR_INITIALIZING_BP_QUEUE, false);

	spLoggerSafePrintDebug(DEBUG_PRIORITY_QUEUE_INITIALIZED, __FILE__, __FUNCTION__,
			__LINE__);

	return true;
}
Exemplo n.º 2
0
Arquivo: KDTree.c Projeto: orrbarkat/c
int* spFindImages(SPPoint* queryFeatures, const int querySize,
		const SPKDTreeNode root, const SPConfig config, SP_CONFIG_MSG *msg){
    int i, knn, numOfSimilarImg, numOfImages;
    int *imageCounter, *res;
    SPListElement element;
    knn = spConfigGetKNN(config, msg);

    SPBPQueue q = spBPQueueCreate(knn);
    if(!q){
        spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        return NULL;
    }
    numOfImages = spConfigGetNumOfImages(config, msg);
    numOfSimilarImg = spConfigGetNumOfSimilarImages(config, msg);
    imageCounter = (int*)calloc(numOfImages, sizeof(int));
    if(!imageCounter){
        spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        spBPQueueDestroy(q);
        return NULL;
    }
    /* count the num of neighbours of every
     * image for all features of the query */
    for(i=0; i<querySize; i++){
        spBPQueueClear(q);
        spKNNSearch(queryFeatures[i], root, q);
        while((element = spBPQueuePeek(q))!=NULL){
            imageCounter[spListElementGetIndex(element)]+=1;
            spListElementDestroy(element);
            spBPQueueDequeue(q);
        }
    }
    spBPQueueClear(q);
    spBPQueueDestroy(q);
    res = getTopImagesFromArray(imageCounter, numOfImages, numOfSimilarImg);
    free(imageCounter);
    return res;
}
Exemplo n.º 3
0
bool testGivenConfFile() {
	char imagePath[100], pcaPath[100];
	SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS;
	SPConfig config = spConfigCreate("./unit_tests/spcbirTestCase1.config", &msg);

	ASSERT_TRUE(config != NULL);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(!strcmp(spConfigGetImagesDirectory(config, &msg), "./images/"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetImagesDirectory(NULL, &msg) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(!strcmp(spConfigGetImagesPrefix(config, &msg), "img"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetImagesPrefix(NULL, &msg) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(!strcmp(spConfigGetImagesSuffix(config, &msg), ".png"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetImagesSuffix(NULL, &msg) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(!strcmp(spConfigGetPCAFilename(config, &msg), "pca.yml"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetPCAFilename(NULL, &msg) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigIsExtractionMode(config, &msg) == true);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigIsExtractionMode(NULL, &msg) == false);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigMinimalGui(config, &msg) == false);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigMinimalGui(NULL, &msg) == false);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 22);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetNumOfImages(NULL, &msg) == -1);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetNumOfFeatures(config, &msg) == 100);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetNumOfFeatures(NULL, &msg) == -1);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetPCADim(config, &msg) == 20);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetPCADim(NULL, &msg) == -1);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetNumOfSimilarImages(config, &msg) == 5);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetNumOfSimilarImages(NULL, &msg) == -1);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetKNN(config, &msg) == 5);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetKNN(NULL, &msg) == -1);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetSplitMethod(config, &msg) == MAX_SPREAD);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetSplitMethod(NULL, &msg) == MAX_SPREAD);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(spConfigGetLoggerLevel(config, &msg) == SP_LOGGER_DEBUG_INFO_WARNING_ERROR_LEVEL);
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetLoggerLevel(NULL, &msg) == SP_LOGGER_INFO_WARNING_ERROR_LEVEL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);

	ASSERT_TRUE(!strcmp(spConfigGetLoggerFilename(config, &msg), "stdout"));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);

	ASSERT_TRUE(spConfigGetLoggerFilename(NULL, &msg) == NULL);
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_ARGUMENT);


	ASSERT_TRUE(spConfigGetImagePath(imagePath, config, 13) == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(imagePath, "./images/img13.png"));

	ASSERT_TRUE(spConfigGetImagePath(imagePath, config, 22) == SP_CONFIG_INDEX_OUT_OF_RANGE);
	ASSERT_TRUE(spConfigGetImagePath(NULL, config, 1) == SP_CONFIG_INVALID_ARGUMENT);
	ASSERT_TRUE(spConfigGetImagePath(imagePath, NULL, 1) == SP_CONFIG_INVALID_ARGUMENT);
	ASSERT_TRUE(spConfigGetImagePath(NULL, NULL, 1) == SP_CONFIG_INVALID_ARGUMENT);


	ASSERT_TRUE(spConfigGetPCAPath(pcaPath, config) == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(pcaPath, "./images/pca.yml"));

	ASSERT_TRUE(spConfigGetPCAPath(NULL, config) == SP_CONFIG_INVALID_ARGUMENT);
	ASSERT_TRUE(spConfigGetPCAPath(pcaPath, NULL) == SP_CONFIG_INVALID_ARGUMENT);
	ASSERT_TRUE(spConfigGetPCAPath(NULL, NULL) == SP_CONFIG_INVALID_ARGUMENT);

	spConfigDestroy(config);

	return true;
}
Exemplo n.º 4
0
bool config_funcFailure_nullCheck()
{
	SP_CONFIG_MSG msg;
	char path[100];

	SPConfig config = NULL;

	ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */
										1, /* file index */
										0,	/* line of the error */
										&config)
				);


	ASSERT_TRUE(false == spConfigIsExtractionMode(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(false == spConfigMinimalGui(NULL,&msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(-1 == spConfigGetNumOfImages(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(-1 == spConfigGetNumOfFeatures(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(-1 == spConfigGetPCADim(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	msg = spConfigGetImagePath(path, NULL, 1);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);
	msg = spConfigGetImagePath(NULL, config , 1);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	msg = spConfigGetFeatsPath(path, NULL, 1);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);
	msg = spConfigGetFeatsPath(NULL, config, 1);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	msg = spConfigGetPCAPath(path,NULL);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);
	msg = spConfigGetPCAPath(NULL,config);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(-1 == spConfigGetNumOfSimilarImages(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	spConfigGetKDTreeSplitMethod(NULL, &msg);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	ASSERT_TRUE(-1 == spConfigGetKNN(NULL, &msg));
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	spConfigGetLoggerLevel(NULL, &msg);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	msg = spConfigGetLoggerFilename(path,NULL);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);
	msg = spConfigGetLoggerFilename(NULL,config);
	checkMsgInvalidArg_AndRevertMsgToSuccess(&msg);

	spConfigDestroy(config);

	return true;
}
Exemplo n.º 5
0
bool config_success_checkDefaults()
{
	SPConfig config = NULL;
	SP_CONFIG_MSG msg;

	ASSERT_TRUE(true == runConfigTest(SUCCESS, /* test type */
										7, /* file index */
										0,	/* line of the error */
										&config)
				);



	char featurePath[100];
	msg = spConfigGetFeatsPath(featurePath, config, 2);
	ASSERT_TRUE( 0 == strcmp(featurePath, "./images10/myImg2.feats") );
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	char imgPath[100];
	msg = spConfigGetImagePath(imgPath, config, 4);
	ASSERT_TRUE( 0 == strcmp(imgPath, "./images10/myImg4.gif") );
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(SPLIT_METHOD_MAXSPREAD ==
							spConfigGetKDTreeSplitMethod(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(1 == spConfigGetKNN(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	char loggerFile[100];
	msg = spConfigGetLoggerFilename(loggerFile, config);
	ASSERT_TRUE( 0 == strcmp(loggerFile, "stdout") );
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(SP_LOGGER_INFO_WARNING_ERROR_LEVEL ==
							spConfigGetLoggerLevel(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(100 == spConfigGetNumOfFeatures(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(10 == spConfigGetNumOfImages(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(1 == spConfigGetNumOfSimilarImages(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE(20 == spConfigGetPCADim(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	char pcaPath[100];
	msg = spConfigGetPCAPath(pcaPath, config);
	ASSERT_TRUE( 0 == strcmp(pcaPath, "./images10/pca.yml") );
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}

	ASSERT_TRUE( true == spConfigIsExtractionMode(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}


	ASSERT_TRUE( false == spConfigMinimalGui(config, &msg));
	if(!checkMsgSuccess_AndRevertMsgToNonSuccess(&msg))
	{
		printf("error line %d", __LINE__);
		return false;
	}


	spConfigDestroy(config);

	return true;
}