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