Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
769 views
in Technique[技术] by (71.8m points)

cocoa touch - UIImagePickerController disable iPhone 4S face detection (iOS 5.1)

I am currently developing an iPhone app that makes use of a UIImagePickerController with a custom overlay to take photos.

Unfortunately I do not have direct access to an iPhone 4S but several testers have reported that the camera picker is drawing a green border around faces exactly like this: http://cdn.iphonehacks.com/wp-content/uploads/2012/03/camera_faces.jpg

Due to the nature of this app this is not desirable.

A thorough search of the UIImagePickerController docs didn't turn up anything and similarly everything I could find on here relating to face detection was providing instructions in how to use a CIDetector or similar.

How can I disable face detection in my UIImagePickerController?

Here is my initialisation code for the UIImagePickerController:

UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];

[cameraPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[cameraPicker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
if ([UIImagePickerController isFlashAvailableForCameraDevice:cameraPicker.cameraDevice]){
    [cameraPicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
}
[cameraPicker setShowsCameraControls:NO];
[cameraPicker setCameraOverlayView:cameraOverlayView];

cameraPicker.delegate = self;
[self presentModalViewController:cameraPicker animated:YES];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try This -->

Lets Say We have one UIViewController named as - RecordVideoViewController

Implementation of -- RecordVideoViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface RecordVideoViewController : UIViewController
- (IBAction)recordAndPlay:(id)sender;

-(BOOL)startCameraControllerFromViewController:(UIViewController*)controllerusingDelegate:
(id)delegate;   

-(void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error
contextInfo(void*)contextInfo; 
@end

Implementation of -- RecordVideoViewController.m

- (IBAction)recordAndPlay:(id)sender {

[self startCameraControllerFromViewController:self usingDelegate:self];

}

-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                             usingDelegate:(id )delegate 
{
// 1 - Validattions
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ==
NO)  
    || (delegate == nil)
    || (controller == nil)) {
    return NO;
}
// 2 - Get image picker
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
// 3 - Display image picker
[controller presentViewController:cameraUI animated:YES completion:nil];
 return YES;
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
 (NSDictionary *)info {
 NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
 [self dismissViewControllerAnimated:YES completion:nil];
 // Handle a movie capture
 if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == 
 kCFCompareEqualTo) {
     NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];

     if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
         UISaveVideoAtPathToSavedPhotosAlbum(moviePath,
         self,@selector(video:didFinishSavingWithError:contextInfo:),nil); 
     }
   }
 }

 -(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:
 (void*)contextInfo {  
   if (error) {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Video Saving
     Failed" 
      delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [alert show];
   } else {
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video Saved" message:@"Saved To
     Photo Album" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];  
    [alert show];
 }
}

Implement This code it, i hope this will help you .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...