Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp

Issue 2859413002: Shape Detection: add idl and mojom for face landmarks and wire for Mac (Closed)
Patch Set: service-worker's global-interface-listing-expected.txt updated Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/shapedetection/FaceDetector.h" 5 #include "modules/shapedetection/FaceDetector.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/geometry/DOMRect.h" 8 #include "core/geometry/DOMRect.h"
9 #include "core/html/canvas/CanvasImageSource.h" 9 #include "core/html/canvas/CanvasImageSource.h"
10 #include "modules/imagecapture/Point2D.h"
10 #include "modules/shapedetection/DetectedFace.h" 11 #include "modules/shapedetection/DetectedFace.h"
11 #include "modules/shapedetection/FaceDetectorOptions.h" 12 #include "modules/shapedetection/FaceDetectorOptions.h"
13 #include "modules/shapedetection/Landmark.h"
12 #include "public/platform/InterfaceProvider.h" 14 #include "public/platform/InterfaceProvider.h"
13 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
14 #include "services/shape_detection/public/interfaces/facedetection_provider.mojo m-blink.h" 16 #include "services/shape_detection/public/interfaces/facedetection_provider.mojo m-blink.h"
15 17
16 namespace blink { 18 namespace blink {
17 19
18 FaceDetector* FaceDetector::Create(const FaceDetectorOptions& options) { 20 FaceDetector* FaceDetector::Create(const FaceDetectorOptions& options) {
19 return new FaceDetector(options); 21 return new FaceDetector(options);
20 } 22 }
21 23
(...skipping 28 matching lines...) Expand all
50 face_service_->Detect(std::move(shared_buffer_handle), image_width, 52 face_service_->Detect(std::move(shared_buffer_handle), image_width,
51 image_height, 53 image_height,
52 ConvertToBaseCallback(WTF::Bind( 54 ConvertToBaseCallback(WTF::Bind(
53 &FaceDetector::OnDetectFaces, WrapPersistent(this), 55 &FaceDetector::OnDetectFaces, WrapPersistent(this),
54 WrapPersistent(resolver)))); 56 WrapPersistent(resolver))));
55 return promise; 57 return promise;
56 } 58 }
57 59
58 void FaceDetector::OnDetectFaces( 60 void FaceDetector::OnDetectFaces(
59 ScriptPromiseResolver* resolver, 61 ScriptPromiseResolver* resolver,
60 shape_detection::mojom::blink::FaceDetectionResultPtr 62 Vector<shape_detection::mojom::blink::FaceDetectionResultPtr>
61 face_detection_result) { 63 face_detection_results) {
62 DCHECK(face_service_requests_.Contains(resolver)); 64 DCHECK(face_service_requests_.Contains(resolver));
63 face_service_requests_.erase(resolver); 65 face_service_requests_.erase(resolver);
64 66
65 HeapVector<Member<DetectedFace>> detected_faces; 67 HeapVector<Member<DetectedFace>> detected_faces;
66 for (const auto& bounding_box : face_detection_result->bounding_boxes) { 68 for (const auto& face : face_detection_results) {
69 HeapVector<Landmark> landmarks;
70 for (const auto& landmark : face->landmarks) {
71 Point2D location;
72 location.setX(landmark->location->x);
73 location.setY(landmark->location->y);
74 Landmark web_landmark;
75 web_landmark.setLocation(location);
76 if (landmark->type == shape_detection::mojom::blink::LandmarkType::EYE) {
77 web_landmark.setType("eye");
78 } else if (landmark->type ==
79 shape_detection::mojom::blink::LandmarkType::MOUTH) {
80 web_landmark.setType("mouth");
81 }
82 landmarks.push_back(web_landmark);
83 }
84
67 detected_faces.push_back(DetectedFace::Create( 85 detected_faces.push_back(DetectedFace::Create(
68 DOMRect::Create(bounding_box->x, bounding_box->y, bounding_box->width, 86 DOMRect::Create(face->bounding_box->x, face->bounding_box->y,
69 bounding_box->height))); 87 face->bounding_box->width, face->bounding_box->height),
88 landmarks));
70 } 89 }
71 90
72 resolver->Resolve(detected_faces); 91 resolver->Resolve(detected_faces);
73 } 92 }
74 93
75 void FaceDetector::OnFaceServiceConnectionError() { 94 void FaceDetector::OnFaceServiceConnectionError() {
76 for (const auto& request : face_service_requests_) { 95 for (const auto& request : face_service_requests_) {
77 request->Reject(DOMException::Create(kNotSupportedError, 96 request->Reject(DOMException::Create(kNotSupportedError,
78 "Face Detection not implemented.")); 97 "Face Detection not implemented."));
79 } 98 }
80 face_service_requests_.clear(); 99 face_service_requests_.clear();
81 face_service_.reset(); 100 face_service_.reset();
82 } 101 }
83 102
84 DEFINE_TRACE(FaceDetector) { 103 DEFINE_TRACE(FaceDetector) {
85 ShapeDetector::Trace(visitor); 104 ShapeDetector::Trace(visitor);
86 visitor->Trace(face_service_requests_); 105 visitor->Trace(face_service_requests_);
87 } 106 }
88 107
89 } // namespace blink 108 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698