Better output

Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
James Ketrenos 2020-01-05 20:10:11 -08:00
parent 189a355033
commit 90b9fdb0b0
2 changed files with 29 additions and 23 deletions

View File

@ -1,9 +1,10 @@
all: scanner all: scanner
ifeq ("$(wildcard /usr/include/sqlite3.h)","") #ifeq ("$(wildcard /usr/include/sqlite3.h)","")
@echo "Install libsqlite3-dev" # @echo "Install libsqlite3-dev"
@false # @false
endif #endif
scanner: scanner.c scanner: scanner.c
gcc -o scanner scanner.c -lm -lsqlite3 gcc -o scanner scanner.c -lm
# gcc -o scanner scanner.c -lm -lsqlite3

View File

@ -14,9 +14,11 @@ typedef struct Face {
struct Face *prev; struct Face *prev;
} Face; } Face;
char fileBuf[5000];
char pathBuf[1028];
Face *readFaceDescriptor(int id, char *path) { Face *readFaceDescriptor(int id, char *path) {
FILE *f; FILE *f;
char buf[5000];
Face *pFace = (Face *)malloc(sizeof(Face)); Face *pFace = (Face *)malloc(sizeof(Face));
memset(pFace, 0, sizeof(Face)); memset(pFace, 0, sizeof(Face));
f = fopen(path, "r"); f = fopen(path, "r");
@ -24,11 +26,11 @@ Face *readFaceDescriptor(int id, char *path) {
free(pFace); free(pFace);
return NULL; return NULL;
} }
size_t s = fread(buf, 1, sizeof(buf), f); size_t s = fread(fileBuf, 1, sizeof(fileBuf), f);
fclose(f); fclose(f);
char *p = buf; char *p = fileBuf;
buf[s] = 0; fileBuf[s] = 0;
while (*p && *p != '-' && *p != '+' && (*p < '0' || *p > '9')) { while (*p && *p != '-' && *p != '+' && (*p < '0' || *p > '9')) {
p++; p++;
} }
@ -60,15 +62,16 @@ long double euclideanDistance(long double *a, long double *b) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int len = 0;
int i; int i;
Face *pChain = NULL; Face *pChain = NULL;
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
char buf[1028]; sprintf(pathBuf, "%s/face-data/%d", argv[1], i);
sprintf(buf, "%s/face-data/%d", argv[1], i); DIR *faceDir = opendir(pathBuf);
DIR *faceDir = opendir(buf); fprintf(stderr, "Reading %s...\n", pathBuf);
if (!faceDir) { if (!faceDir) {
printf("Can not open %s\n", buf); fprintf(stderr, "Can not open %s\n", pathBuf);
continue; continue;
} }
@ -85,11 +88,15 @@ int main(int argc, char *argv[]) {
p++; p++;
} }
char path[1028*2]; 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); Face *pFace = readFaceDescriptor(id, path);
if (!pFace) { if (!pFace) {
continue; continue;
} }
len++;
if (len % 1000 == 0) {
fprintf(stderr, "...read %d...\n", len);
}
if (pChain) { if (pChain) {
pFace->next = pChain; pFace->next = pChain;
} }
@ -98,26 +105,20 @@ int main(int argc, char *argv[]) {
closedir(faceDir); closedir(faceDir);
} }
Face *pLink = pChain; fprintf(stderr, "Read %d face descriptors...\n", len);
int len = 0;
while (pLink) {
Face *tmp = pLink;
len++;
pLink = pLink->next;
}
printf("DELETE FROM facedistances;\n"); printf("DELETE FROM facedistances;\n");
printf("BEGIN TRANSACTION;\n"); printf("BEGIN TRANSACTION;\n");
/* Allocate storage for all distances */ /* Allocate storage for all distances */
pLink = pChain; Face *pLink = pChain;
while (pLink) { while (pLink) {
pLink->distances = (long double *)malloc(sizeof(long double) * len); pLink->distances = (long double *)malloc(sizeof(long double) * len);
pLink = pLink->next; pLink = pLink->next;
} }
pLink = pChain; pLink = pChain;
int sourceIndex = 0; int sourceIndex = 0, lines = 0;
while (pLink) { while (pLink) {
int targetIndex = 0; int targetIndex = 0;
Face *pTarget = pChain; 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) ? pLink->faceId : pTarget->faceId),
((pLink->faceId < pTarget->faceId) ? pTarget->faceId : pLink->faceId), ((pLink->faceId < pTarget->faceId) ? pTarget->faceId : pLink->faceId),
pLink->distances[targetIndex]); 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; pTarget = pTarget->next;