forked from ofirm93/SoftwareProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtModeForMain.c
More file actions
150 lines (138 loc) · 3.72 KB
/
ExtModeForMain.c
File metadata and controls
150 lines (138 loc) · 3.72 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
/*
* ExtModeForMain.c
*
* Created on: Mar 14, 2017
* Author: user
*/
//maybe static char*
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "SPImageProc.h"
#define MAX_STRING_LENGTH 1024
#define FILE_PATH_PATTERN "%s%s%d%s"
#define FEATURE_DIM 128
int spPCADimension = 12;//for now only
//wont need the variables after we have system variables
void ExtractionModeAct(char* directory, char* imagePrefix, char* imageSuffix,
int spNumOfImages, int spNumOfFeatures){
char featSuffix[7] = ".feats";
int* numOfFeatures = malloc(sizeof(int));
if(numOfFeatures == NULL){
return;
}
for(int i=0; i<spNumOfImages;i++){
//getting the paths
char imgPath[MAX_STRING_LENGTH];
sprintf(imgPath, FILE_PATH_PATTERN, directory, imagePrefix, i, imageSuffix); //check positive
char filePath[MAX_STRING_LENGTH];
sprintf(filePath, FILE_PATH_PATTERN, directory, imagePrefix, i, featSuffix); //check positive
FILE* file = fopen(filePath, 'w');
if(file == NULL)
{
free(numOfFeatures);
return;
}
SPPoint** imgFeatures = getImageFeatures(imgPath,i,numOfFeatures); //possible leak
if(imgFeatures == NULL){
free(numOfFeatures);
fclose(file);
return;
}
fprintf(file,"%d,", *numOfFeatures); //check positive
for (int k=0; k<*numOfFeatures;k++){
if(imgFeatures[k] == NULL){
for(int m=0; m<k;m++){
spPointDestroy(imgFeatures[m]);
}
free (imgFeatures);
free(numOfFeatures);
fclose(file);
return;
}
for( int j=0; j<spPCADimension; j++){
fprintf(file,"%f,",spPointGetAxisCoor(imgFeatures[k],j));
}
//fprintf(file," ");
}
fclose(file);
for (int k=0; k<*numOfFeatures;k++){
spPointDestroy(imgFeatures[k]);
}
}
}
SPPoint*** NotExtractionModeAct(char* directory, char* imagePrefix, char* imageSuffix,
int spNumOfImages, int spNumOfFeatures){
//creating the returned variable
SPPoint*** gallery = malloc(sizeof(SPPoint**) * spNumOfImages);
if(gallery == NULL){
return NULL;
}
//null check
char featSuffix[7] = ".feats";
int* numOfFeatures = malloc(sizeof(int));
if(numOfFeatures == NULL){
free(gallery);
return NULL;
}
double* featValArray = malloc(sizeof(double)*spPCADimension);
if(featValArray == NULL){
free(gallery);
free(numOfFeatures);
return NULL;
}
for(int i=0; i<spNumOfImages; i++){
char filePath [MAX_STRING_LENGTH];
sprintf(filePath, FILE_PATH_PATTERN, directory, imagePrefix, i, featSuffix); //check positive
FILE* file = fopen(filePath, 'r');
if(file == NULL)
{
free(gallery);
free(featValArray);
free(numOfFeatures);
return NULL;
}
fscanf(file, "%d,",*numOfFeatures);
gallery[i] = malloc(sizeof(SPPoint*) * *numOfFeatures);
if(gallery[i] == NULL){
for(int b=0; b<i; b++){
for( int j=0; j<spPCADimension; j++){
spPointDestroy(gallery[b][j]);
}
free(gallery[b]);
}
free(gallery);
free(featValArray);
free(numOfFeatures);
fclose(file);
return NULL;
}
for(int k = 0; k<*numOfFeatures;k++){
for(int j=0; j<spPCADimension; j++){
fscanf(file, "%f,",featValArray[j]);
}
gallery[i][k]= spPointCreate(featValArray,spPCADimension,i); //index of feature is image's index
if(gallery[i][k] == NULL){
for(int b=0; b<i; b++){
for( int j=0; j<spPCADimension; j++){
spPointDestroy(gallery[b][j]);
}
free(gallery[b]);
}
for(int j=0; j<k;j++){
spPointDestroy(gallery[i][k]);
}
free(gallery[i]);
free(gallery);
free(featValArray);
free(numOfFeatures);
fclose(file);
return NULL;
}
}
fclose(file);
}
free(featValArray);
free(numOfFeatures);
return gallery;
}