我正在尝试使用tensorflow-js在网络摄像头流上进行对象检测
下面是我的代码:
let model;
var modelPromise = new Promise(function(resolve, reject) {
// Load the model.
model = cocoSsd.load();
$(".progress-bar").hide();
if (model) {
resolve("model loaded!");
}
else {
reject(Error("problem loading model"));
}
});
const video = document.querySelector("#vid");
var camPromise = new Promise(function(resolve, reject) {
if('mediaDevices' in navigator && 'getUserMedia' in navigator.mediaDevices){
navigator.mediaDevices.getUserMedia({ audio: false, video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err){
alert(JSON.stringify(error));
});
}
});
// create function to detect objects in the image
const detection = (vid, mod) => {
console.log("hi");
mod.detect(vid).then(predictions => {
//drawBBox(predictions); --> write function for this!
console.log(predictions);
});
requestAnimationFrame(() => detection(vid, mod));
};
Promise.all([modelPromise, camPromise])
.then(values => detection(video, model))
.catch(error => console.error(error));
已生成并显示网络摄像头流,但cocoSsd并未生成任何预测;我在这里做错什么了吗?