android ar人脸贴图,ARCore与ARKit实现人脸贴纸、更换材质等动画效果

近两年市面上出现了很多有关有关美颜滤镜、贴纸等各种贴纸效果的相机出现,由于项目的需要调研了google开源的一个能够提供3D角度的ARCore框架,本人也结合ARKit在iOS手机上实现了类抖音的效果

系统要求

iOS11.0以上系统

2.iPhone6s以上的Iphone手机

首先看下效果

02d4fd2ef1bb

IMG_3543.PNG

1.引入需求的库

target 'ARCoreFaceDemo'

platform :ios, '10.0'

pod 'ARCore/AugmentedFaces', '~> 1.13.0'

pod 'SnapKit', '~> 4.2.0'

2.使用AVFoundation框架进行数据的采集工作

/// Setup a camera capture session from the front camera to receive captures.

private func setupCamera() {

guard let device =

AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back),

let input = try? AVCaptureDeviceInput(device: device)

else {

NSLog("Failed to create capture device from front camera.")

return

}

let output = AVCaptureVideoDataOutput()

output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]

output.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))

session.sessionPreset = .high

videoInput = input

session.addInput(input)

session.addOutput(output)

captureSession = session

captureDevice = device

cameraImageLayer.contentsGravity = .center

cameraImageLayer.frame = self.view.bounds

view.layer.insertSublayer(cameraImageLayer, at: 0)

startCameraCapture()

}

3.设置场景

private func setupScene() {

let scene = SCNScene(named: "Face.scnassets/fox_face.scn")

// Face.scnassets/face_texture.png

guard let faceImage = UIImage(named: "multiply01.png"),

// let modelRoot = scene?.rootNode.childNode(withName: "asset", recursively: false)

let modelRoot = scene?.rootNode.childNodes.first

else {

NSLog("Failed to load face scene!")

return

}

// SceneKit uses meters for units, while the canonical face mesh

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值