J'essaye d'obtenir un Pixel Shader HLSL pour Silverlight pour travailler afin de soustraire l'image d'arrière-plan d'une image vidéo. Quelqu'un peut-il suggérer un algorithme plus sophistiqué que celui que j'utilise parce que mon algorithme ne le fait pas correctement?HLSL Shader pour soustraire l'image d'arrière-plan
float Tolerance : register(C1);
SamplerState ImageSampler : register(S0);
SamplerState BackgroundSampler : register(S1);
struct VS_INPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 UV0 : TEXCOORD0;
float2 UV1 : TEXCOORD1;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Color : COLOR0;
float2 UV : TEXCOORD0;
};
float4 PS(VS_OUTPUT input) : SV_Target
{
float4 color = tex2D(ImageSampler, input.UV);
float4 background = tex2D(BackgroundSampler, input.UV);
if (abs(background.r - color.r) <= Tolerance &&
abs(background.g - color.g) <= Tolerance &&
abs(background.b - color.b) <= Tolerance)
{
color.rgba = 0;
}
return color;
}
Pour voir un exemple de cela, vous avez besoin d'un ordinateur avec une webcam:
- Aller à la page http://xmldocs.net/alphavideo/background.html
- Appuyez sur [Démarrer l'enregistrement].
- Sortez votre corps de la scène et appuyez sur [Fond d'écran de capture].
- Replacez ensuite votre corps dans la scène et utilisez le curseur pour ajuster la valeur Toleance au shader.
Pourriez-vous expliquer exactement comment "ne le fait pas correctement"? Et je dois dire que je suis surpris que votre shader fonctionne du tout. – Denis
Jetez un coup d'œil à cet exemple de soustraction d'arrière-plan adaptative en HLSL: http://vvvv.org/forum/adaptive-background-substraction – appas