首页 > 解决方案 > VNRectangle Bounding Box 在 AVFoundation Frame 中的 x 轴上偏移不正确

问题描述

这是问题的剪辑这是我如何生成边界框,对坐标应用必要的变换以适应框架。不知道为什么 X 轴如此偏离(除非在中心)。也许它被翻转了?提前致谢!

func drawVisionRequestResults(_ results: [VNRecognizedTextObservation]) {
    //bounding box transformations
    let transform = CGAffineTransform(scaleX: 1, y: -1).translatedBy(x: 0, y: -self.previewView.frame.height)
    let translate = CGAffineTransform.identity.scaledBy(x: self.previewView.frame.width
, y: self.previewView.frame.height)
    //highlight search term in frame
for word in results {
    if word.topCandidates(1).first?.string.lowercased().contains(searchTerm.lowercased()) == true {
    self.counter = 0
    searchingText.text = "Found"
    let rectangleBounds = word.boundingBox.applying(translate).applying(transform)
    previousRectCoordinate = rectangleBounds.origin
    previewView.drawLayer(in: rectangleBounds)
}

标签: swiftavfoundationbounding-boxcoremlvision

解决方案


推荐阅读