public static float GetDistance_3d(this DepthFrame frame, PointF from, PointF to, Intrinsics intr) { // Query the frame for distance // Note: this can be optimized // It is not recommended to issue an API call for each pixel // (since the compiler can't inline these) // However, in this example it is not one of the bottlenecks float udist = frame.GetDistance((int)@from.X, (int)@from.Y); //From float vdist = frame.GetDistance((int)to.X, (int)to.Y); //To // Deproject from pixel to point in 3D var upoint = DeprojectPixelToPoint(intr, from, udist); var vpoint = DeprojectPixelToPoint(intr, to, vdist); // Calculate euclidean distance between the two points return((float)Math.Sqrt(Math.Pow(upoint[0] - vpoint[0], 2) + Math.Pow(upoint[1] - vpoint[1], 2) + Math.Pow(upoint[2] - vpoint[2], 2))); }
/// <summary> /// 計算該像素點座標之深度值(單位:m) /// </summary> internal float get_distance(DepthFrame depth, int x, int y) { float dist = depth.GetDistance(x, y); return(dist); }