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
|
# File 'lib/morandi/redeye.rb', line 7
def tap_on(pb, x, y)
n = ([pb.height,pb.width].max / 10)
x1 = [x - n, 0].max
x2 = [x + n, pb.width].min
y1 = [y - n, 0].max
y2 = [y + n, pb.height].min
return pb unless (x1 >= 0) && (x2 > x1) && (y1 >= 0) && (y2 > y1)
redeye = ::RedEye.new(pb, x1, y1, x2, y2)
sensitivity = 2
blobs = redeye.identify_blobs(sensitivity).reject { |i|
i.noPixels < 4 or ! i.squareish?(0.5, 0.4)
}.sort_by { |i|
i.area_min_x = x1
i.area_min_y = y1
score = (i.noPixels) / (i.distance_from(x, y) ** 2)
}
blob = blobs.last
redeye.correct_blob(blob.id) if blob
pb = redeye.pixbuf
end
|