![](/img/trans.png)
[英]how can i draw square or circle arround eyes and mouth in ciimage iOS
[英]How can I recognize a mouth and teeth within a face on iOS?
我在博客中指出教程有问题。
第5部分)调整坐标系 :说您需要更改窗口和图像的坐标,但这是您不应该做的。 您不应该像在教程中那样更改视图/窗口(在UIKit坐标中)以匹配CoreImage坐标,您应该采取相反的方式。
这是与此相关的代码部分:
(您可以从我的博客文章或直接从这里获得完整的示例代码。它包含此示例和使用CIFilters的其他示例:D)
// Create the image and detector
CIImage *image = [CIImage imageWithCGImage:imageView.image.CGImage];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:...
options:...];
// CoreImage coordinate system origin is at the bottom left corner and UIKit's
// is at the top left corner. So we need to translate features positions before
// drawing them to screen. In order to do so we make an affine transform
CGAffineTransform transform = CGAffineTransformMakeScale(1, -1);
transform = CGAffineTransformTranslate(transform,
0, -imageView.bounds.size.height);
// Get features from the image
NSArray *features = [detector featuresInImage:image];
for(CIFaceFeature* faceFeature in features) {
// Get the face rect: Convert CoreImage to UIKit coordinates
const CGRect faceRect = CGRectApplyAffineTransform(
faceFeature.bounds, transform);
// create a UIView using the bounds of the face
UIView *faceView = [[UIView alloc] initWithFrame:faceRect];
...
if(faceFeature.hasMouthPosition) {
// Get the mouth position translated to imageView UIKit coordinates
const CGPoint mouthPos = CGPointApplyAffineTransform(
faceFeature.mouthPosition, transform);
...
}
}
一旦你得到嘴巴位置( mouthPos
),你只需将你的东西放在它上面或附近。
该特定距离可以通过实验计算,并且必须相对于由眼睛和嘴形成的三角形。 如果可能的话,我会用很多面孔计算这个距离(推特头像?)
希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.