我的故事板中有一个带有几个UIButton的视图控制器.其中一个激活子图层中显示的AVFoundation相机预览图层:
captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:captureVideoPreviewLayer];
Run Code Online (Sandbox Code Playgroud)
这是正常工作,除了预览图层呈现在我的按钮之上,因此即使按钮仍然可点击,用户也无法看到它们.有没有一种简单的方法将子图层放在按钮下面?或者在图层中提升按钮的简单方法?非常感谢!
我需要与应用程序即时心率相同的功能.
基本过程要求用户:
这可以通过打开闪光灯并在血液通过食指时观察光线变化来实现.
如何从视频捕获中获取亮度数据?我应该在哪里寻找这个?我仔细查看了课程,AVCaptureDevice但没有找到任何有用的东西.
我也发现AVCaptureDeviceSubjectAreaDidChangeNotification,这会有用吗?
我正在开发一个增强现实应用程序位置,我需要获得视野[FOV](我只是在方向改变时更新值,所以我正在寻找一种方法,当我调用它时可以得到这个值)
目标是使"程度统治者"与现实相关,如下所示:

我已经AVCaptureSession用来显示相机流; 以及与a相连的路径CAShapeLayer来绘制标尺.这工作得很好,但现在我必须使用视场值将我的元素放在正确的位置(例如,选择160°和170°之间的正确空间!).
实际上,我用这些来源硬编码这些值:https://stackoverflow.com/a/3594424/3198096(特别感谢@ hotpaw2!)但我不确定它们是完全精确的,这不是处理iPhone 5等我无法从官方渠道获取价值(Apple!),但有一个链接显示我认为我需要的所有iDevice的值(4,4S,5,5S):AnandTech | 关于iphone 5s相机改进的一些想法.
注意:经过个人测试和其他在线研究,我很确定这些值是不准确的!这也迫使我使用外部库来检查我使用哪种型号的iPhone来手动初始化我的FOV ......我必须检查所有支持设备的值.
看完这篇文章后:iPhone:实时视频颜色信息,焦距,光圈?,我试图exif data从建议的AVCaptureStillImageOutput 获得.之后,我可以从exif数据中读取焦距,然后通过公式计算水平和垂直视野!(或者可以直接获得如下所示的FOV:http://www.brianklug.org/2011/11/a-quick-analysis-of-exif-data-from-apples-iphone-4s-camera-samples/ - -
注意:经过一定数量的更新后,似乎我们无法直接从exif获取视野!)
来自:http://iphonedevsdk.com/forum/iphone-sdk-development/112225-camera-app-working-well-on-3gs-but-not-on-4s.html和修改后的EXIF数据无法保存正确
这是我正在使用的代码:
AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (camera != nil)
{
captureSession = [[AVCaptureSession alloc] init];
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:nil];
[captureSession addInput:newVideoInput];
captureLayer = [[AVCaptureVideoPreviewLayer alloc] …Run Code Online (Sandbox Code Playgroud) 我的团队正在开发一套用于条形码扫描,ID扫描和OCR的SDK .我们使用设备的相机AVCaptureSession来获取我们执行处理的视频帧.
我们正在探索新的iOS 9多任务处理功能Slide Over和Split View.
Apple建议选择退出这些功能,以相机为中心的应用程序,其中使用整个屏幕进行预览和快速捕捉片刻是一个主要功能(参考).这是他们的示例应用程序AVCam中使用的方法.
但是,我们的客户可能拥有不属于此类别的应用程序(例如移动银行应用程序),因此我们无法强制他们选择退出,而是需要处理SDK中的新功能.我们正在探索最好的方法,因为目前的文档并没有真正告诉我们该做什么.
我们使用简单的Camera示例应用程序来分析用例.该示例应用程序可在Github上获得,它是从iOS 9 Beta 5开发的.
从示例应用程序中,可以清楚地看到使用"幻灯片放映"时以及使用"拆分视图"时发生的系统事件.
UIApplicationWillResignActiveNotification和AVCaptureSessionDidStopRunningNotificationUIApplicationWillEnterForegroundNotification和AVCaptureSessionDidStopRunningNotification之后立即UIApplicationWillResignActiveNotification.AVCaptureSessionDidStopRunningNotification因此,根据经验,AVCaptureSession当使用"幻灯片放大"或"拆分视图"时,它会立即停止.
令人困惑的是UIImagePickerController,我们的示例应用程序也支持它,表现出完全不同的行为.
UIImagePickerController当应用程序进入幻灯片放映/拆分视图时,它不会停止,而是完全正常运行.通常可以在Split View中拍照.实际上,两个应用程序(两者都存在UIImagePickerController)可以并行工作,UIImagePickerController活动应用程序处于活动状态.(你可以通过运行我们的示例应用程序和联系人应用程序 - >新联系人 - >添加照片来尝试
考虑到这一切,我们的问题如下:
如果AVCaptureSession在使用"幻灯片放大"和"拆分视图"时立即暂停,是否最好监控AVCaptureSessionDidStopRunningNotification并向用户显示"Camera Paused"消息,以便他清楚地知道应用程序没有执行扫描?
为什么行为UIImagePickerController不同AVCaptureSession?
我们可以期待Apple比未来beta版本的AVCaptureSession变化行为更符合UIImagePickerController吗?
我目前正在开发一个iOS应用程序,它将CoreImage应用于相机提要以拍摄照片和视频,而且我遇到了一些障碍.
到目前为止,我一直在使用AVCaptureVideoDataOutput获取样本缓冲区并使用CoreImage对其进行操作,然后显示简单的预览,并使用它来捕获照片并保存它们.
当我尝试实现视频录制时,通过在从AVCaptureVideoDataOutput接收视频时将SampleBuffers写入视频,它的帧速率非常慢(可能是因为正在进行的其他图像相关处理).
所以我想知道,AVCaptureVideoDataOutput和AVCaptureMoveFileOutput可以同时在同一个AVCaptureSession上运行吗?
我快速给了它,发现当我添加额外输出时,我的AVCaptureVideoDataOutput停止接收信息.
如果我能让它工作,我希望这意味着我可以简单地使用第二个输出以高帧率录制视频,并在用户停止录制后对视频进行后期处理.
任何帮助将不胜感激.
我的应用程序设置为使用AVCaptureSession从摄像机录制视频,但是没有音频.如何录制音频然后将其添加到文件的videoOutput中我需要做什么?这是录制视频的代码:
AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetMedium;
CALayer *viewLayer = self.vImagePreview.layer;
NSLog(@"viewLayer = %@", viewLayer);
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
AVCaptureDevice *device = [self frontFacingCameraIfAvailable];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput …Run Code Online (Sandbox Code Playgroud) objective-c audio-recording ios avcapturesession avcapturedevice
抓取可视屏幕的裁剪UIImage时,我的AVCaptureVideoPreviewLayer方法出现问题.目前它正在工作,但没有输出我需要的正确作物.
我试图输出一个正方形,但它(通过它的外观)似乎给出了完整的高度和压缩图像.
前一图像显示LIVE屏幕,后一图像显示按下捕获按钮后的图像.您可以看到它已垂直更改以适合方形但高度未垂直裁剪.

捕获图像代码
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
}
}];
Run Code Online (Sandbox Code Playgroud)
裁剪代码
- (void) processImage:(UIImage *)image { //process captured image, crop, resize and rotate
haveImage = YES;
CGRect deviceScreen = _previewLayer.bounds;
CGFloat width = deviceScreen.size.width;
CGFloat height = deviceScreen.size.height;
NSLog(@"WIDTH %f", width); // Outputing 320
NSLog(@"HEIGHT %f", height); // Outputting 320
UIGraphicsBeginImageContext(CGSizeMake(width, width));
[image drawInRect: CGRectMake(0, 0, width, width)];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); …Run Code Online (Sandbox Code Playgroud) 我使用此代码在iOS自定义相机应用程序中实现Tap-to-Focus,但它无法正常工作.这是代码
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touchPer = touches.anyObject() as UITouch
let screenSize = UIScreen.mainScreen().bounds.size
var focus_x = touchPer.locationInView(self.view).x / screenSize.width
var focus_y = touchPer.locationInView(self.view).y / screenSize.height
if let device = captureDevice {
if(device.lockForConfiguration(nil)) {
device.focusMode = AVCaptureFocusMode.ContinuousAutoFocus
device.focusPointOfInterest = CGPointMake(focus_x, focus_y)
device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure
device.unlockForConfiguration()
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的AVCaptureSession运行,以在我的应用程序中获取相机并拍照.如何使用UIGestureRecognizer相机实现"捏缩放"功能?
我不知道这个问题是关于自动布局还是我做错了什么.
我有一个UIViewController和一个UIView内部.
而我正在使用AVCaptureSession相机视图.
问题是,当我在摄像机视图中加载视图时,它不会填充该视图,所以我在左侧和右侧有间隙.
我要做的是UIView用相机填满整个.
这是我的代码:
...
@IBOutlet weak var camView: UIView!
var previewLayer : AVCaptureVideoPreviewLayer!
override func viewDidLoad() {
...
previewLayer = AVCaptureVideoPreviewLayer.layerWithSession(session) as! AVCaptureVideoPreviewLayer
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.frame = self.camView.layer.bounds
self.camView.layer.addSublayer(previewLayer)
session.startRunning()
Run Code Online (Sandbox Code Playgroud) avcapturesession ×10
ios ×10
objective-c ×4
camera ×3
avfoundation ×2
iphone ×2
swift ×2
avcapture ×1
calayer ×1
fieldofview ×1
ios8 ×1
ios9 ×1
multitasking ×1
uibutton ×1
uiview ×1