首先,我知道很多人问过类似的问题 - 但我找不到任何类似的问题。
调用该接口(interface)时:
- (void) captureOutputAVCaptureOutput *)captureOutput didOutputSampleBufferCMSampleBufferRef)sampleBuffer fromConnectionAVCaptureConnection *)connection
{
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
// get buffer dimensions
size_t bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
size_t bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
...
当手机处于“肖像模式”时 - 我得到 480 的高度和 640 的宽度。
奇怪的是,当我检查 [connection videoOrientation] 时,它被正确设置为纵向。
- 为什么连接方向不影响采样缓冲区?
- 我应该自己旋转图片吗?
- 有没有办法将样本配置为由设备方向给出?
谢谢
@加布里埃尔:
我已经有了这个代码:
-(void) viewWillLayoutSubviews
{
// Handle camera
if (_videoPreviewLayer)
{
_videoPreviewLayer.frame = self.view.bounds;
for (AVCaptureOutput* outcap in _captureSession.outputs)
{
for(AVCaptureConnection* con in outcap.connections)
{
switch ([[UIDevice currentDevice] orientation])
{
case UIInterfaceOrientationPortrait:
[con setVideoOrientation:AVCaptureVideoOrientationPortrait];
break;
case UIInterfaceOrientationLandscapeRight:
[con setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; //home button on right. Refer to .h not doc
break;
case UIInterfaceOrientationLandscapeLeft:
[con setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft]; //home button on left. Refer to .h not doc
break;
case UIInterfaceOrientationPortraitUpsideDown:
[con setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown]; //home button on left. Refer to .h not doc
break;
default:
[con setVideoOrientation:AVCaptureVideoOrientationPortrait]; //for portrait upside down. Refer to .h not doc
break;
}
}
}
}
}
正如我上面提到的,在检查连接时 - 它是正确的方向,图像虽然是错误的方向..
您是否通过手动修复来引用 - 我将使用什么方法自动更改为正确的方向?
关键是显示器不错,就是拍照而已……
Best Answer-推荐答案 strong>
解决您的问题:
1 - 检查您是否禁用或修改了方向模式。
2 - 使用 AVFoundation 时,您必须自己旋转图像,这是我使用的代码:
AVCaptureVideoOrientation newOrientation;
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationPortrait:
newOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
newOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
newOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
case UIDeviceOrientationLandscapeRight:
newOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
default:
newOrientation = AVCaptureVideoOrientationPortrait;
}
3 - 使用上面的代码
希望这会有所帮助。
关于captureOutput 中的 iOS 应用程序相机方向,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23398029/
|