【问题标题】:CraftAR Image recognition - Translating matchBoundingBox to points in screenCraftAR 图像识别 - 将 matchBoundingBox 转换为屏幕中的点
【发布时间】:2017-02-07 12:23:17
【问题描述】:

我正在使用来自 Catchoom CraftAR 的设备图像识别,并使用 Github https://github.com/Catchoom/craftar-example-ios-on-device-image-recognition 上提供的示例。

图像识别有效,我想使用 matchBoundingBox 在所有 4 个角上绘制一些正方形。不知何故,我正在做的计算不起作用,我基于这篇文章:

http://support.catchoom.com/customer/portal/articles/1886553-obtain-the-bounding-boxes-of-the-results-of-image-recognition

方形视图被添加到扫描覆盖中,这就是我计算添加 4 个视图的点的方式:

CraftARSearchResult *bestResult = [results objectAtIndex:0];
BoundingBox *box = bestResult.matchBoundingBox;

float w = self._preview.frame.size.width;
float h = self._preview.frame.size.height;

CGPoint tr = CGPointMake(w * box.topRightX , h * box.topRightY);
CGPoint tl = CGPointMake(w * box.topLeftX, h * box.topLeftY);
CGPoint br = CGPointMake(w * box.bottomRightX, h * box.bottomRightY);
CGPoint bl = CGPointMake(w * box.bottomLeftX, h * box.bottomLeftY);

x 位置看起来非常接近,但 y 位置完全关闭并且看起来像镜像。

我正在 iOS 10 iPhone 6s 上进行测试

我错过了什么吗?

【问题讨论】:

    标签: ios iphone augmented-reality image-recognition bounding-box


    【解决方案1】:

    问题是我正在使用预览框架来翻译屏幕中的点。但是通过边界框得到的点与预览视图无关,它们与 VideoFrame 相关(正如 catchoom.com 的支持人员所指出的那样)。 VideoFrame 大小由 capturePreset 设置,它只接受两个值 AVCaptureSessionPreset1280x720AVCaptureSessionPreset640x480。默认是AVCaptureSessionPreset1280x720

    所以在我的情况下,我必须使用大小 1280x720 进行计算,然后将这些坐标转换为预览视图大小中的坐标。

    所以它最终看起来像这样:

    let box = bestResult.matchBoundingBox
    
    let wVideoFrame:CGFloat = 1080.0;
    let hVideoFrame:CGFloat = 720.0;
    
    let wRelativePreview = wVideoFrame/CGFloat(preview.frame.size.height)
    let hRelativePreview = wVideoFrame/CGFloat(preview.frame.size.width)
    
    var tl = CGPoint(x: wVideoFrame * CGFloat(box.topLeftX),y: hVideoFrame * CGFloat(box.topLeftY));
    var tr = CGPoint(x: wVideoFrame * CGFloat(box.topRightX) ,y: hVideoFrame * CGFloat(box.topRightY));
    var br = CGPoint(x: wVideoFrame * CGFloat(box.bottomRightX),y: hVideoFrame * CGFloat(box.bottomRightY));
    var bl = CGPoint(x: wVideoFrame * CGFloat(box.bottomLeftX),y: hVideoFrame * CGFloat(box.bottomLeftY));
    
    tl = CGPoint(x: tl.x/wRelativePreview, y: tl.y/hRelativePreview)
    tr = CGPoint(x: tr.x/wRelativePreview, y: tr.y/hRelativePreview)
    br = CGPoint(x: br.x/wRelativePreview, y: br.y/hRelativePreview)
    bl = CGPoint(x: bl.x/wRelativePreview, y: bl.y/hRelativePreview) 
    
    // 4 square visualize top-left, top.right, bottom-left and bottom-right points
    var fr = vTL.frame;
    fr.origin = tl;
    vTL.frame = fr;
    
    fr.origin = tr;
    vTR.frame = fr;
    
    fr.origin = br;
    vBR.frame = fr;
    
    fr.origin = bl;
    vBL.frame = fr;
    

    现在这些点在屏幕上看起来还不错,但它们看起来有些旋转。所以我将视图旋转了 90 度:

    // overlay is the container of the 3 squares to visualize the points in screen
    overlay.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI/2.0))
    

    请注意,这不是来自 catchoom 支持的官方回复,这可能不是 100% 正确,但对我来说效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2017-07-17
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      相关资源
      最近更新 更多