Class: Cognitive::Face::Client
- Inherits:
-
Object
- Object
- Cognitive::Face::Client
- Defined in:
- lib/cognitive/face/client.rb
Instance Method Summary collapse
-
#add_face_to_face_list(face:, face_list_id:, user_data: nil, target_face: nil) ⇒ Object
Add face to face list.
-
#create_face_list(face_list_id:, name:, user_data: nil) ⇒ Object
Create face list.
-
#delete_face_list(face_list_id:) ⇒ Object
Delete face list Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524f.
-
#delete_face_to_face_list(face_id:, face_list_id:) ⇒ Object
Deleted face from a face list.
-
#detect(face:, return_face_id: true, returnFaceLandmarks: false, returnFaceAttributes: nil) ⇒ Object
Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236.
-
#find_similar(face_id:, face_list_id:, mode: 'matchPerson') ⇒ Object
Find face from a face list.
-
#get_face_list(face_list_id:) ⇒ Object
Get information a face list id Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c.
-
#get_face_lists ⇒ Object
Get all face lists Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c.
-
#initialize(key:) ⇒ Client
constructor
Constructor.
Constructor Details
#initialize(key:) ⇒ Client
Constructor
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cognitive/face/client.rb', line 9 def initialize(key:) @key = key @headers = { 'Ocp-Apim-Subscription-Key' => @key, 'Content-Type': 'application/json' } @endpoints = { detect:'https://api.projectoxford.ai/face/v1.0/detect', facelist: 'https://api.projectoxford.ai/face/v1.0/facelists/', findsimilar: 'https://api.projectoxford.ai/face/v1.0/findsimilars' } end |
Instance Method Details
#add_face_to_face_list(face:, face_list_id:, user_data: nil, target_face: nil) ⇒ Object
Add face to face list
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cognitive/face/client.rb', line 116 def add_face_to_face_list(face:, face_list_id:, user_data: nil, target_face: nil) headers = @headers.merge( params: { userData: user_data, targetFace: target_face }, 'Content-Type': 'application/octet-stream' ) client = RestClient.post( @endpoints[:facelist]+"#{face_list_id}/persistedFaces", face, headers ) Response.new(client).get end |
#create_face_list(face_list_id:, name:, user_data: nil) ⇒ Object
Create face list
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cognitive/face/client.rb', line 94 def create_face_list(face_list_id:,name:,user_data: nil) params = { name: name, userData: user_data }.to_json client = RestClient.put( @endpoints[:facelist]+face_list_id.to_s, params, @headers ) Response.new( client, json: false, response_custom: lambda {|client| client.code == 200} ).get end |
#delete_face_list(face_list_id:) ⇒ Object
Delete face list Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524f
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cognitive/face/client.rb', line 65 def delete_face_list(face_list_id:) client = RestClient.delete( @endpoints[:facelist] + face_list_id.to_s, @headers ) Response.new( client, json: false, response_custom: lambda {|client| client.code == 200} ).get end |
#delete_face_to_face_list(face_id:, face_list_id:) ⇒ Object
Deleted face from a face list
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cognitive/face/client.rb', line 136 def delete_face_to_face_list(face_id:, face_list_id:) client = RestClient.delete( @endpoints[:facelist]+"#{face_list_id}/persistedFaces/#{face_id}", @headers ) Response.new( client, json: false, response_custom: lambda {|client| client.code == 200} ).get end |
#detect(face:, return_face_id: true, returnFaceLandmarks: false, returnFaceAttributes: nil) ⇒ Object
Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cognitive/face/client.rb', line 28 def detect(face:,return_face_id: true, returnFaceLandmarks:false, returnFaceAttributes: nil) query_params = { returnFaceId: return_face_id, returnFaceLandmarks: returnFaceLandmarks } headers = @headers.merge( params: query_params, 'Content-Type': 'application/octet-stream' ) client = RestClient.post( @endpoints[:detect], face, headers ) Response.new(client).get end |
#find_similar(face_id:, face_list_id:, mode: 'matchPerson') ⇒ Object
Find face from a face list
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/cognitive/face/client.rb', line 153 def find_similar(face_id:, face_list_id:, mode: 'matchPerson') data = { faceId: face_id, faceListId: face_list_id, mode: mode } client = RestClient.post( @endpoints[:findsimilar], data.to_json, @headers ) Response.new(client).get end |
#get_face_list(face_list_id:) ⇒ Object
Get information a face list id Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c
53 54 55 56 57 58 59 |
# File 'lib/cognitive/face/client.rb', line 53 def get_face_list(face_list_id:) client = RestClient.get( @endpoints[:facelist] + face_list_id.to_s, @headers ) Response.new(client).get end |
#get_face_lists ⇒ Object
Get all face lists Api rest documentation dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c
81 82 83 84 85 86 87 |
# File 'lib/cognitive/face/client.rb', line 81 def get_face_lists client = RestClient.get( @endpoints[:facelist], @headers ) Response.new(client).get end |