画布在视频上叠加

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

所以我必须根据给定的坐标在视频上绘制多个矩形。问题是我必须每秒在不同的坐标上绘制它们,以清除它们的过去位置。

        function draw() {
            var time = $(".video-detect")[0].duration;
            var i = 0;
            for (let k = 0; k < time; k++) {// every second
                setTimeout(function () {
                    var objArray = [{}];
                    for (; i < facesObject.length; i++) {
                        var x = facesObject[i].Frame_idx[k].Coordinates[0],
                            y = facesObject[i].Frame_idx[k].Coordinates[1],
                            width = facesObject[i].Frame_idx[k].Coordinates[2] - facesObject[i].Frame_idx[k].Coordinates[0],
                            height = facesObject[i].Frame_idx[k].Coordinates[3] - facesObject[i].Frame_idx[k].Coordinates[1];


                 // and here I have to draw the rectangle 
                 // I don't know how to clear the previous rectangles

                      }
                    }
                    console.log(k);
                }, k * 1000);
            }
        }

javascript canvas video settimeout
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.