代码之家  ›  专栏  ›  技术社区  ›  Jesse J

来自ARKit的深度数据

  •  4
  • Jesse J  · 技术社区  · 7 年前

    我试图创建一个单独的AVCaptureSession来接收AVDepthData,但我无法与ARKit同时运行AVCaptureSession。要么调用ARSCNView更新,要么调用AVCaptureDepthDataOutputDelegate,但决不能同时调用两者。

    4 回复  |  直到 7 年前
        1
  •  1
  •   halileohalilei    7 年前

    this 线程并在本文中提到 video ,不,ARKit不向您提供 AVDepthData 当您处于世界跟踪模式时。唯一一次当你被提供

        2
  •  1
  •   johnnyb    5 年前

    let height = Int(arView.frame.height)
    let width = Int(arView.frame.width)
    
    
    UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), true, 0)
    while y < height {
      var x = 0
      while x < width {
        let location = CGPoint(x: x, y: y)
        let results = arView.hitTest(location, types: [.featurePoint, .existingPlane, .estimatedVerticalPlane, .estimatedHorizontalPlane, .existingPlaneUsingGeometry, .existingPlaneUsingExtent])
        let alpha = results.isEmpty ? 1.0 : (1.0 / CGFloat(results.count))
        for result in results {
          let value = 1.0 / (result.distance + 1.0)
          switch result.type {
            case .featurePoint:
              UIColor(red: value, green: 0, blue: 0, alpha: alpha).setFill()
            case .existingPlane:
              UIColor(red: 0, green: 1, blue: 0, alpha: alpha).setFill()
            case .estimatedVerticalPlane:
              UIColor(red: 0, green: 0, blue: value, alpha: alpha).setFill()
            case .estimatedHorizontalPlane:
              UIColor(red: 0, green: 0, blue: value, alpha: alpha).setFill()
            case .existingPlaneUsingGeometry:
              UIColor(red: value, green: value, blue: value, alpha: alpha).setFill()
            case .existingPlaneUsingExtent:
              UIColor(red: value, green: value, blue: value, alpha: alpha).setFill()
            default:
              UIColor.black.setFill()
          }
          UIRectFill(CGRect(x: x, y: y, width: 1, height: 1))
        }
    
        x += 1
      }
    
      y += 1
    
    }
    
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    
    imgView.image = image

    如果需要,可以调整颜色。无论如何,我认为这让我很好地了解了阿基特对世界的看法。

        3
  •  0
  •   hzhou    7 年前

    arkit也使用AVCaptureSession,所以现在在AVCaptureSession进行时不可能使用arscnview,因为它将调用委托-(void)sessionwasdrupted:(ARSession*)session;

        4
  •  0
  •   Psycrow    5 年前

    let configuration = ARWorldTrackingConfiguration()
    configuration.frameSemantics = .personSegmentationWithDepth
    

    然后,在ARSessionDelegate回调中,您可以从ARFrame访问估计的DDepthData

    func session(_ session: ARSession, didUpdate frame: ARFrame) {
         let estimatedDepthData = frame.estimatedDepthData
         ....
    }
    

    您也可以检查

    https://developer.apple.com/documentation/arkit/arframe/3152989-estimateddepthdata

    https://developer.apple.com/documentation/arkit/arframe/2984226-segmentationbuffer