lib/morandi/redeye.rb in morandi-0.12.1 vs lib/morandi/redeye.rb in morandi-0.99.03
- old
+ new
@@ -1,62 +1,50 @@
-require 'redeye'
+# frozen_string_literal: true
module Morandi
module RedEye
# The parameter determines how many reddish pixels needs to be in the area to consider it a valid red eye
# The reason for its existence is to prevent the situations when the bigger red area causes an excessive correction
# e.g. continuous red eyeglasses frame or sunburnt person's skin around eyes forming an area
RED_AREA_DENSITY_THRESHOLD = 0.3
- end
-end
-module Morandi
-module RedEye
-module TapRedEye
- module_function
- 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)
+ # RedEye finder that looks for "eye" closest to a point
+ module TapRedEye
+ module_function
- sensitivity = 2
- blobs = redeye.identify_blobs(sensitivity).reject { |region|
- region.noPixels < 4 || !region.squareish?(0.5, RED_AREA_DENSITY_THRESHOLD)
- }.sort_by { |region|
- region.area_min_x = x1
- region.area_min_y = y1
+ 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
- # Higher is better
- score = (region.noPixels) / (region.distance_from(x, y) ** 2)
- }
+ return pixbuf unless (x1 >= 0) && (x2 > x1) && (y1 >= 0) && (y2 > y1)
- blob = blobs.last
- redeye.correct_blob(blob.id) if blob
- pb = redeye.pixbuf
- end
-end
-end
-end
+ red_eye = MorandiNative::RedEye.new(pixbuf, x1, y1, x2, y2)
-class ::RedEye::Region
- attr_accessor :area_min_x
- attr_accessor :area_min_y
- def centre
- [@area_min_x.to_i + ((maxX + minX) >> 1),
- @area_min_y.to_i + ((maxY + minY) >> 1)]
- end
+ sensitivity = 2
+ blobs = red_eye.identify_blobs(sensitivity).reject do |region|
+ region.noPixels < 4 || !region.squareish?(0.5, RED_AREA_DENSITY_THRESHOLD)
+ end
- # Pythagorean
- def distance_from(x,y)
- cx,cy = centre()
+ sorted_blobs = blobs.sort_by do |region|
+ region.area_min_x = x1
+ region.area_min_y = y1
+ end
- dx = cx - x
- dy = cy - y
-
- Math.sqrt( (dx * dx) + (dy * dy) )
+ blob = sorted_blobs.last
+ red_eye.correct_blob(blob.id) if blob
+ red_eye.pixbuf
+ end
+ end
end
end
+module MorandiNative
+ class RedEye
+ # Represents an area with a suspected red eye
+ class Region
+ attr_accessor :area_min_x, :area_min_y
+ end
+ end
+end