我想將自定義相機實現到我的應用中。所以,我使用AVCaptureDevice
來創建這款相機。在iOS中輸出AVCaptureDevice時設置GrayScale
現在我想只顯示灰色輸出到我的自定義相機。所以我試圖使用setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:
和AVCaptureWhiteBalanceGains
。我正在使用AVCamManual: Extending AVCam to Use Manual Capture。
- (void)setWhiteBalanceGains:(AVCaptureWhiteBalanceGains)gains
{
NSError *error = nil;
if ([videoDevice lockForConfiguration:&error]) {
AVCaptureWhiteBalanceGains normalizedGains = [self normalizedGains:gains]; // Conversion can yield out-of-bound values, cap to limits
[videoDevice setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:normalizedGains completionHandler:nil];
[videoDevice unlockForConfiguration];
}
else {
NSLog(@"Could not lock device for configuration: %@", error);
}
}
但對於這一點,我必須通過 1 4之間所以我創建檢查最大值和最小值這種方法RGB增益值。
- (AVCaptureWhiteBalanceGains)normalizedGains:(AVCaptureWhiteBalanceGains) gains
{
AVCaptureWhiteBalanceGains g = gains;
g.redGain = MAX(1.0, g.redGain);
g.greenGain = MAX(1.0, g.greenGain);
g.blueGain = MAX(1.0, g.blueGain);
g.redGain = MIN(videoDevice.maxWhiteBalanceGain, g.redGain);
g.greenGain = MIN(videoDevice.maxWhiteBalanceGain, g.greenGain);
g.blueGain = MIN(videoDevice.maxWhiteBalanceGain, g.blueGain);
return g;
}
此外,我想獲得不同的效果,如傳遞RGB增益靜態值。
- (AVCaptureWhiteBalanceGains)normalizedGains:(AVCaptureWhiteBalanceGains) gains
{
AVCaptureWhiteBalanceGains g = gains;
g.redGain = 3;
g.greenGain = 2;
g.blueGain = 1;
return g;
}
現在,我想設置此灰階:我自定義相機(式像素= 0.30078125f * R + 0.5859375f * G + 0.11328125f * B)。我已經嘗試過這個公式。
- (AVCaptureWhiteBalanceGains)normalizedGains:(AVCaptureWhiteBalanceGains) gains
{
AVCaptureWhiteBalanceGains g = gains;
g.redGain = g.redGain * 0.30078125;
g.greenGain = g.greenGain * 0.5859375;
g.blueGain = g.blueGain * 0.11328125;
float grayScale = g.redGain + g.greenGain + g.blueGain;
g.redGain = MAX(1.0, grayScale);
g.greenGain = MAX(1.0, grayScale);
g.blueGain = MAX(1.0, grayScale);
g.redGain = MIN(videoDevice.maxWhiteBalanceGain, g.redGain);
g.greenGain = MIN(videoDevice.maxWhiteBalanceGain, g.greenGain);
g.blueGain = MIN(videoDevice.maxWhiteBalanceGain, g.blueGain);
return g;
}
所以如何我通過在1 4之間這個值..?
有什麼方法或比例來比較這些東西..?
任何幫助,將不勝感激。
調整白平衡不會將彩色圖像轉換爲黑白圖像。你需要找到一個不同的API才能做到這一點。例如[vImageMatrixMultiply_ARGB8888](https://developer.apple.com/library/ios/documentation/Performance/Reference/vImage_transform/index.html#//apple_ref/c/func/vImageMatrixMultiply_ARGB8888) – Mats
@Mats:是的,謝謝.. !請提供任何示例代碼以獲得更好的理解。 –
也許這個,http://stackoverflow.com/questions/21207099/,問題幫助。 – Mats