oxford-face-api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb77992f311699a0c0fcb4d58cd8f306e3b20758
4
+ data.tar.gz: ab4b7af6a2dca1278ef7653aa4774cbe1a2ad9c9
5
+ SHA512:
6
+ metadata.gz: 86dffbe90c64f7acb8ac544dd226a87916c9f9604d423b728591c4cd393ed3133b282d99449ba4fbaea3980bde7473f8152b47e6c1c7eb992a0eafdcddf87b49
7
+ data.tar.gz: 63a96d5badd5864bccb8d70b60b67876b5eae2ecafeacff4497bd98d60d1d9c36c6da54d59a8eff03ae4080dae811764c3edcf6a10a12ced0ba3155f76085e22
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swo
11
+ *.swp
12
+ *.gem
13
+ /test/key.txt
14
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oxford-face-api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ # oxford-face-api
2
+ Ruby gem for Microsoft Oxford Face api
3
+
4
+ ### Usage
5
+
6
+ ```
7
+ require 'oxford/face/api'
8
+
9
+ KEY="YOUR_API_KEY" # from Microsoft Oxford
10
+ OxfordFaceApi.init(KEY)
11
+
12
+ f = OxfordFaceApi::Face.new
13
+
14
+ img_url = "https://raw.githubusercontent.com/tantara/oxford-face-api/master/test/example.jpg"
15
+ return_face_id = true
16
+ return_face_landmarks = false
17
+ return_face_attributes = "age,gender"
18
+
19
+ res = f.detect(img_url, return_face_id, return_face_landmarks, return_face_attributes)
20
+ puts res.body # => https://gist.github.com/tantara/5d72786bd3c6acc285a29ec44c4a8d1e
21
+ ```
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oxford/face/api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,278 @@
1
+ require "oxford/face/api/version"
2
+ require "oxford/face/http_client"
3
+
4
+ module OxfordFaceApi
5
+ @api_key = ""
6
+
7
+ def self.init(api_key)
8
+ @api_key = api_key
9
+ end
10
+
11
+ def self.API_KEY
12
+ @api_key
13
+ end
14
+
15
+ class Face
16
+ def initialize
17
+ raise if OxfordFaceApi.API_KEY.empty?
18
+ @client = HttpClient.new(OxfordFaceApi.API_KEY)
19
+ end
20
+
21
+ # Detect
22
+ # POST https://api.projectoxford.ai/face/v1.0/detect[?returnFaceId][&returnFaceLandmarks][&returnFaceAttributes]
23
+ def detect(url, return_face_id = true, return_face_landmarks = false, return_face_attributes = "")
24
+ params = {
25
+ url: url
26
+ }
27
+ @client.post("/detect?returnFaceId=#{return_face_id}&returnFaceLandmarks=#{return_face_landmarks}&returnFaceAttributes=#{return_face_attributes}", params)
28
+ end
29
+
30
+ # TODO
31
+ # Find Similar
32
+ # POST https://api.projectoxford.ai/face/v1.0/findsimilars
33
+ def find_similar
34
+ params = {
35
+ }
36
+ @client.post("/findsimilars", params)
37
+ end
38
+
39
+ # TODO
40
+ # Group
41
+ # POST https://api.projectoxford.ai/face/v1.0/group
42
+ def group
43
+ params = {
44
+ }
45
+ @client.post("/group", params)
46
+ end
47
+
48
+ # Identify
49
+ # POST https://api.projectoxford.ai/face/v1.0/identify
50
+ def identify(group_id, face_ids, max_num_of_candidates_returned = 1, confidence_threshold = 0.5)
51
+ params = {
52
+ faceIds: face_ids,
53
+ personGroupId: group_id,
54
+ maxNumOfCandidatesReturned: max_num_of_candidates_returned,
55
+ confidenceThreshold: confidence_threshold
56
+ }
57
+ @client.post("/identify", params)
58
+ end
59
+
60
+ # Verify
61
+ # POST https://api.projectoxford.ai/face/v1.0/verify
62
+ def verify(face_id, group_id, person_id = "")
63
+ if person_id.empty?
64
+ face_id1 = face_id
65
+ face_id2 = group_id
66
+
67
+ params = {
68
+ faceId1: face_id1,
69
+ faceId2: face_id2,
70
+ }
71
+ else
72
+ params = {
73
+ faceId: face_id,
74
+ personGroupId: group_id,
75
+ personId: person_id
76
+ }
77
+ end
78
+ @client.post("/verify", params)
79
+ end
80
+ end
81
+
82
+ class FaceList
83
+ def initialize
84
+ raise if OxfordFaceApi.API_KEY.empty?
85
+ @client = HttpClient.new(OxfordFaceApi.API_KEY)
86
+ end
87
+
88
+ # Add a Face to a Face List
89
+ # POST https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}/persistedFaces[?userData][&targetFace]
90
+ def add_face(face_list_id, url, user_data = "", target_face = "")
91
+ params = {
92
+ url: url
93
+ }
94
+ @client.post("/facelists/#{face_list_id}/persistedFaces?userData=#{user_data}&targetFace=#{target_face}", params)
95
+ end
96
+
97
+ # Create a Face List
98
+ # PUT https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}
99
+ def create(face_list_id, name, user_data = "")
100
+ params = {
101
+ name: name,
102
+ userData: user_data
103
+ }
104
+ @client.put("/facelists/#{face_list_id}", params)
105
+ end
106
+
107
+ # FIXME
108
+ # Delete a Face from a Face List
109
+ # DELETE https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}/persistedFaces/{persistedFaceId}
110
+ def delete_face(face_list_id, face_id)
111
+ @client.delete("/facelists/#{face_list_id}/persistedFaces/#{face_id}")
112
+ end
113
+
114
+ # FIXME
115
+ # Delete a Face List
116
+ # DELETE https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}
117
+ def delete(face_list_id)
118
+ @client.delete("/facelists/#{face_list_id}")
119
+ end
120
+
121
+ # Get a Face List
122
+ # GET https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}
123
+ def faces(face_list_id)
124
+ @client.get("/facelists/#{face_list_id}")
125
+ end
126
+
127
+ # List Face Lists
128
+ # GET https://api.projectoxford.ai/face/v1.0/facelists
129
+ def all
130
+ @client.get("/facelists")
131
+ end
132
+
133
+ # Update a Face List
134
+ # PATCH https://api.projectoxford.ai/face/v1.0/facelists/{faceListId}
135
+ def update(face_list_id, name, user_data)
136
+ params = {
137
+ name: name,
138
+ userData: user_data
139
+ }
140
+ @client.patch("/facelists/#{face_list_id}", params)
141
+ end
142
+ end
143
+
144
+ class Person
145
+ def initialize
146
+ raise if OxfordFaceApi.API_KEY.empty?
147
+ @client = HttpClient.new(OxfordFaceApi.API_KEY)
148
+ end
149
+
150
+ # Add a Person Face
151
+ # POST https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}/persistedFaces[?userData][&targetFace]
152
+ def add_face(group_id, person_id, url, user_data = "", target_face = "")
153
+ params = {
154
+ url: url
155
+ }
156
+ @client.post("/persongroups/#{group_id}/persons/#{person_id}/persistedFaces?userData=#{user_data}&targetFace=#{target_face}", params)
157
+ end
158
+
159
+ # Create a Person
160
+ # POST https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons
161
+ def create(group_id, name, user_data = "")
162
+ params = {
163
+ name: name,
164
+ userData: user_data
165
+ }
166
+ @client.post("/persongroups/#{group_id}/persons", params)
167
+ end
168
+
169
+ # FIXME
170
+ # Delete a Person
171
+ # DELETE https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}
172
+ def delete(group_id, person_id)
173
+ @client.delete("/persongroups/#{group_id}/persons/#{person_id}")
174
+ end
175
+
176
+ # FIXME
177
+ # Delete a Person Face
178
+ # DELETE https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}
179
+ def delete_face(group_id, person_id, face_id)
180
+ @client.delete("/persongroups/#{group_id}/persons/#{person_id}/persistedFaces/#{face_id}")
181
+ end
182
+
183
+ # Get a Person
184
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}
185
+ def get(group_id, person_id)
186
+ @client.get("/persongroups/#{group_id}/persons/#{person_id}")
187
+ end
188
+
189
+ # Get a Person Face
190
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}
191
+ def face(group_id, person_id, face_id)
192
+ @client.get("/persongroups/#{group_id}/persons/#{person_id}/persistedFaces/#{face_id}")
193
+ end
194
+
195
+ # List Persons in a Person Group
196
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons
197
+ def all(group_id)
198
+ @client.get("/persongroups/#{group_id}/persons")
199
+ end
200
+
201
+ # Update a Person
202
+ # PATCH https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}
203
+ def update(group_id, person_id, name, user_data)
204
+ params = {
205
+ name: name,
206
+ userData: user_data
207
+ }
208
+ @client.patch("/persongroups/#{group_id}/persons/#{person_id}", params)
209
+ end
210
+
211
+ # Update a Person Face
212
+ # PATCH ttps://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}
213
+ def update_face(group_id, person_id, face_id, user_data)
214
+ params = {
215
+ userData: user_data
216
+ }
217
+ @client.patch("/persongroups/#{group_id}/persons/#{person_id}/persistedFaces/#{face_id}", params)
218
+ end
219
+ end
220
+
221
+ class PersonGroup
222
+ def initialize
223
+ raise if OxfordFaceApi.API_KEY.empty?
224
+ @client = HttpClient.new(OxfordFaceApi.API_KEY)
225
+ end
226
+
227
+ # Create a Person Group
228
+ # PUT https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}
229
+ def create(group_id, name, user_data = "")
230
+ params = {
231
+ name: name,
232
+ userData: user_data
233
+ }
234
+ @client.put("/persongroups/#{group_id}", params)
235
+ end
236
+
237
+ # FIXME
238
+ # Delete a Person Group
239
+ # DELETE https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}
240
+ def delete(group_id)
241
+ @client.delete("/persongroups/#{group_id}")
242
+ end
243
+
244
+ # Get a Person Group
245
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}
246
+ def get(group_id)
247
+ @client.get("/persongroups/#{group_id}")
248
+ end
249
+
250
+ # Get Person Group Training Status
251
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/training
252
+ def status(group_id)
253
+ @client.get("/persongroups/#{group_id}/training")
254
+ end
255
+
256
+ # List Person Groups
257
+ # GET https://api.projectoxford.ai/face/v1.0/persongroups[?start][&top]
258
+ def all(start = 1, top = 1000)
259
+ @client.get("/persongroups?start=#{start}&top=#{top}")
260
+ end
261
+
262
+ # Train Person Group
263
+ # POST https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}/train
264
+ def train(group_id)
265
+ @client.post("/persongroups/#{group_id}/train")
266
+ end
267
+
268
+ # Update a Person Group
269
+ # PATCH https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}
270
+ def update(group_id, name, user_data)
271
+ params = {
272
+ name: name,
273
+ userData: user_data
274
+ }
275
+ @client.patch("/persongroups/#{group_id}", params)
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,7 @@
1
+ module Oxford
2
+ module Face
3
+ module Api
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,89 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+
6
+ class HttpClient
7
+ def initialize(api_key)
8
+ uris = URI.parse("https://api.projectoxford.ai")
9
+ @http = Net::HTTP.new(uris.host, uris.port)
10
+ @http.use_ssl = true
11
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
12
+ @api_key = api_key
13
+ end
14
+
15
+ def get(path, params = {})
16
+ request = Net::HTTP::Get.new("/face/v1.0#{path}")
17
+ request.content_type = "application/json"
18
+ request['Ocp-Apim-Subscription-Key'] = @api_key
19
+
20
+ if params.is_a?(Hash)
21
+ request.set_form_data(params)
22
+ else
23
+ request.body = params
24
+ end
25
+
26
+ response = @http.request(request)
27
+ response
28
+ end
29
+
30
+ def post(path, params = {})
31
+ request = Net::HTTP::Post.new("/face/v1.0#{path}")
32
+ request.content_type = "application/json"
33
+ request['Ocp-Apim-Subscription-Key'] = @api_key
34
+
35
+ if params.is_a?(Hash)
36
+ request.body = params.to_json
37
+ else
38
+ request.body = params
39
+ end
40
+
41
+ response = @http.request(request)
42
+ response
43
+ end
44
+
45
+ def put(path, params = {})
46
+ request = Net::HTTP::Put.new("/face/v1.0#{path}")
47
+ request.content_type = "application/json"
48
+ request['Ocp-Apim-Subscription-Key'] = @api_key
49
+
50
+ if params.is_a?(Hash)
51
+ request.body = params.to_json
52
+ else
53
+ request.body = params
54
+ end
55
+
56
+ response = @http.request(request)
57
+ response
58
+ end
59
+
60
+ def patch(path, params = {})
61
+ request = Net::HTTP::Patch.new("/face/v1.0#{path}")
62
+ request.content_type = "application/json"
63
+ request['Ocp-Apim-Subscription-Key'] = @api_key
64
+
65
+ if params.is_a?(Hash)
66
+ request.body = params.to_json
67
+ else
68
+ request.body = params
69
+ end
70
+
71
+ response = @http.request(request)
72
+ response
73
+ end
74
+
75
+ def delete(path, params = {})
76
+ request = Net::HTTP::Delete.new("/face/v1.0#{path}")
77
+ request.content_type = "application/json"
78
+ request['Ocp-Apim-Subscription-Key'] = @api_key
79
+
80
+ if params.is_a?(Hash)
81
+ request.set_form_data(params)
82
+ else
83
+ request.body = params
84
+ end
85
+
86
+ response = @http.request(request)
87
+ response
88
+ end
89
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oxford/face/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oxford-face-api"
8
+ spec.version = Oxford::Face::Api::VERSION
9
+ spec.authors = ["Taekmin Kim"]
10
+ spec.email = ["tantara.tm@gmail.com"]
11
+
12
+ spec.summary = %q{Oxford Face API}
13
+ spec.description = %q{Microsoft Oxford Face API}
14
+ spec.homepage = "https://github.com/tantara/oxford-face-api"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.10.1"
32
+
33
+ spec.add_dependency "rake", ">= 10.0"
34
+ spec.add_dependency "json", ">= 2.0"
35
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxford-face-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taekmin Kim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.10.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.10.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: Microsoft Oxford Face API
84
+ email:
85
+ - tantara.tm@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - lib/oxford/face/api.rb
97
+ - lib/oxford/face/api/version.rb
98
+ - lib/oxford/face/http_client.rb
99
+ - oxford-face-api.gemspec
100
+ homepage: https://github.com/tantara/oxford-face-api
101
+ licenses: []
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Oxford Face API
124
+ test_files: []