gpt4 book ai didi

ios - AVCaptureStillImageOutput 图像倒置返回

转载 作者:可可西里 更新时间:2023-11-01 03:54:21 27 4
gpt4 key购买 nike

我正在使用 captureStillImageAsynchronouslyFromConnection 从相机捕捉图像

图像正在倒置保存。我尝试使用

保存图像
UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUp]

但是这种方向只存在于元数据中,当我从文件中复制数据来处理它时,处理过的图像是颠倒的。 (快速查看显示原件是直立的,但处理/过滤后的图像是颠倒的)。

设置视频捕获方向的正确方法是什么?

我在视频预览层上设置了方向,但这不会影响 AVCaptureStillImageOutput 对象缓冲区中的捕获数据。

我阅读了 AVCaptureStillImageOutput header ,但似乎没有解释如何强制相机预览朝向图像缓冲区。

例如- (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject connection:(AVCaptureConnection *)connection NS_AVAILABLE_IOS(6_0);

谢谢

最佳答案

“问题”是图像方向,iOS 相机仅在一个方向返回图像,除非您设置 -videoOrientation 属性来转换已经拍摄的图像。所以可能会有不同的问题:

  1. videoOrientation 未正确设置
  2. videoOrientation 未全部设置

videoOrientation 属性仅适用于静态图像和视频捕获,不适用于单个缓冲区。
此片段来自 Apple AVCam示例代码。

    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

[AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

if (imageDataSampleBuffer)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
}
}]; <br>

首先根据预览 View 设置方向,然后拍摄,然后以正确的方向将其保存在 Assets 库中

关于ios - AVCaptureStillImageOutput 图像倒置返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22431813/

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