-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_aux.cpp
More file actions
549 lines (520 loc) · 21.1 KB
/
main_aux.cpp
File metadata and controls
549 lines (520 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
//
// Created by Ofir on 29/03/2017.
//
#include <cstdio>
#include <cstdlib>
#include "main_aux.h"
#define MAX_PATH_LENGTH 1024
#define MAX_ERR_MSG_LENGTH 1024
#define ERR_MSG_INVALID_ARG "Error : One of the arguments supplied to the method is invalid."
#define ERR_MSG_INVALID_ARG_IN_METHOD "Error : One of the arguments supplied to the method %s is invalid."
#define ERR_MSG_CANNOT_ALLOCATE_MEM "Error : Couldn't allocate needed memory."
#define ERR_MSG_GET_IMG_PATH "spConfigGetImagePath()"
#define ERR_MSG_INDEX_OUT_OF_RANGE "Error : The index %d of a best candidate is out of range"
#define ERR_MSG_GENERAL "General error. Unexpectedly, the program reached to a code where it shouldn't supposed to."
#define ERR_MSG_MORE_IMG_THAN_AVAILABLE "Error : asked for %d closest images while there are only %d images at all."
#define ERR_MSG_CANNOT_EXT_FEAT "Error : Couldn't extract feature from the given image.\n Please check if Path : %s is correct."
#define ERR_MSG_CANNOT_FIND_CLOSE_FEAT "Error : Couldn't find the closest features to a feature."
#define ERR_MSG_BPQUEUE_PEEK "spBPQueuePeek()"
#define ERR_MSG_BPQUEUE_DEQUEUE "spBPQueueDequeue()"
#define ERR_MSG_CANNOT_PEEK_EMPTY "Error : Couldn't peek to the queue top because it's empty."
#define ERR_MSG_CANNOT_DEQUEUE_EMPTY "Error : Couldn't dequeue element from the queue because it's empty."
#define ERR_MSG_MTHD_GET_IMG_PATH_DATA "spConfigGetImagePathWithData()"
#define ERR_MSG_FAIL_PRINT_TO_FILE "Error : Failed to print to file."
#define ERR_MSG_FAIL_SCAN_FILE "Error : Failed reading from features file.\nPlease check if Path : %s is correct."
extern "C"{
// #include "SPBPriorityQueue.h"
#include "KNearestSearch.h"
}
char* spGetInputFromUser(const char *command) {
if(command == NULL) {
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return NULL;
}
char* input = (char*) malloc(MAX_PATH_LENGTH * sizeof(char));
if(input == NULL){
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
return NULL;
}
printf("%s",command);
fflush(stdout);
scanf("%s", input);
return input;
}
void spNonMinimalGUI(SPConfig config, char* queryPath, int* indexArray, int size) {
if(!queryPath || !config || !indexArray || size<1){
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return;
}
printf("Best candidates for - %s - are:\n", queryPath);
char errorMsg[MAX_ERR_MSG_LENGTH];
for (int i = 0; i < size; ++i) {
char path[1024];
SP_CONFIG_MSG msg = spConfigGetImagePath(path, config, indexArray[i]);
switch (msg){
case SP_CONFIG_INVALID_ARGUMENT:
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_GET_IMG_PATH);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return;
case SP_CONFIG_INDEX_OUT_OF_RANGE:
sprintf(errorMsg, ERR_MSG_INDEX_OUT_OF_RANGE, indexArray[i]);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return;
case SP_CONFIG_SUCCESS:
break;
default:
spLoggerPrintError(ERR_MSG_GENERAL, __FILE__, __func__, __LINE__);
return;
}
printf("%s\n", path);
}
}
void spMinimalGUI(SPConfig config, char* queryPath, int* indexArray, int size) {
if(!queryPath || !config || !indexArray || size<1){
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return;
}
sp::ImageProc s = sp::ImageProc(config);
char errorMsg[MAX_ERR_MSG_LENGTH];
for (int i = 0; i < size; ++i) {
char path[MAX_PATH_LENGTH];
SP_CONFIG_MSG msg = spConfigGetImagePath(path, config, indexArray[i]);
switch (msg){
case SP_CONFIG_INVALID_ARGUMENT:
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_GET_IMG_PATH);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return;
case SP_CONFIG_INDEX_OUT_OF_RANGE:
sprintf(errorMsg, ERR_MSG_INDEX_OUT_OF_RANGE, indexArray[i]);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return;
case SP_CONFIG_SUCCESS:
break;
default:
spLoggerPrintError(ERR_MSG_GENERAL, __FILE__, __func__, __LINE__);
return;
}
s.showImage(path);
}
}
int elementByValueComparator(const void *element1, const void *element2){
double value1 = (*(BPQueueElement*)element1).value;
double value2 = (*(BPQueueElement*)element2).value;
if(value1 - value2 == 0){
return 0;
}
else if( value1 - value2 > 0){
return 1;
}
return -1;
}
int* spGetBestKMatches(SPKDTree *kdTree, char *queryPath, SPConfig config, int numOfImages, int k){
if(!kdTree || !queryPath || !config || numOfImages < 0 || k < 0){
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return NULL;
}
if(k > numOfImages){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_MORE_IMG_THAN_AVAILABLE, k, numOfImages);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return NULL;
}
sp::ImageProc s = sp::ImageProc(config);
int numOfQueryFeat;
SPPoint** queryFeat = s.getImageFeatures(queryPath, DEFAULT_INDEX, &numOfQueryFeat);
if(!queryFeat){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_CANNOT_EXT_FEAT, queryPath);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
return NULL;
}
int* imageCounter =(int*) malloc(numOfImages * sizeof(int));
if(!imageCounter){
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
return NULL;
}
for (int i = 0; i < numOfImages; ++i) {
imageCounter[i] = 0;
}
for (int i = 0; i < numOfQueryFeat; ++i) {
SPBPQueue* kClose = getKClosestPoints(kdTree, queryFeat[i], k);
if(!kClose){
spLoggerPrintError(ERR_MSG_CANNOT_FIND_CLOSE_FEAT, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
return NULL;
}
SP_BPQUEUE_MSG bpqMsg;
BPQueueElement feature;
while(!spBPQueueIsEmpty(kClose)){
bpqMsg = spBPQueuePeek(kClose, &feature);
switch (bpqMsg){
case SP_BPQUEUE_INVALID_ARGUMENT:
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_BPQUEUE_PEEK);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
case SP_BPQUEUE_EMPTY:
spLoggerPrintError(ERR_MSG_CANNOT_PEEK_EMPTY, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
case SP_BPQUEUE_SUCCESS:
break;
default:
spLoggerPrintError(ERR_MSG_GENERAL, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
}
if(feature.index < 0 || feature.index > numOfImages){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INDEX_OUT_OF_RANGE, feature.index);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
}
imageCounter[feature.index] = imageCounter[feature.index] + 1;
bpqMsg = spBPQueueDequeue(kClose);
switch (bpqMsg){
case SP_BPQUEUE_INVALID_ARGUMENT:
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_BPQUEUE_DEQUEUE);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
case SP_BPQUEUE_EMPTY:
spLoggerPrintError(ERR_MSG_CANNOT_DEQUEUE_EMPTY, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
case SP_BPQUEUE_SUCCESS:
break;
default:
spLoggerPrintError(ERR_MSG_GENERAL, __FILE__, __func__, __LINE__);
spDestroySPPointArray(queryFeat, numOfQueryFeat);
free(imageCounter);
spBPQueueDestroy(kClose);
return NULL;
}
}
spBPQueueDestroy(kClose);
}
spDestroySPPointArray(queryFeat, numOfQueryFeat);
BPQueueElement* sortingArr =(BPQueueElement*) malloc(numOfImages * sizeof(BPQueueElement)); // initialize helper array
if (!sortingArr) {
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
free(imageCounter);
return NULL;
}
for (int i = 0; i < numOfImages; ++i) {
sortingArr[i].index = i;
sortingArr[i].value = imageCounter[i];
}
free(imageCounter);
qsort(sortingArr, (size_t) numOfImages, sizeof(BPQueueElement), elementByValueComparator);
int* result =(int*) malloc(k * sizeof(int));
if (!result) {
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
free(sortingArr);
return NULL;
}
for (int i = 0; i < k; ++i) {
result[i] = sortingArr[numOfImages - i - 1].index;
}
free(sortingArr);
return result;
}
void spDestroySPPointArray(SPPoint** array, int size){
if(!array || size < 0){
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return;
}
for (int i = 0; i < size; ++i) {
spPointDestroy(array[i]);
}
free(array);
}
void spDestroySPPoint2DimArray(SPPoint*** gallery, int* numOfFeatArray, int sizeOfGallery){
if(!gallery|| !numOfFeatArray){
return;
}
for(int i = 0; i< sizeOfGallery; i++){
spDestroySPPointArray(gallery[i],numOfFeatArray[i]);
}
free(gallery);
}
SPPoint** ExtractionModeAct(char* directory, char* imagePrefix, char* imageSuffix,
int spNumOfImages, sp::ImageProc spIp, int* totalNumOfFeatures, int spPCADimension){
if(!directory || !imagePrefix || !imageSuffix || !totalNumOfFeatures){
spLoggerPrintError(ERR_MSG_INVALID_ARG, __FILE__, __func__, __LINE__);
return NULL;
}
char featSuffix[7] = ".feats";
int* numOfFeatures = (int*) malloc(sizeof(int));
if(!numOfFeatures){
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
return NULL;
}
int* numOfFeatArray = (int*) malloc(sizeof(int) * spNumOfImages);
if(!numOfFeatArray){
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
free(numOfFeatures);
return NULL;
}
int totalNumOfFeat = 0;
int checker = 0;
SPPoint*** gallery = (SPPoint***) malloc ( sizeof(*gallery) * spNumOfImages ) ;
if(!gallery){
free(numOfFeatures);
free(numOfFeatArray);
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
return NULL;
}
for(int i=0; i<spNumOfImages;i++){
//getting the paths
char imgPath[MAX_PATH_LENGTH];
SP_CONFIG_MSG msg = spConfigGetImagePathWithData(imgPath, directory, imagePrefix, i, imageSuffix);
if(msg != SP_CONFIG_SUCCESS){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_MTHD_GET_IMG_PATH_DATA);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
char filePath [MAX_PATH_LENGTH];
msg = spConfigGetImagePathWithData(filePath, directory, imagePrefix, i, featSuffix);
if(msg != SP_CONFIG_SUCCESS){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_MTHD_GET_IMG_PATH_DATA);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
const char * destPtr = filePath;
const char writeMode = 'w';
FILE* file = fopen(destPtr, &writeMode);
if(file == NULL)
{
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, "Error : Couldn't open a file.\nPlease check if Path : %s is correct.", destPtr);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
SPPoint** imgFeatures = spIp.getImageFeatures(imgPath,i,numOfFeatures);
if(imgFeatures == NULL){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_CANNOT_EXT_FEAT, imgPath);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
fclose(file);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
for(int k = 0 ; k<*numOfFeatures; k++){
if(!imgFeatures[k]){
spDestroySPPointArray(imgFeatures,k);
fclose(file);
free(numOfFeatures);
free(numOfFeatArray);
free(gallery);
return NULL;
}
}
numOfFeatArray[i] = *numOfFeatures;
gallery[i] = imgFeatures;
totalNumOfFeat += *numOfFeatures;
checker = fprintf(file,"%d,", *numOfFeatures); //check positive
if(checker < 0){
spLoggerPrintError(ERR_MSG_FAIL_PRINT_TO_FILE, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
fclose(file);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
for (int k=0; k<*numOfFeatures;k++){
for( int j=0; j<spPCADimension; j++){
checker = fprintf(file,"%f,",spPointGetAxisCoor(imgFeatures[k],j));
if(checker < 0){
spLoggerPrintError(ERR_MSG_FAIL_PRINT_TO_FILE, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
fclose(file);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
}
}
fclose(file);
}
SPPoint** allImageFeatures = (SPPoint**) malloc(totalNumOfFeat * sizeof(*allImageFeatures));
if(!allImageFeatures){
spLoggerPrintError(ERR_MSG_FAIL_PRINT_TO_FILE, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,spNumOfImages);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
int k = 0;
for(int i=0; i<spNumOfImages;i++){
for(int j = 0; j < numOfFeatArray[i]; j++){
allImageFeatures[k] = gallery[i][j];
k++;
}
}
*totalNumOfFeatures = totalNumOfFeat;
free(numOfFeatures);
free(numOfFeatArray);
free(gallery);//NOT destroy - we need the points!
return allImageFeatures;
}
SPPoint** NonExtractionModeAct(char* directory, char* imagePrefix,
int spNumOfImages, int* totalNumOfFeatures, int spPCADimension){
if(!directory || !imagePrefix || !totalNumOfFeatures){
return NULL;
}
const char readMode = 'r';
int checker = 0;
//creating the returned variable
SPPoint*** gallery = (SPPoint***) malloc(sizeof(SPPoint**) * spNumOfImages);
if(gallery == NULL){
return NULL;
}
int* numOfFeatArray = (int*) malloc(sizeof(int) * spNumOfImages);
if(!numOfFeatArray){
spLoggerPrintError(ERR_MSG_CANNOT_ALLOCATE_MEM, __FILE__, __func__, __LINE__);
free(gallery);
return NULL;
}
int totalNumOfFeat = 0;
//null check
char featSuffix[7] = ".feats";
int* numOfFeatures = (int*) malloc(sizeof(int));
if(numOfFeatures == NULL){
free(numOfFeatArray);
free(gallery);
return NULL;
}
double* featValArray = (double*) malloc(sizeof(double)*spPCADimension);
if(featValArray == NULL){
free(gallery);
free(numOfFeatures);
free(numOfFeatArray);
return NULL;
}
for(int i=0; i<spNumOfImages; i++){
char filePath [MAX_PATH_LENGTH];
SP_CONFIG_MSG msg = spConfigGetImagePathWithData(filePath, directory, imagePrefix, i, featSuffix);
if(msg != SP_CONFIG_SUCCESS){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_INVALID_ARG_IN_METHOD, ERR_MSG_MTHD_GET_IMG_PATH_DATA);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
return NULL;
}
FILE* file = fopen(filePath, &readMode);
if(file == NULL)
{
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
return NULL;
}
checker = fscanf(file, "%d,",numOfFeatures);
if(checker < 0){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_FAIL_SCAN_FILE, filePath);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
fclose(file);
return NULL;
}
numOfFeatArray[i] = *numOfFeatures;
totalNumOfFeat += *numOfFeatures;
gallery[i] = (SPPoint**) malloc(sizeof(SPPoint*) * *numOfFeatures);
if(gallery[i] == NULL){
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
fclose(file);
return NULL;
}
for(int k = 0; k<*numOfFeatures;k++){
for(int j=0; j<spPCADimension; j++){
checker = fscanf(file, "%lf,",&featValArray[j]);
if(checker < 0){
char errorMsg[MAX_ERR_MSG_LENGTH];
sprintf(errorMsg, ERR_MSG_FAIL_SCAN_FILE, filePath);
spLoggerPrintError(errorMsg, __FILE__, __func__, __LINE__);
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
return NULL;
}
}
gallery[i][k]= spPointCreate(featValArray,spPCADimension,i); //index of feature is image's index
if(gallery[i][k] == NULL){
spDestroySPPoint2DimArray(gallery,numOfFeatArray,i);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
fclose(file);
return NULL;
}
}
fclose(file);
}
SPPoint** allImageFeatures = (SPPoint**) malloc (totalNumOfFeat * sizeof(SPPoint*) );
if(!allImageFeatures){
spDestroySPPoint2DimArray(gallery,numOfFeatArray,spNumOfImages);
free(numOfFeatures);
free(numOfFeatArray);
free(featValArray);
return NULL;
}
int k = 0;
for(int i=0; i<spNumOfImages; i++){
for(int j=0; j<numOfFeatArray[i]; j++){
allImageFeatures[k] = gallery[i][j];
k++;
}
}
*totalNumOfFeatures = totalNumOfFeat;
free(featValArray);
free(numOfFeatures);
free(numOfFeatArray);
for(int l=0; l<spNumOfImages; l++){
free(gallery[l]);
}
free(gallery); //NOT destroy - we need the points.
return allImageFeatures;
}