Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
captureOutput中的iOS应用程序摄像头方向_Ios_Objective C_Avfoundation - Fatal编程技术网

captureOutput中的iOS应用程序摄像头方向

captureOutput中的iOS应用程序摄像头方向,ios,objective-c,avfoundation,Ios,Objective C,Avfoundation,首先,我知道很多人问了类似的问题,但我找不到任何类似的问题 调用此接口时: - (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVImageBufferRef pixelBuffer = CMSampleBufferG

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

调用此接口时:

- (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]
时,它被正确设置为纵向

  • 为什么连接方向不影响采样的缓冲区
  • 我应该自己旋转图像吗
  • 是否有一种方法可以配置设备方向给定的样本
  • 谢谢


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

    -(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-使用上述代码


    希望这有帮助。

    解决您的问题:

    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-使用上述代码

    希望这有帮助。

    好的

    这太奇怪了

    当默认的应用程序方向是横向时,它就不起作用了

    当我将默认应用程序方向更改为纵向(底部的按钮)时,它突然开始工作

    我想知道这是一个bug还是预期的行为…

    好的

    这太奇怪了

    当默认的应用程序方向是横向时,它就不起作用了

    当我将默认应用程序方向更改为纵向(底部的按钮)时,它突然开始工作


    我想知道这是一个bug还是预期的行为…

    嘿,我在代码中添加了一个代码部分,用于处理连接的方向旋转。。我已经有了。此外,当检查连接对象(传入到方法)时,如果方向正确,显示也很好。。唯一不好的是图像本身。。。有什么想法吗?是的,有一种方法可以让您使用AVCaptureSession实例并设置质量。下面是我使用的一个:captureSessionInstance.sessionPreset=AVCaptureSessionPresetHigh//这也可以是AVCaptureSessionPresetMiddle或AVCaptureSessionPresetLow。希望这对你有帮助!嘿,我在代码中添加了一个代码部分,用于处理连接的方向旋转。。我已经有了。此外,当检查连接对象(传入到方法)时,如果方向正确,显示也很好。。唯一不好的是图像本身。。。有什么想法吗?是的,有一种方法可以让您使用AVCaptureSession实例并设置质量。下面是我使用的一个:captureSessionInstance.sessionPreset=AVCaptureSessionPresetHigh//这也可以是AVCaptureSessionPresetMiddle或AVCaptureSessionPresetLow。希望这对你有帮助!