Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS应用程序视频捕获在弱光下变慢_Ios_Objective C_Camera_Avcapturesession_Avcapturedevice - Fatal编程技术网

iOS应用程序视频捕获在弱光下变慢

iOS应用程序视频捕获在弱光下变慢,ios,objective-c,camera,avcapturesession,avcapturedevice,Ios,Objective C,Camera,Avcapturesession,Avcapturedevice,我有一个iOS应用程序,它使用手机的前置摄像头,并设置AVCaptureSession来读取传入的摄像头数据。我设置了一个简单的帧计数器来检查数据输入的速度,令我惊讶的是,当相机处于弱光状态时,帧速率(使用代码中的imagecount变量测量)非常慢,但一旦我将手机移动到明亮的区域,帧速率将几乎增加三倍。我希望始终保持图像处理的高帧速率,并将minFrameDuration变量设置为30 fps,但这没有帮助。你知道为什么会出现这种随机行为吗 创建捕获会话的代码如下所示: #pragma mar

我有一个iOS应用程序,它使用手机的前置摄像头,并设置AVCaptureSession来读取传入的摄像头数据。我设置了一个简单的帧计数器来检查数据输入的速度,令我惊讶的是,当相机处于弱光状态时,帧速率(使用代码中的imagecount变量测量)非常慢,但一旦我将手机移动到明亮的区域,帧速率将几乎增加三倍。我希望始终保持图像处理的高帧速率,并将minFrameDuration变量设置为30 fps,但这没有帮助。你知道为什么会出现这种随机行为吗

创建捕获会话的代码如下所示:

#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 s,以防止长曝光帧降低帧速率。但是,您应该改为设置maxFrameDuration:您的原样代码表示帧速率不超过30 FPS,但可以是10 FPS或1 FPS

另外,假设用lockForConfiguration:和unlockForConfiguration:括住对这些参数的任何更改,那么可能是您的更改根本不起作用