Module: Morandi::RedEye::TapRedEye

Defined in:
lib/morandi/redeye.rb

Overview

RedEye finder that looks for “eye” closest to a point

Class Method Summary collapse

Class Method Details

.tap_on(pixbuf, x_coord, y_coord) ⇒ Object



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
# File 'lib/morandi/redeye.rb', line 14

def tap_on(pixbuf, x_coord, y_coord)
  n = ([pixbuf.height, pixbuf.width].max / 10)
  x1  = [x_coord - n, 0].max
  x2  = [x_coord + n, pixbuf.width].min
  y1  = [y_coord - n, 0].max
  y2  = [y_coord + n, pixbuf.height].min

  return pixbuf unless (x1 >= 0) && (x2 > x1) && (y1 >= 0) && (y2 > y1)

  red_eye = MorandiNative::RedEye.new(pixbuf, x1, y1, x2, y2)

  sensitivity = 2
  blobs = red_eye.identify_blobs(sensitivity).reject do |region|
    region.noPixels < 4 || !region.squareish?(0.5, RED_AREA_DENSITY_THRESHOLD)
  end

  sorted_blobs = blobs.sort_by do |region|
    region.area_min_x = x1
    region.area_min_y = y1
  end

  blob = sorted_blobs.last
  red_eye.correct_blob(blob.id) if blob
  red_eye.pixbuf
end