Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image filtering effects using BradLarson / GPUImage ** Issue

I want to add different effects to an UIImage. Currently I am trying with using GUIImage library. https://github.com/BradLarson/GPUImage But, I am unable to run most of the examples provided. Only working example for me is FilterShowcase It works great.

But the problem is, its work only with camera. What i want is Load an static image on to a UIImageView and apply those filters.

I tried, but unable to do it.

This is how I tried it

  - (void)setupFilter;
{
//    videoCamera = [[GPUImageVideoCamera alloc]  initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
////    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
//    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;


UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];

imgView.Image=[UIImage imageNamed:@"WID-small.jpg"];

[self.view addSubview:imgView];

BOOL needsSecondImage = NO;

switch (filterType)
{
    case GPUIMAGE_SEPIA:
    {
        self.title = @"Sepia Tone";
        self.filterSettingsSlider.hidden = NO;

        [self.filterSettingsSlider setValue:1.0];
        [self.filterSettingsSlider setMinimumValue:0.0];
        [self.filterSettingsSlider setMaximumValue:1.0];

        filter = [[GPUImageSepiaFilter alloc] init];

        sourcePicture = [[GPUImagePicture alloc] initWithImage:imgView.image smoothlyScaleOutput:YES];
        [sourcePicture processImage];            
        [sourcePicture addTarget:filter];




    }; break;

Actually what I tried to do is, Load a still image instead of videoCamera. But it doesn't work. If anyone can help me, its highly appreciated.

like image 750
smartsanja Avatar asked Dec 15 '22 21:12

smartsanja


1 Answers

First, there are a couple of reasons why the other sample applications might not be building for you. As is stated in this answer, make sure that you have the scheme for the application selected in the upper left of your Xcode window, not the GPUImage framework project. If changing that doesn't help, exit out of Xcode, delete the relevant project directories from your DerivedData directory, and restart Xcode. That sometimes seems to be needed due to a bug in recent Xcode versions.

The filtering of an image is described in the documentation for the project, which is in the Readme.md file and on the page you link above. In particular, see the section titled "Processing a still image":

There are a couple of ways to process a still image and create a result. The first way you can do this is by creating a still image source object and manually creating a filter chain:

UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];

[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];

UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];

For single filters that you wish to apply to an image, you can simply do the following:

GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];

The SimpleImageFilter example application shows how to do this in more detail.

like image 193
Brad Larson Avatar answered Dec 31 '22 10:12

Brad Larson