0

I have:

Main GPUImage preview window GPUImage Histogram sitting on a separate GPUImageView.

//Adding main preview
self.previewView = [[GPUImageView alloc] init];
self.previewView.backgroundColor = [UIColor blackColor];
self.previewView.frame = CGRectMake(0, 0, 414, 552);

[self.view addSubview:self.previewView];
[self.stillCamera addTarget:self.previewView];

//Adding Histogram
self.histogramContainerView = [[GPUImageView alloc] init];
self.previewView.frame = CGRectMake(0, 0, 414, 200);
self.previewView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.histogramContainerView];

self.histFilter = [[GPUImageHistogramFilter alloc] initWithHistogramType:4];
sellf.histGenerator = [[GPUImageHistogramGenerator alloc] init];
[self.histGenerator forceProcessingAtSize:histogramContainerView.sizeInPixels];
[self.stillCamera addTarget:self.histFilter];
[self.histFilter addTarget:self.histGenerator];
[self.histGenerator addTarget:self.histogramContainerView];

Above shows the histogram in a small container inside the main preview window. Histogram looks fine.

Issue: Once the histogram comes on, the main preview window start dropping frames considerably. This is on a iP6+. When I asked about using multithreading (GCD) with GPUImage on here, I was advised to stay away from that.

How can I resolve the frame dropping issue? Is there is a way to safely dispatch the Histogram tasks to a different thread?

1 Answer 1

1

The GPUImageHistogramFilter operates using a scatter / gather operation on the GPU. All GPU-bound processing operations are already being run on a background thread, and need to have their activities coordinated, so thread-wise there isn't anything that can be done to improve this.

The histogram operation's speed is determined by how many points it has to process. The downsamplingFactor property causes only a fraction of the image to be processed. By default, this is 1/16th of the image, but even this can be overloaded by large images.

You can use a dummy filter before your histogram and set -forceProcessingAtSize: on it to rescale the image that goes into your histogram. This can significantly reduce the processing time for filters like the histogram filter.

Finally, I should note that if your stillCamera instance is a GPUImageStillCamera, what you think are dropped frames may actually be just the speed at which the camera is capturing the preview. Grabbing a video feed as a preview from a still camera is different from getting frames from a video camera instance. Still camera previews tend to update at less than 15 FPS, so you might be mistaking that for the filter slowing things down.

3
  • Thanks Brad. I did mess with downsamplingFactor, but not much luck. I AM using GPUImageStillCamera. Is there way to slow down the update rate of the filter (histogram in this case)?
    – Gizmodo
    Jun 4, 2015 at 19:10
  • 1
    @gizmodo - Not really. The filter works on every frame that comes into it. It shouldn't be the source of that strong a performance bottleneck, though. Try out the FilterShowcase sample application, and you'll see it running there on 30-60 FPS input sources without any dropped frames. Either too large an image size is the issue here (adjustable using an intermediate filter with -forceProcessingAtSize: set on it) or the native capture rate of the still camera preview is only giving you frames so fast.
    – Brad Larson
    Jun 4, 2015 at 19:31
  • Thanks again. Looks like I will try the 'dummy filter' trick.
    – Gizmodo
    Jun 4, 2015 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.