2017-06-12 60 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