I've been searching on google for the last few days and interesingly got a library to detect object using JavaScript. Here's the link:
It's called ml5.js and it's built on top of TensorFlow. It uses machine learning algorithm that I am trying to get familiar. I tried to use one of their library from here:
Then type ObjectDetector_COCOSSD_single_image and requires to download it from here. I already downloaded it and run it using local server with VS Code. This code snippet though helped me a lot:
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);
}
}
}
In the console log of the browser, I checked, it sent a request to this api - Model in jSon
It's a jSon file and the model to train, I believe. Though it's unable to detect all object properly like it detects turtle as bird, receipt as book. For the being, is there any model that I can make use of to this library or make it more accurate to detect object?
N.B: My plan is to detect paper specifically receipt from POS, I am not sure if I can modify the above code to make it work as expected though trying to figure out. Anyone has idea or worked on the library could share their opinion, so I can go ahead with it.