Swift:迄今为止的 ARKit 时间间隔
ARSession
的 currentFrame
(ARFrame
) 具有 TimeInterval
类型的 timestamp
属性,该属性表示捕获帧时的正常运行时间。
我需要将此 TimeInterval
转换为设备的当前时域。
如果我对时间戳的假设是正确的,那么将内核 BootTime 和时间戳相加就会得到正确的日期。
问题:将内核 BootTime 和 timestamp
添加在一起会得到一个不正确的日期。 (取决于设备的上次启动时间,最多有 2 天的差异)
当前代码:
func kernelBootTime() -> Date {
var mib = [CTL_KERN, KERN_BOOTTIME]
var bootTime = timeval()
var bootTimeSize = MemoryLayout<timeval>.stride
if sysctl(&mib, UInt32(mib.count), &bootTime, &bootTimeSize, nil, 0) != 0 {
fatalError("Could not get boot time, errno: \(errno)")
}
return Date(timeIntervalSince1970: Double(bootTime.tv_sec) + Double(bootTime.tv_usec) / 1_000_000.0)
}
public func checkTime(_ session: ARSession) {
guard let frame = session.currentFrame else { return }
print(Date(timeInterval: frame.timestamp, since: kernelBootTime()))
}
The currentFrame
(ARFrame
) of ARSession
has a timestamp
attribute of type TimeInterval
which represents the uptime at the moment the frame has been captured.
I need to convert this TimeInterval
to the current time domain of the device.
If my assumption about timestamp
is correct, adding the kernel BootTime and timestamp
together would give me the correct date.
Problem: Adding the kernel BootTime and timestamp
together gives me an Date that is not correct. (depending on the device`s last boot time up to 2 days variance)
Current Code:
func kernelBootTime() -> Date {
var mib = [CTL_KERN, KERN_BOOTTIME]
var bootTime = timeval()
var bootTimeSize = MemoryLayout<timeval>.stride
if sysctl(&mib, UInt32(mib.count), &bootTime, &bootTimeSize, nil, 0) != 0 {
fatalError("Could not get boot time, errno: \(errno)")
}
return Date(timeIntervalSince1970: Double(bootTime.tv_sec) + Double(bootTime.tv_usec) / 1_000_000.0)
}
public func checkTime(_ session: ARSession) {
guard let frame = session.currentFrame else { return }
print(Date(timeInterval: frame.timestamp, since: kernelBootTime()))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。
为您提供上次设备重新启动的日期
打印拍摄图像的确切时间。 (以UTC时间表示)
I found the solution.
gives you the date of the last device restart
prints the exact time when the image was taken. (in UTC time)