gpt4 book ai didi

ios - 如何在 iOS 中使用核心图像准确检测图像中的人脸?

转载 作者:行者123 更新时间:2023-12-03 19:51:21 26 4
gpt4 key购买 nike

在我的应用程序中,我需要准确检测图像的脸部,但我没有得到准确的输出。我使用了 coreimage 框架。我在其他地方没有得到右眼位置、左眼位置和嘴部位置,甚至也没有检测到微笑。

这是我的示例代码。

- (void)drawRect
{
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

CIImage *img=[CIImage imageWithCGImage:imageView.image.CGImage];
NSArray* features = [detector featuresInImage:img];

for (CIFaceFeature *feature in features)
{
CGRect faceRect = feature.bounds;

UIView* face = [[UIView alloc] initWithFrame:faceRect];

[face setBackgroundColor:[[UIColor yellowColor] colorWithAlphaComponent:0.4]];
[imageView addSubview:face];

if(feature.hasLeftEyePosition)
{
UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.leftEyePosition.x,feature.leftEyePosition.y, 20, 20)];
[eye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.2]];
[eye setCenter:feature.leftEyePosition];
[mainView addSubview:eye];

}

if(feature.hasRightEyePosition)
{
UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.rightEyePosition.x, feature.rightEyePosition.y, 20, 20)];
[eye setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.2]];
[eye setCenter:feature.rightEyePosition];
[mainView addSubview:eye];

}

if(feature.hasMouthPosition)
{
UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(feature.mouthPosition.x, feature.mouthPosition.y, 20, 20)];
[mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.2]];
[mouth setCenter:feature.mouthPosition];
[mainView addSubview:mouth];

}
if(feature.hasSmile)
{
NSLog(@"you are smiling");
}

}

}

最佳答案

在y轴上翻转图像以匹配核心图像使用的坐标系,以便获得准确的位置

关于ios - 如何在 iOS 中使用核心图像准确检测图像中的人脸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19944723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com