1. 程式人生 > >強大的影象處理庫---GPUImage

強大的影象處理庫---GPUImage

iOS開發中,想要做影象處理,可以用Core Image,Core Image提供強大的濾鏡效果,可以對影象和照相機的視訊流做處理。今天介紹的是比Core Image更牛掰的一個開源庫GPUImage!GPUImage託管在GitHub上,是一個遵守BSD開源協議的開源庫,可以放心大膽的使用!

GPUImage顧名思義是利用GPU來做影象處理的,相比於CPU要快很多,不至於你的影象處理過程很慢,特別是處理很大的影象時,比如高清視訊。GPUImage支援iOS4.0以上,當然iOS8已經發布的今天,你應該不會去適配iOS4了吧!GPUImage封裝了OpenGL ES2.0,介面設計簡單明瞭,支援ARC,這樣就可以不管OpenGL ES的複雜介面而使用它的處理效能啦。並且作者一直在更新,有支援Swift的傾向,還是值得一學的。

要處理的源對像應該是GPUImageOutput的子類物件,比如:

GPUImageVideoCamera(來自攝像頭的實時視訊)
GPUImageStillCamera(攝像頭照的照片)
GPUImagePicture(靜態圖片)
GPUImageMovie(電影)

源物件載入靜態影象,作為OpenGL ES的紋理物件,然後一幀一幀往下處理。濾鏡和其他的一些遵守GPUImageInput協議,可以用來處理OpenGL ES的紋理,比如,應用程式想要處理實時視訊,把視訊處理成深褐色,然後顯示到螢幕上,就需要GPUImageVideoCamera -> GPUImageSepiaFilter -> GPUImageView。

下面是GPUImage裡面所有的類:

基礎類:

#import "GPUImageContext.h"

#import "GPUImageOutput.h"

#import "GPUImageView.h"

#import "GPUImageVideoCamera.h"

#import "GPUImageStillCamera.h"

#import "GPUImageMovie.h"

#import "GPUImagePicture.h"

#import "GPUImageRawDataInput.h"

#import "GPUImageRawDataOutput.h"

#import

"GPUImageMovieWriter.h"

#import "GPUImageFilterPipeline.h"

#import "GPUImageTextureOutput.h"

#import "GPUImageFilterGroup.h"

#import "GPUImageTextureInput.h"

#import "GPUImageUIElement.h"

#import "GPUImageBuffer.h"

#import "GPUImageFramebuffer.h"

#import "GPUImageFramebufferCache.h"

濾鏡類:

#import "GPUImageFilter.h"

#import "GPUImageTwoInputFilter.h"

#import "GPUImagePixellateFilter.h"

#import "GPUImagePixellatePositionFilter.h"

#import "GPUImageSepiaFilter.h"

#import "GPUImageColorInvertFilter.h"

#import "GPUImageSaturationFilter.h"

#import "GPUImageContrastFilter.h"

#import "GPUImageExposureFilter.h"

#import "GPUImageBrightnessFilter.h"

#import "GPUImageLevelsFilter.h"

#import "GPUImageSharpenFilter.h"

#import "GPUImageGammaFilter.h"

#import "GPUImageSobelEdgeDetectionFilter.h"

#import "GPUImageSketchFilter.h"

#import "GPUImageToonFilter.h"

#import "GPUImageSmoothToonFilter.h"

#import "GPUImageMultiplyBlendFilter.h"

#import "GPUImageDissolveBlendFilter.h"

#import "GPUImageKuwaharaFilter.h"

#import "GPUImageKuwaharaRadius3Filter.h"

#import "GPUImageVignetteFilter.h"

#import "GPUImageGaussianBlurFilter.h"

#import "GPUImageGaussianBlurPositionFilter.h"

#import "GPUImageGaussianSelectiveBlurFilter.h"

#import "GPUImageOverlayBlendFilter.h"

#import "GPUImageDarkenBlendFilter.h"

#import "GPUImageLightenBlendFilter.h"

#import "GPUImageSwirlFilter.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 "GPUImageColorBlendFilter.h"

#import "GPUImageHueBlendFilter.h"

#import "GPUImageSaturationBlendFilter.h"

#import "GPUImageLuminosityBlendFilter.h"

#import "GPUImageCropFilter.h"

#import "GPUImageGrayscaleFilter.h"

#import "GPUImageTransformFilter.h"

#import "GPUImageChromaKeyBlendFilter.h"

#import "GPUImageHazeFilter.h"

#import "GPUImageLuminanceThresholdFilter.h"

#import "GPUImagePosterizeFilter.h"

#import "GPUImageBoxBlurFilter.h"

#import "GPUImageAdaptiveThresholdFilter.h"

#import "GPUImageUnsharpMaskFilter.h"

#import "GPUImageBulgeDistortionFilter.h"

#import "GPUImagePinchDistortionFilter.h"

#import "GPUImageCrosshatchFilter.h"

#import "GPUImageCGAColorspaceFilter.h"

#import "GPUImagePolarPixellateFilter.h"

#import "GPUImageStretchDistortionFilter.h"

#import "GPUImagePerlinNoiseFilter.h"

#import "GPUImageJFAVoronoiFilter.h"

