예제 #1
0
        //Just Capture Data
        //Pass in an array for data points.
        public void AddGestureToTrainingExamples(List <Vector3> capturedLine, Handedness hand)
        {
            string gestureFileLocation = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + recognizerName + "/Gestures/";

            //we need to check if this directory exists.
            //if not we need to create the directory and file.
            System.IO.Directory.CreateDirectory(gestureFileLocation);

            if (capturedLine.Count >= 11)
            {
                if (!Config.USE_RAW_DATA)
                {
                    capturedLine = Utils.SubDivideLine(capturedLine);
                    capturedLine = Utils.DownResLine(capturedLine);
                }

                GestureExample saveMe = new GestureExample();
                saveMe.name          = CurrentGesture.name;
                saveMe.data          = capturedLine;
                saveMe.hand          = hand;
                saveMe.raw           = Config.USE_RAW_DATA;
                saveMe.isSynchronous = CurrentGesture.isSynchronous;
                //System.IO.StreamWriter file = new System.IO.StreamWriter(gestureFileLocation + gestureName + ".txt", true);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(gestureFileLocation + CurrentGesture.name + ".txt", true))
                {
                    file.WriteLine(JsonUtility.ToJson(saveMe));
                }
                CurrentGesture.exampleCount++;
            }
        }
예제 #2
0
        //Just Capture Data
        //Pass in an array for data points.
        public void AddGestureToTrainingExamples(string gestureName, List <Vector3> capturedLine)
        {
            string gestureFileLocation = Config.SAVE_FILE_PATH + recognizerName + "/Gestures/";

            //we need to check if this directory exists.
            //if not we need to create the directory and file.
            System.IO.Directory.CreateDirectory(gestureFileLocation);

            if (capturedLine.Count >= 11)
            {
                if (!Config.USE_RAW_DATA)
                {
                    capturedLine = Utils.Instance.SubDivideLine(capturedLine);
                    capturedLine = Utils.Instance.DownResLine(capturedLine);
                }



                GestureExample saveMe = new GestureExample();
                saveMe.name = gestureName;
                saveMe.data = capturedLine;
                saveMe.raw  = Config.USE_RAW_DATA;
                //System.IO.StreamWriter file = new System.IO.StreamWriter(gestureFileLocation + gestureName + ".txt", true);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(gestureFileLocation + gestureName + ".txt", true))
                {
                    file.WriteLine(JsonUtility.ToJson(saveMe));
                }
            }
        }
예제 #3
0
        public void DeleteGestureExample(GestureExample gestureExample, int lineNumber)
        {
            Gesture g = gestureSettings.FindGesture(gestureExample.name);

            g.exampleCount--;

            Utils.DeleteGestureExample(currentNeuralNet, gestureExample.name, lineNumber);
            allExamples.Remove(gestureExample);
            for (int i = grids.Count - 1; i >= 0; i--)
            {
                // delete the gesture example in the grid
                if (grids[i].examples.Contains(gestureExample))
                {
                    int gestureExampleIndex = grids[i].examples.IndexOf(gestureExample);
                    grids[i].examples.RemoveAt(gestureExampleIndex);
                }

                // delete the gesture gallery example in the grid
                for (int j = grids[i].galleryExamples.Count - 1; j >= 0; j--)
                {
                    if (grids[i].galleryExamples[j].example == gestureExample)
                    {
                        Destroy(grids[i].galleryExamples[j].gameObject);
                        grids[i].galleryExamples.RemoveAt(j);
                    }
                }

                Vector3 lastPosition = galleryRB.position;
                DestroyGestureGalleryGrids();
                CreateGestureGalleryGrids();
                PositionGestureGallery(lastPosition);
            }
        }
예제 #4
0
        void CallDeleteGesture(GestureExample gestureExample, GameObject frame, GameObject line)
        {
            int lineNumber = examples.IndexOf(gestureExample);

            examples.Remove(gestureExample);
            Utils.Instance.DeleteGestureExample(currentNeuralNet, currentGesture, lineNumber);
            GameObject.Destroy(frame);
            GameObject.Destroy(line);
        }
예제 #5
0
        public double[][] ReadAllData()
        {
            //read in the file
            //technically this should only read files that are also in the gestures list.
            //@TODO - compare files in gestures folder to  ones in list.
            string gesturesFilePath = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + recognizerName + "/Gestures/";

            if (!System.IO.Directory.Exists(gesturesFilePath))
            {
                Debug.Log("No recorded gestures. Please record some gestures in VR.");
                return(null);
            }
            string[] files = System.IO.Directory.GetFiles(gesturesFilePath, "*.txt");

            List <string> tmpLines = new List <string>();

            foreach (string fileLocation in files)
            {
                tmpLines.AddRange(System.IO.File.ReadAllLines(fileLocation));
            }
            string[] lines = tmpLines.ToArray();

            double[][]      readData   = new double[lines.Length][];
            List <double[]> tmpAllData = new List <double[]>();

            foreach (string currentLine in lines)
            {
                //Gesture Example will need to know if it is Sync.
                GestureExample myObject = JsonUtility.FromJson <GestureExample>(currentLine);
                if (Config.USE_RAW_DATA)
                {
                    myObject.data = Utils.SubDivideLine(myObject.data);
                    myObject.data = Utils.DownScaleLine(myObject.data);
                }

                List <double> tmpLine = new List <double>();
                //First Add All Inputs
                tmpLine.Add((int)myObject.hand);
                tmpLine.AddRange(myObject.GetAsArray());
                tmpLine.AddRange(FindOutputVector(myObject.name, myObject.hand, myObject.isSynchronous));

                tmpAllData.Add(tmpLine.ToArray());
            }

            return(tmpAllData.ToArray());
        }
