//載入本地需要過濾的圖片 let inputImage = UIImage(named: "yourImage.png") let picture = GPUImagePicture(image: inputImage!) //建立一個濾鏡並加入渲染管道 let filter = GPUImageGrayscaleFilter() picture.addTarget(filter) //建立展示濾鏡圖片的UI控制元件 let filteredImageView = GPUImageView(frame: view.bounds) view.addSubview(filteredImageView) //將濾鏡輸出連結到GPUImageView filter.addTarget(filteredImageView) //開始處理圖片並顯示 picture.processImage()
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //相機 self.videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront]; self.videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait; self.videoCamera.horizontallyMirrorFrontFacingCamera = YES; //濾鏡 self.filter = [[GPUImageBilateralFilter alloc] init]; //組合 [self.videoCamera addTarget:self.filter]; //展示 GPUImageView *gpuImageView = [[GPUImageView alloc] initWithFrame:self.view.bounds]; [self.view insertSubview:gpuImageView atIndex:0]; [self.filter addTarget:gpuImageView]; self.gpuImageView = gpuImageView; //相機開始執行 [self.videoCamera startCameraCapture]; }
//開始編輯 @IBAction func editMovie(_ sender: Any) { let documentDic = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first let movieOldUrl = documentDic?.appendingPathComponent("Movie4_old.mov") let movieNewUrl = documentDic?.appendingPathComponent("Movie4_new.mov") let movieFile = GPUImageMovie(url: movieOldUrl!) let sepiaFilter = GPUImageSepiaFilter() let movieWriter = GPUImageMovieWriter(movieURL: movieNewUrl!, size: CGSizeMake(480.0, 640.0)) movieWriter?.encodingLiveVideo = true movieFile?.addTarget(sepiaFilter) sepiaFilter.addTarget(movieWriter) movieFile?.startProcessing() movieWriter?.startRecording() } //結束編輯 @IBAction func finishEdit(_ sender: Any) { movieFile?.endProcessing() movieWriter?.finishRecording() movieFile?.removeTarget(pixellateFilter) pixellateFilter.removeTarget(movieWriter) }
#import "GPUImageBrightnessFilter.h" //亮度 #import "GPUImageExposureFilter.h" //曝光 #import "GPUImageContrastFilter.h" //對比度 #import "GPUImageSaturationFilter.h" //飽和度 #import "GPUImageGammaFilter.h" //伽馬線 #import "GPUImageColorInvertFilter.h" //反色 #import "GPUImageSepiaFilter.h" //褐色(懷舊) #import "GPUImageLevelsFilter.h" //色階 #import "GPUImageGrayscaleFilter.h" //灰度 #import "GPUImageHistogramFilter.h" //色彩直方圖,顯示在圖片上 #import "GPUImageHistogramGenerator.h" //色彩直方圖 #import "GPUImageRGBFilter.h" //RGB #import "GPUImageToneCurveFilter.h" //色調曲線 #import "GPUImageMonochromeFilter.h" //單色 #import "GPUImageOpacityFilter.h" //不透明度 #import "GPUImageHighlightShadowFilter.h" //提亮陰影 #import "GPUImageFalseColorFilter.h" //色彩替換(替換亮部和暗部色彩) #import "GPUImageHueFilter.h" //色度 #import "GPUImageChromaKeyFilter.h" //色度鍵 #import "GPUImageWhiteBalanceFilter.h" //白平橫 #import "GPUImageAverageColor.h" //畫素平均色值 #import "GPUImageSolidColorGenerator.h" //純色 #import "GPUImageLuminosity.h" //亮度平均 #import "GPUImageAverageLuminanceThresholdFilter.h" //畫素色值亮度平均,影象黑白(有類似漫畫效果) #import "GPUImageLookupFilter.h" //lookup 色彩調整 #import "GPUImageAmatorkaFilter.h" //Amatorka lookup #import "GPUImageMissEtikateFilter.h" //MissEtikate lookup #import "GPUImageSoftEleganceFilter.h" //SoftElegance lookup #pragma mark - 影象處理 Handle Image #import "GPUImageCrosshairGenerator.h" //十字 #import "GPUImageLineGenerator.h" //線條 #import "GPUImageTransformFilter.h" //形狀變化 #import "GPUImageCropFilter.h" //剪裁 #import "GPUImageSharpenFilter.h" //銳化 #import "GPUImageUnsharpMaskFilter.h" //反遮罩銳化 #import "GPUImageFastBlurFilter.h" //模糊 #import "GPUImageGaussianBlurFilter.h" //高斯模糊 #import "GPUImageGaussianSelectiveBlurFilter.h" //高斯模糊,選擇部分清晰 #import "GPUImageBoxBlurFilter.h" //盒狀模糊 #import "GPUImageTiltShiftFilter.h" //條紋模糊,中間清晰,上下兩端模糊 #import "GPUImageMedianFilter.h" //中間值,有種稍微模糊邊緣的效果 #import "GPUImageBilateralFilter.h" //雙邊模糊 #import "GPUImageErosionFilter.h" //侵蝕邊緣模糊,變黑白 #import "GPUImageRGBErosionFilter.h" //RGB侵蝕邊緣模糊,有色彩 #import "GPUImageDilationFilter.h" //擴充套件邊緣模糊,變黑白 #import "GPUImageRGBDilationFilter.h" //RGB擴充套件邊緣模糊,有色彩 #import "GPUImageOpeningFilter.h" //黑白色調模糊 #import "GPUImageRGBOpeningFilter.h" //彩色模糊 #import "GPUImageClosingFilter.h" //黑白色調模糊,暗色會被提亮 #import "GPUImageRGBClosingFilter.h" //彩色模糊,暗色會被提亮 #import "GPUImageLanczosResamplingFilter.h" //Lanczos重取樣,模糊效果 #import "GPUImageNonMaximumSuppressionFilter.h" //非最大抑制,只顯示亮度最高的畫素,其他為黑 #import "GPUImageThresholdedNonMaximumSuppressionFilter.h" //與上相比,畫素丟失更多 #import "GPUImageSobelEdgeDetectionFilter.h" //Sobel邊緣檢測演演算法(白邊,黑內容,有點漫畫的反色效果) #import "GPUImageCannyEdgeDetectionFilter.h" //Canny邊緣檢測演演算法(比上更強烈的黑白對比度) #import "GPUImageThresholdEdgeDetectionFilter.h" //閾值邊緣檢測(效果與上差別不大) #import "GPUImagePrewittEdgeDetectionFilter.h" //普瑞維特(Prewitt)邊緣檢測(效果與Sobel差不多,貌似更平滑) #import "GPUImageXYDerivativeFilter.h" //XYDerivative邊緣檢測,畫面以藍色為主,綠色為邊緣,帶彩色 #import "GPUImageHarrisCornerDetectionFilter.h" //Harris角點檢測,會有綠色小十字顯示在圖片角點處 #import "GPUImageNobleCornerDetectionFilter.h" //Noble角點檢測,檢測點更多 #import "GPUImageShiTomasiFeatureDetectionFilter.h" //ShiTomasi角點檢測,與上差別不大 #import "GPUImageMotionDetector.h" //動作檢測 #import "GPUImageHoughTransformLineDetector.h" //線條檢測 #import "GPUImageParallelCoordinateLineTransformFilter.h" //平行線檢測 #import "GPUImageLocalBinaryPatternFilter.h" //影象黑白化,並有大量噪點 #import "GPUImageLowPassFilter.h" //用於影象加亮 #import "GPUImageHighPassFilter.h" //影象低於某值時顯示為黑 #pragma mark - 視覺效果 Visual Effect #import "GPUImageSketchFilter.h" //素描 #import "GPUImageThresholdSketchFilter.h" //閥值素描,形成有噪點的素描 #import "GPUImageToonFilter.h" //卡通效果(黑色粗線描邊) #import "GPUImageSmoothToonFilter.h" //相比上面的效果更細膩,上面是粗曠的畫風 #import "GPUImageKuwaharaFilter.h" //桑原(Kuwahara)濾波,水粉畫的模糊效果;處理時間比較長,慎用 #import "GPUImageMosaicFilter.h" //黑白馬賽克 #import "GPUImagePixellateFilter.h" //畫素化 #import "GPUImagePolarPixellateFilter.h" //同心圓畫素化 #import "GPUImageCrosshatchFilter.h" //交叉線陰影,形成黑白網狀畫面 #import "GPUImageColorPackingFilter.h" //色彩丟失,模糊(類似監控攝像效果) #import "GPUImageVignetteFilter.h" //暈影,形成黑色圓形邊緣,突出中間影象的效果 #import "GPUImageSwirlFilter.h" //漩渦,中間形成捲曲的畫面 #import "GPUImageBulgeDistortionFilter.h" //凸起失真,魚眼效果 #import "GPUImagePinchDistortionFilter.h" //收縮失真,凹面鏡 #import "GPUImageStretchDistortionFilter.h" //伸展失真,哈哈鏡 #import "GPUImageGlassSphereFilter.h" //水晶球效果 #import "GPUImageSphereRefractionFilter.h" //球形折射,圖形倒立 #import "GPUImagePosterizeFilter.h" //色調分離,形成噪點效果 #import "GPUImageCGAColorspaceFilter.h" //CGA色彩濾鏡,形成黑、淺藍、紫色塊的畫面 #import "GPUImagePerlinNoiseFilter.h" //柏林噪點,花邊噪點 #import "GPUImage3x3ConvolutionFilter.h" //3x3折積,高亮大色塊變黑,加亮邊緣、線條等 #import "GPUImageEmbossFilter.h" //浮雕效果,帶有點3d的感覺 #import "GPUImagePolkaDotFilter.h" //畫素圓點花樣 #import "GPUImageHalftoneFilter.h" //點染,影象黑白化,由黑點構成原圖的大致圖形 #pragma mark - 混合模式 Blend #import "GPUImageMultiplyBlendFilter.h" //通常用於建立陰影和深度效果 #import "GPUImageNormalBlendFilter.h" //正常 #import "GPUImageAlphaBlendFilter.h" //透明混合,通常用於在背景上應用前景的透明度 #import "GPUImageDissolveBlendFilter.h" //溶解 #import "GPUImageOverlayBlendFilter.h" //疊加,通常用於建立陰影效果 #import "GPUImageDarkenBlendFilter.h" //加深混合,通常用於重疊型別 #import "GPUImageLightenBlendFilter.h" //減淡混合,通常用於重疊型別 #import "GPUImageSourceOverBlendFilter.h" //源混合 #import "GPUImageColorBurnBlendFilter.h" //色彩加深混合 #import "GPUImageColorDodgeBlendFilter.h" //色彩減淡混合 #import "GPUImageScreenBlendFilter.h" //螢幕包裹,通常用於建立亮點和鏡頭眩光 #import "GPUImageExclusionBlendFilter.h" //排除混合 #import "GPUImageDifferenceBlendFilter.h" //差異混合,通常用於建立更多變動的顏色 #import "GPUImageSubtractBlendFilter.h" //差值混合,通常用於建立兩個影象之間的動畫變暗模糊效果 #import "GPUImageHardLightBlendFilter.h" //強光混合,通常用於建立陰影效果 #import "GPUImageSoftLightBlendFilter.h" //柔光混合 #import "GPUImageChromaKeyBlendFilter.h" //色度鍵混合 #import "GPUImageMaskFilter.h" //遮罩混合 #import "GPUImageHazeFilter.h" //朦朧加暗 #import "GPUImageLuminanceThresholdFilter.h" //亮度閾 #import "GPUImageAdaptiveThresholdFilter.h" //自適應閾值 #import "GPUImageAddBlendFilter.h" //通常用於建立兩個影象之間的動畫變亮模糊效果 #import "GPUImageDivideBlendFilter.h" //通常用於建立兩個影象之間的動畫變暗模糊效果 #pragma mark - 尚不清楚 #import "GPUImageJFAVoroniFilter.h" #import "GPUImageVoroniConsumerFilter.h"