Я работаю над предварительно обученной моделью Coco-SSD для обнаружения объектов. Я успешно обнаружил объекты на изображении, но теперь мне нужно подсчитать количество указанных c объектов, может кто-нибудь помочь
public async predictWithCocoModel()
{
const model = await cocoSSD.load();
this.detectFrame(this.video,model);
}
detectFrame = (video, model) => {
model.detect(video).then(predictions => {
this.renderPredictions(predictions);
requestAnimationFrame(() => {
this.detectFrame(video, model);});
});
}
renderPredictions = predictions => {
const canvas = <HTMLCanvasElement> document.getElementById ("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 300;
canvas.height = 300;
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// Fonts
const font = "16px sans-serif";
ctx.font = font;
ctx.textBaseline = "top";
ctx.drawImage(this.video,0, 0,300,300);
predictions.forEach(prediction => {
const x = prediction.bbox[0];
const y = prediction.bbox[1];
const width = prediction.bbox[2];
const height = prediction.bbox[3];
// Bounding box
ctx.strokeStyle = "#00FFFF";
ctx.lineWidth = 2;
ctx.strokeRect(x, y, width, height);
// Label background
ctx.fillStyle = "#00FFFF";
const textWidth = ctx.measureText(prediction.class).width;
const textHeight = parseInt(font, 10); // base 10
ctx.fillRect(x, y, textWidth + 4, textHeight + 4);
});
predictions.forEach(prediction => {
const x = prediction.bbox[0];
const y = prediction.bbox[1];
ctx.fillStyle = "#000000";
ctx.fillText(prediction.class, x, y);});
};
Это код, который я использую. Это показывает только прямоугольник на обнаруженном объекте, но мне нужно посчитать количество указанных c объектов и сохранить их в переменной для будущего использования, такой как person: 3