コード例 #1
0
        /// <summary>
        /// Save captured LMFrame data to .txt file
        /// </summary>
        /// <param name="lmFrame">Captured LMFrame</param>
        void saveJSONData(LMFrame lmFrame)
        {
            string jsonStr = lmFrame.toJSON().ToString();

            Debug.WriteLine(jsonStr);
            // save .txt and .zip file
            saveFile(jsonStr, choosedSign);
        }
コード例 #2
0
ファイル: TestForm.cs プロジェクト: NuiLab/mmGRasl
        void showFrameInUIByFrame(Frame frame)
        {
            string leapDesc = LMFrame.DebugStringFromFrame(frame);

            if (this.txbDebugConsole.InvokeRequired)
            {
                txbDebugConsole.Invoke(new dlgUpdateFrameInfo(updateFrameInfo), new object[] { leapDesc });
            }
            else
            {
                updateFrameInfo(leapDesc);
            }

            pictureBox1.Image = Helper.ImageHelper.generateBitmapFromLeapImage(frame.Images[0]);
            pictureBox2.Image = Helper.ImageHelper.generateBitmapFromLeapImage(frame.Images[1]);
        }
コード例 #3
0
        /// <summary>
        /// Update UI with LMFrame data
        /// </summary>
        /// <param name="lmFrame">Selected LMFrame</param>
        void showFrameInUI(LMFrame lmFrame)
        {
            currentFrame = lmFrame;

            string leapDesc = "";

            if (this.txbDebugConsole.InvokeRequired)
            {
                txbDebugConsole.Invoke(new dlgUpdateFrameInfo(updateFrameInfo), new object[] { leapDesc });
            }
            else
            {
                updateFrameInfo(leapDesc);
            }

            LeapGenImageThenShow(lmFrame);
        }
コード例 #4
0
        /// <summary>
        /// Load saved gesture data and show it's information in UI.
        /// </summary>
        /// <param name="fileName">Gesture data file path</param>
        void loadCaptureData(string fileName)
        {
            string captureFolder = FileHelper.captureDataFolderPath(choosedSign);
            string filePath      = captureFolder + "\\" + fileName;

            if (fileName.Contains(".zip"))
            {
                filePath = Helper.FileHelper.txtFilePathFromUnzip(filePath);
            }

            string  text  = System.IO.File.ReadAllText(filePath);
            JObject jObj  = JObject.Parse(text);
            LMFrame frame = new LMFrame(jObj);

            currentFrame = frame;
            showFrameInUI(frame);
        }
コード例 #5
0
        private async Task <int> LeapGenImageThenShow(LMFrame frame)
        {
            return(await Task <int> .Run(() =>
            {
                if (isGenerateImage)
                {
                    return 0;
                }
                isGenerateImage = true;
                Debug.WriteLine("Processing Image");

                pictureBox1.Image = frame.LeftCamImg;
                pictureBox2.Image = frame.RightCamImg;

                isGenerateImage = false;
                return 0;
            }));
        }
コード例 #6
0
ファイル: TestForm.cs プロジェクト: NuiLab/mmGRasl
        private void treeViewMouseDoubleClick(object sender, MouseEventArgs e)
        {
            //
            // Get the selected node.
            //
            TreeNode node = trvTestData.SelectedNode;
            //
            // Render message box.
            //

            string nodeStr = node.Text;

            string testFolderPath = FileHelper.testDataFolderPath();

            string filePath = testFolderPath + "\\" + nodeStr;

            string  frameStr  = File.ReadAllText(filePath);
            JObject jFrameObj = JObject.Parse(frameStr);
            LMFrame aFrame    = new LMFrame(jFrameObj);

            JObject angleObj = mTrain.angleJSONObjectFromLMFrame(aFrame);

            StringBuilder debugTxt = new StringBuilder();

            debugTxt.AppendLine(aFrame.DebugString());
            debugTxt.AppendLine("-------------------------------");
            debugTxt.AppendLine(angleObj.ToString());

            txbDebugConsole.Text = debugTxt.ToString();
            pictureBox1.Image    = aFrame.LeftCamImg;
            pictureBox2.Image    = aFrame.RightCamImg;

            string signName = mTrain.SignNameFromLMFrame(aFrame);

            txbTrainResult.Text = signName;
        }
