Question

I have a program what detects a ball in a 320x240 stream runtime, but if I stream bigger resolution, it gets too slow. I'm assuming if I could use the GPU to calculate each pixels (with their neighbor frames, and neigbor pixels) it would be faster. Anyone knows if I can get data BACK from the GPU with AGAL?

in sort, I have the loop below, what goes through each pixel of the frame, and I want to calculate the most on GPU, to achive better performance.

for(var i:int=cv.length-1; i>1;i--){
                if( (110*255) < (cv[i] & 0x0000FF00) && (cv[i] & 0x0000FF00) < (150*255)){ //i zöld
                    if(  (cv[i+2] & 0x0000FF00) > (150*255) ) { //i+2 világos
                        if(floodhere(cv, i+2)){ //méret nagy
                            prevDiff[i]=0xffffffff; //fehér
                            close.push(i);
                        }
                        else prevDiff[i]=0xffff0000 //méret kicsi -> piros
                    } else {
                        prevDiff[i]=0xff000055 //kék
                    }
                } else {
                    prevDiff[i]=0xff000000 //fekete
                }
            }
Was it helpful?

Solution 2

You may be able to use PixelBender. It also works in separate thread(s) and makes use of multicore CPUs so is much quicker than actionscript.

See http://www.flashmagazine.com/tutorials/detail/using_pixel_bender_to_calculate_information/ for an example

OTHER TIPS

You can use AGAL to make fast calculations on the GPU, just be aware of the limits. It goes roughly like this:
You need to upload you data as as textures (a n*m matrices), one datapoint is a 3x8 bit value. Uploading any kind of big data to the GPU is slow, thus you should not do it in every frame. Getting the texture back to Actionscript is slow too.
You can upload data to the GPU to its global variable memory (but only a limited amount)

The GPU will run your AGAL program parallel on every element on this matrix, and the output will be an n*m matrix too.
Every program instance has access to 3 things: Its coordinates, the global variables, and the uploaded matrices. The output of your program will be written to an output matrix to the same position. If you write multiple programs, the can access this output matrix quickly, but getting it back to the normal memory (for actionscript manipulation) is slow.

AGAL programs are very limited compared to Actionscript:
- max. 256 instructions.
- no loops, functions, classes. You only have mathematical operators and conditionals ("if-else").
- cannot write to the global memory

No way to get data back. You can only get color back. Moreover, to get pixel color in actionscript you should copy data from texture to bitmapdata wich is VEEEERY slow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top