YOLO对象识别更快,更一致

问题描述 投票:0回答:1

使用YOLOp5.js,我正在尝试使用网络摄像头识别对象。即使我已授予访问网络摄像头的权限,但仍然存在以下问题。有什么方法可以更快,更一致地改进对象识别?

  1. 一旦确定绿色矩形并没有持续粘住。我需要稍微移动一下以识别对象。
  2. 我将test.mp4视频保存在本地,如何在保存的视频上进行对象识别。

以下是我的代码:

let video; //Variable for video stream
let yolo;  //Initializing model method with YOLO.
let status; //Status check to determine whether the model has been loaded
let objects = []; //List of objects returned from YOLO

function setup() {
    createCanvas(800, 600); 
    video = createCapture(VIDEO); //Capturing live video from webcam
    video.size(400, 500);

    // Creating a YOLO method using ml5
    yolo = ml5.YOLO(video, startDetecting);

    // Hide the original video
    video.hide();
    status = select('#status');
}

function draw() {
    image(video, 0, 0, width, height); // Displaying image on a canvas
    for (let i = 0; i < objects.length; i++)  //Iterating through all objects
    {
        noStroke();
        fill(0, 255, 0); //Color of text
        text(objects[i].label, objects[i].x * width, objects[i].y * height - 5); //Displaying the label
        noFill();
        strokeWeight(4); 
        stroke(0, 255, 0); // Define rectangular outline here
        rect(objects[i].x * width, objects[i].y * height, objects[i].w * width, objects[i].h * height);
    }
}

function startDetecting() {
    status.html('Model loaded!'); //When the model is loaded
    detect(); //Calling detect method
}

function detect() {
    yolo.detect(function(err, results) {
        objects = results; //Storing results in object
        detect(); //Continuous detection
    });
}
javascript html p5.js yolo
1个回答
0
投票
  1. 一种可能的解决方案是不使用p5.js,而是使用getUserMedia()方法访问摄像机。这样,您可以将视频流镜像到图像元素并检测该图像元素。

  2. 对于保存的视频文件,您可以使用HTML Media Capture接受视频文件并将其放入HTML中:https://www.html5rocks.com/en/tutorials/getusermedia/intro/

完成后,您可以创建一个功能,当您按下播放按钮时,该功能可以进行检测。像这样。

var video = document.getElementById('video');

video.addEventListener('play', function() { // block of code }, 16);
© www.soinside.com 2019 - 2024. All rights reserved.