2017-06-12 62 views
0

我玩形状检测API(https://github.com/WICG/shape-detection-api),在此基础上的例子:https://wicg.github.io/shape-detection-api/#examples形状检测API:“抛出:DOMException:源会玷污血统”

我试图让最简单的工作:

let faceDetector = new FaceDetector({fastMode: true, maxDetectedFaces: 1}); 
// Assuming |theImage| is e.g. a <img> content, or a Blob. 

faceDetector.detect(theImage) 
.then(detectedFaces => { 
    for (const face of detectedFaces) { 
    console.log(' Face @ (${face.boundingBox.x}, ${face.boundingBox.y}),' + 
    ' size ${face.boundingBox.width}x${face.boundingBox.height}'); 
    } 
}).catch(() => { 
    console.error("Face Detection failed, boo."); 
}) 

然而,我正在错误:

VM153:1 Uncaught (in promise) DOMException: Source would taint origin. 

与我使用图像变量是来自计算器图像中的一个:

<img src="https://www.gravatar.com/avatar/619aaf27f793d8ffdbc879c74884c0cc?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32" id="testimg"> 

我的浏览器是Google Chrome Canary 61.0.3128.0,启用了实验性Web功能。

我错过了什么吗?

回答

0

我想这个问题是图像的源产地应该是一样的,你是要去执行脚本

0

答案的位置在这里: https://wicg.github.io/shape-detection-api/#image-sources-for-detection

"If any ImageBitmapSource have an effective script origin (HTML Standard §concept-origin) which is not the same as the Document’s effective script origin, then reject the Promise with a new DOMException whose name is SecurityError."

不要错过包你的代码,如果你是通过HTML标签加载使用图像

window.onload =() => { 
    // TODO: put you code here 
}; 

或通过图像构造

let image = new Image(); 
image.src = 'faces.jpg' 
image.onload =() => { 
    // TODO: put your code here 
} 

Code example