我是iOS编程新手,我搜索了很多核心图像链接,答案和教程,但我仍然不完全理解。我有一个测试应用程序谁有按钮,简单的东西,我有图像,当我按下一些过滤器按钮,它使过滤器和显示它。
CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
CIFilter *colorControls = [CIFilter filterWithName:@"CIColorControls"];
[colorControls setValue:inputImage forKey:@"inputImage"];
[colorControls setValue:[NSNumber numberWithFloat:0.5f] forKey:@"inputSaturation"];
[colorControls setValue:[NSNumber numberWithFloat:0.8f] forKey:@"inputContrast"];
[colorControls setValue:[NSNumber numberWithFloat:0.4f] forKey:@"inputBrightness"];
CIImage *outputImage = [colorControls valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
theImageView.image = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];
现在我想要一个可以检测眼睛和嘴巴并在其周围画出矩形或圆形的按钮,无论什么颜色和颜色都没关系。我来了
- (IBAction)detectFace:(id)sender
{
CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSArray* features = [detector featuresInImage:inputImage];
for (CIFaceFeature *faceFeature in features){}
}
现在我遇到了问题(我不确定这是不是正确的开始)。请帮助我想知道下一步该怎么做..谢谢你提前
答案 0 :(得分:1)
怎么样(没有编译它,但应该关闭):
for (CIFaceFeature *faceFeature in features){
CGRect faceRect = faceFeature.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
CGContextAddRect(context, faceRect);
CGContextDrawPath(context, kCGPathStroke);
}