| OLD | NEW |
| 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/imagecapture/Point2D.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Vector<shape_detection::mojom::blink::FaceDetectionResultPtr> | 58 Vector<shape_detection::mojom::blink::FaceDetectionResultPtr> |
| 59 face_detection_results) { | 59 face_detection_results) { |
| 60 DCHECK(face_service_requests_.Contains(resolver)); | 60 DCHECK(face_service_requests_.Contains(resolver)); |
| 61 face_service_requests_.erase(resolver); | 61 face_service_requests_.erase(resolver); |
| 62 | 62 |
| 63 HeapVector<Member<DetectedFace>> detected_faces; | 63 HeapVector<Member<DetectedFace>> detected_faces; |
| 64 for (const auto& face : face_detection_results) { | 64 for (const auto& face : face_detection_results) { |
| 65 HeapVector<Landmark> landmarks; | 65 HeapVector<Landmark> landmarks; |
| 66 for (const auto& landmark : face->landmarks) { | 66 for (const auto& landmark : face->landmarks) { |
| 67 Point2D location; | 67 Point2D location; |
| 68 location.setX(landmark->location->x); | 68 location.setX(landmark->location.x); |
| 69 location.setY(landmark->location->y); | 69 location.setY(landmark->location.y); |
| 70 Landmark web_landmark; | 70 Landmark web_landmark; |
| 71 web_landmark.setLocation(location); | 71 web_landmark.setLocation(location); |
| 72 if (landmark->type == shape_detection::mojom::blink::LandmarkType::EYE) { | 72 if (landmark->type == shape_detection::mojom::blink::LandmarkType::EYE) { |
| 73 web_landmark.setType("eye"); | 73 web_landmark.setType("eye"); |
| 74 } else if (landmark->type == | 74 } else if (landmark->type == |
| 75 shape_detection::mojom::blink::LandmarkType::MOUTH) { | 75 shape_detection::mojom::blink::LandmarkType::MOUTH) { |
| 76 web_landmark.setType("mouth"); | 76 web_landmark.setType("mouth"); |
| 77 } | 77 } |
| 78 landmarks.push_back(web_landmark); | 78 landmarks.push_back(web_landmark); |
| 79 } | 79 } |
| 80 | 80 |
| 81 detected_faces.push_back(DetectedFace::Create( | 81 detected_faces.push_back(DetectedFace::Create( |
| 82 DOMRect::Create(face->bounding_box->x, face->bounding_box->y, | 82 DOMRect::Create(face->bounding_box.x, face->bounding_box.y, |
| 83 face->bounding_box->width, face->bounding_box->height), | 83 face->bounding_box.width, face->bounding_box.height), |
| 84 landmarks)); | 84 landmarks)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 resolver->Resolve(detected_faces); | 87 resolver->Resolve(detected_faces); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void FaceDetector::OnFaceServiceConnectionError() { | 90 void FaceDetector::OnFaceServiceConnectionError() { |
| 91 for (const auto& request : face_service_requests_) { | 91 for (const auto& request : face_service_requests_) { |
| 92 request->Reject(DOMException::Create(kNotSupportedError, | 92 request->Reject(DOMException::Create(kNotSupportedError, |
| 93 "Face Detection not implemented.")); | 93 "Face Detection not implemented.")); |
| 94 } | 94 } |
| 95 face_service_requests_.clear(); | 95 face_service_requests_.clear(); |
| 96 face_service_.reset(); | 96 face_service_.reset(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 DEFINE_TRACE(FaceDetector) { | 99 DEFINE_TRACE(FaceDetector) { |
| 100 ShapeDetector::Trace(visitor); | 100 ShapeDetector::Trace(visitor); |
| 101 visitor->Trace(face_service_requests_); | 101 visitor->Trace(face_service_requests_); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace blink | 104 } // namespace blink |
| OLD | NEW |