The initial idea was to start a camera stream via AVCaptureSession
, find faces in that raw CMSampleBuffer
and then add some images as layers on AVCaptureVideoPreviewLayer
and then take a screenshot.
After completing that, found out later that the UIGraphicsGetImageFromCurrentImageContext
won't work with AVCaptureVideoPreviewLayer
, so taking screenshot would not solve my purpose here.
So I used Metal
and MTKView
instead to perform some live rendering and the results are good with the combination of CoreImage Filters and Metal. I already know how to detect faces and alter that part of the face using inbuilt CoreImage filters but I can't find a suitable method to add an image on to another image.
How can I blend two images with respect to positioning in the background image? I have CIImage to work with.
答案 0 :(得分:2)
您可以将叠加层加载到CIImage
中,然后使用transformed(by matrix: CGAffineTransform)
将其移动到面部位置,最后使用composited(over dest: CIImage)
将叠加层混合到{视频缓冲区。
您可能需要进行一些工作才能在不同的坐标空间之间进行转换。
还有许多更复杂的合成过滤器可用。在CIImage
类别中查看filters。