我一直在尝试为ARSession期间检测到的QR码绘制边界框。结果是: boundingbox 1 boundingbox 2
正在跟踪条形码,但是边框的几何形状错误。
如何获得正确的边界框坐标?
源代码是:
public func session(_ session: ARSession, didUpdate frame: ARFrame) {
// Only run one Vision request at a time
if self.processing {
return
}
self.processing = true
let request = VNDetectBarcodesRequest { (request, error) in
if let results = request.results, let result = results.first as? VNBarcodeObservation {
DispatchQueue.main.async {
let path = CGMutablePath()
for result in results {
guard let barcode = result as? VNBarcodeObservation else { continue }
let topLeft = self.convert(point: …Run Code Online (Sandbox Code Playgroud) 刚刚发现函数storeCachedResponse(_ cachedResponse:CachedURLResponse,用于请求:URLRequest)是异步工作的。也就是说,执行后不会立即返回结果。我没有在官方文档中找到对此的描述。参见示例:
cache = URLCache(memoryCapacity: 0, diskCapacity: 100 * 1024 * 1024, diskPath: "myCache")
let config = URLSessionConfiguration.default
config.requestCachePolicy = .returnCacheDataElseLoad
config.urlCache = cache
let session = URLSession(configuration: config)
session.dataTask(with: request, completionHandler: {[unowned self]
(data, response, error) in
if let data = data, let response = response, ((response as HTTPURLResponse)?.statusCode ?? 500) < 300 {
let cachedData = CachedURLResponse(response: response, data: data)
self.cache.storeCachedResponse(cachedData, for: request)
let testCachedData = self.cache.cachedResponse(for: request)
}
}
Run Code Online (Sandbox Code Playgroud)
理论上,testCachedData必须包含缓存的响应。但实际上包含的内容是:
testCachedData?.response.url // Ok
testCachedData?.isEmpty // false
testCachedData?.data …Run Code Online (Sandbox Code Playgroud)