// Update is called once per frame void Update() { message2 = ""; message3 = ""; if (!camAvailable) { return; } // Fix the aspect ratio of the camera float ratio = (float)camera.width / (float)camera.height; fit.aspectRatio = ratio; float scaleY = camera.videoVerticallyMirrored ? -1f : 1f; background.rectTransform.localScale = new Vector3(1f, scaleY, 1f); int orient = -camera.videoRotationAngle; background.rectTransform.localEulerAngles = new Vector3(0, 0, orient); // Get the array of pixels of the current frame Color32[] rawImg = camera.GetPixels32(); System.Array.Reverse(rawImg); currentGesture = new GestureFrame(); // Search for all gestures. Call all detectors foreach (var cascade in cascades) { int nDetected = cascade.DetectInFrame(rawImg, camera.width, camera.height); // If at least one gesture is detected then it is added to the frame if (nDetected > 0) { lastFrames.AddGesturesToCurrentFrame(GestureFrame.GetList(cascade.type, cascade.foundInFrame, nDetected)); } } // Get the list of gesture types (just the names) detected List <GestureType> detectedGesturesTypesInCurrentFrame = lastFrames.GetGestureTypesInCurrentFrame(); // Check how many gestures were detected if (detectedGesturesTypesInCurrentFrame.Count == 1) // If only one gesture type was detected { // Select the first gesture currentGesture = lastFrames.GetCurrentFrame().GetGestures()[0]; } else if (detectedGesturesTypesInCurrentFrame.Count > 1) // If there are more than one gesture type { // Search for the most detected gesture in the previous frames GestureFrame prevalentPreviousFrames = lastFrames.GetPrevalentGestureInPreviousFrames(); // Check if the previous frames detected anything if (prevalentPreviousFrames.type == GestureType.NONE) { // If there is no previous prevalent, the first one is selected (because we do not have more information to pick one) currentGesture = lastFrames.GetCurrentFrame().GetGestures()[0]; } else { // Check if the prevalent gesture is among the detected ones if (detectedGesturesTypesInCurrentFrame.Contains(prevalentPreviousFrames.type)) // If it is among them { // The current gesture is one of the similar gestures in the current frame if (lastFrames.GetCurrentFrame().GetGestures(prevalentPreviousFrames.type).Count > 1) { // Should select the closest position to the previous prevalent } currentGesture = lastFrames.GetCurrentFrame().GetGestures(prevalentPreviousFrames.type)[0]; } else // If it is not among them { // Any gesture is selected (first one) currentGesture = lastFrames.GetCurrentFrame().GetGestures()[0]; } } } // Set the true positive of the current frame lastFrames.SetPrevalentInCurrentFrame(currentGesture); // Calculate the position of the gesture according to previous ones //currentGesturePosition = lastFrames.GetPrevalentPositionInPreviousFrame(currentGestureType); //lastFrames.GetPrevalentPositionInPreviousFrame(currentGesture); float RotateSpeed = 700f; // Move to the next frame in the buffer lastFrames.MoveToNextPosition(); }