Skip to content

Commit

Permalink
added the validator for dpm
Browse files Browse the repository at this point in the history
The current result is : 74.36% (31), a little lower than DPM and
HOG implementations. But, this result is without bounding box prediction
such that some correct result may be classified as false alarms.
  • Loading branch information
liuliu committed Apr 6, 2012
1 parent f6bc465 commit bd4ffda
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 12 deletions.
21 changes: 11 additions & 10 deletions bin/bbfdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ int main(int argc, char** argv)
ccv_dense_matrix_t* image = 0;
ccv_bbf_classifier_cascade_t* cascade = ccv_load_bbf_classifier_cascade(argv[2]);
ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_bbf_param_t params = { .interval = 5, .min_neighbors = 2, .flags = 0, .size = ccv_size(24, 24) };
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
ccv_bbf_param_t params = { .interval = 5, .min_neighbors = 2, .flags = 0, .size = ccv_size(24, 24) };
ccv_array_t* seq = ccv_bbf_detect_objects(image, &cascade, 1, params);
elapsed_time = get_current_time() - elapsed_time;
for (i = 0; i < seq->rnum; i++)
Expand All @@ -33,21 +33,21 @@ int main(int argc, char** argv)
ccv_matrix_free(image);
} else {
FILE* r = fopen(argv[1], "rt");
if (argc == 3)
chdir(argv[2]);
if (argc == 4)
chdir(argv[3]);
if(r)
{
char file[1000 + 1];
while(fgets(file, 1000, r))
size_t len = 1024;
char* file = (char*)malloc(len);
ssize_t read;
while((read = getline(&file, &len, r)) != -1)
{
int len = (int)strlen(file);
while(len > 0 && isspace(file[len - 1]))
len--;
file[len] = '\0';
while(read > 1 && isspace(file[read - 1]))
read--;
file[read] = 0;
image = 0;
ccv_read(file, &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
assert(image != 0);
ccv_bbf_param_t params = { .interval = 5, .min_neighbors = 2, .flags = 0, .size = ccv_size(24, 24) };
ccv_array_t* seq = ccv_bbf_detect_objects(image, &cascade, 1, params);
for (i = 0; i < seq->rnum; i++)
{
Expand All @@ -57,6 +57,7 @@ int main(int argc, char** argv)
ccv_array_free(seq);
ccv_matrix_free(image);
}
free(file);
fclose(r);
}
}
Expand Down
36 changes: 35 additions & 1 deletion bin/dpmdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ int main(int argc, char** argv)
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_ANY_FILE);
ccv_dpm_mixture_model_t* model = ccv_load_dpm_mixture_model(argv[2]);
ccv_dpm_param_t params = { .interval = 8, .min_neighbors = 2, .flags = 0, .threshold = -0.3 };
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
ccv_dpm_param_t params = { .interval = 8, .min_neighbors = 2, .flags = 0, .threshold = -0.3 };
ccv_array_t* seq = ccv_dpm_detect_objects(image, &model, 1, params);
elapsed_time = get_current_time() - elapsed_time;
if (seq)
Expand All @@ -38,6 +38,40 @@ int main(int argc, char** argv)
printf("elapsed time %dms\n", elapsed_time);
}
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_GRAY | CCV_IO_ANY_FILE);
assert(image != 0);
ccv_array_t* seq = ccv_dpm_detect_objects(image, &model, 1, params);
if (seq != 0)
{
for (i = 0; i < seq->rnum; i++)
{
ccv_root_comp_t* comp = (ccv_root_comp_t*)ccv_array_get(seq, i);
printf("%s %d %d %d %d %f %d\n", file, comp->rect.x, comp->rect.y, comp->rect.width, comp->rect.height, comp->confidence, comp->pnum);
for (j = 0; j < comp->pnum; j++)
printf("| %d %d %d %d %f\n", comp->part[j].rect.x, comp->part[j].rect.y, comp->part[j].rect.width, comp->part[j].rect.height, comp->part[j].confidence);
}
ccv_array_free(seq);
}
ccv_matrix_free(image);
}
free(file);
fclose(r);
}
}
ccv_drain_cache();
return 0;
Expand Down
61 changes: 61 additions & 0 deletions bin/dpmvldtr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env ruby

exit unless ARGV.length == 2

truth = Hash.new
total = 0

files = Dir.glob(ARGV[0] + '/*.txt')

files.each do |file|
name = nil;
boxes = Array.new
File.new(file).each_line do |line|
next if line[0] == '#'
name = line[line.rindex('/') + 1, line.rindex('"') - (line.rindex('/') + 1)] if line[0, 14].downcase == "image filename"
if line[0, 16].downcase == "bounding box for"
i = line.scan(/object\s*(\d+)/)[0][0].to_i
coord = line.scan(/\((\d+),\s*(\d+)\)\s*-\s*\((\d+),\s*(\d+)\)/)[0]
boxes[i - 1] = { :x => coord[0].to_i, :y => coord[1].to_i, :width => coord[2].to_i - coord[0].to_i, :height => coord[3].to_i - coord[1].to_i }
end
end
truth[name] = boxes;
total += boxes.length;
end

fa = 0
tp = 0

File.new(ARGV[1]).each_line do |line|
next if line[0] == '|'
args = line.split(" ")
name = args[0][args[0].rindex('/') + 1, args[0].length - (args[0].rindex('/') + 1)]
if !truth[name]
fa += 1
else
x = args[1].to_i
y = args[2].to_i
width = args[3].to_i
height = args[4].to_i
outlier = true
truth[name].each do |obj|
opx_min = [obj[:x], x].max
opy_min = [obj[:y], y].max
opx_max = [obj[:x] + obj[:width], x + width].min
opy_max = [obj[:y] + obj[:height], y + height].min
r0 = [opx_max - opx_min, 0].max * [opy_max - opy_min, 0].max
r1 = obj[:width] * obj[:height] * 0.5
if r0 > r1
outlier = false
break
end
end
if outlier
fa += 1
else
tp += 1
end
end
end

print ((tp.to_f / total.to_f * 10000).round / 100.0).to_s + "% ("+ fa.to_s + ")\n"
2 changes: 1 addition & 1 deletion lib/ccv_dpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ccv_array_t* ccv_dpm_detect_objects(ccv_dense_matrix_t* a, ccv_dpm_mixture_model
double scale = pow(2., 1. / (params.interval + 1.));
int next = params.interval + 1;
int scale_upto = (int)(log((double)ccv_min(hr, wr)) / log(scale)) - next;
if (scale_upto < 1) // image is too small to be interesting
if (scale_upto < 0) // image is too small to be interesting
return 0;
ccv_dense_matrix_t** pyr = (ccv_dense_matrix_t**)alloca((scale_upto + next * 2) * sizeof(ccv_dense_matrix_t*));
memset(pyr, 0, (scale_upto + next * 2) * sizeof(ccv_dense_matrix_t*));
Expand Down

0 comments on commit bd4ffda

Please sign in to comment.