| 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 #include "services/shape_detection/face_detection_impl_mac.h" | 5 #include "services/shape_detection/face_detection_impl_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_cftyperef.h" | 7 #include "base/mac/scoped_cftyperef.h" |
| 8 #include "media/capture/video/scoped_result_callback.h" | 8 #include "media/capture/video/scoped_result_callback.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 10 #include "services/shape_detection/detection_utils_mac.h" | 10 #include "services/shape_detection/detection_utils_mac.h" |
| 11 #include "services/shape_detection/face_detection_provider_impl.h" | 11 #include "services/shape_detection/face_detection_provider_impl.h" |
| 12 | 12 |
| 13 namespace shape_detection { | 13 namespace shape_detection { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void RunCallbackWithFaces( | 17 void RunCallbackWithFaces( |
| 18 const shape_detection::mojom::FaceDetection::DetectCallback& callback, | 18 const shape_detection::mojom::FaceDetection::DetectCallback& callback, |
| 19 shape_detection::mojom::FaceDetectionResultPtr faces) { | 19 std::vector<shape_detection::mojom::FaceDetectionResultPtr> results) { |
| 20 callback.Run(std::move(faces)); | 20 callback.Run(std::move(results)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void RunCallbackWithNoFaces( | 23 void RunCallbackWithNoFaces( |
| 24 const shape_detection::mojom::FaceDetection::DetectCallback& callback) { | 24 const shape_detection::mojom::FaceDetection::DetectCallback& callback) { |
| 25 callback.Run(shape_detection::mojom::FaceDetectionResult::New()); | 25 callback.Run(std::vector<shape_detection::mojom::FaceDetectionResultPtr>()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // anonymous namespace | 28 } // anonymous namespace |
| 29 | 29 |
| 30 void FaceDetectionProviderImpl::CreateFaceDetection( | 30 void FaceDetectionProviderImpl::CreateFaceDetection( |
| 31 shape_detection::mojom::FaceDetectionRequest request, | 31 shape_detection::mojom::FaceDetectionRequest request, |
| 32 shape_detection::mojom::FaceDetectorOptionsPtr options) { | 32 shape_detection::mojom::FaceDetectorOptionsPtr options) { |
| 33 mojo::MakeStrongBinding( | 33 mojo::MakeStrongBinding( |
| 34 base::MakeUnique<FaceDetectionImplMac>(std::move(options)), | 34 base::MakeUnique<FaceDetectionImplMac>(std::move(options)), |
| 35 std::move(request)); | 35 std::move(request)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 base::Bind(&RunCallbackWithFaces, callback), | 55 base::Bind(&RunCallbackWithFaces, callback), |
| 56 base::Bind(&RunCallbackWithNoFaces)); | 56 base::Bind(&RunCallbackWithNoFaces)); |
| 57 | 57 |
| 58 base::scoped_nsobject<CIImage> ci_image = | 58 base::scoped_nsobject<CIImage> ci_image = |
| 59 CreateCIImageFromSharedMemory(std::move(frame_data), width, height); | 59 CreateCIImageFromSharedMemory(std::move(frame_data), width, height); |
| 60 if (!ci_image) | 60 if (!ci_image) |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 NSArray* const features = [detector_ featuresInImage:ci_image]; | 63 NSArray* const features = [detector_ featuresInImage:ci_image]; |
| 64 | 64 |
| 65 shape_detection::mojom::FaceDetectionResultPtr faces = | 65 std::vector<mojom::FaceDetectionResultPtr> results; |
| 66 shape_detection::mojom::FaceDetectionResult::New(); | |
| 67 for (CIFaceFeature* const f in features) { | 66 for (CIFaceFeature* const f in features) { |
| 68 // In the default Core Graphics coordinate space, the origin is located | 67 // In the default Core Graphics coordinate space, the origin is located |
| 69 // in the lower-left corner, and thus |ci_image| is flipped vertically. | 68 // in the lower-left corner, and thus |ci_image| is flipped vertically. |
| 70 // We need to adjust |y| coordinate of bounding box before sending it. | 69 // We need to adjust |y| coordinate of bounding box before sending it. |
| 71 gfx::RectF boundingbox(f.bounds.origin.x, | 70 gfx::RectF boundingbox(f.bounds.origin.x, |
| 72 height - f.bounds.origin.y - f.bounds.size.height, | 71 height - f.bounds.origin.y - f.bounds.size.height, |
| 73 f.bounds.size.width, f.bounds.size.height); | 72 f.bounds.size.width, f.bounds.size.height); |
| 74 faces->bounding_boxes.push_back(boundingbox); | 73 |
| 74 auto face = shape_detection::mojom::FaceDetectionResult::New(); |
| 75 face->bounding_box = std::move(boundingbox); |
| 76 |
| 77 if (f.hasLeftEyePosition) { |
| 78 auto landmark = shape_detection::mojom::Landmark::New(); |
| 79 landmark->type = shape_detection::mojom::LandmarkType::EYE; |
| 80 landmark->location = |
| 81 gfx::PointF(f.leftEyePosition.x, height - f.leftEyePosition.y); |
| 82 face->landmarks.push_back(std::move(landmark)); |
| 83 } |
| 84 if (f.hasRightEyePosition) { |
| 85 auto landmark = shape_detection::mojom::Landmark::New(); |
| 86 landmark->type = shape_detection::mojom::LandmarkType::EYE; |
| 87 landmark->location = |
| 88 gfx::PointF(f.rightEyePosition.x, height - f.rightEyePosition.y); |
| 89 face->landmarks.push_back(std::move(landmark)); |
| 90 } |
| 91 if (f.hasMouthPosition) { |
| 92 auto landmark = shape_detection::mojom::Landmark::New(); |
| 93 landmark->type = shape_detection::mojom::LandmarkType::MOUTH; |
| 94 landmark->location = |
| 95 gfx::PointF(f.mouthPosition.x, height - f.mouthPosition.y); |
| 96 face->landmarks.push_back(std::move(landmark)); |
| 97 } |
| 98 |
| 99 results.push_back(std::move(face)); |
| 75 } | 100 } |
| 76 scoped_callback.Run(std::move(faces)); | 101 scoped_callback.Run(std::move(results)); |
| 77 } | 102 } |
| 78 | 103 |
| 79 } // namespace shape_detection | 104 } // namespace shape_detection |
| OLD | NEW |