| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.shape_detection; | 5 package org.chromium.shape_detection; |
| 6 | 6 |
| 7 import android.graphics.PointF; | 7 import android.graphics.PointF; |
| 8 import android.util.SparseArray; | 8 import android.util.SparseArray; |
| 9 | 9 |
| 10 import com.google.android.gms.vision.Frame; | 10 import com.google.android.gms.vision.Frame; |
| 11 import com.google.android.gms.vision.face.Face; | 11 import com.google.android.gms.vision.face.Face; |
| 12 import com.google.android.gms.vision.face.FaceDetector; | 12 import com.google.android.gms.vision.face.FaceDetector; |
| 13 import com.google.android.gms.vision.face.Landmark; | 13 import com.google.android.gms.vision.face.Landmark; |
| 14 | 14 |
| 15 import org.chromium.base.ContextUtils; | 15 import org.chromium.base.ContextUtils; |
| 16 import org.chromium.base.Log; | 16 import org.chromium.base.Log; |
| 17 import org.chromium.gfx.mojom.RectF; | 17 import org.chromium.gfx.mojom.RectF; |
| 18 import org.chromium.mojo.system.MojoException; | 18 import org.chromium.mojo.system.MojoException; |
| 19 import org.chromium.mojo.system.SharedBufferHandle; | |
| 20 import org.chromium.shape_detection.mojom.FaceDetection; | 19 import org.chromium.shape_detection.mojom.FaceDetection; |
| 21 import org.chromium.shape_detection.mojom.FaceDetectionResult; | 20 import org.chromium.shape_detection.mojom.FaceDetectionResult; |
| 22 import org.chromium.shape_detection.mojom.FaceDetectorOptions; | 21 import org.chromium.shape_detection.mojom.FaceDetectorOptions; |
| 23 import org.chromium.shape_detection.mojom.LandmarkType; | 22 import org.chromium.shape_detection.mojom.LandmarkType; |
| 24 | 23 |
| 25 import java.util.ArrayList; | 24 import java.util.ArrayList; |
| 26 import java.util.List; | 25 import java.util.List; |
| 27 | 26 |
| 28 /** | 27 /** |
| 29 * Google Play services implementation of the FaceDetection service defined in | 28 * Google Play services implementation of the FaceDetection service defined in |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 } | 49 } |
| 51 } catch (IllegalArgumentException e) { | 50 } catch (IllegalArgumentException e) { |
| 52 Log.e(TAG, "Unexpected exception " + e); | 51 Log.e(TAG, "Unexpected exception " + e); |
| 53 assert false; | 52 assert false; |
| 54 } | 53 } |
| 55 | 54 |
| 56 mFaceDetector = builder.build(); | 55 mFaceDetector = builder.build(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 @Override | 58 @Override |
| 60 public void detect( | 59 public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse
callback) { |
| 61 SharedBufferHandle frameData, int width, int height, DetectResponse
callback) { | |
| 62 // The vision library will be downloaded the first time the API is used | 60 // The vision library will be downloaded the first time the API is used |
| 63 // on the device; this happens "fast", but it might have not completed, | 61 // on the device; this happens "fast", but it might have not completed, |
| 64 // bail in this case. | 62 // bail in this case. |
| 65 if (!mFaceDetector.isOperational()) { | 63 if (!mFaceDetector.isOperational()) { |
| 66 Log.e(TAG, "FaceDetector is not operational"); | 64 Log.e(TAG, "FaceDetector is not operational"); |
| 67 | 65 |
| 68 // Fallback to Android's FaceDetectionImpl. | 66 // Fallback to Android's FaceDetectionImpl. |
| 69 FaceDetectorOptions options = new FaceDetectorOptions(); | 67 FaceDetectorOptions options = new FaceDetectorOptions(); |
| 70 options.fastMode = mFastMode; | 68 options.fastMode = mFastMode; |
| 71 options.maxDetectedFaces = mMaxFaces; | 69 options.maxDetectedFaces = mMaxFaces; |
| 72 FaceDetectionImpl detector = new FaceDetectionImpl(options); | 70 FaceDetectionImpl detector = new FaceDetectionImpl(options); |
| 73 detector.detect(frameData, width, height, callback); | 71 detector.detect(bitmapData, callback); |
| 74 return; | 72 return; |
| 75 } | 73 } |
| 76 | 74 |
| 77 Frame frame = SharedBufferUtils.convertToFrame(frameData, width, height)
; | 75 Frame frame = BitmapUtils.convertToFrame(bitmapData); |
| 78 if (frame == null) { | 76 if (frame == null) { |
| 79 Log.e(TAG, "Error converting SharedMemory to Frame"); | 77 Log.e(TAG, "Error converting SharedMemory to Frame"); |
| 80 callback.call(new FaceDetectionResult[0]); | 78 callback.call(new FaceDetectionResult[0]); |
| 81 return; | 79 return; |
| 82 } | 80 } |
| 83 | 81 |
| 84 final SparseArray<Face> faces = mFaceDetector.detect(frame); | 82 final SparseArray<Face> faces = mFaceDetector.detect(frame); |
| 85 | 83 |
| 86 FaceDetectionResult[] faceArray = new FaceDetectionResult[faces.size()]; | 84 FaceDetectionResult[] faceArray = new FaceDetectionResult[faces.size()]; |
| 87 for (int i = 0; i < faces.size(); i++) { | 85 for (int i = 0; i < faces.size(); i++) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 @Override | 121 @Override |
| 124 public void close() { | 122 public void close() { |
| 125 mFaceDetector.release(); | 123 mFaceDetector.release(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 @Override | 126 @Override |
| 129 public void onConnectionError(MojoException e) { | 127 public void onConnectionError(MojoException e) { |
| 130 close(); | 128 close(); |
| 131 } | 129 } |
| 132 } | 130 } |
| OLD | NEW |