【发布时间】:2020-03-10 17:48:45
【问题描述】:
我有一个视差图像,我正在使用下面的示例代码对其进行标准化,但它非常慢。 我需要使用一些加速器,如自定义 CIFilter 或任何其他技术,但我不知道怎么做?我目前正在使用 CIContext() 运行代码,它正在 CPU 上运行(不确定)。有没有办法在 GPU 上运行它并在没有自定义 CIfilter 的情况下加速? 这是当前代码:
extension CVPixelBuffer {
func normalize() {
let width = CVPixelBufferGetWidth(self)
let height = CVPixelBufferGetHeight(self)
CVPixelBufferLockBaseAddress(self, CVPixelBufferLockFlags(rawValue: 0))
let baseAddr = CVPixelBufferGetBaseAddress(self)!
let floatBuffer = unsafeBitCast(CVPixelBufferGetBaseAddress(self), to: UnsafeMutablePointer<Float>.self)
var minPixel: Float = 1.0
var maxPixel: Float = 0.0
for y in 0 ..< height {
for x in 0 ..< width {
let pixel = floatBuffer[y * width + x]
minPixel = min(pixel, minPixel)
maxPixel = max(pixel, maxPixel)
}
}
let range = maxPixel - minPixel
for y in 0 ..< height {
for x in 0 ..< width {
let pixel = floatBuffer[y * width + x]
floatBuffer[y * width + x] = (pixel - minPixel) / range
}
}
CVPixelBufferUnlockBaseAddress(self, CVPixelBufferLockFlags(rawValue: 0))
}
}
【问题讨论】:
标签: swift core-image disparity-mapping