1

I am currently trying to make a chroma key effect with a video. It's partially work, meaning: only a few pixels are made transparant. But I need make the other pixels that are in the same color range, or color neighborhood, transparent.

The code below is the one that is being called using requestAnimationFrame.

Any help would be appreciated!

computeFrame() {
    this.c_frame_context.drawImage(
        this.video,
        0,
        0,
        this.c_frame.width,
        this.c_frame.height,
    );
    let frame = this.c_frame_context.getImageData(
        0,
        0,
        this.c_frame.width,
        this.c_frame.height,
    );
    let l = frame.data.length / 4;

    for (let i = 0; i < l; i++) {
        let r = frame.data[i * 4 + 0];
        let g = frame.data[i * 4 + 1];
        let b = frame.data[i * 4 + 2];
        if (r > 180 && g > 194 && b < 189) frame.data[i * 4 + 3] = 0;
    }
    this.c_processed_context.putImageData(frame, 0, 0);
    return;
}

0 Answers0