我發現此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