{
if (bindable is Overlay overlay && newValue is Landmark[,] landmark)
{
- int numberOfPeople = landmark.GetLength(1);
- int numberOfBodyParts = landmark.GetLength(0);
+ int numberOfPeople = landmark.GetLength(0);
+ int numberOfBodyParts = landmark.GetLength(1);
int numberOfPeopleDisplayed = System.Math.Min(numberOfPeople, MaxNumberOfPeople);
for (int i = 0; i < numberOfPeopleDisplayed; i++)
overlay.AddDrawables(bodyMarker);
}
- var landmarksRow = Enumerable.Range(0, landmark.GetLength(0))
- .Select(x => landmark[x, i])
+ var landmarksRow = Enumerable.Range(0, numberOfBodyParts)
+ .Select(x => landmark[i, x])
.ToArray();
overlay.bodyMarkers[i].Update(landmarksRow, overlay.Size);
}
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Fitness.Services;
}
}
+ private static void LogPoseDetection(Tizen.Multimedia.Vision.Landmark[,] landmarks)
+ {
+ int numberOfPeople = landmarks.GetLength(0);
+ int numberOfBodyParts = landmarks.GetLength(1);
+
+ for (int i = 0; i < numberOfPeople; ++i)
+ {
+ var scores = Enumerable.Range(0, numberOfBodyParts)
+ .Select(j => landmarks[i, j].Score);
+ float averageScore = scores.Average();
+ var trimmedScores = scores.Select(score => score.ToString(".000"));
+
+ Services.Logger.Debug($"scores: {string.Join(", ", trimmedScores)}; avg: {averageScore.ToString(".000")}");
+ }
+ }
+
private async void DetectPreview(object sender, PreviewEventArgs e)
{
if (e.Preview.PlaneType == PlaneType.TriplePlane && Interlocked.Exchange(ref isInferencing, 1) == 0)
{
- await Task.Run(() => poseDetector.Detect(e.Preview.Plane as TriplePlane, (uint)e.Preview.Resolution.Height, (uint)e.Preview.Resolution.Width));
- Interlocked.Exchange(ref isInferencing, 0);
+ var stopwatch = new System.Diagnostics.Stopwatch();
+ stopwatch.Start();
+
+ await Task.Run(async () =>
+ {
+ try
+ {
+ var plane = e.Preview.Plane as TriplePlane;
+ if (plane == null)
+ {
+ throw new System.Exception($"Unsupported plane type: {e.Preview.Plane.GetType()}");
+ }
+
+ uint width = (uint)e.Preview.Resolution.Width;
+ uint height = (uint)e.Preview.Resolution.Height;
+
+ var landmarks = await poseDetector.Detect(plane, height, width);
- // TODO: draw line
+ // TODO: Remove when pose detection logs are not required.
+ LogPoseDetection(landmarks);
+
+ NUIContext.InvokeOnMainThread(() =>
+ {
+ // TODO: Pose detection should be moved to the View Model, but now happens here at the View and updates the View Model.
+ if (BindingContext is ViewModels.ScanningViewModel viewModel)
+ {
+ viewModel.PoseLandmarks = landmarks;
+ }
+ });
+ }
+ catch (System.Exception exception)
+ {
+ Services.Logger.Error(exception.Message);
+ }
+ finally
+ {
+ stopwatch.Stop();
+ Services.Logger.Debug($"total time {stopwatch.ElapsedMilliseconds} msec");
+ }
+ });
+
+ Interlocked.Exchange(ref isInferencing, 0);
}
}
}