#import "GPUImageVoronoiConsumerFilter.h"

#import "GPUImageMosaicFilter.h"

#import "GPUImageTiltShiftFilter.h"

#import "GPUImage3x3ConvolutionFilter.h"

#import "GPUImageEmbossFilter.h"

#import "GPUImageCannyEdgeDetectionFilter.h"

#import "GPUImageThresholdEdgeDetectionFilter.h"

#import "GPUImageMaskFilter.h"

#import "GPUImageHistogramFilter.h"

#import "GPUImageHistogramGenerator.h"

#import "GPUImageHistogramEqualizationFilter.h"

#import "GPUImagePrewittEdgeDetectionFilter.h"

#import "GPUImageXYDerivativeFilter.h"

#import "GPUImageHarrisCornerDetectionFilter.h"

#import "GPUImageAlphaBlendFilter.h"

#import "GPUImageNormalBlendFilter.h"

#import "GPUImageNonMaximumSuppressionFilter.h"

#import "GPUImageRGBFilter.h"

#import "GPUImageMedianFilter.h"

#import "GPUImageBilateralFilter.h"

#import "GPUImageCrosshairGenerator.h"

#import "GPUImageToneCurveFilter.h"

#import "GPUImageNobleCornerDetectionFilter.h"

#import "GPUImageShiTomasiFeatureDetectionFilter.h"

#import "GPUImageErosionFilter.h"

#import "GPUImageRGBErosionFilter.h"

#import "GPUImageDilationFilter.h"

#import "GPUImageRGBDilationFilter.h"

#import "GPUImageOpeningFilter.h"

#import "GPUImageRGBOpeningFilter.h"

#import "GPUImageClosingFilter.h"

#import "GPUImageRGBClosingFilter.h"

#import "GPUImageColorPackingFilter.h"

#import "GPUImageSphereRefractionFilter.h"

#import "GPUImageMonochromeFilter.h"

#import "GPUImageOpacityFilter.h"

#import "GPUImageHighlightShadowFilter.h"

#import "GPUImageFalseColorFilter.h"

#import "GPUImageHSBFilter.h"

#import "GPUImageHueFilter.h"

#import "GPUImageGlassSphereFilter.h"

#import "GPUImageLookupFilter.h"

#import "GPUImageAmatorkaFilter.h"

#import "GPUImageMissEtikateFilter.h"

#import "GPUImageSoftEleganceFilter.h"

#import "GPUImageAddBlendFilter.h"

#import "GPUImageDivideBlendFilter.h"

#import "GPUImagePolkaDotFilter.h"

#import "GPUImageLocalBinaryPatternFilter.h"

#import "GPUImageLanczosResamplingFilter.h"

#import "GPUImageAverageColor.h"

#import "GPUImageSolidColorGenerator.h"

#import "GPUImageLuminosity.h"

#import "GPUImageAverageLuminanceThresholdFilter.h"

#import "GPUImageWhiteBalanceFilter.h"

#import "GPUImageChromaKeyFilter.h"

#import "GPUImageLowPassFilter.h"

#import "GPUImageHighPassFilter.h"

#import "GPUImageMotionDetector.h"

#import "GPUImageHalftoneFilter.h"

#import "GPUImageThresholdedNonMaximumSuppressionFilter.h"

#import "GPUImageHoughTransformLineDetector.h"

#import "GPUImageParallelCoordinateLineTransformFilter.h"

#import "GPUImageThresholdSketchFilter.h"

#import "GPUImageLineGenerator.h"

#import "GPUImageLinearBurnBlendFilter.h"

#import "GPUImageGaussianBlurPositionFilter.h"

#import "GPUImagePixellatePositionFilter.h"

#import "GPUImageTwoInputCrossTextureSamplingFilter.h"

#import "GPUImagePoissonBlendFilter.h"

#import "GPUImageMotionBlurFilter.h"

#import "GPUImageZoomBlurFilter.h"

#import "GPUImageLaplacianFilter.h"

#import "GPUImageiOSBlurFilter.h"

#import "GPUImageLuminanceRangeFilter.h"

引入GPUImage到你的工程裡面也跟其他的第三方不一樣,沒有CocoaPod可以用,只能手動引入,有兩種方法:

1、可以把原始檔全部拖到你的工程裡邊,這樣你就可以看見.h和.m檔案了,這樣做的話,你需要手動新增GPUImage需要的庫:

CoreMedia
CoreVideo
OpenGL ES
AVFoundation
QuartzCore

2、如果你不想看見.m檔案可以把它編譯成靜態庫,加入到你的工程,就像加入系統自帶的那些框架一樣:

選擇Add Other...找到你編譯的靜態庫就可以啦,這樣你就不用手動新增GPUImage需要的那些庫啦。編譯靜態庫的方法是:

開啟終端--->cd 你下載的GPUImage包----->sh build.sh

這樣你就可以編譯成功啦,你也可以修改要編譯的目標SDK,用文字編輯器開啟build.sh就可以修改啦。編譯好的檔案在build問價夾裡。

在需要用到GPUImage的檔案裡,加入標頭檔案:

#import <GPUImage/GPUImage.h>,如果不是編譯成靜態庫,就這樣引用:#import "GPUImage.h"。

就寫到這吧!