0

I am trying to get 2D image coordinates from 3D vertices in ARKit/SceneKit. I have read the projectPoint document and have the following code using projectPoint,CGPoint:

var currentFaceAnchor: ARFaceAnchor?
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    guard anchor == currentFaceAnchor,
        let contentNode = selectedContentController.contentNode,
        contentNode.parent == node
        else { return }
    let vertices = currentFaceAnchor!.geometry.vertices
    for vertex in vertices {
        let projectedPoint = sceneView.projectPoint(node.convertPosition(SCNVector3(vertex), to: nil))

        let xVertex = CGFloat(projectedPoint.x)
        let yVertex = CGFloat(projectedPoint.y)
        if beginSaving == true {
        savedPositions.append(CGPoint(x: xVertex, y: yVertex))
        }
    }

I obtained some points: (216.42970275878906, 760.9256591796875),(208.1529541015625, 761.989501953125),(206.86944580078125, 750.0242919921875)...

I could not find much info regarding to 2D image coordinates and I find myself I could not fully understand this. I am wondering whether these points are the actual 2D pointes obtained from the 3D coordinates var vertices: [SIMD3<Float>] and how could one verify this? Any suggestions and help are appreciated!

Thanks,

swiftlearneer
  • 324
  • 4
  • 17
  • 1
    These look like valid coordinates in image-space. They are most likely coordinates in the 1920x1080 landscape image representing a single camera frame. What is your goal with the 2d points, specifically? (Beyond verifying they are valid) – Dennis L Apr 28 '21 at 21:20
  • As proposed here https://stackoverflow.com/a/65348768/3861865, you can draw the 2D points in a `debugView` on top of the `sceneView` to check if they are valid. – oliver May 04 '21 at 09:10
  • @oliver could you explain this: node.convertPosition(SCNVector3(vertex), to: nil)? – swiftlearneer May 04 '21 at 19:15
  • This is a build-in function. According to the documentation https://developer.apple.com/documentation/scenekit/scnnode/1407990-convertposition, with `to:nil`, the function will convert the node's position to the scene’s world coordinate space – oliver May 06 '21 at 08:24

0 Answers0