문제

I've written an own CIFilter kernel which is doing some image processing on the camera signal. It takes two arguments: Argument one is "inputImage" (the current camera image) argument 2 is "backgroundImage" which is being initialized with the first camera image.

The filter is supposed to work recursively. The result of the filter should be used as new "backgroundImage" in the next iteration. I am calculating a background image and some variances and therefore need the result from the previous render.

Unfortunately I cannot use the output CIImage of the CIFilter in the next iteration, because the memory load gets up and up. After 10 seconds of processing it ends up with 1.4GB of RAM usage. Using the filter in a standard manner (without recursion) memory management is fine.

How can I reuse the output of a filter as input in the next iteration? I've done a NSLog on the result image. Ant it told me

background {

CISampler:0x1002e0360 image {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
   FEPromise: 0x1013aa230 extent [0 0 1280 720]; DOD [0 0 1280 720]; filter MyFeatureDetectFilter: 0x101388dd0; kernel coreImageKernel; image {

CISampler:0x10139e200 image {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
   FEBufferImage: 0x10139bee0 metadata.colorspace: HDTV; extent: [0 0 1280 720]; format: BGRA_8; uid 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
}

After some seconds the log becomes sth. like

                            }                                                                                                                                                            
                         }                                                                                                                                                     
                       }                                                                                                                                                                                 
                     }                                                                                                                                                    
                   }                                                                                                                                                       

This tells me that CIImages are 'always' prototypes of the desired operation. And using them recursively adds just the "resulting CIImage 'prototype'" as input into the new 'prototype'. Over time the "rule" for rendering blows up into a huge structure of nested prototypes.

Is there any way to force CIImages to flatten the structure inside memory? I would be happy if I could do recursive processing, because this would blow up the power of QuartzCore to the extreme.

I tried the same in QuartzComposer. Connecting the output with the input works, but takes a lot of memory, too. After some time it crashes. Then I tried to use the Queue from QC and everything worked fine. What is the "xcode" equivalent of the QC Queue? Or is there any mechanism to rewrite my kernel to keep "results" in memory for the next iteration?

도움이 되었습니까?

해결책

It seems like what you're looking for is the CIImageAccumulator class. This allows you to use the output of a filter as its input on the next iteration.

Edit:

For an example of how to use it, you can check out this Apple sample code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top