2013-06-24 38 views
0

我想根據GPUImage示例中的FilterShowcase應用程序使用GPUImageChromaKeyFilter,但顯然我缺少一些東西,因爲它崩潰。GPUImageAlphaBlendFilter - 不完整的篩選器FBO:36054

這裏是我的代碼:

videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack]; 
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait; 


    GPUImageChromaKeyFilter *filter = [[GPUImageChromaKeyFilter alloc] init]; 
    [filter setColorToReplaceRed:0.0 green:1.0 blue:0.0]; 
    [filter prepareForImageCapture]; 


    videoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 480)]; 
    [self.view addSubview:videoView]; 


    UIImage *inputImage = [UIImage imageNamed:@"bedroom.jpeg"]; 
    GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES]; 
    [sourcePicture processImage]; 
    [sourcePicture addTarget:filter]; 





    [sourcePicture removeTarget:filter]; 
    [videoCamera removeTarget:filter]; 
    [videoCamera addTarget:filter]; 

    GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
    blendFilter.mix = 1.0; 
    [sourcePicture addTarget:blendFilter]; 
    [filter addTarget:blendFilter]; 





    [blendFilter addTarget:videoView]; 
    [videoCamera startCameraCapture]; 

當我運行它,它只是告訴這個:

2013年6月24日15:24:45.369 GPUImage測試[1284:1703] *斷言故障 在 - [GPUImageAlphaBlendFilter createFilterFBOofSize:], /用戶/你好/桌面/ xcode中/ GPUImage測試/ GPUImage /框架/來源/ GPUImageFilter.m:369

2013年6月24日15:24:45.383 GPUImage試驗[1284:1703] *終止應用程序 由於未捕獲的異常 'NSInternalInconsistencyException',原因: '不完全濾波器FBO:36054'

*首先扔調用堆棧:

(0x3134f3e7 0x391d9963 0x3134f29d 0x31c25fa3 0xc9563 0xd608d 0xc8b3d 0xc9885 0xdaa63 0xcc11f 0xdb39f 0xca07b 0xcc153 0xd266f 0xd2dbb 0xd3f35 0x395f3793 0x395f6b3b 0x395f467d 0x395f7613 0x395f77d9 0x3961b7f1 0x3961b684)

的libC++ abi.dylib:終止叫做拋出異常

有誰看到我做錯了什麼?

在此先感謝。

+0

看起來像問題可能是該過濾器設置爲混合過濾器的來源 – rezand

回答

4

-processImage是異步的。當您調用它時,它不會運行到完成狀態,因此您需要維護過濾器結構直到完成處理。

這意味着您之後不能再調用-removeTarget:,也意味着您需要將您的sourcePicture實例掛起作爲實例變量,直到處理完成。否則,它將在此方法結束時被釋放,並將導致其輸出結果被取消。

想要設置過濾器鏈並在正確配置所有內容時運行-processImage。只要您需要過濾的結果,您就需要維護源圖片。

+0

天啊!非常感謝你,它的工作原理;) – user2006934