Commit f1f5959f authored by mcasas's avatar mcasas Committed by Commit bot

Face Detection: Use DetectedFace in FaceDetector.cpp iso DOMRect

FaceDetector.detect() in ToT returns a sequence<DetectedObject>,
but DetectedObject doesn't exist, and it should return DetectedFace
instead according to the Spec. Also, DetectedFace is not used at the
moment (FaceDetector  goes around this issue by returning DOMRects
directly).

This CL sorts that out by returning DetectedFaces directly.

BUG=673075

Review-Url: https://codereview.chromium.org/2564123003
Cr-Commit-Position: refs/heads/master@{#437794}
parent 3268c758
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
var detector = new FaceDetector(); var detector = new FaceDetector();
var results = ""; var results = "";
detector.detect(img) detector.detect(img)
.then(boundingBoxes => { .then(detectedFaces => {
for (var i=0; i<boundingBoxes.length; i++) { for (var i = 0; i < detectedFaces.length; i++) {
var boundingBox = boundingBoxes[i]; var boundingBox = detectedFaces[i].boundingBox;
var result = boundingBox.x + "," + boundingBox.y + "," + var result = boundingBox.x + "," + boundingBox.y + "," +
boundingBox.width + "," + boundingBox.height; boundingBox.width + "," + boundingBox.height;
results += result + "#"; results += result + "#";
......
...@@ -27,7 +27,7 @@ class MODULES_EXPORT DetectedBarcode final ...@@ -27,7 +27,7 @@ class MODULES_EXPORT DetectedBarcode final
DECLARE_TRACE(); DECLARE_TRACE();
private: private:
DetectedBarcode(String rawValue, DOMRect* boundingBox); DetectedBarcode(String, DOMRect*);
const String m_rawValue; const String m_rawValue;
const Member<DOMRect> m_boundingBox; const Member<DOMRect> m_boundingBox;
......
...@@ -9,13 +9,19 @@ ...@@ -9,13 +9,19 @@
namespace blink { namespace blink {
DetectedFace* DetectedFace::create() { DetectedFace* DetectedFace::create() {
return new DetectedFace(); return new DetectedFace(DOMRect::create());
}
DetectedFace* DetectedFace::create(DOMRect* boundingBox) {
return new DetectedFace(boundingBox);
} }
DOMRect* DetectedFace::boundingBox() const { DOMRect* DetectedFace::boundingBox() const {
return m_boundingBox.get(); return m_boundingBox.get();
} }
DetectedFace::DetectedFace(DOMRect* boundingBox) : m_boundingBox(boundingBox) {}
DEFINE_TRACE(DetectedFace) { DEFINE_TRACE(DetectedFace) {
visitor->trace(m_boundingBox); visitor->trace(m_boundingBox);
} }
......
...@@ -18,10 +18,14 @@ class MODULES_EXPORT DetectedFace final : public GarbageCollected<DetectedFace>, ...@@ -18,10 +18,14 @@ class MODULES_EXPORT DetectedFace final : public GarbageCollected<DetectedFace>,
public: public:
static DetectedFace* create(); static DetectedFace* create();
static DetectedFace* create(DOMRect*);
DOMRect* boundingBox() const; DOMRect* boundingBox() const;
DECLARE_TRACE(); DECLARE_TRACE();
private: private:
explicit DetectedFace(DOMRect*);
Member<DOMRect> m_boundingBox; Member<DOMRect> m_boundingBox;
}; };
......
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
Constructor, Constructor,
RuntimeEnabled=ShapeDetection, RuntimeEnabled=ShapeDetection,
] interface DetectedFace { ] interface DetectedFace {
// TODO(xianglu): Implement missing fields. https://crbug.com/646083 // TODO(xianglu): Implement any other fields. https://crbug.com/646083
readonly attribute DOMRect boundingBox; readonly attribute DOMRect boundingBox;
}; };
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "core/frame/LocalDOMWindow.h" #include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/html/canvas/CanvasImageSource.h" #include "core/html/canvas/CanvasImageSource.h"
#include "modules/shapedetection/DetectedFace.h"
#include "public/platform/InterfaceProvider.h" #include "public/platform/InterfaceProvider.h"
namespace blink { namespace blink {
...@@ -55,11 +56,11 @@ void FaceDetector::onDetectFaces( ...@@ -55,11 +56,11 @@ void FaceDetector::onDetectFaces(
DCHECK(m_faceServiceRequests.contains(resolver)); DCHECK(m_faceServiceRequests.contains(resolver));
m_faceServiceRequests.remove(resolver); m_faceServiceRequests.remove(resolver);
HeapVector<Member<DOMRect>> detectedFaces; HeapVector<Member<DetectedFace>> detectedFaces;
for (const auto& boundingBox : faceDetectionResult->bounding_boxes) { for (const auto& boundingBox : faceDetectionResult->bounding_boxes) {
detectedFaces.append(DOMRect::create(boundingBox->x, boundingBox->y, detectedFaces.append(DetectedFace::create(
boundingBox->width, DOMRect::create(boundingBox->x, boundingBox->y, boundingBox->width,
boundingBox->height)); boundingBox->height)));
} }
resolver->resolve(detectedFaces); resolver->resolve(detectedFaces);
......
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
Exposed=(Window,Worker), Exposed=(Window,Worker),
RuntimeEnabled=ShapeDetection, RuntimeEnabled=ShapeDetection,
] interface FaceDetector { ] interface FaceDetector {
[CallWith=ScriptState, Measure] Promise<sequence<DetectedObject>> detect(CanvasImageSource image); [CallWith=ScriptState, Measure] Promise<sequence<DetectedFace>> detect(CanvasImageSource image);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment