简体   繁体   中英

Trouble generating a mask image; CISourceOverCompositing not working as expected

I'm basically trying to get the "Anonymous Faces Filter Recipe" example to work in the iOS simulator.

There are no errors or warnings, but it appears as though "CISourceOverCompositing" filter is not working as expected. The circles are being drawn on the maskImage destructively as opposed to additively. For example, if 5 faces are found, 5 circles are drawn but only the last is shown on the maskImage.

How can I make it so that each circle is drawn to the maskImage in an additive fashion?

Here is the code I'm using to build the mask:

// Create a green circle to cover the rects that are returned.
CIImage *maskImage = nil;
for (CIFeature *f in faces){
    CIVector *circleCenter = [CIVector vectorWithX:f.bounds.origin.x+f.bounds.size.width/2.0 Y:f.bounds.origin.y+f.bounds.size.height/2.0];
    CGFloat circleRadius = MIN([f bounds].size.width, [f bounds].size.height)/1.5;
    CIFilter *radialGradient = [CIFilter filterWithName:@"CIRadialGradient" keysAndValues:
                                @"inputRadius0", [NSNumber numberWithFloat:circleRadius],
                                @"inputRadius1", [NSNumber numberWithFloat:circleRadius+1.0f],
                                @"inputColor0", [CIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0],
                                @"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],
                                @"inputCenter", circleCenter, nil];
    CIImage *circleImage = [radialGradient valueForKey:@"outputImage"];
    if (maskImage == nil) {
        maskImage = circleImage;
    } else {
        maskImage = [[CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues:@"inputImage", circleImage, @"inputBackgroundImage",maskImage, nil] valueForKey:@"outputImage"];
    }
}

Unfortunately the source code found on the Anonymous Faces Filter Recipe did not compile or work right out of the box. The issue with the CISourceOverCompositing filter can be found with the inputColor1 parameter and the alpha channel. Replace the inputColor1 color with the following and you should be good to go:

@"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM