Skip to content

Instantly share code, notes, and snippets.

@duyhungtnn
Forked from gnus212/11
Last active August 29, 2015 14:07
Show Gist options
  • Save duyhungtnn/424c12b9450ae5cf9b8f to your computer and use it in GitHub Desktop.
Save duyhungtnn/424c12b9450ae5cf9b8f to your computer and use it in GitHub Desktop.
- (BOOL) setupCaptureSessionParameters
{
NSLog(@"--- Configure Camera options...");
/*
* Create capture session with optimal size to OpenCV processing
*/
captureSession = [[AVCaptureSession alloc] init];
captureSession.sessionPreset = AVCaptureSessionPreset640x480;
AVCaptureDevice *cameraBack =[self videoDeviceWithPosition:AVCaptureDevicePositionBack];
if ([cameraBack lockForConfiguration:nil])
{
NSLog(@"lockForConfiguration...");
// No autofocus
if ( [cameraBack isFocusModeSupported:AVCaptureFocusModeLocked])
{
cameraBack.focusMode = AVCaptureFocusModeLocked;
}
// Focus center image always
if ( [cameraBack isFocusPointOfInterestSupported])
{
cameraBack.focusPointOfInterest = CGPointMake(0.5, 0.5);
}
// Autoexpose color is have a several change of lights
if ( [cameraBack isExposurePointOfInterestSupported] )
{
cameraBack.exposureMode = AVCaptureExposureModeContinuousAutoExposure;
}
// Auto adjust white balance is user aim to a reflectant surface
if ( [cameraBack isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance])
{
cameraBack.whiteBalanceMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance;
}
// Only Focus far
if ( [cameraBack isAutoFocusRangeRestrictionSupported])
{
cameraBack.autoFocusRangeRestriction = AVCaptureAutoFocusRangeRestrictionFar;
}
// Choose best rate depending preset
AVCaptureDeviceFormat *bestFormat = nil;
AVFrameRateRange *bestFrameRateRange = nil;
for ( AVCaptureDeviceFormat *format in [cameraBack formats] )
{
for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges )
{
if ( range.maxFrameRate > bestFrameRateRange.maxFrameRate )
{
bestFormat = format;
bestFrameRateRange = range;
}
}
}
if (bestFormat)
{
cameraBack.activeFormat = bestFormat;
cameraBack.activeVideoMinFrameDuration = bestFrameRateRange.minFrameDuration;
cameraBack.activeVideoMaxFrameDuration = bestFrameRateRange.maxFrameDuration;
}
[cameraBack unlockForConfiguration];
NSLog(@"unlockForConfiguration!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment