【发布时间】:2020-02-02 20:07:42
【问题描述】:
我的应用程序使用 Apple 的示例代码使用 Vision 跟踪视频的多个对象(在我的例子中,它在举重练习期间跟踪杠铃的路径),但在更新到 iOS 13 后,视频无法正确显示。不像以前那样填满屏幕,现在视频被裁剪了,你只能看到它的一小部分。我已经与 Apple 技术支持人员进行了交谈,他们承认了这个错误,但他们的计划中没有修复。
最让我烦恼的是 a) 横向视频可以正常工作,但纵向视频不行 b) 该错误仅发生在真实设备中,而不发生在模拟器中。请参阅附件中用于根据视频比例(横向或纵向)显示视频的代码部分。
private func scaleImage(to viewSize: CGSize) -> UIImage? {
guard self.image != nil && self.image.size != CGSize.zero else {
return nil
}
self.imageAreaRect = CGRect.zero
// There are two possible cases to fully fit self.image into the the ImageTrackingView area:
// Option 1) image.width = view.width ==> image.height <= view.height
// Option 2) image.height = view.height ==> image.width <= view.width
let imageAspectRatio = self.image.size.width / self.image.size.height
// Check if we're in Option 1) case and initialize self.imageAreaRect accordingly
let imageSizeOption1 = CGSize(width: viewSize.width, height: floor(viewSize.width / imageAspectRatio))
if imageSizeOption1.height <= viewSize.height {
print("Landscape. View size: \(viewSize)")
let imageX: CGFloat = 0
let imageY = floor((viewSize.height - imageSizeOption1.height) / 2.0)
self.imageAreaRect = CGRect(x: imageX,
y: imageY,
width: imageSizeOption1.width,
height: imageSizeOption1.height)
}
if self.imageAreaRect == CGRect.zero {
// Check if we're in Option 2) case if Option 1) didn't work out and initialize imageAreaRect accordingly
print("portrait. View size: \(viewSize)")
let imageSizeOption2 = CGSize(width: floor(viewSize.height * imageAspectRatio), height: viewSize.height)
if imageSizeOption2.width <= viewSize.width {
let imageX = floor((viewSize.width - imageSizeOption2.width) / 2.0)
let imageY: CGFloat = 0
self.imageAreaRect = CGRect(x: imageX,
y: imageY,
width: imageSizeOption2.width,
height: imageSizeOption2.height)
}
}
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(self.imageAreaRect.size, false, 0.0)
self.image.draw(in: CGRect(x: 0.0, y: 0.0, width: self.imageAreaRect.size.width, height: self.imageAreaRect.size.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
附带说明一下,我发现 iOS 13 中的对象跟踪功能几乎无法使用......它几乎无法正常工作。对于我在 iOS 12 中实现的一项功能,我不断获得 0.8-0.99 的跟踪置信度,而在 iOS 13 上,置信度从未超过 0.15。
-
感谢您的反馈安迪。我没有遇到这个问题:我的应用程序基本上像以前一样跟踪所有内容。如果您像我一样使用 Apple 的示例代码,您是否尝试过我在自我回答中提供的解决方法?
标签: ios13 vision video-tracking