2

I am using AVFoundation for front camera View. From the Front camera, I'm detecting the Face from each frame using vision framework. From that, I'm able to get CGPoints of nose. Now, I want to add a 3D object on one of the nose points using sceneKit view and I want to convert those Nose CGPoint to SCNVector3 so that I can give the position to the 3D object.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Himanshu Ahuja
  • 197
  • 1
  • 13
  • Could be a duplicate of https://stackoverflow.com/questions/26832208/get-scnvector3-from-cgpoint – adamfowlerphoto Jan 25 '18 at 12:11
  • @spads SCNVector3 taking x,y,z values in very small magnitude. For eg. Value of even 0.1 is making large displacement. The Link u have mentioned, is projecting the CGPoint, but even projection does'nt give the values of such small magnitude. – Himanshu Ahuja Jan 29 '18 at 05:26

1 Answers1

1

Convert CGPoint to SCNVector in SceneKit either by hitTest or raycast method,

 let touchPoint = CGPoint(x: 34, y: 298) // for hitTest example
 let hitTestResult : [ARHitTestResult]  = sceneView.hitTest(touchPoint, types: .featurePoint)
     guard let hitResult = hitTestResult.first else {
       return
       }
 let vector = SCNVector3((hitResult.worldTransform.columns.3.x), (hitResult.worldTransform.columns.3.y), (hitResult.worldTransform.columns.3.z))
        print(vector) // returns somewhat like this SCNVector3(x: -0.2502137, y: 0.15422173, z: -0.17789307)
AzeTech
  • 623
  • 11
  • 21