我知道iOS 5.0上的核心图像supports facial detection(another example of this),它给出了脸部的整体位置以及眼睛和嘴巴在该脸部内的位置。如何识别iOS上脸部的嘴和牙齿?
但是,我想细化这个位置来检测嘴里的牙齿和牙齿的位置。我的目标是在用户的嘴和牙齿上放置一个护嘴。
有没有办法在iOS上完成此操作?
我知道iOS 5.0上的核心图像supports facial detection(another example of this),它给出了脸部的整体位置以及眼睛和嘴巴在该脸部内的位置。如何识别iOS上脸部的嘴和牙齿?
但是,我想细化这个位置来检测嘴里的牙齿和牙齿的位置。我的目标是在用户的嘴和牙齿上放置一个护嘴。
有没有办法在iOS上完成此操作?
我指出my blog该教程有问题。
部分5)调整坐标系:你需要改变窗口和图像的坐标,但这是你不应该做的。你不应该改变你的视图/窗口(在UIKit坐标中)以与教程中的CoreImage坐标相匹配,你应该采取相反的措施。
这是相关的代码做到这一点的一部分:
(你可以从heremy blog post或直接获取整个样本代码,它包含了这一点,并使用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
),你只需将你的东西放在或靠近它。
这个特定的距离可以通过实验来计算,并且必须相对于由眼睛和嘴巴形成的三角形。我会用很多的面孔,如果可以计算这个距离(微博头像?)
希望它能帮助:)
谢谢纳乔,它非常有用:) – javienegas 2013-12-12 22:02:33
编辑的问题,使他们更具可读性和帮助社区是一回事,但完全重新编写他们并添加不存在的句子是另一回事。 @Brad Larson加入'我知道iOS 5上的核心图像支持面部检测'。用户可能知道这一点,但你怎么能这样认为。我指出这一点的唯一原因是因为我在回答中提到了这个事实,这使得我的答案看起来像我根本没有读过这个问题! – bandejapaisa 2012-06-16 17:29:23
@bandejapaisa - 提问者链接到iOS 5.0上的Core Image教程(在链接的博客文章的标题中声明),所以我想表达该链接的情况,以防将来在某些时候死亡。然后他们表示这不足以满足他们的需求,所以我澄清了这个问题,以说明为什么Core Image不是一个好的解决方案。鉴于他们提供的链接的内容,我觉得这是一个合理的补充。 – 2012-06-17 00:31:54