예제 #6
0
        public double[][] ReadAllData()
        {
            //read in the file
            //technically this should only read files that are also in the gestures list.
            //@TODO - compare files in gestures folder to  ones in list.
            string gesturesFilePath = Config.SAVE_FILE_PATH + recognizerName + "/Gestures/";

            if (!System.IO.Directory.Exists(gesturesFilePath))
            {
                Debug.Log("No recorded gestures. Please record some gestures in VR.");
                return(null);
            }
            string[] files = System.IO.Directory.GetFiles(gesturesFilePath, "*.txt");

            List <string> tmpLines = new List <string>();

            foreach (string fileLocation in files)
            {
                tmpLines.AddRange(System.IO.File.ReadAllLines(fileLocation));
            }
            string[] lines = tmpLines.ToArray();
            //This need to read every file inside of gestures.
            //string[] lines = System.IO.File.ReadAllLines(Config.SAVE_FILE_PATH + examplesFileName);

            double[][]      readData   = new double[lines.Length][];
            List <double[]> tmpAllData = new List <double[]>();

            foreach (string currentLine in lines)
            {
                GestureExample myObject = JsonUtility.FromJson <GestureExample>(currentLine);
                if (Config.USE_RAW_DATA)
                {
                    myObject.data = Utils.Instance.SubDivideLine(myObject.data);
                    myObject.data = Utils.Instance.DownScaleLine(myObject.data);
                }

                List <double> tmpLine = new List <double>();
                tmpLine.AddRange(myObject.GetAsArray());
                tmpLine.AddRange(CalculateOutputVector(myObject.name));

                tmpAllData.Add(tmpLine.ToArray());
            }

            return(tmpAllData.ToArray());
        }
예제 #7
0
        public static void RenameGestureFile(string gestureOldName, string gestureNewName, string networkName)
        {
            string oldPath = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + networkName + "/Gestures/" + gestureOldName + ".txt";
            string newPath = Application.streamingAssetsPath + Config.NEURAL_NET_PATH + networkName + "/Gestures/" + gestureNewName + ".txt";

            //get all them old gesture
            string[]      oldLines = System.IO.File.ReadAllLines(oldPath);
            List <string> newLines = new List <string>();

            foreach (string line in oldLines)
            {
                GestureExample currentGest = JsonUtility.FromJson <GestureExample>(line);
                currentGest.name = gestureNewName;
                newLines.Add(JsonUtility.ToJson(currentGest));
            }
            System.IO.File.WriteAllLines(newPath, newLines.ToArray());
            DeleteGestureFile(gestureOldName, networkName);
        }
예제 #8
0
        public void Init(VRGestureGalleryGrid _grid, GestureExample _example, int _lineNumber)
        {
            grid       = _grid;
            example    = _example;
            lineNumber = _lineNumber;

            // draw the line
            lineDrawing = DrawGesture(example.data, _lineNumber);

            transform.localPosition = Vector3.zero;
            transform.localScale    = Vector3.one;

            // set the trash icon position
            RectTransform trashTF = (RectTransform)trash.transform;

            trashTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 20);
            trashTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);

            // add the button listener function
            button.onClick.AddListener(() => grid.gallery.DeleteGestureExample(example, lineNumber));
        }
예제 #9
0
        void GenerateGestureGallery()
        {
            float xPos   = 0;
            float yPos   = 0;
            int   column = 0;
            int   row    = 0;

            // draw gesture at position
            float gridStartPosX = (gridUnitSize * gridMaxColumns) / 2;
            int   gridMaxRows   = examples.Count / gridMaxColumns;
            float gridStartPosY = (gridUnitSize * gridMaxRows) / 2;

            // go through all the gesture examples and draw them in a grid
            for (int i = 0; i < examples.Count; i++)
            {
                // set the next position
                xPos = column * gridUnitSize;
                yPos = -row * gridUnitSize;

                // offset positions to center the transform
                xPos -= gridStartPosX;
                yPos += gridStartPosY;

                Vector3 localPos = new Vector3(xPos, yPos, 0);

                // draw the gesture
                GameObject gestureLine = DrawGesture(examples[i].data, localPos, i);

                // draw the frame
                Vector3    framePos = localPos + frameOffset;
                GameObject frame    = GameObject.Instantiate(framePrefab) as GameObject;
                frame.transform.parent        = transform;
                frame.transform.localPosition = framePos;
                frame.transform.localRotation = Quaternion.identity;
                frame.name = "Frame " + i;
                frame.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, gridUnitSize);
                frame.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, gridUnitSize);
                Button         frameButton = frame.GetComponent <Button>();
                GestureExample example     = examples[i];
                GameObject     lineObj     = gestureLine;
                frameButton.onClick.AddListener(() => CallDeleteGesture(example, frame, lineObj));

                // set the trash icon position
                VRGestureGalleryFrame frameScript = frame.GetComponent <VRGestureGalleryFrame>();
                RectTransform         trashTF     = (RectTransform)frameScript.trash.transform;
                frameScript.trash.transform.localPosition = Vector3.zero;
                trashTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, gridUnitSize * 2);
                trashTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, gridUnitSize * 2);

                // change column or row
                column += 1;
                if (column >= gridMaxColumns)
                {
                    column = 0;
                    row   += 1;
                }
            }

            // instructions adjust
            // needs work
            float instructionsPosY = ((row + 1) * gridUnitSize);

            instructions.localPosition = new Vector3(0, instructionsPosY, 0);

            galleryState = GestureGalleryState.Visible;
        }