如何使用静止图像<gpuimage:jfavoronoi + voronoiconsumer>?

时间:2015-10-29 09:50:16

标签: gpuimage

简要

  

使用时很麻烦   GPUImageJFVoronoiFilter + GPUImageVoronoiConsumerFilter
  为了处理静止图像,任何人都可以帮助看一下它?   谢谢。
  
  我参考了示例案例GPUIMAGE_VORONOI   FilterShowcase,下面是图片和我的代码和结果
图片(看起来很不正常):

input_pictures:

  

stillImage lena.jpg:

     
    

http://i.stack.imgur.com/ce59q.jpg

  
     

voroni_points2.png:

     
    

http://i.stack.imgur.com/CsP8G.png

  
     

WID-small.jpg:

     
    

http://i.stack.imgur.com/JKBFl.jpg

  

///================================================   
GPUImageOutput<GPUImageInput> *filter;
GPUImagePicture *sourcePicture;

//the example  use videoCamera    
//videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
//videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

///i use still image: 
GPUImagePicture * stillImage = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@“lena.jpg”]];

BOOL needsSecondImage = NO;  
needsSecondImage = YES; 

GPUImageJFAVoronoiFilter *jfa = [[GPUImageJFAVoronoiFilter alloc] init];
[jfa setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
sourcePicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"voroni_points2.png"]];
[sourcePicture addTarget:jfa];
filter = [[GPUImageVoronoiConsumerFilter alloc] init];
[jfa setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
[(GPUImageVoronoiConsumerFilter *)filter setSizeInPixels:CGSizeMake(1024.0, 1024.0)];

 //the example  use videoCamera    
 //[videoCamera addTarget:filter];
 ///i use still image: 
[stillImage addTarget:filter];
[jfa addTarget:filter];
[sourcePicture processImage];

UIImage *inputImage;
///i don’t understand why to add this step ,i just copy the example codes
///in FilterShowcase
inputImage = [UIImage imageNamed:@"WID-small.jpg"];
sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
[sourcePicture processImage];
[sourcePicture addTarget:filter];

//the example  use videoCamera      
//[filter addTarget:filterView];
//[videoCamera startCameraCapture];

///i use still image: 
[stillImage processImage];
[filter useNextFrameForImageCapture];
UIImage * filteredImage;
filteredImage = [filter imageFromCurrentFramebuffer];

[self.selectedImageView setImage:filteredImage];

///==============================================

结果

  

与此链接的结果比较

  http://unitzeroone.com/labs/jfavoronoi/
  这在GPUImageJFAVoronoiFilter.m中提到,
  我得到了奇怪的结果,显然,这似乎不是voronoi的预期结果:
  
  result.png:

     
    

http://i.stack.imgur.com/Lrx7D.png

  

1 个答案:

答案 0 :(得分:0)

我修改了GPUImageJFAVoronoi。*和GPUImageVoronoiConsumer。*让 stillImage工作,详情请参考:     https://github.com/ihgazni/voronoi_modified_GPUImage