简体   繁体   English

使用SVG过滤器feMatrixColor的HTML页面中的Chromakey

[英]Chromakey in an HTML page using SVG filter feMatrixColor

I'm implementing a real-time chromakey in order to transform green pixels displayed from the webcam in the webpage, into transparent pixels. 我正在实现一个实时色度键,以便将网页中网络摄像头显示的绿色像素转换为透明像素。

The SVG filter that I found seems pretty powerful but it's still quite unclear for me about how to use it. 我发现的SVG过滤器似乎非常强大,但我仍然不清楚如何使用它。

The feMatrixColor filter from SVG: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix 来自SVG的feMatrixColor过滤器: https//developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix

I found this example https://codepen.io/iamschulz/pen/MmxdMQ that is close to what I'm trying to do. 我发现这个示例https://codepen.io/iamschulz/pen/MmxdMQ接近我正在尝试做的事情。

I have to calibrate the color when my application loads, and to do so I need to generate the matching color matrix. 我需要在应用程序加载时校准颜色,为此我需要生成匹配的颜色矩阵。

 <feColorMatrix type="matrix" 
   values="1   0   0   0   0 
           0   1   0   0   0  
           0   0   1   0   0 
           1.5 -2  1.5 0   1" />

Above is an example where the alpha is set to zero for a defined green color. 以上是对于定义的绿色将alpha设置为零的示例。 I don't use it as the perfect reference, but it works. 我不会将它作为完美的参考,但它的工作原理。 Furthermore, I noticed that the last column do a lot in the rendering and I didn't get what's it's role. 此外,我注意到最后一列在渲染中做了很多,我没有得到它的作用。 The quality of the final result varies a lot depending on this value. 最终结果的质量根据此值而变化很大。

I'd like to create a function which returns me a matrix with a picked color in the input but I don't understand the logic behind that matrix. 我想创建一个函数,它在输入中返回一个带有拾取颜色的矩阵,但我不理解该矩阵背后的逻辑。

This is an example where I'm using an svg filter to remove the green. 这是我使用svg过滤器去除绿色的示例。 I've used this tool (where you can drag and drop an image) to get the right filter: https://codepen.io/enxaneta/full/ENRZGO 我已经使用过这个工具(你可以拖放一个图像)来获得正确的过滤器: https//codepen.io/enxaneta/full/ENRZGO

 <svg viewBox="0 0 90 50"> <defs> <filter id="f"> <feColorMatrix in="SourceGraphic" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 1 -1 1 "></feColorMatrix> </filter> </defs> <g filter="url(#f)"> <rect fill="red" width="30" height="50" /> <rect fill="green" x="30" width="30" height="50" /> <rect fill="blue" x="60" width="30" height="50" /> </g> </svg> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM