/// <summary> /// /// </summary> /// <param name="processingEngine"></param> /// <param name="dataWidth">Largeur de la fenêtre de données dans laquelle se trouve les blobs</param> /// <param name="dataHeight">Hauteur de la fenêtre de données dans laquelle se trouve les blobs</param> public KinectBlobsMatcher(ImageProcessingEngine processingEngine, int dataWidth,int dataHeight) { if (processingEngine == null) throw new ArgumentNullException("processingEngine"); ProcessingEngine = processingEngine; if (ProcessingEngine.MaxMainBlobsCount <= 1) throw new ArgumentOutOfRangeException("processingEngine.MaxMainBlobsCount <= 1"); BlobsTracker = new ImageProcessing.BlobsTracker(); DataWidth = dataWidth; DataHeight = dataHeight; LeftHandBlob = new BlobParametersRecord(); LeftHandBlob.CursorPosition = idealLeftHandPosition; RightHandBlob = new BlobParametersRecord(); RightHandBlob.CursorPosition = idealRightHandPosition; scoringBlobs = new BlobParametersRecord[ProcessingEngine.MaxMainBlobsCount]; for (int i = 0; i < scoringBlobs.Length; i++) scoringBlobs[i] = new BlobParametersRecord(); LeftHandBlob.CursorPosition = idealLeftHandPosition; RightHandBlob.CursorPosition = idealRightHandPosition; }
private void CheckHandBlob(List<BlobsTracker.TrackedBlob> blobs, BlobParametersRecord handBlob, BlobsTracker.TrackedBlob excludedBlob, ref Vector2 idealHandPosition) { if (!blobs.Contains(handBlob.MBlob) || handBlob.MBlob == excludedBlob || handBlob.MBlob == null) { var p_idealPosition = new Vector2(idealHandPosition.X * DataWidth, idealHandPosition.Y * DataHeight); BlobsTracker.TrackedBlob closestBlob = null; double score = double.MaxValue; foreach (var item in blobs) { if (item != excludedBlob) { var d = (new Vector2(item.Current.EstimatedCursorX, item.Current.EstimatedCursorY) - p_idealPosition).Length(); if (d < score) { score = d; closestBlob = item; } } } if (score < 20) { handBlob.MBlob = closestBlob; handBlob.empty = false; } else { handBlob.MBlob = null; handBlob.empty = true; } } if (handBlob.MBlob != null) { var blobCursor = handBlob.MBlob.InvertedCursor ? new Vector2(handBlob.MBlob.Current.InvertedEstimatedCursorX / DataWidth, handBlob.MBlob.Current.InvertedEstimatedCursorY / DataHeight) : new Vector2(handBlob.MBlob.Current.EstimatedCursorX / DataWidth, handBlob.MBlob.Current.EstimatedCursorY / DataHeight); var newPos = handBlob.CursorPosition * updateLatency + (1 - updateLatency) * blobCursor; if (!double.IsNaN(newPos.X) && !double.IsNaN(newPos.Y)) handBlob.CursorPosition = newPos; } else handBlob.CursorPosition = idealHandPosition; }