face_cropper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 702e3d2fbe93f586b47c7e3f2848f05729cc81b5
4
- data.tar.gz: c5b462c7ca47f0d8b535a9cb16074f62de01cbb9
3
+ metadata.gz: 9c89713391b5a27b50e98b92593bf3e8b2d75e25
4
+ data.tar.gz: 3fc35625fb69b98d8eb7fd2df147e62ffa9a254e
5
5
  SHA512:
6
- metadata.gz: 8d730b640816b8195ee5ccf5e558838cefc9462eef2e2dc9ef6f1e1aa7aa237cdaec11d201bf77069986c4a43a826ad92f8a31381a887e75560561f2b2d3412f
7
- data.tar.gz: 5a1fa3cab16bbefb0294cd8f8aaf141ea5fdb5a4f3498d4b8e5172de3494b2fb8d1ad28a75f0e0b0bf4452d23d17b054162a81592f8d340b5231d5736c230248
6
+ metadata.gz: 9cc757c499d094dc49c1731fc2d9bd481c23eae51cd54ff433af746c239f65aa17189bfac7148cedb04112c7a25ed64ad8e8a4604881741a597b3e7d300f1534
7
+ data.tar.gz: bd4ef21b9c51fdd4112704979c1c3601547885e099f36f9fa389c36bb47094db99e9b52cce94b6486e41324dd15e4219c624d450cdbcfc99b4770dd0ea78d048
@@ -9,9 +9,10 @@ class FaceCropper
9
9
  @to_bucket = params[:to_bucket]
10
10
  @image_key = params[:image_key]
11
11
  @face_boxis = params[:face_details]
12
+ @region = params[:region] || 'us-east-1'
12
13
  end
13
14
 
14
- def crop_and_upload!
15
+ def crop!
15
16
  faces = @face_boxis || detect_faces!
16
17
 
17
18
  tmp_original_image_path = download_original_image!
@@ -25,7 +26,7 @@ class FaceCropper
25
26
  end
26
27
 
27
28
  def detect_faces!
28
- detector = AwsRekognitionFaceDetector.new(bucket: @from_bucket, image_key: @image_key)
29
+ detector = AwsRekognitionFaceDetector.new(bucket: @from_bucket, image_key: @image_key, region: @region)
29
30
  detector.dcetect!.tap {|r| debug_print(r) }
30
31
  end
31
32
 
@@ -54,6 +55,6 @@ class FaceCropper
54
55
  end
55
56
 
56
57
  def s3_client
57
- @s3_client ||= Aws::S3::Client.new(region: 'us-east-1')
58
+ @s3_client ||= Aws::S3::Client.new(region: @region)
58
59
  end
59
60
  end
@@ -3,13 +3,14 @@ require 'pp'
3
3
 
4
4
  class FaceCropper
5
5
  class AwsRekognitionFaceDetector
6
- def initialize(bucket:, image_key:)
6
+ def initialize(bucket:, image_key:, region:)
7
7
  @bucket = bucket
8
8
  @imaget_key = image_key
9
+ @region = region
9
10
  end
10
11
 
11
12
  def dcetect!
12
- rekognition = Aws::Rekognition::Client.new(region: 'us-east-1')
13
+ rekognition = Aws::Rekognition::Client.new(region: @region)
13
14
 
14
15
  rekognition.detect_faces(
15
16
  image: {
@@ -4,11 +4,12 @@ class FaceCropper
4
4
  class FaceBox
5
5
  attr_reader :top, :left, :height, :width
6
6
 
7
- def initialize(top: , left: , height: , width:)
7
+ def initialize(top: , left: , height: , width: , margin: 0)
8
8
  @top = top
9
9
  @left = left
10
10
  @height = height
11
11
  @width = width
12
+ @margin = margin
12
13
  end
13
14
 
14
15
  def crop_face!(image_path)
@@ -26,10 +27,10 @@ class FaceCropper
26
27
 
27
28
  def calculate_position(image_width: , image_height:)
28
29
  {
29
- width: (@width * image_width).to_i,
30
- height: (@height * image.height).to_i,
31
- x: (@top * image.height).to_i,
32
- y: (@left * image.width).to_i
30
+ width: (@width * image_width).to_i + @margin,
31
+ height: (@height * image.height).to_i + @margin,
32
+ x: [(@top * image.height).to_i - @margin, 0].min,
33
+ y: [(@left * image.width).to_i - @margin, 0].min
33
34
  }
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  class FaceCropper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: face_cropper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takkanm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-19 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk