0
현재 카메라를 사용하여 초당 15 프레임을 30 초 (총 450 프레임) 캡처하는 iOS 애플리케이션을 만들고 있습니다. 문제는 [self.session startRunning] (제공된 코드의 마지막 줄)이 작동하지 않는 것입니다. 캡쳐해야하는 450 프레임 각각의 평균 적색 값을 취하기 위해 색상이라고하는 배열을 설정했기 때문에 이것을 말합니다. 그러나 탐지를 시작하고 중지 한 후에도 배열은 비어 있습니다. 내가 뭘 놓치고 있니?self.startRunning이 제대로 작동하지 않습니다.
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController()
@property (nonatomic, strong) AVCaptureSession *session;
@property (nonatomic, strong) NSMutableArray *hues;
@end
const int SECONDS = 15;
const int FPS = 30;
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.hues = [[NSMutableArray alloc] init]; // initiate things (from old code)
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPresetLow;
NSInteger numberOfFramesCaptured = self.hues.count;
// initialize the session with proper settings (from docs)
NSError *error = nil;
AVCaptureDevice *captureDevice; // initialize captureDevice and input, and add input (from old code)
AVCaptureDeviceInput *videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captureDevice error:&error];
if ([self.session canAddInput:videoInput])
{ // fails
[self.session addInput:videoInput];
}
// find the max fps we can get from the given device (from old code)
AVCaptureDeviceFormat *currentFormat = [captureDevice activeFormat];
for (AVCaptureDeviceFormat *format in captureDevice.formats) // executes twice
{ // skips all of this
NSArray *ranges = format.videoSupportedFrameRateRanges;
AVFrameRateRange *frameRates = ranges[0];
// find the lowest resolution format at the frame rate we want (from old code)
if (frameRates.maxFrameRate == FPS && (!currentFormat || (CMVideoFormatDescriptionGetDimensions(format.formatDescription).width < CMVideoFormatDescriptionGetDimensions(currentFormat.formatDescription).width && CMVideoFormatDescriptionGetDimensions(format.formatDescription).height < CMVideoFormatDescriptionGetDimensions(currentFormat.formatDescription).height)))
{
currentFormat = format;
}
}
// tell the device to use the max frame rate (from old code)
[captureDevice lockForConfiguration:nil];
captureDevice.torchMode = AVCaptureTorchModeOn;
captureDevice.activeFormat = currentFormat;
captureDevice.activeVideoMinFrameDuration = CMTimeMake(1, FPS);
captureDevice.activeVideoMaxFrameDuration = CMTimeMake(1, FPS);
[captureDevice unlockForConfiguration];
// set the output (from old code)
AVCaptureVideoDataOutput *videoOutput = [[AVCaptureVideoDataOutput alloc] init];
// create a queue to run the capture on (from old code)
dispatch_queue_t queue = dispatch_queue_create("queue", NULL);
// setup our delegate (from old code)
[videoOutput setSampleBufferDelegate:self queue:queue];
// configure the pixel format (from old code)
videoOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil];
videoOutput.alwaysDiscardsLateVideoFrames = NO;
[self.session addOutput:videoOutput];
// start the video session
[self.session startRunning]; // PROBLEM OCCURS HERE
문제인가요? – fi12
어떻게 초기화할까요? – fi12
'[AVCaptureDevice devicesWithMediaType : AVMediaTypeVideo];'에서 적절한 장치를 선택해야합니다. 앞뒤 카메라 – vojer