- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用 AVCaptureDevice
实现自定义相机,这需要自动对焦和曝光才能很好地工作。我正在使用以下代码来进行相机初始化
- (void) initializeCamera {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) { // authorized
[self.captureVideoPreviewLayer removeFromSuperlayer];
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
[self removeDeviceObserverForFocus];
self.captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[self addDeviceObserverForFocus];
NSError *error = nil;
[self.captureDevice lockForConfiguration:nil]; //you must lock before setting torch mode
[self.captureDevice setSubjectAreaChangeMonitoringEnabled:YES];
[self.captureDevice unlockForConfiguration];
//Capture layer
self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
self.captureVideoPreviewLayer.bounds = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));
self.captureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(self.captureVideoPreviewLayer.bounds), CGRectGetMidY(self.captureVideoPreviewLayer.bounds));
[self.captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
self.captureVideoPreviewLayer.connection.enabled = YES;
[self.viewCamera.layer insertSublayer:self.captureVideoPreviewLayer atIndex:0];
//Capture input
self.captureInput = [AVCaptureDeviceInput deviceInputWithDevice:self.captureDevice error:&error];
if (!self.captureInput) {
[self capturePhoto];
}
else {
if ([self.captureSession canAddInput:self.captureInput]) {
[self.captureSession addInput:self.captureInput];
}
}
self.captureOutput = [[AVCaptureStillImageOutput alloc] init];
[self.captureOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
[self.captureSession addOutput:self.captureOutput];
//THIS LINE
[self.captureSession setSessionPreset:AVCaptureSessionPresetPhoto];
// setup metadata capture
AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
CGRect visibleMetadataOutputRect = [self.captureVideoPreviewLayer metadataOutputRectOfInterestForRect:self.vwCamera.bounds];
metadataOutput.rectOfInterest = visibleMetadataOutputRect;
[self.captureSession addOutput:metadataOutput];
dispatch_async(dispatch_get_main_queue(), ^{
[self.captureSession startRunning];
});
}
else if(status == AVAuthorizationStatusNotDetermined){ // not determined
//Try for getting permission
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
[self performSelectorOnMainThread:@selector(initializeCamera) withObject:nil waitUntilDone:NO];
}];
}
}
- (void)removeDeviceObserverForFocus {
@try {
while ([self.captureDevice observationInfo] != nil) {
[self.captureDevice removeObserver:self forKeyPath:@"adjustingFocus"];
}
}
@catch (NSException *exception) {
NSLog(@"Exception");
}
@finally {
}
}
- (void)addDeviceObserverForFocus {
[self.captureDevice addObserver:self forKeyPath:@"adjustingFocus" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if( [keyPath isEqualToString:@"adjustingFocus"] ){
BOOL adjustingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
if (adjustingFocus) {
[self showFocusSquareAtPoint:self.viewCamera.center];
}
}
}
为了通过相机的移动来监控焦点,我正在执行以下操作..
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(avCaptureDeviceSubjectAreaDidChangeNotification:) name:AVCaptureDeviceSubjectAreaDidChangeNotification object:nil];
#pragma mark - AVCaptureDeviceSubjectAreaDidChangeNotification
-(void)avCaptureDeviceSubjectAreaDidChangeNotification:(NSNotification *)notification{
CGPoint devicePoint = CGPointMake( 0.5, 0.5 );
[self focusWithMode:AVCaptureFocusModeContinuousAutoFocus exposeWithMode:AVCaptureExposureModeContinuousAutoExposure atDevicePoint:devicePoint monitorSubjectAreaChange:NO];
[self showFocusSquareAtPoint:self.vwCamera.center];
}
- (void)focusWithMode:(AVCaptureFocusMode)focusMode exposeWithMode:(AVCaptureExposureMode)exposureMode atDevicePoint:(CGPoint)point monitorSubjectAreaChange:(BOOL)monitorSubjectAreaChange
{
dispatch_async( dispatch_get_main_queue(), ^{
AVCaptureDevice *device = self.captureDevice;
NSError *error = nil;
if ( [device lockForConfiguration:&error] ) {
// Setting (focus/exposure)PointOfInterest alone does not initiate a (focus/exposure) operation.
// Call -set(Focus/Exposure)Mode: to apply the new point of interest.
if ( device.isFocusPointOfInterestSupported && [device isFocusModeSupported:focusMode] ) {
device.focusPointOfInterest = point;
device.focusMode = focusMode;
}
if ( device.isExposurePointOfInterestSupported && [device isExposureModeSupported:exposureMode] ) {
device.exposurePointOfInterest = point;
device.exposureMode = exposureMode;
}
device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange;
[device unlockForConfiguration];
}
else {
NSLog( @"Could not lock device for configuration: %@", error );
}
} );
}
当我使用这个[self.captureSession setSessionPreset:AVCaptureSessionPresetPhoto];
如果我将相机预设更改为 AVCaptureSessionPresetHigh
等其他设置,自动对焦和曝光将无法按预期正常工作。
谁遇到过这样的情况吗?
谢谢你的帮助。
最佳答案
您想拍照或录制视频吗?因为高预设是针对视频的,曝光和对焦的工作方式不同(我相信)。以下是文档中有关不同预设的信息 - AVCaptureSessionPresets
关于iOS - AVCaptureDevice - 自动对焦和相机捕捉曝光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688627/
如何知道 WM_DEVICECHANGE 的到来? WndProc 被覆盖。我收到了所有消息,但没有一条是 WM_DEVICECHANGE 类型的。 RegisterDeviceNotificatio
我想创建一个滚动的表面列表框,它会在拖动完成后自动捕捉到一个位置,以便屏幕上的中心项目在视口(viewport)中居中。 我已经得到了中心项,但现在像往常一样,WPF 处理大小、屏幕位置和偏移量的方式
如果我有一个使用步长的范围 slider ,例如从 0 到 100,步长为 5,然后我在该范围之间有一个随机值,比如说 56,我如何确定最接近的捕捉值 (55) 是多少? 我正在考虑向前和向后循环,直
我想添加到模块记录器中的所有功能。我想记录函数的“开始”时间和“结束”时间。这样我就可以获得每个函数(同步函数)的执行时间。 但我不知道如何让它工作.. =(我不想以某种动态方式重写函数 - 我想在将
我正在编写一个 C# 应用程序,如果文件已被某个进程使用,我必须在其中显示一条消息,如果该文件不存在,则应用程序需要显示另一条消息。 像这样: try { //Code to open a f
所以我正在使用城市词典 api,他们的术语可以链接到其他使用 [term] 和 api 的框,我想使它们实际上在 markdown 中超链接,即 term所以我尝试制作一个替换正则表达式来做到这一点我
我有一个使用鼠标滚轮 jQuery 插件的水平滚动网站。滚动有效,但我想将每个“文章”捕捉到文档的左侧,这样一旦停止滚动,它就不会停留在一半的位置。 我目前的标记: CSS #viewport { w
我需要在 windows 上录制声音。我需要写信来传输我从演讲者那里听到的内容。我可以依赖什么方法/API? 最佳答案 您可以使用 DirectSound ;可以找到 sample here这是针对麦
for ii = 1:2:2*de.nP G=[one, aux3(:,ii), aux3(:,ii) - aux2(:,ii),aux3(:,ii+1) - a
您好,感谢阅读。我是编程、C# 和套接字编程方面的新手。在我的代码中,我尝试发现问题以在我的应用程序中提供容错能力。以下内容: catch (ArgumentNullException
我有一个函数可以运行用户生成的正则表达式。但是,如果用户输入了一个不会运行的正则表达式,那么它就会停止并跌倒。我试过将行包装在 Try/Catch block 中,但是没有任何反应。 如果有帮助,我正
嵌套的 Try/Catch 是否表示您的编码不干净?我想知道,因为在我的 catch 中,我正在调用另一个方法,如果失败,我会收到另一个运行时错误,所以我很想再次使用另一个 try/catch 将这些
我不知道如何放置一个相对于其同级路径边界框的路径。想象一个像窗口一样的盒子,我想在它的右上角放一个关闭按钮。这是在变换窗口(缩放 3 倍)后组合在一起的框和关闭按钮: 我只是在
我正在尝试使用 UISlider 实现某种形式的捕捉或步骤。我编写了以下代码,但它并没有像我希望的那样顺利。它可以工作,但是当我向上滑动它时,它会向右移动 5 个点,使手指不在“滑动圆”的中心 这是我
目前,我使用 Snap SVG 创建一个小型建模工具。 var p = Snap.path(pathString).attr({fill:'none', stroke:'black', strokeW
我希望能够使用 Snap SVG 将一组集合作为一个组进行拖动。到目前为止,我只能将子集(矩形和文本框)作为一个项目进行拖动,但我想要实现的是集体“表格”是可拖动的,而其中的字段仍保留为单独的形状,因
我有一段代码可以像这样抛出和捕获错误 try { } catch (e: FooException) { } catch (e: BarException) { } finally { } 并且有一些
我定义了一个自定义错误处理程序,它捕获所有异常并将它们保存到日志中。现在,如果我在 mysqli 查询中出现语法错误,例如拼写错误,页面会在此时完全停止加载。不会引发异常,因此不会触发错误处理程序,也
我有以下分组的svg文件,g的id为flower-petals,然后里面的每个部分都是花瓣,我似乎无法更改每个内部路径的填充。 我将 snap 的 petals 变量定义为 petals.Snap("
当脚本执行 Read-Host cmdlet,关闭窗口不会激活 finally堵塞。下面是一个随意但功能最少的示例。我正在使用 PowerShell 5.0。 Beep() 只是为了让 finally
我是一名优秀的程序员,十分优秀!