Implementation of Real-time GPUimage filter and real-time gpuimage Filter

Source: Internet
Author: User

Implementation of Real-time GPUimage filter and real-time gpuimage Filter

GPUImageStillCamera in GPUIMAGE can call the System camera and implement real-time filters. However, I have not found a full screen method for the camera.

GPUImageStillCameraInherited from the GPUImageVideoCamera class, added the photo capture function.

GPUImageVideoCamera

Initialization Method:

-(Id) initWithSessionPreset :( NSString *) sessionPreset cameraPosition :( AVCaptureDevicePosition) cameraPosition

SessionPreset is the resolution when the camera is shooting. The value is as follows:

AVCaptureSessionPresetPhotoAVCaptureSessionPresetHighAVCaptureSessionPresetMediumAVCaptureSessionPresetLowAVCaptureSessionPreset320x240AVCaptureSessionPreset352x288AVCaptureSessionPreset640x480AVCaptureSessionPreset960x540AVCaptureSessionPreset1280x720AVCaptureSessionPreset1920x1080AVCaptureSessionPreset3840x2160AVCaptureSessionPresetiFrame960x540AVCaptureSessionPresetiFrame1280x720AVCaptureSessionPresetInputPriority

 

CameraPosition camera device, divided into front and back

AVCaptureDevicePositionFrontAVCaptureDevicePositionBack

 

 

-(Void) startCameraCapture; start to capture

-(Void) stopCameraCapture; stop capture

-(Void) rotateCamera; switch between front and rear cameras

 

Add Real-Time Filter

DefinitionGPUImageStillCameraObject

mCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];    _isBack = YES;//    _mCamera.horizontallyMirrorRearFacingCamera = NO;//    _mCamera.horizontallyMirrorFrontFacingCamera = YES;    _mCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

 

Define the filter to be applied

_mFilter = [[FWAmaroFilter alloc] init];

 

 

Define the GPUImageView object and setGPUImageStillCameraThe image captured by the object is printed on the GPUImageView layer.

    _mGPUImgView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 426)];

 

Add filter

    [_mCamera addTarget:_mFilter];

 

Add display

    [_mFilter addTarget:_mGPUImgView];

 

Start capture

    [_mCamera startCameraCapture];

 

    [self.view addSubview:_mGPUImgView];

 

So far. Real-time filters have been implemented

 

Implement photo taking

-(void)takePhoto{    [_mCamera capturePhotoAsJPEGProcessedUpToFilter:_mFilter withCompletionHandler:^(NSData *processedJPEG, NSError *error){        [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{        [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:processedJPEG options:nil];        } completionHandler:^(BOOL success, NSError * _Nullable error) {                    }];    }];}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.