Add image to AR Resources on the fly for image recognition

前端 未结 2 1602
[愿得一人]
[愿得一人] 2021-02-04 10:15

ARKit 1.5 introduces image recognition. In the code you have to create a Set of the reference images like this:

let referenceImages = ARReferenceIma         


        
2条回答
  •  -上瘾入骨i
    2021-02-04 10:25

    let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
    let pathToObject = documentDirectory + "/reference.jpg"
    let imageUrl = URL(fileURLWithPath: pathToObject)
    let imageData: Data = try! Data(contentsOf: imageUrl)
    let image = UIImage(data: imageData, scale: UIScreen.main.scale)
    let cgImage = image!.cgImage
    
    let referenceImages = ARReferenceImage.init(cgImage!, orientation: .up, physicalWidth: 0.595)
    referenceImages.name = "Reference Image"
    let configuration = ARImageTrackingConfiguration()
    configuration.trackingImages = [referenceImages]
    session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
    

提交回复
热议问题