• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

captureOutput 中的 iOS 应用程序相机方向

[复制链接]
菜鸟教程小白 发表于 2022-12-13 07:36:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

调用该接口(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] 时,它被正确设置为纵向。

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

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

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

关键是显示器不错,就是拍照而已……



Best Answer-推荐答案


解决您的问题:

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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap