我想从图像中检测牙齿,并希望用滑块将它们变白。
我找到了以下口腔检测代码。但是我应该如何检测确切的牙齿位置,以便我可以美白它们。这个有第三方吗?
// draw a CI image with the previously loaded face detection picture
CIImage* image = [CIImage imageWithCGImage:imageView.image.CGImage];
// create a face detector - since speed is not an issue now we'll use a high accuracy detector
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
// create an array containing all the detected faces from the detector
NSArray* features = [detector featuresInImage:image];
CGAffineTransform transform = CGAffineTransformMakeScale(1, -1);
transform = CGAffineTransformTranslate(transform, 0, -imageView.bounds.size.height);
for(CIFaceFeature* faceFeature in features)
{
// Get the face rect: Translate CoreImage coordinates 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];
faceView.layer.borderWidth = 1;
faceView.layer.borderColor = [[UIColor redColor] CGColor];
// get the width of the face
CGFloat faceWidth = faceFeature.bounds.size.width;
// add the new view to create a box around the face
[imageView addSubview:faceView];
if(faceFeature.hasMouthPosition)
{
// Get the mouth position translated to imageView UIKit coordinates
const CGPoint mouthPos = CGPointApplyAffineTransform(faceFeature.mouthPosition, transform);
// Create an UIView to represent the mouth, its size depend on the width of the face.
UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(mouthPos.x - faceWidth*MOUTH_SIZE_RATE*0.5,
mouthPos.y - faceWidth*MOUTH_SIZE_RATE*0.5,
faceWidth*MOUTH_SIZE_RATE,
faceWidth*MOUTH_SIZE_RATE)];
// make the mouth look nice and add it to the view
mouth.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.3];
//mouth.layer.cornerRadius = faceWidth*MOUTH_SIZE_RATE*0.5;
[imageView addSubview:mouth];
NSLog(@"Mouth %g %g", faceFeature.mouthPosition.x, faceFeature.mouthPosition.y);
}
}