Better output
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
parent
189a355033
commit
90b9fdb0b0
@ -1,9 +1,10 @@
|
||||
all: scanner
|
||||
|
||||
ifeq ("$(wildcard /usr/include/sqlite3.h)","")
|
||||
@echo "Install libsqlite3-dev"
|
||||
@false
|
||||
endif
|
||||
#ifeq ("$(wildcard /usr/include/sqlite3.h)","")
|
||||
# @echo "Install libsqlite3-dev"
|
||||
# @false
|
||||
#endif
|
||||
|
||||
scanner: scanner.c
|
||||
gcc -o scanner scanner.c -lm -lsqlite3
|
||||
gcc -o scanner scanner.c -lm
|
||||
# gcc -o scanner scanner.c -lm -lsqlite3
|
||||
|
@ -14,9 +14,11 @@ typedef struct Face {
|
||||
struct Face *prev;
|
||||
} Face;
|
||||
|
||||
char fileBuf[5000];
|
||||
char pathBuf[1028];
|
||||
|
||||
Face *readFaceDescriptor(int id, char *path) {
|
||||
FILE *f;
|
||||
char buf[5000];
|
||||
Face *pFace = (Face *)malloc(sizeof(Face));
|
||||
memset(pFace, 0, sizeof(Face));
|
||||
f = fopen(path, "r");
|
||||
@ -24,11 +26,11 @@ Face *readFaceDescriptor(int id, char *path) {
|
||||
free(pFace);
|
||||
return NULL;
|
||||
}
|
||||
size_t s = fread(buf, 1, sizeof(buf), f);
|
||||
size_t s = fread(fileBuf, 1, sizeof(fileBuf), f);
|
||||
fclose(f);
|
||||
|
||||
char *p = buf;
|
||||
buf[s] = 0;
|
||||
char *p = fileBuf;
|
||||
fileBuf[s] = 0;
|
||||
while (*p && *p != '-' && *p != '+' && (*p < '0' || *p > '9')) {
|
||||
p++;
|
||||
}
|
||||
@ -60,15 +62,16 @@ long double euclideanDistance(long double *a, long double *b) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int len = 0;
|
||||
int i;
|
||||
Face *pChain = NULL;
|
||||
for (i = 0; i < 100; i++) {
|
||||
char buf[1028];
|
||||
sprintf(buf, "%s/face-data/%d", argv[1], i);
|
||||
DIR *faceDir = opendir(buf);
|
||||
sprintf(pathBuf, "%s/face-data/%d", argv[1], i);
|
||||
DIR *faceDir = opendir(pathBuf);
|
||||
fprintf(stderr, "Reading %s...\n", pathBuf);
|
||||
|
||||
if (!faceDir) {
|
||||
printf("Can not open %s\n", buf);
|
||||
fprintf(stderr, "Can not open %s\n", pathBuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -85,11 +88,15 @@ int main(int argc, char *argv[]) {
|
||||
p++;
|
||||
}
|
||||
char path[1028*2];
|
||||
sprintf(path, "%s/%s", buf, ent->d_name);
|
||||
sprintf(path, "%s/%s", pathBuf, ent->d_name);
|
||||
Face *pFace = readFaceDescriptor(id, path);
|
||||
if (!pFace) {
|
||||
continue;
|
||||
}
|
||||
len++;
|
||||
if (len % 1000 == 0) {
|
||||
fprintf(stderr, "...read %d...\n", len);
|
||||
}
|
||||
if (pChain) {
|
||||
pFace->next = pChain;
|
||||
}
|
||||
@ -98,26 +105,20 @@ int main(int argc, char *argv[]) {
|
||||
closedir(faceDir);
|
||||
}
|
||||
|
||||
Face *pLink = pChain;
|
||||
int len = 0;
|
||||
while (pLink) {
|
||||
Face *tmp = pLink;
|
||||
len++;
|
||||
pLink = pLink->next;
|
||||
}
|
||||
fprintf(stderr, "Read %d face descriptors...\n", len);
|
||||
|
||||
printf("DELETE FROM facedistances;\n");
|
||||
printf("BEGIN TRANSACTION;\n");
|
||||
|
||||
/* Allocate storage for all distances */
|
||||
pLink = pChain;
|
||||
Face *pLink = pChain;
|
||||
while (pLink) {
|
||||
pLink->distances = (long double *)malloc(sizeof(long double) * len);
|
||||
pLink = pLink->next;
|
||||
}
|
||||
|
||||
pLink = pChain;
|
||||
int sourceIndex = 0;
|
||||
int sourceIndex = 0, lines = 0;
|
||||
while (pLink) {
|
||||
int targetIndex = 0;
|
||||
Face *pTarget = pChain;
|
||||
@ -133,6 +134,10 @@ int main(int argc, char *argv[]) {
|
||||
((pLink->faceId < pTarget->faceId) ? pLink->faceId : pTarget->faceId),
|
||||
((pLink->faceId < pTarget->faceId) ? pTarget->faceId : pLink->faceId),
|
||||
pLink->distances[targetIndex]);
|
||||
lines++;
|
||||
if (lines % 1000 == 0) {
|
||||
fprintf(stderr, "...output %d DB lines (%0.2f complete)...\n", lines, (float)(1. * sourceIndex / (1. * len)));
|
||||
}
|
||||
}
|
||||
}
|
||||
pTarget = pTarget->next;
|
||||
|
Loading…
x
Reference in New Issue
Block a user