簡體   English   中英

CVPixelBufferRef:Video Buffer 和 Depth Buffer 方向不同

[英]CVPixelBufferRef: Video Buffer and Depth Buffer have different orientations

現在我正在使用 iOS 的深度相機,因為我想測量幀中某些點到相機的距離。

我在我的相機解決方案中完成了所有必要的設置,現在我手中有兩個CVPixelBufferRef - 一個帶有像素數據,一個帶有深度數據。

這就是我從AVCaptureDataOutputSynchronizer獲取兩個緩沖區的方式:

- (void)dataOutputSynchronizer:(AVCaptureDataOutputSynchronizer *)synchronizer didOutputSynchronizedDataCollection:(AVCaptureSynchronizedDataCollection *)synchronizedDataCollection
{
    
    AVCaptureSynchronizedDepthData *syncedDepthData = (AVCaptureSynchronizedDepthData *)[synchronizedDataCollection synchronizedDataForCaptureOutput:depthDataOutput];
    AVCaptureSynchronizedSampleBufferData *syncedVideoData = (AVCaptureSynchronizedSampleBufferData *)[synchronizedDataCollection synchronizedDataForCaptureOutput:dataOutput];
    
    if (syncedDepthData.depthDataWasDropped || syncedVideoData.sampleBufferWasDropped) {
        return;
    }
    
    AVDepthData *depthData = syncedDepthData.depthData;
    CVPixelBufferRef depthPixelBuffer = depthData.depthDataMap;
    
    CMSampleBufferRef sampleBuffer = syncedVideoData.sampleBuffer;
    
    if (!CMSampleBufferDataIsReady(sampleBuffer)) {
        return;
    }
    //... code continues
}

在獲取任何深度數據之前,我決定檢查緩沖區的尺寸是否對齊。 我發現,我buffer with pixel data尺寸為480x640 (垂直,就像我的應用程序的方向) buffer with depth data尺寸為640x480 (水平)。

顯然,緩沖區不同,我無法將像素與深度值相匹配。 我需要以某種方式旋轉我的深度緩沖區嗎? 這是一個已知的問題?

請告知我應該如何解決這個問題。 提前致謝!

是的,我也看到了,希望這有幫助。 以弧度表示的角度。

extension CVPixelBuffer {
    func transformedImage(targetSize: CGSize, rotationAngle: CGFloat) -> CIImage? {
        let image = CIImage(cvPixelBuffer: self, options: [:])
        let scaleFactor = Float(targetSize.width) / Float(image.extent.width)
        return image.transformed(by: CGAffineTransform(rotationAngle: rotationAngle)).applyingFilter("CIBicubicScaleTransform", parameters: ["inputScale": scaleFactor])
    }
}

來電方:我將角度用作:-(.pi/2)

let depthMap = pixelBuffer.transformedImage(targetSize: desiredSize, rotationAngle: -(.pi/2))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM