BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

JFA Voronoi is broken #2062

Open nyrov opened 9 years ago

nyrov commented 9 years ago

It seems like JFA Voronoi not fills buffer in a correct way, so Voronoi Consumer fails with "Tried to overrelease a framebuffer". Seems like the problem in the "renderToTextureWithVertices" method, but I coud not work it out.

Can anyone point some tips on how to fix the filter? Please.

ihgazni commented 8 years ago

the variable "numPasses" seemed not inited ,yes ?

nyrov commented 8 years ago

No, this won't help. I've even seen a pull request with this fix, but it doesn't solve the problem.

2015-10-28 13:42 GMT+03:00 dapeli notifications@github.com:

the variable "numPasses" seemed not inited ,yes ?

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

ihgazni commented 8 years ago

hi, nyrov, i make voronoi filter work when using stillImage

please excuse me for my poor english description( english is not my native language), i hope the below brief description could help. all the way i attach the modified .h .m source code and the result screen-snap-shot.

i changed the GPUImageJFAVoronoiFilter.h and GPUImageJFAVoronoiFilter.m and GPUImageVoronoiConsumerFilter.m and make Voronoi filter to work with stillImage.(i did not test videoCamera).

because i am a totally newer of opengl-es, i just refer to the implement of this webgl exzample which mentioned in GPUImageJFAVoronoiFilter.h http://unitzeroone.com/labs/jfavoronoi/, so please tell me if something not correct in my modified codes.

there is one thing different between GPUImage implement and the upper webgl implement: the GPUImage use a already exist voronoi_points.png while the webgl_implement use fillRect to generate one, all others seems nearly same. so the mainly change is about “usingNextFrameForImageCapture ” in GPUImageJFAVoronoiFilter.m

  1. the modified files here ——————————— https://github.com/ihgazni/voronoi_modified_GPUImage https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/dli_modified_GPUImageJFAVoronoiFilter.h https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/dli_modified_GPUImageJFAVoronoiFilter.m https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/dli_modified_GPUImageVoronoiConsumerFilter.h https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/dli_modified_GPUImageVoronoiConsumerFilter.m

but i change the USAGE when you using the new JFA , i move the for circle of numPASSes out from GPUImageJFAVoronoiFilter.m now GPUImageJFAVoronoiFilter will output a image,then you need to use the original image and the image GPUImageJFAVoronoiFilter generated to pass them (in strict order when addTarget ) to GPUImageVoronoiConsumerFilter

1.how to use it

    GPUImageOutput<GPUImageInput> *filter;
    GPUImagePicture *sourcePicture;
    UIImage * filteredImage;
    CGFloat temp = 0.5;
    GPUImagePicture * stillImage = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"lena.jpg"]];
    GPUImageJFAVoronoiFilter * jfa = [[GPUImageJFAVoronoiFilter alloc] init];
    [jfa setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
    [jfa setInitStep:temp];
    sourcePicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"voronoi_points2.png"]];
    [sourcePicture addTarget:jfa];
    [jfa useNextFrameForImageCapture];
    [sourcePicture processImage];
    [jfa useNextFrameForImageCapture];
    filteredImage = [jfa imageFromCurrentFramebuffer];
    //numPasses = 9
    for (int j=1; j<=9; j++) {
        temp = temp / 2;
        sourcePicture = [[GPUImagePicture alloc] initWithImage:filteredImage];
        [jfa setInitStep:temp];
        [sourcePicture addTarget:jfa];
        [jfa useNextFrameForImageCapture];
        [sourcePicture processImage];
        [jfa useNextFrameForImageCapture];
        filteredImage = [jfa imageFromCurrentFramebuffer];
    }
    filter = [[GPUImageVoronoiConsumerFilter alloc] init];
   [(GPUImageVoronoiConsumerFilter *)filter setSizeInPixels:CGSizeMake(1024.0, 1024.0)];
    sourcePicture = [[GPUImagePicture alloc] initWithImage:filteredImage];
    [stillImage addTarget:filter];
    [sourcePicture addTarget:filter];
    [filter useNextFrameForImageCapture];
    [stillImage processImage];
    [sourcePicture processImage];
    filteredImage = [filter imageFromCurrentFramebuffer];
   [self.selectedImageView setImage:filteredImage];
  1. the result effect in simulator ————————————— https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/lena_stillImage_result.png

3.the original stillImage and voronoi_points picture —————————————————————— https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/voronoi_points2.png https://github.com/ihgazni/voronoi_modified_GPUImage/blob/master/lena.jpg

Yogesh-MV commented 8 years ago

WhenI try to apply the "GPUImageVoronoiConsumerFilter" filter, my app get crashed. I am receiving the error "Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?". But I am already using the "useNextFrameForImageCapture", before applying process image state. Even though I am getting this crash. Could anyone please hep on this.