gpt4 book ai didi

iOS 应用程序视频捕捉在低光下变慢

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:26 25 4
gpt4 key购买 nike

我有一个 iOS 应用,它使用手机的前置摄像头并设置 AVCaptureSession 来读取传入的摄像头数据。我设置了一个简单的帧计数器来检查数据传入的速度,令我惊讶的是,当相机处于低光照条件下时,帧速率(使用代码中的 imagecount 变量测量)非常慢,但是一旦我移动 Handlebars 机放到明亮的地方帧率几乎会增加三倍。我想在整个过程中保持图像处理的高帧率,并将 minFrameDuration 变量设置为 30 fps,但这没有帮助。关于为什么会出现这种随机行为的任何想法?

创建捕获 session 的代码如下:

#pragma mark Create and configure a capture session and start it running

- (void)setupCaptureSession
{

NSError *error = nil;

// Create the session
session = [[AVCaptureSession alloc] init];

// Configure the session to produce lower resolution video frames, if your
// processing algorithm can cope. We'll specify medium quality for the
// chosen device.
session.sessionPreset = AVCaptureSessionPresetLow;

// Find a suitable AVCaptureDevice
//AVCaptureDevice *device=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSArray *devices = [AVCaptureDevice devices];
AVCaptureDevice *frontCamera;
AVCaptureDevice *backCamera;

for (AVCaptureDevice *device in devices) {



if ([device hasMediaType:AVMediaTypeVideo]) {

if ([device position] == AVCaptureDevicePositionFront) {

backCamera = device;
}
else {

frontCamera = device;
}
}
}


//Create a device input with the device and add it to the session.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:backCamera
error:&error];

if (!input) {
//Handling the error appropriately.
}
[session addInput:input];

// Create a VideoDataOutput and add it to the session
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];

// Configure your output.
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);

// Specify the pixel format
output.videoSettings =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];

// If you wish to cap the frame rate to a known value, such as 30 fps, set
// minFrameDuration.
output.minFrameDuration = CMTimeMake(1,30);

//Start the session running to start the flow of data

[session startRunning];

}

#pragma mark Delegate routine that is called when a sample buffer was written

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
//counter to track frame rate
imagecount++;

//display to help see speed of images being processed on ios app
NSString *recognized = [[NSString alloc] initWithFormat:@"IMG COUNT - %d",imagecount];
[self performSelectorOnMainThread:@selector(debuggingText:) withObject:recognized waitUntilDone:YES];

}

最佳答案

当光线较少时,相机需要更长的曝光时间才能在每个像素中获得相同的信噪比。这就是为什么您可能期望帧速率在低光照条件下下降。

您将 minFrameDuration 设置为 1/30 秒,以试图防止长时间曝光帧降低帧速率。但是,您应该改为设置 maxFrameDuration:您的代码原样表示帧速率不超过 30 FPS,但它可能是 10 FPS 或 1 FPS....

此外,the Documentation说用 lockForConfiguration: 和 unlockForConfiguration: 括起对这些参数的任何更改,所以可能是您的更改没有被采用。

关于iOS 应用程序视频捕捉在低光下变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com