I am using GPUImage to process incoming video, and each frame I would like to determine the average luminosity of many rectangular subregions of the incoming image for hit detection purposes in a game, but I am having trouble doing so in a way that doesn't kill FPS.
My current situation is to loop through the hit boxes of interest, crop the frame of said hit boxes with GPUImageCropFilter, do average luminosity on the cropped region and in its completion block call hit method on main thread if luminosity is high enough. This works okay if there are just a few hit boxes, but for the project I am working on there could be dozens at a time which kills the FPS.
Are there any recommended ways to modify the above approach to improve performance? I am thinking it might be possible to accomplish this by making a new filter with a custom shader that does a kind of localized pixelation effect (pixellating the rectangles of interest, so then I can just check any pixel in that region for the luminosity), but I am not sure if it is possible to pass in an array of areas of interest like this to a filter / shader. Thanks.