Search code examples
objective-cgpuimage

GPUImage luminosity of camera real time


I am trying out the GPUImage framework, which looks awesome, however I can't get my head around how to get continuous feed back from the camera view

basically I would like to be able to log out the luminosity of what ever the camera view is seeing as it changes, so for instance if the camera was still in a light room and someone put their hand down towards the lens gradually nslog would fire out a list of values

I was able to get a read out on load of the luminosity, however I need this to be constant rather than a one off, this is mainly down to my lack of understanding of the framework, but it would be cool if anyone had any pointers

- (void)viewDidLoad
{
[super viewDidLoad];

GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;



GPUImageLuminosity*lumin = [[GPUImageLuminosity alloc] init];
[videoCamera addTarget:lumin];



[(GPUImageLuminosity *)lumin setLuminosityProcessingFinishedBlock:^(CGFloat luminosity, CMTime frameTime) {
    // Do something with the luminosity here

    NSLog(@"Lumin is %f ", luminosity);
}];

 [videoCamera startCameraCapture];


}

NSlog output is 2013-07-28 22:30:42.419 Photo[1750:1603] Lumin is 0.189748 2013-07-28 22:30:42.476 Photo[1750:1603] Lumin is 0.230812


Solution

  • I believe your problem is the fact that your application is ARC-enabled, and you are not keeping a reference around to your GPUImageVideoCamera instance. This means that as soon as -viewDidLoad finishes, your camera will be deallocated and you'll stop getting frames from it. I'm surprised you're even able to get one frame before the camera is deallocated.

    For continuous processing, you want to make your camera (and possibly your luminosity processor) be a strongly referenced instance variable on your class. You'll need to keep it alive past this method, and to be able to pause it when heading to the background or to terminate capture as needed.