title: Teeth whitening iOS
body: <p>I want to detect the teeth from an image and want to whiten them with slider. </p>
  
  <p>I found the following code for mouth detection. But how should I detect the exact  teeth location so that I could whiten them. Is there any third party for this?</p>
  
  <pre><code>// 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);
          }
      }
  </code></pre>