在iOS 13中跟踪多个对象

问题描述 投票:0回答:1

我的应用使用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
}

任何帮助将不胜感激。

谢谢

ios13 vision video-tracking
1个回答
0
投票

经过数周的Apple技术支持,他们提出了一个非常简单的解决方法。基本上,您只需要通过CGImage进行转换,而不是直接从CIImage转换为UIImage。

© www.soinside.com 2019 - 2024. All rights reserved.