forked from liuliu/ccv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.rb
executable file
·65 lines (59 loc) · 1.97 KB
/
validator.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
62
63
64
65
#!/usr/bin/env ruby
exit unless ARGV.length == 2
truth = Hash.new
total = 0
File.new(ARGV[0]).each_line do |line|
args = line.split(" ")
name = args[0].split(".")[0].downcase
truth[name] = Array.new if truth[name].nil?
truth[name].push({:left_eye => {:x => args[1].to_f, :y => args[2].to_f},
:right_eye => {:x => args[3].to_f, :y => args[4].to_f},
:nose => {:x => args[5].to_f, :y => args[6].to_f},
:left_mouth => {:x => args[7].to_f, :y => args[8].to_f},
:center_mouth => {:x => args[9].to_f, :y => args[10].to_f},
:right_mouth => {:x => args[11].to_f, :y => args[12].to_f}})
total += 1
end
fa = 0
tp = 0
File.new(ARGV[1]).each_line do |line|
args = line.split(" ")
name = args[0].split(".")[0].downcase
if !truth[name]
fa += 1
else
# relaxing the box
x = args[1].to_f
y = args[2].to_f
width = args[3].to_f
height = args[4].to_f
x -= width * 0.25
y -= height * 0.25
width *= 1.5
height *= 1.5
outlier = true
truth[name].each do |face|
if (face[:left_eye][:x] > x && face[:left_eye][:x] < x + width &&
face[:left_eye][:y] > y && face[:left_eye][:y] < y + height &&
face[:right_eye][:x] > x && face[:right_eye][:x] < x + width &&
face[:right_eye][:y] > y && face[:right_eye][:y] < y + height &&
face[:nose][:x] > x && face[:nose][:x] < x + width &&
face[:nose][:y] > y && face[:nose][:y] < y + height &&
face[:left_mouth][:x] > x && face[:left_mouth][:x] < x + width &&
face[:left_mouth][:y] > y && face[:left_mouth][:y] < y + height &&
face[:center_mouth][:x] > x && face[:center_mouth][:x] < x + width &&
face[:center_mouth][:y] > y && face[:center_mouth][:y] < y + height &&
face[:right_mouth][:x] > x && face[:right_mouth][:x] < x + width &&
face[:right_mouth][:y] > y && face[:right_mouth][:y] < y + height)
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"