コード例 #7
0
ファイル: TestForm.cs プロジェクト: NuiLab/mmGRasl
        // get_frame_from_leap_motion_device
        void newFrameHandler(Frame frame)
        {
            if (mStatus == TestStatus.Training)
            {
                return;
            }

            if (mStatus == TestStatus.Testing)
            {
                long currentMillis = Helper.TimeHelper.currentTime();
                // capture only 1 frame for 1  humnan sign


                if (currentMillis - lastMillisecond > delayMillisecondToRecord)
                {
                    Debug.WriteLine("Show image");
                    lastMillisecond = currentMillis;
                    showFrameInUIByFrame(frame);
                }
            }


            if (mStatus == TestStatus.Capturing)
            {
                if (isCapture)
                {
                    return;
                }
                isCapture = true;
                LMFrame lmFrame = new LMFrame(frame, "0");

                LMFrame testFrame = new LMFrame(JObject.Parse(lmFrame.toJSON().ToString()));

                currentFrame = testFrame;

                JObject angleObj = mTrain.angleJSONObjectFromLMFrame(testFrame);

                StringBuilder debugTxt = new StringBuilder();
                debugTxt.AppendLine(testFrame.DebugString());
                debugTxt.AppendLine("-------------------------------");
                debugTxt.AppendLine(angleObj.ToString());

                txbDebugConsole.Text = debugTxt.ToString();

                string signName = mTrain.SignNameFromLMFrameByListData(testFrame);

                txbTrainResult.Text = signName;

                string folderPath = FileHelper.testDataFolderPath();
                string fileName   = captureDataFileNameGetNext(folderPath);

                string txtFilePath = folderPath + "\\" + fileName + ".txt";

                Debug.WriteLine("Begin save");
                // pass in true to cause writes to be appended
                StreamWriter sw = new StreamWriter(txtFilePath, true);

                // use writeline so we get a newline character written
                sw.WriteLine(lmFrame.toJSON().ToString());

                // Ensure data is written to disk
                sw.Close();

                ReloadListTestData();
            }
        }
コード例 #8
0
        /// <summary>
        /// Leap Motion frame handling
        /// </summary>
        /// <param name="frame">A frame get from leap motion</param>
        void newFrameHandler(Frame frame)
        {
            long currentMillis = Helper.TimeHelper.currentTime();

            // capture only 1 frame for 1  humnan sign

            if (mCaptureStatus == CaptureStatus.PreAutoCapture)
            {
                if (currentMillis - lastMillisecond > delayMillisecondToRecord)
                {
                    Debug.WriteLine("Show image");
                    lastMillisecond = currentMillis;
                    showFrameInUIByFrame(frame);
                }

                return;
            }

            if (mCaptureStatus == CaptureStatus.PreCapture)
            {
                // auto capture each time. status change to capture
                long autoCaptureCountdown = currentMillis - lastAutocaptureTime;
                if (autoCaptureCountdown > autoCaptureTimeOut)
                {
                    lastAutocaptureTime = currentMillis;
                    mCaptureStatus      = CaptureStatus.Capture;
                    lbCaptureText.Text  = "Capturing ....";
                }
                else
                {
                    lbCaptureText.Text = "Capture in " + autoCaptureCountdown + " milliseconds";

                    if (currentMillis - lastMillisecond > delayMillisecondToRecord)
                    {
                        Debug.WriteLine("Show image");
                        lastMillisecond = currentMillis;
                        showFrameInUIByFrame(frame);
                    }

                    return;
                }
            }
            if (mCaptureStatus != CaptureStatus.Capture)
            {
                return;
            }
            mCaptureStatus = CaptureStatus.FinishCapture;

            // Leap Motion Frame will be convert to LMFrame
            LMFrame lmFrame;

            try
            {
                lmFrame = new LMFrame(frame, choosedSign);
            }
            catch (Exception e)
            {
                FileHelper.saveDebugString("LMFrame create : " + "frame data: " + frame.ToString() + "\\n" + e.Data.ToString());
                return;
            }

            if (lmFrame.LeftCamImg == null)
            {
                return;
            }


            // Save test data
            currentLeapMotionFrame = frame;

            showFrameInUI(lmFrame);

            saveJSONData(lmFrame);

            if (autoCaptureCount + 2 > autoCaptureFileCount)
            {
                lbCaptureText.Text = "Auto capture finished.";
                mCaptureStatus     = CaptureStatus.PreviewSign;
                reloadListHumanSign();
                updateUIByCaptureStatus();
            }
            else
            {
                autoCaptureCount++;
            }
        }