【问题标题】:UIImagePickerController disable iPhone 4S face detection (iOS 5.1)UIImagePickerController 禁用 iPhone 4S 人脸检测 (iOS 5.1)
【发布时间】:2012-09-01 04:03:54
【问题描述】:

我目前正在开发一个 iPhone 应用程序,它使用带有自定义叠加层的 UIImagePickerController 来拍照。

很遗憾,我无法直接使用 iPhone 4S,但一些测试人员报告说相机选择器在面部周围绘制了一个绿色边框,就像这样:http://cdn.iphonehacks.com/wp-content/uploads/2012/03/camera_faces.jpg

由于此应用的性质,这是不可取的。

对 UIImagePickerController 文档的彻底搜索没有发现任何东西,同样,我在此处可以找到的与面部检测相关的所有内容都提供了有关如何使用 CIDetector 或类似内容的说明。

如何在我的 UIImagePickerController 中禁用人脸检测?

这是我的 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];

【问题讨论】:

    标签: ios cocoa-touch uiimagepickercontroller face-detection


    【解决方案1】:

    试试这个 -->

    假设我们有一个 UIViewController 命名为 - RecordVideoViewController

    实现 -- 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
    

    实现 -- 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];
     }
    }
    

    实现这段代码吧,希望对你有帮助。

    【讨论】:

      【解决方案2】:

      看看这篇文章。这里有一些提示,但仍然无法在 Apple 的有关此 API 的文档之外找到太多信息。 Proper usage of CIDetectorTracking

      【讨论】:

        猜你喜欢
        • 2015-12-23
        • 2017-11-14
        • 2012-04-15
        • 2013-07-16
        • 2016-06-02
        • 2013-04-14
        • 2012-02-25
        • 1970-01-01
        相关资源
        最近更新 更多