1

I use GPUImageStillCamera to take a picture and load the picture into a GPUImageView

Now how can I apply a filter to a still GPUImageView?

The only examples I see online are to first create a GPUImagePicture (which requires a UIImage) but it seems rather wasteful to have to create a UIImage from GPUImageView then load it into the GPUImagePicture when I could just apply the filters to the GPUImageView directly. But I don't know how

I've tried:

  GPUImageFilter *sepiaFilter [[GPUImageSepiaFilter alloc]init];
  [sepiaFilter addTarget:gpuImageView];

  //and then tried these in a bunch of different orders
  [filter useNextFrameForImageCapture];
  [currentFilter endProcessing];
  [currentFilter imageFromCurrentFramebuffer];

EDIT: Here is how I load the image into the GPUImageView

self.stillCamera = [[GPUImageStillCamera alloc]
                        initWithSessionPreset:AVCaptureSessionPresetPhoto
                        cameraPosition:AVCaptureDevicePositionFront];
self.stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
self.filterEmpty = [[GPUImageGammaFilter alloc] init];

[self.stillCamera addTarget:self.filterEmpty];


[self.filterEmpty addTarget:self.capturedImageView];
[self.stillCamera startCameraCapture];


[self.stillCamera capturePhotoAsJPEGProcessedUpToFilter:self.filterEmpty withCompletionHandler:^(NSData *processedJPEG, NSError *error){

[self.stillCamera stopCameraCapture];

//and then from here the gpuimageview is loaded with the taken picture
MobileMon
  • 8,341
  • 5
  • 56
  • 75

1 Answers1

0

Have a regular image view on top of GPUImageView.

Let's call that UIImageVIew imageView.

[self.stillCamera capturePhotoAsImageProcessedUpToFilter:self.filterEmpty 
   withCompletionHandler:^(UIImage *processedImage, NSError *error) {
      imageView.image = processedImage;
      //stop, dispose of, or just continue with the camera,
      //depending on what you want with your app.
}];

At least, this is how I do it on a realtime photo filtering app, and it works perfectly.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • User can apply different filters in rapid succession (much like instagram) so I don't want to have to convert the GPUImageView to a UIImage because its very hard on memory and causes app to crash – MobileMon Jan 23 '15 at 18:19
  • @MobileMon yeah, I admit memory is sometimes an issue. How about this example from GPUImage's own examples: https://github.com/BradLarson/GPUImage/blob/master/examples/iOS/SimpleImageFilter/SimpleImageFilter/SimpleImageViewController.m I think it can help you achieve applying effects in rapid succession. – Can Poyrazoğlu Jan 23 '15 at 18:23
  • All of them require a UIImage first for the sourcePicture. Is there any way to set a GPUImageView as the source for a sourcePicture?? – MobileMon Jan 23 '15 at 18:56
  • @MobileMon Technically there should be a way. But again, you'll be needing two instances, one "original" and one "edited" as the effects you'll be applying will be destructive. – Can Poyrazoğlu Jan 25 '15 at 13:15