c# - Is it possible to use a shader to find the "difference" between two textures? (XNA/HLSL) -


I have created a simple webcam based application that detects "the edges of the speed", so draws a texture that Indicates where the pixels are different from the current frame is different from the previous frame. This is my code:

  // is a Texture2D of the last frame // current piece is a texture2D of the current frame // The difference is another texture2D // Variance is an int, the default is 100; Color [] difference data = new color [current cloth Mode * Current results. height]; Color [] currentData = new color [current cloth. Ritual * current mix. height]; Color [] lastData = new color [last cloth With * final cloth] high]; CurrentTexture.GetData & LT; Color & gt; (CurrentData); LastTexture.GetData & LT; Color & gt; (LastData); For (int i = 0; i & lt; current data langti; i ++) {int sumCD = ColorSum (current data [i]); // ColorSum C. R + C B + C G is similar to where there is a color. Int sumLD = ColorSum (final data [i]); If ((sumCD> NMD-NIdD) & amp; amp; and (sumCD & lt; sumLD + variance) difference data [i] = new color (0, 0, 0, 0); // If the current pixel is within the range of +/- variation (default: 100) variable, this has not changed significantly, so it is black Other difference data [i] = new color (0, (byte) monastery Abs (sumCD-sumLD), 0); // It has changed a lot so that the shade of green can be prepared. } Difference difference = New texture 2D (game1.GraphicsDevice, current piece. Witth, current piece. Highlight); DifferenceTexture.SetData & LT; Color & gt; (DifferenceData); Letteresure = New Texture 2D (Game 1. Graphics Device, Content Identity, Contritation. Height); LastTexture.SetData & LT; Color & gt; (CurrentData);  

Is this calculation a way to load the GPU using the shaders (it can go to 25/26 FPS using the above method, but this is a bit slow)? I have a basic understanding of how HLSL shaders work and do not expect a complete solution, I just want to know that this would be possible and how to get "difference" textual data from Shaad and it really does not get any faster Ho .

Thank you in advance.

Dual thread approach to your problem, from Microsoft See Net Parallel Extensions CTP.

If you are not planning to deploy an XBox360, then this library works well with XNA, and I've seen improvements in speed and speed in some loops and iterations.

You must change only a few line codes, for example:

 for  (int i = 0; i & lt; currentData.Length; i ++) will change to {// ...}  

:

  parallel.for (0, current data length, representative (intI) {// ...});  

In order to automatically create each core in your processor, help with number crunching. It's fast and excellent.

Good luck!


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -