diff --git a/vision/api/face_detection/requirements.txt b/vision/api/face_detection/requirements.txt deleted file mode 100644 index 965872d93b7..00000000000 --- a/vision/api/face_detection/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -google-api-python-client==1.6.2 -Pillow==4.0.0 diff --git a/vision/cloud-client/face_detection/.gitignore b/vision/cloud-client/face_detection/.gitignore new file mode 100644 index 00000000000..01f02dff9a7 --- /dev/null +++ b/vision/cloud-client/face_detection/.gitignore @@ -0,0 +1 @@ +out.jpg diff --git a/vision/api/face_detection/README.rst b/vision/cloud-client/face_detection/README.rst similarity index 100% rename from vision/api/face_detection/README.rst rename to vision/cloud-client/face_detection/README.rst diff --git a/vision/api/face_detection/README.rst.in b/vision/cloud-client/face_detection/README.rst.in similarity index 100% rename from vision/api/face_detection/README.rst.in rename to vision/cloud-client/face_detection/README.rst.in diff --git a/vision/api/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py similarity index 71% rename from vision/api/face_detection/faces.py rename to vision/cloud-client/face_detection/faces.py index 43d1e093988..6baef63c76b 100755 --- a/vision/api/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -14,20 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Draws squares around faces in the given image.""" +"""Draws squares around detected faces in the given image.""" import argparse -import base64 -import googleapiclient.discovery -from PIL import Image -from PIL import ImageDraw - - -# [START get_vision_service] -def get_vision_service(): - return googleapiclient.discovery.build('vision', 'v1') -# [END get_vision_service] +from google.cloud import vision +from PIL import Image, ImageDraw def detect_face(face_file, max_results=4): @@ -37,26 +29,14 @@ def detect_face(face_file, max_results=4): face_file: A file-like object containing an image with faces. Returns: - An array of dicts with information about the faces in the picture. + An array of Face objects with information about the picture. """ - image_content = face_file.read() - batch_request = [{ - 'image': { - 'content': base64.b64encode(image_content).decode('utf-8') - }, - 'features': [{ - 'type': 'FACE_DETECTION', - 'maxResults': max_results, - }] - }] - - service = get_vision_service() - request = service.images().annotate(body={ - 'requests': batch_request, - }) - response = request.execute() - - return response['responses'][0]['faceAnnotations'] + content = face_file.read() + # [START get_vision_service] + image = vision.Client().image(content=content) + # [END get_vision_service] + + return image.detect_faces() def highlight_faces(image, faces, output_filename): @@ -73,8 +53,8 @@ def highlight_faces(image, faces, output_filename): draw = ImageDraw.Draw(im) for face in faces: - box = [(v.get('x', 0.0), v.get('y', 0.0)) - for v in face['fdBoundingPoly']['vertices']] + box = [(bound.x_coordinate, bound.y_coordinate) + for bound in face.bounds.vertices] draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) diff --git a/vision/api/face_detection/faces_test.py b/vision/cloud-client/face_detection/faces_test.py similarity index 100% rename from vision/api/face_detection/faces_test.py rename to vision/cloud-client/face_detection/faces_test.py diff --git a/vision/cloud-client/face_detection/requirements.txt b/vision/cloud-client/face_detection/requirements.txt new file mode 100644 index 00000000000..7a5de2e03c8 --- /dev/null +++ b/vision/cloud-client/face_detection/requirements.txt @@ -0,0 +1,2 @@ +google-cloud-vision==0.23.3 +Pillow==4.0.0 diff --git a/vision/api/face_detection/resources/face-input.jpg b/vision/cloud-client/face_detection/resources/face-input.jpg similarity index 100% rename from vision/api/face_detection/resources/face-input.jpg rename to vision/cloud-client/face_detection/resources/face-input.jpg