Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eduhpxavier opened this issue Oct 29, 2018 · 1 comment
Open

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

eduhpxavier opened this issue Oct 29, 2018 · 1 comment

Comments

@eduhpxavier
Copy link

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]);
        }
    }
@donut87
Copy link

donut87 commented Oct 29, 2018

The answer lies in lines 109 & 110

<canvas id="overlay" width="400" height="300"></canvas>

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants