-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone_process.c
More file actions
97 lines (75 loc) · 2.22 KB
/
one_process.c
File metadata and controls
97 lines (75 loc) · 2.22 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <float.h>
#include "worker.h"
//ABDULLAH FINAL
int main(int argc, char **argv) {
char ch;
char path[PATHLENGTH];
char *startdir = ".";
char *image_file = NULL;
while((ch = getopt(argc, argv, "d:")) != -1) {
switch (ch) {
case 'd':
startdir = optarg;
break;
default:
fprintf(stderr, "Usage: queryone [-d DIRECTORY_NAME] FILE_NAME\n");
exit(1);
}
}
if (optind != argc-1) {
fprintf(stderr, "Usage: queryone [-d DIRECTORY_NAME] FILE_NAME\n");
} else
image_file = argv[optind];
// Open the directory provided by the user (or current working directory)
Image *img = read_image(image_file);
if(!img){
exit(1);
}
DIR *dirp;
if((dirp = opendir(startdir)) == NULL) {
perror("opendir");
exit(1);
}
struct dirent *dp;
CompRecord CRec;
strcpy(CRec.filename,"");
CRec.distance = FLT_MAX;
while((dp = readdir(dirp)) != NULL) {
if(strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0 ||
strcmp(dp->d_name, ".svn") == 0){
continue;
}
strncpy(path, startdir, PATHLENGTH);
strncat(path, "/", PATHLENGTH - strlen(path) - 1);
strncat(path, dp->d_name, PATHLENGTH - strlen(path) - 1);
struct stat sbuf;
if(stat(path, &sbuf) == -1) {
//This should only fail if we got the path wrong
// or we don't have permissions on this entry.
perror("stat");
exit(1);
}
// Only call process_dir if it is a directory
// Otherwise ignore it.
if(S_ISDIR(sbuf.st_mode)) {
//printf("Processing all images in directory: %s \n", path);
CompRecord c = process_dir(path,img,-459);
if(c.distance<CRec.distance){
CRec.distance = c.distance;
strcpy(CRec.filename,c.filename);
}
}
}
printf("The most similar image is %s with a distance of %f\n", CRec.filename, CRec.distance);
free(img->p);
free(img);
return 0;
}