clmtrackr icon indicating copy to clipboard operation
clmtrackr copied to clipboard

Issue capture a screenshot of a mask rendered take a snapshot.

Open eduhpxavier opened this issue 6 years ago • 1 comments

Hi, i was trying take a shot using this code in https://www.auduno.com/clmtrackr/examples/face_mask.html but the screen show only WebCan without mask, could you helpme?¿

CODE:

    var videoId = 'videoel';  <--
    var scaleFactor = 1;
    var snapshots = [];

    /**
     * Captures a image frame from the provided video element.
     *
     * @param {Video} video HTML5 video element from where the image frame will be captured.
     * @param {Number} scaleFactor Factor to scale the canvas element that will be return. This is an optional parameter.
     *
     * @return {Canvas}
     */
    function capture(video, scaleFactor) {
        if (scaleFactor == null) {
            scaleFactor = 1;
        }
        var w = video.videoWidth * scaleFactor;
        var h = video.videoHeight * scaleFactor;
        var canvas = document.createElement('canvas');
        canvas.width = w;
        canvas.height = h;
        var ctx = canvas.getContext('2d');
        ctx.drawImage(video, 0, 0, w, h);
        return canvas;
    }

    /**
     * Invokes the <code>capture</code> function and attaches the canvas element to the DOM.
     */
    function shoot() {

        html2canvas(document.querySelector("#capture")).then(canvasr => {
            document.body.appendChild(canvasr)
        });

        var video = document.getElementById(videoId);
        var output = document.getElementById('output');
        var canvas = capture(video, scaleFactor);

        canvas.onclick = function () {
            window.open(this.toDataURL());
        };
        snapshots.unshift(canvas);
        output.innerHTML = '';
        for (var i = 0; i < 4; i++) {
            output.appendChild(snapshots[i]);
        }
    }

eduhpxavier avatar Oct 29 '18 19:10 eduhpxavier

The answer lies in lines 109 & 110 https://github.com/auduno/clmtrackr/blob/ebe5264b5152cb5a814081314706ef97fcd28df7/examples/face_mask.html#L109 There are 2 canvases (is that the correct plural???) that are lying over the video tag. So you would need to merge the video with the overlay canvas. This should work by drawing the content of the canvas with the ID 'webgl' (Line 110) in your newly formed canvas element.

I hope this helps.

donut87 avatar Oct 29 '18 20:10 donut87