gpt4 book ai didi

captureOutput 中的 iOS 应用相机方向

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:43:15 24 4
gpt4 key购买 nike

首先,我知道很多人问过类似的问题 - 但我找不到任何类似的问题。

调用该接口(interface)时:

- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)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] 时,它被正确设置为纵向。

  1. 为什么连接方向不影响采样缓冲区?
  2. 我应该自己旋转图像吗?
  3. 有没有办法将样本配置为由设备方向给出?

谢谢


@加布里埃尔:我已经有了这个代码:

-(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;
}
}
}
}
}

正如我上面提到的,在检查连接时 - 它是正确的方向,尽管图像是错误的方向..

您是否通过手动修复它来引用 - 使用什么方法自动更改为正确的方向?

关键是显示效果不错,只是拍照...

最佳答案

解决您的问题:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com