我想逐帧处理来自相机的实时视频,但当我尝试将我的图像转换为 cv :: Mat 时,我总是得到CGBitmapContextCreate: unsupported parameter combination: set CGBITMAP_CONTEXT_LOG_ERRORS environmental variable to see the details
。如果我设置了该变量,我得到Assertion Failed(0)
SIGABRT。
我已尝试使用this方法以及包含来自 ios.h 的方法,但我仍然得到相同的结果。我尝试了所有我能找到的东西。我认为唯一剩下的就是当我将CMSampleBuffer
转换为UIImage
时,我不知道与我的图像有关的内容。这是我的代码:
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
DispatchQueue.global(qos: .background).async {
let pixelBuff = CMSampleBufferGetImageBuffer(sampleBuffer)
let ciImage:CIImage? = CIImage(cvPixelBuffer: pixelBuff!)
let img = UIImage(ciImage: ciImage!)
let i = self.cv.processImage(withOpenCV: img)
DispatchQueue.main.async {
self.imageView.image = i
}
}
}
我还尝试了在谷歌上发现的很多不同的方法来将我的缓冲区转换为UIImage,但仍然没有。你有什么想法吗?
答案 0 :(得分:0)
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
DispatchQueue.global(qos: .background).async {
let pixelBuff = CMSampleBufferGetImageBuffer(sampleBuffer)
let ciImage:CIImage? = CIImage(cvPixelBuffer: pixelBuff!)
let img = UIImage(ciImage: ciImage!)
// convert image
let theimage = UIImage(data: img!.pngData()!)
let i = self.cv.processImage(withOpenCV: theimage)
DispatchQueue.main.async {
self.imageView.image = i
}
}
}