面部检测后如何旋转图像? iOS版

时间:2014-01-21 03:12:25

标签: image ios7 detection

我试过旋转图像和视图,只查看或仅图像,但我没有我需要的视图。我只想在屏幕顶部使用面部图像,我可以旋转一个窗口,但我使用的代码不在AppDelegate中,而且我也不想旋转其他元素,我的代码在这里旋转所有视图。

 -(void)markFaces:(UIImageView *)facePicture
{
// draw a CI image with the previously loaded face detection picture
CIImage* image = [CIImage imageWithCGImage:facePicture.image.CGImage];

// create a face detector - since speed is not an issue 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];

// we'll iterate through every detected face.  CIFaceFeature provides us
// with the width for the entire face, and the coordinates of each eye
// and the mouth if detected.  Also provided are BOOL's for the eye's and
// mouth so we can check if they already exist.
for(CIFaceFeature* faceFeature in features)
{
    // get the width of the face
    CGFloat faceWidth = faceFeature.bounds.size.width;

    // create a UIView using the bounds of the face
    UIView* faceView = [[UIView alloc] initWithFrame:faceFeature.bounds];

    // add a border around the newly created UIView
    faceView.layer.borderWidth = 1;
    faceView.layer.borderColor = [[UIColor redColor] CGColor];
    faceView.backgroundColor = [UIColor blackColor];
    // add the new view to create a box around the face
    //[faceView setTransform:CGAffineTransformMakeScale(-1, -1)];

    [self.view addSubview:faceView];
    [self.view setTransform:CGAffineTransformMakeScale(-1, -1)]; // !!!!
}


-(void)faceDetector
{
// Load the picture for face detection
UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test1.jpeg"]];
// Draw the face detection image
[self.view addSubview:image];

// Execute the method used to markFaces in background
 [self performSelectorInBackground:@selector(markFaces:) withObject:image];

// flip image on y-axis to match coordinate system used by core image
[image setTransform:CGAffineTransformMakeScale(1, -1)];//!!

}

0 个答案:

没有答案