javascript - 使用 tensorflow-js 在网络摄像头上进行对象检测
问题描述
我正在尝试在网络摄像头流上使用 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 没有生成预测;我在这里做错了吗?
解决方案
推荐阅读
- javascript - 当部分在页面上处于活动状态时突出显示目录中的项目作为滚动
- javascript - 使用可变输入动态绘制/旋转 SVG
- java - setFragment 不能应用于其他片段
- .htaccess - 301 重定向/htaccess
- flutter - 同一个小部件上的英雄动画 -> 重建不跟随
- vue.js - 将 Vuex getter 与本地存储一起使用时如何刷新它?
- arrays - GoogleSheet,Hot 减去一个数组,每个单元格与最后一个?
- python - 以特定数字作为参数的奇怪 Python Pandas read_sql_query() 行为
- python - 如何隐藏我正在使用机器人的事实?
- spring - 在 kotlin 中转换为未知类型时杰克逊 IntelliJ 错误