处理AVCaptureVideoDataOutput关于方向的图像数据的推荐方法是什么 [英] What is the recommended way to deal with AVCaptureVideoDataOutput image data regarding orientation

查看:644
本文介绍了处理AVCaptureVideoDataOutput关于方向的图像数据的推荐方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,对从AVCaptureSession中的AVCaptureVideoDataOutput获得的图像数据进行一些实时处理。

I am writing an application that does some real-time processing on image data it gets from AVCaptureVideoDataOutput within an AVCaptureSession.

我目前能够启动会话,添加输入&输出,然后检索图像数据,将其转换为UIImage并在屏幕上实时显示。

I am currently able to start the session, add input & output and then retrieve image data, convert it to UIImage and display it on the screen live.

我遇到的主要问题是图像的方向是尴尬的。它旋转和镜像,它也看起来扭曲。我已经做了一些研究,我发现了一些相关 问题,我试过已经建议的代码,但它不能解决旋转问题。

The main problem I'm having is that the image's orientation is awkward. It's rotated and mirrored and it also looks skewed. I've done some research into it, I've found some related questions, and I've tried the code that has been suggested but it doesn't fix the rotation problem.

我认为连接的问题假设UIImages来自其他地方(也许更高级api它会自动添加更多的信息,例如方向,或者可能是因为我从视频输出Feed中获取它。

I think the questions linked assume the UIImages came from somewhere else (perhaps a higher-level api that adds more information, such as orientation, to the image automatically. Or perhaps it's because I'm getting it from a video output feed?

我不是真的想找修复它的代码(虽然注释的例子会真正有用的),而是一个很好的解释这种方式获得的图像的生命周期是如何工作的;什么是处理它的建议方式,以便它可以显示在屏幕对手机的方向有意义吗?返回的CGImageRef的方向是什么?等等。

I am not really looking for the code that fixes it (although an annotated example would be really helpful), but rather a good explanation of what the lifecycle of an image obtained in this way works; What's the recommended way to deal with it so that it can be displayed on the screen in a way that makes sense to the phone's orientation? What's the orientation of the CGImageRef that comes back? etc.

我有一个

I have a previous question that has the code I'm using to set up the AVCaptureSession.

推荐答案

视频连接通常是用来创建视频连接(例如AVCaptureVideoOrientationLandscapeRight)
这个
apple Q& A

The video connection is usually in landscape (e.g. AVCaptureVideoOrientationLandscapeRight) There is some good info on this apple Q&A

我的理解是你不能在AVCaptureVideoDataOutput上设置视频方向。
因此,在AVCaptureSession委托方法中链接中旋转当前帧图像的所有各种技巧 captureOutput:didOutputSampleBuffer:fromConnection:

My understanding is that you cannot set the video Orientation on AVCaptureVideoDataOutput. Hence all the various tricks in your links to rotate the current frame image in the AVCaptureSession delegate method captureOutput:didOutputSampleBuffer:fromConnection:

我假设你从上一篇文章中看到了SquareCam示例项目。 RosyWriter项目还通过将连接的videoOrientation属性与应用程序预期的引用纵向方向进行比较,提供了一些有趣的方向处理。

I assume from your previous post that you looked at the SquareCam sample project. The RosyWriter project provides also some interesting handling of orientation, by comparing the videoOrientation property of the connection to a "reference" portrait orientation expected by the application.

希望它有帮助。

这篇关于处理AVCaptureVideoDataOutput关于方向的图像数据的推荐方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