I am trying to project rawFeaturePoints from ARFrame into the 2D Image plane, and get the distances from the points to the camera, but when I plot them using Python, they don't make sense. Here's my attempt:
func get2DPoints(arView: ARSCNView, arCamera: ARCamera, rawFeaturePoints: [vector_float3], filename: String) {
file_path = filename
let cameraPosition = arCamera.transform.columns.3
let screenSize = UIScreen.main.bounds
for point in rawFeaturePoints {
let scn_point = SCNVector3(point)
// get the pixel coordinates
let projected_point = arView.projectPoint(scn_point)
print("Projected Point: \(projected_point)")
if projected_point.x > 0 && projected_point.y > 0 {
// Calculating distance between a raw feature point and the camera
let distance_from_camera = sqrt(pow(cameraPosition.x - scn_point.x, 2) + pow(cameraPosition.y - scn_point.y, 2) + pow(cameraPosition.z - scn_point.z, 2))
let feature_point = FeaturePoint(x: projected_point.x, y: projected_point.y, z: distance_from_camera)
featurePoints.append(feature_point)
}
}
print("Finished processing rawFeaturePoints")
}
I am getting the points from frame.rawFeaturePoints?.points and then projecting them. The points mostly make sense, but when I try to plot them in Python on top of the frame, they are not correct. My understanding is that projectPoint already projects the point to the 2D Image plane so there would be no need for further transforms. It seems to be some that the origin could be different in python and ARKit but both are the same (as far as I know, top left). Any ideas?