单击粉红色按钮后,我想将图像添加到我的分类器中。目前,它给出了一个标题为 CORS 的警告。我可能做错了什么?是因为我如何加载图像吗?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Getting Started with ml5.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- ml5 -->
<script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
</head>
;
<body>
<img src="./images/pink/1.png" class="pink1" alt="pink1">
<img src="./images/pink/2.png" class="pink2" alt="pink2">
<img src="./images/pink/3.png" class="pink3" alt="pink3">
</body>
<script>
let pinkButton
console.log('ml5 version:', ml5.version);
function mobileReady() {
console.log('mobileNet loaded');
}
function setup() {
mobileNet = ml5.featureExtractor('MobileNet')
classifier = mobileNet.classification()
pinkButton = createButton('add pink')
pinkButton.mousePressed(function(){
image1 = document.querySelector(".pink1")
image2 = document.querySelector(".pink2")
image3 = document.querySelector(".pink3")
classifier.addImage(image1, 'pink')
classifier.addImage(image2, 'pink')
classifier.addImage(image3, 'pink')
console.log('CLASSIFER', classifier)
})
}
</script>
</body>
</html>
编辑:尝试在 querySelector 之后添加它,但对我不起作用。
image1.crossOrigin = 'anonymous'
image2.crossOrigin = 'anonymous'
image3.crossOrigin = 'anonymous'