为什么LUT表图像间歇性地无法在ObjectiveC / iOS中的GPUImage中加载?

时间:2016-10-27 13:48:30

标签: ios objective-c computer-vision gpuimage

我制作了一个简单的试用版应用程序,其中包含实时预览一些过滤器(颜色LUT表)的功能。应用程序启动时,LUT过滤器效果通常不会应用,或者应用时没有明显的变化。如果我关闭应用程序并重新启动,直到我看到更改,它最终将按预期工作。

在发现它最终会起作用并且我没有完全错误地实现GPUImage库之后,我开始认为这是一个加载顺序或计时问题。我添加了一个UISegmentedControl来更改LUT过滤器的源.png,以便在启动应用程序后很好地修改过滤器。令我沮丧的是,如果LUT图像在启动时加载不正确,则事后通过UISegmentedControl更改LUT源图像没有(可观察的)效果。在这一点上,我想,也许还有一些我不了解的更基本的东西。

这是视图控制器,其中大部分相关代码都是。同样,这个目的更多的是概念验证,而不是现阶段的最终产品,但这个概念只是间歇性证明,呵呵!

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "GPUImage/GPUImage.h"
@import CoreFoundation;
@import ImageIO;
@import UIKit;

@interface ViewController ()
- (void)applyColorLUT:(NSString *)LUTFileName;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
    scroll.contentSize = CGSizeMake(320, 700);
    scroll.showsHorizontalScrollIndicator = YES;

    NSArray *filterTypeArray = [NSArray arrayWithObjects: @"First", @"Second", @"Third", nil];
    UISegmentedControl *navSegmentedControl = [[UISegmentedControl alloc] initWithItems:filterTypeArray];
    navSegmentedControl.frame = CGRectMake(0, (self.view.frame.size.height-50), self.view.frame.size.width, 50);

    [navSegmentedControl addTarget:self action:@selector(NavSegmentControlAction:) forControlEvents:UIControlEventValueChanged];
    [navSegmentedControl setSelectedSegmentIndex:0];


    filteredVideoView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.height-50))];
    filteredVideoView.backgroundColor=[UIColor blueColor];
    filteredVideoView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
    [self.view addSubview:filteredVideoView];
    [self.view addSubview:navSegmentedControl];

    //set up video capture/source
    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
    videoCamera.horizontallyMirrorFrontFacingCamera = NO;
    videoCamera.horizontallyMirrorRearFacingCamera = NO;



    lookupFilter = [[GPUImageLookupFilter alloc] init];
    [self applyColorLUT:@"lookup_first"];

      //run
    [videoCamera startCameraCapture];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)NavSegmentControlAction:(UISegmentedControl *)segment
{
    switch (segment.selectedSegmentIndex) {
        case 0:{
            [self applyColorLUT:@"lookup_first"];
            break;}
        case 1:{
            [self applyColorLUT:@"lookup_second"];
            break;}
        case 2:{
            [self applyColorLUT:@"lookup_third"];
            break;}

    }
}

- (void)applyColorLUT:(NSString *)LUTFileName
{
    [videoCamera removeAllTargets];
    [lookupImageSource removeAllTargets];
    [lookupFilter removeAllTargets];

    lookupImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:LUTFileName]];
    [lookupImageSource processImage];
    [videoCamera addTarget:lookupFilter atTextureLocation:0];
    [lookupImageSource addTarget:lookupFilter atTextureLocation:1];
    [lookupFilter addTarget:filteredVideoView];

}


@end

0 个答案:

没有答案