forked from liuliu/ccv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscddetect.c
69 lines (67 loc) · 1.99 KB
/
scddetect.c
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
#include "ccv.h"
#include <sys/time.h>
#include <ctype.h>
static unsigned int get_current_time(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
int main(int argc, char** argv)
{
assert(argc >= 3);
int i;
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
ccv_scd_classifier_cascade_t* cascade = ccv_scd_classifier_cascade_read(argv[2]);
ccv_read(argv[1], &image, CCV_IO_RGB_COLOR | CCV_IO_ANY_FILE);
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
ccv_array_t* seq = ccv_scd_detect_objects(image, &cascade, 1, ccv_scd_default_params);
elapsed_time = get_current_time() - elapsed_time;
for (i = 0; i < seq->rnum; i++)
{
ccv_comp_t* comp = (ccv_comp_t*)ccv_array_get(seq, i);
printf("%d %d %d %d %f\n", comp->rect.x, comp->rect.y, comp->rect.width, comp->rect.height, comp->classification.confidence);
}
printf("total : %d in time %dms\n", seq->rnum, elapsed_time);
ccv_array_free(seq);
ccv_matrix_free(image);
} else {
FILE* r = fopen(argv[1], "rt");
if (argc == 4)
chdir(argv[3]);
if(r)
{
size_t len = 1024;
char* file = (char*)malloc(len);
ssize_t read;
while((read = getline(&file, &len, r)) != -1)
{
while(read > 1 && isspace(file[read - 1]))
read--;
file[read] = 0;
image = 0;
ccv_read(file, &image, CCV_IO_RGB_COLOR | CCV_IO_ANY_FILE);
assert(image != 0);
ccv_scd_param_t params = ccv_scd_default_params;
params.size = ccv_size(24, 24);
ccv_array_t* seq = ccv_scd_detect_objects(image, &cascade, 1, params);
printf("%s %d\n", file, seq->rnum);
for (i = 0; i < seq->rnum; i++)
{
ccv_comp_t* comp = (ccv_comp_t*)ccv_array_get(seq, i);
printf("%d %d %d %d %f\n", comp->rect.x, comp->rect.y, comp->rect.width, comp->rect.height, comp->classification.confidence);
}
ccv_array_free(seq);
ccv_matrix_free(image);
}
free(file);
fclose(r);
}
}
ccv_scd_classifier_cascade_free(cascade);
ccv_disable_cache();
return 0;
}