【发布时间】:2019-03-06 15:44:10
【问题描述】:
我想从服务器添加 ARReferenceImages。为此,我得到一个包含图像 URL 的数组。 T 尝试使用以下函数,该函数迭代 url 并将新创建的 ARImages 添加到集合中。但它不起作用。
func addReferences(media: NSArray){
var customReferenceSet = Set<ARReferenceImage>()
for medium in media{
let type = (medium as AnyObject).value(forKey: "type");
let t = type as! String
let reference = (medium as AnyObject).value(forKey: "reference");
let ref = reference as! String
let ide = (medium as AnyObject).value(forKey: "id");
let id = ide as! String
let url = URL(string: ref)
let session = URLSession(configuration: .default)
let downloadPicTask = session.dataTask(with: url!) { (data, response, error) in
if let e = error {
print("Error downloading picture: \(e)")
} else {
if let res = response as? HTTPURLResponse {
print("Downloaded picture with response code \(res.statusCode)")
if let imageData = data {
let image = UIImage(data: imageData)!
let imageToCIImage = CIImage(image: image)
let cgImage = self.convertCIImageToCGImage(inputImage: imageToCIImage!)
let arImage = ARReferenceImage(cgImage!, orientation: CGImagePropertyOrientation.up, physicalWidth: 0.2)
arImage.name = id
customReferenceSet.insert(arImage)
} else {
print("Couldn't get image: Image is nil")
}
} else {
print("Couldn't get response code for some reason")
}
}
}
downloadPicTask.resume()
}
self.configuration = ARWorldTrackingConfiguration()
self.configuration?.detectionImages = customReferenceSet
sceneView.session.run(configuration!)
}
有时,但不是每次,我都会得到以下输出:
[boringssl_session_read] SSL_ERROR_ZERO_RETURN(6):操作失败,因为连接已通过 close_notify 警报彻底关闭
一些想法?
【问题讨论】:
标签: ios swift arkit image-recognition