iOS无需相机UI即可通过前置摄像头获得脸部宽度

时间:2013-11-25 07:17:30

标签: ios avfoundation core-image ios-camera

Rightnow我正在开发一款应用程序,通过使用带AVFoundation和Core-image框架的前置摄像头来检测用户脸部和设备之间的距离。

对于面部检测,我从苹果网站获得了一个示例代码(squarecam)           https://developer.apple.com/LIBRARY/IOS/samplecode/SquareCam/Introduction/Intro.html

在此示例中,他们使用AvFoundation控制相机和核心 - 图像以使用相机UI检测脸部。   但我需要没有相机UI的这些过程。是否可以使用AVFoundation框架隐藏相机UI。

2 个答案:

答案 0 :(得分:0)

您可以使用UIImagePickerViewController并将showsCameraControls属性设置为NO,并使用cameraOverlayView提供您自己的用户界面。这是示例https://developer.apple.com/LIBRARY/IOS/samplecode/PhotoPicker/Introduction/Intro.html

或可以使用AVFoundation类,请参阅AVCamCaptureManagerAVCamRecorder类。这是Apple https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112

的演示

答案 1 :(得分:0)

如果我理解正确,您希望在仍然从相机获取视频时隐藏相机预览?

在这种情况下,我相信你可以继续使用squarecam中的代码,只需隐藏PreviewLayer。

你仍然会得到

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

所以你可以得到图像。

但是,我建议您找到Stachecam的示例代码,并查看用于实时面部检测的AVMetaDataOutput实现