void OnGUI() { GUI.Box(drawArea, "Draw Area"); GUI.Label(new Rect(10, Screen.height - 40, 500, 50), message); if (GUI.Button(new Rect(Screen.width - 100, 10, 100, 30), "Recognize")) { recognized = true; Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; } GUI.Label(new Rect(Screen.width - 200, 150, 70, 30), "Add as: "); newGestureName = GUI.TextField(new Rect(Screen.width - 150, 150, 100, 30), newGestureName); if (GUI.Button(new Rect(Screen.width - 50, 150, 50, 30), "Add") && points.Count > 0 && newGestureName != "") { string fileName = String.Format("{0}/{1}.xml", "Assets/PDollar/Resources/GestureSet/", newGestureName); #if !UNITY_WEBPLAYER GestureIO.WriteGesture(points.ToArray(), newGestureName, fileName); #endif trainingSet.Add(new Gesture(points.ToArray(), newGestureName)); newGestureName = ""; } }
private void RecognizeGesture() { Gesture candidate = new Gesture(points.ToArray()); string gestureClass = ""; string recognizer = ""; switch (cbRecognizer.SelectedIndex) { case 0: recognizer = "$P"; gestureClass = PointCloudRecognizer.Classify(candidate, trainingSet); break; case 1: recognizer = "$P+"; gestureClass = PointCloudRecognizerPlus.Classify(candidate, trainingSet); break; case 2: recognizer = "$Q"; QPointCloudRecognizer.UseEarlyAbandoning = chkUseEarlyAbandoning.Checked; QPointCloudRecognizer.UseLowerBounding = chkUseLowerBounding.Checked; gestureClass = QPointCloudRecognizer.Classify(candidate, trainingSet); break; } MessageBox.Show("Recognized as: " + gestureClass, recognizer); }
void EndMovement() { Debug.Log("End Movement"); isMoving = false; //Create the gesture from the position list Point[] pointArray = new Point[positionsList.Count]; for (int i = 0; i < positionsList.Count; i++) { Vector2 screenPoint = Camera.main.WorldToScreenPoint(positionsList[i]); pointArray[i] = new Point(screenPoint.x, screenPoint.y, 0); } Gesture newGesture = new Gesture(pointArray); if (creationMode) { newGesture.Name = newGestureName; traningSet.Add(newGesture); string fileName = Application.persistentDataPath + "/" + newGestureName + ".xml"; GestureIO.WriteGesture(pointArray, newGestureName, fileName); } else { Result result = PointCloudRecognizer.Classify(newGesture, traningSet.ToArray()); Debug.Log(result.GestureClass + result.Score); if (result.Score > recognitionThreshold) { OnRecognized.Invoke(result.GestureClass); } } }
private Result?GetCurrentGesture() { for (var i = 1; i < points.Count; i++) { float lineZ = initialCameraTransform.position.z + initialCameraTransform.forward.z * 2.0f; Vector3 startPos = new Vector3(points[i - 1].X, points[i - 1].Y, lineZ); Vector3 endPos = new Vector3(points[i].X, points[i].Y, lineZ); Debug.DrawLine(startPos, endPos, Color.green, 0.2f); } if (points.Count < 20) { return(null); } // Check for minimum gesture size if (!IsGestureLargeEnough(points)) { return(null); } Gesture candidate = new Gesture(points.ToArray()); /* foreach (var point in candidate.Points) * { * Debug.Log(point.X + " " + point.Y + " " + point.StrokeID); * } */ return(PointCloudRecognizer.Classify(candidate, trainingSet)); }
public static void DetectSpell(Gesture gesture, Gesture[] trainingSet) { string spellName = PointCloudRecognizer.Classify(gesture, trainingSet); if (spellName.Length <= 0 || !spells.ContainsKey(spellName) || !learnedSpells.Contains(spellName)) { return; } GameObject spellToCast = spells[spellName]; switch (spellName) { case "Fire Ball": GameController.player.GetComponent <PlayerAI>().CastTargetSpell(spellToCast, 0f); break; case "Wind Wave": GameController.player.GetComponent <PlayerAI>().CastSelfSpell(spellToCast, 0f); break; case "Arcane Beam": GameController.player.GetComponent <PlayerAI>().CastTargetSpell(spellToCast, 1f); break; case "Chain Lightning": GameController.player.GetComponent <PlayerAI>().CastTargetSpell(spellToCast, 0f); break; } //print(spellName); }
private void RecognizeGesture() { Gesture candidate = new Gesture(points.ToArray()); string gestureClass = PointCloudRecognizer.Classify(candidate, trainingSet); MessageBox.Show("Recognized as: " + gestureClass); }
/// <summary> /// Checks for classification after a set period /// </summary> /// <returns></returns> public IEnumerator DelayRecognition() { yield return(new WaitForSeconds(recognitionDelay)); // Classify the gesture from our points array and training set Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); // Only return data if the confidence exceeds the required minimum confidence score if (gestureResult.Score <= minimumRequiredConfidenceScore) { OnUnmatchedGesture?.Invoke(); yield break; } // If a gesture is expected but another gesture is detected, "Incorrect Symbol" will be returned with a confidence score of 1 if (!String.IsNullOrEmpty(expectedGesture) && expectedGesture != gestureResult.GestureClass) { OnMatchedGesture?.Invoke("Incorrect Symbol", 1); yield break; } // gestureResult.GestureClass represents the matched gesture GetComponentInChildren <Text>().text = gestureResult.GestureClass; // Send off the results to other classes subscribed to the event OnMatchedGesture?.Invoke(gestureResult.GestureClass, gestureResult.Score); DetroyLineRenderers(gameObject); }
public void Recognize() { if (Input.touchCount > 0) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { if (recognized) { recognized = false; strokeId = -1; points.Clear(); } ++strokeId; } if (touch.phase == TouchPhase.Moved) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); points.Add(new Point(virtualKeyPosition.x, -virtualKeyPosition.y, strokeId)); } if (touch.phase == TouchPhase.Ended) { recognized = true; Gesture candidate = new Gesture(points.ToArray()); gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); } } }
public Tuple <GameObject, float> Gesture_Classify(Point[] candidate_points, float t) { Debug.Log(t); Gesture candidate = new Gesture(candidate_points); length += candidate.PathLength(candidate_points); time += t; numGesture++; Tuple <GameObject, float> tower = null; Tuple <string, float> result = PointCloudRecognizer.Classify(candidate, trainingSet); similarity += result.Item2; Debug.Log(result); if (result.Item2 < 0.7) { return(null); } for (int i = 0; i < objs.Count; i++) { if (result.Item1 == towersType[i]) { tower = new Tuple <GameObject, float>(objs[i], result.Item2); break; } } return(tower); }
void EndMovement() { //Debug.Log("End Movement"); isMoving = false; //Create The Gesture From The Position List Point[] pointArray = new Point[positionsList.Count]; //same size with positionsList for (int i = 0; i < positionsList.Count; i++) { Vector2 screenPoint = Camera.main.WorldToScreenPoint(positionsList[i]); //movement의 x,y좌표(point) 추출 pointArray[i] = new Point(screenPoint.x, screenPoint.y, 0); //stroke가 뭐지???? } Gesture newGesture = new Gesture(pointArray); //pointArray배열 안에 있는 point들로 이루어진 gesture //Add a new gesture to training set if (creationMode) //새로 gesture을 만들고 싶은 경우 { newGesture.Name = newGestureName; //public으로 입력해준 newGestureName의 값을 새 gesture의 이름으로 설정 trainingSet.Add(newGesture); //Gesture List에 newGesture 넣기 //생성한 gesture 파일로 저장 string fileName = Application.persistentDataPath + "/" + newGestureName + ".xml"; GestureIO.WriteGesture(pointArray, newGestureName, fileName); } //recognize else { Result result = PointCloudRecognizer.Classify(newGesture, trainingSet.ToArray()); //gesture 분류 //tells us which geture it is, but also the score of the recognition of this element Debug.Log(result.GestureClass + " " + result.Score); //결과 출력! } }
void Recognize() { recognized = true; if (Time.unscaledTime - startDrawingTime < 0.3f) { return; } Gesture candidate = new Gesture(points.ToArray()); try { Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; //Debug.Log(message); // Comprobar si se ha acertado symbolsGameManager.OnSymbolDrawn(gestureResult); } catch (IndexOutOfRangeException exception) { Debug.LogException(exception, this); } //if (IsGestureCorrect(gestureResult.Score)) //Se puede hacer un score para todos o que cada uno tenga su nivel de score (GestureClass). De momento, todos igual // Debug.Log("¡Correcto!"); //else Debug.Log("ERROR!"); }
public override void FlickOccured(object sender, System.EventArgs e) { bool cast = twoFingerFlickGesture.ScreenFlickVector.x > 0f; if (cast && !recognized) { recognized = true; PDollarGestureRecognizer.Gesture candidate = new PDollarGestureRecognizer.Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); if (gestureResult.Score > runeSuccessScore) { RuneSuccess(gestureResult); } else { RuneFailure(); } } else if (!cast) { RuneFailure(); } }
void OnGdUI() { GUI.Box(drawArea, "Draw Area"); GUI.Label(new Rect(10, Screen.height - 40, 500, 50), message); if (GUI.Button(new Rect(Screen.width - 100, 10, 100, 30), "Recognize")) { recognized = true; Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; } GUI.Label(new Rect(Screen.width - 200, 150, 70, 30), "Add as: "); newGestureName = GUI.TextField(new Rect(Screen.width - 150, 150, 100, 30), newGestureName); if (GUI.Button(new Rect(Screen.width - 50, 150, 50, 30), "Add") && points.Count > 0 && newGestureName != "") { string fileName = System.String.Format("{0}/{1}-{2}.xml", Application.persistentDataPath, newGestureName, System.DateTime.Now.ToFileTime()); #if !UNITY_WEBPLAYER GestureIO.WriteGesture(points.ToArray(), newGestureName, fileName); #endif trainingSet.Add(new Gesture(points.ToArray(), newGestureName)); newGestureName = ""; } }
//fonction qui termine le mouvement et essaie de reconnaître ou créer le glyphe donné par le joueur void endMove() { //on termine le mouvement inMotion = false; //creer un tableau qui a la grandeur du tableau de points créé en start+update Point[] pointsArray = new Point[positionList.Count]; //pour chaque point de la liste de positions for (int i = 0; i < positionList.Count; i++) { //le point dans l'ecran devient la position en i traduite du monde vers l'ecran Vector2 screenPoint = Camera.main.WorldToScreenPoint(positionList[i]); //on ne veut garder que le x et y de ce point pour la reconnaissance pointsArray[i] = new Point(screenPoint.x, screenPoint.y, 0); } //le mouvement donné = aux points décrits dans la boucle ci-haut Gesture newGesture = new Gesture(pointsArray); //si on est en mode de creation de glyphe if (creationMode) { //le nom du glyph devient celui choisi dans la console newGesture.Name = newGestureName; //rajouter ce glyph à la liste de glyphes connus trainingSet.Add(newGesture); //créer un fichier xml qui aura le nom indiqué et qui contiendra la liste de points string fileName = Application.dataPath + "/gestures/" + newGestureName + ".xml"; GestureIO.WriteGesture(pointsArray, newGestureName, fileName); } //si on n'est pas en mode creatif else { //besoin de >1 pour faire le calcul, sinon crash (on peut pas calculer le chemin entre 2 points s'il n'y a pas 2 points!) if (pointsArray.Length > 1) { //Provient du code PDollar //fonction Classify de PointCloudRecognizer -> retourne la class du glyphe qui match le plus entre la gesture du joueur et celles dans la liste //transferer la liste en array avec toArray() Result result = PointCloudRecognizer.Classify(newGesture, trainingSet.ToArray()); //si le score de notre resultat est acceptable if (result.Score > recognitionThreshold) { //invoquer la fonction implémentée dans l'inspecteur de Unity OnRecognized.Invoke(result.GestureClass); } } } //detruit le tracé apres 3s Destroy(trailClone, 3f); //enlève le parent du tracé trailClone.transform.parent = null; }
// Dokonuje porownania naszych punktow z zaladowanymi symbolami. Wynik porownania zapisuje w message. protected Result checkPattern() { Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; return(gestureResult); }
private void OnSkillDraw(List <Point> points) { Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); Debug.Log(gestureResult.GestureClass + " " + System.Math.Round(gestureResult.Score, 2)); spellCaster.CastSpell(gestureResult.GestureClass); }
public static void Classify() { var points = PointBuffer.ToArray().Normalize(SampleSize, PointOrigin.TopLeft); var gestures = Resources.LoadAll <Gesture>(""); var winner = PointCloudRecognizer.Classify(points, gestures); Debug.Log(string.Format("<color=#57A64A>-->Winner is {0}!!!</color>", winner)); }
public void recogniseStroke() { isClassified = true; Gesture classifyArray = new Gesture(strokePoints.ToArray()); Result classificationResult = PointCloudRecognizer.Classify(classifyArray, classificationGestures.ToArray()); recogniseMessage.text = classificationResult.GestureClass; }
/// <summary> /// Callback for when a touch ends /// </summary> private void HandleOnTouchUp(int playerID, int fingerID, Vector2 pos) { GestureData gs = playerGestureState [playerID]; gs.numFingersDown--; if (gs.numFingersDown < 0) { gs.numFingersDown = 0; //something went wrong } float swipeTime = Time.time - gs.swipeStartTime; //Time the touch stayed at the screen till now. if (gs.couldBeSwipe && swipeTime < MAX_SWIPE_TIME) { float xSwipeDist = pos.x - gs.swipeStartPos.x; //X Swipe distance float ySwipeDist = pos.y - gs.swipeStartPos.y; //Y Swipe distance if (Mathf.Abs(xSwipeDist) > MIN_SWIPE_DIST) //only one swipe allowed at a time { if (xSwipeDist < 0 && SwipeLeft != null) { SwipeLeft(playerID); } else if (xSwipeDist >= 0 && SwipeRight != null) { SwipeRight(playerID); } } else if (Mathf.Abs(ySwipeDist) > MIN_SWIPE_DIST) { if (ySwipeDist < 0 && SwipeDown != null) { SwipeDown(playerID); } else if (ySwipeDist >= 0 && SwipeUp != null) { SwipeUp(playerID); } } } if (gs.numFingersDown == 0 && gs.points.Count >= 2) { gs.points.Add(new Point(pos.x, pos.y, fingerID)); Gesture candidate = new Gesture(gs.points.ToArray()); string gestureClass = PointCloudRecognizer.Classify(candidate, trainingSet); if (OnComplexGesture != null) { OnComplexGesture(playerID, gestureClass); } gs.points.Clear(); } playerGestureState [playerID] = gs; }
public Result Recognizer() { recognized = true; Gesture candidate = new Gesture(points.ToArray()); gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; return(gestureResult); }
/// <summary> /// Called when input released (gesture completed) /// </summary> void CompleteGesture() { // Get gesture result Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; CheckGesture(gestureResult); ClearDrawing(); }
private void RecognizeGesture() { Gesture candidate = new Gesture(points.ToArray()); string gestureClass = ""; switch (cbRecognizer.SelectedIndex) { case 0: gestureClass = PointCloudRecognizer.Classify(candidate, trainingSet); break; case 1: gestureClass = PointCloudRecognizerPlus.Classify(candidate, trainingSet); break; } MessageBox.Show("Recognized as: " + gestureClass); }
private Result RecognizeGesture() { foreach (Point pnt in points) { Debug.Log("Points x:" + pnt.X + "Points y:" + pnt.Y); } Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); return(gestureResult); //Debug.Log(gestureResult.GestureClass + " " + gestureResult.Score); }
override protected void OnGUI() { //Tutaj poza wyswietlaniem wiadomosci dodajemy przycisk do rozpoznawania dedykowane i przycisk do dodawania symbolu. GUI.contentColor = Color.yellow; GUIStyle guiButton = new GUIStyle(GUI.skin.button); guiButton.fontSize = 50; guiButton.normal.textColor = Color.yellow; GUI.contentColor = Color.yellow; GUIStyle guiLabel = new GUIStyle(); guiLabel.fontSize = 50; guiLabel.normal.textColor = Color.yellow; GUI.contentColor = Color.yellow; GUIStyle guiText = new GUIStyle(GUI.skin.textField); guiText.fontSize = 60; guiText.normal.textColor = Color.yellow; //in awake or start use these lines of code to set the size of the font base.OnGUI(); if (GUI.Button(new Rect(50, Screen.height - 300, 400, 100), "Recognize", guiButton)) { Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; } GUI.Label(new Rect(100, Screen.height - 150, 200, 100), "Save as: ", guiLabel); newGestureName = GUI.TextField(new Rect(350, Screen.height - 150, 600, 75), newGestureName, guiText); if (GUI.Button(new Rect(600, Screen.height - 300, 400, 100), "Save", guiButton) && points.Count > 0 && newGestureName != "") { string fileName = String.Format("{0}/{1}-{2}.xml", Application.persistentDataPath, newGestureName, DateTime.Now.ToFileTime()); #if !UNITY_WEBPLAYER GestureIO.WriteGesture(points.ToArray(), newGestureName, fileName); #endif trainingSet.Add(new Gesture(points.ToArray(), newGestureName)); newGestureName = ""; } }
void Update() { if (ready) { if (Input.touchCount > 0) { reset = false; var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { startTime = Time.time; startPos = touch.position; if (recognized) { recognized = false; strokeId = -1; points.Clear(); } ++strokeId; } if (touch.phase == TouchPhase.Moved) { points.Add(new Point(touch.position.x, -touch.position.y, strokeId)); } if (touch.phase == TouchPhase.Ended) { if (Time.time - startTime < maxTime && (touch.position - startPos).magnitude > minDist) { recognized = true; if (points.Count > 2) { Gesture candidate = new Gesture(points.ToArray()); gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); InterpretGesture(gestureResult.GestureClass, points); } } } } } if (Input.touchCount == 0 && !reset) { reset = true; Reset(); } }
void Update() { //if (Input.GetMouseButtonDown(1)) // rX = Input.mousePosition.x; //if (Input.GetMouseButtonUp(1)) //{ // if (Input.mousePosition.x > rX) // { // recognized = true; // PDollarGestureRecognizer.Gesture candidate = new PDollarGestureRecognizer.Gesture(points.ToArray()); // Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); // if (gestureResult.Score > runeSuccessScore) // RuneSuccess(gestureResult); // else // RuneFailure(); // } // else // { // RuneFailure(); // } //} if (Input.GetKeyDown(KeyCode.C)) { if (!recognized) { recognized = true; PDollarGestureRecognizer.Gesture candidate = new PDollarGestureRecognizer.Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); if (gestureResult.Score > runeSuccessScore) { RuneSuccess(gestureResult); } else { RuneFailure(); } } } else if (Input.GetKeyDown(KeyCode.X)) { RuneFailure(); } }
public void OnEndDrag(PointerEventData eventData) { var sample = _pointBuffer.ToArray().Normalize(32, PointOrigin.BottomLeft); var gesture = PointCloudRecognizer.Classify(sample, _gestures, .15f); if (gesture == string.Empty) { Debug.Log("<color=#57A64A>-->No match.</color>"); } else { Debug.Log(string.Format("<color=#57A64A>-->Match {0}!</color>", gesture)); } ProccessGesture(gesture); }
/// <summary> /// 辨識 /// </summary> public bool Recognize() { recognized = true; Gesture candidate = new Gesture(points.ToArray()); Result gestureResult = PointCloudRecognizer.Classify(candidate, traingSet.ToArray()); message = gestureResult.GestureClass + " " + gestureResult.Score; print(message); print(answer); print(gestureResult.GestureClass == answer && gestureResult.Score > 0.3f); return(gestureResult.GestureClass == answer && gestureResult.Score > 0.3f); }
public void recognizeLatestGesture(List <Point> gesture) { Gesture candidate = new Gesture(gesture.ToArray()); inputGestures.Add(candidate); Result gestureResult = PointCloudRecognizer.Classify(candidate, trainingSet.ToArray()); if (gestureResult.Score >= 0.5) { resultingGestures.Add(gestureResult); candidate.Name = gestureResult.GestureClass; Debug.Log(candidate.Name); Debug.Log(gestureResult.Score); } }
public static void RecognizeEvents(string eventStream) { List <Gesture> templates = new List <Gesture>(); string[] files = Directory.GetFiles("./templates"); foreach (string file in files) { templates.Add(ReadGestureFromFile(file, false)); } try { StreamReader reader = File.OpenText(eventStream); List <Point> pointList = new List <Point>(); int strokeID = 0; string line; while ((line = reader.ReadLine()) != null) { if (line == "MOUSEDOWN") { continue; } else if (line == "MOUSEUP") { strokeID++; } else if (line == "RECOGNIZE") { Gesture gesture = new Gesture(pointList.ToArray()); string recognized = PointCloudRecognizer.Classify(gesture, templates.ToArray()); if (recognized != "") { Console.WriteLine(recognized); } strokeID = 0; pointList.Clear(); } else { int[] coords = line.Split(',').Select(int.Parse).ToArray(); pointList.Add(new Point(coords[0], coords[1], strokeID)); } } } catch (FileNotFoundException) { Console.WriteLine("File " + eventStream + " not found!"); } }