-
-
Save gnus212/7869648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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