GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

capturePhotoAsJPEGProcessedUpToFilter Resolution

Open andrewgarn opened this issue 14 years ago • 10 comments

What is the correct way of capturing a full resolution filtered image with metadata from the iPhone camera? I'm saving an image to the camera roll successfully, but its being heavily scaled down to 640 x 852. I'm using the session preset "AVCaptureSessionPresetPhoto" as the docs says that should be full resolution

My code is based off the SimplePhotoFilter project, except I had to add [stillCamera pauseCamerCapture] before saving the image or the image was saved with distortion lines down the edge

Is it possible to save it at native 3264 x 2448 resolution with normal iPhone camera metadata? I'm developing on a 4S. Thanks

andrewgarn avatar May 31 '12 09:05 andrewgarn

The [stillCamera pauseCameraCapture] is what's preventing the full-size photos from being processed, because you're telling the application to ignore incoming frames after that's activated. Therefore, you're only processing the last preview frame of video, which is 640 x 852.

Are you sure that you were following the SimplePhotoFilter example? If you allocate a default still image camera using [[GPUImageStillCamera alloc] init], everything should be set to the correct presets for taking photos. If you change the presets in any way for the still camera, there is a known bug in iOS where the camera will send some corrupt image data for photos at the non-photo preset. Using the SimplePhotoFilter example, I see none of this artifacting when taking pictures with the way it is configured.

BradLarson avatar May 31 '12 15:05 BradLarson

I think my issue my be related to the resolution as well, but I can't seem to resolve it. I copied the code from SimplePhotoFilter to take pictures, and it worked fine on my 4S, but when I ran the takePicture code in my application, I get *** -[NSConcreteMutableData length]: message sent to deallocated instance 0xe954ce0 on the processedJPEG object. Have you seen this before? I've done a bit of researching, and haven't found an answer. If I don't try to use processedJPEG in my code, then my phone will just freeze in the callback method, and after a while automatically restart...

heatherSnepenger avatar Jun 01 '12 14:06 heatherSnepenger

That might have to do with the block of code here:

    NSData *dataForJPEGFile = nil;
    @autoreleasepool {
        UIImage *filteredPhoto = [finalFilterInChain imageFromCurrentlyProcessedOutput];

//            report_memory(@"After UIImage generation");

        dataForJPEGFile = UIImageJPEGRepresentation(filteredPhoto, 0.8);
//            report_memory(@"After JPEG generation");
    }

where I generate the JPEG representation within an autorelease pool. I thought that it would survive outside of that pool under ARC, but it's possible that it is not doing so. I'll look into it.

BradLarson avatar Jun 01 '12 15:06 BradLarson

I just got this to work today. Photos are full size and look good in both lanscape and portrait when compared with Camera+ photos. My code is based on the SimplePhotoFilter example.

- (IBAction)captureStillImage:(id)sender {
    self.captureImageGesture.enabled = NO;
    [self snapShutter];
    [self.stillCamera capturePhotoAsJPEGProcessedUpToFilter:self.filter withCompletionHandler:^(NSData* imageData, NSError* error){
        if (error) {
            [self alertOnError:error];
        }
        else {
            UIImage* capturedImage = [[UIImage alloc] initWithData:imageData];
            if ([self.delegate respondsToSelector:@selector(didCaptureImage:)]) {
                [self.delegate didCaptureImage:capturedImage];
            }
        }             
        runOnMainQueueWithoutDeadlocking(^{
            self.captureImageGesture.enabled = YES;
        });
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.stillCamera = [[GPUImageStillCamera alloc] init];
    self.stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
    self.filter = [[GPUImageGammaFilter alloc] init];
    [self.filter prepareForImageCapture];    
    [self.stillCamera addTarget:filter];
    GPUImageView* filterView = (GPUImageView*)self.view;
    filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
    [self.filter addTarget:filterView];    
    [self.stillCamera startCameraCapture];
}

troystribling avatar Jun 02 '12 19:06 troystribling

Awesome -thanks I'll try it.

On Jun 2, 2012, at 3:09 PM, Troy Stribling wrote:

I just got this to work today. Photos are full size and look good in both lanscape and portrait when compared with Camera+ photos. My code is based on the SimplePhotoFilter example.

- (IBAction)captureStillImage:(id)sender {
   self.captureImageGesture.enabled = NO;
   [self snapShutter];
   [self.stillCamera capturePhotoAsJPEGProcessedUpToFilter:self.filter withCompletionHandler:^(NSData* imageData, NSError* error){
       if (error) {
           [self alertOnError:error];
       }
       else {
           UIImage* capturedImage = [[UIImage alloc] initWithData:imageData];
           if ([self.delegate respondsToSelector:@selector(didCaptureImage:)]) {
               [self.delegate didCaptureImage:capturedImage];
           }
       }             
       runOnMainQueueWithoutDeadlocking(^{
           self.captureImageGesture.enabled = YES;
       });
   }];
}

- (void)viewDidLoad {
   [super viewDidLoad];
   self.stillCamera = [[GPUImageStillCamera alloc] init];
   self.stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
   self.filter = [[GPUImageGammaFilter alloc] init];
   [self.filter prepareForImageCapture];    
   [self.stillCamera addTarget:filter];
   GPUImageView* filterView = (GPUImageView*)self.view;
   filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
   [self.filter addTarget:filterView];    
   [self.stillCamera startCameraCapture];
}


Reply to this email directly or view it on GitHub: https://github.com/BradLarson/GPUImage/issues/173#issuecomment-6079964

heatherSnepenger avatar Jun 03 '12 22:06 heatherSnepenger

Ok. It turns out that since my project was not using arc, and I added a project using arc, I needed to let the compiler know that the project used arc, then all the funky memory issues were taken care of.

heatherSnepenger avatar Jun 04 '12 14:06 heatherSnepenger

when I pauseCamerCapture?

ordinary avatar Jul 24 '12 08:07 ordinary

I there a way to save image in resolution 1280x853?

balabs avatar Sep 20 '12 13:09 balabs

@balabs - This isn't really related to the issue here, but if you need to do this, simply use -forceProcessingAtSize: on one of your filters in the chain the downsample to a lower resolution.

BradLarson avatar Sep 20 '12 14:09 BradLarson

That's what I needed. Thanks for extremely fast response. Best regards

balabs avatar Sep 20 '12 14:09 balabs