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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c89713391b5a27b50e98b92593bf3e8b2d75e25
|
4
|
+
data.tar.gz: 3fc35625fb69b98d8eb7fd2df147e62ffa9a254e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc757c499d094dc49c1731fc2d9bd481c23eae51cd54ff433af746c239f65aa17189bfac7148cedb04112c7a25ed64ad8e8a4604881741a597b3e7d300f1534
|
7
|
+
data.tar.gz: bd4ef21b9c51fdd4112704979c1c3601547885e099f36f9fa389c36bb47094db99e9b52cce94b6486e41324dd15e4219c624d450cdbcfc99b4770dd0ea78d048
|
data/lib/face_cropper.rb
CHANGED
@@ -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
|
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:
|
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:
|
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
|
32
|
-
y: (@left
|
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
|
data/lib/face_cropper/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|