我发现此link将图像放在脸部点上。就像我需要检测眼睛并在那里放置图像一样?如何使用CIFeatures在眼睛和嘴巴上放置图像
为了简单起见,我需要在人眼上放置一个图像。我该怎么做?任何提示将不胜感激!
我发现此link将图像放在脸部点上。就像我需要检测眼睛并在那里放置图像一样?如何使用CIFeatures在眼睛和嘴巴上放置图像
为了简单起见,我需要在人眼上放置一个图像。我该怎么做?任何提示将不胜感激!
for (CIFaceFeature *ff in features) {
// find the correct position for the square layer within the previewLayer
// the feature box originates in the bottom left of the video frame.
// (Bottom right if mirroring is turned on)
CGRect faceRect = [ff bounds];
// flip preview width and height
CGFloat temp = faceRect.size.width;
faceRect.size.width = faceRect.size.height;
faceRect.size.height = temp;
temp = faceRect.origin.x;
faceRect.origin.x = faceRect.origin.y;
faceRect.origin.y = temp;
// scale coordinates so they fit in the preview box, which may be scaled
CGFloat widthScaleBy = previewBox.size.width/clap.size.height;
CGFloat heightScaleBy = previewBox.size.height/clap.size.width;
faceRect.size.width *= widthScaleBy;
faceRect.size.height *= heightScaleBy;
faceRect.origin.x *= widthScaleBy;
faceRect.origin.y *= heightScaleBy;
if (isMirrored)
faceRect = CGRectOffset(faceRect, previewBox.origin.x + previewBox.size.width - faceRect.size.width - (faceRect.origin.x * 2), previewBox.origin.y);
else
faceRect = CGRectOffset(faceRect, previewBox.origin.x, previewBox.origin.y);
你可以得到脸部RECT但ü需要精细的图像
这将帮助ü获得每个位置
-(void)markFaces:(CIImage *)image
{
// draw a CI image with the previously loaded face detection picture
@autoreleasepool {
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracy forKey:CIDetectorAccuracyHigh]];
// create an array containing all the detected faces from the detector
NSArray* features = [detector featuresInImage:image];
NSLog(@"The Address Of CIImage In: %p %s",image,__FUNCTION__);
NSLog(@"Array Count %d",[features count]);
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if([features count]==0)
{
//No image is present
}
else
{
for(CIFaceFeature* faceFeature in features)
{
if(faceFeature.hasMouthPosition)
{
// Your code based on the mouth position
}
if (faceFeature.hasLeftEyePosition) {
// Write your code Note: points are mirrored point so u need to take care of that
}
if (faceFeature.hasRightEyePosition) {
// Write your code Note: points are mirrored point so u need to take care of that
}
}
}
}
苹果iOS 5及更高版本的眼球,在内部提供了这种功能。
请参阅该苹果文档中有关同:
在这个例子中,他们都在做同样的,因为你需要 - 面部及眼部检测。
希望这会对你有所帮助。
感谢您的回复。我会试一试,让你知道! – 3DNewbie
@ 3DNewbie永远欢迎 – Spynet
我已经完成了检测眼睛。但我的问题是在眼睛上画一个覆盖图像?如何做到这一点?即不规则的圆形或正方形,我需要在眼睛上覆盖图像。 – 3DNewbie