forked from liuliu/ccv
/
dpmvldtr.rb
executable file
·61 lines (54 loc) · 1.51 KB
/
dpmvldtr.rb
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
#!/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.6
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"