首页 > 解决方案 > 检测特定对象的库

问题描述

过去几天我一直在谷歌上搜索,有趣的是有一个库可以使用JavaScript. 这是链接:

GitHub 项目

它被称为ml5.js,它建立在TensorFlow. 它使用我试图熟悉的机器学习算法。我试图从这里使用他们的一个库:

示例项目

然后输入ObjectDetector_COCOSSD_single_image并要求从这里下载。我已经下载了它并使用带有VS Code的本地服务器运行它。这个代码片段虽然帮助了我很多:

let objectDetector;

let img;
let objects = [];
let status;

function preload(){
  img = loadImage('images/cat.jpg');
}


function setup() {
  createCanvas(640, 420);

  objectDetector = ml5.objectDetector('cocossd', modelReady);

}

//Change the status when the model loads.
function modelReady() {
  console.log("model Ready!")
  status = true;
  console.log('Detecting') 
  objectDetector.detect(img, gotResult);
}

//A function to run when we get any errors and the results
function gotResult(err, results) {
  if (err) {
    console.log(err);
  }
  console.log(results)
  objects = results;
}


function draw() {
  //Unless the model is loaded, do not draw anything to canvas
  if (status != undefined) {
    image(img, 0, 0)

    for (let i = 0; i < objects.length; i++) {
      noStroke();
      fill(0, 255, 0);
      text(objects[i].label + " " + nfc(objects[i].confidence * 100.0, 2) + "%", objects[i].x + 5, objects[i].y + 15);
      noFill();
      strokeWeight(4);
      stroke(0, 255, 0);
      rect(objects[i].x, objects[i].y, objects[i].width, objects[i].height);
    }
  }
}

在浏览器的控制台日志中,我检查了一下,它向这个 api 发送了一个请求 - Model in json

我相信这是一个jSon文件和训练模型。虽然它无法正确检测所有对象,就像它检测乌龟为鸟,收据为书一样。就目前而言,是否有任何模型可以用于该库或使其更准确地检测对象?

注意:我的计划是检测来自 POS 的特定纸质收据,我不确定是否可以修改上述代码以使其按预期工作,尽管试图弄清楚。任何有想法或在图书馆工作的人都可以分享他们的意见,所以我可以继续。

标签: javascripttensorflowmachine-learningml5

解决方案


推荐阅读