如果你使用 aEnumIndexableCollection<FeaturePoint, PointF>
所以你可以使用 aFaceTrackFrame
的GetProjected3DShape()
方法。你像这样使用它:
private byte[] colorImage;
private ColorImageFormat colorImageFormat = ColorImageFormat.Undefined;
private short[] depthImage;
private DepthImageFormat depthImageFormat = DepthImageFormat.Undefined;
KinectSensor Kinect = KinectSensor.KinectSensors[0];
private Skeleton[] skeletonData;
colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame();
depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame();
skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame();
colorImageFrame.CopyPixelDataTo(this.colorImage);
depthImageFrame.CopyPixelDataTo(this.depthImage);
skeletonFrame.CopySkeletonDataTo(this.skeletonData);
skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
foreach(Skeleton skeletonOfInterest in skeletonData)
{
FaceTrackFrame frame = faceTracker.Track(
colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);
}
private EnumIndexableCollection<FeaturePoint, PointF> facePoints = frame.GetProjected3DShape();
然后您可以使用图像中的每个点。我会有一个const double preferedDistance
你可以将当前深度和不同点的 x 和 y 相乘,以通过公式找到 x 和 y 的首选版本和深度
首选距离/当前距离
例子:
const double preferredDistance = 500.0;//this can be any number you want.
double currentDistance = //however you are calculating the distance
double whatToMultiply = preferredDistance / currentDistance;
double x1 = this.facePoints[39].X;
double y1 = this.facePoints[39].Y;
double x2 = this.facePoints[8].X;
double y2 = this.facePoints[8].Y;
double result = whatToMultiply * //however you are calculating distance.
然后你可以List<>
知道要搜索的距离。我还建议你有一个List<>
bool ,如果结果匹配,它与要设置为 true 的距离相协调,这样你就可以跟踪哪个 bool 是真/假。
例子:
List<double> DistanceFromEyeToNose = new List<double>
{
1,
2,
3 //etc
};
List<bool> IsMatch = new List<bool>
{
false,
false,
false //etc
};
然后使用for
循环搜索它。
for (int i = 0; i < DistanceFromEyeToNose.Count; i++)
{
if (result == DistanceFromEyeToNose[i]) IsMatch[i] = true;
}
希望这可以帮助!